org.jpox.store.rdbms.adapter
Class H2Adapter

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

public class H2Adapter
extends DatabaseAdapter

Provides methods for adapting SQL language elements to the H2 Database Engine.

Version:
$Revision: 1.19 $

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jpox.store.rdbms.adapter.DatabaseAdapter
DatabaseAdapter.JDBCTypeInfo
 
Field Summary
 
Fields inherited from class org.jpox.store.rdbms.adapter.DatabaseAdapter
catalogSeparator, driverMajorVersion, driverMinorVersion, driverName, driverVersion, LOCALISER, maxColumnNameLength, maxConstraintNameLength, maxIndexNameLength, maxTableNameLength, storesLowerCaseIdentifiers, storesLowerCaseQuotedIdentifiers, storesMixedCaseIdentifiers, storesMixedCaseQuotedIdentifiers, storesMixedCaseQuotedSensitiveIdentifiers, storesMixedCaseSensitiveIdentifiers, storesUpperCaseIdentifiers, storesUpperCaseQuotedIdentifiers, supportsCatalogsInTableDefinitions, supportsSchemasInTableDefinitions, supportsStatementBatching, typesByTypeNumber
 
Fields inherited from class org.jpox.store.mapped.AbstractDatastoreAdapter
datastoreMajorVersion, datastoreMinorVersion, datastoreProductName, datastoreProductVersion, datastoreRevisionVersion, identifierQuoteString, LOCALISER_BASE, mappingManager, reservedKeywords
 
Constructor Summary
H2Adapter(java.sql.DatabaseMetaData metadata)
          Constructs a H2 adapter based on the given JDBC metadata.
 
Method Summary
 java.lang.String getAddColumnStatement(org.jpox.store.mapped.DatastoreContainerObject table, Column col)
          Accessor for the SQL statement to add a column to a table.
 java.lang.String getAddPrimaryKeyStatement(PrimaryKey pk, org.jpox.store.mapped.IdentifierFactory factory)
          HSQL 1.7.0 does not support ALTER TABLE to define a primary key
 java.lang.String getAutoIncrementKeyword()
          Accessor for the auto-increment keyword for generating DDLs (CREATE TABLEs...).
 java.lang.String getAutoIncrementStmt(Table table, java.lang.String columnName)
          Accessor for the auto-increment sql statement for this datastore.
 java.lang.String getDropTableStatement(org.jpox.store.mapped.DatastoreContainerObject table)
          Returns the appropriate SQL to drop the given table.
 java.lang.String getInsertStatementForNoColumns(Table table)
          Method to retutn 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 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.
 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 LIMUT keyword.
 int getRequiredTransactionIsolationLevel()
          Accessor for the "required" transaction isolation level if it has to be a certain value for this adapter.
 java.lang.String getSchemaName(java.sql.Connection conn)
          Accessor for the Schema Name for this datastore.
 java.lang.String getVendorID()
          Accessor for the vendor ID for this adapter.
 boolean isValidPrimaryKeyType(int datatype)
          Accessor for whether the specified type is allow to be part of a PK.
 org.jpox.store.mapped.expression.NumericExpression modOperator(org.jpox.store.mapped.expression.ScalarExpression operand1, org.jpox.store.mapped.expression.ScalarExpression operand2)
          Method to generate a modulus expression.
 org.jpox.store.mapped.expression.LogicSetExpression newTableExpression(org.jpox.store.mapped.expression.QueryExpression qs, org.jpox.store.mapped.DatastoreContainerObject table, org.jpox.store.mapped.DatastoreIdentifier rangeVar)
          Return a new TableExpression appropriate to MySQL.
 TypeInfo newTypeInfo(java.sql.ResultSet rs)
          Factory for TypeInfo objects.
 boolean supportsAnalysisMethods()
          Accessor for whether the SQL extensions CUBE, ROLLUP are supported.
 boolean supportsCheckConstraintsInEndCreateStatements()
          Whether this datastore supports the use of CHECK after the column definitions in CREATE TABLE statements (DDL).
 boolean supportsDeferredConstraints()
          Whether we support deferred constraints in keys.
 boolean supportsIdentityFields()
          Whether we support autoincrementing fields.
 boolean supportsLockWithSelectForUpdate()
          Whether this datastore supports locking using SELECT ...
 boolean supportsPrimaryKeyInCreateStatements()
          Whether the datastore supports specification of the primary key in CREATE TABLE statements.
 boolean supportsTransactionIsolationLevel(int isolationLevel)
          Accessor for whether the adapter supports the transaction isolation level.
 boolean supportsUniqueConstraintsInEndCreateStatements()
          Whether to allow Unique statements in the section of CREATE TABLE after the column definitions.
 
Methods inherited from class org.jpox.store.rdbms.adapter.DatabaseAdapter
absMethod, acosMethod, addTypeInfo, asinMethod, atanMethod, cartersianProduct, ceilMethod, closeConnection, concatOperator, cosMethod, createIndexesBeforeForeignKeys, endsWithMethod, expMethod, floorMethod, getAddCandidateKeyStatement, getAddForeignKeyStatement, getCatalogName, getCatalogSeparator, getCharColumnsPaddedWithSpaces, getCheckConstraintForValues, getColumns, getColumns, getConnection, getContinuationString, getCreateIndexStatement, getCreateTableStatement, getCurrentDateMethod, getCurrentTimeMethod, getCurrentTimestampMethod, getDatastoreDateStatement, getDayMethod, getDriverMajorVersion, getDriverMinorVersion, getDropViewStatement, getEscapeCharacter, getEscapedPatternExpression, getEscapePatternExpression, getExistingIndexes, getHourMethod, getMaxForeignKeys, getMaxIndexes, getMinuteMethod, getMonthMethod, getNewMappingManager, getNewUUIDFunction, getNonAnsiInnerJoinWhereClause, getNonAnsiLeftOuterJoinWhereClause, getNonAnsiRightOuterJoinWhereClause, getOperatorConcat, getPatternExpressionAnyCharacter, getPatternExpressionZeroMoreCharacters, getPlaceWithOptionAfterFromClause, getPlaceWithOptionWithinJoinClauses, getRangeByLimitWhereClause, getRangeByRowNumberColumn, getSecondMethod, getSelectNewUUIDStmt, getSelectWithLockOption, getSequenceCreateStmt, getSequenceNextStmt, getSupportsPersistOfUnassignedChar, getSurrogateForEmptyStrings, getTables, getTransactionIsolationForSchemaCreation, getTypeInfo, getUnlimitedLengthPrecisionValue, getYearMethod, includeOrderByColumnsInSelect, indexOfMethod, initialiseDatastore, isIdentityFieldDataType, isNullEqualsEmptyStrings, isSQLKeyword, isStoresLowerCaseIdentifiers, isStoresLowerCaseQuotedIdentifiers, isStoresMixedCaseIdentifiers, isStoresMixedCaseQuotedIdentifiers, isStoresUpperCaseIdentifiers, isStoresUpperCaseQuotedIdentifiers, iteratorReservedWords, iteratorTypeInfo, lengthMethod, loadDatastoreMapping, logConfiguration, logMethod, matchesMethod, newColumnInfo, newExportedKeyInfo, newForeignKeyInfo, newQueryStatement, newQueryStatement, parseKeywordList, requiresColumnDefaultsInitialising, setDefaultTypeInfoForJDBCType, sinMethod, sqrtMethod, startsWithMethod, substringMethod, substringMethod, supportsAlterTableDropConstraint, supportsAlterTableDropForeignKeyConstraint, supportsAnsiJoinSyntax, supportsAutoIncrementColumnTypeSpecification, supportsAutoIncrementKeysNullSpecification, supportsBooleanComparison, supportsCatalogsInTableDefinitions, supportsCheckInCreateStatements, supportsDefaultBeforeNullInColumnOptions, supportsDefaultKeywordInColumnOptions, supportsDefaultKeywordWithNotNullInColumnOptions, supportsDistinctWithSelectForUpdate, supportsEscapeExpressionInLikePredicate, supportsExistsSyntax, supportsForeignKeyDeleteAction, supportsForeignKeyUpdateAction, supportsNullsInCandidateKeys, supportsNullsKeywordInColumnOptions, supportsProjectionInTableReferenceJoins, supportsSchemasInTableDefinitions, supportsSettingBlobUsingSetString, supportsSettingClobUsingSetString, supportsStatementBatching, supportsStatementGetGeneratedKeys, supportsUnionSyntax, tanMethod, toNumericExpression, toString, toStringExpression, toStringExpression, translateMethod, trimMethod, useUnionAll
 
Methods inherited from class org.jpox.store.mapped.AbstractDatastoreAdapter
getAdapterTime, getDatastoreMajorVersion, getDatastoreMinorVersion, getIdentifierQuoteString, getMapping, getMapping, getMapping, getMapping, getMapping, getMappingManager, getMiliseconds, getTime, isBitReallyBoolean, isReservedKeyword, supportsQueryFetchSize, 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.mapped.DatastoreAdapter
getAdapterTime, getDatastoreMajorVersion, getDatastoreMinorVersion, getMapping, getMapping, getMapping, getMapping, getMappingManager, isBitReallyBoolean, isReservedKeyword, supportsQueryFetchSize
 

Constructor Detail

H2Adapter

public H2Adapter(java.sql.DatabaseMetaData metadata)
Constructs a H2 adapter based on the given JDBC metadata.

Parameters:
metadata - the database metadata.
Method Detail

getVendorID

public java.lang.String getVendorID()
Accessor for the vendor ID for this adapter.

Specified by:
getVendorID in interface org.jpox.store.mapped.DatastoreAdapter
Overrides:
getVendorID in class org.jpox.store.mapped.AbstractDatastoreAdapter
Returns:
The vendor ID

newTypeInfo

public TypeInfo newTypeInfo(java.sql.ResultSet rs)
Factory for TypeInfo objects.

Overrides:
newTypeInfo in class DatabaseAdapter
Parameters:
rs - The ResultSet from DatabaseMetaData.getTypeInfo().
Returns:
A TypeInfo object.

getMaxTableNameLength

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

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

getMaxConstraintNameLength

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

Specified by:
getMaxConstraintNameLength in interface RDBMSAdapter
Overrides:
getMaxConstraintNameLength in class DatabaseAdapter
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
Overrides:
getMaxIndexNameLength in class DatabaseAdapter
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
Overrides:
getMaxColumnNameLength in class DatabaseAdapter
Returns:
Max column name length

getAddColumnStatement

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

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

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 LIMUT keyword.

Specified by:
getRangeByLimitSelectClause in interface RDBMSAdapter
Overrides:
getRangeByLimitSelectClause in class DatabaseAdapter
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.

supportsTransactionIsolationLevel

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

Specified by:
supportsTransactionIsolationLevel in interface RDBMSAdapter
Overrides:
supportsTransactionIsolationLevel in class DatabaseAdapter
Parameters:
isolationLevel - the isolation level
Returns:
Whether the transaction isolation level setting is supported.

getRequiredTransactionIsolationLevel

public int getRequiredTransactionIsolationLevel()
Accessor for the "required" transaction isolation level if it has to be a certain value for this adapter.

Specified by:
getRequiredTransactionIsolationLevel in interface RDBMSAdapter
Overrides:
getRequiredTransactionIsolationLevel in class DatabaseAdapter
Returns:
Transaction isolation level (-1 implies no restriction)

supportsPrimaryKeyInCreateStatements

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

Specified by:
supportsPrimaryKeyInCreateStatements in interface RDBMSAdapter
Overrides:
supportsPrimaryKeyInCreateStatements in class DatabaseAdapter
Returns:
Whether it allows "PRIMARY KEY ..."

supportsLockWithSelectForUpdate

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

Specified by:
supportsLockWithSelectForUpdate in interface RDBMSAdapter
Overrides:
supportsLockWithSelectForUpdate in class DatabaseAdapter
Returns:
whether we support locking using SELECT ... FOR UPDATE.

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
Overrides:
getSchemaName in class DatabaseAdapter
Parameters:
conn - Connection to the datastore
Returns:
The schema name
Throws:
java.sql.SQLException - Thrown if error occurs in determining the schema name.

getAddPrimaryKeyStatement

public java.lang.String getAddPrimaryKeyStatement(PrimaryKey pk,
                                                  org.jpox.store.mapped.IdentifierFactory factory)
HSQL 1.7.0 does not support ALTER TABLE to define a primary key

Specified by:
getAddPrimaryKeyStatement in interface RDBMSAdapter
Overrides:
getAddPrimaryKeyStatement in class DatabaseAdapter
Parameters:
pk - An object describing the primary key.
factory - Identifier factory
Returns:
The PK statement

getDropTableStatement

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

 DROP TABLE FOO
 

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

supportsDeferredConstraints

public boolean supportsDeferredConstraints()
Whether we support deferred constraints in keys.

Specified by:
supportsDeferredConstraints in interface RDBMSAdapter
Overrides:
supportsDeferredConstraints in class DatabaseAdapter
Returns:
whether we support deferred constraints in keys.

supportsIdentityFields

public boolean supportsIdentityFields()
Whether we support autoincrementing fields.

Specified by:
supportsIdentityFields in interface org.jpox.store.mapped.DatastoreAdapter
Overrides:
supportsIdentityFields in class org.jpox.store.mapped.AbstractDatastoreAdapter
Returns:
whether we support autoincrementing fields.

supportsAnalysisMethods

public boolean supportsAnalysisMethods()
Accessor for whether the SQL extensions CUBE, ROLLUP are supported.

Specified by:
supportsAnalysisMethods in interface RDBMSAdapter
Overrides:
supportsAnalysisMethods in class DatabaseAdapter
Returns:
Whether the SQL extensions CUBE, ROLLUP are supported.

getAutoIncrementStmt

public java.lang.String getAutoIncrementStmt(Table table,
                                             java.lang.String columnName)
Accessor for the auto-increment sql statement for this datastore.

Specified by:
getAutoIncrementStmt in interface RDBMSAdapter
Overrides:
getAutoIncrementStmt in class DatabaseAdapter
Parameters:
table - 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 auto-increment key

getAutoIncrementKeyword

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

Specified by:
getAutoIncrementKeyword in interface RDBMSAdapter
Overrides:
getAutoIncrementKeyword in class DatabaseAdapter
Returns:
The keyword for a column using auto-increment

getInsertStatementForNoColumns

public java.lang.String getInsertStatementForNoColumns(Table table)
Method to retutn 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
Overrides:
getInsertStatementForNoColumns in class DatabaseAdapter
Parameters:
table - The table
Returns:
The INSERT statement

supportsUniqueConstraintsInEndCreateStatements

public boolean supportsUniqueConstraintsInEndCreateStatements()
Whether to allow Unique statements in the section of CREATE TABLE after the column definitions.

Specified by:
supportsUniqueConstraintsInEndCreateStatements in interface RDBMSAdapter
Overrides:
supportsUniqueConstraintsInEndCreateStatements in class DatabaseAdapter
Returns:
whether we can use UNIQUE after the column definitions CREATE TABLE.
See Also:
DatabaseAdapter.supportsUniqueConstraintsInEndCreateStatements()

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')) )

Overrides:
supportsCheckConstraintsInEndCreateStatements in class DatabaseAdapter
Returns:
whether we can use CHECK after the column definitions in CREATE TABLE.

isValidPrimaryKeyType

public boolean isValidPrimaryKeyType(int datatype)
Accessor for whether the specified type is allow to be part of a PK.

Specified by:
isValidPrimaryKeyType in interface RDBMSAdapter
Overrides:
isValidPrimaryKeyType in class DatabaseAdapter
Parameters:
datatype - The JDBC type
Returns:
Whether it is permitted in the PK

modOperator

public org.jpox.store.mapped.expression.NumericExpression modOperator(org.jpox.store.mapped.expression.ScalarExpression operand1,
                                                                      org.jpox.store.mapped.expression.ScalarExpression operand2)
Method to generate a modulus expression. The binary % operator is said to yield the remainder of its operands from an implied division; the left-hand operand is the dividend and the right-hand operand is the divisor. This returns MOD(expr1, expr2).

Specified by:
modOperator in interface org.jpox.store.mapped.DatastoreAdapter
Specified by:
modOperator in interface org.jpox.store.mapped.expression.ExpressionOperatorAdapter
Overrides:
modOperator in class org.jpox.store.mapped.AbstractDatastoreAdapter
Parameters:
operand1 - the left expression
operand2 - the right expression
Returns:
The Expression for modulus

newTableExpression

public org.jpox.store.mapped.expression.LogicSetExpression newTableExpression(org.jpox.store.mapped.expression.QueryExpression qs,
                                                                              org.jpox.store.mapped.DatastoreContainerObject table,
                                                                              org.jpox.store.mapped.DatastoreIdentifier rangeVar)
Return a new TableExpression appropriate to MySQL. MySQL does not support the TableExprAsSubjoins so instead we use TableExprAsJoins.

Specified by:
newTableExpression in interface RDBMSAdapter
Overrides:
newTableExpression in class DatabaseAdapter
Parameters:
qs - The QueryStatement to add the expression to
table - The table in the expression
rangeVar - range variable to assign to the expression.
Returns:
The expression.


Copyright © -2008 . All Rights Reserved.