Class RDBMSSchemaHandler

  • All Implemented Interfaces:
    org.datanucleus.store.schema.StoreSchemaHandler

    public class RDBMSSchemaHandler
    extends org.datanucleus.store.schema.AbstractStoreSchemaHandler
    Handler for RDBMS schema information. Provides access to the following types of schema data
    • types : type information for the datastore columns
    • tables : hierarchy of schema-tables-columns.
    • foreign-keys : FK info for a table
    • primary-keys : PK info for a table
    • indices : Indices info for a table
    • columns : Columns info for a table
    • column : Column info for a column of a table
    • schemas : Schemas info
    • catalogs : Catalogs info
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static long COLUMN_INFO_EXPIRATION_MS
      Time within which column info is valid (millisecs).
      protected RDBMSStoreManager rdbmsStoreMgr  
      protected java.util.Map<java.lang.String,​org.datanucleus.store.schema.StoreSchemaData> schemaDataByName
      Map of schema data, keyed by its symbolic name where the data is cached.
      static java.lang.String TYPE_CATALOG  
      static java.lang.String TYPE_COLUMN  
      static java.lang.String TYPE_COLUMNS  
      static java.lang.String TYPE_FKS  
      static java.lang.String TYPE_INDICES  
      static java.lang.String TYPE_PKS  
      static java.lang.String TYPE_SCHEMA  
      static java.lang.String TYPE_TABLES  
      static java.lang.String TYPE_TYPES  
      • Fields inherited from class org.datanucleus.store.schema.AbstractStoreSchemaHandler

        autoCreateColumns, autoCreateConstraints, autoCreateDatabase, autoCreateTables, autoCreateWarnOnError, autoDeleteColumns, storeMgr, validateColumns, validateConstraints, validateTables
    • Constructor Summary

      Constructors 
      Constructor Description
      RDBMSSchemaHandler​(org.datanucleus.store.StoreManager storeMgr)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Method to clear out any cached schema information.
      void createDatabase​(java.lang.String catalogName, java.lang.String schemaName, java.util.Properties props, java.lang.Object connection)  
      void createSchemaForClasses​(java.util.Set<java.lang.String> classNames, java.util.Properties props, java.lang.Object connection)  
      void deleteDatabase​(java.lang.String catalogName, java.lang.String schemaName, java.util.Properties props, java.lang.Object connection)  
      void deleteSchemaForClasses​(java.util.Set<java.lang.String> classNames, java.util.Properties props, java.lang.Object connection)  
      protected DatastoreAdapter getDatastoreAdapter()  
      private java.lang.String getIdentifierForUseWithDatabaseMetaData​(java.lang.String identifier)
      Convenience method to convert the passed identifier into the correct case for use with this datastore adapter, and removing any quote characters.
      private static java.lang.String getNameWithoutQuotes​(java.lang.String name)  
      protected RDBMSColumnInfo getRDBMSColumnInfoForColumn​(java.sql.Connection conn, Table table, java.lang.String columnName)
      Convenience method to get the column info from the datastore for the column in the specified table.
      protected RDBMSSchemaInfo getRDBMSSchemaInfoForCatalogSchema​(java.sql.Connection conn, java.lang.String catalog, java.lang.String schema)
      Convenience method to retrieve schema information for all tables in the specified catalog/schema.
      protected RDBMSSchemaInfo getRDBMSSchemasInfo​(java.sql.Connection conn, java.lang.String schemaName, java.lang.String catalogName)
      Convenience method to read the schemas information for this datastore.
      protected RDBMSTableFKInfo getRDBMSTableFKInfoForTable​(java.sql.Connection conn, java.lang.String catalogName, java.lang.String schemaName, java.lang.String tableName)
      Convenience method to get the ForeignKey info for the specified table from the datastore.
      protected RDBMSTableFKInfo getRDBMSTableFKInfoForTable​(java.sql.Connection conn, Table table)
      Convenience method to get the ForeignKey info for the specified table from the datastore.
      protected RDBMSTableIndexInfo getRDBMSTableIndexInfoForTable​(java.sql.Connection conn, java.lang.String catalogName, java.lang.String schemaName, java.lang.String tableName)
      Convenience method to get the index info for the catalog+schema+tableName in the datastore.
      protected RDBMSTableIndexInfo getRDBMSTableIndexInfoForTable​(java.sql.Connection conn, Table table)
      Convenience method to get the index info for the specified table from the datastore.
      protected RDBMSTableInfo getRDBMSTableInfoForTable​(java.sql.Connection conn, java.lang.String catalogName, java.lang.String schemaName, java.lang.String tableName)
      Convenience method to get the column info for the catalog+schema+tableName in the datastore.
      protected RDBMSTableInfo getRDBMSTableInfoForTable​(java.sql.Connection conn, Table table)
      Convenience method to get the column info for the specified table from the datastore.
      protected RDBMSTablePKInfo getRDBMSTablePKInfoForTable​(java.sql.Connection conn, java.lang.String catalogName, java.lang.String schemaName, java.lang.String tableName)
      Convenience method to get the PrimaryKey info for the specified table from the datastore.
      protected RDBMSTablePKInfo getRDBMSTablePKInfoForTable​(java.sql.Connection conn, Table table)
      Convenience method to get the PrimaryKey info for the specified table from the datastore.
      protected RDBMSTypesInfo getRDBMSTypesInfo​(java.sql.Connection conn)
      Convenience method to read and cache the types information for this datastore.
      org.datanucleus.store.schema.StoreSchemaData getSchemaData​(java.lang.Object connection, java.lang.String name, java.lang.Object[] values)
      Accessor for schema data store under the provided name and defined by the specified values.
      private java.lang.String getTableKeyInRDBMSSchemaInfo​(java.lang.String catalog, java.lang.String schema, java.lang.String table)
      Convenience accessor for the key that we use to store a tables information in RDBMSSchemaInfo.
      java.lang.String getTableType​(java.sql.Connection conn, Table table)
      Returns the type of a database table/view in the datastore.
      private boolean identifiersCaseInsensitive()
      Convenience method to return if identifiers for this datastore should be treated as case insensitive.
      private void refreshTableData​(java.lang.Object connection, java.lang.String catalog, java.lang.String schema, java.util.Collection tableNames)
      Convenience method for refreshing the table-column information for the tables specified within the defined catalog/schema.
      private static java.lang.String[] splitTableIdentifierName​(java.lang.String separator, java.lang.String name)
      Method to split a fully-qualified database table name into its constituent parts (CATALOG.SCHEMA.TABLE).
      void validateSchema​(java.util.Set<java.lang.String> classNames, java.util.Properties props, java.lang.Object connection)  
      • Methods inherited from class org.datanucleus.store.schema.AbstractStoreSchemaHandler

        enableSchemaGeneration, getStoreManager, isAutoCreateColumns, isAutoCreateConstraints, isAutoCreateDatabase, isAutoCreateTables, isAutoCreateWarnOnError, isAutoDeleteColumns, isValidateColumns, isValidateConstraints, isValidateTables, resetSchemaGeneration
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • COLUMN_INFO_EXPIRATION_MS

        protected static final long COLUMN_INFO_EXPIRATION_MS
        Time within which column info is valid (millisecs). Set to 5 mins.
        See Also:
        Constant Field Values
      • schemaDataByName

        protected java.util.Map<java.lang.String,​org.datanucleus.store.schema.StoreSchemaData> schemaDataByName
        Map of schema data, keyed by its symbolic name where the data is cached. Can be "types", "tables" etc. The "tables" cached here are "known tables" and not just all tables for the catalog/schema.
    • Constructor Detail

      • RDBMSSchemaHandler

        public RDBMSSchemaHandler​(org.datanucleus.store.StoreManager storeMgr)
    • Method Detail

      • clear

        public void clear()
        Method to clear out any cached schema information.
        Specified by:
        clear in interface org.datanucleus.store.schema.StoreSchemaHandler
        Overrides:
        clear in class org.datanucleus.store.schema.AbstractStoreSchemaHandler
      • createDatabase

        public void createDatabase​(java.lang.String catalogName,
                                   java.lang.String schemaName,
                                   java.util.Properties props,
                                   java.lang.Object connection)
        Specified by:
        createDatabase in interface org.datanucleus.store.schema.StoreSchemaHandler
        Overrides:
        createDatabase in class org.datanucleus.store.schema.AbstractStoreSchemaHandler
      • deleteDatabase

        public void deleteDatabase​(java.lang.String catalogName,
                                   java.lang.String schemaName,
                                   java.util.Properties props,
                                   java.lang.Object connection)
        Specified by:
        deleteDatabase in interface org.datanucleus.store.schema.StoreSchemaHandler
        Overrides:
        deleteDatabase in class org.datanucleus.store.schema.AbstractStoreSchemaHandler
      • createSchemaForClasses

        public void createSchemaForClasses​(java.util.Set<java.lang.String> classNames,
                                           java.util.Properties props,
                                           java.lang.Object connection)
        Specified by:
        createSchemaForClasses in interface org.datanucleus.store.schema.StoreSchemaHandler
        Overrides:
        createSchemaForClasses in class org.datanucleus.store.schema.AbstractStoreSchemaHandler
      • deleteSchemaForClasses

        public void deleteSchemaForClasses​(java.util.Set<java.lang.String> classNames,
                                           java.util.Properties props,
                                           java.lang.Object connection)
        Specified by:
        deleteSchemaForClasses in interface org.datanucleus.store.schema.StoreSchemaHandler
        Overrides:
        deleteSchemaForClasses in class org.datanucleus.store.schema.AbstractStoreSchemaHandler
      • validateSchema

        public void validateSchema​(java.util.Set<java.lang.String> classNames,
                                   java.util.Properties props,
                                   java.lang.Object connection)
        Specified by:
        validateSchema in interface org.datanucleus.store.schema.StoreSchemaHandler
        Overrides:
        validateSchema in class org.datanucleus.store.schema.AbstractStoreSchemaHandler
      • getSchemaData

        public org.datanucleus.store.schema.StoreSchemaData getSchemaData​(java.lang.Object connection,
                                                                          java.lang.String name,
                                                                          java.lang.Object[] values)
        Accessor for schema data store under the provided name and defined by the specified values. When there are no "values" the following are supported usages:-
        • types : return the JDBC/SQL types for the datastore. Returns an RDBMSTypesInfo which contains the JDBCTypeInfo, which in turn contains the SQLTypeInfo. Types information is loaded on the first call and is cached thereafter.
        • tables : return all currently loaded tables, with their columns. Returns an RDBMSSchemaInfo. When a table has been loaded for more than a period of time and is requested again we discard the cached info and go to the datastore in case it has been updated.
        When there is only one "value" the following are supported usages:-
        • foreign-keys : return all foreign keys for a Table, where the Table is passed in. Returns an RDBMSTableFKInfo
        • primary-keys : return all primary keys for a Table, where the Table is passed in. Returns an RDBMSTablePFKInfo
        • indices : return all indices for a Table, where the Table is passed in. Returns an RDBMSTableIndexInfo
        • columns : return all columns for a Table, where the Table is passed in. Returns an RDBMSTableInfo.
        • schema : return the schema info (catalog+schema) where the schema name is passed in. Returns null if not present in the database.
        When there are two "values" the following are supported usages:-
        • columns : return column info for the supplied Table and column name. Returns an RDBMSTableInfo.
        • tables : return table information for the supplied catalog and schema names. Returns an RDBMSSchemaInfo
        When there are 3 "values" the following are supported usages:-
        • foreign-keys : return all foreign keys for a Table, where the catalog+schema+table is passed in. Returns an RDBMSTableFKInfo
        • primary-keys : return all primary keys for a Table, where the catalog+schema+table is passed in. Returns an RDBMSTablePFKInfo
        • indices : return all indices for a Table, where the catalog+schema+table is passed in. Returns an RDBMSTableIndexInfo
        • columns : return all columns for a Table, where the catalog+schema+table is passed in. Returns an RDBMSTableInfo.
        Specified by:
        getSchemaData in interface org.datanucleus.store.schema.StoreSchemaHandler
        Overrides:
        getSchemaData in class org.datanucleus.store.schema.AbstractStoreSchemaHandler
        Parameters:
        connection - Connection to the datastore
        name - Name of the schema component to return.
        values - Value(s) to use as qualifier(s) for selecting the schema component
        Returns:
        Schema data definition for this name
      • getTableType

        public java.lang.String getTableType​(java.sql.Connection conn,
                                             Table table)
                                      throws java.sql.SQLException
        Returns the type of a database table/view in the datastore. Uses DatabaseMetaData.getTables() to extract this information.
        Parameters:
        conn - Connection to the database.
        table - The table/view
        Returns:
        The table type (consistent with the return from DatabaseMetaData.getTables())
        Throws:
        java.sql.SQLException - if an error occurs obtaining the information
      • getRDBMSTypesInfo

        protected RDBMSTypesInfo getRDBMSTypesInfo​(java.sql.Connection conn)
        Convenience method to read and cache the types information for this datastore.
        Parameters:
        conn - Connection to the datastore
        Returns:
        The RDBMSTypesInfo
      • getRDBMSSchemasInfo

        protected RDBMSSchemaInfo getRDBMSSchemasInfo​(java.sql.Connection conn,
                                                      java.lang.String schemaName,
                                                      java.lang.String catalogName)
        Convenience method to read the schemas information for this datastore.
        Parameters:
        conn - Connection to the datastore
        schemaName - Name of the schema to check for
        catalogName - Name of the catalog to check for
        Returns:
        The RDBMSTypesInfo
      • getNameWithoutQuotes

        private static java.lang.String getNameWithoutQuotes​(java.lang.String name)
      • getRDBMSTableFKInfoForTable

        protected RDBMSTableFKInfo getRDBMSTableFKInfoForTable​(java.sql.Connection conn,
                                                               Table table)
        Convenience method to get the ForeignKey info for the specified table from the datastore.
        Parameters:
        conn - Connection to use
        table - The table
        Returns:
        The foreign key info
      • getRDBMSTableFKInfoForTable

        protected RDBMSTableFKInfo getRDBMSTableFKInfoForTable​(java.sql.Connection conn,
                                                               java.lang.String catalogName,
                                                               java.lang.String schemaName,
                                                               java.lang.String tableName)
        Convenience method to get the ForeignKey info for the specified table from the datastore.
        Parameters:
        conn - Connection to use
        catalogName - Catalog
        schemaName - Schema
        tableName - Name of the table
        Returns:
        The foreign key info
      • getRDBMSTablePKInfoForTable

        protected RDBMSTablePKInfo getRDBMSTablePKInfoForTable​(java.sql.Connection conn,
                                                               Table table)
        Convenience method to get the PrimaryKey info for the specified table from the datastore.
        Parameters:
        conn - Connection to use
        table - The table
        Returns:
        The primary key info
      • getRDBMSTablePKInfoForTable

        protected RDBMSTablePKInfo getRDBMSTablePKInfoForTable​(java.sql.Connection conn,
                                                               java.lang.String catalogName,
                                                               java.lang.String schemaName,
                                                               java.lang.String tableName)
        Convenience method to get the PrimaryKey info for the specified table from the datastore.
        Parameters:
        conn - Connection to use
        catalogName - Catalog
        schemaName - Schema
        tableName - Name of the table
        Returns:
        The primary key info
      • getRDBMSTableIndexInfoForTable

        protected RDBMSTableIndexInfo getRDBMSTableIndexInfoForTable​(java.sql.Connection conn,
                                                                     Table table)
        Convenience method to get the index info for the specified table from the datastore. Returns ALL indexes regardless of whether unique or not.
        Parameters:
        conn - Connection to use
        table - The table
        Returns:
        The index info
      • getRDBMSTableIndexInfoForTable

        protected RDBMSTableIndexInfo getRDBMSTableIndexInfoForTable​(java.sql.Connection conn,
                                                                     java.lang.String catalogName,
                                                                     java.lang.String schemaName,
                                                                     java.lang.String tableName)
        Convenience method to get the index info for the catalog+schema+tableName in the datastore. Returns ALL indexes regardless of whether unique or not.
        Parameters:
        conn - Connection to use
        catalogName - Catalog
        schemaName - Schema
        tableName - Name of the table
        Returns:
        The index info
      • getRDBMSSchemaInfoForCatalogSchema

        protected RDBMSSchemaInfo getRDBMSSchemaInfoForCatalogSchema​(java.sql.Connection conn,
                                                                     java.lang.String catalog,
                                                                     java.lang.String schema)
        Convenience method to retrieve schema information for all tables in the specified catalog/schema.
        Parameters:
        conn - Connection
        catalog - Catalog
        schema - Schema
        Returns:
        Schema information
      • getRDBMSTableInfoForTable

        protected RDBMSTableInfo getRDBMSTableInfoForTable​(java.sql.Connection conn,
                                                           Table table)
        Convenience method to get the column info for the specified table from the datastore.
        Parameters:
        conn - Connection to use
        table - The table
        Returns:
        The table info containing the columns
      • getRDBMSTableInfoForTable

        protected RDBMSTableInfo getRDBMSTableInfoForTable​(java.sql.Connection conn,
                                                           java.lang.String catalogName,
                                                           java.lang.String schemaName,
                                                           java.lang.String tableName)
        Convenience method to get the column info for the catalog+schema+tableName in the datastore.
        Parameters:
        conn - Connection to use
        catalogName - Catalog
        schemaName - Schema
        tableName - Name of the table
        Returns:
        The table info containing the columns
      • getRDBMSColumnInfoForColumn

        protected RDBMSColumnInfo getRDBMSColumnInfoForColumn​(java.sql.Connection conn,
                                                              Table table,
                                                              java.lang.String columnName)
        Convenience method to get the column info from the datastore for the column in the specified table.
        Parameters:
        conn - Connection to use
        table - The table
        columnName - Name of the column
        Returns:
        The column info for the table+column
      • refreshTableData

        private void refreshTableData​(java.lang.Object connection,
                                      java.lang.String catalog,
                                      java.lang.String schema,
                                      java.util.Collection tableNames)
        Convenience method for refreshing the table-column information for the tables specified within the defined catalog/schema.
        Parameters:
        connection - Connection to the datastore
        catalog - Catalog to refresh
        schema - Schema to refresh
        tableNames - Collection of table names (String) to refresh
      • getTableKeyInRDBMSSchemaInfo

        private java.lang.String getTableKeyInRDBMSSchemaInfo​(java.lang.String catalog,
                                                              java.lang.String schema,
                                                              java.lang.String table)
        Convenience accessor for the key that we use to store a tables information in RDBMSSchemaInfo.
        Parameters:
        catalog - The catalog name
        schema - The schema name
        table - The table name
        Returns:
        Its key (fully-qualified table name)
      • splitTableIdentifierName

        private static java.lang.String[] splitTableIdentifierName​(java.lang.String separator,
                                                                   java.lang.String name)
        Method to split a fully-qualified database table name into its constituent parts (CATALOG.SCHEMA.TABLE). This is typically used where a user has specified a table name as fully qualified in the MetaData.
        Parameters:
        separator - Separator character
        name - The fully qualified name.
        Returns:
        The separated parts of the name (catalog, schema, table)
      • getIdentifierForUseWithDatabaseMetaData

        private java.lang.String getIdentifierForUseWithDatabaseMetaData​(java.lang.String identifier)
        Convenience method to convert the passed identifier into the correct case for use with this datastore adapter, and removing any quote characters.
        Parameters:
        identifier - The raw identifier
        Returns:
        The identifier for use
      • identifiersCaseInsensitive

        private boolean identifiersCaseInsensitive()
        Convenience method to return if identifiers for this datastore should be treated as case insensitive. For example MySQL on Linux supports case-sensitive, whereas MySQL on Windows is case insensitive.
        Returns:
        Whether case insensitive.