@Service(value=Backend.class) public class Oracle extends AbstractSql2003Backend
Date-conversion: Oracle does not use an index on a DATE-column if passed as a Timestamp-variable via a prepared statement, even if used in conjunction with an SQL-hint /*+ INDEX(...) In such cases the TO_DATE-function must be explicitly used.
Example:
if (getDb().isOracle()) {
query.add(" AND m." + CN_ZEITPUNKT + ">=" + OracleHelper.timestampString(par.vonZeitpunkt));
}
else {
query.add(" AND m." + CN_ZEITPUNKT + ">=?", par.vonZeitpunkt);
}
or:
if (getDb().isOracle()) {
query.add(" AND m." + CN_ZEITPUNKT + ">=TO_DATE(?,'" + OracleHelper.ORA_TIMESTAMP_FORMAT + "')",
OracleHelper.timestampFormat.format(par.vonZeitpunkt));
}
else {
query.add(" AND m." + CN_ZEITPUNKT + ">=?", par.vonZeitpunkt);
}
Rule: if possible use TIMESTAMP column type for a Timestamp-java attribute. In such a case
at least Oracle 10 uses the correct index and you don't need this workaround.| Modifier and Type | Field and Description |
|---|---|
static DateFormat |
dateFormat |
static String |
ORA_DATE_FORMAT |
static String |
ORA_TIME_FORMAT |
static String |
ORA_TIMESTAMP_FORMAT |
static String |
ORACLE_EMPTY_STRING |
static String |
SQL_NESTED_SELECT_1
window function part 1.
|
static String |
SQL_NESTED_SELECT_2
window function part 2.
|
static String |
SQL_NESTED_SELECT_LIMIT
condition for limit and offset.
|
static String |
SQL_NESTED_SELECT_OFFSET
condition for limit and offset.
|
static String |
SQL_NESTED_SELECT_ROWNUM
condition for limit and offset.
|
static DateFormat |
timeFormat |
static DateFormat |
timestampFormat |
SQL_WINDOW_1, SQL_WINDOW_2, SQL_WINDOW_LIMIT, SQL_WINDOW_OFFSETSQL_COALESCE, SQL_FOR_UPDATEEMPTY_STRING, TYPE_BIGINT, TYPE_BIT, TYPE_BLOB, TYPE_BOOL, TYPE_BOOLEAN, TYPE_BYTE, TYPE_BYTEA, TYPE_CHAR_1, 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_VARCHARSQL_ALLSTAR, SQL_AND, SQL_ANDNOT, SQL_COMMA, SQL_COMMA_PAR, SQL_DELETE, SQL_EQUAL, SQL_EQUAL_PAR, SQL_EQUAL_PAR_COMMA, SQL_EQUAL_ZERO, SQL_FROM, SQL_GREATER, SQL_GREATER_PAR, SQL_GREATEROREQUAL, SQL_GREATEROREQUAL_PAR, SQL_GROUPBY, 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 and Description |
|---|
Oracle() |
| Modifier and Type | Method and Description |
|---|---|
void |
assertValidName(String nameType,
String name)
Asserts that given string is a valid name and usage.
|
void |
buildSelectSql(StringBuilder sqlBuilder,
boolean writeLock,
int limit,
int offset)
Creates a select statement string from an inner sql string.
|
Connection |
createConnection(String url,
String username,
char[] password)
Creates a jdbc connection.
|
static String |
dateString(Date date)
Converts a date to a string.
|
protected String |
extractWhereClause(String sql,
int whereOffset)
Extracts the where clause from a given sql.
|
String |
getBackendId(Connection connection)
Determines the unique id or name used by the backend for a given connection.
|
String |
getDriverClassName()
Gets the JDBC driver class name.
|
String |
getEmptyString()
Gets the empty string.
|
int |
getMaxSize(SqlType sqlType)
Returns the maximum size for a given SQL-type.
|
String |
getName()
Gets the name of the backend.
|
boolean |
isMatchingUrl(String url)
Checks whether the backend belongs to the given jdbc url.
|
SqlType[] |
jdbcTypeToSqlType(int jdbcType,
int size,
int scale)
Converts the JDBC data type integer to a tentackle backend SqlTypes.
|
String |
sqlAddColumn(String tableName,
String columnName,
String comment,
SqlType sqlType,
int size,
int scale,
boolean nullable,
Object defaultValue)
Generates sql code to add a column.
|
String |
sqlAlterColumnDefault(String tableName,
String columnName,
SqlType sqlType,
Object defaultValue)
Generates sql code to change the default value a column.
|
String |
sqlAlterColumnNullConstraint(String tableName,
String columnName,
boolean nullable)
Generates sql code to change the null-constraint of a column.
|
String |
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.
|
String |
sqlCreateColumnComment(String tableName,
String columnName,
String comment)
Generates SQL code to create the comment for an attribute.
|
String |
sqlCreateTableComment(String tableName,
String comment)
Generates SQL code to create the comment for a table.
|
String |
sqlNextFromSequene(String name)
Creates the SQL string to retrieve the next id from a sequence.
|
boolean |
sqlRequiresExtraCommit()
According to the JDBC-specs
Connection.setAutoCommit(boolean)(true)
should commit, but some backends require an extra Connection.commit(). |
String |
sqlTypeToString(SqlType sqlType,
int size)
Converts the java SQL-type to the database type name.
|
static String |
timestampString(Timestamp timestamp)
Converts a timestamp to a string.
|
static String |
timeString(Time time)
Converts a time to a string.
|
String |
valueToLiteral(SqlType sqlType,
Object value)
Conberts a type and value to a literal string.
|
getReservedWords, setLeadingSelectParameters, setTrailingSelectParameters, supportsSequencesgetCoalesceKeyword, sqlCreateForeignKey, sqlDropForeignKeyallowsExpressionsReferringToTablesBeingUpdated, columnTypeNullDefaultToString, columnTypeToString, createColumnMetaData, createIndexColumnMetaData, createIndexMetaData, createTableMetaData, getDefaultSize, getMaxScale, getMetaData, getMigrationStrategy, getModelMetaData, getTableMetaData, isCommunicationLinkException, isConstraintException, isDefaultEqual, isMatchingName, needAliasForSubselect, needSetLongWorkaround, needTxForFetchsize, optimizeSql, sqlAlterColumnComment, sqlAlterTableComment, sqlAsBeforeTableAlias, sqlComment, sqlCreateColumn, sqlCreateIndex, sqlCreateTableAttributeWithoutComment, sqlCreateTableClosing, sqlCreateTableIntro, sqlCreateTableIntroWithoutComment, sqlDropColumn, sqlDropIndex, sqlFunction, sqlJoin, sqlJoinSelects, sqlRenameAndAlterColumnType, sqlRenameColumn, sqlResultSetIsClosedSupported, sqlUpdateToNotNull, toQuotedString, toStringpublic static final String SQL_NESTED_SELECT_1
public static final String SQL_NESTED_SELECT_2
public static final String SQL_NESTED_SELECT_ROWNUM
public static final String SQL_NESTED_SELECT_LIMIT
public static final String SQL_NESTED_SELECT_OFFSET
public static final String ORA_DATE_FORMAT
public static final String ORA_TIME_FORMAT
public static final String ORA_TIMESTAMP_FORMAT
public static final DateFormat dateFormat
public static final DateFormat timeFormat
public static final DateFormat timestampFormat
public static final String ORACLE_EMPTY_STRING
public static String dateString(Date date)
date - the datepublic static String timeString(Time time)
time - the timepublic static String timestampString(Timestamp timestamp)
timestamp - the timestamppublic String getDriverClassName()
Backendpublic Connection createConnection(String url, String username, char[] password) throws SQLException
BackendcreateConnection in interface BackendcreateConnection in class AbstractBackendurl - the jdbc urlusername - the usernamepassword - the passwordSQLException - if connection could not be establishedpublic boolean isMatchingUrl(String url)
Backendurl - the jdbc urlpublic String getName()
Backendpublic String getBackendId(Connection connection)
Backend
Useful to figure out the corresponding ManagedConnection from the backend's logfiles.
connection - the jdbc connectionpublic String getEmptyString()
BackendSome 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.
getEmptyString in interface BackendgetEmptyString in class AbstractBackendpublic String valueToLiteral(SqlType sqlType, Object value)
BackendvalueToLiteral in interface BackendvalueToLiteral in class AbstractBackendsqlType - the sql typevalue - the valuepublic boolean sqlRequiresExtraCommit()
BackendConnection.setAutoCommit(boolean)(true)
should commit, but some backends require an extra Connection.commit().sqlRequiresExtraCommit in interface BackendsqlRequiresExtraCommit in class AbstractBackendpublic void buildSelectSql(StringBuilder sqlBuilder, boolean writeLock, int limit, int offset)
Backend
sqlBuilder is anything as FROM... WHERE... ORDER BY....
It is decorated with a leading SELECT plus optional clauses
like for the given parameters.
buildSelectSql in interface BackendbuildSelectSql in class AbstractSql2003BackendsqlBuilder - the sql builder, initially containing the inner sql without leading SELECT.writeLock - true select should write locklimit - the limit value, ≤ 0 if no limit clauseoffset - the offset value, ≤ 0 if no offset clausepublic int getMaxSize(SqlType sqlType)
BackendgetMaxSize in interface BackendgetMaxSize in class AbstractBackendsqlType - the SQL-typepublic String sqlTypeToString(SqlType sqlType, int size)
BackendsqlTypeToString in interface BackendsqlTypeToString in class AbstractBackendsqlType - the java sql typesize - the column's sizepublic SqlType[] jdbcTypeToSqlType(int jdbcType, int size, int scale)
BackendThere may be more than one sqltype returned!
jdbcTypeToSqlType in interface BackendjdbcTypeToSqlType in class AbstractBackendjdbcType - the jdbc data typesize - the column sizescale - the column's scaleTypespublic void assertValidName(String nameType, String name)
BackendassertValidName in interface BackendassertValidName in class AbstractBackendnameType - the type/usage of the namename - the namepublic String sqlNextFromSequene(String name)
BackendsqlNextFromSequene in interface BackendsqlNextFromSequene in class AbstractSql2003Backendname - the name of the sequencepublic String sqlCreateTableComment(String tableName, String comment)
BackendsqlCreateTableComment in interface BackendsqlCreateTableComment in class AbstractBackendtableName - the table namecomment - optional comment, null if noneBackend.sqlCreateTableIntro(java.lang.String, java.lang.String) or Backend.sqlCreateTableClosing(java.lang.String, java.lang.String)public String sqlCreateColumnComment(String tableName, String columnName, String comment)
BackendsqlCreateColumnComment in interface BackendsqlCreateColumnComment in class AbstractBackendtableName - the table namecolumnName - the column namecomment - optional comment, null if noneBackend.sqlCreateColumn(java.lang.String, java.lang.String, org.tentackle.sql.SqlType, int, int, boolean, java.lang.Object, boolean, boolean)public String sqlAddColumn(String tableName, String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue)
BackendsqlAddColumn in interface BackendsqlAddColumn in class AbstractBackendtableName - 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 valuepublic String sqlAlterColumnNullConstraint(String tableName, String columnName, boolean nullable)
BackendsqlAlterColumnNullConstraint in interface BackendsqlAlterColumnNullConstraint in class AbstractBackendtableName - the tablenamecolumnName - the new column namenullable - true if NULL, else NOT NULLBackend.sqlAlterColumnType(java.lang.String, java.lang.String, java.lang.String, org.tentackle.sql.SqlType, int, int, boolean, java.lang.Object)public String sqlAlterColumnType(String tableName, String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue)
BackendsqlAlterColumnType in interface BackendsqlAlterColumnType in class AbstractBackendtableName - 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 valuepublic String sqlAlterColumnDefault(String tableName, String columnName, SqlType sqlType, Object defaultValue)
BackendsqlAlterColumnDefault in interface BackendsqlAlterColumnDefault in class AbstractBackendtableName - the tablenamecolumnName - the new column namesqlType - the JDBC sql typedefaultValue - the optional default valueBackend.sqlAlterColumnType(java.lang.String, java.lang.String, java.lang.String, org.tentackle.sql.SqlType, int, int, boolean, java.lang.Object)protected String extractWhereClause(String sql, int whereOffset)
AbstractBackendextractWhereClause in class AbstractBackendsql - the sql statementwhereOffset - the location of WHERE in sqlCopyright © 2016 Krake Softwaretechnik. All rights reserved.