Class RDBMSSchemaHandler

java.lang.Object
org.datanucleus.store.schema.AbstractStoreSchemaHandler
org.datanucleus.store.rdbms.schema.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 Details

  • Constructor Details

    • RDBMSSchemaHandler

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

    • getDatastoreAdapter

      protected DatastoreAdapter getDatastoreAdapter()
    • 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(String catalogName, String schemaName, Properties props, 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(String catalogName, String schemaName, Properties props, 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(Set<String> classNames, Properties props, 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(Set<String> classNames, Properties props, 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(Set<String> classNames, Properties props, 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(Object connection, String name, 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 String getTableType(Connection conn, Table table) throws 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:
      SQLException - if an error occurs obtaining the information
    • getRDBMSTypesInfo

      protected RDBMSTypesInfo getRDBMSTypesInfo(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(Connection conn, String schemaName, 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 String getNameWithoutQuotes(String name)
    • getRDBMSTableFKInfoForTable

      protected RDBMSTableFKInfo getRDBMSTableFKInfoForTable(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(Connection conn, String catalogName, String schemaName, 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(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(Connection conn, String catalogName, String schemaName, 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(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(Connection conn, String catalogName, String schemaName, 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(Connection conn, String catalog, 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(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(Connection conn, String catalogName, String schemaName, 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(Connection conn, Table table, 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(Object connection, String catalog, String schema, 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 String getTableKeyInRDBMSSchemaInfo(String catalog, String schema, 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 String[] splitTableIdentifierName(String separator, 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 String getIdentifierForUseWithDatabaseMetaData(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.