Package com.ibm.fhir.database.utils.api
Interface IDatabaseTranslator
-
- All Known Implementing Classes:
Db2Translator
,DerbyNetworkTranslator
,DerbyTranslator
,PostgresTranslator
public interface IDatabaseTranslator
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
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description String
addForUpdate(String sql)
Append FOR UPDATE/FOR UPDATE WITH RS depending on the target DB typeboolean
clobSupportsInline()
Does the database support inlining for clobsString
createGlobalTempTable(String ddl)
String
createSequence(String name, int cache)
Craft the DDL for a CREATE SEQUENCE statementString
currentTimestampString()
Get the "CURRENT TIMESTAMP" string for the database typeString
dropForeignKeyConstraint(String qualifiedTableName, String constraintName)
Generate the DDL for dropping the named FK constraint from the given tableString
dualTableName()
The name of the "DUAL" table...that special table giving us one row/column.void
fillProperties(Properties p, ConnectionDetails cd)
Configure the properties using information from the ConnectionDetailsString
getDriverClassName()
Get the driver class to use for connectionsDbType
getType()
The main type of the databaseString
getUrl(Properties connectionProperties)
Get the JDBC connection URL based on the propertiesString
globalTempTableName(String tableName)
Get the proper table name based on the type of database we are connected to.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 TYPEboolean
isConnectionError(SQLException x)
Returns true if the exception represents a connection errorboolean
isDeadlock(SQLException x)
Was this statement the victim of a deadlockboolean
isDerby()
Are we working with a Derby databaseboolean
isDuplicate(SQLException x)
Check the exception to see if it is reporting a duplicate value constraint violationdefault boolean
isIndexUseSchemaPrefix()
Does this database use the schema prefix when defining indexesboolean
isLockTimeout(SQLException x)
Database timed out waiting to get a lock.boolean
isUndefinedName(SQLException x)
Returns true if the SQLException is indicating an object is undefined (e.g.String
limit(String arg)
Get the correct LIMIT/FETCH NEXT ROWS clause for the databaseString
nextValue(String schemaName, String sequenceName)
Statement for getting the next value (for use in a select list or insert values)String
pagination(int offset, int rowsPerPage)
Construct a pagination clause specific to the type of databaseString
reorgTableCommand(String tableName)
Return the REORG TABLE command if supported, or null otherwiseString
selectSequenceNextValue(String schemaName, String sequenceName)
Compose a select statement to obtain the next value from the named sequenceString
timestampDiff(String left, String right, String alias)
Returns an expression which computes the timestamp difference between left and right in secondsDataAccessException
translate(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:
-
nextValue
String nextValue(String schemaName, String sequenceName)
Statement for getting the next value (for use in a select list or insert values)- 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:
-
limit
String limit(String arg)
Get the correct LIMIT/FETCH NEXT ROWS clause for the database- Parameters:
arg
- a literal int or ? bind-variable marker- Returns:
-
pagination
String pagination(int offset, int rowsPerPage)
Construct a pagination clause specific to the type of database- Parameters:
offset
- the row offsetrowsPerPage
- limit the number of rows returned (from the offset)- 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
-
dropForeignKeyConstraint
String dropForeignKeyConstraint(String qualifiedTableName, String constraintName)
Generate the DDL for dropping the named FK constraint from the given table- Parameters:
qualifiedTableName
- such as schema.foo_tabconstraintName
- the constraint name of the FK- Returns:
-
isIndexUseSchemaPrefix
default boolean isIndexUseSchemaPrefix()
Does this database use the schema prefix when defining indexes- Returns:
-
-