- java.lang.Object
-
- org.tentackle.sql.backends.AbstractBackend
-
- org.tentackle.sql.backends.AbstractSql92Backend
-
- org.tentackle.sql.backends.AbstractSql2003Backend
-
- org.tentackle.sql.backends.Oracle
-
- All Implemented Interfaces:
Backend
@Service(Backend.class) public class Oracle extends AbstractSql2003Backend
Backend for Oracle.- Author:
- harald
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSQL_NESTED_SELECT_1window function part 1.static java.lang.StringSQL_NESTED_SELECT_2window function part 2.static java.lang.StringSQL_NESTED_SELECT_LIMITcondition for limit and offset.static java.lang.StringSQL_NESTED_SELECT_OFFSETcondition for limit and offset.static java.lang.StringSQL_NESTED_SELECT_ROWNUMcondition for limit and offset.-
Fields inherited from class org.tentackle.sql.backends.AbstractSql2003Backend
RESERVED_WORDS_SQL2003, SQL_WINDOW_1, SQL_WINDOW_2, SQL_WINDOW_LIMIT, SQL_WINDOW_OFFSET
-
Fields inherited from class org.tentackle.sql.backends.AbstractSql92Backend
RESERVED_WORDS_SQL92, SQL_COALESCE, SQL_FOR_UPDATE
-
Fields 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_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_VARBINARY_MAX, TYPE_VARCHAR
-
Fields 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_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 Constructor Description Oracle()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassertValidName(SqlNameType nameType, java.lang.String name)Asserts that given string is a valid name and usage.voidbuildSelectSql(java.lang.StringBuilder sqlBuilder, boolean writeLock, int limit, int offset)Creates a select statement string from an inner sql string.java.lang.StringcolumnTypeNullDefaultToString(java.lang.String columnName, SqlType sqlType, int size, int scale, boolean nullable, java.lang.Object defaultValue)Converts an sqltype, size, scale, nullable and default value to a database type declaration.ColumnMetaDatacreateColumnMetaData(TableMetaData tableMetaData)Creates a column meta data instance.java.sql.ConnectioncreateConnection(java.lang.String url, java.lang.String username, char[] password)Creates a jdbc connection.static java.lang.StringdateString(java.sql.Date date)Converts a date to a string.protected java.lang.StringextractWhereClause(java.lang.String sql, int whereOffset)Extracts the where clause from a given sql.java.lang.StringgetBackendId(java.sql.Connection connection)Determines the unique id or name used by the backend for a given connection.java.lang.StringgetDriverClassName()Gets the JDBC driver class name.java.lang.StringgetEmptyString()Gets the empty string.intgetMaxSize(SqlType sqlType)Returns the maximum size for a given SQL-type.java.lang.StringgetName()Gets the name of the backend.booleanisMatchingUrl(java.lang.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.booleanisReservedSchemaName(java.lang.String name)Checks whether this is a reserved schema name for this backend.booleanisReservedTableName(java.lang.String name)Checks whether this a reserved table name for this backend.
Applies only to tables.booleanisTemporaryName(java.lang.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.SqlType[]jdbcTypeToSqlType(int jdbcType, int size, int scale)Converts the JDBC data type integer to a tentackle backend SqlTypes.java.lang.StringsqlAddColumn(java.lang.String tableName, java.lang.String columnName, java.lang.String comment, SqlType sqlType, int size, int scale, boolean nullable, java.lang.Object defaultValue)Generates sql code to add a column.java.lang.StringsqlAlterColumnDefault(java.lang.String tableName, java.lang.String columnName, SqlType sqlType, java.lang.Object defaultValue)Generates sql code to change the default value a column.java.lang.StringsqlAlterColumnNullConstraint(java.lang.String tableName, java.lang.String columnName, boolean nullable)Generates sql code to change the null-constraint of a column.java.lang.StringsqlAlterColumnType(java.lang.String tableName, java.lang.String columnName, java.lang.String comment, SqlType sqlType, int size, int scale, boolean nullable, java.lang.Object defaultValue)Generates sql code to change the datatype of a column.java.lang.StringsqlCreateColumnComment(java.lang.String tableName, java.lang.String columnName, java.lang.String comment)Generates SQL code to create the comment for an attribute.java.lang.StringsqlCreateTableComment(java.lang.String tableName, java.lang.String comment)Generates SQL code to create the comment for a table.java.lang.StringsqlNextFromSequene(java.lang.String name)Creates the SQL string to retrieve the next id from a sequence.java.lang.StringsqlRenameTable(java.lang.String tableName, java.lang.String newTableName)Generate sql code to rename a table.booleansqlRequiresExtraCommit()According to the JDBC-specsConnection.setAutoCommit(boolean)(true) should commit, but some backends require an extraConnection.commit().java.lang.StringsqlTypeToString(SqlType sqlType, int size)Converts the java SQL-type to the database type name.static java.lang.StringtimestampString(java.sql.Timestamp timestamp)Converts a timestamp to a string.static java.lang.StringtimeString(java.sql.Time time)Converts a time to a string.java.lang.StringvalueToLiteral(SqlType sqlType, java.lang.Object value)Conberts a type and value to a literal string.-
Methods inherited from class org.tentackle.sql.backends.AbstractSql2003Backend
getReservedWords, setLeadingSelectParameters, setTrailingSelectParameters, supportsSequences
-
Methods inherited from class org.tentackle.sql.backends.AbstractSql92Backend
getCoalesceKeyword, sqlCreateForeignKey, sqlDropForeignKey
-
Methods inherited from class org.tentackle.sql.backends.AbstractBackend
allowsExpressionsReferringToTablesBeingUpdated, buildSelectSql, columnTypeToString, createIndexColumnMetaData, createIndexMetaData, createPassword, createTableMetaData, getDefaultSchema, getDefaultSize, getMaxScale, getMetaData, getMigrationStrategy, getModelMetaData, getTableHeaders, getTableMetaData, isArrayOperatorSupported, isClobSupported, isCommunicationLinkException, isConstraintException, isDefaultEqual, isDropIfExistsEnabled, isDropIfExistsSupported, isFilteredIndexSupported, isFunctionBasedIndexSupported, isMatchingName, isReleaseSavepointSupported, needAliasForSubselect, needSetLongWorkaround, needTxForFetchsize, normalizeDefault, optimizeSql, setArray, setDropIfExistsEnabled, sqlAlterColumnComment, sqlAlterTableComment, sqlAsBeforeTableAlias, sqlComment, sqlCreateColumn, sqlCreateIndex, sqlCreateTableAttributeWithoutComment, sqlCreateTableClosing, sqlCreateTableIntro, sqlCreateTableIntroWithoutComment, sqlDropColumn, sqlDropIndex, sqlDropTable, sqlFunction, sqlJoin, sqlJoinSelects, sqlJoinSelects, sqlRenameAndAlterColumnType, sqlRenameColumn, sqlRenameIndex, sqlResultSetIsClosedSupported, sqlUpdateToNotNull, toInternalType, toQuotedString, toString
-
-
-
-
Field Detail
-
SQL_NESTED_SELECT_1
public static final java.lang.String SQL_NESTED_SELECT_1
window function part 1.- See Also:
- Constant Field Values
-
SQL_NESTED_SELECT_2
public static final java.lang.String SQL_NESTED_SELECT_2
window function part 2.- See Also:
- Constant Field Values
-
SQL_NESTED_SELECT_ROWNUM
public static final java.lang.String SQL_NESTED_SELECT_ROWNUM
condition for limit and offset.- See Also:
- Constant Field Values
-
SQL_NESTED_SELECT_LIMIT
public static final java.lang.String SQL_NESTED_SELECT_LIMIT
condition for limit and offset.- See Also:
- Constant Field Values
-
SQL_NESTED_SELECT_OFFSET
public static final java.lang.String SQL_NESTED_SELECT_OFFSET
condition for limit and offset.- See Also:
- Constant Field Values
-
-
Method Detail
-
dateString
public static java.lang.String dateString(java.sql.Date date)
Converts a date to a string.- Parameters:
date- the date- Returns:
- a TO_DATE-date-string
-
timeString
public static java.lang.String timeString(java.sql.Time time)
Converts a time to a string.- Parameters:
time- the time- Returns:
- a TO_DATE-time-string
-
timestampString
public static java.lang.String timestampString(java.sql.Timestamp timestamp)
Converts a timestamp to a string.- Parameters:
timestamp- the timestamp- Returns:
- a TO_DATE-timestamp-string
-
getDriverClassName
public java.lang.String getDriverClassName()
Description copied from interface:BackendGets the JDBC driver class name.- Returns:
- the class name
-
createConnection
public java.sql.Connection createConnection(java.lang.String url, java.lang.String username, char[] password) throws java.sql.SQLExceptionDescription copied from interface:BackendCreates a jdbc connection.- Specified by:
createConnectionin interfaceBackend- Overrides:
createConnectionin classAbstractBackend- Parameters:
url- the jdbc urlusername- the usernamepassword- the password- Returns:
- the created connection
- Throws:
java.sql.SQLException- if connection could not be established
-
isMatchingUrl
public boolean isMatchingUrl(java.lang.String url)
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
public java.lang.String getName()
Description copied from interface:BackendGets the name of the backend.- Returns:
- the name
-
getBackendId
public java.lang.String getBackendId(java.sql.Connection connection)
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
-
isTemporaryName
public boolean isTemporaryName(java.lang.String name)
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- Overrides:
isTemporaryNamein classAbstractBackend- Parameters:
name- the name- Returns:
- true temporary (invalid) name
-
isReservedTableName
public boolean isReservedTableName(java.lang.String name)
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- Overrides:
isReservedTableNamein classAbstractBackend- Parameters:
name- the table name- Returns:
- true if reserved by backend
-
isReservedSchemaName
public boolean isReservedSchemaName(java.lang.String name)
Description copied from interface:BackendChecks whether this is a reserved schema name for this backend.- Specified by:
isReservedSchemaNamein interfaceBackend- Overrides:
isReservedSchemaNamein classAbstractBackend- Parameters:
name- the schema name- Returns:
- true if reserved by backend
-
assertValidName
public void assertValidName(SqlNameType nameType, java.lang.String name)
Description copied from interface:BackendAsserts that given string is a valid name and usage.- Specified by:
assertValidNamein interfaceBackend- Overrides:
assertValidNamein classAbstractBackend- Parameters:
nameType- the type/usage of the namename- the name
-
getEmptyString
public java.lang.String 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- Overrides:
getEmptyStringin classAbstractBackend- Returns:
- the empty string (never null)
-
columnTypeNullDefaultToString
public java.lang.String columnTypeNullDefaultToString(java.lang.String columnName, SqlType sqlType, int size, int scale, boolean nullable, java.lang.Object defaultValue)Description copied from interface:BackendConverts an sqltype, size, scale, nullable and default value to a database type declaration.- Specified by:
columnTypeNullDefaultToStringin interfaceBackend- Overrides:
columnTypeNullDefaultToStringin classAbstractBackend- 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
public java.lang.String valueToLiteral(SqlType sqlType, java.lang.Object value)
Description copied from interface:BackendConberts a type and value to a literal string.- Specified by:
valueToLiteralin interfaceBackend- Overrides:
valueToLiteralin classAbstractBackend- Parameters:
sqlType- the sql typevalue- the value- Returns:
- the constant
-
createColumnMetaData
public ColumnMetaData createColumnMetaData(TableMetaData tableMetaData)
Description copied from interface:BackendCreates a column meta data instance.- Specified by:
createColumnMetaDatain interfaceBackend- Overrides:
createColumnMetaDatain classAbstractBackend- Parameters:
tableMetaData- the table meta data this column belongs to- Returns:
- the meta data
-
sqlRequiresExtraCommit
public boolean sqlRequiresExtraCommit()
Description copied from interface:BackendAccording to the JDBC-specsConnection.setAutoCommit(boolean)(true) should commit, but some backends require an extraConnection.commit().- Specified by:
sqlRequiresExtraCommitin interfaceBackend- Overrides:
sqlRequiresExtraCommitin classAbstractBackend- Returns:
- true if the database needs an extra commit
-
buildSelectSql
public void buildSelectSql(java.lang.StringBuilder sqlBuilder, boolean writeLock, int limit, int offset)Description copied from interface:BackendCreates a select statement string from an inner sql string.sqlBuilderis anything asFROM... WHERE... ORDER BY....
It is decorated with a leadingSELECTplus optional clauses like for the given parameters.- Specified by:
buildSelectSqlin interfaceBackend- Overrides:
buildSelectSqlin classAbstractSql2003Backend- Parameters:
sqlBuilder- the sql builder, initially containing the inner 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
-
getMaxSize
public int getMaxSize(SqlType sqlType)
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
-
sqlTypeToString
public java.lang.String sqlTypeToString(SqlType sqlType, int size)
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
public SqlType[] jdbcTypeToSqlType(int jdbcType, int size, int scale)
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:
Types
-
sqlNextFromSequene
public java.lang.String sqlNextFromSequene(java.lang.String name)
Description copied from interface:BackendCreates the SQL string to retrieve the next id from a sequence.- Specified by:
sqlNextFromSequenein interfaceBackend- Overrides:
sqlNextFromSequenein classAbstractSql2003Backend- Parameters:
name- the name of the sequence- Returns:
- the SQL code
-
sqlRenameTable
public java.lang.String sqlRenameTable(java.lang.String tableName, java.lang.String newTableName)Description copied from interface:BackendGenerate sql code to rename a table.- Specified by:
sqlRenameTablein interfaceBackend- Overrides:
sqlRenameTablein classAbstractBackend- Parameters:
tableName- the old tablename (with leading schema, if any)newTableName- the new tablename (without schema)- Returns:
- the SQL code
-
sqlCreateTableComment
public java.lang.String sqlCreateTableComment(java.lang.String tableName, java.lang.String comment)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
public java.lang.String sqlCreateColumnComment(java.lang.String tableName, java.lang.String columnName, java.lang.String comment)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 java.lang.String sqlAddColumn(java.lang.String tableName, java.lang.String columnName, java.lang.String comment, SqlType sqlType, int size, int scale, boolean nullable, java.lang.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
-
sqlAlterColumnNullConstraint
public java.lang.String sqlAlterColumnNullConstraint(java.lang.String tableName, java.lang.String columnName, boolean nullable)Description copied from interface:BackendGenerates sql code to change the null-constraint of a column.- Specified by:
sqlAlterColumnNullConstraintin interfaceBackend- Overrides:
sqlAlterColumnNullConstraintin classAbstractBackend- 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)
-
sqlAlterColumnType
public java.lang.String sqlAlterColumnType(java.lang.String tableName, java.lang.String columnName, java.lang.String comment, SqlType sqlType, int size, int scale, boolean nullable, java.lang.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
-
sqlAlterColumnDefault
public java.lang.String sqlAlterColumnDefault(java.lang.String tableName, java.lang.String columnName, SqlType sqlType, java.lang.Object defaultValue)Description copied from interface:BackendGenerates sql code to change the default value a column.- Specified by:
sqlAlterColumnDefaultin interfaceBackend- Overrides:
sqlAlterColumnDefaultin classAbstractBackend- 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)
-
extractWhereClause
protected java.lang.String extractWhereClause(java.lang.String sql, int whereOffset)Description copied from class:AbstractBackendExtracts the where clause from a given sql.- Overrides:
extractWhereClausein classAbstractBackend- Parameters:
sql- the sql statementwhereOffset- the location of WHERE in sql- Returns:
- the where clause without the keyword WHERE
-
-