Class CloudSpannerAdapter

    • Constructor Detail

      • CloudSpannerAdapter

        public CloudSpannerAdapter​(DatabaseMetaData metadata)
    • Method Detail

      • 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
      • 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.
      • 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.
      • getSQLMethodClass

        public Class 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