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.BaseDatastoreAdapter
BaseDatastoreAdapter.ColumnTypeMappings
-
-
Field Summary
Fields Modifier and Type Field Description static StringCLOUD_SPANNER_RESERVED_KEYWORDS-
Fields inherited from class org.datanucleus.store.rdbms.adapter.BaseDatastoreAdapter
catalogSeparator, 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.DatastoreAdapter
ACCESS_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 Summary
Constructors Constructor Description CloudSpannerAdapter(DatabaseMetaData metadata)
-
Method Summary
All 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.BaseDatastoreAdapter
addSQLTypeForJDBCType, 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_KEYWORDS
public static final String CLOUD_SPANNER_RESERVED_KEYWORDS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CloudSpannerAdapter
public CloudSpannerAdapter(DatabaseMetaData metadata)
-
-
Method Detail
-
getVendorID
public String getVendorID()
How vendor calls this driver- Specified by:
getVendorIDin interfaceDatastoreAdapter- Overrides:
getVendorIDin classBaseDatastoreAdapter- Returns:
- the vendor naming
-
getTransactionIsolationForSchemaCreation
public int getTransactionIsolationForSchemaCreation()
Spanner INFORMATION_SCHEMA works only in read-only transactions https://cloud.google.com/spanner/docs/information-schema- Specified by:
getTransactionIsolationForSchemaCreationin interfaceDatastoreAdapter- Overrides:
getTransactionIsolationForSchemaCreationin classBaseDatastoreAdapter- Returns:
- transaction isolation level for schema creation
-
initialiseTypes
public 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 interfaceDatastoreAdapter- Overrides:
initialiseTypesin classBaseDatastoreAdapter- Parameters:
handler- SchemaHandler that we initialise the types formconn- managed connection to use
-
isValidPrimaryKeyType
public 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 interfaceDatastoreAdapter- Overrides:
isValidPrimaryKeyTypein classBaseDatastoreAdapter- Parameters:
jdbcType- the jdbc type to check- Returns:
- Whether the provided type is suitable for part of the PK
-
sequenceExists
public boolean sequenceExists(Connection conn, String catalogName, String schemaName, String seqName)
Spanner does not support sequence statements.- Specified by:
sequenceExistsin interfaceDatastoreAdapter- Overrides:
sequenceExistsin classBaseDatastoreAdapter- Parameters:
conn- Connection to use for checkingcatalogName- Catalog nameschemaName- Schema nameseqName- Name of the sequence- Returns:
- false since Spanner does not support sequence statements
-
getCreateDatabaseStatement
public String getCreateDatabaseStatement(String catalogName, String schemaName)
Create database statement for Spanner JDBC.- Specified by:
getCreateDatabaseStatementin interfaceDatastoreAdapter- Overrides:
getCreateDatabaseStatementin classBaseDatastoreAdapter- Parameters:
catalogName- catalog name (does not exist in Spanner)schemaName- schema name- Returns:
- The DDL statement
-
getDropDatabaseStatement
public String getDropDatabaseStatement(String catalogName, String schemaName)
Drop database statement for Spanner JDBC- Specified by:
getDropDatabaseStatementin interfaceDatastoreAdapter- Overrides:
getDropDatabaseStatementin classBaseDatastoreAdapter- Parameters:
catalogName- catalog name (does not exist in Spanner)schemaName- schema name- Returns:
- The DDL statement
-
getDropTableStatement
public String getDropTableStatement(Table table)
Drop table statement- Specified by:
getDropTableStatementin interfaceDatastoreAdapter- Overrides:
getDropTableStatementin classBaseDatastoreAdapter- Parameters:
table- to drop.- Returns:
- The text of the SQL statement.
-
getCreateTableStatement
public 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 interfaceDatastoreAdapter- Overrides:
getCreateTableStatementin classBaseDatastoreAdapter- Parameters:
table- the table to create.columns- the columns of the table.props- properties for controlling the table creationfactory- factory for identifiers- Returns:
- The text of the SQL statement.
-
getAddPrimaryKeyStatement
public String getAddPrimaryKeyStatement(PrimaryKey pk, IdentifierFactory factory)
Cannot add or change primary key after creation- Specified by:
getAddPrimaryKeyStatementin interfaceDatastoreAdapter- Overrides:
getAddPrimaryKeyStatementin classBaseDatastoreAdapter- Parameters:
pk- an object describing the primary key.factory- identifier factory- Returns:
- The text of the SQL statement.
-
getEscapePatternExpression
public String getEscapePatternExpression()
Escape pattern is not supported in Spanner- Specified by:
getEscapePatternExpressionin interfaceDatastoreAdapter- Overrides:
getEscapePatternExpressionin classBaseDatastoreAdapter- Returns:
- the character.
-
getEscapeCharacter
public String getEscapeCharacter()
The character for escaping characters in pattern expressions.- Specified by:
getEscapeCharacterin interfaceDatastoreAdapter- Overrides:
getEscapeCharacterin classBaseDatastoreAdapter- Returns:
- the character.
-
getRangeByLimitEndOfStatementClause
public 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 interfaceDatastoreAdapter- Overrides:
getRangeByLimitEndOfStatementClausein classBaseDatastoreAdapter- Parameters:
offset- the offset to return fromcount- the number of items to returnhasOrdering- whether ordering is present- Returns:
- the SQL to append to allow for ranges using OFFSET/FETCH.
-
newSQLTypeInfo
public 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 interfaceDatastoreAdapter- Overrides:
newSQLTypeInfoin classBaseDatastoreAdapter- Parameters:
rs- ResultSet- Returns:
- The SQL type info
-
isStatementCancel
public boolean isStatementCancel(SQLException sqle)
Description copied from class:BaseDatastoreAdapterreturn whether this exception represents a cancelled statement.- Specified by:
isStatementCancelin interfaceDatastoreAdapter- Overrides:
isStatementCancelin classBaseDatastoreAdapter- Parameters:
sqle- the exception- Returns:
- whether it is a cancel
-
isStatementTimeout
public boolean isStatementTimeout(SQLException sqle)
Description copied from class:BaseDatastoreAdapterreturn whether this exception represents a timed out statement.- Specified by:
isStatementTimeoutin interfaceDatastoreAdapter- Overrides:
isStatementTimeoutin classBaseDatastoreAdapter- Parameters:
sqle- the exception- Returns:
- whether it is a timeout
-
getSQLMethodClass
public 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 interfaceDatastoreAdapter- Overrides:
getSQLMethodClassin classBaseDatastoreAdapter- Parameters:
className- Name of the class (or null if this is a STATIC method)methodName- Method nameclr- ClassLoader resolver, in case className is a subclass of a supported type- Returns:
- The SQLMethod class (or null if not defined for this datastore).
-
loadColumnMappings
protected 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 classBaseDatastoreAdapter- Parameters:
mgr- the PluginManagerclr- the ClassLoaderResolver
-
-