Skip to content

Commit

Permalink
issue #3676 removed dead code related to Db2
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 21, 2022
1 parent 2da2031 commit 75489a6
Show file tree
Hide file tree
Showing 68 changed files with 541 additions and 3,678 deletions.
4 changes: 0 additions & 4 deletions fhir-bucket/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -56,6 +56,6 @@ public class Constants {
public static final int IMPORT_RETRY_TIMES = 1;
public static final int COS_REQUEST_TIMEOUT = 10000;
// Batch writing to DB can take long time which can make the idle COS/S3 client connection timeout, so set the client socket timeout
// to 120 seconds which is the default DB2 timeout.
// to 120 seconds which is the default liberty transaction timeout.
public static final int COS_SOCKET_TIMEOUT = 120000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ public void setupDerbyRepository() {
}

/**
* Set up the connection pool and transaction provider for connecting to a DB2
* Set up the connection pool and transaction provider for connecting to a PostgreSQL
* database
*/
public void setupPostgresRepository() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2020, 2021
* (C) Copyright IBM Corp. 2020, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -22,7 +22,7 @@
/**
* DAO to encapsulate all the SQL/DML used to retrieve and persist data
* in the schema.
* Supports: Db2 and Derby
* Supports: Derby
* Does not support: PostgreSQL
*/
public class MergeResourceTypes implements IDatabaseStatement {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2020, 2021
* (C) Copyright IBM Corp. 2020, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -38,7 +38,7 @@ public MergeResources(Collection<ResourceRec> resources) {
@Override
public void run(IDatabaseTranslator translator, Connection c) {

// Support for PostgreSQL as well as Derby/Db2
// Support for PostgreSQL as well as Derby
final String currentTimestamp = translator.currentTimestampString();
final String dual = translator.dualTableName();
final String source = dual == null ? "(SELECT 1)" : dual;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public void testDefaultDatasourceLookup() throws Exception {
PropertyGroup dsPG = FHIRConfigHelper.getPropertyGroup(dsPropertyName);
assertNotNull(dsPG);
String type = dsPG.getStringProperty("type");
assertEquals("db2", type);
assertEquals("postgresql", type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"persistence": {
"datasources": {
"default": {
"type": "db2"
"type": "postgresql"
}
},
"payload": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2019
* (C) Copyright IBM Corp. 2019, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -33,7 +33,7 @@ public interface IConnectionProvider {
/**
* Get the translator associated with this connection provider. Supports
* interpretation of SQLExceptions and the ability to tweak
* SQL statements to handle differences between DB2 and Derby
* SQL statements to handle differences between databases
* @return
*/
public IDatabaseTranslator getTranslator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@

/**
* Abstraction of the SQL to use for a given database. This allows us to hide as
* much as possible the differences in syntax and support between DB2 and Derby
* (which is used for unit-testing). Derby is pretty close to DB2 in most cases,
* but notably does not support partitioning, variables or SPL stored
* procedures.
* much as possible the differences in syntax and support between databases.
*/
public interface IDatabaseAdapter {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2019, 2020
* (C) Copyright IBM Corp. 2019, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -13,9 +13,7 @@
import com.ibm.fhir.database.utils.model.DbType;

/**
* Lets us adjust DDL/DML/SQL statements to match the target database. This
* is needed because DB2 and Derby have a few differences, and we need to
* tweak the SQL in order to support all the unit tests we want/need
* Lets us adjust DDL/DML/SQL statements to match the target database.
*/
public interface IDatabaseTranslator {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
import com.ibm.fhir.database.utils.tenant.UpdateTenantStatusDAO;

/**
* Provides schema control functions common to our supported databases (DB2 and Derby)
* Provides schema control functions common to our supported databases:
* PostgreSQL
* Derby (for unit tests, not production)
*/
public abstract class CommonDatabaseAdapter implements IDatabaseAdapter, IDatabaseTypeAdapter {
private static final Logger logger = Logger.getLogger(CommonDatabaseAdapter.class.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2019, 2020
* (C) Copyright IBM Corp. 2019, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -41,7 +41,7 @@ public DropForeignKeyConstraint(String schemaName, String tableName, String... c
public void run(IDatabaseTranslator translator, Connection c) {
String qTableName = DataDefinitionUtil.getQualifiedName(schemaName, tableName);

// Need to account for the syntax differences betweeb Db2/Derby and PostgreSQL
// Need to account for the syntax differences between Derby and PostgreSQL
// DB2: ALTER TABLE tbl DROP FOREIGN KEY fkConstraintName
// PostgreSQL: ALTER TABLE tbl DROP CONSTRAINT fkConstraintName
for (String constraintName : constraintNames) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2020
* (C) Copyright IBM Corp. 2020, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -45,7 +45,7 @@ public GetSequenceNextValueDAO(String schemaName, String sequenceName) {
public Long run(IDatabaseTranslator translator, Connection c) {
// you can't get the current value before calling next value in a given session,
// so we simply bump the sequence number. The translator is used to support
// our different database flavors (e.g. Derby, DB2 and PostgreSQL)
// our different database flavors (e.g. Derby and PostgreSQL)
final String SQL = translator.selectSequenceNextValue(schemaName, sequenceName);

try (PreparedStatement ps = c.prepareStatement(SQL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Adapter to build the plain version of the FHIR schema. Uses
* the IDatabaseAdapter to hide the specifics of a particular
* database flavor (like Db2, PostgreSQL, Derby etc).
* database flavor (like PostgreSQL, Derby etc).
*/
public class PlainSchemaAdapter implements ISchemaAdapter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ public String varbinaryClause(int size) {

@Override
public String blobClause(long size, int inlineSize) {
// Derby doesn't support the INLINE feature (which greatly helps with
// performance on DB2)
// Derby doesn't support the INLINE feature
return "BLOB(" + size + ")";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ public ITaskGroup collect(final ITaskCollector tc, final ISchemaAdapter target,
@Override
public void applyTx(ISchemaAdapter target, SchemaApplyContext context, ITransactionProvider tp, IVersionHistoryService vhs) {
// Wrap the apply operation in its own transaction, as this is likely
// being executed from a thread-pool. DB2 has some issues with deadlocks
// on its catalog tables (SQLCODE=-911, SQLSTATE=40001, SQLERRMC=2) when
// applying schema changes in parallel, so we need a little retry loop.
// being executed from a thread-pool. The retry loop is required to
// cover any deadlocks we might encounter caused by issuing DDL in
// parallel.
int remainingAttempts = 10;
while (remainingAttempts-- > 0) {
try (ITransaction tx = tp.getTransaction()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ public String toString() {
@Override
public void applyTx(ISchemaAdapter target, SchemaApplyContext context, ITransactionProvider tp, IVersionHistoryService vhs) {
// Wrap the apply operation in its own transaction, as this is likely
// being executed from a thread-pool. DB2 has some issues with deadlocks
// on its catalog tables (SQLCODE=-911, SQLSTATE=40001, SQLERRMC=2) when
// applying schema changes in parallel, so we need a little retry loop.
// being executed from a thread-pool.
int remainingAttempts = 10;
while (remainingAttempts-- > 0) {
try (ITransaction tx = tp.getTransaction()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public class Table extends BaseObject {
// All the FK constraints used by this table
private final List<ForeignKeyConstraint> fkConstraints = new ArrayList<>();

// enable access control
private final SessionVariableDef accessControlVar;

private final Tablespace tablespace;

// The column to use when making this table multi-tenant (if supported by the the target)
Expand Down Expand Up @@ -90,7 +87,7 @@ public class Table extends BaseObject {
public Table(String schemaName, String name, int version, String tenantColumnName,
Collection<ColumnBase> columns, PrimaryKeyDef pk,
IdentityDef identity, Collection<IndexDef> indexes, Collection<ForeignKeyConstraint> fkConstraints,
SessionVariableDef accessControlVar, Tablespace tablespace, List<IDatabaseObject> dependencies, Map<String,String> tags,
Tablespace tablespace, List<IDatabaseObject> dependencies, Map<String,String> tags,
Collection<GroupPrivilege> privileges, List<Migration> migrations, List<With> withs, List<CheckConstraint> checkConstraints,
DistributionType distributionType, String distributionColumnName, boolean create) {
super(schemaName, name, DatabaseObjectType.TABLE, version, migrations);
Expand All @@ -100,7 +97,6 @@ public Table(String schemaName, String name, int version, String tenantColumnNam
this.identity = identity;
this.indexes.addAll(indexes);
this.fkConstraints.addAll(fkConstraints);
this.accessControlVar = accessControlVar;
this.tablespace = tablespace;
this.withs = withs;
this.checkConstraints.addAll(checkConstraints);
Expand Down Expand Up @@ -179,18 +175,6 @@ public void apply(ISchemaAdapter target, SchemaApplyContext context) {
fkc.apply(getSchemaName(), getObjectName(), this.tenantColumnName, target, this.distributionType);
}
}

// Apply tenant access control if required
if (this.accessControlVar != null) {
// The accessControlVar represents a DB2 session variable. Programs must set this value
// for the current tenant when executing any SQL (both reads and writes) on
// tables with this access control enabled
final String variableName = accessControlVar.getQualifiedName();
final String tenantPermission = getObjectName() + "_TENANT";
final String predicate = getQualifiedName() + ".MT_ID = " + variableName;
target.createOrReplacePermission(getSchemaName(), tenantPermission, getObjectName(), predicate);
target.activateRowAccessControl(getSchemaName(), getObjectName());
}
}

@Override
Expand All @@ -201,17 +185,6 @@ public void apply(Integer priorVersion, ISchemaAdapter target, SchemaApplyContex
for (Migration step : migrations) {
step.migrateFrom(priorVersion).stream().forEachOrdered(target::runStatement);
}
// Re-apply tenant access control if required
if (this.accessControlVar != null && this.create) {
// The accessControlVar represents a DB2 session variable. Programs must set this value
// for the current tenant when executing any SQL (both reads and writes) on
// tables with this access control enabled
final String variableName = accessControlVar.getQualifiedName();
final String tenantPermission = getObjectName() + "_TENANT";
final String predicate = getQualifiedName() + ".MT_ID = " + variableName;
target.createOrReplacePermission(getSchemaName(), tenantPermission, getObjectName(), predicate);
target.activateRowAccessControl(getSchemaName(), getObjectName());
}
}
}

Expand All @@ -225,12 +198,6 @@ protected void grantGroupPrivileges(ISchemaAdapter target, Set<Privilege> group,

@Override
public void drop(ISchemaAdapter target) {
if (this.accessControlVar != null) {
target.deactivateRowAccessControl(getSchemaName(), getObjectName());

final String tenantPermission = getObjectName() + "_TENANT";
target.dropPermission(getSchemaName(), tenantPermission);
}
target.dropTable(getSchemaName(), getObjectName());
}

Expand Down Expand Up @@ -280,9 +247,6 @@ public static class Builder extends VersionedSchemaObject {
// The tablespace to use for this table [optional]
private Tablespace tablespace;

// The variable to use for access control (when set)
private SessionVariableDef accessControlVar;

// Privileges to be granted on this table
private List<GroupPrivilege> privileges = new ArrayList<>();

Expand Down Expand Up @@ -864,7 +828,7 @@ public Table build(IDataModel dataModel) {
// Our schema objects are immutable by design, so all initialization takes place
// through the constructor
return new Table(getSchemaName(), getObjectName(), this.version, this.tenantColumnName, buildColumns(), this.primaryKey, this.identity, this.indexes.values(),
enabledFKConstraints, this.accessControlVar, this.tablespace, allDependencies, tags, privileges, migrations, withs, checkConstraints, distributionType,
enabledFKConstraints, this.tablespace, allDependencies, tags, privileges, migrations, withs, checkConstraints, distributionType,
distributionColumnName, create);
}

Expand Down Expand Up @@ -932,18 +896,6 @@ protected List<ColumnBase> buildColumns() {
return result;
}

/**
* Switch on access control for this table
*/
public Builder enableAccessControl(SessionVariableDef var) {
this.accessControlVar = var;

// Add the session variable as a dependency for this table
this.dependencies.add(var);

return this;
}

/**
* @param tagName
* @param tagValue
Expand All @@ -970,9 +922,7 @@ public Builder addPrivileges(Collection<GroupPrivilege> gps) {
}

/**
* Setter to configure this table for multitenancy. Multitenancy support depends on the target
* ...which in this case means DB2 supports it (using partitioning) but Derby does not...so for
* Derby, we don't create the extra column or FK relationships back to the TENANTS table.
* Setter to configure this table for multitenancy when supported by the target database type
* @return
*/
public Builder setTenantColumnName(String name) {
Expand Down
4 changes: 0 additions & 4 deletions fhir-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions fhir-install/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
<groupId>org.apache.derby</groupId>
<artifactId>derbytools</artifactId>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions fhir-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,6 @@
<version>22.0.0.4</version>
<type>zip</type>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>11.5.7.0</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions fhir-persistence-blob-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@
<artifactId>derbytools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
Loading

0 comments on commit 75489a6

Please sign in to comment.