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 the BaseDatastoreAdapter.
  • Field Details

  • Constructor Details

  • Method Details

    • getVendorID

      public String getVendorID()
      How vendor calls this driver
      Specified by:
      getVendorID in interface DatastoreAdapter
      Overrides:
      getVendorID in class BaseDatastoreAdapter
      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:
      getTransactionIsolationForSchemaCreation in interface DatastoreAdapter
      Overrides:
      getTransactionIsolationForSchemaCreation in class BaseDatastoreAdapter
      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:
      initialiseTypes in interface DatastoreAdapter
      Overrides:
      initialiseTypes in class BaseDatastoreAdapter
      Parameters:
      handler - SchemaHandler that we initialise the types for
      mconn - 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:
      isValidPrimaryKeyType in interface DatastoreAdapter
      Overrides:
      isValidPrimaryKeyType in class BaseDatastoreAdapter
      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:
      sequenceExists in interface DatastoreAdapter
      Overrides:
      sequenceExists in 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
    • getCreateDatabaseStatement

      public String getCreateDatabaseStatement(String catalogName, String schemaName)
      Create database statement for Spanner JDBC.
      Specified by:
      getCreateDatabaseStatement in interface DatastoreAdapter
      Overrides:
      getCreateDatabaseStatement in class BaseDatastoreAdapter
      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:
      getDropDatabaseStatement in interface DatastoreAdapter
      Overrides:
      getDropDatabaseStatement in class BaseDatastoreAdapter
      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:
      getDropTableStatement in interface DatastoreAdapter
      Overrides:
      getDropTableStatement in class BaseDatastoreAdapter
      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:
      getCreateTableStatement in interface DatastoreAdapter
      Overrides:
      getCreateTableStatement in 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.
    • getAddPrimaryKeyStatement

      public String getAddPrimaryKeyStatement(PrimaryKey pk, IdentifierFactory factory)
      Cannot add or change primary key after creation
      Specified by:
      getAddPrimaryKeyStatement in interface DatastoreAdapter
      Overrides:
      getAddPrimaryKeyStatement in class BaseDatastoreAdapter
      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:
      getEscapePatternExpression in interface DatastoreAdapter
      Overrides:
      getEscapePatternExpression in class BaseDatastoreAdapter
      Returns:
      the character.
    • getEscapeCharacter

      public String getEscapeCharacter()
      The character for escaping characters in pattern expressions.
      Specified by:
      getEscapeCharacter in interface DatastoreAdapter
      Overrides:
      getEscapeCharacter in class BaseDatastoreAdapter
      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:
      getRangeByLimitEndOfStatementClause in interface DatastoreAdapter
      Overrides:
      getRangeByLimitEndOfStatementClause in 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.
    • newSQLTypeInfo

      public SQLTypeInfo newSQLTypeInfo(ResultSet rs)
      Description copied from interface: DatastoreAdapter
      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 DatastoreAdapter
      Overrides:
      newSQLTypeInfo in class BaseDatastoreAdapter
      Parameters:
      rs - ResultSet
      Returns:
      The SQL type info
    • isStatementCancel

      public boolean isStatementCancel(SQLException sqle)
      Description copied from class: BaseDatastoreAdapter
      return whether this exception represents a cancelled statement.
      Specified by:
      isStatementCancel in interface DatastoreAdapter
      Overrides:
      isStatementCancel in class BaseDatastoreAdapter
      Parameters:
      sqle - the exception
      Returns:
      whether it is a cancel
    • isStatementTimeout

      public boolean isStatementTimeout(SQLException sqle)
      Description copied from class: BaseDatastoreAdapter
      return whether this exception represents a timed out statement.
      Specified by:
      isStatementTimeout in interface DatastoreAdapter
      Overrides:
      isStatementTimeout in class BaseDatastoreAdapter
      Parameters:
      sqle - the exception
      Returns:
      whether it is a timeout
    • getSQLMethodClass

      public Class<? extends SQLMethod> getSQLMethodClass(String className, String methodName, org.datanucleus.ClassLoaderResolver clr)
      Description copied from interface: DatastoreAdapter
      Accessor for the SQLMethod class for the query invocation of specified class + method name (if available for this datastore).
      Specified by:
      getSQLMethodClass in interface DatastoreAdapter
      Overrides:
      getSQLMethodClass in 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).
    • 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:
      loadColumnMappings in class BaseDatastoreAdapter
      Parameters:
      mgr - the PluginManager
      clr - the ClassLoaderResolver