Class PostgresTranslator
- java.lang.Object
-
- com.ibm.fhir.database.utils.postgres.PostgresTranslator
-
- All Implemented Interfaces:
IDatabaseTranslator
public class PostgresTranslator extends Object implements IDatabaseTranslator
translates database access to Postgres supported access.
-
-
Constructor Summary
Constructors Constructor Description PostgresTranslator()
-
Method Summary
All Methods Instance Methods Concrete 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 violationboolean
isDuplicateSchema(SQLException x)
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
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
-
addForUpdate
public String addForUpdate(String sql)
Description copied from interface:IDatabaseTranslator
Append FOR UPDATE/FOR UPDATE WITH RS depending on the target DB type- Specified by:
addForUpdate
in interfaceIDatabaseTranslator
- Returns:
-
isDerby
public boolean isDerby()
Description copied from interface:IDatabaseTranslator
Are we working with a Derby database- Specified by:
isDerby
in interfaceIDatabaseTranslator
- Returns:
-
globalTempTableName
public String globalTempTableName(String tableName)
Description copied from interface:IDatabaseTranslator
Get the proper table name based on the type of database we are connected to. Derby has its own handling of temp tables- Specified by:
globalTempTableName
in interfaceIDatabaseTranslator
- Returns:
-
createGlobalTempTable
public String createGlobalTempTable(String ddl)
- Specified by:
createGlobalTempTable
in interfaceIDatabaseTranslator
- Returns:
-
isDuplicate
public boolean isDuplicate(SQLException x)
Description copied from interface:IDatabaseTranslator
Check the exception to see if it is reporting a duplicate value constraint violation- Specified by:
isDuplicate
in interfaceIDatabaseTranslator
- Returns:
-
isAlreadyExists
public boolean isAlreadyExists(SQLException x)
Description copied from interface:IDatabaseTranslator
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- Specified by:
isAlreadyExists
in interfaceIDatabaseTranslator
- Returns:
-
isLockTimeout
public boolean isLockTimeout(SQLException x)
Description copied from interface:IDatabaseTranslator
Database timed out waiting to get a lock. This is not the same as a deadlock, of course- Specified by:
isLockTimeout
in interfaceIDatabaseTranslator
- Returns:
-
isIndexUseSchemaPrefix
public boolean isIndexUseSchemaPrefix()
Description copied from interface:IDatabaseTranslator
Does this database use the schema prefix when defining indexes- Specified by:
isIndexUseSchemaPrefix
in interfaceIDatabaseTranslator
- Returns:
-
isDeadlock
public boolean isDeadlock(SQLException x)
Description copied from interface:IDatabaseTranslator
Was this statement the victim of a deadlock- Specified by:
isDeadlock
in interfaceIDatabaseTranslator
- Returns:
-
isConnectionError
public boolean isConnectionError(SQLException x)
Description copied from interface:IDatabaseTranslator
Returns true if the exception represents a connection error- Specified by:
isConnectionError
in interfaceIDatabaseTranslator
- Returns:
-
translate
public DataAccessException translate(SQLException x)
Description copied from interface:IDatabaseTranslator
Get an appropriate instance of ReplicatorException to throw depending on the details of SQLException- Specified by:
translate
in interfaceIDatabaseTranslator
- Returns:
-
isDuplicateSchema
public boolean isDuplicateSchema(SQLException x)
-
isUndefinedName
public boolean isUndefinedName(SQLException x)
Description copied from interface:IDatabaseTranslator
Returns true if the SQLException is indicating an object is undefined (e.g. "DROP TABLE foo.bar", where table "foo.bar" doesn't exist)- Specified by:
isUndefinedName
in interfaceIDatabaseTranslator
- Returns:
-
fillProperties
public void fillProperties(Properties p, ConnectionDetails cd)
Description copied from interface:IDatabaseTranslator
Configure the properties using information from the ConnectionDetails- Specified by:
fillProperties
in interfaceIDatabaseTranslator
-
timestampDiff
public String timestampDiff(String left, String right, String alias)
Description copied from interface:IDatabaseTranslator
Returns an expression which computes the timestamp difference between left and right in seconds- Specified by:
timestampDiff
in interfaceIDatabaseTranslator
alias
- adds " AS alias " if alias is not null- Returns:
-
createSequence
public String createSequence(String name, int cache)
Description copied from interface:IDatabaseTranslator
Craft the DDL for a CREATE SEQUENCE statement- Specified by:
createSequence
in interfaceIDatabaseTranslator
cache
- the number of sequence values to cache, if supported by the database- Returns:
-
reorgTableCommand
public String reorgTableCommand(String tableName)
Description copied from interface:IDatabaseTranslator
Return the REORG TABLE command if supported, or null otherwise- Specified by:
reorgTableCommand
in interfaceIDatabaseTranslator
- Returns:
-
getDriverClassName
public String getDriverClassName()
Description copied from interface:IDatabaseTranslator
Get the driver class to use for connections- Specified by:
getDriverClassName
in interfaceIDatabaseTranslator
- Returns:
-
getUrl
public String getUrl(Properties connectionProperties)
Description copied from interface:IDatabaseTranslator
Get the JDBC connection URL based on the properties- Specified by:
getUrl
in interfaceIDatabaseTranslator
- Returns:
-
clobSupportsInline
public boolean clobSupportsInline()
Description copied from interface:IDatabaseTranslator
Does the database support inlining for clobs- Specified by:
clobSupportsInline
in interfaceIDatabaseTranslator
- Returns:
-
getType
public DbType getType()
Description copied from interface:IDatabaseTranslator
The main type of the database- Specified by:
getType
in interfaceIDatabaseTranslator
- Returns:
-
dualTableName
public String dualTableName()
Description copied from interface:IDatabaseTranslator
The name of the "DUAL" table...that special table giving us one row/column.- Specified by:
dualTableName
in interfaceIDatabaseTranslator
- Returns:
- the name of the "DUAL" table for the database, or null if not supported
-
selectSequenceNextValue
public String selectSequenceNextValue(String schemaName, String sequenceName)
Description copied from interface:IDatabaseTranslator
Compose a select statement to obtain the next value from the named sequence- Specified by:
selectSequenceNextValue
in interfaceIDatabaseTranslator
- Returns:
-
currentTimestampString
public String currentTimestampString()
Description copied from interface:IDatabaseTranslator
Get the "CURRENT TIMESTAMP" string for the database type- Specified by:
currentTimestampString
in interfaceIDatabaseTranslator
- Returns:
-
dropForeignKeyConstraint
public String dropForeignKeyConstraint(String qualifiedTableName, String constraintName)
Description copied from interface:IDatabaseTranslator
Generate the DDL for dropping the named FK constraint from the given table- Specified by:
dropForeignKeyConstraint
in interfaceIDatabaseTranslator
- Parameters:
qualifiedTableName
- such as schema.foo_tabconstraintName
- the constraint name of the FK- Returns:
-
nextValue
public String nextValue(String schemaName, String sequenceName)
Description copied from interface:IDatabaseTranslator
Statement for getting the next value (for use in a select list or insert values)- Specified by:
nextValue
in interfaceIDatabaseTranslator
- Returns:
-
limit
public String limit(String arg)
Description copied from interface:IDatabaseTranslator
Get the correct LIMIT/FETCH NEXT ROWS clause for the database- Specified by:
limit
in interfaceIDatabaseTranslator
- Parameters:
arg
- a literal int or ? bind-variable marker- Returns:
-
-