Class DerbyTranslator
- java.lang.Object
-
- org.linuxforhealth.fhir.database.utils.derby.DerbyTranslator
-
- All Implemented Interfaces:
IDatabaseTranslator
- Direct Known Subclasses:
DerbyNetworkTranslator
public class DerbyTranslator extends java.lang.Object implements IDatabaseTranslator
translates database access to Derby supported access.
-
-
Constructor Summary
Constructors Constructor Description DerbyTranslator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringaddForUpdate(java.lang.String sql)Append FOR UPDATE/FOR UPDATE WITH RS depending on the target DB typebooleanclobSupportsInline()Does the database support inlining for clobsjava.lang.StringcreateGlobalTempTable(java.lang.String ddl)java.lang.StringcreateSequence(java.lang.String name, int cache)Craft the DDL for a CREATE SEQUENCE statementjava.lang.StringcurrentTimestampString()Get the "CURRENT TIMESTAMP" string for the database typejava.lang.StringdropForeignKeyConstraint(java.lang.String qualifiedTableName, java.lang.String constraintName)Generate the DDL for dropping the named FK constraint from the given tablejava.lang.StringdropView(java.lang.String qualifiedViewName)Generate the DDL for dropping the named viewjava.lang.StringdualTableName()The name of the "DUAL" table...that special table giving us one row/column.voidfillProperties(java.util.Properties p, ConnectionDetails cd)Configure the properties using information from the ConnectionDetailsjava.lang.StringgetDriverClassName()Get the driver class to use for connectionsDbTypegetType()The main type of the databasejava.lang.StringgetUrl(java.util.Properties connectionProperties)Get the JDBC connection URL based on the propertiesjava.lang.StringglobalTempTableName(java.lang.String tableName)Get the proper table name based on the type of database we are connected to.booleanisAlreadyExists(java.sql.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(java.sql.SQLException x)Returns true if the exception represents a connection errorbooleanisDeadlock(java.sql.SQLException x)Was this statement the victim of a deadlockbooleanisDerby()Are we working with a Derby databasebooleanisDuplicate(java.sql.SQLException x)Check the exception to see if it is reporting a duplicate value constraint violationbooleanisFamilyPostgreSQL()True if the database type is part of the PostgreSQL family (POSTGRESQL, CITUS)booleanisLockTimeout(java.sql.SQLException x)Database timed out waiting to get a lock.booleanisUndefinedName(java.sql.SQLException x)Returns true if the SQLException is indicating an object is undefined (e.g.java.lang.Stringlimit(java.lang.String arg)Get the correct LIMIT/FETCH NEXT ROWS clause for the databasejava.lang.StringnextValue(java.lang.String schemaName, java.lang.String sequenceName)Statement for getting the next value (for use in a select list or insert values)java.lang.Stringpagination(int offset, int rowsPerPage)Construct a pagination clause specific to the type of databasejava.lang.StringreorgTableCommand(java.lang.String tableName)Return the REORG TABLE command if supported, or null otherwisejava.lang.StringselectSequenceNextValue(java.lang.String schemaName, java.lang.String sequenceName)Compose a select statement to obtain the next value from the named sequencejava.lang.StringtimestampDiff(java.lang.String left, java.lang.String right, java.lang.String alias)Returns an expression which computes the timestamp difference between left and right in secondsDataAccessExceptiontranslate(java.sql.SQLException x)Get an appropriate instance of ReplicatorException to throw depending on the details of SQLException-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.linuxforhealth.fhir.database.utils.api.IDatabaseTranslator
isIndexUseSchemaPrefix, maximumQueryParameters
-
-
-
-
Method Detail
-
addForUpdate
public java.lang.String addForUpdate(java.lang.String sql)
Description copied from interface:IDatabaseTranslatorAppend FOR UPDATE/FOR UPDATE WITH RS depending on the target DB type- Specified by:
addForUpdatein interfaceIDatabaseTranslator- Returns:
-
isDerby
public boolean isDerby()
Description copied from interface:IDatabaseTranslatorAre we working with a Derby database- Specified by:
isDerbyin interfaceIDatabaseTranslator- Returns:
-
globalTempTableName
public java.lang.String globalTempTableName(java.lang.String tableName)
Description copied from interface:IDatabaseTranslatorGet the proper table name based on the type of database we are connected to. Derby has its own handling of temp tables- Specified by:
globalTempTableNamein interfaceIDatabaseTranslator- Returns:
-
createGlobalTempTable
public java.lang.String createGlobalTempTable(java.lang.String ddl)
- Specified by:
createGlobalTempTablein interfaceIDatabaseTranslator- Returns:
-
isDuplicate
public boolean isDuplicate(java.sql.SQLException x)
Description copied from interface:IDatabaseTranslatorCheck the exception to see if it is reporting a duplicate value constraint violation- Specified by:
isDuplicatein interfaceIDatabaseTranslator- Returns:
-
isAlreadyExists
public boolean isAlreadyExists(java.sql.SQLException x)
Description copied from interface:IDatabaseTranslatorCheck 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:
isAlreadyExistsin interfaceIDatabaseTranslator- Returns:
-
isLockTimeout
public boolean isLockTimeout(java.sql.SQLException x)
Description copied from interface:IDatabaseTranslatorDatabase timed out waiting to get a lock. This is not the same as a deadlock, of course- Specified by:
isLockTimeoutin interfaceIDatabaseTranslator- Returns:
-
isDeadlock
public boolean isDeadlock(java.sql.SQLException x)
Description copied from interface:IDatabaseTranslatorWas this statement the victim of a deadlock- Specified by:
isDeadlockin interfaceIDatabaseTranslator- Returns:
-
isConnectionError
public boolean isConnectionError(java.sql.SQLException x)
Description copied from interface:IDatabaseTranslatorReturns true if the exception represents a connection error- Specified by:
isConnectionErrorin interfaceIDatabaseTranslator- Returns:
-
translate
public DataAccessException translate(java.sql.SQLException x)
Description copied from interface:IDatabaseTranslatorGet an appropriate instance of ReplicatorException to throw depending on the details of SQLException- Specified by:
translatein interfaceIDatabaseTranslator- Returns:
-
isUndefinedName
public boolean isUndefinedName(java.sql.SQLException x)
Description copied from interface:IDatabaseTranslatorReturns 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:
isUndefinedNamein interfaceIDatabaseTranslator- Returns:
-
fillProperties
public void fillProperties(java.util.Properties p, ConnectionDetails cd)Description copied from interface:IDatabaseTranslatorConfigure the properties using information from the ConnectionDetails- Specified by:
fillPropertiesin interfaceIDatabaseTranslator
-
timestampDiff
public java.lang.String timestampDiff(java.lang.String left, java.lang.String right, java.lang.String alias)Description copied from interface:IDatabaseTranslatorReturns an expression which computes the timestamp difference between left and right in seconds- Specified by:
timestampDiffin interfaceIDatabaseTranslatoralias- adds " AS alias " if alias is not null- Returns:
-
createSequence
public java.lang.String createSequence(java.lang.String name, int cache)Description copied from interface:IDatabaseTranslatorCraft the DDL for a CREATE SEQUENCE statement- Specified by:
createSequencein interfaceIDatabaseTranslatorcache- the number of sequence values to cache, if supported by the database- Returns:
-
reorgTableCommand
public java.lang.String reorgTableCommand(java.lang.String tableName)
Description copied from interface:IDatabaseTranslatorReturn the REORG TABLE command if supported, or null otherwise- Specified by:
reorgTableCommandin interfaceIDatabaseTranslator- Returns:
-
getDriverClassName
public java.lang.String getDriverClassName()
Description copied from interface:IDatabaseTranslatorGet the driver class to use for connections- Specified by:
getDriverClassNamein interfaceIDatabaseTranslator- Returns:
-
getUrl
public java.lang.String getUrl(java.util.Properties connectionProperties)
Description copied from interface:IDatabaseTranslatorGet the JDBC connection URL based on the properties- Specified by:
getUrlin interfaceIDatabaseTranslator- Returns:
-
clobSupportsInline
public boolean clobSupportsInline()
Description copied from interface:IDatabaseTranslatorDoes the database support inlining for clobs- Specified by:
clobSupportsInlinein interfaceIDatabaseTranslator- Returns:
-
getType
public DbType getType()
Description copied from interface:IDatabaseTranslatorThe main type of the database- Specified by:
getTypein interfaceIDatabaseTranslator- Returns:
-
dualTableName
public java.lang.String dualTableName()
Description copied from interface:IDatabaseTranslatorThe name of the "DUAL" table...that special table giving us one row/column.- Specified by:
dualTableNamein interfaceIDatabaseTranslator- Returns:
- the name of the "DUAL" table for the database, or null if not supported
-
selectSequenceNextValue
public java.lang.String selectSequenceNextValue(java.lang.String schemaName, java.lang.String sequenceName)Description copied from interface:IDatabaseTranslatorCompose a select statement to obtain the next value from the named sequence- Specified by:
selectSequenceNextValuein interfaceIDatabaseTranslator- Returns:
-
currentTimestampString
public java.lang.String currentTimestampString()
Description copied from interface:IDatabaseTranslatorGet the "CURRENT TIMESTAMP" string for the database type- Specified by:
currentTimestampStringin interfaceIDatabaseTranslator- Returns:
-
dropForeignKeyConstraint
public java.lang.String dropForeignKeyConstraint(java.lang.String qualifiedTableName, java.lang.String constraintName)Description copied from interface:IDatabaseTranslatorGenerate the DDL for dropping the named FK constraint from the given table- Specified by:
dropForeignKeyConstraintin interfaceIDatabaseTranslator- Parameters:
qualifiedTableName- such as schema.foo_tabconstraintName- the constraint name of the FK- Returns:
-
dropView
public java.lang.String dropView(java.lang.String qualifiedViewName)
Description copied from interface:IDatabaseTranslatorGenerate the DDL for dropping the named view- Specified by:
dropViewin interfaceIDatabaseTranslator- Returns:
-
nextValue
public java.lang.String nextValue(java.lang.String schemaName, java.lang.String sequenceName)Description copied from interface:IDatabaseTranslatorStatement for getting the next value (for use in a select list or insert values)- Specified by:
nextValuein interfaceIDatabaseTranslator- Returns:
-
limit
public java.lang.String limit(java.lang.String arg)
Description copied from interface:IDatabaseTranslatorGet the correct LIMIT/FETCH NEXT ROWS clause for the database- Specified by:
limitin interfaceIDatabaseTranslator- Parameters:
arg- a literal int or ? bind-variable marker- Returns:
-
pagination
public java.lang.String pagination(int offset, int rowsPerPage)Description copied from interface:IDatabaseTranslatorConstruct a pagination clause specific to the type of database- Specified by:
paginationin interfaceIDatabaseTranslator- Parameters:
offset- the row offsetrowsPerPage- limit the number of rows returned (from the offset)- Returns:
-
isFamilyPostgreSQL
public boolean isFamilyPostgreSQL()
Description copied from interface:IDatabaseTranslatorTrue if the database type is part of the PostgreSQL family (POSTGRESQL, CITUS)- Specified by:
isFamilyPostgreSQLin interfaceIDatabaseTranslator- Returns:
-
-