Class CloudSpannerAdapter

    • Field Detail

      • CLOUD_SPANNER_RESERVED_KEYWORDS

        public static final java.lang.String CLOUD_SPANNER_RESERVED_KEYWORDS
        See Also:
        Constant Field Values
    • Constructor Detail

      • CloudSpannerAdapter

        public CloudSpannerAdapter​(java.sql.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​(java.sql.Connection conn,
                                      java.lang.String catalogName,
                                      java.lang.String schemaName,
                                      java.lang.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 java.lang.String getCreateDatabaseStatement​(java.lang.String catalogName,
                                                           java.lang.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 java.lang.String getDropDatabaseStatement​(java.lang.String catalogName,
                                                         java.lang.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
      • getCreateTableStatement

        public java.lang.String getCreateTableStatement​(TableImpl table,
                                                        Column[] columns,
                                                        java.util.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 java.lang.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​(java.sql.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
      • getSQLMethodClass

        public java.lang.Class<? extends SQLMethod> getSQLMethodClass​(java.lang.String className,
                                                                      java.lang.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