public abstract class BaseDatabaseType extends Object implements DatabaseType
DatabaseType classes that provide the per-database type functionality to create
tables and build queries.
Here's a good page which shows some of the differences between SQL databases.
| Modifier and Type | Field and Description |
|---|---|
protected static String |
DEFAULT_SEQUENCE_SUFFIX |
protected Driver |
driver |
protected Logger |
logger |
| Constructor and Description |
|---|
BaseDatabaseType() |
| Modifier and Type | Method and Description |
|---|---|
void |
addPrimaryKeySql(FieldType[] fieldTypes,
List<String> additionalArgs,
List<String> statementsBefore,
List<String> statementsAfter,
List<String> queriesAfter)
Appends information about primary key field(s) to the additional-args or other lists.
|
void |
addUniqueComboSql(FieldType[] fieldTypes,
List<String> additionalArgs,
List<String> statementsBefore,
List<String> statementsAfter,
List<String> queriesAfter)
Appends information about unique field(s) to the additional-args or other lists.
|
protected void |
appendBigDecimalNumericType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a BigDecimal object.
|
protected void |
appendBooleanType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a Java boolean.
|
protected void |
appendByteArrayType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for either a serialized Java object or a byte[].
|
protected void |
appendByteType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a Java byte.
|
protected void |
appendCharType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a Java char.
|
void |
appendColumnArg(String tableName,
StringBuilder sb,
FieldType fieldType,
List<String> additionalArgs,
List<String> statementsBefore,
List<String> statementsAfter,
List<String> queriesAfter)
Takes a
FieldType and appends the SQL necessary to create the field to the string builder. |
void |
appendCreateSchemaSuffix(StringBuilder sb)
Append the SQL necessary to properly finish a CREATE SCHEMA line.
|
void |
appendCreateTableSuffix(StringBuilder sb)
Append the SQL necessary to properly finish a CREATE TABLE line.
|
protected void |
appendDateType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a Java Date.
|
void |
appendDeleteLimitValue(StringBuilder sb,
long limit)
Append to the string builder the necessary SQL to limit the deleted rows to a certain number.
|
protected void |
appendDoubleType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a Java double.
|
void |
appendEscapedEntityName(StringBuilder sb,
String name)
Add a entity-name word to the string builder wrapped in the proper characters to escape it.
|
void |
appendEscapedWord(StringBuilder sb,
String word)
Add the word to the string builder wrapped in the proper characters to escape it.
|
protected void |
appendFloatType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a Java float.
|
void |
appendInsertNoColumns(StringBuilder sb)
Append the SQL necessary to properly finish a "INSERT INTO xxx" line when there are no arguments.
|
protected void |
appendIntegerType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a Java integer.
|
void |
appendLimitValue(StringBuilder sb,
long limit,
Long offset)
Append to the string builder the necessary SQL to limit the results to a certain number.
|
protected void |
appendLongStringType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a Java Long String.
|
protected void |
appendLongType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a Java long.
|
void |
appendOffsetValue(StringBuilder sb,
long offset)
Append to the string builder the necessary SQL to start the results at a certain row number.
|
void |
appendSelectNextValFromSequence(StringBuilder sb,
String sequenceName)
Append the SQL necessary to get the next-value from a sequence.
|
protected void |
appendSerializableType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a serialized Java object.
|
protected void |
appendShortType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a Java short.
|
protected void |
appendStringType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a Java String.
|
void |
appendUpdateLimitValue(StringBuilder sb,
long limit)
Append to the string builder the necessary SQL to limit the updated rows to a certain number.
|
protected void |
appendUuidNativeType(StringBuilder sb,
FieldType fieldType,
int fieldWidth)
Output the SQL type for a Java UUID.
|
protected void |
configureGeneratedId(String tableName,
StringBuilder sb,
FieldType fieldType,
List<String> statementsBefore,
List<String> statementsAfter,
List<String> additionalArgs,
List<String> queriesAfter)
Output the SQL necessary to configure a generated-id column.
|
protected void |
configureGeneratedIdSequence(StringBuilder sb,
FieldType fieldType,
List<String> statementsBefore,
List<String> additionalArgs,
List<String> queriesAfter)
Output the SQL necessary to configure a generated-id column.
|
protected void |
configureId(StringBuilder sb,
FieldType fieldType,
List<String> statementsBefore,
List<String> additionalArgs,
List<String> queriesAfter)
Output the SQL necessary to configure an id column.
|
String |
downCaseString(String string,
boolean forceEnglish)
Returns the lowercase version of a string for generating and fields and methods.
|
void |
dropColumnArg(FieldType fieldType,
List<String> statementsBefore,
List<String> statementsAfter)
Takes a
FieldType and adds the necessary statements to the before and after lists necessary so that the
dropping of the table will succeed and will clear other associated sequences or other database artifacts |
<T> DatabaseTableConfig<T> |
extractDatabaseTableConfig(ConnectionSource connectionSource,
Class<T> clazz)
Extract and return a custom database configuration for this class.
|
protected boolean |
generatedIdSqlAtEnd()
Return true if we should add generated-id SQL in the
addPrimaryKeySql(com.j256.ormlite.field.FieldType[], java.util.List<java.lang.String>, java.util.List<java.lang.String>, java.util.List<java.lang.String>, java.util.List<java.lang.String>) method at the end. |
String |
generateIdSequenceName(String tableName,
FieldType idFieldType)
Return the name of an ID sequence based on the tabelName and the fieldType of the id.
|
String |
getCommentLinePrefix()
Return the prefix to put at the front of a SQL line to mark it as a comment.
|
DataPersister |
getDataPersister(DataPersister defaultPersister,
FieldType fieldType)
Return the DataPersister to associate with the DataType.
|
protected String[] |
getDriverClassNames()
Return the name of the driver(s) class associated with this database type.
|
FieldConverter |
getFieldConverter(DataPersister dataPersister,
FieldType fieldType)
Return the FieldConverter to associate with the DataType.
|
String |
getPingStatement()
Return an statement that doesn't do anything but which can be used to ping the database by sending it over a
database connection.
|
boolean |
isAllowGeneratedIdInsertSupported()
Does the database support the
DatabaseField.allowGeneratedIdInsert() setting which allows people to
insert values into generated-id columns. |
boolean |
isBatchUseTransaction()
Returns true if batch operations should be done inside of a transaction.
|
boolean |
isCreateIfNotExistsSupported()
Returns true if the table creation IF NOT EXISTS syntax is supported.
|
boolean |
isCreateIndexIfNotExistsSupported()
Does the database support the "CREATE INDEX IF NOT EXISTS" SQL construct.
|
boolean |
isCreateSchemaIfNotExistsSupported()
Does the database support the "CREATE SCHEMA IF NOT EXISTS" SQL construct.
|
boolean |
isCreateSchemaReturnsNegative()
Returns true if CREATE and DROP SCHEMA statements can return < 0 and still have worked.
|
boolean |
isCreateSchemaReturnsZero()
Returns true if a 'CREATE SCHEMA' statement should return 0.
|
boolean |
isCreateTableReturnsNegative()
Returns true if CREATE and DROP TABLE statements can return < 0 and still have worked.
|
boolean |
isCreateTableReturnsZero()
Returns true if a 'CREATE TABLE' statement should return 0.
|
boolean |
isEntityNamesMustBeUpCase()
Returns true if table and field names should be made uppercase.
|
boolean |
isIdSequenceNeeded()
Return true if the database needs a sequence when you use generated IDs.
|
boolean |
isLimitAfterDeleteSupported()
Return true if LIMIT is supported after the DELETE command.
|
boolean |
isLimitAfterSelect()
Return true if the LIMIT should be called after SELECT otherwise at the end of the WHERE (the default).
|
boolean |
isLimitAfterUpdateSupported()
Return true if LIMIT is supported after the UPDATE command.
|
boolean |
isLimitDeleteAtEndSupported()
Return true if LIMIT is supported at the end of the DELETE statement.
|
boolean |
isLimitSqlSupported()
Return true if the database supports the LIMIT SQL command.
|
boolean |
isLimitUpdateAtEndSupported()
Return true if LIMIT is supported at the end of the UPDATE statement.
|
boolean |
isNestedSavePointsSupported()
Returns true if nested savePoints are supported, otherwise false.
|
boolean |
isOffsetLimitArgument()
Return true if the database supports the offset as a comma argument from the limit.
|
boolean |
isOffsetSqlSupported()
Return true if the database supports the OFFSET SQL command in some form.
|
boolean |
isSelectSequenceBeforeInsert()
Returns true if we have to select the value of the sequence before we insert a new data row.
|
boolean |
isSequenceNamesMustBeLowerCase()
Returns true if the sequence names need to be lowercased.
|
boolean |
isTruncateSupported()
Returns true if the table truncate operation is supported.
|
boolean |
isVarcharFieldWidthSupported()
Return true if the database supports the width parameter on VARCHAR fields.
|
boolean |
loadDriver()
Load the driver class associated with this database so it can wire itself into JDBC.
|
void |
setDriver(Driver driver)
Set the driver instance on the database type.
|
String |
upCaseEntityName(String entityName)
Returns the uppercase version of an entity name.
|
String |
upCaseString(String string,
boolean forceEnglish)
Returns the uppercase version of a string for generating and matching fields and methods.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetDatabaseName, isDatabaseUrlThisTypeprotected static String DEFAULT_SEQUENCE_SUFFIX
protected Driver driver
protected Logger logger
protected String[] getDriverClassNames()
public boolean loadDriver()
DatabaseTypeloadDriver in interface DatabaseTypepublic void setDriver(Driver driver)
DatabaseTypesetDriver in interface DatabaseTypepublic void appendColumnArg(String tableName, StringBuilder sb, FieldType fieldType, List<String> additionalArgs, List<String> statementsBefore, List<String> statementsAfter, List<String> queriesAfter) throws SQLException
DatabaseTypeFieldType and appends the SQL necessary to create the field to the string builder. The field may
also generate additional arguments which go at the end of the insert statement or additional statements to be
executed before or afterwards depending on the configurations. The database can also add to the list of queries
that will be performed afterward to test portions of the config.appendColumnArg in interface DatabaseTypeSQLExceptionprotected void appendStringType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendUuidNativeType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendLongStringType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendDateType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendBooleanType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendCharType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendByteType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendShortType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendIntegerType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendLongType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendFloatType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendDoubleType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendByteArrayType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendSerializableType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void appendBigDecimalNumericType(StringBuilder sb, FieldType fieldType, int fieldWidth)
protected void configureGeneratedIdSequence(StringBuilder sb, FieldType fieldType, List<String> statementsBefore, List<String> additionalArgs, List<String> queriesAfter) throws SQLException
SQLExceptionprotected void configureGeneratedId(String tableName, StringBuilder sb, FieldType fieldType, List<String> statementsBefore, List<String> statementsAfter, List<String> additionalArgs, List<String> queriesAfter)
protected void configureId(StringBuilder sb, FieldType fieldType, List<String> statementsBefore, List<String> additionalArgs, List<String> queriesAfter)
public void addPrimaryKeySql(FieldType[] fieldTypes, List<String> additionalArgs, List<String> statementsBefore, List<String> statementsAfter, List<String> queriesAfter)
DatabaseTypeaddPrimaryKeySql in interface DatabaseTypeprotected boolean generatedIdSqlAtEnd()
addPrimaryKeySql(com.j256.ormlite.field.FieldType[], java.util.List<java.lang.String>, java.util.List<java.lang.String>, java.util.List<java.lang.String>, java.util.List<java.lang.String>) method at the end. If false then
it needs to be done by hand inline.public void addUniqueComboSql(FieldType[] fieldTypes, List<String> additionalArgs, List<String> statementsBefore, List<String> statementsAfter, List<String> queriesAfter)
DatabaseTypeaddUniqueComboSql in interface DatabaseTypepublic void dropColumnArg(FieldType fieldType, List<String> statementsBefore, List<String> statementsAfter)
DatabaseTypeFieldType and adds the necessary statements to the before and after lists necessary so that the
dropping of the table will succeed and will clear other associated sequences or other database artifactsdropColumnArg in interface DatabaseTypepublic void appendEscapedWord(StringBuilder sb, String word)
DatabaseTypeappendEscapedWord in interface DatabaseTypepublic void appendEscapedEntityName(StringBuilder sb, String name)
DatabaseTypeappendEscapedEntityName in interface DatabaseTypepublic String generateIdSequenceName(String tableName, FieldType idFieldType)
DatabaseTypegenerateIdSequenceName in interface DatabaseTypepublic String getCommentLinePrefix()
DatabaseTypegetCommentLinePrefix in interface DatabaseTypepublic DataPersister getDataPersister(DataPersister defaultPersister, FieldType fieldType)
DatabaseTypegetDataPersister in interface DatabaseTypepublic FieldConverter getFieldConverter(DataPersister dataPersister, FieldType fieldType)
DatabaseTypegetFieldConverter in interface DatabaseTypepublic boolean isIdSequenceNeeded()
DatabaseTypeisIdSequenceNeeded in interface DatabaseTypepublic boolean isVarcharFieldWidthSupported()
DatabaseTypeisVarcharFieldWidthSupported in interface DatabaseTypepublic boolean isLimitSqlSupported()
DatabaseTypeStatement.setMaxRows(int) instead. See prepareSqlStatement in MappedPreparedQuery.isLimitSqlSupported in interface DatabaseTypepublic boolean isOffsetSqlSupported()
DatabaseTypeisOffsetSqlSupported in interface DatabaseTypepublic boolean isOffsetLimitArgument()
DatabaseTypeisOffsetLimitArgument in interface DatabaseTypepublic boolean isLimitAfterSelect()
DatabaseTypeisLimitAfterSelect in interface DatabaseTypepublic boolean isLimitAfterUpdateSupported()
DatabaseTypeisLimitAfterUpdateSupported in interface DatabaseTypepublic boolean isLimitUpdateAtEndSupported()
DatabaseTypeisLimitUpdateAtEndSupported in interface DatabaseTypepublic boolean isLimitAfterDeleteSupported()
DatabaseTypeisLimitAfterDeleteSupported in interface DatabaseTypepublic boolean isLimitDeleteAtEndSupported()
DatabaseTypeisLimitDeleteAtEndSupported in interface DatabaseTypepublic void appendLimitValue(StringBuilder sb, long limit, Long offset)
DatabaseTypeappendLimitValue in interface DatabaseTypepublic void appendUpdateLimitValue(StringBuilder sb, long limit)
DatabaseTypeappendUpdateLimitValue in interface DatabaseTypepublic void appendDeleteLimitValue(StringBuilder sb, long limit)
DatabaseTypeappendDeleteLimitValue in interface DatabaseTypepublic void appendOffsetValue(StringBuilder sb, long offset)
DatabaseTypeappendOffsetValue in interface DatabaseTypepublic void appendSelectNextValFromSequence(StringBuilder sb, String sequenceName)
DatabaseTypeDatabaseType.isIdSequenceNeeded() is true.appendSelectNextValFromSequence in interface DatabaseTypepublic void appendCreateTableSuffix(StringBuilder sb)
DatabaseTypeappendCreateTableSuffix in interface DatabaseTypepublic void appendCreateSchemaSuffix(StringBuilder sb)
DatabaseTypeappendCreateSchemaSuffix in interface DatabaseTypepublic boolean isCreateTableReturnsZero()
DatabaseTypeisCreateTableReturnsZero in interface DatabaseTypepublic boolean isCreateSchemaReturnsZero()
DatabaseTypeisCreateSchemaReturnsZero in interface DatabaseTypepublic boolean isCreateTableReturnsNegative()
DatabaseTypeisCreateTableReturnsNegative in interface DatabaseTypepublic boolean isCreateSchemaReturnsNegative()
DatabaseTypeisCreateSchemaReturnsNegative in interface DatabaseTypepublic boolean isEntityNamesMustBeUpCase()
DatabaseTypeTurns out that Derby and Hsqldb are doing something wrong (IMO) with entity names. If you create a table with the name "footable" (with the quotes) then it will be created as lowercase footable, case sensitive. However, if you then issue the query 'select * from footable' (without quotes) it won't find the table because it gets promoted to be FOOTABLE and is searched in a case sensitive manner. So for these databases, entity names have to be forced to be uppercase so external queries will also work.
isEntityNamesMustBeUpCase in interface DatabaseTypepublic String upCaseEntityName(String entityName)
DatabaseTypeupCaseEntityName in interface DatabaseTypepublic String upCaseString(String string, boolean forceEnglish)
DatabaseTypeupCaseString in interface DatabaseTypestring - String to up case.forceEnglish - Set to true to use the English locale otherwise false to use the default local one.public String downCaseString(String string, boolean forceEnglish)
DatabaseTypedownCaseString in interface DatabaseTypestring - String to down case.forceEnglish - Set to true to use the English locale otherwise false to use the default local one.public boolean isNestedSavePointsSupported()
DatabaseTypeisNestedSavePointsSupported in interface DatabaseTypepublic String getPingStatement()
DatabaseTypegetPingStatement in interface DatabaseTypepublic boolean isBatchUseTransaction()
DatabaseTypeisBatchUseTransaction in interface DatabaseTypepublic boolean isTruncateSupported()
DatabaseTypeisTruncateSupported in interface DatabaseTypepublic boolean isCreateIfNotExistsSupported()
DatabaseTypeisCreateIfNotExistsSupported in interface DatabaseTypepublic boolean isCreateIndexIfNotExistsSupported()
DatabaseTypeDatabaseType.isCreateIfNotExistsSupported().isCreateIndexIfNotExistsSupported in interface DatabaseTypepublic boolean isCreateSchemaIfNotExistsSupported()
DatabaseTypeDatabaseType.isCreateIfNotExistsSupported().isCreateSchemaIfNotExistsSupported in interface DatabaseTypepublic boolean isSelectSequenceBeforeInsert()
DatabaseTypeisSelectSequenceBeforeInsert in interface DatabaseTypepublic boolean isAllowGeneratedIdInsertSupported()
DatabaseTypeDatabaseField.allowGeneratedIdInsert() setting which allows people to
insert values into generated-id columns.isAllowGeneratedIdInsertSupported in interface DatabaseTypepublic <T> DatabaseTableConfig<T> extractDatabaseTableConfig(ConnectionSource connectionSource, Class<T> clazz) throws SQLException
DatabaseTypeextractDatabaseTableConfig in interface DatabaseTypeSQLException - for sub classes.public void appendInsertNoColumns(StringBuilder sb)
DatabaseTypeappendInsertNoColumns in interface DatabaseTypepublic boolean isSequenceNamesMustBeLowerCase()
DatabaseTypeisSequenceNamesMustBeLowerCase in interface DatabaseTypeThis documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.