com.im.commons.db 5.9.2

com.im.commons.db
Interface DatabasePlatform

All Known Subinterfaces:
DatabasePlatformX
All Known Implementing Classes:
AbstractDatabasePlatform

public interface DatabasePlatform


Field Summary
static String IJC_SCHEMA_OTHER_TABLE_NAME
           
static String NAME_PRIMARY_KEY_CONSTRAINT
          Marker for a constraint that enforces the primary key.
 
Method Summary
 DBColInfo buildColumnInfoForColumn(String dbSchemaName, String tableName, String columnName)
          Build the DBColInfos for the particlaar column.
 List<DBColInfo> buildColumnInfosForTable(String dbSchemaName, String tableName)
          Build the DBColInfos for the table.
 List<DBConstraintInfo> buildConstraintInfosForTable(String dbSchemaName, String tableName, List<DBColInfo> cols)
          Retrieves unique constraints declared for the table.
 List<DBForeignKeyInfo> buildExportedForeignKeyInfoForTable(String schemaName, String tableName)
          Build exported foreign key info
 List<DBForeignKeyInfo> buildImportedForeignKeyInfoForTable(String schemaName, String tableName)
          Build imported foreign key info
 List<DBIndexInfo> buildIndexInfoForTable(String schemaName, String tableName)
          Build index info for the specified table
 Set<String> buildJChemPropertyTableNames()
           
 List<DBSequenceInfo> buildSequenceInfo(String schema)
           
 DBSequenceInfo buildSequenceInfo(String schema, String seqName)
           
 DBTableInfo buildTableInfo(String schema, String table, LazyLoader lazyLoader, DFFeedback feedback)
          Build the full table info for this table.
 DBTableInfo buildTableInfoFull(String schema, String table, LazyLoader lazyLoader, DFFeedback feedback)
           
 Map<String,DBTableInfo> buildTableInfos(String schema, List<String> tablesToInit, LazyLoader lazyLoader, DFFeedback feedback)
          Build all table infos for the specified schema
 Map<String,DBTableInfo> buildTableInfosEager(String schema, DFFeedback feedback)
           
 Map<String,DBTableInfo> buildTableInfosLazy(String schema, LazyLoader lazyLoader, DFFeedback feedback)
           
 void checkSchemaExistence(String schemaId)
          Checks whether an schema exists in the IJC metadata registry (IJC_SCHEMA table) or not also checks whether the database/ IJC_SCHEMA table exists or not.
 void executeDDL(String[] sql, boolean log)
          Execute these DDL statements
 void executeDDL(String sql, boolean log)
          Execute this DDL statement
 String getAddAuthoritySql()
           
 String getAddUserSql()
           
 DataSource getDataSource()
           
 DBDatabaseInfo getDBInfo()
           
 String getDefaultSchemaName()
           
 String getDeleteAuthoritiesSql()
           
 String getDeleteUserSql()
           
 JdbcTemplate getJdbcTemplate()
           
 LobHandler getLobHandler()
           
 Set<String> getMetaTableNames()
           
 List<String> getSchemaNames()
          Get the list of schema names that are accessible to the user.
 String getSetEnabledSql()
           
 String[] getTableNames(String schema)
          Get the table names for the specified schema
 DataSourceTransactionManager getTransactionManager()
           
 String getUpdatePasswordSql()
           
 List<String> getUsedSchemas()
          Get used schema by IJC schema
 String[] getViewNames(String schema)
          Get the view names for the specified schema
 boolean isProjectDatabase()
           
 Object readValue(ResultSet rs, String columnName, Class columnClass, int jdbcType)
          Deprecated. Use the DBValueHandler which is available from the DBFieldCapability instead.
 void shutdown()
          Default is to do nothing.
 String sqlAddColumn(String schemaPlusTable, String colName, String colClass, String nativeType, String columnDefinition, String defaultValue, boolean isNotNull)
           
 String sqlAddForeignKey(String fkName, String parentSchemaPlusTable, String dependentSchemaPlusTable, String[] parentCols, String[] dependentCols, String onDeleteRule, String onUpdateRule)
           
 String sqlAddIndex(String indexName, String indexType, String schemaPlusTable, String[] columns, boolean[] asc)
          Add an index to the table
 String sqlAddUniqueConstraint(String consName, String schemaPlusTable, String[] columns)
          Add unique constraint for some columns in the table.
 String sqlAlterColumnRequired(String schemaPlusTable, String columnName, String nativeType, String columnDefinition, String defaultValue, boolean required)
           
 String sqlCount(SchemaQualifiedName schemaPlusTable)
           
 String[] sqlCreateSecurityTables()
          Get the SQL need3ed to create the username/password tables.
 String[] sqlCreateSecurityTablesExternalConstraints()
          Constraints from the security tables to the other tables.
 String sqlCreateSequence(String schemaPlusSequenceName)
           
 String sqlCreateTable(String schemaPlusTable, List<DBDatabaseInfo.NativeType> columnDefs, List<String> columnNames)
          Creates a table with the given name and the fields.
 String sqlDeleteRow(String schemaPlusTable, String whereClause)
          Generate SQL to delete a row.
 String sqlDropForeignKey(String schemaPlusTable, String fkName)
           
 String sqlDropIndex(String schemaPlusTable, String indexName)
           
 String sqlDropPrimaryConstraint(String schemaPlusTable, String consName, String[] columns)
           
 String sqlDropSequence(String schemaPlusSequenceName)
           
 String sqlDropTable(String schemaPlusTable)
           
 String sqlDropUniqueConstraint(String schemaPlusTable, String consName, String[] columns)
           
 String sqlFullColumnDefinition(String colClass, String nativeType, String columnDefinition, String defaultValue, boolean isNotNull)
          Generate the full column definition, including the defintion of any default value and the NULL/NOT NULL.
 String sqlInsertRow(SchemaQualifiedName schemaPlusTable, List columnNames)
          Creates insert row sql for a prepared statement of the form INSERT INTO table_name (col_1, col_2...) VALUES (?,?...)
 String sqlInsertRowDefaults(SchemaQualifiedName schemaPlusTable, String[] idColumnNames)
          Creates insert row sql that inserts the default value for these columns.
 String sqlLastId(SchemaQualifiedName schemaPlusTable)
           
 String sqlNow()
          get the appropriate SQL clause for the curent time.
 String sqlRebuildIndex(String schemaPlusTable, String indexName)
           
 String sqlSelectDistinct(SchemaQualifiedName schemaPlusTable, String[] columnNames)
           
 String sqlSelectDuplicateRows(String schemaPlusTable, String[] columns)
           
 SQLSelectStatement sqlSelectInList(SchemaQualifiedName schemaPlusTable, List<SQLSelectElement> selectElements, String inClauseColName, DBDatabaseInfo.ColumnSQLType inClauseColType, Collection ids)
           
 SQLSelectStatement sqlSelectPS(SchemaQualifiedName schemaPlusTable, List<SQLSelectElement> selectElements, String idCol)
          Creates SQL for a select statement that uses a PreparedStatement.
 String[] sqlUpdateIJCViewsTable()
           
 String sqlUpdateRow(SchemaQualifiedName schemaPlusTable, String updateClause, String whereClause)
           
 String sqlUpgradeCommand(String version, String key)
           
 void start()
          Starts the platform by connecting to the database.
 DataAccessException translateSQLException(String message, String sql, SQLException ex)
           
 void updateHeartbeat(String userName, String schemaId)
          Updates when the last time user accessed the database for purpose of changing the data
 

Field Detail

IJC_SCHEMA_OTHER_TABLE_NAME

static final String IJC_SCHEMA_OTHER_TABLE_NAME
See Also:
Constant Field Values

NAME_PRIMARY_KEY_CONSTRAINT

static final String NAME_PRIMARY_KEY_CONSTRAINT
Marker for a constraint that enforces the primary key. It is not a real name; the string must be a non-identifier so it does not clash with real constraint names.

See Also:
Constant Field Values
Method Detail

getDataSource

DataSource getDataSource()

getTransactionManager

DataSourceTransactionManager getTransactionManager()

getJdbcTemplate

JdbcTemplate getJdbcTemplate()

getDBInfo

DBDatabaseInfo getDBInfo()

buildJChemPropertyTableNames

Set<String> buildJChemPropertyTableNames()

getDefaultSchemaName

String getDefaultSchemaName()
Returns:
The default schema to be used

buildTableInfo

DBTableInfo buildTableInfo(String schema,
                           String table,
                           LazyLoader lazyLoader,
                           DFFeedback feedback)
Build the full table info for this table. The table info contains all the information about the table.

Parameters:
schema - The schema in which the table resides
table - The table name
Returns:
The database table info The method can return null if the table does not exist.

buildTableInfoFull

DBTableInfo buildTableInfoFull(String schema,
                               String table,
                               LazyLoader lazyLoader,
                               DFFeedback feedback)

buildTableInfos

Map<String,DBTableInfo> buildTableInfos(String schema,
                                        List<String> tablesToInit,
                                        LazyLoader lazyLoader,
                                        DFFeedback feedback)
Build all table infos for the specified schema

Parameters:
schema -
Returns:
A map of DBTableInfos keyed by the schema qualified table/view name

buildTableInfosLazy

Map<String,DBTableInfo> buildTableInfosLazy(String schema,
                                            LazyLoader lazyLoader,
                                            DFFeedback feedback)

buildTableInfosEager

Map<String,DBTableInfo> buildTableInfosEager(String schema,
                                             DFFeedback feedback)

buildColumnInfosForTable

List<DBColInfo> buildColumnInfosForTable(String dbSchemaName,
                                         String tableName)
Build the DBColInfos for the table.

Parameters:
dbSchemaName - The schema name
tableName - The table name
Returns:
A list of DBColInfos for the table

buildColumnInfoForColumn

DBColInfo buildColumnInfoForColumn(String dbSchemaName,
                                   String tableName,
                                   String columnName)
Build the DBColInfos for the particlaar column.

Parameters:
dbSchemaName - The schema name
tableName - The table name
columnName - The column name to match
Returns:
The DBColInfo

buildIndexInfoForTable

List<DBIndexInfo> buildIndexInfoForTable(String schemaName,
                                         String tableName)
Build index info for the specified table

Parameters:
schemaName - The schema name
tableName - The table name
Returns:
The indexes for the specified table

buildExportedForeignKeyInfoForTable

List<DBForeignKeyInfo> buildExportedForeignKeyInfoForTable(String schemaName,
                                                           String tableName)
Build exported foreign key info

Parameters:
schemaName - The schema name
tableName - The table name
Returns:
The exported foreign keys

buildImportedForeignKeyInfoForTable

List<DBForeignKeyInfo> buildImportedForeignKeyInfoForTable(String schemaName,
                                                           String tableName)
Build imported foreign key info

Parameters:
schemaName - The schema name
tableName - The table name
Returns:
The imported foreign keys

getLobHandler

LobHandler getLobHandler()
Returns:
The SpringFramework LobHandler for this type of database

readValue

@Deprecated
Object readValue(ResultSet rs,
                            String columnName,
                            Class columnClass,
                            int jdbcType)
                 throws SQLException
Deprecated. Use the DBValueHandler which is available from the DBFieldCapability instead.

Read the value from the ResultSet. The DatabasePlatform method is used so that custom methods of reading the values (e.g from Blob or Clob columns) can be implemented for a particular database type

Throws:
SQLException

sqlFullColumnDefinition

String sqlFullColumnDefinition(String colClass,
                               String nativeType,
                               String columnDefinition,
                               String defaultValue,
                               boolean isNotNull)
Generate the full column definition, including the defintion of any default value and the NULL/NOT NULL. e.g. VARCHAR(100) DEFAULT 'foo' NOT NULL

Parameters:
colClass -
nativeType -
columnDefinition -
defaultValue -
isNotNull -
Returns:
The column definition

buildSequenceInfo

List<DBSequenceInfo> buildSequenceInfo(String schema)
Returns:
All the sequences

buildSequenceInfo

DBSequenceInfo buildSequenceInfo(String schema,
                                 String seqName)
Parameters:
seqName -
Returns:
The sequence with the specified name

sqlCreateSequence

String sqlCreateSequence(String schemaPlusSequenceName)

sqlDropSequence

String sqlDropSequence(String schemaPlusSequenceName)

sqlAddColumn

String sqlAddColumn(String schemaPlusTable,
                    String colName,
                    String colClass,
                    String nativeType,
                    String columnDefinition,
                    String defaultValue,
                    boolean isNotNull)

sqlUpgradeCommand

String sqlUpgradeCommand(String version,
                         String key)

sqlSelectDuplicateRows

String sqlSelectDuplicateRows(String schemaPlusTable,
                              String[] columns)

sqlDeleteRow

String sqlDeleteRow(String schemaPlusTable,
                    String whereClause)
Generate SQL to delete a row. The ? placeholder will be used for the ID(s) of the row to delete

Parameters:
schemaPlusTable - The schema and name of the table to delete from
whereClause - The "WHERE" part of the SQL delete command.
Returns:
SQL in the from of DELETE FROM <table> WHERE <col> = ? [AND <filter>]

sqlInsertRow

String sqlInsertRow(SchemaQualifiedName schemaPlusTable,
                    List columnNames)
Creates insert row sql for a prepared statement of the form INSERT INTO table_name (col_1, col_2...) VALUES (?,?...)

Parameters:
schemaPlusTable - The schema and name of the table
columnNames - The names of the columns with data
Returns:
The SQL

sqlAlterColumnRequired

String sqlAlterColumnRequired(String schemaPlusTable,
                              String columnName,
                              String nativeType,
                              String columnDefinition,
                              String defaultValue,
                              boolean required)

sqlNow

String sqlNow()
get the appropriate SQL clause for the curent time. e.g NOW(), CURRENT_TIMESTAMP() etc.

Returns:
The SQL fragment for the current time

getSchemaNames

List<String> getSchemaNames()
Get the list of schema names that are accessible to the user. If DB does not support schemas then an empty list is returned.

Returns:
The names of the schemas

getUsedSchemas

List<String> getUsedSchemas()
Get used schema by IJC schema


getTableNames

String[] getTableNames(String schema)
Get the table names for the specified schema

Parameters:
schema - The schema to look in. Should be null if the database does not support schemas
Returns:
The tables in this schema.

sqlDropTable

String sqlDropTable(String schemaPlusTable)

executeDDL

void executeDDL(String[] sql,
                boolean log)
Execute these DDL statements

Parameters:
sql - Array of SQL statements
log - Whether to log by default. Note that the user preference might overrride this.

executeDDL

void executeDDL(String sql,
                boolean log)
Execute this DDL statement

Parameters:
sql - A SQL statement
log - Whether to log by default. Note that the user preference might overrride this.

sqlCreateSecurityTables

String[] sqlCreateSecurityTables()
Get the SQL need3ed to create the username/password tables.

Returns:
An array of SQL statements needed to create all the tables, indexes, foreign keys...

sqlCreateSecurityTablesExternalConstraints

String[] sqlCreateSecurityTablesExternalConstraints()
Constraints from the security tables to the other tables. Can only be added if the other tables are present


getAddUserSql

String getAddUserSql()

getAddAuthoritySql

String getAddAuthoritySql()

getUpdatePasswordSql

String getUpdatePasswordSql()

getSetEnabledSql

String getSetEnabledSql()

getDeleteUserSql

String getDeleteUserSql()

getDeleteAuthoritiesSql

String getDeleteAuthoritiesSql()

sqlInsertRowDefaults

String sqlInsertRowDefaults(SchemaQualifiedName schemaPlusTable,
                            String[] idColumnNames)
Creates insert row sql that inserts the default value for these columns. Useful when inserting empty rows when at least one column (the PK column) has to be specified.

Parameters:
schemaPlusTable - The name of the table
idColumnNames - The names of the columns to insert the default
Returns:
The SQL

sqlSelectInList

SQLSelectStatement sqlSelectInList(SchemaQualifiedName schemaPlusTable,
                                   List<SQLSelectElement> selectElements,
                                   String inClauseColName,
                                   DBDatabaseInfo.ColumnSQLType inClauseColType,
                                   Collection ids)
Parameters:
schemaPlusTable -
selectElements - Set of elements to select
inClauseColName -
inClauseColType -
Returns:
The SQLSelectStatement

sqlSelectPS

SQLSelectStatement sqlSelectPS(SchemaQualifiedName schemaPlusTable,
                               List<SQLSelectElement> selectElements,
                               String idCol)
Creates SQL for a select statement that uses a PreparedStatement. e.g. SELECT foo, bar from baz where idCol = ?

Parameters:
schemaPlusTable - The table
selectElements - The elelement that the statement shoudl select
idCol - The column to use for the bound variable in the where clause

sqlLastId

String sqlLastId(SchemaQualifiedName schemaPlusTable)

sqlSelectDistinct

String sqlSelectDistinct(SchemaQualifiedName schemaPlusTable,
                         String[] columnNames)

sqlUpdateRow

String sqlUpdateRow(SchemaQualifiedName schemaPlusTable,
                    String updateClause,
                    String whereClause)
Parameters:
schemaPlusTable - The name of the table to update
updateClause - The values to update e.g. col1 = 'hello world', col2 = 77
whereClause - The where clause to defined the row(s) e.g. id = 999
Returns:
The SQL

sqlCount

String sqlCount(SchemaQualifiedName schemaPlusTable)

sqlAddUniqueConstraint

String sqlAddUniqueConstraint(String consName,
                              String schemaPlusTable,
                              String[] columns)
Add unique constraint for some columns in the table. Usually that will imply creation of an unique-valued index in the database.

Parameters:
consName - The c onstraint name
schemaPlusTable - The t able name
columns - The c olumns which will form the unique key. Order is important.
Returns:
SQL statement to create the unique key

sqlDropPrimaryConstraint

String sqlDropPrimaryConstraint(String schemaPlusTable,
                                String consName,
                                String[] columns)

sqlDropUniqueConstraint

String sqlDropUniqueConstraint(String schemaPlusTable,
                               String consName,
                               String[] columns)

getMetaTableNames

Set<String> getMetaTableNames()
Returns:
The names of tables, that hold the schema metadata information

shutdown

void shutdown()
Default is to do nothing. Override if something needs to be done


sqlAddForeignKey

String sqlAddForeignKey(String fkName,
                        String parentSchemaPlusTable,
                        String dependentSchemaPlusTable,
                        String[] parentCols,
                        String[] dependentCols,
                        String onDeleteRule,
                        String onUpdateRule)

sqlCreateTable

String sqlCreateTable(String schemaPlusTable,
                      List<DBDatabaseInfo.NativeType> columnDefs,
                      List<String> columnNames)
Creates a table with the given name and the fields. The list of columnDefs cannot be empty or null; the table must contain at least one column. The list of column names must be the same size as column definitions; name at index "i" will be used for column defined by definition at index "i".

Parameters:
schemaPlusTable -
columnDefs - The column definitions
columnNames - The column names
Returns:
SQL statement to create the table

buildConstraintInfosForTable

List<DBConstraintInfo> buildConstraintInfosForTable(String dbSchemaName,
                                                    String tableName,
                                                    List<DBColInfo> cols)
Retrieves unique constraints declared for the table. Returns empty list if no unique constraint exists. Also reports PRIMARY keys as unique constraints.

Parameters:
dbSchemaName - The schema and name of the table
tableName - The n ame of the table
cols - The columns in the table to look in
Returns:
List of constraints.

sqlDropForeignKey

String sqlDropForeignKey(String schemaPlusTable,
                         String fkName)

getViewNames

String[] getViewNames(String schema)
Get the view names for the specified schema

Parameters:
schema - The schema to look in. Should be null if the database does not support schemas
Returns:
The views in this schema.

translateSQLException

DataAccessException translateSQLException(String message,
                                          String sql,
                                          SQLException ex)

sqlRebuildIndex

String sqlRebuildIndex(String schemaPlusTable,
                       String indexName)

sqlDropIndex

String sqlDropIndex(String schemaPlusTable,
                    String indexName)

sqlAddIndex

String sqlAddIndex(String indexName,
                   String indexType,
                   String schemaPlusTable,
                   String[] columns,
                   boolean[] asc)
Add an index to the table

Parameters:
indexName - The name for the index.
indexType - The type of index. e.g. UNIQUE. Consult the supportedIndexTypes() method to find out which types your DB supports. Can be null for a regular index.
schemaPlusTable - The table for the index
columns - The columns
asc - Is the index for this column ascending or descending. true means ASC, false means DESC. Can be null, but if specified must have the same size as the columns Must be the same number of values as there are columns.
Returns:
The SQL for adding the index

isProjectDatabase

boolean isProjectDatabase()

start

void start()
           throws InitializationException
Starts the platform by connecting to the database. Call to catch errors early. Call shutdown() to release resources allocated by "start".

Throws:
InitializationException

sqlUpdateIJCViewsTable

String[] sqlUpdateIJCViewsTable()
Returns:
SQL statements to upgrade the IJC_Views table

checkSchemaExistence

void checkSchemaExistence(String schemaId)
                          throws SchemaDoesNotExistException
Checks whether an schema exists in the IJC metadata registry (IJC_SCHEMA table) or not also checks whether the database/ IJC_SCHEMA table exists or not.

Parameters:
schemaId -
Throws:
SchemaDoesNotExistException

updateHeartbeat

void updateHeartbeat(String userName,
                     String schemaId)
Updates when the last time user accessed the database for purpose of changing the data

Parameters:
userName - current logged in use
schemaId - current schema

com.im.commons.db 5.9.2