org.jpox.store.rdbms.adapter
Class DatabaseAdapter

java.lang.Object
  extended byorg.jpox.store.AbstractDatastoreAdapter
      extended byorg.jpox.store.rdbms.adapter.DatabaseAdapter
All Implemented Interfaces:
DatastoreAdapter, ExpressionConversionAdapter, ExpressionLogicSetAdapter, ExpressionMethodAdapter, ExpressionOperatorAdapter, ExpressionPatternAdapter, ExpressionSupportedFeaturesAdapter, RDBMSAdapter

public class DatabaseAdapter
extends AbstractDatastoreAdapter
implements RDBMSAdapter

Provides methods for adapting SQL language elements to a specific vendor's database. A database adapter is primarily used to map generic JDBC data types and SQL identifiers to specific types/identifiers suitable for the database in use.

Each database adapter corresponds to a particular combination of database, database version, driver, and driver version, as provided by the driver's own metadata. Database adapters cannot be constructed directly, but must be obtained using the RDBMSAdapterFactory class.

Version:
$Revision: 1.94 $
See Also:
RDBMSAdapterFactory, DatabaseMetaData

Field Summary
protected  java.lang.String catalogSeparator
          The String used to separate catalog and table name.
protected  int driverMajorVersion
          The major version number of the underlying driver.
protected  int driverMinorVersion
          The minor version number of the underlying driver.
protected  java.lang.String driverName
          the JDBC driver name
protected  java.lang.String driverVersion
          the JDBC driver version
protected static Localiser LOCALISER
           
protected  int maxColumnNameLength
          The maximum length to be used for a column name.
protected  int maxConstraintNameLength
          The maximum length to be used for a table constraint name.
protected  int maxIndexNameLength
          The maximum length to be used for an index name.
protected  int maxTableNameLength
          The maximum length to be used for a table name.
protected  boolean supportsCatalogsInTableDefinitions
          true if the database supports catalogs in table definition
protected  boolean supportsSchemasInTableDefinitions
          true if the database supports schemas in table definition
protected  java.util.HashMap typesByTypeNumber
          JDBC types, keyed by the type number.
 
Fields inherited from class org.jpox.store.AbstractDatastoreAdapter
datastoreMajorVersion, datastoreMinorVersion, datastoreProductName, datastoreProductVersion, datastoreRevisionVersion, dictionary, identifierCase, identifierQuoteString, LOCALISER_BASE, mappingManager, reservedKeywords
 
Fields inherited from interface org.jpox.store.DatastoreAdapter
IDENTIFIER_LOWER_CASE, IDENTIFIER_LOWER_CASE_QUOTED, IDENTIFIER_MIXED_CASE, IDENTIFIER_MIXED_CASE_QUOTED, IDENTIFIER_UPPER_CASE, IDENTIFIER_UPPER_CASE_QUOTED
 
Constructor Summary
protected DatabaseAdapter(Dictionary dictionary, java.sql.DatabaseMetaData metadata)
          Constructs a database adapter based on the given JDBC metadata.
 
Method Summary
 NumericExpression absMethod(ScalarExpression expr)
          Returns the appropriate SQL expression for the JDOQL Math.abs(EXPRESSION) method.
 NumericExpression acosMethod(ScalarExpression expr)
          Returns the appropriate SQL expression for the JDOQL Math.acos(EXPRESSION) method.
 NumericExpression asinMethod(ScalarExpression expr)
          Returns the appropriate SQL expression for the JDOQL Math.asin(EXPRESSION) method.
 NumericExpression atanMethod(ScalarExpression expr)
          Returns the appropriate SQL expression for the JDOQL Math.atan(EXPRESSION) method.
 java.lang.String cartersianProduct(LogicSetExpression Y)
          Generates a expression that represents the cartesian product of two sets: X and Y.
 NumericExpression ceilMethod(ScalarExpression expr)
          Returns the appropriate SQL expression for the JDOQL ceil(EXPRESSION) method.
 void closeConnection(java.sql.Connection conn)
          Method to close a Connection to the datastore.
 ScalarExpression concatOperator(ScalarExpression operand1, ScalarExpression operand2)
           If only one operand expression is of type String, then string conversion is performed on the other operand to produce a string at run time.
 NumericExpression cosMethod(ScalarExpression expr)
          Returns the appropriate SQL expression for the JDOQL Math.cos(EXPRESSION) method.
 boolean createIndexesBeforeForeignKeys()
          Whether to create indexes before foreign keys.
protected  void createTypeInfo(java.sql.DatabaseMetaData metadata)
          Creates TypeInfo objects for all of the data types and indexes them in the typesByTypeNumber map by their JDBC data type number.
 BooleanExpression endsWithMethod(ScalarExpression leftOperand, ScalarExpression rightOperand)
          Returns whether this string ends with the specified string.
 NumericExpression expMethod(ScalarExpression expr)
          Returns the appropriate SQL expression for the JDOQL Math.exp(EXPRESSION) method.
 NumericExpression floorMethod(ScalarExpression expr)
          Returns the appropriate SQL expression for the JDOQL Math.floor(EXPRESSION) method.
 java.lang.String getAddCandidateKeyStatement(CandidateKey ck)
          Returns the appropriate SQL to add a candidate key to its table.
 java.lang.String getAddColumnStatement(DatastoreContainerObject table, Column col)
          Accessor for the SQL statement to add a column to a table.
 java.lang.String getAddForeignKeyStatement(ForeignKey fk)
          Returns the appropriate SQL to add a foreign key to its table.
 java.lang.String getAddPrimaryKeyStatement(PrimaryKey pk)
          Returns the appropriate SQL to add a primary key to its table.
 java.lang.String getAutoIncrementKeyword()
          Accessor for the autoincrementing keyword for generating DDLs.
 java.lang.String getAutoIncrementStmt(java.lang.String tableName, java.lang.String columnName)
          Accessor for the autoincrementing sql statement for this datastore.
 java.lang.String getCatalogName(java.sql.Connection conn)
          Accessor for the Catalog Name for this datastore.
 java.lang.String getCatalogSeparator()
          Accessor for the catalog separator.
 java.sql.ResultSet getColumns(java.sql.Connection conn, java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Accessor for table and column information for a catalog/schema in this datastore.
 java.sql.ResultSet getColumns(java.sql.Connection conn, java.lang.String catalog, java.lang.String schema, java.lang.String table, java.lang.String columnNamePattern)
          Accessor for table and column information for a catalog/schema in this datastore.
 java.sql.Connection getConnection(javax.sql.DataSource[] ds, java.lang.String userName, java.lang.String password, int isolationLevel)
          Accessor for a Connection to the datastore.
 java.lang.String getContinuationString()
          Continuation string to use where the SQL statement goes over more than 1 line.
 java.lang.String getCreateIndexStatement(Index idx)
          Returns the appropriate SQL to add an index to its table.
 java.lang.String getCreateTableStatement(TableImpl table, Column[] columns, java.util.Properties props)
          Returns the appropriate SQL to create the given table having the given columns.
 NumericExpression getDayMethod(SqlTemporalExpression date)
          Returns the appropriate SQL expression for the JDOQL Date.getDay() method.
 java.lang.String getDropTableStatement(DatastoreContainerObject table)
          Returns the appropriate SQL to drop the given table.
 java.lang.String getDropViewStatement(ViewImpl view)
          Returns the appropriate SQL to drop the given view.
 java.lang.String getEscapeCharacter()
          The character for escaping characters in pattern expressions.
 ScalarExpression getEscapedPatternExpression(ScalarExpression patternExpression)
          The pattern string for representing one character.
 java.lang.String getEscapePatternExpression()
          The character for escaping characters in pattern expressions.
 java.sql.ResultSet getExistingIndexes(java.sql.Connection conn, java.sql.DatabaseMetaData dmd, java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Provide the existing indexes in the database for the table
 NumericExpression getHourMethod(SqlTemporalExpression time)
          Returns the appropriate SQL expression for the JDOQL Time.getHour() method.
 java.lang.String getInsertStatementForNoColumns(Table table)
          Method to return the INSERT statement to use when inserting into a table that has no columns specified.
 int getMaxColumnNameLength()
          Accessor for the maximum column name length permitted on this datastore.
 int getMaxConstraintNameLength()
          Accessor for the maximum constraint name length permitted on this datastore.
 int getMaxForeignKeys()
          Accessor for the maximum foreign keys by table permitted for this datastore.
 int getMaxIndexes()
          Accessor for the maximum indexes by schema permitted for this datastore.
 int getMaxIndexNameLength()
          Accessor for the maximum index name length permitted on this datastore.
 int getMaxTableNameLength()
          Accessor for the maximum table name length permitted on this datastore.
 NumericExpression getMinuteMethod(SqlTemporalExpression time)
          Returns the appropriate SQL expression for the JDOQL Time.getMinute() method.
 NumericExpression getMonthMethod(SqlTemporalExpression date)
          Returns the appropriate SQL expression for the JDOQL Date.getMonth() method.
protected  MappingManager getNewMappingManager()
          Accessor for a new Mapping Manager
 java.lang.String getNewUUIDFunction()
          The function to creates a unique value of type uniqueidentifier.
 java.lang.String getNonAnsiInnerJoinWhereClause(java.lang.String col1, java.lang.String col2)
          Accessor for the WHERE clause to add to provide an INNER JOIN using non-ANSI syntax.
 java.lang.String getNonAnsiLeftOuterJoinWhereClause(java.lang.String col1, java.lang.String col2)
          Accessor for the WHERE clause to add to provide a LEFT OUTER JOIN using non-ANSI syntax.
 java.lang.String getNonAnsiRightOuterJoinWhereClause(java.lang.String col1, java.lang.String col2)
          Accessor for the WHERE clause to add to provide a RIGHT OUTER JOIN using non-ANSI syntax.
 java.lang.String getOperatorConcat()
          An operator in a string expression that concatenates two or more character or binary strings, columns, or a combination of strings and column names into one expression (a string operator).
 java.lang.String getPatternExpressionAnyCharacter()
          The pattern string for representing one character that is expanded in word searches.
 java.lang.String getPatternExpressionZeroMoreCharacters()
          The pattern string for representing zero or more characters that is expanded in word searches.
 boolean getPlaceWithOptionAfterFromClause()
          Determines whether the getSelectWithLockOption() is to be placed right before the FROM clause, or at the end of the statement
 boolean getPlaceWithOptionWithinJoinClauses()
          Determines whether lock option has to be placed within JOIN clauses as well.
 java.lang.String getRangeByLimitSelectClause(long offset, long count)
          Method to return the SQL to append to the SELECT clause of a SELECT statement to handle restriction of ranges using the LIMIT keyword.
 java.lang.String getRangeByLimitWhereClause(long offset, long count)
          Method to return the SQL to append to the WHERE clause of a SELECT statement to handle restriction of ranges using the LIMIT keyword.
 java.lang.String getRangeByRowNumberColumn()
          Method to return the column name to use when handling ranges via a rownumber on the select.
 java.lang.String getSchemaName(java.sql.Connection conn)
          Accessor for the Schema Name for this datastore.
 NumericExpression getSecondMethod(SqlTemporalExpression time)
          Returns the appropriate SQL expression for the JDOQL Time.getSecond() method.
 java.lang.String getSelectNewUUIDStmt()
          The function to creates a unique value of type uniqueidentifier.
 java.lang.String getSelectWithLockOption()
          The option to specify in "SELECT ...
 java.lang.String getSequenceCreateStmt(java.lang.String sequence_name, java.lang.String min, java.lang.String max, java.lang.String start, java.lang.String increment, java.lang.String cache_size)
          Accessor for the sequence create statement for this datastore.
 java.lang.String getSequenceNextStmt(java.lang.String sequence_name)
          Accessor for the sequence statement to get the next id for this datastore.
 java.lang.String getSurrogateForEmptyStrings()
          Some databases, Oracle, treats an empty string (0 length) equals null
 java.sql.ResultSet getTables(java.sql.Connection conn, java.lang.String catalog, java.lang.String schema)
          Accessor for table information for a catalog/schema in this datastore.
 int getTransactionIsolationForSchemaCreation()
          Accessor for the transaction isolation level to use during schema creation.
 TypeInfo getTypeInfo(int dataType)
          Returns type information for the database type that best implements the given JDBC type.
 TypeInfo getTypeInfo(int[] candidateDataTypes)
          Returns type information for the first one of the given candidate JDBC data types supported by this database.
 int getUnlimitedLengthPrecisionValue(TypeInfo typeInfo)
          Returns the precision value to be used when creating string columns of "unlimited" length.
 NumericExpression getYearMethod(SqlTemporalExpression date)
          Returns the appropriate SQL expression for the JDOQL Date.getYear() method.
 boolean includeOrderByColumnsInSelect()
          Whether to include ORDER BY columns in a SELECT.
 boolean includeOrderByColumnsInSelectUsingAlias()
          Whether to specify ORDER BY columns in SELECTS using aliases.
 NumericExpression indexOfMethod(ScalarExpression source, ScalarExpression str, NumericExpression from)
          Returns the appropriate SQL expression for the JDOQL String.indexOf() method.
 void initialiseDatastore(java.lang.Object conn)
          Creates the auxiliary functions/procedures in the schema
 boolean isAutoIncrementingDataType(java.lang.String typeName)
          Verifies if the given typeName is auto incremented by the datastore.
 boolean isBitReallyBoolean()
          Accessor for whether a JDBC Types.BIT is really mapped in the datastore to a boolean field.
 boolean isNullEqualsEmptyStrings()
          Some databases, Oracle, treats an empty string (0 length) equals null
 boolean isSQLKeyword(java.lang.String word)
          Tests if a given string is a SQL key word.
 boolean isValidPrimaryKeyType(int datatype)
          Method to return whether the specified JDBC type is valid for use in a PrimaryKey.
 java.util.Iterator iteratorReservedWords()
          Iterator for the reserved words constructed from the method DataBaseMetaData.getSQLKeywords + standard SQL reserved words
 java.util.Iterator iteratorTypeInfo()
          Iterator for the TypeInfo objects constructed from the method DataBaseMetaData.getTypeInfo
 NumericExpression lengthMethod(StringExpression str)
          Returns the appropriate SQL expression for the JDOQL String.length() method.
 NumericExpression logMethod(ScalarExpression expr)
          Returns the appropriate SQL expression for the JDOQL Math.log(EXPRESSION) method.
 ColumnInfo newColumnInfo(java.sql.ResultSet rs)
          A factory for ColumnInfo objects.
 ExportedKeyInfo newExportedKeyInfo(java.sql.ResultSet rs)
          A factory for ForeignKeyInfo objects.
 ForeignKeyInfo newForeignKeyInfo(java.sql.ResultSet rs)
          A factory for ForeignKeyInfo objects.
 QueryExpression newQueryStatement(DatastoreContainerObject table, ClassLoaderResolver clr)
          Accessor for a new query statement.
 QueryExpression newQueryStatement(DatastoreContainerObject table, DatastoreIdentifier rangeVar, ClassLoaderResolver clr)
          Accessor for a new query statement.
 LogicSetExpression newTableExpression(QueryExpression qs, DatastoreContainerObject table, DatastoreIdentifier rangeVar)
          Returns a new TableExpression object appropriate for this DBMS.
protected  TypeInfo newTypeInfo(java.sql.ResultSet rs)
          A factory for TypeInfo objects.
protected  java.util.Set parseKeywordList(java.lang.String list)
          Utility method to parse a list of keywords and split them out into words.
 boolean requiresColumnDefaultsInitialising()
          Accessor for whether the column defaults need initialising for this datastore
 NumericExpression sinMethod(ScalarExpression expr)
          Returns the appropriate SQL expression for the JDOQL Math.sin(EXPRESSION) method.
 NumericExpression sqrtMethod(ScalarExpression expr)
          Returns the appropriate SQL expression for the JDOQL Math.sqrt(EXPRESSION) method.
 BooleanExpression startsWithMethod(ScalarExpression source, ScalarExpression str)
          Method to handle the starts with operation.
 StringExpression substringMethod(StringExpression str, NumericExpression begin)
          Returns the appropriate SQL expression for the JDOQL String.substring(str,begin) method.
 StringExpression substringMethod(StringExpression str, NumericExpression begin, NumericExpression end)
          Returns the appropriate SQL expression for the JDOQL String.substring(str,begin,end) method.
 boolean supportsAlterTableDropConstraint()
          Whether this datastore supports ALTER TABLE DROP constraints
 boolean supportsAlterTableDropForeignKeyConstraint()
          Whether this datastore supports ALTER TABLE DROP FOREIGN KEY constraints
 boolean supportsAnsiJoinSyntax()
          Accessor for whether the RDBMS supports ANSI join syntax.
 boolean supportsAutoIncrementColumnTypeSpecification()
          Whether we support auto-increment/identity keys with column type specification.
 boolean supportsAutoIncrementKeysNullSpecification()
          Whether we support autoincrementing keys with nullability specification.
 boolean supportsBooleanComparison()
          Whether we support Boolean comparisons.
 boolean supportsCatalogsInTableDefinitions()
          Whether this datastore supports the use of the catalog name in SQL table definitions (DDL).
 boolean supportsCheckConstraintsInEndCreateStatements()
          Whether this datastore supports the use of CHECK after the column definitions in CREATE TABLE statements (DDL).
 boolean supportsCheckInCreateStatements()
          Whether this datastore supports the use of CHECK in CREATE TABLE statements (DDL).
 boolean supportsDefaultBeforeNullInColumnOptions()
          Whether any DEFAULT tag will be before any NULL/NOT NULL in the column options.
 boolean supportsDefaultKeywordInColumnOptions()
          Whether we support DEFAULT tag in CREATE TABLE statements
 boolean supportsDefaultKeywordWithNotNullInColumnOptions()
          Whether we support DEFAULT tag together with NOT NULL in CREATE TABLE statements.
 boolean supportsDeferredConstraints()
          Whether this datastore supports deferred constraints.
 boolean supportsDistinctWithSelectForUpdate()
          Whether this datastore supports using DISTINCT when using SELECT ...
 boolean supportsEscapeExpressionInLikePredicate()
          Whether this datastore supports the use of the escape expression in like predicates
 boolean supportsExistsSyntax()
          Whether the RDBMS supports use of EXISTS syntax.
 boolean supportsForeignKeyDeleteAction(ForeignKey.FKAction action)
          Whether this datastore supports the specified foreign key delete action
 boolean supportsForeignKeyUpdateAction(ForeignKey.FKAction action)
          Whether this datastore supports the specified foreign key update action
 boolean supportsLockWithSelectForUpdate()
          Whether this datastore supports SELECT ...
 boolean supportsNullsInCandidateKeys()
          Whether we support NULLs in candidate keys.
 boolean supportsNullsKeywordInColumnOptions()
          Whether the database support NULLs in the column options for table creation.
 boolean supportsPrimaryKeyInCreateStatements()
          Whether the datastore supports specification of the primary key in CREATE TABLE statements.
 boolean supportsSchemasInTableDefinitions()
          Whether this datastore supports the use of the schema name in SQL table definitions (DDL).
 boolean supportsSettingBlobUsingSetString()
          Accessor for whether setting a BLOB value allows use of PreparedStatement.setString()
 boolean supportsSettingClobUsingSetString()
          Accessor for whether setting a CLOB value allows use of PreparedStatement.setString()
 boolean supportsStatementGetGeneratedKeys()
          Whether the datastore supports Statement.getGeneratedKeys()
 boolean supportsTransactionIsolationLevel(int isolationLevel)
          Accessor for whether the adapter supports the transaction isolation level
 boolean supportsUnionSyntax()
          Whether the RDBMS supports use of UNION syntax.
 boolean supportsUniqueConstraintsInEndCreateStatements()
          Whether this datastore supports the use of UNIQUE after the column definitions in CREATE TABLE statements (DDL).
 NumericExpression tanMethod(ScalarExpression expr)
          Returns the appropriate SQL expression for the JDOQL Math.tan(EXPRESSION) method.
 NumericExpression toNumericExpression(CharacterExpression expr)
          Returns the appropriate expression for the (int)'A' expression.
 java.lang.String toString()
          Overridden toString() method adding more information.
 StringExpression toStringExpression(NumericExpression expr)
          A String conversion that converts a numeric expression to string.
 StringExpression toStringExpression(StringLiteral expr)
          A String conversion that converts a String literal to String expression.
 StringExpression trimMethod(StringExpression str)
          Returns the appropriate SQL expression for the JDOQL String.trim(str) method.
 boolean useUnionAll()
          Union combines the results of two or more queries into a single result set.
 
Methods inherited from class org.jpox.store.AbstractDatastoreAdapter
getAdapterTime, getDatastoreMajorVersion, getDatastoreMinorVersion, getDictionary, getIdentifierCase, getIdentifierInAdapterCase, getIdentifierQuoteString, getMapping, getMapping, getMapping, getMapping, getMapping, getMappingManager, getMiliseconds, getTime, getVendorID, isReservedKeyword, loadDatastoreMapping, modOperator, supportsAutoIncrementFields, supportsQueryFetchSizeLowerThanOne, supportsSequences
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jpox.store.rdbms.adapter.RDBMSAdapter
getIdentifierQuoteString, supportsSequences
 
Methods inherited from interface org.jpox.store.DatastoreAdapter
getAdapterTime, getDatastoreMajorVersion, getDatastoreMinorVersion, getDictionary, getIdentifierCase, getIdentifierInAdapterCase, getMapping, getMapping, getMapping, getMapping, getMappingManager, getVendorID, isReservedKeyword, loadDatastoreMapping, modOperator, supportsAutoIncrementFields, supportsQueryFetchSizeLowerThanOne
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER

driverName

protected java.lang.String driverName
the JDBC driver name


driverVersion

protected java.lang.String driverVersion
the JDBC driver version


driverMajorVersion

protected int driverMajorVersion
The major version number of the underlying driver.


driverMinorVersion

protected int driverMinorVersion
The minor version number of the underlying driver.


maxTableNameLength

protected int maxTableNameLength
The maximum length to be used for a table name.


maxConstraintNameLength

protected int maxConstraintNameLength
The maximum length to be used for a table constraint name.


maxIndexNameLength

protected int maxIndexNameLength
The maximum length to be used for an index name.


maxColumnNameLength

protected int maxColumnNameLength
The maximum length to be used for a column name.


supportsCatalogsInTableDefinitions

protected boolean supportsCatalogsInTableDefinitions
true if the database supports catalogs in table definition


supportsSchemasInTableDefinitions

protected boolean supportsSchemasInTableDefinitions
true if the database supports schemas in table definition


catalogSeparator

protected java.lang.String catalogSeparator
The String used to separate catalog and table name.


typesByTypeNumber

protected final java.util.HashMap typesByTypeNumber
JDBC types, keyed by the type number. Allowing for overriding by RDBMS.

Constructor Detail

DatabaseAdapter

protected DatabaseAdapter(Dictionary dictionary,
                          java.sql.DatabaseMetaData metadata)
Constructs a database adapter based on the given JDBC metadata.

Parameters:
metadata - the database metadata.
Method Detail

initialiseDatastore

public void initialiseDatastore(java.lang.Object conn)
Creates the auxiliary functions/procedures in the schema

Specified by:
initialiseDatastore in interface DatastoreAdapter
Parameters:
conn - the connection to the datastore

getMaxTableNameLength

public int getMaxTableNameLength()
Accessor for the maximum table name length permitted on this datastore.

Specified by:
getMaxTableNameLength in interface RDBMSAdapter
Returns:
Max table name length

getMaxForeignKeys

public int getMaxForeignKeys()
Accessor for the maximum foreign keys by table permitted for this datastore.

Specified by:
getMaxForeignKeys in interface RDBMSAdapter
Returns:
Max number of FKs for a table

getMaxIndexes

public int getMaxIndexes()
Accessor for the maximum indexes by schema permitted for this datastore.

Specified by:
getMaxIndexes in interface RDBMSAdapter
Returns:
Max number of indexes for a table

getMaxConstraintNameLength

public int getMaxConstraintNameLength()
Accessor for the maximum constraint name length permitted on this datastore.

Specified by:
getMaxConstraintNameLength in interface RDBMSAdapter
Returns:
Max constraint name length

getMaxIndexNameLength

public int getMaxIndexNameLength()
Accessor for the maximum index name length permitted on this datastore.

Specified by:
getMaxIndexNameLength in interface RDBMSAdapter
Returns:
Max index name length

getMaxColumnNameLength

public int getMaxColumnNameLength()
Accessor for the maximum column name length permitted on this datastore.

Specified by:
getMaxColumnNameLength in interface RDBMSAdapter
Returns:
Max column name length

iteratorTypeInfo

public java.util.Iterator iteratorTypeInfo()
Iterator for the TypeInfo objects constructed from the method DataBaseMetaData.getTypeInfo

Specified by:
iteratorTypeInfo in interface RDBMSAdapter
Returns:
an Iterator with org.jpox.store.rdbms.typeinfo.TypeInfo

iteratorReservedWords

public java.util.Iterator iteratorReservedWords()
Iterator for the reserved words constructed from the method DataBaseMetaData.getSQLKeywords + standard SQL reserved words

Specified by:
iteratorReservedWords in interface RDBMSAdapter
Returns:
an Iterator with a set of reserved words

createTypeInfo

protected void createTypeInfo(java.sql.DatabaseMetaData metadata)
                       throws java.sql.SQLException
Creates TypeInfo objects for all of the data types and indexes them in the typesByTypeNumber map by their JDBC data type number.

Parameters:
metadata - The MetaData for this datastore
Throws:
java.sql.SQLException - Thrown if error occurs in the creation.

newTypeInfo

protected TypeInfo newTypeInfo(java.sql.ResultSet rs)
A factory for TypeInfo objects. This method should always be used instead of directly constructing TypeInfo objects in order to give the DatabaseAdapter an opportunity to modify and/or correct the metadata obtained from the JDBC driver. The type information object is constructed from the current row of the given result set. The ResultSet object passed must have been obtained from a call to DatabaseMetaData.getTypeInfo().

The constructor only retrieves the values from the current row; the caller is required to advance to the next row with ResultSet.next()

Parameters:
rs - The result set returned from DatabaseMetaData.getTypeInfo().
Returns:
A TypeInfo object constructed from the current result set row, or null if the type indicated by this row should be excluded from use.

newColumnInfo

public ColumnInfo newColumnInfo(java.sql.ResultSet rs)
A factory for ColumnInfo objects. This method should always be used instead of directly constructing ColumnInfo objects in order to give the DatabaseAdapter an opportunity to modify and/or correct the metadata obtained from the JDBC driver. The column information object is constructed from the current row of the given result set. The ResultSet object passed must have been obtained from a call to DatabaseMetaData.getColumns().

The constructor only retrieves the values from the current row; the caller is required to advance to the next row with ResultSet.next()

Specified by:
newColumnInfo in interface RDBMSAdapter
Parameters:
rs - The result set returned from DatabaseMetaData.getColumns().
Returns:
The column info

newForeignKeyInfo

public ForeignKeyInfo newForeignKeyInfo(java.sql.ResultSet rs)
A factory for ForeignKeyInfo objects. This method should always be used instead of directly constructing ForeignKeyInfo objects in order to give the DatabaseAdapter an opportunity to modify and/or correct the metadata obtained from the JDBC driver. The column information object is constructed from the current row of the given result set. The ResultSet object passed must have been obtained from a call to DatabaseMetaData.getImportedKeys() or DatabaseMetaData.getExportedKeys().

The constructor only retrieves the values from the current row; the caller is required to advance to the next row with ResultSet.next()

Specified by:
newForeignKeyInfo in interface RDBMSAdapter
Parameters:
rs - The result set returned from DatabaseMetaData.get??portedKeys()
Returns:
The foreign key info

newExportedKeyInfo

public ExportedKeyInfo newExportedKeyInfo(java.sql.ResultSet rs)
A factory for ForeignKeyInfo objects. This method should always be used instead of directly constructing ForeignKeyInfo objects in order to give the DatabaseAdapter an opportunity to modify and/or correct the metadata obtained from the JDBC driver. The column information object is constructed from the current row of the given result set. The ResultSet object passed must have been obtained from a call to DatabaseMetaData.getExportedKeys().

The constructor only retrieves the values from the current row; the caller is required to advance to the next row with ResultSet.next()

Parameters:
rs - The result set returned from DatabaseMetaData.getExportedKeys()
Returns:
The ExportedKeyInfo

parseKeywordList

protected java.util.Set parseKeywordList(java.lang.String list)
Utility method to parse a list of keywords and split them out into words.

Parameters:
list - The comma-separated list of keywords.
Returns:
Set of keywords.

isSQLKeyword

public boolean isSQLKeyword(java.lang.String word)
Tests if a given string is a SQL key word.

The list of key words tested against is defined to contain all SQL/92 key words, plus any additional key words reported by the JDBC driver for this adapter via DatabaseMetaData.getSQLKeywords().

In general, use of a SQL key word as an identifier should be avoided. SQL/92 key words are divided into reserved and non-reserved words. If a reserved word is used as an identifier it must be quoted with double quotes. Strictly speaking, the same is not true of non-reserved words. However, as C.J. Date writes in A Guide To The SQL Standard :

The rule by which it is determined within the standard that one key word needs to be reserved while another need not is not clear to this writer. In practice, it is probably wise to treat all key words as reserved.

Specified by:
isSQLKeyword in interface RDBMSAdapter
Parameters:
word - The word to test.
Returns:
true if word is a SQL key word for this DBMS. The comparison is case-insensitive.
See Also:
SQLConstants

getTypeInfo

public TypeInfo getTypeInfo(int dataType)
                     throws UnsupportedDataTypeException
Returns type information for the database type that best implements the given JDBC type.

Specified by:
getTypeInfo in interface RDBMSAdapter
Parameters:
dataType - JDBC type number of the data type.
Returns:
type information for the best matching type.
Throws:
UnsupportedDataTypeException - Thrown if the specified datatype is not supported.

getTypeInfo

public TypeInfo getTypeInfo(int[] candidateDataTypes)
                     throws UnsupportedDataTypeException
Returns type information for the first one of the given candidate JDBC data types supported by this database.

Parameters:
candidateDataTypes - array of JDBC type numbers of the data types to be checked in order of preference.
Returns:
type information for the first supported type.
Throws:
UnsupportedDataTypeException - Thrown if one of the datatypes is not supported.

getUnlimitedLengthPrecisionValue

public int getUnlimitedLengthPrecisionValue(TypeInfo typeInfo)
Returns the precision value to be used when creating string columns of "unlimited" length. Usually, if this value is needed it is provided in the database metadata (TypeInfo.precision). However, for some types in some databases the value must be computed specially.

Specified by:
getUnlimitedLengthPrecisionValue in interface RDBMSAdapter
Parameters:
typeInfo - the typeInfo object for which the precision value is needed.
Returns:
the precision value to be used when creating the column, or -1 if no value should be used.

isValidPrimaryKeyType

public boolean isValidPrimaryKeyType(int datatype)
Method to return whether the specified JDBC type is valid for use in a PrimaryKey.

Specified by:
isValidPrimaryKeyType in interface RDBMSAdapter
Parameters:
datatype - The JDBC type.
Returns:
Whether it is valid for use in the PK

isNullEqualsEmptyStrings

public boolean isNullEqualsEmptyStrings()
Some databases, Oracle, treats an empty string (0 length) equals null

Specified by:
isNullEqualsEmptyStrings in interface RDBMSAdapter
Returns:
whether the database treats an empty string as null

isBitReallyBoolean

public boolean isBitReallyBoolean()
Accessor for whether a JDBC Types.BIT is really mapped in the datastore to a boolean field.

Specified by:
isBitReallyBoolean in interface RDBMSAdapter
Returns:
Whether it is really a boolean

supportsSettingBlobUsingSetString

public boolean supportsSettingBlobUsingSetString()
Accessor for whether setting a BLOB value allows use of PreparedStatement.setString()

Specified by:
supportsSettingBlobUsingSetString in interface RDBMSAdapter
Returns:
Whether setString is allowed.

supportsSettingClobUsingSetString

public boolean supportsSettingClobUsingSetString()
Accessor for whether setting a CLOB value allows use of PreparedStatement.setString()

Specified by:
supportsSettingClobUsingSetString in interface RDBMSAdapter
Returns:
Whether setString is allowed.

getSurrogateForEmptyStrings

public java.lang.String getSurrogateForEmptyStrings()
Some databases, Oracle, treats an empty string (0 length) equals null

Specified by:
getSurrogateForEmptyStrings in interface RDBMSAdapter
Returns:
returns a surrogate to replace the empty string in the database otherwise it would be treated as null

getNewMappingManager

protected MappingManager getNewMappingManager()
Accessor for a new Mapping Manager

Specified by:
getNewMappingManager in class AbstractDatastoreAdapter
Returns:
The mapping manager

supportsTransactionIsolationLevel

public boolean supportsTransactionIsolationLevel(int isolationLevel)
Accessor for whether the adapter supports the transaction isolation level

Parameters:
isolationLevel - the isolation level
Returns:
Whether the transaction isolation level setting is supported.

getTransactionIsolationForSchemaCreation

public int getTransactionIsolationForSchemaCreation()
Accessor for the transaction isolation level to use during schema creation.

Specified by:
getTransactionIsolationForSchemaCreation in interface RDBMSAdapter
Returns:
The transaction isolation level for schema generation process

getConnection

public java.sql.Connection getConnection(javax.sql.DataSource[] ds,
                                         java.lang.String userName,
                                         java.lang.String password,
                                         int isolationLevel)
                                  throws java.sql.SQLException
Accessor for a Connection to the datastore.

Specified by:
getConnection in interface DatastoreAdapter
Parameters:
ds - The data source. Possible to have more than one datasource for failover
userName - The username for the datastore
password - The password for the datastore
isolationLevel - The level of transaction isolation
Returns:
The Connection
Throws:
java.sql.SQLException - Thrown when an error occurs in the creation.

closeConnection

public void closeConnection(java.sql.Connection conn)
                     throws java.sql.SQLException
Method to close a Connection to the datastore.

Specified by:
closeConnection in interface DatastoreAdapter
Parameters:
conn - The connection
Throws:
java.sql.SQLException - Thrown if error occurs on the close.

getCatalogName

public java.lang.String getCatalogName(java.sql.Connection conn)
                                throws java.sql.SQLException
Accessor for the Catalog Name for this datastore.

Specified by:
getCatalogName in interface RDBMSAdapter
Parameters:
conn - Connection to the datastore
Returns:
The catalog name
Throws:
java.sql.SQLException - Thrown if error occurs in determining the catalog name.

getSchemaName

public java.lang.String getSchemaName(java.sql.Connection conn)
                               throws java.sql.SQLException
Accessor for the Schema Name for this datastore.

Specified by:
getSchemaName in interface RDBMSAdapter
Parameters:
conn - Connection to the datastore
Returns:
The schema name
Throws:
java.sql.SQLException - Thrown if error occurs in determining the schema name.

getCatalogSeparator

public java.lang.String getCatalogSeparator()
Accessor for the catalog separator.

Specified by:
getCatalogSeparator in interface RDBMSAdapter
Returns:
Catalog separator string.

supportsEscapeExpressionInLikePredicate

public boolean supportsEscapeExpressionInLikePredicate()
Whether this datastore supports the use of the escape expression in like predicates

Specified by:
supportsEscapeExpressionInLikePredicate in interface ExpressionSupportedFeaturesAdapter
Returns:
whether we can use the escape expression in like predicates

supportsCatalogsInTableDefinitions

public boolean supportsCatalogsInTableDefinitions()
Whether this datastore supports the use of the catalog name in SQL table definitions (DDL).

Specified by:
supportsCatalogsInTableDefinitions in interface RDBMSAdapter
Returns:
whether we can use the catalog name in DDL

supportsSchemasInTableDefinitions

public boolean supportsSchemasInTableDefinitions()
Whether this datastore supports the use of the schema name in SQL table definitions (DDL).

Specified by:
supportsSchemasInTableDefinitions in interface RDBMSAdapter
Returns:
whether we can use the schema name in DDL

supportsUnionSyntax

public boolean supportsUnionSyntax()
Whether the RDBMS supports use of UNION syntax.

Specified by:
supportsUnionSyntax in interface RDBMSAdapter
Returns:
Whether UNION is supported.

supportsExistsSyntax

public boolean supportsExistsSyntax()
Whether the RDBMS supports use of EXISTS syntax.

Specified by:
supportsExistsSyntax in interface RDBMSAdapter
Returns:
Whether EXISTS is supported.

getEscapedPatternExpression

public ScalarExpression getEscapedPatternExpression(ScalarExpression patternExpression)
The pattern string for representing one character. Most of databases will use the underscore character.

Specified by:
getEscapedPatternExpression in interface ExpressionPatternAdapter
Parameters:
patternExpression - The expression that represents one character for a matcher/parser in the database
Returns:
the pattern string.

getPatternExpressionAnyCharacter

public java.lang.String getPatternExpressionAnyCharacter()
The pattern string for representing one character that is expanded in word searches. Most of databases will use the underscore character.

Specified by:
getPatternExpressionAnyCharacter in interface ExpressionPatternAdapter
Returns:
the pattern string.

getPatternExpressionZeroMoreCharacters

public java.lang.String getPatternExpressionZeroMoreCharacters()
The pattern string for representing zero or more characters that is expanded in word searches. Most of databases will use the percent sign character.

Specified by:
getPatternExpressionZeroMoreCharacters in interface ExpressionPatternAdapter
Returns:
the pattern string.

getEscapePatternExpression

public java.lang.String getEscapePatternExpression()
The character for escaping characters in pattern expressions.

Specified by:
getEscapePatternExpression in interface ExpressionPatternAdapter
Returns:
the character.

getEscapeCharacter

public java.lang.String getEscapeCharacter()
The character for escaping characters in pattern expressions.

Specified by:
getEscapeCharacter in interface ExpressionPatternAdapter
Returns:
the character.

getContinuationString

public java.lang.String getContinuationString()
Continuation string to use where the SQL statement goes over more than 1 line. Some JDBC adapters (e.g DB2) don't do conversion.

Returns:
Continuation string.

createIndexesBeforeForeignKeys

public boolean createIndexesBeforeForeignKeys()
Whether to create indexes before foreign keys.

Specified by:
createIndexesBeforeForeignKeys in interface RDBMSAdapter
Returns:
Whether to create indexes before foreign keys

includeOrderByColumnsInSelect

public boolean includeOrderByColumnsInSelect()
Whether to include ORDER BY columns in a SELECT.

Specified by:
includeOrderByColumnsInSelect in interface RDBMSAdapter
Returns:
Whether to include ORDER BY in SELECTs

includeOrderByColumnsInSelectUsingAlias

public boolean includeOrderByColumnsInSelectUsingAlias()
Whether to specify ORDER BY columns in SELECTS using aliases.

Returns:
Whether to include ORDER BY in SELECTs using aliases

cartersianProduct

public java.lang.String cartersianProduct(LogicSetExpression Y)
Generates a expression that represents the cartesian product of two sets: X and Y. Actually, X is not generated to the expression.

Specified by:
cartersianProduct in interface ExpressionLogicSetAdapter
Parameters:
Y - right hand set
Returns:
the cartesion product expression. if the cartesian product expression is "X x Y", the returned expression is " x Y". Note that the left hand set was not introduced to the expression

useUnionAll

public boolean useUnionAll()
Union combines the results of two or more queries into a single result set. Union include only distinct rows and Union all may include duplicates. When using the UNION statement, keep in mind that, by default, it performs the equivalent of a SELECT DISTINCT on the final result set. In other words, UNION takes the results of two like recordsets, combines them, and then performs a SELECT DISTINCT in order to eliminate any duplicate rows. This process occurs even if there are no duplicate records in the final recordset. If you know that there are duplicate records, and this presents a problem for your application, then by all means use the UNION statement to eliminate the duplicate rows. On the other hand, if you know that there will never be any duplicate rows, or if there are, and this presents no problem to your application, then you should use the UNION ALL statement instead of the UNION statement. The advantage of the UNION ALL is that is does not perform the SELECT DISTINCT function, which saves a lot of unnecessary SQL Server resources from being using.

Specified by:
useUnionAll in interface RDBMSAdapter
Returns:
Whether to use UNION ALL instead of UNION

supportsAlterTableDropConstraint

public boolean supportsAlterTableDropConstraint()
Whether this datastore supports ALTER TABLE DROP constraints

Specified by:
supportsAlterTableDropConstraint in interface RDBMSAdapter
Returns:
whether we support ALTER TABLE DROP constraints

supportsAlterTableDropForeignKeyConstraint

public boolean supportsAlterTableDropForeignKeyConstraint()
Whether this datastore supports ALTER TABLE DROP FOREIGN KEY constraints

Specified by:
supportsAlterTableDropForeignKeyConstraint in interface RDBMSAdapter
Returns:
whether we support ALTER TABLE DROP FOREIGN KEY constraints

supportsDeferredConstraints

public boolean supportsDeferredConstraints()
Whether this datastore supports deferred constraints.

Specified by:
supportsDeferredConstraints in interface RDBMSAdapter
Returns:
whether we support deferred constraints.

supportsLockWithSelectForUpdate

public boolean supportsLockWithSelectForUpdate()
Whether this datastore supports SELECT ... FOR UPDATE.

Specified by:
supportsLockWithSelectForUpdate in interface RDBMSAdapter
Returns:
whether we support SELECT ... FOR UPDATE.

supportsDistinctWithSelectForUpdate

public boolean supportsDistinctWithSelectForUpdate()
Whether this datastore supports using DISTINCT when using SELECT ... FOR UPDATE.

Specified by:
supportsDistinctWithSelectForUpdate in interface RDBMSAdapter
Returns:
whether the datastore supports DISTINCT in same statement as FOR UPDATE

getSelectWithLockOption

public java.lang.String getSelectWithLockOption()
The option to specify in "SELECT ... FROM TABLE ... WITH (option)" to lock instances Null if not supported.

Specified by:
getSelectWithLockOption in interface RDBMSAdapter
Returns:
The option to specify with "SELECT ... FROM TABLE ... WITH (option)"

getPlaceWithOptionAfterFromClause

public boolean getPlaceWithOptionAfterFromClause()
Determines whether the getSelectWithLockOption() is to be placed right before the FROM clause, or at the end of the statement

Specified by:
getPlaceWithOptionAfterFromClause in interface RDBMSAdapter
Returns:
true if option has to be placed right after the from clause

getPlaceWithOptionWithinJoinClauses

public boolean getPlaceWithOptionWithinJoinClauses()
Determines whether lock option has to be placed within JOIN clauses as well.

Specified by:
getPlaceWithOptionWithinJoinClauses in interface RDBMSAdapter
Returns:
true if option has to be placed right after the join clause

getSelectNewUUIDStmt

public java.lang.String getSelectNewUUIDStmt()
The function to creates a unique value of type uniqueidentifier.

Specified by:
getSelectNewUUIDStmt in interface RDBMSAdapter
Returns:
The function. e.g. "SELECT NEWID()"

getNewUUIDFunction

public java.lang.String getNewUUIDFunction()
The function to creates a unique value of type uniqueidentifier.

Returns:
The function. e.g. "NEWID()"

supportsForeignKeyUpdateAction

public boolean supportsForeignKeyUpdateAction(ForeignKey.FKAction action)
Whether this datastore supports the specified foreign key update action

Specified by:
supportsForeignKeyUpdateAction in interface RDBMSAdapter
Parameters:
action - The update action
Returns:
Whether it is supported

supportsForeignKeyDeleteAction

public boolean supportsForeignKeyDeleteAction(ForeignKey.FKAction action)
Whether this datastore supports the specified foreign key delete action

Specified by:
supportsForeignKeyDeleteAction in interface RDBMSAdapter
Parameters:
action - The delete action
Returns:
Whether it is supported

supportsPrimaryKeyInCreateStatements

public boolean supportsPrimaryKeyInCreateStatements()
Whether the datastore supports specification of the primary key in CREATE TABLE statements.

Specified by:
supportsPrimaryKeyInCreateStatements in interface RDBMSAdapter
Returns:
Whetehr it allows "PRIMARY KEY ..."

supportsCheckInCreateStatements

public boolean supportsCheckInCreateStatements()
Whether this datastore supports the use of CHECK in CREATE TABLE statements (DDL).

Specified by:
supportsCheckInCreateStatements in interface RDBMSAdapter
Returns:
whether we can use CHECK in CREATE TABLE.

supportsCheckConstraintsInEndCreateStatements

public boolean supportsCheckConstraintsInEndCreateStatements()
Whether this datastore supports the use of CHECK after the column definitions in CREATE TABLE statements (DDL). e.g.
 CREATE TABLE XXX
 (
     COL_A int,
     COL_B char(1),
     PRIMARY KEY (COL_A),
     CHECK (COL_B IN ('Y','N'))
 )
 

Returns:
whether we can use CHECK after the column definitions CREATE TABLE.

supportsUniqueConstraintsInEndCreateStatements

public boolean supportsUniqueConstraintsInEndCreateStatements()
Whether this datastore supports the use of UNIQUE after the column definitions in CREATE TABLE statements (DDL). e.g.
 CREATE TABLE XXX
 (
     COL_A int,
     COL_B char(1),
     PRIMARY KEY (COL_A),
     UNIQUE (COL_B ...)
 )
 

Specified by:
supportsUniqueConstraintsInEndCreateStatements in interface RDBMSAdapter
Returns:
whether we can use UNIQUE after the column definitions CREATE TABLE.

supportsStatementGetGeneratedKeys

public boolean supportsStatementGetGeneratedKeys()
Whether the datastore supports Statement.getGeneratedKeys()

Specified by:
supportsStatementGetGeneratedKeys in interface RDBMSAdapter
Returns:
true if it is supported

supportsBooleanComparison

public boolean supportsBooleanComparison()
Whether we support Boolean comparisons.

Specified by:
supportsBooleanComparison in interface ExpressionSupportedFeaturesAdapter
Returns:
whether we support Boolean comparisons.

supportsNullsInCandidateKeys

public boolean supportsNullsInCandidateKeys()
Whether we support NULLs in candidate keys.

Specified by:
supportsNullsInCandidateKeys in interface RDBMSAdapter
Returns:
whether we support NULLs in candidate keys.

supportsNullsKeywordInColumnOptions

public boolean supportsNullsKeywordInColumnOptions()
Whether the database support NULLs in the column options for table creation.

Specified by:
supportsNullsKeywordInColumnOptions in interface RDBMSAdapter
Returns:
whether the database support NULLs in the column options for table creation.

supportsDefaultKeywordInColumnOptions

public boolean supportsDefaultKeywordInColumnOptions()
Whether we support DEFAULT tag in CREATE TABLE statements

Specified by:
supportsDefaultKeywordInColumnOptions in interface RDBMSAdapter
Returns:
whether we support the DEFAULT tag in CREATE TABLE

supportsDefaultKeywordWithNotNullInColumnOptions

public boolean supportsDefaultKeywordWithNotNullInColumnOptions()
Whether we support DEFAULT tag together with NOT NULL in CREATE TABLE statements.
 CREATE TABLE X ( MEMORY_SIZE BIGINT DEFAULT 0 NOT NULL )
 
Some databases only support DEFAULT {ConstantExpression | NULL}

Specified by:
supportsDefaultKeywordWithNotNullInColumnOptions in interface RDBMSAdapter
Returns:
whether we support the DEFAULT tag together with NOT NULL in CREATE TABLE

supportsDefaultBeforeNullInColumnOptions

public boolean supportsDefaultBeforeNullInColumnOptions()
Whether any DEFAULT tag will be before any NULL/NOT NULL in the column options.

Specified by:
supportsDefaultBeforeNullInColumnOptions in interface RDBMSAdapter
Returns:
Whether to put DEFAULT before NULL

supportsAnsiJoinSyntax

public boolean supportsAnsiJoinSyntax()
Accessor for whether the RDBMS supports ANSI join syntax.

Specified by:
supportsAnsiJoinSyntax in interface RDBMSAdapter
Returns:
Whether the RDBMS supports ANSI join syntax

getNonAnsiInnerJoinWhereClause

public java.lang.String getNonAnsiInnerJoinWhereClause(java.lang.String col1,
                                                       java.lang.String col2)
Accessor for the WHERE clause to add to provide an INNER JOIN using non-ANSI syntax.

Specified by:
getNonAnsiInnerJoinWhereClause in interface RDBMSAdapter
Parameters:
col1 - The main datastore column
col2 - The secondary column to join to
Returns:
The Inner Join WHERE clause.

getNonAnsiLeftOuterJoinWhereClause

public java.lang.String getNonAnsiLeftOuterJoinWhereClause(java.lang.String col1,
                                                           java.lang.String col2)
Accessor for the WHERE clause to add to provide a LEFT OUTER JOIN using non-ANSI syntax.

Specified by:
getNonAnsiLeftOuterJoinWhereClause in interface RDBMSAdapter
Parameters:
col1 - The main datastore column
col2 - The secondary column to join to
Returns:
The Left Outer Join WHERE clause.

getNonAnsiRightOuterJoinWhereClause

public java.lang.String getNonAnsiRightOuterJoinWhereClause(java.lang.String col1,
                                                            java.lang.String col2)
Accessor for the WHERE clause to add to provide a RIGHT OUTER JOIN using non-ANSI syntax.

Parameters:
col1 - The main datastore column
col2 - The secondary column to join to
Returns:
The Right Outer Join WHERE clause.

getAutoIncrementStmt

public java.lang.String getAutoIncrementStmt(java.lang.String tableName,
                                             java.lang.String columnName)
Accessor for the autoincrementing sql statement for this datastore.

Specified by:
getAutoIncrementStmt in interface RDBMSAdapter
Parameters:
tableName - Name of the table that the autoincrement is for
columnName - Name of the column that the autoincrement is for
Returns:
The statement for getting the latest autoincremented key

getAutoIncrementKeyword

public java.lang.String getAutoIncrementKeyword()
Accessor for the autoincrementing keyword for generating DDLs. (CREATE TABLEs...).

Specified by:
getAutoIncrementKeyword in interface RDBMSAdapter
Returns:
The keyword for a column using autoincrement

isAutoIncrementingDataType

public boolean isAutoIncrementingDataType(java.lang.String typeName)
Verifies if the given typeName is auto incremented by the datastore.

Specified by:
isAutoIncrementingDataType in interface DatastoreAdapter
Parameters:
typeName - the datastore type name
Returns:
true when the typeName has values auto incremented by the datastore

supportsAutoIncrementKeysNullSpecification

public boolean supportsAutoIncrementKeysNullSpecification()
Whether we support autoincrementing keys with nullability specification.

Specified by:
supportsAutoIncrementKeysNullSpecification in interface RDBMSAdapter
Returns:
whether we support autoincrementing keys with nullability spec.

supportsAutoIncrementColumnTypeSpecification

public boolean supportsAutoIncrementColumnTypeSpecification()
Whether we support auto-increment/identity keys with column type specification.

Specified by:
supportsAutoIncrementColumnTypeSpecification in interface RDBMSAdapter
Returns:
whether we support auto-increment keys with column type spec.

getInsertStatementForNoColumns

public java.lang.String getInsertStatementForNoColumns(Table table)
Method to return the INSERT statement to use when inserting into a table that has no columns specified. This is the case when we have a single column in the table and that column is autoincrement/identity (and so is assigned automatically in the datastore).

Specified by:
getInsertStatementForNoColumns in interface RDBMSAdapter
Parameters:
table - The table
Returns:
The statement for the INSERT

getSequenceCreateStmt

public java.lang.String getSequenceCreateStmt(java.lang.String sequence_name,
                                              java.lang.String min,
                                              java.lang.String max,
                                              java.lang.String start,
                                              java.lang.String increment,
                                              java.lang.String cache_size)
Accessor for the sequence create statement for this datastore. TODO Change param types to int.

Specified by:
getSequenceCreateStmt in interface RDBMSAdapter
Parameters:
sequence_name - Name of the sequence
min - Minimum value for the sequence
max - Maximum value for the sequence
start - Start value for the sequence
increment - Increment value for the sequence
cache_size - Cache size for the sequence
Returns:
The statement for getting the next id from the sequence

getSequenceNextStmt

public java.lang.String getSequenceNextStmt(java.lang.String sequence_name)
Accessor for the sequence statement to get the next id for this datastore.

Specified by:
getSequenceNextStmt in interface RDBMSAdapter
Parameters:
sequence_name - Name of the sequence
Returns:
The statement for getting the next id for the sequence

getExistingIndexes

public java.sql.ResultSet getExistingIndexes(java.sql.Connection conn,
                                             java.sql.DatabaseMetaData dmd,
                                             java.lang.String catalog,
                                             java.lang.String schema,
                                             java.lang.String table)
                                      throws java.sql.SQLException
Provide the existing indexes in the database for the table

Specified by:
getExistingIndexes in interface RDBMSAdapter
Parameters:
conn - the JDBC connection
dmd - the DatabaseMetaData
catalog - the catalog name
schema - the schema name
table - the table name
Returns:
a ResultSet with the format @see DatabaseMetaData#getIndexInfo(java.lang.String, java.lang.String, java.lang.String, boolean, boolean)
Throws:
java.sql.SQLException

newQueryStatement

public QueryExpression newQueryStatement(DatastoreContainerObject table,
                                         ClassLoaderResolver clr)
Accessor for a new query statement.

Specified by:
newQueryStatement in interface DatastoreAdapter
Specified by:
newQueryStatement in class AbstractDatastoreAdapter
Parameters:
table - The table to query
clr - The ClassLoaderResolver
Returns:
The Query Statement

newQueryStatement

public QueryExpression newQueryStatement(DatastoreContainerObject table,
                                         DatastoreIdentifier rangeVar,
                                         ClassLoaderResolver clr)
Accessor for a new query statement.

Specified by:
newQueryStatement in interface DatastoreAdapter
Specified by:
newQueryStatement in class AbstractDatastoreAdapter
Parameters:
table - The table to query
rangeVar - A range variable for the query
clr - The ClassLoaderResolver
Returns:
The Query Statement

newTableExpression

public LogicSetExpression newTableExpression(QueryExpression qs,
                                             DatastoreContainerObject table,
                                             DatastoreIdentifier rangeVar)
Returns a new TableExpression object appropriate for this DBMS. This should be an instance of one of the three built-in styles of table expression: TableExprAsSubjoins is the default, which arguably produces the most readable SQL but doesn't work on all DBMS's. TableExprAsSubjoins should work anywhere, but may be less efficient.

Specified by:
newTableExpression in interface RDBMSAdapter
Parameters:
qs - The query statement in which the table expression will be included.
table - The main table in the expression.
rangeVar - The SQL alias, or "range variable", to assign to the expression or to the main table.
Returns:
The expression

getCreateTableStatement

public java.lang.String getCreateTableStatement(TableImpl table,
                                                Column[] columns,
                                                java.util.Properties props)
Returns the appropriate SQL to create the given table having the given columns. No column constraints or key definitions should be included. It should return something like:

 CREATE TABLE FOO ( BAR VARCHAR(30), BAZ INTEGER )
 

Specified by:
getCreateTableStatement in interface RDBMSAdapter
Parameters:
table - The table to create.
columns - The columns of the table.
props - Properties for controlling the table creation
Returns:
The text of the SQL statement.

getAddPrimaryKeyStatement

public java.lang.String getAddPrimaryKeyStatement(PrimaryKey pk)
Returns the appropriate SQL to add a primary key to its table. It should return something like:

 ALTER TABLE FOO ADD CONSTRAINT FOO_PK PRIMARY KEY (BAR)
 ALTER TABLE FOO ADD PRIMARY KEY (BAR)
 

Specified by:
getAddPrimaryKeyStatement in interface RDBMSAdapter
Parameters:
pk - An object describing the primary key.
Returns:
The text of the SQL statement.

getAddCandidateKeyStatement

public java.lang.String getAddCandidateKeyStatement(CandidateKey ck)
Returns the appropriate SQL to add a candidate key to its table. It should return something like:

 ALTER TABLE FOO ADD CONSTRAINT FOO_CK UNIQUE (BAZ)
 ALTER TABLE FOO ADD UNIQUE (BAZ)
 

Specified by:
getAddCandidateKeyStatement in interface RDBMSAdapter
Parameters:
ck - An object describing the candidate key.
Returns:
The text of the SQL statement.

getAddForeignKeyStatement

public java.lang.String getAddForeignKeyStatement(ForeignKey fk)
Returns the appropriate SQL to add a foreign key to its table. It should return something like:

 ALTER TABLE FOO ADD CONSTRAINT FOO_FK1 FOREIGN KEY (BAR, BAZ) REFERENCES ABC (COL1, COL2)
 ALTER TABLE FOO ADD FOREIGN KEY (BAR, BAZ) REFERENCES ABC (COL1, COL2)
 

Specified by:
getAddForeignKeyStatement in interface RDBMSAdapter
Parameters:
fk - An object describing the foreign key.
Returns:
The text of the SQL statement.

getAddColumnStatement

public java.lang.String getAddColumnStatement(DatastoreContainerObject table,
                                              Column col)
Accessor for the SQL statement to add a column to a table.

Specified by:
getAddColumnStatement in interface RDBMSAdapter
Parameters:
table - The table
col - The column
Returns:
The SQL necessary to add the column

getCreateIndexStatement

public java.lang.String getCreateIndexStatement(Index idx)
Returns the appropriate SQL to add an index to its table. It should return something like:

 CREATE INDEX FOO_N1 ON FOO (BAR,BAZ) [Extended Settings]
 CREATE UNIQUE INDEX FOO_U1 ON FOO (BAR,BAZ) [Extended Settings]
 

Specified by:
getCreateIndexStatement in interface RDBMSAdapter
Parameters:
idx - An object describing the index.
Returns:
The text of the SQL statement.

getDropTableStatement

public java.lang.String getDropTableStatement(DatastoreContainerObject table)
Returns the appropriate SQL to drop the given table. It should return something like:

 DROP TABLE FOO CASCADE
 

Specified by:
getDropTableStatement in interface RDBMSAdapter
Parameters:
table - The table to drop.
Returns:
The text of the SQL statement.

getDropViewStatement

public java.lang.String getDropViewStatement(ViewImpl view)
Returns the appropriate SQL to drop the given view. It should return something like:

 DROP VIEW FOO
 

Specified by:
getDropViewStatement in interface RDBMSAdapter
Parameters:
view - The view to drop.
Returns:
The text of the SQL statement.

getRangeByLimitSelectClause

public java.lang.String getRangeByLimitSelectClause(long offset,
                                                    long count)
Method to return the SQL to append to the SELECT clause of a SELECT statement to handle restriction of ranges using the LIMIT keyword. Defaults to an empty string (not supported). SELECT {LIMIT} params

Specified by:
getRangeByLimitSelectClause in interface RDBMSAdapter
Parameters:
offset - The offset to return from
count - The number of items to return
Returns:
The SQL to append to allow for ranges using LIMIT.

getRangeByLimitWhereClause

public java.lang.String getRangeByLimitWhereClause(long offset,
                                                   long count)
Method to return the SQL to append to the WHERE clause of a SELECT statement to handle restriction of ranges using the LIMIT keyword. Defaults to an empty string (not supported). SELECT param ... WHERE {LIMIT}

Specified by:
getRangeByLimitWhereClause in interface RDBMSAdapter
Parameters:
offset - The offset to return from
count - The number of items to return
Returns:
The SQL to append to allow for ranges using LIMIT.

getRangeByRowNumberColumn

public java.lang.String getRangeByRowNumberColumn()
Method to return the column name to use when handling ranges via a rownumber on the select. Defaults to an empty string (not supported).

Specified by:
getRangeByRowNumberColumn in interface RDBMSAdapter
Returns:
The row number column.

toNumericExpression

public NumericExpression toNumericExpression(CharacterExpression expr)
Returns the appropriate expression for the (int)'A' expression. In SQL, it should compile something like:

 ASCII('A')
 

Specified by:
toNumericExpression in interface ExpressionConversionAdapter
Parameters:
expr - The CharacterExpression
Returns:
The NumericExpression

absMethod

public NumericExpression absMethod(ScalarExpression expr)
Returns the appropriate SQL expression for the JDOQL Math.abs(EXPRESSION) method. It should return something like:

 ABS(str)
 

Specified by:
absMethod in interface ExpressionMethodAdapter
Parameters:
expr - The argument to the abs() method.
Returns:
The text of the SQL expression.

sqrtMethod

public NumericExpression sqrtMethod(ScalarExpression expr)
Returns the appropriate SQL expression for the JDOQL Math.sqrt(EXPRESSION) method. It should return something like:

 SQRT(str)
 

Specified by:
sqrtMethod in interface ExpressionMethodAdapter
Parameters:
expr - The argument to the sqrt() method.
Returns:
The text of the SQL expression.

cosMethod

public NumericExpression cosMethod(ScalarExpression expr)
Returns the appropriate SQL expression for the JDOQL Math.cos(EXPRESSION) method. It should return something like:

 COS(str)
 

Specified by:
cosMethod in interface ExpressionMethodAdapter
Parameters:
expr - The argument to the cos() method.
Returns:
The text of the SQL expression.

sinMethod

public NumericExpression sinMethod(ScalarExpression expr)
Returns the appropriate SQL expression for the JDOQL Math.sin(EXPRESSION) method. It should return something like:

 SIN(str)
 

Specified by:
sinMethod in interface ExpressionMethodAdapter
Parameters:
expr - The argument to the sin() method.
Returns:
The text of the SQL expression.

tanMethod

public NumericExpression tanMethod(ScalarExpression expr)
Returns the appropriate SQL expression for the JDOQL Math.tan(EXPRESSION) method. It should return something like:

 TAN(str)
 

Specified by:
tanMethod in interface ExpressionMethodAdapter
Parameters:
expr - The argument to the tan() method.
Returns:
The text of the SQL expression.

acosMethod

public NumericExpression acosMethod(ScalarExpression expr)
Returns the appropriate SQL expression for the JDOQL Math.acos(EXPRESSION) method. It should return something like:

 ACOS(str)
 

Specified by:
acosMethod in interface ExpressionMethodAdapter
Parameters:
expr - The argument to the cos() method.
Returns:
The text of the SQL expression.

asinMethod

public NumericExpression asinMethod(ScalarExpression expr)
Returns the appropriate SQL expression for the JDOQL Math.asin(EXPRESSION) method. It should return something like:

 ASIN(str)
 

Specified by:
asinMethod in interface ExpressionMethodAdapter
Parameters:
expr - The argument to the asin() method.
Returns:
The text of the SQL expression.

atanMethod

public NumericExpression atanMethod(ScalarExpression expr)
Returns the appropriate SQL expression for the JDOQL Math.atan(EXPRESSION) method. It should return something like:

 ATAN(str)
 

Specified by:
atanMethod in interface ExpressionMethodAdapter
Parameters:
expr - The argument to the atan() method.
Returns:
The text of the SQL expression.

endsWithMethod

public BooleanExpression endsWithMethod(ScalarExpression leftOperand,
                                        ScalarExpression rightOperand)
Returns whether this string ends with the specified string.

Specified by:
endsWithMethod in interface ExpressionMethodAdapter
Parameters:
leftOperand - the source string
rightOperand - The string to compare against.
Returns:
Whether it ends with the string.

expMethod

public NumericExpression expMethod(ScalarExpression expr)
Returns the appropriate SQL expression for the JDOQL Math.exp(EXPRESSION) method. It should return something like:

 EXP(str)
 

Specified by:
expMethod in interface ExpressionMethodAdapter
Parameters:
expr - The argument to the exp() method.
Returns:
The text of the SQL expression.

logMethod

public NumericExpression logMethod(ScalarExpression expr)
Returns the appropriate SQL expression for the JDOQL Math.log(EXPRESSION) method. It should return something like:

 LOG(str)
 

Specified by:
logMethod in interface ExpressionMethodAdapter
Parameters:
expr - The argument to the log() method.
Returns:
The text of the SQL expression.

floorMethod

public NumericExpression floorMethod(ScalarExpression expr)
Returns the appropriate SQL expression for the JDOQL Math.floor(EXPRESSION) method. It should return something like:

 FLOOR(str)
 

Specified by:
floorMethod in interface ExpressionMethodAdapter
Parameters:
expr - The argument to the floor() method.
Returns:
The text of the SQL expression.

ceilMethod

public NumericExpression ceilMethod(ScalarExpression expr)
Returns the appropriate SQL expression for the JDOQL ceil(EXPRESSION) method. It should return something like:

 CEIL(str)
 

Specified by:
ceilMethod in interface ExpressionMethodAdapter
Parameters:
expr - The argument to the ceil() method.
Returns:
The text of the SQL expression.

lengthMethod

public NumericExpression lengthMethod(StringExpression str)
Returns the appropriate SQL expression for the JDOQL String.length() method. It should return something like:

 CHAR_LENGTH(str)
 

Specified by:
lengthMethod in interface ExpressionMethodAdapter
Parameters:
str - The argument to the length() method.
Returns:
The text of the SQL expression.

toStringExpression

public StringExpression toStringExpression(NumericExpression expr)
A String conversion that converts a numeric expression to string. If the expr argument represents a Literal value, converts to a Literal string. In SQL, it should compile something like:

 CAST(999999 AS VARCHAR(4000))
 

Specified by:
toStringExpression in interface ExpressionConversionAdapter
Parameters:
expr - The NumericExpression
Returns:
the StringExpression

toStringExpression

public StringExpression toStringExpression(StringLiteral expr)
A String conversion that converts a String literal to String expression. It will allow the String to only be evaluated at runtime. In SQL, it should compile something like:

 CAST(999999 AS VARCHAR(4000))
 

Specified by:
toStringExpression in interface ExpressionConversionAdapter
Parameters:
expr - The NumericExpression
Returns:
the StringExpression

substringMethod

public StringExpression substringMethod(StringExpression str,
                                        NumericExpression begin)
Returns the appropriate SQL expression for the JDOQL String.substring(str,begin) method. It should return something like:

 SUBSTRING(str FROM begin)
 
Note that the value of begin is base 0(Java-style), while most SQL string functions use base 1.

Specified by:
substringMethod in interface ExpressionMethodAdapter
Parameters:
str - The first argument to the substring() method.
begin - The second argument to the substring() method.
Returns:
The text of the SQL expression.

trimMethod

public StringExpression trimMethod(StringExpression str)
Returns the appropriate SQL expression for the JDOQL String.trim(str) method. It should return something like:

 TRIM(str)
 

Specified by:
trimMethod in interface ExpressionMethodAdapter
Parameters:
str - The first argument to the trim() method.
Returns:
The text of the SQL expression.

substringMethod

public StringExpression substringMethod(StringExpression str,
                                        NumericExpression begin,
                                        NumericExpression end)
Returns the appropriate SQL expression for the JDOQL String.substring(str,begin,end) method. It should return something like:

 SUBSTRING(str FROM begin FOR len)
 
Note that the value of begin is base 0 (Java-style), while most SQL string functions use base 1. Note also that an end position is given, while most SQL substring functions take a length.

Specified by:
substringMethod in interface ExpressionMethodAdapter
Parameters:
str - The first argument to the substring() method.
begin - The second argument to the substring() method.
end - The third argument to the substring() method.
Returns:
The text of the SQL expression.

startsWithMethod

public BooleanExpression startsWithMethod(ScalarExpression source,
                                          ScalarExpression str)
Method to handle the starts with operation. Will return something like
 source LIKE str%
 

Specified by:
startsWithMethod in interface ExpressionMethodAdapter
Parameters:
source - The expression with the searched string
str - The expression for the search string
Returns:
The expression.

indexOfMethod

public NumericExpression indexOfMethod(ScalarExpression source,
                                       ScalarExpression str,
                                       NumericExpression from)
Returns the appropriate SQL expression for the JDOQL String.indexOf() method. It should return something like:

 LOCATE(str, substr [,pos])-1
 
since LOCATE returns the first character as position 1. Similarly the "pos" is based on the first position being 1.

Specified by:
indexOfMethod in interface ExpressionMethodAdapter
Parameters:
source - The expression we want to search.
str - The argument to the indexOf() method.
from - The from position
Returns:
The text of the SQL expression.

getOperatorConcat

public java.lang.String getOperatorConcat()
An operator in a string expression that concatenates two or more character or binary strings, columns, or a combination of strings and column names into one expression (a string operator).

Specified by:
getOperatorConcat in interface ExpressionOperatorAdapter
Returns:
the operator SQL String

concatOperator

public ScalarExpression concatOperator(ScalarExpression operand1,
                                       ScalarExpression operand2)

If only one operand expression is of type String, then string conversion is performed on the other operand to produce a string at run time. The result is a reference to a String object (newly created, unless the expression is a compile-time constant expression (§15.28))that is the concatenation of the two operand strings. The characters of the left-hand operand precede the characters of the right-hand operand in the newly created string. If an operand of type String is null, then the string "null" is used instead of that operand. "null" is used instead of that operand.

Concatenates two or more character or binary strings, columns, or a combination of strings and column names into one expression (a string operator).

Specified by:
concatOperator in interface ExpressionOperatorAdapter
Parameters:
operand1 - the left expression
operand2 - the right expression
Returns:
The Expression for concatenation

getDayMethod

public NumericExpression getDayMethod(SqlTemporalExpression date)
Returns the appropriate SQL expression for the JDOQL Date.getDay() method. It should return something like:
DAY(date)

Specified by:
getDayMethod in interface ExpressionMethodAdapter
Parameters:
date - The date for the getDay() method.
Returns:
The text of the SQL expression.

getMonthMethod

public NumericExpression getMonthMethod(SqlTemporalExpression date)
Returns the appropriate SQL expression for the JDOQL Date.getMonth() method. It should return something like:
MONTH(date)

Specified by:
getMonthMethod in interface ExpressionMethodAdapter
Parameters:
date - The date for the getMonth() method.
Returns:
The text of the SQL expression.

getYearMethod

public NumericExpression getYearMethod(SqlTemporalExpression date)
Returns the appropriate SQL expression for the JDOQL Date.getYear() method. It should return something like:
YEAR(date)

Specified by:
getYearMethod in interface ExpressionMethodAdapter
Parameters:
date - The date for the getYear() method.
Returns:
The text of the SQL expression.

getHourMethod

public NumericExpression getHourMethod(SqlTemporalExpression time)
Returns the appropriate SQL expression for the JDOQL Time.getHour() method. It should return something like:
HOUR(time)

Specified by:
getHourMethod in interface ExpressionMethodAdapter
Parameters:
time - The time for the getHour() method.
Returns:
The text of the SQL expression.

getMinuteMethod

public NumericExpression getMinuteMethod(SqlTemporalExpression time)
Returns the appropriate SQL expression for the JDOQL Time.getMinute() method. It should return something like:
MINUTE(time)

Specified by:
getMinuteMethod in interface ExpressionMethodAdapter
Parameters:
time - The time for the getMinute() method.
Returns:
The text of the SQL expression.

getSecondMethod

public NumericExpression getSecondMethod(SqlTemporalExpression time)
Returns the appropriate SQL expression for the JDOQL Time.getSecond() method. It should return something like:
SECOND(time)

Specified by:
getSecondMethod in interface ExpressionMethodAdapter
Parameters:
time - The time for the getSecond() method.
Returns:
The text of the SQL expression.

getColumns

public java.sql.ResultSet getColumns(java.sql.Connection conn,
                                     java.lang.String catalog,
                                     java.lang.String schema,
                                     java.lang.String table)
                              throws java.sql.SQLException
Accessor for table and column information for a catalog/schema in this datastore.

Specified by:
getColumns in interface RDBMSAdapter
Parameters:
conn - Connection to use
catalog - The catalog (null if none)
schema - The schema (null if none)
table - The table (null if all)
Returns:
ResultSet containing the table/column information
Throws:
java.sql.SQLException - Thrown if an error occurs

getTables

public java.sql.ResultSet getTables(java.sql.Connection conn,
                                    java.lang.String catalog,
                                    java.lang.String schema)
                             throws java.sql.SQLException
Accessor for table information for a catalog/schema in this datastore.

Specified by:
getTables in interface RDBMSAdapter
Parameters:
conn - Connection to use
catalog - The catalog (null if none)
schema - The schema (null if none)
Returns:
ResultSet containing the table information
Throws:
java.sql.SQLException - Thrown if an error occurs

getColumns

public java.sql.ResultSet getColumns(java.sql.Connection conn,
                                     java.lang.String catalog,
                                     java.lang.String schema,
                                     java.lang.String table,
                                     java.lang.String columnNamePattern)
                              throws java.sql.SQLException
Accessor for table and column information for a catalog/schema in this datastore.

Specified by:
getColumns in interface RDBMSAdapter
Parameters:
conn - Connection to use
catalog - The catalog (null if none)
schema - The schema (null if none)
table - The table (null if all)
columnNamePattern - The column name (null if all)
Returns:
ResultSet containing the table/column information
Throws:
java.sql.SQLException - Thrown if an error occurs

requiresColumnDefaultsInitialising

public boolean requiresColumnDefaultsInitialising()
Accessor for whether the column defaults need initialising for this datastore

Specified by:
requiresColumnDefaultsInitialising in interface RDBMSAdapter
Returns:
Whether to initialise the column defaults

toString

public java.lang.String toString()
Overridden toString() method adding more information.

Specified by:
toString in interface DatastoreAdapter
Overrides:
toString in class AbstractDatastoreAdapter
Returns:
The string form of this object.


Copyright © -2007 . All Rights Reserved.