|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.j256.ormlite.db.BaseDatabaseType
public abstract class BaseDatabaseType
Base class for all of the 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 versions.
Nested Class Summary | |
---|---|
protected static class |
BaseDatabaseType.BooleanNumberFieldConverter
Conversion to/from the Boolean Java field as a number because some databases like the true/false. |
Field Summary | |
---|---|
protected static int |
DEFAULT_DATE_STRING_WIDTH
|
protected static String |
DEFAULT_SEQUENCE_SUFFIX
|
protected static int |
DEFAULT_VARCHAR_WIDTH
|
Constructor Summary | |
---|---|
BaseDatabaseType()
|
Method Summary | |
---|---|
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. |
protected void |
addSingleUnique(StringBuilder sb,
FieldType fieldType,
List<String> additionalArgs,
List<String> statementsAfter)
Add SQL to handle a unique=true field. |
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 |
appendBooleanType(StringBuilder sb)
Output the SQL type for a Java boolean. |
protected void |
appendByteArrayType(StringBuilder sb)
Output the SQL type for either a serialized Java object or a byte[]. |
protected void |
appendByteType(StringBuilder sb)
Output the SQL type for a Java byte. |
protected void |
appendCanBeNull(StringBuilder sb,
FieldType fieldType)
If the field can be nullable, do we need to add some sort of NULL SQL for the create table. |
protected void |
appendCharType(StringBuilder sb)
Output the SQL type for a Java char. |
void |
appendColumnArg(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 |
appendCreateTableSuffix(StringBuilder sb)
Append the SQL necessary to properly finish a CREATE TABLE line. |
protected void |
appendDateLongType(StringBuilder sb)
Output the SQL type for a Java Date. |
protected void |
appendDateStringType(StringBuilder sb,
int fieldWidth)
Output the SQL type for a Java Date as a string. |
protected void |
appendDateType(StringBuilder sb,
int fieldWidth)
Output the SQL type for a Java Date. |
protected void |
appendDefaultValue(StringBuilder sb,
FieldType fieldType,
Object defaultValue)
Output the SQL type for a Java boolean default value. |
protected void |
appendDoubleType(StringBuilder sb)
Output the SQL type for a Java double. |
protected void |
appendEnumIntType(StringBuilder sb,
FieldType fieldType)
Output the SQL type for a Enum object stored as intg. |
protected void |
appendEnumStringType(StringBuilder sb,
FieldType fieldType)
Output the SQL type for a Enum object stored as String. |
void |
appendEscapedEntityName(StringBuilder sb,
String word)
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)
Output the SQL type for a Java float. |
protected void |
appendIntegerType(StringBuilder sb)
Output the SQL type for a Java integer. |
void |
appendLimitValue(StringBuilder sb,
int limit,
Integer offset)
Append to the string builder the necessary SQL to limit the results to a certain number. |
protected void |
appendLongStringType(StringBuilder sb)
Output the SQL type for a Java Long String. |
protected void |
appendLongType(StringBuilder sb)
Output the SQL type for a Java long. |
void |
appendOffsetValue(StringBuilder sb,
int 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)
Output the SQL type for a serialized Java object. |
protected void |
appendShortType(StringBuilder sb)
Output the SQL type for a Java short. |
protected void |
appendStringType(StringBuilder sb,
int fieldWidth)
Output the SQL type for a Java String. |
protected void |
configureGeneratedId(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 |
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. |
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 |
protected boolean |
generatedIdSqlAtEnd()
Return true if we should add generated-id SQL in the addPrimaryKeySql(com.j256.ormlite.field.FieldType[], java.util.List 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. |
protected abstract String |
getDatabaseName()
Return the name of the database for logging purposes. |
protected int |
getDefaultVarcharWidth()
Return the default varchar width if not specified by DatabaseField.width() . |
protected abstract String |
getDriverClassName()
Return the name of the driver class associated with this database type. |
FieldConverter |
getFieldConverter(DataType dataType)
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 |
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 |
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 |
isLimitAfterSelect()
Return true if the LIMIT should be called after SELECT otherwise at the end of the WHERE (the default). |
boolean |
isLimitSqlSupported()
Return true if the database supports the LIMIT SQL command. |
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 |
isTruncateSupported()
Returns true if the table truncate operation is supported. |
boolean |
isVarcharFieldWidthSupported()
Return true if the database supports the width parameter on VARCHAR fields. |
void |
loadDriver()
Load the driver class associated with this database so it can wire itself into JDBC. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.j256.ormlite.db.DatabaseType |
---|
isDatabaseUrlThisType |
Field Detail |
---|
protected static int DEFAULT_VARCHAR_WIDTH
protected static int DEFAULT_DATE_STRING_WIDTH
protected static String DEFAULT_SEQUENCE_SUFFIX
Constructor Detail |
---|
public BaseDatabaseType()
Method Detail |
---|
protected abstract String getDriverClassName()
protected abstract String getDatabaseName()
public void loadDriver() throws SQLException
DatabaseType
loadDriver
in interface DatabaseType
SQLException
- If the driver class is not available in the classpath.public void appendColumnArg(StringBuilder sb, FieldType fieldType, List<String> additionalArgs, List<String> statementsBefore, List<String> statementsAfter, List<String> queriesAfter) throws SQLException
DatabaseType
FieldType
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 DatabaseType
SQLException
protected void appendStringType(StringBuilder sb, int fieldWidth)
protected void appendLongStringType(StringBuilder sb)
protected void appendDateType(StringBuilder sb, int fieldWidth)
protected void appendDateLongType(StringBuilder sb)
protected void appendDateStringType(StringBuilder sb, int fieldWidth)
protected void appendBooleanType(StringBuilder sb)
protected void appendCharType(StringBuilder sb)
protected void appendByteType(StringBuilder sb)
protected void appendShortType(StringBuilder sb)
protected void appendIntegerType(StringBuilder sb)
protected void appendLongType(StringBuilder sb)
protected void appendFloatType(StringBuilder sb)
protected void appendDoubleType(StringBuilder sb)
protected void appendByteArrayType(StringBuilder sb)
protected void appendSerializableType(StringBuilder sb)
protected void appendEnumStringType(StringBuilder sb, FieldType fieldType)
protected void appendEnumIntType(StringBuilder sb, FieldType fieldType)
protected void appendDefaultValue(StringBuilder sb, FieldType fieldType, Object defaultValue)
protected void configureGeneratedIdSequence(StringBuilder sb, FieldType fieldType, List<String> statementsBefore, List<String> additionalArgs, List<String> queriesAfter) throws SQLException
SQLException
protected void configureGeneratedId(StringBuilder sb, FieldType fieldType, List<String> statementsBefore, 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) throws SQLException
DatabaseType
addPrimaryKeySql
in interface DatabaseType
SQLException
protected boolean generatedIdSqlAtEnd()
addPrimaryKeySql(com.j256.ormlite.field.FieldType[], java.util.List, java.util.List, java.util.List, java.util.List)
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) throws SQLException
DatabaseType
addUniqueComboSql
in interface DatabaseType
SQLException
public void dropColumnArg(FieldType fieldType, List<String> statementsBefore, List<String> statementsAfter)
DatabaseType
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
dropColumnArg
in interface DatabaseType
public void appendEscapedWord(StringBuilder sb, String word)
DatabaseType
appendEscapedWord
in interface DatabaseType
public void appendEscapedEntityName(StringBuilder sb, String word)
DatabaseType
appendEscapedEntityName
in interface DatabaseType
public String generateIdSequenceName(String tableName, FieldType idFieldType)
DatabaseType
generateIdSequenceName
in interface DatabaseType
public String getCommentLinePrefix()
DatabaseType
getCommentLinePrefix
in interface DatabaseType
public FieldConverter getFieldConverter(DataType dataType)
DatabaseType
getFieldConverter
in interface DatabaseType
public boolean isIdSequenceNeeded()
DatabaseType
isIdSequenceNeeded
in interface DatabaseType
public boolean isVarcharFieldWidthSupported()
DatabaseType
isVarcharFieldWidthSupported
in interface DatabaseType
public boolean isLimitSqlSupported()
DatabaseType
Statement.setMaxRows(int)
instead. See prepareSqlStatement in MappedPreparedQuery.
isLimitSqlSupported
in interface DatabaseType
public boolean isOffsetSqlSupported()
DatabaseType
isOffsetSqlSupported
in interface DatabaseType
public boolean isOffsetLimitArgument()
DatabaseType
isOffsetLimitArgument
in interface DatabaseType
public boolean isLimitAfterSelect()
DatabaseType
isLimitAfterSelect
in interface DatabaseType
public void appendLimitValue(StringBuilder sb, int limit, Integer offset)
DatabaseType
appendLimitValue
in interface DatabaseType
public void appendOffsetValue(StringBuilder sb, int offset)
DatabaseType
appendOffsetValue
in interface DatabaseType
protected int getDefaultVarcharWidth()
DatabaseField.width()
.
public void appendSelectNextValFromSequence(StringBuilder sb, String sequenceName)
DatabaseType
DatabaseType.isIdSequenceNeeded()
is true.
appendSelectNextValFromSequence
in interface DatabaseType
public void appendCreateTableSuffix(StringBuilder sb)
DatabaseType
appendCreateTableSuffix
in interface DatabaseType
public boolean isCreateTableReturnsZero()
DatabaseType
isCreateTableReturnsZero
in interface DatabaseType
public boolean isEntityNamesMustBeUpCase()
DatabaseType
Turns 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 DatabaseType
public boolean isNestedSavePointsSupported()
DatabaseType
isNestedSavePointsSupported
in interface DatabaseType
public String getPingStatement()
DatabaseType
getPingStatement
in interface DatabaseType
public boolean isBatchUseTransaction()
DatabaseType
isBatchUseTransaction
in interface DatabaseType
public boolean isTruncateSupported()
DatabaseType
isTruncateSupported
in interface DatabaseType
public boolean isCreateIfNotExistsSupported()
DatabaseType
isCreateIfNotExistsSupported
in interface DatabaseType
protected void appendCanBeNull(StringBuilder sb, FieldType fieldType)
protected void addSingleUnique(StringBuilder sb, FieldType fieldType, List<String> additionalArgs, List<String> statementsAfter)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |