Package com.ibm.fhir.database.utils.api
Interface IDatabaseTranslator
-
- All Known Implementing Classes:
Db2Translator,DerbyNetworkTranslator,DerbyTranslator,PostgreSqlTranslator
public interface IDatabaseTranslatorLets 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
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description StringaddForUpdate(String sql)Append FOR UPDATE/FOR UPDATE WITH RS depending on the target DB typebooleanclobSupportsInline()Does the database support inlining for clobsStringcreateGlobalTempTable(String ddl)StringcreateSequence(String name, int cache)Craft the DDL for a CREATE SEQUENCE statementStringcurrentTimestampString()Get the "CURRENT TIMESTAMP" string for the database typeStringdualTableName()The name of the "DUAL" table...that special table giving us one row/column.voidfillProperties(Properties p, ConnectionDetails cd)Configure the properties using information from the ConnectionDetailsStringgetDriverClassName()Get the driver class to use for connectionsDbTypegetType()The main type of the databaseStringgetUrl(Properties connectionProperties)Get the JDBC connection URL based on the propertiesStringglobalTempTableName(String tableName)Get the proper table name based on the type of database we are connected to.booleanisAlreadyExists(SQLException x)Check the exception to see if it is reporting that THE NAME OF THE OBJECT TO BE CREATED OR THE TARGET OF A RENAME STATEMENT IS IDENTICAL TO THE EXISTING NAME OF THE OBJECT TYPEbooleanisConnectionError(SQLException x)Returns true if the exception represents a connection errorbooleanisDeadlock(SQLException x)Was this statement the victim of a deadlockbooleanisDerby()Are we working with a Derby databasebooleanisDuplicate(SQLException x)Check the exception to see if it is reporting a duplicate value constraint violationbooleanisLockTimeout(SQLException x)Database timed out waiting to get a lock.booleanisUndefinedName(SQLException x)Returns true if the SQLException is indicating an object is undefined (e.g.StringreorgTableCommand(String tableName)Return the REORG TABLE command if supported, or null otherwiseStringselectSequenceNextValue(String schemaName, String sequenceName)Compose a select statement to obtain the next value from the named sequenceStringtimestampDiff(String left, String right, String alias)Returns an expression which computes the timestamp difference between left and right in secondsDataAccessExceptiontranslate(SQLException x)Get an appropriate instance of ReplicatorException to throw depending on the details of SQLException
-
-
-
Method Detail
-
isDerby
boolean isDerby()
Are we working with a Derby database- Returns:
-
addForUpdate
String addForUpdate(String sql)
Append FOR UPDATE/FOR UPDATE WITH RS depending on the target DB type- Parameters:
sql-- Returns:
-
globalTempTableName
String globalTempTableName(String tableName)
Get the proper table name based on the type of database we are connected to. Derby has its own handling of temp tables- Parameters:
tableName-- Returns:
-
selectSequenceNextValue
String selectSequenceNextValue(String schemaName, String sequenceName)
Compose a select statement to obtain the next value from the named sequence- Parameters:
schemaName-sequenceName-- Returns:
-
isDuplicate
boolean isDuplicate(SQLException x)
Check the exception to see if it is reporting a duplicate value constraint violation- Parameters:
x-- Returns:
-
isAlreadyExists
boolean isAlreadyExists(SQLException x)
Check the exception to see if it is reporting that THE NAME OF THE OBJECT TO BE CREATED OR THE TARGET OF A RENAME STATEMENT IS IDENTICAL TO THE EXISTING NAME OF THE OBJECT TYPE- Parameters:
x-- Returns:
-
isLockTimeout
boolean isLockTimeout(SQLException x)
Database timed out waiting to get a lock. This is not the same as a deadlock, of course- Parameters:
x-- Returns:
-
isDeadlock
boolean isDeadlock(SQLException x)
Was this statement the victim of a deadlock- Parameters:
x-- Returns:
-
isConnectionError
boolean isConnectionError(SQLException x)
Returns true if the exception represents a connection error- Parameters:
x-- Returns:
-
translate
DataAccessException translate(SQLException x)
Get an appropriate instance of ReplicatorException to throw depending on the details of SQLException- Parameters:
x-- Returns:
-
isUndefinedName
boolean isUndefinedName(SQLException x)
Returns true if the SQLException is indicating an object is undefined (e.g. "DROP TABLE foo.bar", where table "foo.bar" doesn't exist)- Parameters:
x-- Returns:
-
fillProperties
void fillProperties(Properties p, ConnectionDetails cd)
Configure the properties using information from the ConnectionDetails- Parameters:
p-cd-
-
timestampDiff
String timestampDiff(String left, String right, String alias)
Returns an expression which computes the timestamp difference between left and right in seconds- Parameters:
left-right-alias- adds " AS alias " if alias is not null- Returns:
-
currentTimestampString
String currentTimestampString()
Get the "CURRENT TIMESTAMP" string for the database type- Returns:
-
createSequence
String createSequence(String name, int cache)
Craft the DDL for a CREATE SEQUENCE statement- Parameters:
name-cache- the number of sequence values to cache, if supported by the database- Returns:
-
reorgTableCommand
String reorgTableCommand(String tableName)
Return the REORG TABLE command if supported, or null otherwise- Parameters:
tableName-- Returns:
-
getDriverClassName
String getDriverClassName()
Get the driver class to use for connections- Returns:
-
getUrl
String getUrl(Properties connectionProperties)
Get the JDBC connection URL based on the properties- Parameters:
connectionProperties-- Returns:
-
clobSupportsInline
boolean clobSupportsInline()
Does the database support inlining for clobs- Returns:
-
getType
DbType getType()
The main type of the database- Returns:
-
dualTableName
String dualTableName()
The name of the "DUAL" table...that special table giving us one row/column.- Returns:
- the name of the "DUAL" table for the database, or null if not supported
-
-