Class Oracle

All Implemented Interfaces:
Backend

@Service(Backend.class) public class Oracle extends AbstractSql2003Backend
Backend for Oracle.
Author:
harald
  • Field Details

    • SQL_NESTED_SELECT_1

      public static final String SQL_NESTED_SELECT_1
      window function part 1.
      See Also:
    • SQL_NESTED_SELECT_2

      public static final String SQL_NESTED_SELECT_2
      window function part 2.
      See Also:
    • SQL_NESTED_SELECT_ROWNUM

      public static final String SQL_NESTED_SELECT_ROWNUM
      condition for limit and offset.
      See Also:
    • SQL_NESTED_SELECT_LIMIT

      public static final String SQL_NESTED_SELECT_LIMIT
      condition for limit and offset.
      See Also:
    • SQL_NESTED_SELECT_OFFSET

      public static final String SQL_NESTED_SELECT_OFFSET
      condition for limit and offset.
      See Also:
  • Constructor Details

    • Oracle

      public Oracle()
  • Method Details

    • dateString

      public static String dateString(Date date)
      Converts a date to a string.
      Parameters:
      date - the date
      Returns:
      a TO_DATE-date-string
    • timeString

      public static String timeString(Time time)
      Converts a time to a string.
      Parameters:
      time - the time
      Returns:
      a TO_DATE-time-string
    • timestampString

      public static String timestampString(Timestamp timestamp)
      Converts a timestamp to a string.
      Parameters:
      timestamp - the timestamp
      Returns:
      a TO_DATE-timestamp-string
    • getDriverClassName

      public String getDriverClassName()
      Description copied from interface: Backend
      Gets the JDBC driver class name.
      Returns:
      the class name
    • createConnection

      public Connection createConnection(String url, String username, char[] password) throws SQLException
      Description copied from interface: Backend
      Creates a jdbc connection.
      Specified by:
      createConnection in interface Backend
      Overrides:
      createConnection in class AbstractBackend
      Parameters:
      url - the jdbc url
      username - the username
      password - the password
      Returns:
      the created connection
      Throws:
      SQLException - if connection could not be established
    • isMatchingUrl

      public boolean isMatchingUrl(String url)
      Description copied from interface: Backend
      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. The others must be selected via name.
      Parameters:
      url - the jdbc url
      Returns:
      true if matches
    • getName

      public String getName()
      Description copied from interface: Backend
      Gets the name of the backend.
      Returns:
      the name
    • getBackendId

      public String getBackendId(Connection connection)
      Description copied from interface: Backend
      Determines the unique id or name used by the backend for a given connection.

      Useful to figure out the corresponding ManagedConnection from the backend's logfiles.

      Parameters:
      connection - the jdbc connection
      Returns:
      the backend id, null if none
    • isTemporaryName

      public boolean isTemporaryName(String name)
      Description copied from interface: Backend
      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.
      Specified by:
      isTemporaryName in interface Backend
      Overrides:
      isTemporaryName in class AbstractBackend
      Parameters:
      name - the name
      Returns:
      true temporary (invalid) name
    • isReservedTableName

      public boolean isReservedTableName(String name)
      Description copied from interface: Backend
      Checks whether this a reserved table name for this backend.
      Applies only to tables. Not to be mixed up with Backend.getReservedWords().
      Useful to avoid conflicts with naming conventions for backend specific things, such as snapshots.
      Specified by:
      isReservedTableName in interface Backend
      Overrides:
      isReservedTableName in class AbstractBackend
      Parameters:
      name - the table name
      Returns:
      true if reserved by backend
    • isReservedSchemaName

      public boolean isReservedSchemaName(String name)
      Description copied from interface: Backend
      Checks whether this is a reserved schema name for this backend.
      Specified by:
      isReservedSchemaName in interface Backend
      Overrides:
      isReservedSchemaName in class AbstractBackend
      Parameters:
      name - the schema name
      Returns:
      true if reserved by backend
    • assertValidName

      public void assertValidName(SqlNameType nameType, String name)
      Description copied from interface: Backend
      Asserts that given string is a valid name and usage.
      Specified by:
      assertValidName in interface Backend
      Overrides:
      assertValidName in class AbstractBackend
      Parameters:
      nameType - the type/usage of the name
      name - the name
    • isTransientTransactionException

      public boolean isTransientTransactionException(SQLException ex)
      Description copied from interface: Backend
      Determines 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:
      isTransientTransactionException in interface Backend
      Overrides:
      isTransientTransactionException in class AbstractBackend
      Parameters:
      ex - the exception
      Returns:
      true if retrying the transaction may succeed
    • getEmptyString

      public String getEmptyString()
      Description copied from interface: Backend
      Gets 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:
      getEmptyString in interface Backend
      Overrides:
      getEmptyString in class AbstractBackend
      Returns:
      the empty string (never null)
    • columnTypeNullDefaultToString

      public String columnTypeNullDefaultToString(String columnName, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue)
      Description copied from interface: Backend
      Converts an sqltype, size, scale, nullable and default value to a database type declaration.
      Specified by:
      columnTypeNullDefaultToString in interface Backend
      Overrides:
      columnTypeNullDefaultToString in class AbstractBackend
      Parameters:
      columnName - the database column name
      sqlType - the JDBC sql type
      size - the optional size
      scale - the optional scale
      nullable - true if NULL, else NOT NULL
      defaultValue - the optional default value
      Returns:
      the SQL code
    • valueToLiteral

      public String valueToLiteral(SqlType sqlType, Object value)
      Description copied from interface: Backend
      Conberts a type and value to a literal string.
      Specified by:
      valueToLiteral in interface Backend
      Overrides:
      valueToLiteral in class AbstractBackend
      Parameters:
      sqlType - the sql type
      value - the value
      Returns:
      the constant
    • createColumnMetaData

      public ColumnMetaData createColumnMetaData(TableMetaData tableMetaData)
      Description copied from interface: Backend
      Creates a column meta data instance.
      Specified by:
      createColumnMetaData in interface Backend
      Overrides:
      createColumnMetaData in class AbstractBackend
      Parameters:
      tableMetaData - the table meta data this column belongs to
      Returns:
      the meta data
    • sqlRequiresExtraCommit

      public boolean sqlRequiresExtraCommit()
      Description copied from interface: Backend
      According to the JDBC-specs Connection.setAutoCommit(boolean)(true) should commit, but some backends require an extra Connection.commit().
      Specified by:
      sqlRequiresExtraCommit in interface Backend
      Overrides:
      sqlRequiresExtraCommit in class AbstractBackend
      Returns:
      true if the database needs an extra commit
    • buildSelectSql

      public void buildSelectSql(StringBuilder sqlBuilder, boolean writeLock, int limit, int offset)
      Description copied from interface: Backend
      Creates a select statement string from an inner sql string.

      sqlBuilder is anything as FROM... WHERE... ORDER BY....
      It is decorated with a leading SELECT plus optional clauses like for the given parameters.

      Specified by:
      buildSelectSql in interface Backend
      Overrides:
      buildSelectSql in class AbstractSql2003Backend
      Parameters:
      sqlBuilder - the sql builder, initially containing the inner sql without leading SELECT.
      writeLock - true select should write lock
      limit - the limit value, ≤ 0 if no limit clause
      offset - the offset value, ≤ 0 if no offset clause
    • getMaxSize

      public int getMaxSize(SqlType sqlType)
      Description copied from interface: Backend
      Returns the maximum size for a given SQL-type.
      Specified by:
      getMaxSize in interface Backend
      Overrides:
      getMaxSize in class AbstractBackend
      Parameters:
      sqlType - the SQL-type
      Returns:
      the maximum size, 0 if unlimited, -1 if type without size
    • sqlTypeToString

      public String sqlTypeToString(SqlType sqlType, int size)
      Description copied from interface: Backend
      Converts the java SQL-type to the database type name.
      Specified by:
      sqlTypeToString in interface Backend
      Overrides:
      sqlTypeToString in class AbstractBackend
      Parameters:
      sqlType - the java sql type
      size - the column's size
      Returns:
      the corresponding type string
    • jdbcTypeToSqlType

      public SqlType[] jdbcTypeToSqlType(int jdbcType, int size, int scale)
      Description copied from interface: Backend
      Converts the JDBC data type integer to a tentackle backend SqlTypes.

      There may be more than one sqltype returned!

      Specified by:
      jdbcTypeToSqlType in interface Backend
      Overrides:
      jdbcTypeToSqlType in class AbstractBackend
      Parameters:
      jdbcType - the jdbc data type
      size - the column size
      scale - the column's scale
      Returns:
      the SqlTypes, empty array if no mapping available or no exact match (not generated by TT)
      See Also:
    • sqlNextFromSequene

      public String sqlNextFromSequene(String name)
      Description copied from interface: Backend
      Creates the SQL string to retrieve the next id from a sequence.
      Specified by:
      sqlNextFromSequene in interface Backend
      Overrides:
      sqlNextFromSequene in class AbstractSql2003Backend
      Parameters:
      name - the name of the sequence
      Returns:
      the SQL code
    • sqlRenameTable

      public String sqlRenameTable(String tableName, String newTableName)
      Description copied from interface: Backend
      Generate sql code to rename a table.
      Specified by:
      sqlRenameTable in interface Backend
      Overrides:
      sqlRenameTable in class AbstractBackend
      Parameters:
      tableName - the old tablename (with leading schema, if any)
      newTableName - the new tablename (without schema)
      Returns:
      the SQL code
    • sqlCreateTableComment

      public String sqlCreateTableComment(String tableName, String comment)
      Description copied from interface: Backend
      Generates SQL code to create the comment for a table.
      Specified by:
      sqlCreateTableComment in interface Backend
      Overrides:
      sqlCreateTableComment in class AbstractBackend
      Parameters:
      tableName - the table name
      comment - optional comment, null if none
      Returns:
      the SQL code, empty string if comment is created via Backend.sqlCreateTableIntro(java.lang.String, java.lang.String) or Backend.sqlCreateTableClosing(java.lang.String, java.lang.String)
    • sqlCreateColumnComment

      public String sqlCreateColumnComment(String tableName, String columnName, String comment)
      Description copied from interface: Backend
      Generates SQL code to create the comment for an attribute.
      Specified by:
      sqlCreateColumnComment in interface Backend
      Overrides:
      sqlCreateColumnComment in class AbstractBackend
      Parameters:
      tableName - the table name
      columnName - the column name
      comment - 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: Backend
      Generates sql code to add a column.
      Specified by:
      sqlAddColumn in interface Backend
      Overrides:
      sqlAddColumn in class AbstractBackend
      Parameters:
      tableName - the tablename
      columnName - the new column name
      comment - optional comment, null if none
      sqlType - the JDBC sql type
      size - the optional size
      scale - the optional scale
      nullable - true if NULL, else NOT NULL
      defaultValue - the optional default value
      Returns:
      the SQL code
    • sqlAlterColumnNullConstraint

      public String sqlAlterColumnNullConstraint(String tableName, String columnName, boolean nullable)
      Description copied from interface: Backend
      Generates sql code to change the null-constraint of a column.
      Specified by:
      sqlAlterColumnNullConstraint in interface Backend
      Overrides:
      sqlAlterColumnNullConstraint in class AbstractBackend
      Parameters:
      tableName - the tablename
      columnName - the new column name
      nullable - 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 String sqlAlterColumnType(String tableName, String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue)
      Description copied from interface: Backend
      Generates sql code to change the datatype of a column.
      Specified by:
      sqlAlterColumnType in interface Backend
      Overrides:
      sqlAlterColumnType in class AbstractBackend
      Parameters:
      tableName - the tablename
      columnName - the new column name
      comment - optional comment, null if none
      sqlType - the JDBC sql type
      size - the optional size
      scale - the optional scale
      nullable - true if NULL, else NOT NULL
      defaultValue - the optional default value
      Returns:
      the SQL code
    • sqlAlterColumnDefault

      public String sqlAlterColumnDefault(String tableName, String columnName, SqlType sqlType, Object defaultValue)
      Description copied from interface: Backend
      Generates sql code to change the default value a column.
      Specified by:
      sqlAlterColumnDefault in interface Backend
      Overrides:
      sqlAlterColumnDefault in class AbstractBackend
      Parameters:
      tableName - the tablename
      columnName - the new column name
      sqlType - the JDBC sql type
      defaultValue - 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 String extractWhereClause(String sql, int whereOffset)
      Description copied from class: AbstractBackend
      Extracts the where clause from a given sql.
      Overrides:
      extractWhereClause in class AbstractBackend
      Parameters:
      sql - the sql statement
      whereOffset - the location of WHERE in sql
      Returns:
      the where clause without the keyword WHERE