Class CloudSpannerAdapter
- java.lang.Object
- 
- org.datanucleus.store.rdbms.adapter.BaseDatastoreAdapter
- 
- org.datanucleus.store.rdbms.adapter.CloudSpannerAdapter
 
 
- 
- All Implemented Interfaces:
- DatastoreAdapter
 
 public class CloudSpannerAdapter extends BaseDatastoreAdapter CloudSpannerAdapter defines the types, features that are supported and also deviate from theBaseDatastoreAdapter.
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class org.datanucleus.store.rdbms.adapter.BaseDatastoreAdapterBaseDatastoreAdapter.ColumnTypeMappings
 
- 
 - 
Field SummaryFields Modifier and Type Field Description static StringCLOUD_SPANNER_RESERVED_KEYWORDS- 
Fields inherited from class org.datanucleus.store.rdbms.adapter.BaseDatastoreAdaptercatalogSeparator, datastoreMajorVersion, datastoreMinorVersion, datastoreProductName, datastoreProductVersion, datastoreRevisionVersion, driverMajorVersion, driverMinorVersion, driverName, driverVersion, identifierQuoteString, MAX_IDENTIFIER_LENGTH, maxColumnNameLength, maxConstraintNameLength, maxIndexNameLength, maxTableNameLength, NONRESERVED_WORDS, reservedKeywords, SQL2003_RESERVED_WORDS, SQL92_RESERVED_WORDS, SQL99_RESERVED_WORDS, supportedJdbcTypesById, supportedOptions, unsupportedJdbcTypesById
 - 
Fields inherited from interface org.datanucleus.store.rdbms.adapter.DatastoreAdapterACCESS_PARENTQUERY_IN_SUBQUERY_JOINED, ALTER_TABLE_DROP_CONSTRAINT_SYNTAX, ALTER_TABLE_DROP_FOREIGN_KEY_CONSTRAINT, ANSI_CROSSJOIN_SYNTAX, ANSI_JOIN_SYNTAX, BIT_IS_REALLY_BOOLEAN, BLOB_SET_USING_SETSTRING, BOOLEAN_COMPARISON, CATALOGS_IN_TABLE_DEFINITIONS, CHAR_COLUMNS_PADDED_WITH_SPACES, CHECK_IN_CREATE_STATEMENTS, CHECK_IN_END_CREATE_STATEMENTS, CLOB_SET_USING_SETSTRING, COLUMN_LENGTH_SEMANTICS, CREATE_INDEX_COLUMN_ORDERING, CREATE_INDEXES_BEFORE_FOREIGN_KEYS, CROSSJOIN_ASINNER11_SYNTAX, 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, ESCAPE_EXPRESSION_IN_LIKE_PREDICATE, EXISTS_SYNTAX, FK_DELETE_ACTION_CASCADE, FK_DELETE_ACTION_DEFAULT, FK_DELETE_ACTION_NULL, FK_DELETE_ACTION_RESTRICT, FK_IN_END_CREATE_STATEMENTS, FK_UPDATE_ACTION_CASCADE, FK_UPDATE_ACTION_DEFAULT, FK_UPDATE_ACTION_NULL, FK_UPDATE_ACTION_RESTRICT, GET_GENERATED_KEYS_STATEMENT, GROUP_BY_REQUIRES_ALL_SELECT_PRIMARIES, GROUPING_WITH_SELECT_FOR_UPDATE, HAVING_WITH_SELECT_FOR_UPDATE, HOLD_CURSORS_OVER_COMMIT, IDENTIFIERS_LOWERCASE, IDENTIFIERS_LOWERCASE_QUOTED, IDENTIFIERS_MIXEDCASE, IDENTIFIERS_MIXEDCASE_QUOTED, IDENTIFIERS_MIXEDCASE_QUOTED_SENSITIVE, IDENTIFIERS_MIXEDCASE_SENSITIVE, IDENTIFIERS_UPPERCASE, IDENTIFIERS_UPPERCASE_QUOTED, IDENTITY_COLUMN_TYPE_SPECIFICATION, IDENTITY_COLUMNS, IDENTITY_KEYS_NULL_SPECIFICATION, IDENTITY_PK_IN_CREATE_TABLE_COLUMN_DEF, INCLUDE_ORDERBY_COLS_IN_SELECT, LOCK_ROW_USING_OPTION_AFTER_FROM, LOCK_ROW_USING_OPTION_WITHIN_JOIN, LOCK_ROW_USING_SELECT_FOR_UPDATE, LOCK_ROW_USING_SELECT_FOR_UPDATE_NOWAIT, MULTITABLES_WITH_SELECT_FOR_UPDATE, NATIVE_ENUM_TYPE, NULL_EQUALS_EMPTY_STRING, NULLS_IN_CANDIDATE_KEYS, NULLS_KEYWORD_IN_COLUMN_OPTIONS, OPERATOR_BITWISE_AND, OPERATOR_BITWISE_OR, OPERATOR_BITWISE_XOR, ORDERBY_NULLS_DIRECTIVES, ORDERBY_NULLS_USING_CASE_NULL, ORDERBY_NULLS_USING_COLUMN_IS_NULL, ORDERBY_NULLS_USING_ISNULL, ORDERBY_USING_SELECT_COLUMN_INDEX, ORDERING_WITH_SELECT_FOR_UPDATE, PARAMETER_IN_CASE_IN_UPDATE_CLAUSE, PERSIST_OF_UNASSIGNED_CHAR, PRIMARYKEY_IN_CREATE_STATEMENTS, PROJECTION_IN_TABLE_REFERENCE_JOINS, RAW_PREFIX_LIKE_STATEMENTS, RESULTSET_TYPE_FORWARD_ONLY, RESULTSET_TYPE_SCROLL_INSENSITIVE, RESULTSET_TYPE_SCROLL_SENSITIVE, RIGHT_OUTER_JOIN, SCHEMAS_IN_TABLE_DEFINITIONS, SEQUENCES, SOME_ANY_ALL_SUBQUERY_EXPRESSIONS, STATEMENT_BATCHING, STORED_PROCEDURES, SUBQUERY_IN_HAVING, 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, UPDATE_DELETE_STATEMENT_ALLOW_TABLE_ALIAS_IN_WHERE_CLAUSE, UPDATE_STATEMENT_ALLOW_TABLE_ALIAS_IN_SET_CLAUSE, USE_UNION_ALL, VALUE_GENERATION_UUID_STRING, VIEWS
 
- 
 - 
Constructor SummaryConstructors Constructor Description CloudSpannerAdapter(DatabaseMetaData metadata)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetAddPrimaryKeyStatement(PrimaryKey pk, IdentifierFactory factory)Cannot add or change primary key after creationStringgetCreateDatabaseStatement(String catalogName, String schemaName)Create database statement for Spanner JDBC.StringgetCreateTableStatement(TableImpl table, Column[] columns, Properties props, IdentifierFactory factory)Creates a spanner table with primary key.StringgetDropDatabaseStatement(String catalogName, String schemaName)Drop database statement for Spanner JDBCStringgetDropTableStatement(Table table)Drop table statementStringgetEscapeCharacter()The character for escaping characters in pattern expressions.StringgetEscapePatternExpression()Escape pattern is not supported in SpannerStringgetRangeByLimitEndOfStatementClause(long offset, long count, boolean hasOrdering)Method to return the SQL to append to the WHERE clause of a SELECT statement to handle restriction of ranges using the LIMIT keyword.ClassgetSQLMethodClass(String className, String methodName, org.datanucleus.ClassLoaderResolver clr)Accessor for the SQLMethod class for the query invocation of specified class + method name (if available for this datastore).intgetTransactionIsolationForSchemaCreation()Spanner INFORMATION_SCHEMA works only in read-only transactions https://cloud.google.com/spanner/docs/information-schemaStringgetVendorID()How vendor calls this drivervoidinitialiseTypes(org.datanucleus.store.schema.StoreSchemaHandler handler, org.datanucleus.store.connection.ManagedConnection mconn)This function adds on any missing JDBC types when not available from driver metadata Spanner driver only provides the common types.booleanisStatementCancel(SQLException sqle)return whether this exception represents a cancelled statement.booleanisStatementTimeout(SQLException sqle)return whether this exception represents a timed out statement.booleanisValidPrimaryKeyType(org.datanucleus.metadata.JdbcType jdbcType)Spanner does not support NUMERIC (and hence DECIMAL) as a valid primary key column type.protected voidloadColumnMappings(org.datanucleus.plugin.PluginManager mgr, org.datanucleus.ClassLoaderResolver clr)Load all datastore mappings defined in the associated plugins.SQLTypeInfonewSQLTypeInfo(ResultSet rs)Create a new SQL type info from the current row of the passed ResultSet.booleansequenceExists(Connection conn, String catalogName, String schemaName, String seqName)Spanner does not support sequence statements.- 
Methods inherited from class org.datanucleus.store.rdbms.adapter.BaseDatastoreAdapteraddSQLTypeForJDBCType, deregisterColumnMappingsForJDBCType, getAdapterTime, getAddCandidateKeyStatement, getAddColumnStatement, getAddForeignKeyStatement, getCatalogName, getCatalogSeparator, getCheckConstraintForValues, getColumnMappingClass, getColumns, getContinuationString, getCreateIndexStatement, getDatastoreDateStatement, getDatastoreDriverName, getDatastoreDriverVersion, getDatastoreIdentifierMaxLength, getDatastoreProductName, getDatastoreProductVersion, getDefaultSqlTypeForJavaType, getDeleteTableStatement, getDriverMajorVersion, getDriverMinorVersion, getDropViewStatement, getExistingIndexes, getIdentifierQuoteString, getIdentityJavaTypeForType, getIdentityKeyword, getIdentityLastValueStmt, getInsertStatementForNoColumns, getJDBCTypeForName, getMappingManager, getMaxForeignKeys, getMaxIndexes, getMiliseconds, getNameForJDBCType, getNewUUIDFunction, getNumericConversionFunction, getOrderString, getPatternExpressionAnyCharacter, getPatternExpressionZeroMoreCharacters, getPreferredDefaultSQLTypeForJDBCType, getRangeByRowNumberColumn, getRangeByRowNumberColumn2, getRequiredTransactionIsolationLevel, getReservedWords, getSchemaName, getSelectForUpdateText, getSelectNewUUIDStmt, getSelectWithLockOption, getSequenceCreateStmt, getSequenceNextStmt, getSQLOperationClass, getSQLTypeInfoForJdbcType, getSupportedOptions, getSurrogateForEmptyStrings, getTime, getUnlimitedLengthPrecisionValue, getUpdateTableStatement, initialise, initialiseDatastore, isIdentityFieldDataType, isReservedKeyword, newFKInfo, newRDBMSColumnInfo, registerColumnMapping, registerColumnMapping, supportsOption, supportsQueryFetchSize, supportsTransactionIsolation, toString, validToIndexMapping, validToSelectMappingInStatement
 
- 
 
- 
- 
- 
Field Detail- 
CLOUD_SPANNER_RESERVED_KEYWORDSpublic static final String CLOUD_SPANNER_RESERVED_KEYWORDS - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
CloudSpannerAdapterpublic CloudSpannerAdapter(DatabaseMetaData metadata) 
 
- 
 - 
Method Detail- 
getVendorIDpublic String getVendorID() How vendor calls this driver- Specified by:
- getVendorIDin interface- DatastoreAdapter
- Overrides:
- getVendorIDin class- BaseDatastoreAdapter
- Returns:
- the vendor naming
 
 - 
getTransactionIsolationForSchemaCreationpublic int getTransactionIsolationForSchemaCreation() Spanner INFORMATION_SCHEMA works only in read-only transactions https://cloud.google.com/spanner/docs/information-schema- Specified by:
- getTransactionIsolationForSchemaCreationin interface- DatastoreAdapter
- Overrides:
- getTransactionIsolationForSchemaCreationin class- BaseDatastoreAdapter
- Returns:
- transaction isolation level for schema creation
 
 - 
initialiseTypespublic void initialiseTypes(org.datanucleus.store.schema.StoreSchemaHandler handler, org.datanucleus.store.connection.ManagedConnection mconn)This function adds on any missing JDBC types when not available from driver metadata Spanner driver only provides the common types. We should map the missing ones.JDBC type (Spanner type) as follows :- nvarchar (string), bigint (int64), binary (byte), double (float64), boolean (bool), date (date), timestamp (timestamp), numeric (numeric) Copied the mappings from Hibernate, https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate/blob/master/google-cloud-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/SpannerDialect.java The precision values are obtained from Spanner JDBC driver metadata https://github.com/googleapis/java-spanner-jdbc/blob/master/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java - Specified by:
- initialiseTypesin interface- DatastoreAdapter
- Overrides:
- initialiseTypesin class- BaseDatastoreAdapter
- Parameters:
- handler- SchemaHandler that we initialise the types for
- mconn- managed connection to use
 
 - 
isValidPrimaryKeyTypepublic boolean isValidPrimaryKeyType(org.datanucleus.metadata.JdbcType jdbcType) Spanner does not support NUMERIC (and hence DECIMAL) as a valid primary key column type.- Specified by:
- isValidPrimaryKeyTypein interface- DatastoreAdapter
- Overrides:
- isValidPrimaryKeyTypein class- BaseDatastoreAdapter
- Parameters:
- jdbcType- the jdbc type to check
- Returns:
- Whether the provided type is suitable for part of the PK
 
 - 
sequenceExistspublic boolean sequenceExists(Connection conn, String catalogName, String schemaName, String seqName) Spanner does not support sequence statements.- Specified by:
- sequenceExistsin interface- DatastoreAdapter
- Overrides:
- sequenceExistsin class- BaseDatastoreAdapter
- Parameters:
- conn- Connection to use for checking
- catalogName- Catalog name
- schemaName- Schema name
- seqName- Name of the sequence
- Returns:
- false since Spanner does not support sequence statements
 
 - 
getCreateDatabaseStatementpublic String getCreateDatabaseStatement(String catalogName, String schemaName) Create database statement for Spanner JDBC.- Specified by:
- getCreateDatabaseStatementin interface- DatastoreAdapter
- Overrides:
- getCreateDatabaseStatementin class- BaseDatastoreAdapter
- Parameters:
- catalogName- catalog name (does not exist in Spanner)
- schemaName- schema name
- Returns:
- The DDL statement
 
 - 
getDropDatabaseStatementpublic String getDropDatabaseStatement(String catalogName, String schemaName) Drop database statement for Spanner JDBC- Specified by:
- getDropDatabaseStatementin interface- DatastoreAdapter
- Overrides:
- getDropDatabaseStatementin class- BaseDatastoreAdapter
- Parameters:
- catalogName- catalog name (does not exist in Spanner)
- schemaName- schema name
- Returns:
- The DDL statement
 
 - 
getDropTableStatementpublic String getDropTableStatement(Table table) Drop table statement- Specified by:
- getDropTableStatementin interface- DatastoreAdapter
- Overrides:
- getDropTableStatementin class- BaseDatastoreAdapter
- Parameters:
- table- to drop.
- Returns:
- The text of the SQL statement.
 
 - 
getCreateTableStatementpublic String getCreateTableStatement(TableImpl table, Column[] columns, Properties props, IdentifierFactory factory) Creates a spanner table with primary key. Many other features like check, constraint, interleave, cascade are not supported yet. It is better to create table without using Datanucleus. Instead, use plain SQL statements.- Specified by:
- getCreateTableStatementin interface- DatastoreAdapter
- Overrides:
- getCreateTableStatementin class- BaseDatastoreAdapter
- Parameters:
- table- the table to create.
- columns- the columns of the table.
- props- properties for controlling the table creation
- factory- factory for identifiers
- Returns:
- The text of the SQL statement.
 
 - 
getAddPrimaryKeyStatementpublic String getAddPrimaryKeyStatement(PrimaryKey pk, IdentifierFactory factory) Cannot add or change primary key after creation- Specified by:
- getAddPrimaryKeyStatementin interface- DatastoreAdapter
- Overrides:
- getAddPrimaryKeyStatementin class- BaseDatastoreAdapter
- Parameters:
- pk- an object describing the primary key.
- factory- identifier factory
- Returns:
- The text of the SQL statement.
 
 - 
getEscapePatternExpressionpublic String getEscapePatternExpression() Escape pattern is not supported in Spanner- Specified by:
- getEscapePatternExpressionin interface- DatastoreAdapter
- Overrides:
- getEscapePatternExpressionin class- BaseDatastoreAdapter
- Returns:
- the character.
 
 - 
getEscapeCharacterpublic String getEscapeCharacter() The character for escaping characters in pattern expressions.- Specified by:
- getEscapeCharacterin interface- DatastoreAdapter
- Overrides:
- getEscapeCharacterin class- BaseDatastoreAdapter
- Returns:
- the character.
 
 - 
getRangeByLimitEndOfStatementClausepublic String getRangeByLimitEndOfStatementClause(long offset, long count, boolean hasOrdering) Method to return the SQL to append to the WHERE clause of a SELECT statement to handle restriction of ranges using the LIMIT keyword.- Specified by:
- getRangeByLimitEndOfStatementClausein interface- DatastoreAdapter
- Overrides:
- getRangeByLimitEndOfStatementClausein class- BaseDatastoreAdapter
- Parameters:
- offset- the offset to return from
- count- the number of items to return
- hasOrdering- whether ordering is present
- Returns:
- the SQL to append to allow for ranges using OFFSET/FETCH.
 
 - 
newSQLTypeInfopublic SQLTypeInfo newSQLTypeInfo(ResultSet rs) Description copied from interface:DatastoreAdapterCreate 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:
- newSQLTypeInfoin interface- DatastoreAdapter
- Overrides:
- newSQLTypeInfoin class- BaseDatastoreAdapter
- Parameters:
- rs- ResultSet
- Returns:
- The SQL type info
 
 - 
isStatementCancelpublic boolean isStatementCancel(SQLException sqle) Description copied from class:BaseDatastoreAdapterreturn whether this exception represents a cancelled statement.- Specified by:
- isStatementCancelin interface- DatastoreAdapter
- Overrides:
- isStatementCancelin class- BaseDatastoreAdapter
- Parameters:
- sqle- the exception
- Returns:
- whether it is a cancel
 
 - 
isStatementTimeoutpublic boolean isStatementTimeout(SQLException sqle) Description copied from class:BaseDatastoreAdapterreturn whether this exception represents a timed out statement.- Specified by:
- isStatementTimeoutin interface- DatastoreAdapter
- Overrides:
- isStatementTimeoutin class- BaseDatastoreAdapter
- Parameters:
- sqle- the exception
- Returns:
- whether it is a timeout
 
 - 
getSQLMethodClasspublic Class getSQLMethodClass(String className, String methodName, org.datanucleus.ClassLoaderResolver clr) Description copied from interface:DatastoreAdapterAccessor for the SQLMethod class for the query invocation of specified class + method name (if available for this datastore).- Specified by:
- getSQLMethodClassin interface- DatastoreAdapter
- Overrides:
- getSQLMethodClassin class- BaseDatastoreAdapter
- Parameters:
- className- Name of the class (or null if this is a STATIC method)
- methodName- Method name
- clr- ClassLoader resolver, in case className is a subclass of a supported type
- Returns:
- The SQLMethod class (or null if not defined for this datastore).
 
 - 
loadColumnMappingsprotected void loadColumnMappings(org.datanucleus.plugin.PluginManager mgr, org.datanucleus.ClassLoaderResolver clr)Load all datastore mappings defined in the associated plugins. We handle RDBMS datastore mappings so refer to rdbms-mapping-class, jdbc-type, sql-type in particular. SQL Type (Spanner Type) as follows :- nvarchar (string), bigint (int64), binary (byte), double (float64), boolean (bool), date (date), timestamp (timestamp), numeric (numeric)- Overrides:
- loadColumnMappingsin class- BaseDatastoreAdapter
- Parameters:
- mgr- the PluginManager
- clr- the ClassLoaderResolver
 
 
- 
 
-