java.lang.Object
org.tentackle.sql.backends.AbstractBackend
- All Implemented Interfaces:
Backend
- Direct Known Subclasses:
AbstractSql92Backend
Abstract parent class for backends.
- Author:
- harald
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final StringFields 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 TypeMethodDescriptionvoidassertValidName(SqlNameType nameType, String name) Asserts that given string is a valid name and usage.buildSelectSql(String sql, boolean writeLock, int limit, int offset) Creates a select statement string from an inner sql string.columnTypeNullDefaultToString(String columnName, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue) Converts an sqltype, size, scale, nullable and default value to a database type declaration.columnTypeToString(SqlType sqlType, int size, int scale) Converts an sqltype, size and scale to a database type declaration.createColumnMetaData(TableMetaData tableMetaData) Creates a column meta data instance.createConnection(String url, String username, char[] password) Creates a jdbc connection.createIndexColumnMetaData(IndexMetaData indexMetaData) Creates an index column meta data instance.createIndexMetaData(TableMetaData tableMetaData) Creates an index meta data instance.protected StringcreatePassword(char[] password) Creates a password string from a password char array.
Unfortunately,DriverManager.getConnection(String, String, String)requires the password as a string.createScriptRunner(Connection connection) Creates a script runner instance.createTableMetaData(ModelMetaData modelMetaData, String tableName) Creates a meta data instance.protected StringextractWhereClause(String sql, int whereOffset) Extracts the where clause from a given sql.Gets the string to begin a block comment in generated code.String[]Gets all strings that begin a block comment.Gets the string to end a block comment in generated code.String[]Gets all strings that end a block comment.Gets the keyword for the COALESCE function.Gets the default schema name.
Some backends store the objects in a default schema, if no explicit schema is given.intgetDefaultSize(SqlType sqlType) Gets the default size if no size given in model.Gets the empty string.
Some dbms (most famous: Oracle) handle empty strings as null.intgetMaxScale(SqlType sqlType, int size) Returns the maximum scale for a given SQL-type and size.intgetMaxSize(SqlType sqlType) Returns the maximum size for a given SQL-type.getMetaData(BackendInfo backendInfo) Gets the metadata from the backend.getMigrationStrategy(ColumnMetaData column, String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue) Determines the best migration strategy.getModelMetaData(DatabaseMetaData[] metaData, String[] schemas, String... tableNames) Retrieves the metadata.Gets the string to begin a single line comment in generated code.String[]Gets all strings that begin a single line comment.The SQL statement separator used in generated code.String[]The all SQL statement separators.getTableHeaders(DatabaseMetaData metaData) Gets all table headers for a given metadata.getTableMetaData(ModelMetaData modelMetaData, String tableName) Gets the table metadata for a given table name.booleanReturns whether backend requires an alias for a sub-select.booleanisArrayOperatorSupported(String operator) Returns whether the backend supports given array operator.booleanReturns whether the backend support CLOB types.
If not, it will be emulated as VARCHAR with the maximum possible size.booleanDetermines whether exception is a communication error.booleanDetermines whether exception is a constraint violation.booleanisDatabaseInMemory(String url) Returns whether the URL denotes an in-memory database.
Used by test suites to decide whether to populate the database before running the tests.booleanisDefaultEqual(ColumnMetaData column, SqlType sqlType, Object defaultValue) Checks whether the column's default corresponds to the model's default value.booleanReturns whether this backend is deprecated and superseded by a newer implementation.
Deprecated backends are omitted fromBackendFactory.getAllBackends().booleanReturns whether backend should addIF EXISTSfor generated DROPs.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.protected booleanisExceptionErrorCodeMatching(SQLException ex, int... codes) Checks if the exception's error code equals given number(s).protected booleanisExceptionStateMatching(SQLException ex, String... states) Checks if the exception's state equals given string(s).protected booleanisExceptionStateStartingWith(SQLException ex, String... prefixes) Checks if the exception's state starts with a given string(s).booleanDetermines whether backend allows expressions referring to tables being updated.booleanAccording to the JDBC-specsConnection.setAutoCommit(boolean)(true) should commit, but some backends require an extraConnection.commit().booleanReturns whether backend supports filtered indexes.booleanReturns whether function based indexes are supported.booleanisMatchingName(String name) Checks whether the backend belongs to the given name.booleanReturns whether the backend supports posix-style escapes via backslash.booleanReturns whether the backend supports releasing savepoints explicitly.booleanisReservedSchemaName(String name) Checks whether this is a reserved schema name for this backend.booleanisReservedTableName(String name) Checks whether this a reserved table name for this backend.
Applies only to tables.booleanisReservedWord(String word) Checks whether given string is a reserved word.booleanReturns whether the backend supports schemas.booleanisTemporaryName(String name) Checks whether this is a temporary name.
Returns whether an entity-, attribute- or index-name is temporary and should not be taken into account for migration or even used in the model.
Depending on the backend, temporary names start with an underscore or some other lead string.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.booleanChecks for the (postgres) bug that fetch-size is ignored if not within a new transaction.booleanReturns whether the backend supports theUUIDnatively via JDBC setObject/getObject.SqlType[]jdbcTypeToSqlType(int jdbcType, int size, int scale) Converts the JDBC data type integer to a tentackle backend SqlTypes.protected StringnormalizeDefault(String str) Normalize the default string to compare.optimizeSql(String sql) Optimize SQL code.
Replace WHERE 1=1 AND/OR to WHERE.voidsetArray(PreparedStatement statement, int pos, SqlType type, Collection<?> elements, String operator) Sets an array parameter in a prepared statement.voidsetDropIfExistsEnabled(boolean dropIfExistsEnabled) Some database support drop index/constraint/columnIF EXISTS.
This may be useful if migration scripts are generated against non-production databases that contain test indexes etc...
Notice, that those temporary DDL changes should better use the temporary prefix (seeBackend.isTemporaryName(String)) in order to be ignored by the migrator.sqlAddColumn(String tableName, String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue) Generates sql code to add a column.sqlAlterColumnComment(String tableName, String columnName, String comment) Generates SQL code to alter the comment for an attribute.sqlAlterColumnDefault(String tableName, String columnName, SqlType sqlType, Object defaultValue) Generates sql code to change the default value a column.sqlAlterColumnNullConstraint(String tableName, String columnName, boolean nullable) Generates sql code to change the null-constraint of 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.sqlAlterTableComment(String tableName, String comment) Generates SQL code to alter the comment for a table.Gets the string before the table alias.
In most databases the " AS " is optional and some don't accept it all.sqlComment(String text) Create comment sql code that is interpreted as a comment by the backend.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.sqlCreateIndex(String tableName, String indexName, boolean unique, String filterCondition, String... columnNames) Generates the CREATE INDEX statement.sqlCreateSchema(String name) Creates the SQL string to create a schema.protected StringsqlCreateTableAttributeWithoutComment(String columnName, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue, boolean primaryKey, boolean withTrailingComma) Generates the attribute definition of a CREATE TABLE statement.sqlCreateTableClosing(String tableName, String comment) Generates the last line of a CREATE TABLE statement.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.protected StringsqlCreateTableIntroWithoutComment(String tableName) Generates the first line of a CREATE TABLE statement.sqlDropColumn(String tableName, String columnName) Generates sql code to drop a column.sqlDropIndex(String schemaName, String tableNameWithoutSchema, String indexName) Generates the DROP INDEX statement.sqlDropTable(String schemaName, String tableNameWithoutSchema) Generates the DROP TABLE statement.sqlFunction(String functionName, String expression) Creates an sql function expression.Creates a join clause.voidsqlJoinSelects(JoinType type, boolean addColumns, StringBuilder select, String joinSelect, String joinSelectIdAlias, String joinAlias, String join) Generate SQL-code for joining a table to an existing select.sqlJoinSelects(JoinType type, boolean addColumns, String select, String joinSelect, String joinSelectIdAlias, String joinAlias, String join) Generate SQL-code for joining a table to an existing select.sqlRenameAndAlterColumnType(String tableName, String oldColumnName, String newColumnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue) Generates sql code to rename a column.sqlRenameColumn(String tableName, String oldColumnName, String newColumnName) Generates sql code to rename a column.sqlRenameIndex(String tableName, String oldIndexName, String newIndexName) Generates sql code to rename an index.sqlRenameTable(String tableName, String newTableName) Generate sql code to rename a table.sqlTypeToString(SqlType sqlType, int size) Converts the java SQL-type to the database type name.sqlUpdateToNotNull(String tableName, String columnName, SqlType sqlType, Object defaultValue, boolean migrated) Generates code to update a column to a non-null value.toInternalType(String sqlTypeName) Converts a backend specific type name to an internal name used by driver specific methods.toQuotedString(String str) Converts a string to a string enclosed in single quotes.toString()voidvalidateVersion(int databaseMajorVersion, int databaseMinorVersion) Verifies that the major and minor version of the connection's metadata is compatible with this backend.
If the latest backend is not compatible, the URL may be post-fixed with a backend type for an older version, for example:valueToLiteral(SqlType sqlType, Object value) Converts a type and value to a literal string.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.tentackle.sql.Backend
buildSelectSql, getBackendId, getDriverClassName, getName, getReservedWords, isMatchingUrl, isSequenceSupported, setLeadingSelectParameters, setTrailingSelectParameters, sqlCreateForeignKey, sqlCreateSequence, sqlCreateSequenceComment, sqlDropForeignKey, sqlNextFromSequence
-
Field Details
-
TYPE_BIGINT
- See Also:
-
TYPE_BIT
- See Also:
-
TYPE_BLOB
- See Also:
-
TYPE_CLOB
- See Also:
-
TYPE_BOOL
- See Also:
-
TYPE_BOOLEAN
- See Also:
-
TYPE_BYTEA
- See Also:
-
TYPE_BYTE
- See Also:
-
TYPE_CHAR_1
- See Also:
-
TYPE_DATE
- See Also:
-
TYPE_DATETIME
- See Also:
-
TYPE_DATETIME_YEAR_TO_SECOND
- See Also:
-
TYPE_DECIMAL
- See Also:
-
TYPE_DECIMAL_19
- See Also:
-
TYPE_DOUBLE
- See Also:
-
TYPE_DOUBLE_PRECISION
- See Also:
-
TYPE_FLOAT
- See Also:
-
TYPE_FLOAT4
- See Also:
-
TYPE_FLOAT8
- See Also:
-
TYPE_INT
- See Also:
-
TYPE_INT2
- See Also:
-
TYPE_INT4
- See Also:
-
TYPE_INT8
- See Also:
-
TYPE_INTEGER
- See Also:
-
TYPE_NCHAR_1
- See Also:
-
TYPE_NUMBER
- See Also:
-
TYPE_NUMBER_1
- See Also:
-
TYPE_NUMBER_5
- See Also:
-
TYPE_NUMBER_10
- See Also:
-
TYPE_NUMBER_19
- See Also:
-
TYPE_NVARCHAR
- See Also:
-
TYPE_NVARCHAR_MAX
- See Also:
-
TYPE_REAL
- See Also:
-
TYPE_TEXT
- See Also:
-
TYPE_TIME
- See Also:
-
TYPE_TIMESTAMP
- See Also:
-
TYPE_TINYINT
- See Also:
-
TYPE_SMALLFLOAT
- See Also:
-
TYPE_SMALLINT
- See Also:
-
TYPE_VARBINARY_MAX
- See Also:
-
TYPE_VARCHAR
- See Also:
-
TYPE_UUID
- See Also:
-
-
Constructor Details
-
AbstractBackend
public AbstractBackend()Parent constructor.
-
-
Method Details
-
isMatchingName
Description copied from interface:BackendChecks whether the backend belongs to the given name.- Specified by:
isMatchingNamein interfaceBackend- Parameters:
name- the backend's name- Returns:
- true if matches
-
validateVersion
public void validateVersion(int databaseMajorVersion, int databaseMinorVersion) Description copied from interface:BackendVerifies that the major and minor version of the connection's metadata is compatible with this backend.
If the latest backend is not compatible, the URL may be post-fixed with a backend type for an older version, for example:jdbc:oracle:thin:@//localhost:1521/xe|Oracle8
Throws
BackendExceptionif incompatible.- Specified by:
validateVersionin interfaceBackend- Parameters:
databaseMajorVersion- the major versiondatabaseMinorVersion- the minor version- See Also:
-
isDeprecated
public boolean isDeprecated()Description copied from interface:BackendReturns whether this backend is deprecated and superseded by a newer implementation.
Deprecated backends are omitted fromBackendFactory.getAllBackends().- Specified by:
isDeprecatedin interfaceBackend- Returns:
- true if deprecated
-
toString
-
createConnection
public Connection createConnection(String url, String username, char[] password) throws SQLException Description copied from interface:BackendCreates a jdbc connection.- Specified by:
createConnectionin interfaceBackend- Parameters:
url- the jdbc urlusername- the usernamepassword- the password- Returns:
- the created connection
- Throws:
SQLException- if connection could not be established
-
getMetaData
Description copied from interface:BackendGets the metadata from the backend.Important: the connection of the metadata is open!
- Specified by:
getMetaDatain interfaceBackend- Parameters:
backendInfo- the backend info- Returns:
- the metadata, may be more than one if schemas set in backendInfo
- Throws:
SQLException- if failed
-
getTableHeaders
public List<DatabaseMetaDataTableHeader> getTableHeaders(DatabaseMetaData metaData) throws SQLException Description copied from interface:BackendGets all table headers for a given metadata.- Specified by:
getTableHeadersin interfaceBackend- Parameters:
metaData- the database metadata- Returns:
- the list of table headers
- Throws:
SQLException- if failed
-
isTemporaryName
Description copied from interface:BackendChecks whether this is a temporary name.
Returns whether an entity-, attribute- or index-name is temporary and should not be taken into account for migration or even used in the model.
Depending on the backend, temporary names start with an underscore or some other lead string.- Specified by:
isTemporaryNamein interfaceBackend- Parameters:
name- the name- Returns:
- true temporary (invalid) name
-
isReservedWord
Checks whether given string is a reserved word.- Parameters:
word- the word- Returns:
- true if reserved word
-
isReservedTableName
Description copied from interface:BackendChecks whether this a reserved table name for this backend.
Applies only to tables. Not to be mixed up withBackend.getReservedWords().
Useful to avoid conflicts with naming conventions for backend specific things, such as snapshots.- Specified by:
isReservedTableNamein interfaceBackend- Parameters:
name- the table name- Returns:
- true if reserved by backend
-
isReservedSchemaName
Description copied from interface:BackendChecks whether this is a reserved schema name for this backend.- Specified by:
isReservedSchemaNamein interfaceBackend- Parameters:
name- the schema name- Returns:
- true if reserved by backend
-
getEmptyString
Description copied from interface:BackendGets the empty string.
Some dbms (most famous: Oracle) handle empty strings as null. In such cases the empty string (e.g. Oracle) may consist of a single blank, or whatever.- Specified by:
getEmptyStringin interfaceBackend- Returns:
- the empty string (never null)
-
sqlAsBeforeTableAlias
Description copied from interface:BackendGets the string before the table alias.
In most databases the " AS " is optional and some don't accept it all.- Specified by:
sqlAsBeforeTableAliasin interfaceBackend- Returns:
- the as-string
-
isAliasRequiredForSubSelect
public boolean isAliasRequiredForSubSelect()Description copied from interface:BackendReturns whether backend requires an alias for a sub-select.- Specified by:
isAliasRequiredForSubSelectin interfaceBackend- Returns:
- true if sub-select needs an alias.
-
isExtraCommitRequired
public boolean isExtraCommitRequired()Description copied from interface:BackendAccording to the JDBC-specsConnection.setAutoCommit(boolean)(true) should commit, but some backends require an extraConnection.commit().- Specified by:
isExtraCommitRequiredin interfaceBackend- Returns:
- true if the database needs an extra commit
-
sqlComment
Description copied from interface:BackendCreate comment sql code that is interpreted as a comment by the backend.- Specified by:
sqlCommentin interfaceBackend- Parameters:
text- any text, single or multiline- Returns:
- the comment, null if text was null
-
sqlJoin
Description copied from interface:BackendCreates a join clause. -
sqlFunction
Description copied from interface:BackendCreates an sql function expression.Example:
sqlFunction("max", CN_ID) --> "MAX(id)"- Specified by:
sqlFunctionin interfaceBackend- Parameters:
functionName- the function name, will be translated to uppercaseexpression- the expression, may be null- Returns:
- the sql code
-
getCoalesceKeyword
Description copied from interface:BackendGets the keyword for the COALESCE function.- Specified by:
getCoalesceKeywordin interfaceBackend- Returns:
- the keyword
-
isExpressionReferringToTableBeingUpdatedSupported
public boolean isExpressionReferringToTableBeingUpdatedSupported()Description copied from interface:BackendDetermines whether backend allows expressions referring to tables being updated.- Specified by:
isExpressionReferringToTableBeingUpdatedSupportedin interfaceBackend- Returns:
- true if allowed
-
isTxRequiredForFetchsize
public boolean isTxRequiredForFetchsize()Description copied from interface:BackendChecks for the (postgres) bug that fetch-size is ignored if not within a new transaction.- Specified by:
isTxRequiredForFetchsizein interfaceBackend- Returns:
- true if start tx
-
isConstraintException
Description copied from interface:BackendDetermines whether exception is a constraint violation.- Specified by:
isConstraintExceptionin interfaceBackend- Parameters:
ex- the exception- Returns:
- true if constraint violation
-
isCommunicationLinkException
Description copied from interface:BackendDetermines whether exception is a communication error.- Specified by:
isCommunicationLinkExceptionin interfaceBackend- Parameters:
ex- the exception- Returns:
- true if comlink down or alike
-
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- Parameters:
ex- the exception- Returns:
- true if retrying the transaction may succeed
-
getMaxSize
Description copied from interface:BackendReturns the maximum size for a given SQL-type.- Specified by:
getMaxSizein interfaceBackend- Parameters:
sqlType- the SQL-type- Returns:
- the maximum size, 0 if unlimited, -1 if type without size
-
getMaxScale
Description copied from interface:BackendReturns the maximum scale for a given SQL-type and size.- Specified by:
getMaxScalein interfaceBackend- Parameters:
sqlType- the SQL-typesize- the size, 0 if unlimited- Returns:
- the maximum scale, 0 if unlimited
-
getDefaultSize
Description copied from interface:BackendGets the default size if no size given in model.- Specified by:
getDefaultSizein interfaceBackend- Parameters:
sqlType- the SQL-type- Returns:
- the default size, 0 if no default size
-
getDefaultSchema
Description copied from interface:BackendGets the default schema name.
Some backends store the objects in a default schema, if no explicit schema is given.- Specified by:
getDefaultSchemain interfaceBackend- Returns:
- the default schema, null if none
-
getModelMetaData
public ModelMetaData getModelMetaData(DatabaseMetaData[] metaData, String[] schemas, String... tableNames) Description copied from interface:BackendRetrieves the metadata.- Specified by:
getModelMetaDatain interfaceBackend- Parameters:
metaData- the metadata for the whole databaseschemas- the optional schemas to filter tables, null if no filtertableNames- the tables of the model- Returns:
- the metadata, null if no such table
-
getTableMetaData
Description copied from interface:BackendGets the table metadata for a given table name.- Specified by:
getTableMetaDatain interfaceBackend- Parameters:
modelMetaData- the model the table belongs totableName- the model's table name- Returns:
- the table data
-
createTableMetaData
Description copied from interface:BackendCreates a meta data instance.- Specified by:
createTableMetaDatain interfaceBackend- Parameters:
modelMetaData- the whole metadatatableName- the model's table name- Returns:
- the meta data
-
createColumnMetaData
Description copied from interface:BackendCreates a column meta data instance.- Specified by:
createColumnMetaDatain interfaceBackend- Parameters:
tableMetaData- the table metadata this column belongs to- Returns:
- the meta data
-
createIndexMetaData
Description copied from interface:BackendCreates an index meta data instance.- Specified by:
createIndexMetaDatain interfaceBackend- Parameters:
tableMetaData- the table metadata this index belongs to- Returns:
- the meta data
-
createIndexColumnMetaData
Description copied from interface:BackendCreates an index column meta data instance.- Specified by:
createIndexColumnMetaDatain interfaceBackend- Parameters:
indexMetaData- the meta meta data this column belongs to- Returns:
- the meta data
-
sqlCreateTableIntro
Description copied from interface:BackendGenerates the first line of a CREATE TABLE statement.- Specified by:
sqlCreateTableIntroin interfaceBackend- Parameters:
tableName- the tablename with optional schema separated by a dotcomment- optional comment, null if none- Returns:
- the SQL code including the opening bracket
-
sqlCreateTableClosing
Description copied from interface:BackendGenerates the last line of a CREATE TABLE statement.- Specified by:
sqlCreateTableClosingin interfaceBackend- Parameters:
tableName- the tablename with optional schema separated by a dotcomment- optional comment, null if none- Returns:
- the SQL code including the closing bracket
-
sqlCreateTableComment
Description copied from interface:BackendGenerates SQL code to create the comment for a table.- Specified by:
sqlCreateTableCommentin interfaceBackend- 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)
-
sqlAlterTableComment
Description copied from interface:BackendGenerates SQL code to alter the comment for a table.- Specified by:
sqlAlterTableCommentin interfaceBackend- Parameters:
tableName- the table namecomment- optional comment, null to clear- Returns:
- the SQL code
-
columnTypeToString
Description copied from interface:BackendConverts an sqltype, size and scale to a database type declaration.- Specified by:
columnTypeToStringin interfaceBackend- Parameters:
sqlType- the SQL typesize- the sizescale- the scale- Returns:
- the type definition
-
columnTypeNullDefaultToString
public String columnTypeNullDefaultToString(String columnName, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue) Description copied from interface:BackendConverts an sqltype, size, scale, nullable and default value to a database type declaration.- Specified by:
columnTypeNullDefaultToStringin interfaceBackend- Parameters:
columnName- the database column namesqlType- the JDBC sql typesize- the optional sizescale- the optional scalenullable- true if NULL, else NOT NULLdefaultValue- the optional default value- Returns:
- the SQL code
-
valueToLiteral
Description copied from interface:BackendConverts a type and value to a literal string.- Specified by:
valueToLiteralin interfaceBackend- Parameters:
sqlType- the sql typevalue- the value- Returns:
- the constant
-
getStatementSeparators
Description copied from interface:BackendThe all SQL statement separators.- Specified by:
getStatementSeparatorsin interfaceBackend- Returns:
- the separators, usually
";"
-
getStatementSeparator
Description copied from interface:BackendThe SQL statement separator used in generated code.- Specified by:
getStatementSeparatorin interfaceBackend- Returns:
- the separator, usually
";"
-
getSingleLineComments
Description copied from interface:BackendGets all strings that begin a single line comment.- Specified by:
getSingleLineCommentsin interfaceBackend- Returns:
- the single line comment strings, usually
"--"
-
getSingleLineComment
Description copied from interface:BackendGets the string to begin a single line comment in generated code.- Specified by:
getSingleLineCommentin interfaceBackend- Returns:
- the single line comment string, usually
"--"
-
getBlockCommentBegins
Description copied from interface:BackendGets all strings that begin a block comment.- Specified by:
getBlockCommentBeginsin interfaceBackend- Returns:
- the strings to begin a block comment, usually
"/*"
-
getBlockCommentBegin
Description copied from interface:BackendGets the string to begin a block comment in generated code.- Specified by:
getBlockCommentBeginin interfaceBackend- Returns:
- the string to begin a block comment, usually
"/*"
-
getBlockCommentEnds
Description copied from interface:BackendGets all strings that end a block comment.- Specified by:
getBlockCommentEndsin interfaceBackend- Returns:
- the strings to end a block comment, usually
"*/"
-
getBlockCommentEnd
Description copied from interface:BackendGets the string to end a block comment in generated code.- Specified by:
getBlockCommentEndin interfaceBackend- Returns:
- the string to end a block comment, usually
"*/"
-
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- 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
-
isDefaultEqual
Description copied from interface:BackendChecks whether the column's default corresponds to the model's default value.- Specified by:
isDefaultEqualin interfaceBackend- Parameters:
column- the column to inspectsqlType- the sql typedefaultValue- the model's default value- Returns:
- true if same
-
getMigrationStrategy
public MigrationStrategy[] getMigrationStrategy(ColumnMetaData column, String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue) Description copied from interface:BackendDetermines the best migration strategy.- Specified by:
getMigrationStrategyin interfaceBackend- Parameters:
column- old column meta datacolumnName- new column namecomment- new commentsqlType- new sql typesize- new sizescale- new scalenullable- new nullabledefaultValue- new default- Returns:
- the strategies in order to achieve the migration
-
sqlRenameTable
Description copied from interface:BackendGenerate sql code to rename a table.- Specified by:
sqlRenameTablein interfaceBackend- Parameters:
tableName- the old tablename (with leading schema, if any)newTableName- the new tablename (without schema)- Returns:
- the SQL code
-
sqlRenameColumn
Description copied from interface:BackendGenerates sql code to rename a column.- Specified by:
sqlRenameColumnin interfaceBackend- Parameters:
tableName- the tablenameoldColumnName- the old column namenewColumnName- the new column name- Returns:
- the SQL code, null if full spec sqlRenameAndAlterColumnType below is necessary
-
sqlRenameIndex
Description copied from interface:BackendGenerates sql code to rename an index.- Specified by:
sqlRenameIndexin interfaceBackend- 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
-
sqlRenameAndAlterColumnType
public String sqlRenameAndAlterColumnType(String tableName, String oldColumnName, String newColumnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue) Description copied from interface:BackendGenerates sql code to rename a column.- Specified by:
sqlRenameAndAlterColumnTypein interfaceBackend- Parameters:
tableName- the tablenameoldColumnName- the old column namenewColumnName- 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
-
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- 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
-
sqlDropColumn
Description copied from interface:BackendGenerates sql code to drop a column.- Specified by:
sqlDropColumnin interfaceBackend- Parameters:
tableName- the tablenamecolumnName- the new column name- 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- 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
-
sqlAlterColumnNullConstraint
Description copied from interface:BackendGenerates sql code to change the null-constraint of a column.- Specified by:
sqlAlterColumnNullConstraintin interfaceBackend- Parameters:
tableName- the tablenamecolumnName- the new column namenullable- true if NULL, else NOT NULL- Returns:
- the SQL code, null if need
Backend.sqlAlterColumnType(java.lang.String, java.lang.String, java.lang.String, org.tentackle.sql.SqlType, int, int, boolean, java.lang.Object)
-
sqlUpdateToNotNull
public String sqlUpdateToNotNull(String tableName, String columnName, SqlType sqlType, Object defaultValue, boolean migrated) Description copied from interface:BackendGenerates code to update a column to a non-null value.- Specified by:
sqlUpdateToNotNullin interfaceBackend- Parameters:
tableName- the tablenamecolumnName- the column namesqlType- the sql typedefaultValue- the optional default value if defined in the modelmigrated- true if column is migrated, false if added- Returns:
- the SQL code
-
sqlAlterColumnDefault
public String sqlAlterColumnDefault(String tableName, String columnName, SqlType sqlType, Object defaultValue) Description copied from interface:BackendGenerates sql code to change the default value a column.- Specified by:
sqlAlterColumnDefaultin interfaceBackend- Parameters:
tableName- the tablenamecolumnName- the new column namesqlType- the JDBC sql typedefaultValue- the optional default value- Returns:
- the SQL code, null if need
Backend.sqlAlterColumnType(java.lang.String, java.lang.String, java.lang.String, org.tentackle.sql.SqlType, int, int, boolean, java.lang.Object)
-
sqlCreateColumnComment
Description copied from interface:BackendGenerates SQL code to create the comment for an attribute.- Specified by:
sqlCreateColumnCommentin interfaceBackend- 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)
-
sqlAlterColumnComment
Description copied from interface:BackendGenerates SQL code to alter the comment for an attribute.- Specified by:
sqlAlterColumnCommentin interfaceBackend- Parameters:
tableName- the table namecolumnName- the column namecomment- optional comment, null to clear- Returns:
- the SQL code, null if
Backend.sqlRenameAndAlterColumnType(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.tentackle.sql.SqlType, int, int, boolean, java.lang.Object)must be used instead
-
sqlTypeToString
Description copied from interface:BackendConverts the java SQL-type to the database type name.- Specified by:
sqlTypeToStringin interfaceBackend- Parameters:
sqlType- the java sql typesize- the column's size- Returns:
- the corresponding type string
-
sqlCreateIndex
public String sqlCreateIndex(String tableName, String indexName, boolean unique, String filterCondition, String... columnNames) Description copied from interface:BackendGenerates the CREATE INDEX statement.- Specified by:
sqlCreateIndexin interfaceBackend- Parameters:
tableName- the table nameindexName- the name of the indexunique- true if index is uniquefilterCondition- the filter condition (null if none)columnNames- the column names (with a leading '-' if descending). Simple function-based indexes are also supported.- Returns:
- the SQL code
-
sqlDropIndex
Description copied from interface:BackendGenerates the DROP INDEX statement.- Specified by:
sqlDropIndexin interfaceBackend- Parameters:
schemaName- the optional schema, null if nonetableNameWithoutSchema- the table name without the schemaindexName- the name of the index- Returns:
- the SQL code
-
sqlDropTable
Description copied from interface:BackendGenerates the DROP TABLE statement.- Specified by:
sqlDropTablein interfaceBackend- Parameters:
schemaName- the optional schema, null if nonetableNameWithoutSchema- the table name without the schema- Returns:
- the SQL code
-
sqlJoinSelects
public void sqlJoinSelects(JoinType type, boolean addColumns, StringBuilder select, String joinSelect, String joinSelectIdAlias, String joinAlias, String join) Description copied from interface:BackendGenerate SQL-code for joining a table to an existing select.- Specified by:
sqlJoinSelectsin interfaceBackend- Parameters:
type- the join typeaddColumns- true if columns of joined table should be added to the result setselect- the original select statementjoinSelect- the select to join with the original sql or just a tablenamejoinSelectIdAlias- extra id alias to add to the joined select, null if nonejoinAlias- the alias of the joined selectjoin- the join clause
-
assertValidName
Description copied from interface:BackendAsserts that given string is a valid name and usage.- Specified by:
assertValidNamein interfaceBackend- Parameters:
nameType- the type/usage of the namename- the name
-
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- 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:
-
toQuotedString
Description copied from interface:BackendConverts a string to a string enclosed in single quotes.- Specified by:
toQuotedStringin interfaceBackend- Parameters:
str- the string- Returns:
- the quoted string
-
optimizeSql
Description copied from interface:BackendOptimize SQL code.
Replace WHERE 1=1 AND/OR to WHERE. Any remaining WHERE 1=1 will be removed too. If you don't want your statements getting optimized, use lowercase for those keywords.- Specified by:
optimizeSqlin interfaceBackend- Parameters:
sql- the original sql code- Returns:
- the optimized sql code
-
buildSelectSql
Description copied from interface:BackendCreates a select statement string from an inner sql string.Same as
Backend.buildSelectSql(StringBuilder, boolean, int, int), but for strings.- Specified by:
buildSelectSqlin interfaceBackend- Parameters:
sql- the sql without leadingSELECT.writeLock- true select should write locklimit- the limit value, ≤ 0 if no limit clauseoffset- the offset value, ≤ 0 if no offset clause- Returns:
- the select statement
-
sqlJoinSelects
public String sqlJoinSelects(JoinType type, boolean addColumns, String select, String joinSelect, String joinSelectIdAlias, String joinAlias, String join) Description copied from interface:BackendGenerate SQL-code for joining a table to an existing select.- Specified by:
sqlJoinSelectsin interfaceBackend- Parameters:
type- the join typeaddColumns- true if columns of joined table should be added to the result setselect- the original select statementjoinSelect- the select to join with the original sql or just a tablenamejoinSelectIdAlias- extra id alias to add to the joined select, null if nonejoinAlias- the alias of the joined selectjoin- the join clause- Returns:
- the select statement
-
isReleaseSavepointSupported
public boolean isReleaseSavepointSupported()Description copied from interface:BackendReturns whether the backend supports releasing savepoints explicitly. If not, the savepoints are released when the transaction finishs.- Specified by:
isReleaseSavepointSupportedin interfaceBackend- Returns:
- true if release is supported, else false
-
isClobSupported
public boolean isClobSupported()Description copied from interface:BackendReturns whether the backend support CLOB types.
If not, it will be emulated as VARCHAR with the maximum possible size.- Specified by:
isClobSupportedin interfaceBackend- Returns:
- true if supported, false if treat as varchar
-
isUUIDSupported
public boolean isUUIDSupported()Description copied from interface:BackendReturns whether the backend supports theUUIDnatively via JDBC setObject/getObject.- Specified by:
isUUIDSupportedin interfaceBackend- Returns:
- true if supported, false if mapped to VARCHAR(36)
-
isFunctionBasedIndexSupported
public boolean isFunctionBasedIndexSupported()Description copied from interface:BackendReturns whether function based indexes are supported.- Specified by:
isFunctionBasedIndexSupportedin interfaceBackend- Returns:
- true if supported
-
isFilteredIndexSupported
public boolean isFilteredIndexSupported()Description copied from interface:BackendReturns whether backend supports filtered indexes.- Specified by:
isFilteredIndexSupportedin interfaceBackend- Returns:
- true if supported, false if model will raise an error if filtered index is used
-
setDropIfExistsEnabled
public void setDropIfExistsEnabled(boolean dropIfExistsEnabled) Description copied from interface:BackendSome database support drop index/constraint/columnIF EXISTS.
This may be useful if migration scripts are generated against non-production databases that contain test indexes etc...
Notice, that those temporary DDL changes should better use the temporary prefix (seeBackend.isTemporaryName(String)) in order to be ignored by the migrator.- Specified by:
setDropIfExistsEnabledin interfaceBackend- Parameters:
dropIfExistsEnabled- true ifIF EXISTSshould be used
-
isDropIfExistsEnabled
public boolean isDropIfExistsEnabled()Description copied from interface:BackendReturns whether backend should addIF EXISTSfor generated DROPs.- Specified by:
isDropIfExistsEnabledin interfaceBackend- Returns:
- true if
IF EXISTSis turned on and supported, false if not supported or turned off
-
toInternalType
Description copied from interface:BackendConverts a backend specific type name to an internal name used by driver specific methods.- Specified by:
toInternalTypein interfaceBackend- Parameters:
sqlTypeName- the original type used in SQL scripts- Returns:
- the JDBC internal name
-
isArrayOperatorSupported
Description copied from interface:BackendReturns whether the backend supports given array operator.- Specified by:
isArrayOperatorSupportedin interfaceBackend- Parameters:
operator- the array operator- Returns:
- true if supported
-
setArray
public void setArray(PreparedStatement statement, int pos, SqlType type, Collection<?> elements, String operator) throws SQLException Description copied from interface:BackendSets an array parameter in a prepared statement.- Specified by:
setArrayin interfaceBackend- Parameters:
statement- the prepared statementpos- the parameter position (starting at 1)type- the element's SQL typeelements- the elements to be converted to an array parameteroperator- the array operator- Throws:
SQLException
-
isSchemaSupported
public boolean isSchemaSupported()Description copied from interface:BackendReturns whether the backend supports schemas.- Specified by:
isSchemaSupportedin interfaceBackend- Returns:
- true if supported
- See Also:
-
sqlCreateSchema
Description copied from interface:BackendCreates the SQL string to create a schema.- Specified by:
sqlCreateSchemain interfaceBackend- Parameters:
name- the schema name- Returns:
- the SQL code
- See Also:
-
isPosixEscapeSyntaxSupported
public boolean isPosixEscapeSyntaxSupported()Description copied from interface:BackendReturns whether the backend supports posix-style escapes via backslash.- Specified by:
isPosixEscapeSyntaxSupportedin interfaceBackend- Returns:
- true if supported
-
createScriptRunner
Description copied from interface:BackendCreates a script runner instance.- Specified by:
createScriptRunnerin interfaceBackend- Parameters:
connection- the SQL-connection
-
isDatabaseInMemory
Description copied from interface:BackendReturns whether the URL denotes an in-memory database.
Used by test suites to decide whether to populate the database before running the tests.- Specified by:
isDatabaseInMemoryin interfaceBackend- Parameters:
url- the JDBC url- Returns:
- true if in-memory
-
sqlCreateTableIntroWithoutComment
Generates the first line of a CREATE TABLE statement.- Parameters:
tableName- the tablename with optional schema separated by a dot- Returns:
- the SQL code including the opening bracket
-
createPassword
Creates a password string from a password char array.
Unfortunately,DriverManager.getConnection(String, String, String)requires the password as a string. This method creates a string from a char array and optionally decrypts it. Encrypted passwords are detected by a leading~. If an unencrypted password must begin with a~, it must be escaped by a leading backslash\~.- Parameters:
password- the probably encrypted password- Returns:
- the cleartext password
-
normalizeDefault
Normalize the default string to compare.- Parameters:
str- the default value as a string, may be null- Returns:
- the normalized value, never null
-
sqlCreateTableAttributeWithoutComment
protected String sqlCreateTableAttributeWithoutComment(String columnName, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue, boolean primaryKey, boolean withTrailingComma) Generates the attribute definition of a CREATE TABLE statement.- Parameters:
columnName- the database column namesqlType- 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
-
extractWhereClause
Extracts the where clause from a given sql.- Parameters:
sql- the sql statementwhereOffset- the location of WHERE in sql- Returns:
- the where clause without the keyword WHERE
-
isDropIfExistsSupported
protected boolean isDropIfExistsSupported()Adds "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.- Returns:
- true if supported
-
isExceptionStateStartingWith
Checks if the exception's state starts with a given string(s).- Parameters:
ex- the exceptionprefixes- the prefixes the state starts with- Returns:
- true if so
-
isExceptionStateMatching
Checks if the exception's state equals given string(s).- Parameters:
ex- the exceptionstates- the states to check for- Returns:
- true if matches
-
isExceptionErrorCodeMatching
Checks if the exception's error code equals given number(s).- Parameters:
ex- the exceptioncodes- the error codes to check for- Returns:
- true if matches
-