com.j256.ormlite.db
Interface DatabaseType

All Known Implementing Classes:
BaseDatabaseType, BaseSqliteDatabaseType

public interface DatabaseType

Definition of the per-database functionality needed to isolate the differences between the various databases.

Author:
graywatson

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.
 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.
 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 appendCreateTableSuffix(StringBuilder sb)
          Append the SQL necessary to properly finish a CREATE TABLE line.
 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.
 void appendLimitValue(StringBuilder sb, int limit, Integer offset)
          Append to the string builder the necessary SQL to limit the results to a certain number.
 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.
 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
 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.
 String getDatabaseName()
          Return the name of the database for logging purposes.
 FieldConverter getFieldConverter(DataPersister 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 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 isCreateTableReturnsZero()
          Returns true if a 'CREATE TABLE' statement should return 0.
 boolean isDatabaseUrlThisType(String url, String dbTypePart)
          Return true if the database URL corresponds to this database type.
 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 isSelectSequenceBeforeInsert()
          Returns true if we have to select the value of the sequence before we insert a new data row.
 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.
 void setDriver(Driver driver)
          Set the driver instance on the database type.
 

Method Detail

isDatabaseUrlThisType

boolean isDatabaseUrlThisType(String url,
                              String dbTypePart)
Return true if the database URL corresponds to this database type. Usually the URI is in the form jdbc:ddd:... where ddd is the driver url part.


loadDriver

void loadDriver()
                throws SQLException
Load the driver class associated with this database so it can wire itself into JDBC.

Throws:
SQLException - If the driver class is not available in the classpath.

setDriver

void setDriver(Driver driver)
Set the driver instance on the database type.


appendColumnArg

void appendColumnArg(String tableName,
                     StringBuilder sb,
                     FieldType fieldType,
                     List<String> additionalArgs,
                     List<String> statementsBefore,
                     List<String> statementsAfter,
                     List<String> queriesAfter)
                     throws SQLException
Takes a 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.

Throws:
SQLException

addPrimaryKeySql

void addPrimaryKeySql(FieldType[] fieldTypes,
                      List<String> additionalArgs,
                      List<String> statementsBefore,
                      List<String> statementsAfter,
                      List<String> queriesAfter)
                      throws SQLException
Appends information about primary key field(s) to the additional-args or other lists.

Throws:
SQLException

addUniqueComboSql

void addUniqueComboSql(FieldType[] fieldTypes,
                       List<String> additionalArgs,
                       List<String> statementsBefore,
                       List<String> statementsAfter,
                       List<String> queriesAfter)
                       throws SQLException
Appends information about unique field(s) to the additional-args or other lists.

Throws:
SQLException

dropColumnArg

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


appendEscapedEntityName

void appendEscapedEntityName(StringBuilder sb,
                             String word)
Add a entity-name word to the string builder wrapped in the proper characters to escape it. This avoids problems with table, column, and sequence-names being reserved words.


appendEscapedWord

void appendEscapedWord(StringBuilder sb,
                       String word)
Add the word to the string builder wrapped in the proper characters to escape it. This avoids problems with data values being reserved words.


generateIdSequenceName

String generateIdSequenceName(String tableName,
                              FieldType idFieldType)
Return the name of an ID sequence based on the tabelName and the fieldType of the id.


getCommentLinePrefix

String getCommentLinePrefix()
Return the prefix to put at the front of a SQL line to mark it as a comment.


isIdSequenceNeeded

boolean isIdSequenceNeeded()
Return true if the database needs a sequence when you use generated IDs. Some databases (H2, MySQL) create them auto-magically. This also means that the database needs to query for a sequence value before the object is inserted. For old[er] versions of Postgres, for example, the JDBC call-back stuff to get the just-inserted id value does not work so we have to get the next sequence value by hand, assign it into the object, and then insert the object -- yes two SQL statements.


getFieldConverter

FieldConverter getFieldConverter(DataPersister dataType)
Return the FieldConverter to associate with the DataType. This allows the database instance to convert a field as necessary before it goes to the database.


isVarcharFieldWidthSupported

boolean isVarcharFieldWidthSupported()
Return true if the database supports the width parameter on VARCHAR fields.


isLimitSqlSupported

boolean isLimitSqlSupported()
Return true if the database supports the LIMIT SQL command. Otherwise we have to use the Statement.setMaxRows(int) instead. See prepareSqlStatement in MappedPreparedQuery.


isLimitAfterSelect

boolean isLimitAfterSelect()
Return true if the LIMIT should be called after SELECT otherwise at the end of the WHERE (the default).


appendLimitValue

void appendLimitValue(StringBuilder sb,
                      int limit,
                      Integer offset)
Append to the string builder the necessary SQL to limit the results to a certain number. With some database types, the offset is an argument to the LIMIT so the offset value (which could be null or not) is passed in. The database type can choose to ignore it.


isOffsetSqlSupported

boolean isOffsetSqlSupported()
Return true if the database supports the OFFSET SQL command in some form.


isOffsetLimitArgument

boolean isOffsetLimitArgument()
Return true if the database supports the offset as a comma argument from the limit. This also means that the limit _must_ be specified if the offset is specified


appendOffsetValue

void appendOffsetValue(StringBuilder sb,
                       int offset)
Append to the string builder the necessary SQL to start the results at a certain row number.


appendSelectNextValFromSequence

void appendSelectNextValFromSequence(StringBuilder sb,
                                     String sequenceName)
Append the SQL necessary to get the next-value from a sequence. This is only necessary if isIdSequenceNeeded() is true.


appendCreateTableSuffix

void appendCreateTableSuffix(StringBuilder sb)
Append the SQL necessary to properly finish a CREATE TABLE line.


isCreateTableReturnsZero

boolean isCreateTableReturnsZero()
Returns true if a 'CREATE TABLE' statement should return 0. False if > 0.


isEntityNamesMustBeUpCase

boolean isEntityNamesMustBeUpCase()
Returns true if table and field names should be made uppercase.

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.


isNestedSavePointsSupported

boolean isNestedSavePointsSupported()
Returns true if nested savePoints are supported, otherwise false.


getPingStatement

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.


isBatchUseTransaction

boolean isBatchUseTransaction()
Returns true if batch operations should be done inside of a transaction. Default is false in which case auto-commit disabling will be done.


isTruncateSupported

boolean isTruncateSupported()
Returns true if the table truncate operation is supported.


isCreateIfNotExistsSupported

boolean isCreateIfNotExistsSupported()
Returns true if the table creation IF NOT EXISTS syntax is supported.


isSelectSequenceBeforeInsert

boolean isSelectSequenceBeforeInsert()
Returns true if we have to select the value of the sequence before we insert a new data row.


isAllowGeneratedIdInsertSupported

boolean isAllowGeneratedIdInsertSupported()
Does the database support the DatabaseField.allowGeneratedIdInsert() setting which allows people to insert values into generated-id columns.


getDatabaseName

String getDatabaseName()
Return the name of the database for logging purposes.



This content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.