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 class
AbstractDBInfo.BooleanColumnValueConvertorFactory
class
AbstractDBInfo.BooleanValueColumnConvertor
static interface
AbstractDBInfo.ColumnValueConvertor
static interface
AbstractDBInfo.ColumnValueConvertorFactory
static class
AbstractDBInfo.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.String
cartEnvironment
protected 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 void
addSQLWriter(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.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.boolean
convertNamesToLowerCase()
Informs whether used DB platform uses lower case for names.boolean
convertNamesToUpperCase()
Informs whether used DB platform uses upper case for names.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.protected org.springframework.jdbc.support.lob.LobHandler
createLobHandler()
java.lang.String
fixNativeType(java.lang.String nativeType)
Convert the native type to its correct form (adjust for Oracle quirks!).java.lang.String
getCartridgeOwner()
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.String
getDBIdentifierQuoteString()
Get the identifier needed to quote identifiers (e..g column names) for this DB.DBType
getDBType()
java.lang.String
getDeleteRuleAction(int actionCode)
Returns a string representation of the action code for delete rule in a FK.java.lang.String
getJChemCartServerJChemTableVersion()
Get the index version number used by the cartridge.java.lang.String
getJChemCartServerJChemVersion()
Get the JChem version number used by the cartridge.org.springframework.jdbc.support.lob.LobHandler
getLobHandler()
int
getMaxColumnNameLength()
Retrieves the maximum number of characters this database allows for a column name.int
getMaxElementsInList()
int
getMaxIndexNameLength()
Retrieves the maximum number of characters this database allows for a index name.int
getMaxTableNameLength()
Retrieves the maximum number of characters this database allows in a table name.SQLWriter
getSQLWriter()
java.util.Set<DBDatabaseInfo.DatabaseOperation>
getUnsupportedDatabaseOperations()
java.lang.String
getUpdateRuleAction(int actionCode)
Returns a string representation of the action code for update rule in a FK.java.lang.Integer
isCartridgeJChemTableVersionCurrent()
Compare the table version used by the cartridge to the one used by JChem.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.static java.lang.String[]
lookupArrayValues(java.util.Properties props, java.lang.String key)
DBDatabaseInfo.NativeType
nativeType(int jdbcType, java.lang.String suppliedType)
Create a native type.DBDatabaseInfo.NativeType
nativeType(int jdbcType, java.lang.String suppliedType, int size)
Create a native type.DBDatabaseInfo.NativeType
nativeType(int jdbcType, java.lang.String suppliedType, int size, int scale)
Create the native type for these settings.DBDatabaseInfo.NativeType
nativeType(java.lang.String nativeColumnType)
Create the NativeType for the specified column type.protected static void
registerJdbcType(int jdbcType, java.lang.String sqlType)
boolean
requiresNotNullDefault()
Determines if it is legal to declare a column NOT NULL while giving no default value.boolean
requiresNotNullDefault(DBDatabaseInfo.ColumnSQLType type)
Determines if it is legal to declare a column NOT NULL while giving no default value.boolean
requiresNotNullFK()
Determines, if the columns participating in FK must be NOT NULL.boolean
requiresNotNullUnique()
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()
boolean
supportsOperation(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:DBDatabaseInfo
Get the identifier needed to quote identifiers (e..g column names) for this DB.- Specified by:
getDBIdentifierQuoteString
in interfaceDBDatabaseInfo
-
getDBType
public DBType getDBType()
- Specified by:
getDBType
in 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:
supportsOperation
in interfaceDBDatabaseInfo
- Returns:
- True.
-
getUnsupportedDatabaseOperations
public java.util.Set<DBDatabaseInfo.DatabaseOperation> getUnsupportedDatabaseOperations()
- Specified by:
getUnsupportedDatabaseOperations
in interfaceDBDatabaseInfo
-
supportedIndexTypes
public java.lang.String[] supportedIndexTypes()
- Specified by:
supportedIndexTypes
in interfaceDBDatabaseInfo
-
getMaxElementsInList
public int getMaxElementsInList()
- Specified by:
getMaxElementsInList
in interfaceDBDatabaseInfo
-
getMaxTableNameLength
public int getMaxTableNameLength()
Description copied from interface:DBDatabaseInfo
Retrieves the maximum number of characters this database allows in a table name.- Specified by:
getMaxTableNameLength
in interfaceDBDatabaseInfo
-
getMaxColumnNameLength
public int getMaxColumnNameLength()
Description copied from interface:DBDatabaseInfo
Retrieves the maximum number of characters this database allows for a column name.- Specified by:
getMaxColumnNameLength
in interfaceDBDatabaseInfo
-
getMaxIndexNameLength
public int getMaxIndexNameLength()
Description copied from interface:DBDatabaseInfo
Retrieves the maximum number of characters this database allows for a index name.- Specified by:
getMaxIndexNameLength
in interfaceDBDatabaseInfo
-
getCartridgeOwner
public java.lang.String getCartridgeOwner()
Description copied from interface:DBDatabaseInfo
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.- Specified by:
getCartridgeOwner
in 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:
getJChemCartServerJChemVersion
in 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:
getJChemCartServerJChemTableVersion
in 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:
isCartridgeJChemVersionCurrent
in 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:
isCartridgeJChemTableVersionCurrent
in 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:
nativeType
in 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:DBDatabaseInfo
Create a native type. Length and scale will be set to zero as they are unspecified.- Specified by:
nativeType
in 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:DBDatabaseInfo
Create a native type. Scale is not defined.- Specified by:
nativeType
in interfaceDBDatabaseInfo
- Parameters:
jdbcType
- (@link java.sql.Types}suppliedType
- The name of native type nameDBDatabaseInfo.ColumnSQLType
size
- 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:
nativeType
in interfaceDBDatabaseInfo
- Parameters:
jdbcType
- (@link java.sql.Types}suppliedType
- The name of native type nameDBDatabaseInfo.ColumnSQLType
size
- 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:
availableNativeTypesForColumnType
in 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:DBDatabaseInfo
Determines if it is legal to declare a column NOT NULL while giving no default value. Database platform dependent.- Specified by:
requiresNotNullDefault
in 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:
requiresNotNullDefault
in interfaceDBDatabaseInfo
- Parameters:
type
-
-
requiresNotNullFK
public boolean requiresNotNullFK()
Determines, if the columns participating in FK must be NOT NULL.- Specified by:
requiresNotNullFK
in 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:
requiresNotNullUnique
in interfaceDBDatabaseInfo
- Returns:
- True, if a field participating in UNIQUE constraint must be NOT NULL
-
supportedForeignKeyOnDeleteValues
public java.lang.String[] supportedForeignKeyOnDeleteValues()
- Specified by:
supportedForeignKeyOnDeleteValues
in interfaceDBDatabaseInfo
-
supportedForeignKeyOnUpdateValues
public java.lang.String[] supportedForeignKeyOnUpdateValues()
- Specified by:
supportedForeignKeyOnUpdateValues
in 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:
getUpdateRuleAction
in 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:
getDeleteRuleAction
in 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:
fixNativeType
in 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:
convertAndWriteVariable
in 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:
createBindVariable
in interfaceDBDatabaseInfo
-
getSQLWriter
public SQLWriter getSQLWriter()
- Specified by:
getSQLWriter
in interfaceDBDatabaseInfo
-
addSQLWriter
protected void addSQLWriter(DBDatabaseInfo.ColumnSQLType colType, SQLWriter.SQLValueWriter writer)
-
getLobHandler
public org.springframework.jdbc.support.lob.LobHandler getLobHandler()
- Specified by:
getLobHandler
in interfaceDBDatabaseInfo
-
createLobHandler
protected org.springframework.jdbc.support.lob.LobHandler createLobHandler()
-
convertNamesToUpperCase
public boolean convertNamesToUpperCase()
Description copied from interface:DBDatabaseInfo
Informs whether used DB platform uses upper case for names.- Specified by:
convertNamesToUpperCase
in interfaceDBDatabaseInfo
- Returns:
true
if db platform defines propertymetadata-convertNamesToUpperCase
and that property is set to "true" (ignoring case). Otherwise returnsfalse
.
-
convertNamesToLowerCase
public boolean convertNamesToLowerCase()
Description copied from interface:DBDatabaseInfo
Informs whether used DB platform uses lower case for names.- Specified by:
convertNamesToLowerCase
in interfaceDBDatabaseInfo
- Returns:
true
if db platform defines propertymetadata-convertNamesToLowerCase
and that property is set to "true" (ignoring case). Otherwise returnsfalse
.
-
-