org.datanucleus.store.rdbms.adapter
Class DatabaseAdapter

java.lang.Object
  extended by org.datanucleus.store.rdbms.adapter.DatabaseAdapter
All Implemented Interfaces:
org.datanucleus.store.mapped.DatastoreAdapter, org.datanucleus.store.mapped.expression.ExpressionConversionAdapter, org.datanucleus.store.mapped.expression.ExpressionLogicSetAdapter, org.datanucleus.store.mapped.expression.ExpressionMethodAdapter, org.datanucleus.store.mapped.expression.ExpressionOperatorAdapter, org.datanucleus.store.mapped.expression.ExpressionPatternAdapter, RDBMSAdapter
Direct Known Subclasses:
DB2Adapter, DerbyAdapter, FirebirdAdapter, H2Adapter, HSQLAdapter, InformixAdapter, McKoiAdapter, MSSQLServerAdapter, MySQLAdapter, OracleAdapter, PointbaseAdapter, PostgreSQLAdapter, SAPDBAdapter, SybaseAdapter

public class DatabaseAdapter
extends java.lang.Object
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.

See Also:
RDBMSAdapterFactory, DatabaseMetaData

Field Summary
protected  java.lang.String catalogSeparator
          The String used to separate catalog and table name.
protected  int datastoreMajorVersion
          The major version number of the underlying datastore.
protected  int datastoreMinorVersion
          The minor version number of the underlying datastore.
protected  java.lang.String datastoreProductName
          The product name of the underlying datastore.
protected  java.lang.String datastoreProductVersion
          The version number of the underlying datastore as a string.
protected  int datastoreRevisionVersion
          The revision version number of the underlying datastore.
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  java.lang.String identifierQuoteString
          The String used to quote identifiers.
protected static org.datanucleus.util.Localiser LOCALISER
           
protected static org.datanucleus.util.Localiser LOCALISER_BASE
           
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  java.util.Map<java.lang.String,java.lang.Object> properties
          Optional properties controlling the configuration.
protected  java.util.HashSet<java.lang.String> reservedKeywords
          The set of reserved keywords for this datastore.
protected  java.util.Collection<java.lang.String> supportedOptions
          Supported option names.
 
Fields inherited from interface org.datanucleus.store.rdbms.adapter.RDBMSAdapter
ACCESS_PARENTQUERY_IN_SUBQUERY, ALTER_TABLE_DROP_CONSTRAINT_SYNTAX, ALTER_TABLE_DROP_FOREIGN_KEY_CONSTRAINT, ANSI_JOIN_SYNTAX, AUTO_INCREMENT_COLUMN_TYPE_SPECIFICATION, AUTO_INCREMENT_KEYS_NULL_SPECIFICATION, BLOB_SET_USING_SETSTRING, CHAR_COLUMNS_PADDED_WITH_SPACES, CHECK_IN_CREATE_STATEMENTS, CHECK_IN_END_CREATE_STATEMENTS, CLOB_SET_USING_SETSTRING, CREATE_INDEXES_BEFORE_FOREIGN_KEYS, DATETIME_STORES_MILLISECS, DEFAULT_BEFORE_NULL_IN_COLUMN_OPTIONS, DEFAULT_KEYWORD_IN_COLUMN_OPTIONS, DEFAULT_KEYWORD_WITH_NOT_NULL_IN_COLUMN_OPTIONS, DEFERRED_CONSTRAINTS, DISTINCT_WITH_SELECT_FOR_UPDATE, EXISTS_SYNTAX, FK_DELETE_ACTION_CASCADE, FK_DELETE_ACTION_DEFAULT, FK_DELETE_ACTION_NULL, FK_DELETE_ACTION_RESTRICT, FK_UPDATE_ACTION_CASCADE, FK_UPDATE_ACTION_DEFAULT, FK_UPDATE_ACTION_NULL, FK_UPDATE_ACTION_RESTRICT, GET_GENERATED_KEYS_STATEMENT, INCLUDE_ORDERBY_COLS_IN_SELECT, LOCK_OPTION_PLACED_AFTER_FROM, LOCK_OPTION_PLACED_WITHIN_JOIN, LOCK_WITH_SELECT_FOR_UPDATE, NULL_EQUALS_EMPTY_STRING, NULLS_IN_CANDIDATE_KEYS, NULLS_KEYWORD_IN_COLUMN_OPTIONS, ORDERBY_USING_SELECT_COLUMN_INDEX, PERSIST_OF_UNASSIGNED_CHAR, PRIMARYKEY_IN_CREATE_STATEMENTS, STATEMENT_BATCHING, TX_ISOLATION_NONE, TX_ISOLATION_READ_COMMITTED, TX_ISOLATION_READ_UNCOMMITTED, TX_ISOLATION_REPEATABLE_READ, TX_ISOLATION_SERIALIZABLE, UNION_SYNTAX, UNIQUE_IN_END_CREATE_STATEMENTS, USE_UNION_ALL, VIEWS
 
Fields inherited from interface org.datanucleus.store.mapped.DatastoreAdapter
ANALYSIS_METHODS, BIT_IS_REALLY_BOOLEAN, BOOLEAN_COMPARISON, CATALOGS_IN_TABLE_DEFINITIONS, ESCAPE_EXPRESSION_IN_LIKE_PREDICATE, IDENTIFIERS_LOWERCASE, IDENTIFIERS_LOWERCASE_QUOTED, IDENTIFIERS_MIXEDCASE, IDENTIFIERS_MIXEDCASE_QUOTED, IDENTIFIERS_MIXEDCASE_QUOTED_SENSITIVE, IDENTIFIERS_MIXEDCASE_SENSITIVE, IDENTIFIERS_UPPERCASE, IDENTIFIERS_UPPERCASE_QUOTED, IDENTITY_COLUMNS, PROJECTION_IN_TABLE_REFERENCE_JOINS, SCHEMAS_IN_TABLE_DEFINITIONS, SEQUENCES
 
Constructor Summary
protected DatabaseAdapter(java.sql.DatabaseMetaData metadata)
          Constructs a database adapter based on the given JDBC metadata.
 
Method Summary
protected  void addSQLTypeForJDBCType(org.datanucleus.store.schema.StoreSchemaHandler handler, org.datanucleus.ManagedConnection mconn, short jdbcTypeNumber, SQLTypeInfo sqlType, boolean addIfNotPresent)
          Convenience method for use by adapters to add their own fake JDBC/SQL types in where the JDBC driver doesn't provide some type.
 java.lang.String cartersianProduct(org.datanucleus.store.mapped.expression.LogicSetExpression Y)
          Generates a expression that represents the cartesian product of two sets: X and Y.
 org.datanucleus.store.mapped.expression.ScalarExpression concatOperator(org.datanucleus.store.mapped.expression.ScalarExpression operand1, org.datanucleus.store.mapped.expression.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.
 org.datanucleus.store.mapped.expression.BooleanExpression endsWithMethod(org.datanucleus.store.mapped.expression.ScalarExpression leftOperand, org.datanucleus.store.mapped.expression.ScalarExpression rightOperand)
          Returns whether this string ends with the specified string.
 long getAdapterTime(java.sql.Timestamp time)
           
 java.lang.String getAddCandidateKeyStatement(CandidateKey ck, org.datanucleus.store.mapped.IdentifierFactory factory)
          Returns the appropriate SQL to add a candidate key to its table.
 java.lang.String getAddColumnStatement(org.datanucleus.store.mapped.DatastoreContainerObject table, Column col)
          Accessor for the SQL statement to add a column to a table.
 java.lang.String getAddForeignKeyStatement(ForeignKey fk, org.datanucleus.store.mapped.IdentifierFactory factory)
          Returns the appropriate SQL to add a foreign key to its table.
 java.lang.String getAddPrimaryKeyStatement(PrimaryKey pk, org.datanucleus.store.mapped.IdentifierFactory factory)
          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(Table table, 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.lang.String getCheckConstraintForValues(org.datanucleus.store.mapped.DatastoreIdentifier identifier, java.lang.Object[] values, boolean nullable)
          Creates a CHECK constraint definition based on the given values e.g.
 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(ConnectionProvider connProvider, javax.sql.DataSource[] ds, 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, org.datanucleus.store.mapped.IdentifierFactory factory)
          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.
 org.datanucleus.store.mapped.expression.ScalarExpression getCurrentDateMethod(org.datanucleus.store.mapped.expression.QueryExpression qs)
          Method to return an expression for the current date in the datastore.
 org.datanucleus.store.mapped.expression.ScalarExpression getCurrentTimeMethod(org.datanucleus.store.mapped.expression.QueryExpression qs)
          Method to return an expression for the current time in the datastore.
 org.datanucleus.store.mapped.expression.ScalarExpression getCurrentTimestampMethod(org.datanucleus.store.mapped.expression.QueryExpression qs)
          Method to return an expression for the current timestamp in the datastore.
 java.lang.String getDatastoreDateStatement()
          Accessor for a statement that will return the statement to use to get the datastore date.
 int getDatastoreIdentifierMaxLength(org.datanucleus.store.mapped.IdentifierType identifierType)
          Method to return the maximum length of a datastore identifier of the specified type.
 int getDatastoreMajorVersion()
           
 int getDatastoreMinorVersion()
           
 int getDriverMajorVersion()
          Accessor for the JDBC driver major version
 int getDriverMinorVersion()
          Accessor for the JDBC driver minor version
 java.lang.String getDropTableStatement(org.datanucleus.store.mapped.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.
 org.datanucleus.store.mapped.expression.ScalarExpression getEscapedPatternExpression(org.datanucleus.store.mapped.expression.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.lang.String catalog, java.lang.String schema, java.lang.String table)
          Provide the existing indexes in the database for the table.
 java.lang.String getIdentifierQuoteString()
          Accessor for an identifier quote string.
 java.lang.String getInsertStatementForNoColumns(Table table)
          Method to return the INSERT statement to use when inserting into a table that has no columns specified.
protected  org.datanucleus.store.mapped.mapping.JavaTypeMapping getMapping(java.lang.Class c, org.datanucleus.store.mapped.expression.ScalarExpression expr)
          Convenience accessor for the mapping for the specified class.
 org.datanucleus.store.mapped.mapping.MappingManager getMappingManager(org.datanucleus.store.mapped.MappedStoreManager storeMgr)
          Accessor for a MappingManager suitable for use with this datastore adapter.
 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.
protected  int getMiliseconds(long nanos)
           
 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 getNumericConversionFunction()
          Accessor for the function to use for converting to numeric.
 org.datanucleus.store.mapped.expression.NumericExpression getNumericExpressionForMethod(java.lang.String method, org.datanucleus.store.mapped.expression.ScalarExpression expr)
          Accessor for a numeric expression to represent the method call, with passed argument.
 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.
 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.
 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 getSelectForUpdateText()
          Method returning the text to append to the end of the SELECT to perform the equivalent of "SELECT ...
 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.util.Collection<java.lang.String> getSupportedOptions()
          Accessor for the options that are supported by this datastore adapter and the underlying datastore.
 java.lang.String getSurrogateForEmptyStrings()
          Some databases, Oracle, treats an empty string (0 length) equals null
protected  long getTime(long time, long nanos)
           
 int getTransactionIsolationForSchemaCreation()
          Accessor for the transaction isolation level to use during schema creation.
 int getUnlimitedLengthPrecisionValue(SQLTypeInfo typeInfo)
          Returns the precision value to be used when creating string columns of "unlimited" length.
 java.lang.Object getValueForProperty(java.lang.String name)
          Accessor for a property.
 java.lang.String getVendorID()
           
 org.datanucleus.store.mapped.expression.NumericExpression indexOfMethod(org.datanucleus.store.mapped.expression.ScalarExpression source, org.datanucleus.store.mapped.expression.ScalarExpression str, org.datanucleus.store.mapped.expression.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
 void initialiseTypes(org.datanucleus.store.schema.StoreSchemaHandler handler, org.datanucleus.ManagedConnection mconn)
          Initialise the types for this datastore.
 boolean isIdentityFieldDataType(java.lang.String typeName)
          Verifies if the given typeName is auto incremented by the datastore.
 boolean isKeyword(java.lang.String word)
          Tests if a given string is a SQL key word.
 boolean isReservedKeyword(java.lang.String word)
          Tests if a given string is a SQL keyword.
 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
 void logConfiguration()
          Convenience method to log the configuration of this datastore adapter.
 org.datanucleus.store.mapped.expression.StringExpression lowerMethod(org.datanucleus.store.mapped.expression.StringExpression str)
           
 org.datanucleus.store.mapped.expression.BooleanExpression matchesMethod(org.datanucleus.store.mapped.expression.StringExpression text, org.datanucleus.store.mapped.expression.StringExpression pattern)
          Matches this to the argument expression pattern.
 org.datanucleus.store.mapped.expression.NumericExpression modOperator(org.datanucleus.store.mapped.expression.ScalarExpression operand1, org.datanucleus.store.mapped.expression.ScalarExpression operand2)
           
 ForeignKeyInfo newFKInfo(java.sql.ResultSet rs)
          Method to return ForeignKeyInfo for the current row of the ResultSet which will have been obtained from a call to DatabaseMetaData.getImportedKeys() or DatabaseMetaData.getExportedKeys().
 org.datanucleus.store.mapped.expression.QueryExpression newQueryStatement(org.datanucleus.store.mapped.DatastoreContainerObject table, org.datanucleus.store.mapped.DatastoreIdentifier rangeVar, org.datanucleus.ClassLoaderResolver clr)
          Accessor for a new query statement.
 RDBMSColumnInfo newRDBMSColumnInfo(java.sql.ResultSet rs)
          Create a new column info from the current row of the passed ResultSet.
 SQLTypeInfo newSQLTypeInfo(java.sql.ResultSet rs)
          Create a new SQL type info from the current row of the passed ResultSet.
 org.datanucleus.store.mapped.expression.LogicSetExpression newTableExpression(org.datanucleus.store.mapped.expression.QueryExpression qs, org.datanucleus.store.mapped.DatastoreContainerObject table, org.datanucleus.store.mapped.DatastoreIdentifier rangeVar)
          Returns a new TableExpression object appropriate for this DBMS.
protected  java.util.Set parseKeywordList(java.lang.String list)
          Utility method to parse a list of keywords and split them out into words.
 void removeUnsupportedMappings(org.datanucleus.store.schema.StoreSchemaHandler handler, org.datanucleus.ManagedConnection mconn)
          Remove all mappings from the mapping manager that don't have a datastore type initialised.
 void setProperties(java.util.Map<java.lang.String,java.lang.Object> props)
          Set any properties controlling how the adapter is configured.
 org.datanucleus.store.mapped.expression.BooleanExpression startsWithMethod(org.datanucleus.store.mapped.expression.ScalarExpression source, org.datanucleus.store.mapped.expression.ScalarExpression str)
          Method to handle the starts with operation.
 org.datanucleus.store.mapped.expression.StringExpression substringMethod(org.datanucleus.store.mapped.expression.StringExpression str, org.datanucleus.store.mapped.expression.NumericExpression begin)
          Returns the appropriate SQL expression for the JDOQL String.substring(str,begin) method.
 org.datanucleus.store.mapped.expression.StringExpression substringMethod(org.datanucleus.store.mapped.expression.StringExpression str, org.datanucleus.store.mapped.expression.NumericExpression begin, org.datanucleus.store.mapped.expression.NumericExpression end)
          Returns the appropriate SQL expression for the JDOQL String.substring(str,begin,end) method.
 boolean supportsOption(java.lang.String option)
          Accessor for whether the supplied option is supported.
 boolean supportsQueryFetchSize(int size)
          Whether the datastore will support setting the query fetch size to the supplied value.
 boolean supportsTransactionIsolation(int level)
          Accessor for whether this database adapter supports the specified transaction isolation.
 org.datanucleus.store.mapped.expression.NumericExpression toNumericExpression(org.datanucleus.store.mapped.expression.CharacterExpression expr)
          Returns the appropriate expression for the (int)'A' expression.
 java.lang.String toString()
           
 org.datanucleus.store.mapped.expression.StringExpression toStringExpression(org.datanucleus.store.mapped.expression.NumericExpression expr)
          A String conversion that converts a numeric expression to string.
 org.datanucleus.store.mapped.expression.StringExpression toStringExpression(org.datanucleus.store.mapped.expression.StringLiteral expr)
          A String conversion that converts a String literal to String expression.
 org.datanucleus.store.mapped.expression.StringExpression translateMethod(org.datanucleus.store.mapped.expression.ScalarExpression expr, org.datanucleus.store.mapped.expression.ScalarExpression toExpr, org.datanucleus.store.mapped.expression.ScalarExpression fromExpr)
          Method to translate all chars in this expression to the fromExpr which corresponds to toExpr.
 org.datanucleus.store.mapped.expression.StringExpression trimMethod(org.datanucleus.store.mapped.expression.StringExpression str, boolean leading, boolean trailing)
          Returns the appropriate SQL expression for a query "trim" method.
 org.datanucleus.store.mapped.expression.StringExpression upperMethod(org.datanucleus.store.mapped.expression.StringExpression str)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOCALISER_BASE

protected static final org.datanucleus.util.Localiser LOCALISER_BASE

LOCALISER

protected static final org.datanucleus.util.Localiser LOCALISER

reservedKeywords

protected final java.util.HashSet<java.lang.String> reservedKeywords
The set of reserved keywords for this datastore.


datastoreProductName

protected java.lang.String datastoreProductName
The product name of the underlying datastore.


datastoreProductVersion

protected java.lang.String datastoreProductVersion
The version number of the underlying datastore as a string.


datastoreMajorVersion

protected int datastoreMajorVersion
The major version number of the underlying datastore.


datastoreMinorVersion

protected int datastoreMinorVersion
The minor version number of the underlying datastore.


datastoreRevisionVersion

protected int datastoreRevisionVersion
The revision version number of the underlying datastore.


identifierQuoteString

protected java.lang.String identifierQuoteString
The String used to quote identifiers.


supportedOptions

protected java.util.Collection<java.lang.String> supportedOptions
Supported option names.


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.


catalogSeparator

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


properties

protected java.util.Map<java.lang.String,java.lang.Object> properties
Optional properties controlling the configuration.

Constructor Detail

DatabaseAdapter

protected DatabaseAdapter(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 org.datanucleus.store.mapped.DatastoreAdapter
Parameters:
conn - the connection to the datastore

initialiseTypes

public void initialiseTypes(org.datanucleus.store.schema.StoreSchemaHandler handler,
                            org.datanucleus.ManagedConnection mconn)
Initialise the types for this datastore.

Specified by:
initialiseTypes in interface org.datanucleus.store.mapped.DatastoreAdapter
Parameters:
handler - SchemaHandler that we initialise the types for
mconn - Managed connection to use

setProperties

public void setProperties(java.util.Map<java.lang.String,java.lang.Object> props)
Set any properties controlling how the adapter is configured.

Specified by:
setProperties in interface org.datanucleus.store.mapped.DatastoreAdapter
Parameters:
props - The properties

getValueForProperty

public java.lang.Object getValueForProperty(java.lang.String name)
Accessor for a property. Null imples not defined

Parameters:
name - Name of the property
Returns:
Its value

removeUnsupportedMappings

public void removeUnsupportedMappings(org.datanucleus.store.schema.StoreSchemaHandler handler,
                                      org.datanucleus.ManagedConnection mconn)
Remove all mappings from the mapping manager that don't have a datastore type initialised.

Specified by:
removeUnsupportedMappings in interface org.datanucleus.store.mapped.DatastoreAdapter
Parameters:
handler - Schema handler
mconn - Managed connection to use

addSQLTypeForJDBCType

protected void addSQLTypeForJDBCType(org.datanucleus.store.schema.StoreSchemaHandler handler,
                                     org.datanucleus.ManagedConnection mconn,
                                     short jdbcTypeNumber,
                                     SQLTypeInfo sqlType,
                                     boolean addIfNotPresent)
Convenience method for use by adapters to add their own fake JDBC/SQL types in where the JDBC driver doesn't provide some type.

Parameters:
handler - the schema handler managing the types
mconn - Connection to use
jdbcTypeNumber - The JDBC type
sqlType - The type info to use
addIfNotPresent - whether to add only if JDBC type not present

supportsTransactionIsolation

public boolean supportsTransactionIsolation(int level)
Accessor for whether this database adapter supports the specified transaction isolation.

Specified by:
supportsTransactionIsolation in interface RDBMSAdapter
Parameters:
level - The isolation level (as defined by Connection enums).
Returns:
Whether it is supported.

logConfiguration

public void logConfiguration()
Convenience method to log the configuration of this datastore adapter.

Specified by:
logConfiguration in interface RDBMSAdapter

getSupportedOptions

public java.util.Collection<java.lang.String> getSupportedOptions()
Accessor for the options that are supported by this datastore adapter and the underlying datastore.

Specified by:
getSupportedOptions in interface org.datanucleus.store.mapped.DatastoreAdapter
Returns:
The options (Collection)

supportsOption

public boolean supportsOption(java.lang.String option)
Accessor for whether the supplied option is supported.

Specified by:
supportsOption in interface org.datanucleus.store.mapped.DatastoreAdapter
Parameters:
option - The option
Returns:
Whether supported.

getMappingManager

public org.datanucleus.store.mapped.mapping.MappingManager getMappingManager(org.datanucleus.store.mapped.MappedStoreManager storeMgr)
Accessor for a MappingManager suitable for use with this datastore adapter.

Specified by:
getMappingManager in interface org.datanucleus.store.mapped.DatastoreAdapter
Parameters:
storeMgr - The StoreManager
Returns:
the MappingManager

getAdapterTime

public long getAdapterTime(java.sql.Timestamp time)
Specified by:
getAdapterTime in interface org.datanucleus.store.mapped.DatastoreAdapter

getTime

protected long getTime(long time,
                       long nanos)

getMiliseconds

protected int getMiliseconds(long nanos)

getDatastoreMajorVersion

public int getDatastoreMajorVersion()
Specified by:
getDatastoreMajorVersion in interface org.datanucleus.store.mapped.DatastoreAdapter

getDatastoreMinorVersion

public int getDatastoreMinorVersion()
Specified by:
getDatastoreMinorVersion in interface org.datanucleus.store.mapped.DatastoreAdapter

supportsQueryFetchSize

public boolean supportsQueryFetchSize(int size)
Whether the datastore will support setting the query fetch size to the supplied value.

Specified by:
supportsQueryFetchSize in interface org.datanucleus.store.mapped.DatastoreAdapter
Parameters:
size - The value to set to
Returns:
Whether it is supported.

getVendorID

public java.lang.String getVendorID()
Specified by:
getVendorID in interface org.datanucleus.store.mapped.DatastoreAdapter

isReservedKeyword

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

The list of key words tested against is defined to contain all SQL/92 keywords, 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:
isReservedKeyword in interface org.datanucleus.store.mapped.DatastoreAdapter
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

getIdentifierQuoteString

public java.lang.String getIdentifierQuoteString()
Accessor for an identifier quote string.

Specified by:
getIdentifierQuoteString in interface org.datanucleus.store.mapped.DatastoreAdapter
Returns:
Identifier quote string.

getDriverMajorVersion

public int getDriverMajorVersion()
Accessor for the JDBC driver major version

Returns:
The driver major version

getDriverMinorVersion

public int getDriverMinorVersion()
Accessor for the JDBC driver minor version

Returns:
The driver minor version

getDatastoreIdentifierMaxLength

public int getDatastoreIdentifierMaxLength(org.datanucleus.store.mapped.IdentifierType identifierType)
Method to return the maximum length of a datastore identifier of the specified type. If no limit exists then returns -1

Specified by:
getDatastoreIdentifierMaxLength in interface org.datanucleus.store.mapped.DatastoreAdapter
Parameters:
identifierType - Type of identifier (see IdentifierFactory.TABLE, etc)
Returns:
The max permitted length of this type of identifier

getMaxForeignKeys

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

Specified by:
getMaxForeignKeys in interface org.datanucleus.store.mapped.DatastoreAdapter
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 org.datanucleus.store.mapped.DatastoreAdapter
Returns:
Max number of indexes for a table

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

newRDBMSColumnInfo

public RDBMSColumnInfo newRDBMSColumnInfo(java.sql.ResultSet rs)
Description copied from interface: RDBMSAdapter
Create a new column info from the current row of the passed ResultSet. Allows an adapter to override particular column information where the JDBC driver is known to be buggy.

Specified by:
newRDBMSColumnInfo in interface RDBMSAdapter
Parameters:
rs - Result Set
Returns:
The column info

newSQLTypeInfo

public SQLTypeInfo newSQLTypeInfo(java.sql.ResultSet rs)
Description copied from interface: RDBMSAdapter
Create a new SQL type info from the current row of the passed ResultSet. Allows an adapter to override particular types where the JDBC driver is known to be buggy.

Specified by:
newSQLTypeInfo in interface RDBMSAdapter
Parameters:
rs - ResultSet
Returns:
The SQL type info

newFKInfo

public ForeignKeyInfo newFKInfo(java.sql.ResultSet rs)
Method to return ForeignKeyInfo for the current row of the ResultSet which will have been obtained from a call to DatabaseMetaData.getImportedKeys() or DatabaseMetaData.getExportedKeys().

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

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.

isKeyword

public boolean isKeyword(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.

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

getUnlimitedLengthPrecisionValue

public int getUnlimitedLengthPrecisionValue(SQLTypeInfo 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. However, for some types in some databases the value must be computed.

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

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

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

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
Returns:
Transaction isolation level (-1 implies no restriction)

getConnection

public java.sql.Connection getConnection(ConnectionProvider connProvider,
                                         javax.sql.DataSource[] ds,
                                         int isolationLevel)
                                  throws java.sql.SQLException
Accessor for a Connection to the datastore. TODO Remove this since it is embodied in ConnectionFactoryImpl now

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

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 org.datanucleus.store.mapped.DatastoreAdapter
Returns:
Catalog separator string.

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

getSelectForUpdateText

public java.lang.String getSelectForUpdateText()
Method returning the text to append to the end of the SELECT to perform the equivalent of "SELECT ... FOR UPDATE" (on some RDBMS). This method means that we can have different text with some datastores (e.g Derby).

Returns:
The "FOR UPDATE" text

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()"

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(Table table,
                                             java.lang.String columnName)
Accessor for the autoincrementing sql statement for this datastore.

Specified by:
getAutoIncrementStmt in interface RDBMSAdapter
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 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

isIdentityFieldDataType

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

Specified by:
isIdentityFieldDataType in interface org.datanucleus.store.mapped.DatastoreAdapter
Parameters:
typeName - the datastore type name
Returns:
true when the typeName has values auto incremented by the datastore

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.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. This is implemented if and only if the datastore has its own way of getting indexes. Otherwise we will use DatabaseMetaData.getIndexInfo(). The implementation here returns null.

Specified by:
getExistingIndexes in interface RDBMSAdapter
Parameters:
conn - the JDBC connection
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

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,
                                                  org.datanucleus.store.mapped.IdentifierFactory factory)
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.
factory - Identifier factory
Returns:
The text of the SQL statement.

getAddCandidateKeyStatement

public java.lang.String getAddCandidateKeyStatement(CandidateKey ck,
                                                    org.datanucleus.store.mapped.IdentifierFactory factory)
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.
factory - Identifier factory
Returns:
The text of the SQL statement.

getAddForeignKeyStatement

public java.lang.String getAddForeignKeyStatement(ForeignKey fk,
                                                  org.datanucleus.store.mapped.IdentifierFactory factory)
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.
factory - Identifier factory
Returns:
The text of the SQL statement.

getAddColumnStatement

public java.lang.String getAddColumnStatement(org.datanucleus.store.mapped.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,
                                                org.datanucleus.store.mapped.IdentifierFactory factory)
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.
factory - Identifier factory
Returns:
The text of the SQL statement.

getCheckConstraintForValues

public java.lang.String getCheckConstraintForValues(org.datanucleus.store.mapped.DatastoreIdentifier identifier,
                                                    java.lang.Object[] values,
                                                    boolean nullable)
Creates a CHECK constraint definition based on the given values e.g.
CHECK ("COLUMN" IN ('VAL1','VAL2') OR "COLUMN" IS NULL)

Specified by:
getCheckConstraintForValues in interface RDBMSAdapter
Parameters:
identifier - Column identifier
values - Valid values
nullable - whether the datastore identifier is null
Returns:
The check constraint

getDropTableStatement

public java.lang.String getDropTableStatement(org.datanucleus.store.mapped.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.

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

toString

public java.lang.String toString()
Specified by:
toString in interface org.datanucleus.store.mapped.DatastoreAdapter
Overrides:
toString in class java.lang.Object

getDatastoreDateStatement

public java.lang.String getDatastoreDateStatement()
Accessor for a statement that will return the statement to use to get the datastore date.

Specified by:
getDatastoreDateStatement in interface RDBMSAdapter
Returns:
SQL statement to get the datastore date

getCurrentDateMethod

public org.datanucleus.store.mapped.expression.ScalarExpression getCurrentDateMethod(org.datanucleus.store.mapped.expression.QueryExpression qs)
Method to return an expression for the current date in the datastore.

Specified by:
getCurrentDateMethod in interface org.datanucleus.store.mapped.expression.ExpressionMethodAdapter
Parameters:
qs - QueryExpression
Returns:
Current date expression for this datastore

getCurrentTimeMethod

public org.datanucleus.store.mapped.expression.ScalarExpression getCurrentTimeMethod(org.datanucleus.store.mapped.expression.QueryExpression qs)
Method to return an expression for the current time in the datastore.

Specified by:
getCurrentTimeMethod in interface org.datanucleus.store.mapped.expression.ExpressionMethodAdapter
Parameters:
qs - QueryExpression
Returns:
Current time expression for this datastore

getCurrentTimestampMethod

public org.datanucleus.store.mapped.expression.ScalarExpression getCurrentTimestampMethod(org.datanucleus.store.mapped.expression.QueryExpression qs)
Method to return an expression for the current timestamp in the datastore.

Specified by:
getCurrentTimestampMethod in interface org.datanucleus.store.mapped.expression.ExpressionMethodAdapter
Parameters:
qs - QueryExpression
Returns:
Current timestamp expression for this datastore

modOperator

public org.datanucleus.store.mapped.expression.NumericExpression modOperator(org.datanucleus.store.mapped.expression.ScalarExpression operand1,
                                                                             org.datanucleus.store.mapped.expression.ScalarExpression operand2)
Specified by:
modOperator in interface org.datanucleus.store.mapped.DatastoreAdapter
Specified by:
modOperator in interface org.datanucleus.store.mapped.expression.ExpressionOperatorAdapter

getMapping

protected final org.datanucleus.store.mapped.mapping.JavaTypeMapping getMapping(java.lang.Class c,
                                                                                org.datanucleus.store.mapped.expression.ScalarExpression expr)
Convenience accessor for the mapping for the specified class. Provides a wrapper to the method on the MappingManager.

Parameters:
c - Java type
expr - the ScalarExpression
Returns:
The mapping for the class.

getEscapedPatternExpression

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

Specified by:
getEscapedPatternExpression in interface org.datanucleus.store.mapped.expression.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 org.datanucleus.store.mapped.expression.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 org.datanucleus.store.mapped.expression.ExpressionPatternAdapter
Returns:
the pattern string.

getEscapePatternExpression

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

Specified by:
getEscapePatternExpression in interface org.datanucleus.store.mapped.expression.ExpressionPatternAdapter
Returns:
the character.

getEscapeCharacter

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

Specified by:
getEscapeCharacter in interface org.datanucleus.store.mapped.expression.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.

cartersianProduct

public java.lang.String cartersianProduct(org.datanucleus.store.mapped.expression.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 org.datanucleus.store.mapped.expression.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

newQueryStatement

public org.datanucleus.store.mapped.expression.QueryExpression newQueryStatement(org.datanucleus.store.mapped.DatastoreContainerObject table,
                                                                                 org.datanucleus.store.mapped.DatastoreIdentifier rangeVar,
                                                                                 org.datanucleus.ClassLoaderResolver clr)
Accessor for a new query statement.

Specified by:
newQueryStatement in interface org.datanucleus.store.mapped.DatastoreAdapter
Parameters:
table - The table to query
rangeVar - A range variable for the query
clr - The ClassLoaderResolver
Returns:
The Query Statement

newTableExpression

public org.datanucleus.store.mapped.expression.LogicSetExpression newTableExpression(org.datanucleus.store.mapped.expression.QueryExpression qs,
                                                                                     org.datanucleus.store.mapped.DatastoreContainerObject table,
                                                                                     org.datanucleus.store.mapped.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

getNumericConversionFunction

public java.lang.String getNumericConversionFunction()
Accessor for the function to use for converting to numeric.

Returns:
The numeric conversion function for this datastore.

toNumericExpression

public org.datanucleus.store.mapped.expression.NumericExpression toNumericExpression(org.datanucleus.store.mapped.expression.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 org.datanucleus.store.mapped.expression.ExpressionConversionAdapter
Parameters:
expr - The CharacterExpression
Returns:
The NumericExpression

translateMethod

public org.datanucleus.store.mapped.expression.StringExpression translateMethod(org.datanucleus.store.mapped.expression.ScalarExpression expr,
                                                                                org.datanucleus.store.mapped.expression.ScalarExpression toExpr,
                                                                                org.datanucleus.store.mapped.expression.ScalarExpression fromExpr)
Method to translate all chars in this expression to the fromExpr which corresponds to toExpr.

Specified by:
translateMethod in interface org.datanucleus.store.mapped.expression.ExpressionMethodAdapter
Returns:
The expression.

getNumericExpressionForMethod

public org.datanucleus.store.mapped.expression.NumericExpression getNumericExpressionForMethod(java.lang.String method,
                                                                                               org.datanucleus.store.mapped.expression.ScalarExpression expr)
Accessor for a numeric expression to represent the method call, with passed argument.

Specified by:
getNumericExpressionForMethod in interface org.datanucleus.store.mapped.DatastoreAdapter
Parameters:
method - The method (case insensitive)
expr - The argument to the method
Returns:
The numeric expression that results

endsWithMethod

public org.datanucleus.store.mapped.expression.BooleanExpression endsWithMethod(org.datanucleus.store.mapped.expression.ScalarExpression leftOperand,
                                                                                org.datanucleus.store.mapped.expression.ScalarExpression rightOperand)
Returns whether this string ends with the specified string.

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

matchesMethod

public org.datanucleus.store.mapped.expression.BooleanExpression matchesMethod(org.datanucleus.store.mapped.expression.StringExpression text,
                                                                               org.datanucleus.store.mapped.expression.StringExpression pattern)
Matches this to the argument expression pattern. Use "." to find any character and ".*" for wildcard matches. A global case-insensitive flag "(?i)" can be set for the pattern. If used, the global case-insensitive flag must prefix the pattern. The pattern passed to matches must be a literal or parameter.

Specified by:
matchesMethod in interface org.datanucleus.store.mapped.expression.ExpressionMethodAdapter
Parameters:
text - The argument to the length() method.
pattern - The literal expression with the pattern.
Returns:
the match expression.

toStringExpression

public org.datanucleus.store.mapped.expression.StringExpression toStringExpression(org.datanucleus.store.mapped.expression.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 org.datanucleus.store.mapped.expression.ExpressionConversionAdapter
Parameters:
expr - The NumericExpression
Returns:
the StringExpression

toStringExpression

public org.datanucleus.store.mapped.expression.StringExpression toStringExpression(org.datanucleus.store.mapped.expression.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 org.datanucleus.store.mapped.expression.ExpressionConversionAdapter
Parameters:
expr - The NumericExpression
Returns:
the StringExpression

substringMethod

public org.datanucleus.store.mapped.expression.StringExpression substringMethod(org.datanucleus.store.mapped.expression.StringExpression str,
                                                                                org.datanucleus.store.mapped.expression.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 org.datanucleus.store.mapped.expression.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.

lowerMethod

public org.datanucleus.store.mapped.expression.StringExpression lowerMethod(org.datanucleus.store.mapped.expression.StringExpression str)
Specified by:
lowerMethod in interface org.datanucleus.store.mapped.expression.ExpressionMethodAdapter

upperMethod

public org.datanucleus.store.mapped.expression.StringExpression upperMethod(org.datanucleus.store.mapped.expression.StringExpression str)
Specified by:
upperMethod in interface org.datanucleus.store.mapped.expression.ExpressionMethodAdapter

trimMethod

public org.datanucleus.store.mapped.expression.StringExpression trimMethod(org.datanucleus.store.mapped.expression.StringExpression str,
                                                                           boolean leading,
                                                                           boolean trailing)
Returns the appropriate SQL expression for a query "trim" method. It should return something like:
TRIM(str)

Specified by:
trimMethod in interface org.datanucleus.store.mapped.expression.ExpressionMethodAdapter
Parameters:
str - The first argument to the trim() method.
leading - Whether to trim leading spaces
trailing - Whether to trim trailing spaces
Returns:
The text of the SQL expression.

substringMethod

public org.datanucleus.store.mapped.expression.StringExpression substringMethod(org.datanucleus.store.mapped.expression.StringExpression str,
                                                                                org.datanucleus.store.mapped.expression.NumericExpression begin,
                                                                                org.datanucleus.store.mapped.expression.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 org.datanucleus.store.mapped.expression.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 org.datanucleus.store.mapped.expression.BooleanExpression startsWithMethod(org.datanucleus.store.mapped.expression.ScalarExpression source,
                                                                                  org.datanucleus.store.mapped.expression.ScalarExpression str)
Method to handle the starts with operation. Will return something like
 source LIKE str%
 

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

indexOfMethod

public org.datanucleus.store.mapped.expression.NumericExpression indexOfMethod(org.datanucleus.store.mapped.expression.ScalarExpression source,
                                                                               org.datanucleus.store.mapped.expression.ScalarExpression str,
                                                                               org.datanucleus.store.mapped.expression.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 org.datanucleus.store.mapped.expression.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 org.datanucleus.store.mapped.expression.ExpressionOperatorAdapter
Returns:
the operator SQL String

concatOperator

public org.datanucleus.store.mapped.expression.ScalarExpression concatOperator(org.datanucleus.store.mapped.expression.ScalarExpression operand1,
                                                                               org.datanucleus.store.mapped.expression.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 org.datanucleus.store.mapped.expression.ExpressionOperatorAdapter
Parameters:
operand1 - the left expression
operand2 - the right expression
Returns:
The Expression for concatenation


Copyright © 2009. All Rights Reserved.