Package com.im.commons.db.ddl
Class AbstractDBInfo
- java.lang.Object
-
- com.im.commons.db.ddl.AbstractDBInfo
-
- All Implemented Interfaces:
DBDatabaseInfo,java.io.Serializable
public abstract class AbstractDBInfo extends java.lang.Object implements DBDatabaseInfo
- Author:
- Tim Dudgeon
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classAbstractDBInfo.BooleanColumnValueConvertorFactoryclassAbstractDBInfo.BooleanValueColumnConvertorstatic interfaceAbstractDBInfo.ColumnValueConvertorstatic interfaceAbstractDBInfo.ColumnValueConvertorFactorystatic classAbstractDBInfo.PlatformNativeType-
Nested classes/interfaces inherited from interface com.im.commons.db.ddl.DBDatabaseInfo
DBDatabaseInfo.ColumnSizing, DBDatabaseInfo.ColumnSQLType, DBDatabaseInfo.DatabaseOperation, DBDatabaseInfo.NativeType, DBDatabaseInfo.PKType, DBDatabaseInfo.ResizingSupported
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringcartEnvironmentprotected java.util.Set<DBDatabaseInfo.DatabaseOperation>unsupportedDatabaseOperations-
Fields inherited from interface com.im.commons.db.ddl.DBDatabaseInfo
ARRAY, BIGINT, BINARY, BIT, BLOB, BOOLEAN, CART_PROP_JChemPropertiesTable, CART_PROP_TableType, CHAR, CLOB, DATALINK, DATE, DECIMAL, DEFAULT_JCHEMPROPERTIES_TABLE_NAME, DISTINCT, DOUBLE, FLOAT, INDEX_UNIQUE, INT, INTEGER, JAVA_OBJECT, LONGVARBINARY, LONGVARCHAR, NCHAR, NULL, NUMBER, NUMERIC, NVARCHAR, NVARCHAR2, OTHER, REAL, REF, ROWID, SMALLINT, STRUCT, TIME, TIMESTAMP, TINYINT, VARBINARY, VARCHAR, VARCHAR2
-
-
Constructor Summary
Constructors Constructor Description AbstractDBInfo(DBType dbType, java.lang.String dbIdentifierQuoteString)AbstractDBInfo(DBType dbType, java.lang.String dbIdentifierQuoteString, java.lang.String cartOwner, java.lang.String cartEnv)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddSQLWriter(DBDatabaseInfo.ColumnSQLType colType, SQLWriter.SQLValueWriter writer)DBDatabaseInfo.NativeType[]availableNativeTypesForColumnType(java.lang.String columnType)Get the native types that this platform supports for this particular column type.java.lang.StringconvertAndWriteVariable(java.lang.String clsName, DBDatabaseInfo.ColumnSQLType columnType, java.lang.Object var)Write this variable as a String so that it can be used in a DDL or DML statement.booleanconvertNamesToLowerCase()Informs whether used DB platform uses lower case for names.booleanconvertNamesToUpperCase()Informs whether used DB platform uses upper case for names.java.lang.ObjectcreateBindVariable(java.lang.String clsName, DBDatabaseInfo.ColumnSQLType columnType, java.lang.Object var)create a bind variable that can be used in a PreparedStatment.protected org.springframework.jdbc.support.lob.LobHandlercreateLobHandler()java.lang.StringfixNativeType(java.lang.String nativeType)Convert the native type to its correct form (adjust for Oracle quirks!).java.lang.StringgetCartridgeOwner()Get the user who owns the cartridge functions, or null if the DB does not support the JChem cartridge or the cartridge is not installed.java.lang.StringgetDBIdentifierQuoteString()Get the identifier needed to quote identifiers (e..g column names) for this DB.DBTypegetDBType()java.lang.StringgetDeleteRuleAction(int actionCode)Returns a string representation of the action code for delete rule in a FK.java.lang.StringgetJChemCartServerJChemTableVersion()Get the index version number used by the cartridge.java.lang.StringgetJChemCartServerJChemVersion()Get the JChem version number used by the cartridge.org.springframework.jdbc.support.lob.LobHandlergetLobHandler()intgetMaxColumnNameLength()Retrieves the maximum number of characters this database allows for a column name.intgetMaxElementsInList()intgetMaxIndexNameLength()Retrieves the maximum number of characters this database allows for a index name.intgetMaxTableNameLength()Retrieves the maximum number of characters this database allows in a table name.SQLWritergetSQLWriter()java.util.Set<DBDatabaseInfo.DatabaseOperation>getUnsupportedDatabaseOperations()java.lang.StringgetUpdateRuleAction(int actionCode)Returns a string representation of the action code for update rule in a FK.java.lang.IntegerisCartridgeJChemTableVersionCurrent()Compare the table version used by the cartridge to the one used by JChem.java.lang.IntegerisCartridgeJChemVersionCurrent()Compare the JChem version to the JChem cartridge to the one used by the JChem version that is being used here.static java.lang.String[]lookupArrayValues(java.util.Properties props, java.lang.String key)DBDatabaseInfo.NativeTypenativeType(int jdbcType, java.lang.String suppliedType)Create a native type.DBDatabaseInfo.NativeTypenativeType(int jdbcType, java.lang.String suppliedType, int size)Create a native type.DBDatabaseInfo.NativeTypenativeType(int jdbcType, java.lang.String suppliedType, int size, int scale)Create the native type for these settings.DBDatabaseInfo.NativeTypenativeType(java.lang.String nativeColumnType)Create the NativeType for the specified column type.protected static voidregisterJdbcType(int jdbcType, java.lang.String sqlType)booleanrequiresNotNullDefault()Determines if it is legal to declare a column NOT NULL while giving no default value.booleanrequiresNotNullDefault(DBDatabaseInfo.ColumnSQLType type)Determines if it is legal to declare a column NOT NULL while giving no default value.booleanrequiresNotNullFK()Determines, if the columns participating in FK must be NOT NULL.booleanrequiresNotNullUnique()Determines, if the DB requires a NOT NULL constraint before an UQ can be created for the field.java.lang.String[]supportedForeignKeyOnDeleteValues()java.lang.String[]supportedForeignKeyOnUpdateValues()java.lang.String[]supportedIndexTypes()booleansupportsOperation(DBDatabaseInfo.DatabaseOperation op)Is this operation supported by the database.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.im.commons.db.ddl.DBDatabaseInfo
isSupportsSchemas, prepareDefaultFromDatabaseMetadata
-
-
-
-
Field Detail
-
unsupportedDatabaseOperations
protected final java.util.Set<DBDatabaseInfo.DatabaseOperation> unsupportedDatabaseOperations
-
cartEnvironment
protected final java.lang.String cartEnvironment
-
-
Method Detail
-
registerJdbcType
protected static void registerJdbcType(int jdbcType, java.lang.String sqlType)
-
getDBIdentifierQuoteString
public java.lang.String getDBIdentifierQuoteString()
Description copied from interface:DBDatabaseInfoGet the identifier needed to quote identifiers (e..g column names) for this DB.- Specified by:
getDBIdentifierQuoteStringin interfaceDBDatabaseInfo
-
getDBType
public DBType getDBType()
- Specified by:
getDBTypein interfaceDBDatabaseInfo
-
supportsOperation
public boolean supportsOperation(DBDatabaseInfo.DatabaseOperation op)
Is this operation supported by the database. To mark an operation as not supported subclasses should add it to the unsupportedDatabaseOperations Set;- Specified by:
supportsOperationin interfaceDBDatabaseInfo- Returns:
- True.
-
getUnsupportedDatabaseOperations
public java.util.Set<DBDatabaseInfo.DatabaseOperation> getUnsupportedDatabaseOperations()
- Specified by:
getUnsupportedDatabaseOperationsin interfaceDBDatabaseInfo
-
supportedIndexTypes
public java.lang.String[] supportedIndexTypes()
- Specified by:
supportedIndexTypesin interfaceDBDatabaseInfo
-
getMaxElementsInList
public int getMaxElementsInList()
- Specified by:
getMaxElementsInListin interfaceDBDatabaseInfo
-
getMaxTableNameLength
public int getMaxTableNameLength()
Description copied from interface:DBDatabaseInfoRetrieves the maximum number of characters this database allows in a table name.- Specified by:
getMaxTableNameLengthin interfaceDBDatabaseInfo
-
getMaxColumnNameLength
public int getMaxColumnNameLength()
Description copied from interface:DBDatabaseInfoRetrieves the maximum number of characters this database allows for a column name.- Specified by:
getMaxColumnNameLengthin interfaceDBDatabaseInfo
-
getMaxIndexNameLength
public int getMaxIndexNameLength()
Description copied from interface:DBDatabaseInfoRetrieves the maximum number of characters this database allows for a index name.- Specified by:
getMaxIndexNameLengthin interfaceDBDatabaseInfo
-
getCartridgeOwner
public java.lang.String getCartridgeOwner()
Description copied from interface:DBDatabaseInfoGet the user who owns the cartridge functions, or null if the DB does not support the JChem cartridge or the cartridge is not installed.- Specified by:
getCartridgeOwnerin interfaceDBDatabaseInfo- Returns:
- The owner
-
getJChemCartServerJChemVersion
public java.lang.String getJChemCartServerJChemVersion()
Get the JChem version number used by the cartridge. e.g. 5.1.1. If the cart is not present then null will be returned.- Specified by:
getJChemCartServerJChemVersionin interfaceDBDatabaseInfo- Returns:
- The JChem version
-
getJChemCartServerJChemTableVersion
public java.lang.String getJChemCartServerJChemTableVersion()
Get the index version number used by the cartridge. This is the same as the JChem table version. e.g. 50102 This is only available since JChem 5.1.2. If prior to this, or the cart is not present then null is returned. Note that this is related to the JChem version but the table version is not increased with every JChem version, so it may lag a version or two behind.- Specified by:
getJChemCartServerJChemTableVersionin interfaceDBDatabaseInfo- Returns:
- The cartridge JChem table version
-
isCartridgeJChemVersionCurrent
public java.lang.Integer isCartridgeJChemVersionCurrent()
Compare the JChem version to the JChem cartridge to the one used by the JChem version that is being used here.- Specified by:
isCartridgeJChemVersionCurrentin interfaceDBDatabaseInfo- Returns:
- 0 if the JChem version is the same, a negative number if the cartridge version is older than the one in use, a positive number if it is newer, and null if the cart is not enabled
-
isCartridgeJChemTableVersionCurrent
public java.lang.Integer isCartridgeJChemTableVersionCurrent()
Compare the table version used by the cartridge to the one used by JChem. If the table version is not available (older JChem versions), or cannot be recognised then the JChem versions are compared.- Specified by:
isCartridgeJChemTableVersionCurrentin interfaceDBDatabaseInfo- Returns:
- 0 if the table versions are the same, a negative number if the cartridge version is older than the one in use in the local jchem.jar, a positive number if the cartridge version is newer, and null if the cart is not enabled.
-
nativeType
public DBDatabaseInfo.NativeType nativeType(java.lang.String nativeColumnType)
Create the NativeType for the specified column type.- Specified by:
nativeTypein interfaceDBDatabaseInfo- Parameters:
nativeColumnType- The actual column definition in the database e.g. VARCHAR2, FLOAT... The JDBC type, length and scale will be set to zero as they are unspecified.
-
nativeType
public final DBDatabaseInfo.NativeType nativeType(int jdbcType, java.lang.String suppliedType)
Description copied from interface:DBDatabaseInfoCreate a native type. Length and scale will be set to zero as they are unspecified.- Specified by:
nativeTypein interfaceDBDatabaseInfo- Parameters:
jdbcType- (@link java.sql.Types}suppliedType- The name of native type nameDBDatabaseInfo.ColumnSQLType
-
nativeType
public final DBDatabaseInfo.NativeType nativeType(int jdbcType, java.lang.String suppliedType, int size)
Description copied from interface:DBDatabaseInfoCreate a native type. Scale is not defined.- Specified by:
nativeTypein interfaceDBDatabaseInfo- Parameters:
jdbcType- (@link java.sql.Types}suppliedType- The name of native type nameDBDatabaseInfo.ColumnSQLTypesize- The size of the type
-
nativeType
public DBDatabaseInfo.NativeType nativeType(int jdbcType, java.lang.String suppliedType, int size, int scale)
Create the native type for these settings. If the suppliedType is not specified then a "best guess" will be used.- Specified by:
nativeTypein interfaceDBDatabaseInfo- Parameters:
jdbcType- (@link java.sql.Types}suppliedType- The name of native type nameDBDatabaseInfo.ColumnSQLTypesize- The size of the typescale- The scale of the type
-
availableNativeTypesForColumnType
public DBDatabaseInfo.NativeType[] availableNativeTypesForColumnType(java.lang.String columnType)
Get the native types that this platform supports for this particular column type.- Specified by:
availableNativeTypesForColumnTypein interfaceDBDatabaseInfo- Parameters:
columnType- The generic type of the column (TEXT, INTEGER) defined by the constants in DBDatabaseInfo.ColumnBoundTypes- Returns:
- An array of compatible column native types
-
requiresNotNullDefault
public boolean requiresNotNullDefault()
Description copied from interface:DBDatabaseInfoDetermines if it is legal to declare a column NOT NULL while giving no default value. Database platform dependent.- Specified by:
requiresNotNullDefaultin interfaceDBDatabaseInfo- Returns:
- True, if the default value is required, false otherwise
-
requiresNotNullDefault
public boolean requiresNotNullDefault(DBDatabaseInfo.ColumnSQLType type)
Determines if it is legal to declare a column NOT NULL while giving no default value. It is not database platform dependent. It is an application logic.- Specified by:
requiresNotNullDefaultin interfaceDBDatabaseInfo- Parameters:
type-
-
requiresNotNullFK
public boolean requiresNotNullFK()
Determines, if the columns participating in FK must be NOT NULL.- Specified by:
requiresNotNullFKin interfaceDBDatabaseInfo- Returns:
- True, if the column must be NOT NULL before FK to it can be made
-
requiresNotNullUnique
public boolean requiresNotNullUnique()
Determines, if the DB requires a NOT NULL constraint before an UQ can be created for the field.- Specified by:
requiresNotNullUniquein interfaceDBDatabaseInfo- Returns:
- True, if a field participating in UNIQUE constraint must be NOT NULL
-
supportedForeignKeyOnDeleteValues
public java.lang.String[] supportedForeignKeyOnDeleteValues()
- Specified by:
supportedForeignKeyOnDeleteValuesin interfaceDBDatabaseInfo
-
supportedForeignKeyOnUpdateValues
public java.lang.String[] supportedForeignKeyOnUpdateValues()
- Specified by:
supportedForeignKeyOnUpdateValuesin interfaceDBDatabaseInfo
-
getUpdateRuleAction
public java.lang.String getUpdateRuleAction(int actionCode)
Returns a string representation of the action code for update rule in a FK.- Specified by:
getUpdateRuleActionin interfaceDBDatabaseInfo- Parameters:
actionCode- The action code- Returns:
- The string representation of the action code
-
getDeleteRuleAction
public java.lang.String getDeleteRuleAction(int actionCode)
Returns a string representation of the action code for delete rule in a FK.- Specified by:
getDeleteRuleActionin interfaceDBDatabaseInfo- Parameters:
actionCode- The action code- Returns:
- The string representation of the action code
-
fixNativeType
public java.lang.String fixNativeType(java.lang.String nativeType)
Convert the native type to its correct form (adjust for Oracle quirks!).- Specified by:
fixNativeTypein interfaceDBDatabaseInfo- Parameters:
nativeType-- Returns:
- The corrected native type
-
lookupArrayValues
public static java.lang.String[] lookupArrayValues(java.util.Properties props, java.lang.String key)
-
convertAndWriteVariable
public java.lang.String convertAndWriteVariable(java.lang.String clsName, DBDatabaseInfo.ColumnSQLType columnType, java.lang.Object var)Write this variable as a String so that it can be used in a DDL or DML statement.- Specified by:
convertAndWriteVariablein interfaceDBDatabaseInfo
-
createBindVariable
public java.lang.Object createBindVariable(java.lang.String clsName, DBDatabaseInfo.ColumnSQLType columnType, java.lang.Object var)create a bind variable that can be used in a PreparedStatment.- Specified by:
createBindVariablein interfaceDBDatabaseInfo
-
getSQLWriter
public SQLWriter getSQLWriter()
- Specified by:
getSQLWriterin interfaceDBDatabaseInfo
-
addSQLWriter
protected void addSQLWriter(DBDatabaseInfo.ColumnSQLType colType, SQLWriter.SQLValueWriter writer)
-
getLobHandler
public org.springframework.jdbc.support.lob.LobHandler getLobHandler()
- Specified by:
getLobHandlerin interfaceDBDatabaseInfo
-
createLobHandler
protected org.springframework.jdbc.support.lob.LobHandler createLobHandler()
-
convertNamesToUpperCase
public boolean convertNamesToUpperCase()
Description copied from interface:DBDatabaseInfoInforms whether used DB platform uses upper case for names.- Specified by:
convertNamesToUpperCasein interfaceDBDatabaseInfo- Returns:
trueif db platform defines propertymetadata-convertNamesToUpperCaseand that property is set to "true" (ignoring case). Otherwise returnsfalse.
-
convertNamesToLowerCase
public boolean convertNamesToLowerCase()
Description copied from interface:DBDatabaseInfoInforms whether used DB platform uses lower case for names.- Specified by:
convertNamesToLowerCasein interfaceDBDatabaseInfo- Returns:
trueif db platform defines propertymetadata-convertNamesToLowerCaseand that property is set to "true" (ignoring case). Otherwise returnsfalse.
-
-