- All Implemented Interfaces:
Backend
Backend for DB2.
- Author:
- harald
-
Field Summary
Fields inherited from class org.tentackle.sql.backends.AbstractSql2003Backend
RESERVED_WORDS_SQL2003, SQL_WINDOW_1, SQL_WINDOW_2, SQL_WINDOW_LIMIT, SQL_WINDOW_OFFSETFields inherited from class org.tentackle.sql.backends.AbstractSql92Backend
RESERVED_WORDS_SQL92, SQL_COALESCE, SQL_FOR_UPDATEFields inherited from class org.tentackle.sql.backends.AbstractBackend
TYPE_BIGINT, TYPE_BIT, TYPE_BLOB, TYPE_BOOL, TYPE_BOOLEAN, TYPE_BYTE, TYPE_BYTEA, TYPE_CHAR_1, TYPE_CLOB, TYPE_DATE, TYPE_DATETIME, TYPE_DATETIME_YEAR_TO_SECOND, TYPE_DECIMAL, TYPE_DECIMAL_19, TYPE_DOUBLE, TYPE_DOUBLE_PRECISION, TYPE_FLOAT, TYPE_FLOAT4, TYPE_FLOAT8, TYPE_INT, TYPE_INT2, TYPE_INT4, TYPE_INT8, TYPE_INTEGER, TYPE_NCHAR_1, TYPE_NUMBER, TYPE_NUMBER_1, TYPE_NUMBER_10, TYPE_NUMBER_19, TYPE_NUMBER_5, TYPE_NVARCHAR, TYPE_NVARCHAR_MAX, TYPE_REAL, TYPE_SMALLFLOAT, TYPE_SMALLINT, TYPE_TEXT, TYPE_TIME, TYPE_TIMESTAMP, TYPE_TINYINT, TYPE_UUID, TYPE_VARBINARY_MAX, TYPE_VARCHARFields inherited from interface org.tentackle.sql.Backend
SQL_ALLSTAR, SQL_ALTER_COLUMN, SQL_ALTER_INDEX, SQL_ALTER_TABLE, SQL_AND, SQL_ANDNOT, SQL_ARRAY_ALL, SQL_ARRAY_ALL_PAR, SQL_ARRAY_ANY, SQL_ARRAY_ANY_PAR, SQL_ARRAY_IN, SQL_ARRAY_IN_PAR, SQL_ARRAY_NOT_IN, SQL_ARRAY_NOT_IN_PAR, SQL_ARRAY_PAR, SQL_COMMA, SQL_COMMA_PAR, SQL_DELETE, SQL_DOT_STAR, SQL_EQUAL, SQL_EQUAL_PAR, SQL_EQUAL_PAR_COMMA, SQL_EQUAL_ZERO, SQL_EXISTS, SQL_FROM, SQL_GREATER, SQL_GREATER_PAR, SQL_GREATEROREQUAL, SQL_GREATEROREQUAL_PAR, SQL_GROUPBY, SQL_IF_EXISTS, SQL_INSERT_INTO, SQL_INSERT_VALUES, SQL_ISNOTNULL, SQL_ISNULL, SQL_LEFT_PARENTHESIS, SQL_LESS, SQL_LESS_PAR, SQL_LESSOREQUAL, SQL_LESSOREQUAL_PAR, SQL_LIKE, SQL_LIKE_PAR, SQL_MAX, SQL_MIN, SQL_NOT, SQL_NOTEQUAL, SQL_NOTEQUAL_PAR, SQL_NOTEQUAL_ZERO, SQL_NOTLIKE, SQL_NOTLIKE_PAR, SQL_OR, SQL_ORDERBY, SQL_ORNOT, SQL_PAR, SQL_PAR_COMMA, SQL_PLUS_ONE, SQL_RIGHT_PARENTHESIS, SQL_SELECT, SQL_SELECT_ALL_FROM, SQL_SET, SQL_SORTASC, SQL_SORTDESC, SQL_UPDATE, SQL_WHERE, SQL_WHEREALL, SQL_WHEREAND, SQL_WHERENOTHING, SQL_WHEREOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetBackendId(Connection connection) Determines the unique id or name used by the backend for a given connection.Gets the JDBC driver class name.intgetMaxSize(SqlType sqlType) Returns the maximum size for a given SQL-type.getName()Gets the name of the backend.protected booleanAdds "IF EXISTS" to drop clauses, if supported by the backend.
Makes migration a little more robust in case the same SQL scripts are applied to different databases than those used to generate the migration scripts for.booleanReturns whether function based indexes are supported.booleanisMatchingUrl(String url) Checks whether the backend belongs to the given jdbc url.
If multiple backend implementations are provided for the same database type, only one backend should match the URL.booleanDetermines whether exception is transient and retrying the transaction may succeed.
Typical transient exceptions are thrown when a deadlock is detected or when serialized transaction isolation is used.SqlType[]jdbcTypeToSqlType(int jdbcType, int size, int scale) Converts the JDBC data type integer to a tentackle backend SqlTypes.sqlAddColumn(String tableName, String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue) Generates sql code to add a column.sqlAlterColumnType(String tableName, String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue) Generates sql code to change the datatype of a column.sqlCreateColumn(String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue, boolean primaryKey, boolean withTrailingComma) Generates the attribute definition of a CREATE TABLE statement.sqlCreateColumnComment(String tableName, String columnName, String comment) Generates SQL code to create the comment for an attribute.sqlCreateTableComment(String tableName, String comment) Generates SQL code to create the comment for a table.sqlCreateTableIntro(String tableName, String comment) Generates the first line of a CREATE TABLE statement.sqlRenameIndex(String tableName, String oldIndexName, String newIndexName) Generates sql code to rename an index.sqlTypeToString(SqlType sqlType, int size) Converts the java SQL-type to the database type name.Methods inherited from class org.tentackle.sql.backends.AbstractSql2003Backend
buildSelectSql, getReservedWords, isSequenceSupported, setLeadingSelectParameters, setTrailingSelectParameters, sqlCreateSequence, sqlNextFromSequenceMethods inherited from class org.tentackle.sql.backends.AbstractSql92Backend
getCoalesceKeyword, isLeadingSelectMissing, sqlCreateForeignKey, sqlCreateSequenceComment, sqlDropForeignKeyMethods inherited from class org.tentackle.sql.backends.AbstractBackend
assertValidName, buildSelectSql, columnTypeNullDefaultToString, columnTypeToString, createColumnMetaData, createConnection, createIndexColumnMetaData, createIndexMetaData, createPassword, createScriptRunner, createTableMetaData, extractWhereClause, getBlockCommentBegin, getBlockCommentBegins, getBlockCommentEnd, getBlockCommentEnds, getDefaultSchema, getDefaultSize, getDummySelect, getEmptyString, getMaxScale, getMetaData, getMigrationStrategy, getModelMetaData, getSingleLineComment, getSingleLineComments, getStatementSeparator, getStatementSeparators, getTableHeaders, getTableMetaData, isAliasRequiredForSubSelect, isArrayOperatorSupported, isClobSupported, isCommunicationLinkException, isConstraintException, isDatabaseInMemory, isDefaultEqual, isDeprecated, isDropIfExistsEnabled, isExceptionErrorCodeMatching, isExceptionStateMatching, isExceptionStateStartingWith, isExpressionReferringToTableBeingUpdatedSupported, isExtraCommitRequired, isFilteredIndexSupported, isMatchingName, isPosixEscapeSyntaxSupported, isReleaseSavepointSupported, isReservedSchemaName, isReservedTableName, isReservedWord, isSchemaSupported, isTemporaryName, isTxRequiredForFetchsize, isUUIDSupported, normalizeDefault, optimizeSql, setArray, setDropIfExistsEnabled, sqlAlterColumnComment, sqlAlterColumnDefault, sqlAlterColumnNullConstraint, sqlAlterTableComment, sqlAsBeforeTableAlias, sqlComment, sqlCreateIndex, sqlCreateSchema, sqlCreateTableAttributeWithoutComment, sqlCreateTableClosing, sqlCreateTableIntroWithoutComment, sqlDropColumn, sqlDropIndex, sqlDropTable, sqlFunction, sqlJoin, sqlJoinSelects, sqlJoinSelects, sqlRenameAndAlterColumnType, sqlRenameColumn, sqlRenameTable, sqlUpdateToNotNull, toInternalType, toQuotedString, toString, validateVersion, valueToLiteral
-
Constructor Details
-
Db2
public Db2()Creates the DB2 backend.
-
-
Method Details
-
isMatchingUrl
Description copied from interface:BackendChecks whether the backend belongs to the given jdbc url.
If multiple backend implementations are provided for the same database type, only one backend should match the URL. The others must be selected via name.- Parameters:
url- the jdbc url- Returns:
- true if matches
-
getName
Description copied from interface:BackendGets the name of the backend.- Returns:
- the name
-
getDriverClassName
Description copied from interface:BackendGets the JDBC driver class name.- Returns:
- the class name
-
getMaxSize
Description copied from interface:BackendReturns the maximum size for a given SQL-type.- Specified by:
getMaxSizein interfaceBackend- Overrides:
getMaxSizein classAbstractBackend- Parameters:
sqlType- the SQL-type- Returns:
- the maximum size, 0 if unlimited, -1 if type without size
-
getBackendId
Description copied from interface:BackendDetermines the unique id or name used by the backend for a given connection.Useful to figure out the corresponding
ManagedConnectionfrom the backend's logfiles.- Parameters:
connection- the jdbc connection- Returns:
- the backend id, null if none
-
isTransientTransactionException
Description copied from interface:BackendDetermines whether exception is transient and retrying the transaction may succeed.
Typical transient exceptions are thrown when a deadlock is detected or when serialized transaction isolation is used.Other transient errors are not covered by this method (e.g. connection timeouts, etc...).
- Specified by:
isTransientTransactionExceptionin interfaceBackend- Overrides:
isTransientTransactionExceptionin classAbstractBackend- Parameters:
ex- the exception- Returns:
- true if retrying the transaction may succeed
-
isFunctionBasedIndexSupported
public boolean isFunctionBasedIndexSupported()Description copied from interface:BackendReturns whether function based indexes are supported.- Specified by:
isFunctionBasedIndexSupportedin interfaceBackend- Overrides:
isFunctionBasedIndexSupportedin classAbstractBackend- Returns:
- true if supported
-
sqlCreateTableIntro
Description copied from interface:BackendGenerates the first line of a CREATE TABLE statement.- Specified by:
sqlCreateTableIntroin interfaceBackend- Overrides:
sqlCreateTableIntroin classAbstractBackend- Parameters:
tableName- the tablename with optional schema separated by a dotcomment- optional comment, null if none- Returns:
- the SQL code including the opening bracket
-
sqlTypeToString
Description copied from interface:BackendConverts the java SQL-type to the database type name.- Specified by:
sqlTypeToStringin interfaceBackend- Overrides:
sqlTypeToStringin classAbstractBackend- Parameters:
sqlType- the java sql typesize- the column's size- Returns:
- the corresponding type string
-
jdbcTypeToSqlType
Description copied from interface:BackendConverts the JDBC data type integer to a tentackle backend SqlTypes.There may be more than one sqltype returned!
- Specified by:
jdbcTypeToSqlTypein interfaceBackend- Overrides:
jdbcTypeToSqlTypein classAbstractBackend- Parameters:
jdbcType- the jdbc data typesize- the column sizescale- the column's scale- Returns:
- the SqlTypes, empty array if no mapping available or no exact match (not generated by TT)
- See Also:
-
sqlCreateColumn
public String sqlCreateColumn(String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue, boolean primaryKey, boolean withTrailingComma) Description copied from interface:BackendGenerates the attribute definition of a CREATE TABLE statement.- Specified by:
sqlCreateColumnin interfaceBackend- Overrides:
sqlCreateColumnin classAbstractBackend- Parameters:
columnName- the database column namecomment- optional comment, null if nonesqlType- the JDBC sql typesize- the optional sizescale- the optional scalenullable- true if NULL, else NOT NULLdefaultValue- the optional default valueprimaryKey- true if this is a primary keywithTrailingComma- true if append a comma- Returns:
- the SQL code
-
sqlCreateTableComment
Description copied from interface:BackendGenerates SQL code to create the comment for a table.- Specified by:
sqlCreateTableCommentin interfaceBackend- Overrides:
sqlCreateTableCommentin classAbstractBackend- Parameters:
tableName- the table namecomment- optional comment, null if none- Returns:
- the SQL code, empty string if comment is created via
Backend.sqlCreateTableIntro(java.lang.String, java.lang.String)orBackend.sqlCreateTableClosing(java.lang.String, java.lang.String)
-
sqlCreateColumnComment
Description copied from interface:BackendGenerates SQL code to create the comment for an attribute.- Specified by:
sqlCreateColumnCommentin interfaceBackend- Overrides:
sqlCreateColumnCommentin classAbstractBackend- Parameters:
tableName- the table namecolumnName- the column namecomment- optional comment, null if none- Returns:
- the SQL code, empty string if comment is created via
Backend.sqlCreateColumn(java.lang.String, java.lang.String, org.tentackle.sql.SqlType, int, int, boolean, java.lang.Object, boolean, boolean)
-
sqlAddColumn
public String sqlAddColumn(String tableName, String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue) Description copied from interface:BackendGenerates sql code to add a column.- Specified by:
sqlAddColumnin interfaceBackend- Overrides:
sqlAddColumnin classAbstractBackend- Parameters:
tableName- the tablenamecolumnName- the new column namecomment- optional comment, null if nonesqlType- the JDBC sql typesize- the optional sizescale- the optional scalenullable- true if NULL, else NOT NULLdefaultValue- the optional default value- Returns:
- the SQL code
-
sqlAlterColumnType
public String sqlAlterColumnType(String tableName, String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue) Description copied from interface:BackendGenerates sql code to change the datatype of a column.- Specified by:
sqlAlterColumnTypein interfaceBackend- Overrides:
sqlAlterColumnTypein classAbstractBackend- Parameters:
tableName- the tablenamecolumnName- the new column namecomment- optional comment, null if nonesqlType- the JDBC sql typesize- the optional sizescale- the optional scalenullable- true if NULL, else NOT NULLdefaultValue- the optional default value- Returns:
- the SQL code
-
sqlRenameIndex
Description copied from interface:BackendGenerates sql code to rename an index.- Specified by:
sqlRenameIndexin interfaceBackend- Overrides:
sqlRenameIndexin classAbstractBackend- Parameters:
tableName- the tablenameoldIndexName- the old column namenewIndexName- the new column name- Returns:
- the SQL code, null if not supported by the backend, and we need to drop and create
-
isDropIfExistsSupported
protected boolean isDropIfExistsSupported()Description copied from class:AbstractBackendAdds "IF EXISTS" to drop clauses, if supported by the backend.
Makes migration a little more robust in case the same SQL scripts are applied to different databases than those used to generate the migration scripts for.- Overrides:
isDropIfExistsSupportedin classAbstractBackend- Returns:
- true if supported
-