Skip to content

Commit

Permalink
issue #3676 remove more legacy tenant-specific code
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Arnold <robin.arnold@ibm.com>
  • Loading branch information
punktilious committed Jul 25, 2022
1 parent dae4754 commit 012eb24
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -740,21 +740,17 @@ private static void configureCitusConnection(Connection c) {
* DerbyBootstrapper.populateResourceTypeAndParameterNameTableEntries
* and DerbyFhirDatabase.populateResourceTypeAndParameterNameTableEntries
* The reason is there are three different ways of managing the transaction.
* @param tenantId
* the mt_id that is used to setup the partition.
* passing in null signals not multi-tenant.
*/
protected void populateResourceTypeAndParameterNameTableEntries(Integer tenantId) {
protected void populateResourceTypeAndParameterNameTableEntries() {
try (ITransaction tx = TransactionFactory.openTransaction(connectionPool)) {
try (Connection c = connectionPool.getConnection();) {
String logTenantId = tenantId != null ? Integer.toString(tenantId) : "default";
logger.info("tenantId [" + logTenantId + "] is being pre-populated with lookup table data.");
logger.info("Populating schema with lookup table data.");
PopulateResourceTypes populateResourceTypes =
new PopulateResourceTypes(schema.getAdminSchemaName(), schema.getSchemaName(), tenantId);
new PopulateResourceTypes(schema.getSchemaName());
populateResourceTypes.run(translator, c);

PopulateParameterNames populateParameterNames =
new PopulateParameterNames(schema.getAdminSchemaName(), schema.getSchemaName(), tenantId);
new PopulateParameterNames(schema.getSchemaName());
populateParameterNames.run(translator, c);
logger.info("Finished prepopulating the resource type and search parameter code/name tables tables");
} catch (SQLException ex) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -29,14 +28,14 @@
*/
public class PopulateParameterNames implements IDatabaseStatement {

private final String adminSchemaName;
private final String schemaName;
private final Integer tenantId;

public PopulateParameterNames(String adminSchemaName, String schemaName, Integer tenantId) {
this.adminSchemaName = adminSchemaName;
/**
* Public constructor
* @param schemaName
*/
public PopulateParameterNames(String schemaName) {
this.schemaName = schemaName;
this.tenantId = tenantId;
}

@Override
Expand All @@ -45,26 +44,9 @@ public void run(IDatabaseTranslator translator, Connection c) {

// For Db2 multi-tenancy, we need to set up the SV_TENANT_ID in order for the row-based-access-control
// to work
final String stmtVariable = String.format("SET %s.SV_TENANT_ID = %d", adminSchemaName, tenantId);
final String stmtResourceTypeInsert;
final String PARAMETER_NAMES = String.format("SELECT PARAMETER_NAME_ID, PARAMETER_NAME FROM %s.parameter_names", schemaName);
if (tenantId != null) {
stmtResourceTypeInsert =
String.format("INSERT INTO %s.parameter_names (MT_ID, PARAMETER_NAME_ID, PARAMETER_NAME) "
+ "VALUES (%s.sv_tenant_id, %s, ?)", schemaName, adminSchemaName, nextRefVal);
} else {
stmtResourceTypeInsert =
final String stmtResourceTypeInsert =
String.format("INSERT INTO %s.parameter_names (PARAMETER_NAME_ID, PARAMETER_NAME) VALUES (%s, ?)", schemaName, nextRefVal);
}

// Configure RBAC if we're Db2 multi-tenant
if (tenantId != null) {
try (Statement s = c.createStatement();) {
s.execute(stmtVariable);
} catch (SQLException x) {
throw translator.translate(x);
}
}

// Grab a set containing all the current parameter names so we can skip them
Set<String> currentParameterNames = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -35,41 +34,25 @@
public class PopulateResourceTypes implements IDatabaseStatement {

private static final Logger LOGGER = Logger.getLogger(PopulateResourceTypes.class.getName());
private final String adminSchemaName;
private final String schemaName;
private final Integer tenantId;

private static final String Y = "Y";

public PopulateResourceTypes(String adminSchemaName, String schemaName, Integer tenantId) {
this.adminSchemaName = adminSchemaName;
/**
* Public constructor
* @param schemaName
*/
public PopulateResourceTypes(String schemaName) {
this.schemaName = schemaName;
this.tenantId = tenantId;
}

@Override
public void run(IDatabaseTranslator translator, Connection c) {
final String stmtVariable = String.format("SET %s.SV_TENANT_ID = %d", adminSchemaName, tenantId);
final String stmtResourceTypeInsert;
final String RESOURCE_TYPES = String.format("SELECT resource_type_id, resource_type, retired FROM %s.resource_types", schemaName);
if (tenantId != null) {
stmtResourceTypeInsert = String.format("INSERT INTO %s.resource_types (mt_id, resource_type_id, resource_type) "
+ "VALUES (%s.sv_tenant_id, ?, ?)", schemaName, adminSchemaName);
} else {
stmtResourceTypeInsert = String.format("INSERT INTO %s.resource_types (resource_type_id, resource_type) "
final String stmtResourceTypeInsert = String.format("INSERT INTO %s.resource_types (resource_type_id, resource_type) "
+ "VALUES (?, ?)", schemaName);
}
final String stmtResourceTypeUpdate = String.format("UPDATE %s.resource_types SET retired = 'Y' WHERE resource_type = ?", schemaName);

// Only if it's multitenant is tenantId not null.
if (tenantId != null) {
try (Statement s = c.createStatement();) {
s.execute(stmtVariable);
} catch (SQLException e) {
throw translator.translate(e);
}
}

Map<String, Integer> values = new HashMap<>();
List<String> previouslyRetiredTypes = new ArrayList<>();
try (PreparedStatement list = c.prepareStatement(RESOURCE_TYPES)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2019, 2021
* (C) Copyright IBM Corp. 2019, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -147,11 +147,11 @@ public void populateResourceTypeAndParameterNameTableEntries() throws SQLExcepti

if (!populated) {
PopulateResourceTypes populateResourceTypes =
new PopulateResourceTypes(ADMIN_SCHEMA_NAME, SCHEMA_NAME, null);
new PopulateResourceTypes(SCHEMA_NAME);
populateResourceTypes.run(translator, connection);

PopulateParameterNames populateParameterNames =
new PopulateParameterNames(ADMIN_SCHEMA_NAME, SCHEMA_NAME, null);
new PopulateParameterNames(SCHEMA_NAME);
populateParameterNames.run(translator, connection);
logger.info("Finished prepopulating the resource type and search parameter code/name tables tables");
} else {
Expand Down

0 comments on commit 012eb24

Please sign in to comment.