public abstract class JdbcAdaptor extends AbstractJdbcAdaptor
| Modifier and Type | Class and Description |
|---|---|
static class |
JdbcAdaptor.PaginationParamsOrder
The order of pagination paramaters embedded into the SQL.
|
| Constructor and Description |
|---|
JdbcAdaptor() |
| Modifier and Type | Method and Description |
|---|---|
abstract String |
createColumnDDL(AbstractColumn columnDefinition)
Creates(generates) the BasicColumn Definition DDL for the column.
|
String |
createCreateTableStatement(AbstractTable table,
Collection<String> ddlColumns,
List<String> pkColumns,
List<String> uniqueColumns)
Creates the create table statement
|
void |
createForeignKey(DataSource datasource,
ForeignKey foreignKey)
Creates a foreign key on the table
|
protected void |
createIndex(DataSource datasource,
EntityTable table,
String indexName,
BasicColumn[] columns)
Creates the index for the table.
|
void |
createOrUpdateTable(AbstractTable table,
DataSource datasource,
DDLMode ddlMode)
Creates or update the table.
|
abstract void |
createSequenceIfNecessary(DataSource datasource,
SequenceGenerator sequence)
Creates the sequence if not exists.
|
void |
createTableGeneratorIfNecessary(DataSource datasource,
TableGenerator table)
Creates the table generator if not exists.
|
void |
dropAllForeignKeys(DataSource datasource,
Set<AbstractTable> tableSet) |
void |
dropAllSequences(DataSource datasource,
Collection<SequenceGenerator> sequences) |
void |
dropAllTables(DataSource datasource,
Collection<AbstractTable> tables)
Drops the tables in the database
|
protected void |
dropSequence(QueryRunner runner,
SequenceGenerator sequence)
Drops the sequence.
|
protected void |
dropTable(QueryRunner runner,
AbstractTable table)
Drops the table
|
String |
escape(String name)
Escapes an SQL name
|
protected Collection<AbstractColumn> |
getColumns(AbstractTable table)
Returns the sorted columns.
|
protected String |
getColumnType(AbstractColumn cd,
int sqlType)
Returns the data type of the column.
|
String |
getCurrentDate()
Returns the current date literal
|
String |
getCurrentTime()
Returns the current time literal
|
String |
getCurrentTimeStamp()
Returns the current time stamp literal
|
protected abstract String |
getDatabaseName()
Returns the name of the database.
|
String |
getDateTimeFunctionTemplate(DateTimeFunctionType type)
Returns the date time function template for the type
type. |
protected String |
getDropForeignKeySql(String schema,
String table,
String foreignKey)
Returns the SQL to drop the foreign key.
|
int |
getInsertBatchSize()
Returns the insertBatchSize of the JdbcAdaptor.
|
abstract long |
getNextSequence(DataSource datasource,
String sequenceName)
Returns next sequence number from the database.
|
String |
getNumericFunctionTemplate(NumericFunctionType type)
Returns the numeric function template.
|
abstract JdbcAdaptor.PaginationParamsOrder |
getPaginationParamsOrder()
Returns the pagination params order for the adaptor.
|
protected String |
getPkCreateSql(String schema,
String table,
Set<String> pkColumns)
Returns the priary key drop SQL.
|
protected String |
getPkDropSql(String schema,
String table,
String pkName)
Returns the priary key drop SQL.
|
int |
getRemoveBatchSize()
Returns the removeBatchSize of the JdbcAdaptor.
|
abstract String |
getSelectLastIdentitySql(BasicColumn identityColumn)
Returns the SQL to select the last identity generated.
|
void |
importSql(ClassLoader classLoader,
DataSource dataSource,
String importSqlFileName)
Executes the initial import sql.
|
protected abstract boolean |
isForeignKeyHasDefaultIndex()
Underlining DB creates an index for foreign Keys
|
boolean |
isPmdBroken()
Returns if the PMD is Broken for the adaptor.
|
protected boolean |
isTableRequiredPrimaryKey()
DB forces a primary key or not
|
protected void |
logRelaxed(SQLException e,
String message)
Logs the message as warning and with exception as debug.
|
boolean |
modifiesParameters()
Returns if the JDBC adaptor modifies parameters.
|
void |
modifyParameters(ParameterMetaData pmd,
Object[] params)
Modifies the parameters.
|
abstract boolean |
paginationNeedsMaxResultsAlways()
Returns if pagination always needs the max results paramater.
|
abstract boolean |
paginationNeedsStartAlways()
Returns if pagination always needs the start paramater.
|
boolean |
parameterizedPagination()
Returns if the paginated sql uses parameters instead of hard coded pagination variables.
|
protected String |
qualified(String schema,
String jdbcClassName)
Returns the schema if it is set otherwise falls back to the default schema.
|
void |
setInsertBatchSize(int insertBatchSize)
Sets the insertBatchSize of the JdbcAdaptor.
|
void |
setRemoveBatchSize(int removeBatchSize)
Sets the removeBatchSize of the JdbcAdaptor.
|
abstract IdType |
supports(javax.persistence.GenerationType type)
Returns the id type supported.
|
boolean |
supportsNamedParams()
Returns if the database supports named params i.e.:
select * from mytable field = :p1. |
boolean |
supportsOrdinalParams()
Returns if the database supports ordinal params i.e.:
select * from mytable field = ?1. |
applyCast, applyConcat, applyLikeEscape, applyLock, applyPagination, applySubStr, applyTrim, castBoolean, getAdapter, getCastClassName, getProductNamespublic abstract String createColumnDDL(AbstractColumn columnDefinition)
columnDefinition - the column definition to create the DDL frompublic String createCreateTableStatement(AbstractTable table, Collection<String> ddlColumns, List<String> pkColumns, List<String> uniqueColumns)
table - the definition of the tableddlColumns - the DDL for the columnspkColumns - the list of primary key column namesuniqueColumns - the list of columns that are uniquepublic void createForeignKey(DataSource datasource, ForeignKey foreignKey)
datasource - the datasourceforeignKey - the foreign keyprotected void createIndex(DataSource datasource, EntityTable table, String indexName, BasicColumn[] columns) throws SQLException
datasource - the datasourcetable - the tableindexName - the name of the indexcolumns - the columnsSQLException - throw in case index creation failspublic void createOrUpdateTable(AbstractTable table, DataSource datasource, DDLMode ddlMode)
table - the tabledatasource - the datasourceddlMode - the ddl modepublic abstract void createSequenceIfNecessary(DataSource datasource, SequenceGenerator sequence)
datasource - the datasource to usesequence - the sequence to createpublic final void createTableGeneratorIfNecessary(DataSource datasource, TableGenerator table)
datasource - the datasource to usetable - the table generatorpublic void dropAllForeignKeys(DataSource datasource, Set<AbstractTable> tableSet)
datasource - the datasourcetableSet - the foreign keyspublic void dropAllSequences(DataSource datasource, Collection<SequenceGenerator> sequences) throws SQLException
datasource - the datasourcesequences - the sequencesSQLException - thrown if the SQL failspublic void dropAllTables(DataSource datasource, Collection<AbstractTable> tables) throws SQLException
datasource - the datasourcetables - the set of tables to dropSQLException - thrown if the SQL failsprotected void dropSequence(QueryRunner runner, SequenceGenerator sequence) throws SQLException
runner - the runnersequence - the sequenceSQLException - thrown if SQL failsprotected void dropTable(QueryRunner runner, AbstractTable table) throws SQLException
runner - the runnertable - the tableSQLExceptionpublic String escape(String name)
name - the original nameprotected Collection<AbstractColumn> getColumns(AbstractTable table)
table - the tableprotected String getColumnType(AbstractColumn cd, int sqlType)
cd - the column definitionsqlType - the sql typepublic String getCurrentDate()
public String getCurrentTime()
public String getCurrentTimeStamp()
protected abstract String getDatabaseName()
public String getDateTimeFunctionTemplate(DateTimeFunctionType type)
type.type - the type of the functiontypeprotected String getDropForeignKeySql(String schema, String table, String foreignKey)
schema - the name of the schematable - the name of the tableforeignKey - the name of the foreign keypublic int getInsertBatchSize()
public abstract long getNextSequence(DataSource datasource, String sequenceName) throws SQLException
datasource - the datasource to usesequenceName - the name of the sequenceSQLException - thrown in case of an SQL errorpublic String getNumericFunctionTemplate(NumericFunctionType type)
type - the id typeIdType selected, the Id passed or nullpublic abstract JdbcAdaptor.PaginationParamsOrder getPaginationParamsOrder()
protected String getPkCreateSql(String schema, String table, Set<String> pkColumns)
schema - the name of the schematable - the name of the tablepkColumns - the set of the primary key column namesprotected String getPkDropSql(String schema, String table, String pkName)
schema - the name of the schematable - the name of the tablepkName - the name of the primary keypublic int getRemoveBatchSize()
public abstract String getSelectLastIdentitySql(BasicColumn identityColumn)
identityColumn - the identity columnpublic void importSql(ClassLoader classLoader, DataSource dataSource, String importSqlFileName)
classLoader - the class loaderdataSource - the datasourceimportSqlFileName - the name of the import sqlprotected abstract boolean isForeignKeyHasDefaultIndex()
public boolean isPmdBroken()
protected boolean isTableRequiredPrimaryKey()
protected void logRelaxed(SQLException e, String message)
e - the sql exceptionmessage - the messagepublic boolean modifiesParameters()
public void modifyParameters(ParameterMetaData pmd, Object[] params)
The default implementation does nothing.
Individual adaptors are free to modify.
pmd - the statement's parameter metadataparams - the parameters to modifypublic abstract boolean paginationNeedsMaxResultsAlways()
public abstract boolean paginationNeedsStartAlways()
public boolean parameterizedPagination()
protected String qualified(String schema, String jdbcClassName)
schema - the schema namejdbcClassName - the name of the table or sequenceSQLException - thrown in case of an SQL errorpublic void setInsertBatchSize(int insertBatchSize)
insertBatchSize - the insertBatchSize to set for JdbcAdaptorpublic void setRemoveBatchSize(int removeBatchSize)
removeBatchSize - the removeBatchSize to set for JdbcAdaptorpublic abstract IdType supports(javax.persistence.GenerationType type)
If the idType is null, the adapter should suggest an IdType in return.
If the idType is some other value than null then the adapter should either return the same IdType if supported or null value
in case the adapter does not support the specified IdType.
type - the id typeIdType selected, the Id passed or nullpublic boolean supportsNamedParams()
select * from mytable field = :p1.public boolean supportsOrdinalParams()
select * from mytable field = ?1.Copyright © 2012-2013 Batoo. All Rights Reserved.