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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final long
Time within which column info is valid (millisecs).protected final RDBMSStoreManager
Map of schema data, keyed by its symbolic name where the data is cached.static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class org.datanucleus.store.schema.AbstractStoreSchemaHandler
autoCreateColumns, autoCreateConstraints, autoCreateDatabase, autoCreateTables, autoCreateWarnOnError, autoDeleteColumns, storeMgr, validateColumns, validateConstraints, validateTables
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Method to clear out any cached schema information.void
createDatabase
(String catalogName, String schemaName, Properties props, Object connection) void
createSchemaForClasses
(Set<String> classNames, Properties props, Object connection) void
deleteDatabase
(String catalogName, String schemaName, Properties props, Object connection) void
deleteSchemaForClasses
(Set<String> classNames, Properties props, Object connection) protected DatastoreAdapter
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.private static String
getNameWithoutQuotes
(String name) 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.protected RDBMSSchemaInfo
getRDBMSSchemaInfoForCatalogSchema
(Connection conn, String catalog, String schema) Convenience method to retrieve schema information for all tables in the specified catalog/schema.protected RDBMSSchemaInfo
getRDBMSSchemasInfo
(Connection conn, String schemaName, String catalogName) Convenience method to read the schemas information for this datastore.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.protected RDBMSTableFKInfo
getRDBMSTableFKInfoForTable
(Connection conn, Table table) Convenience method to get the ForeignKey info for the specified table from the datastore.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.protected RDBMSTableIndexInfo
getRDBMSTableIndexInfoForTable
(Connection conn, Table table) Convenience method to get the index info for the specified table from the datastore.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.protected RDBMSTableInfo
getRDBMSTableInfoForTable
(Connection conn, Table table) Convenience method to get the column info for the specified table from the datastore.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.protected RDBMSTablePKInfo
getRDBMSTablePKInfoForTable
(Connection conn, Table table) Convenience method to get the PrimaryKey info for the specified table from the datastore.protected RDBMSTypesInfo
getRDBMSTypesInfo
(Connection conn) Convenience method to read and cache the types information for this datastore.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.private String
getTableKeyInRDBMSSchemaInfo
(String catalog, String schema, String table) Convenience accessor for the key that we use to store a tables information in RDBMSSchemaInfo.getTableType
(Connection conn, Table table) Returns the type of a database table/view in the datastore.private boolean
Convenience method to return if identifiers for this datastore should be treated as case insensitive.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.private static String[]
splitTableIdentifierName
(String separator, String name) Method to split a fully-qualified database table name into its constituent parts (CATALOG.SCHEMA.TABLE).void
validateSchema
(Set<String> classNames, Properties props, Object connection) Methods inherited from class org.datanucleus.store.schema.AbstractStoreSchemaHandler
enableSchemaGeneration, getStoreManager, isAutoCreateColumns, isAutoCreateConstraints, isAutoCreateDatabase, isAutoCreateTables, isAutoCreateWarnOnError, isAutoDeleteColumns, isValidateColumns, isValidateConstraints, isValidateTables, resetSchemaGeneration
-
Field Details
-
COLUMN_INFO_EXPIRATION_MS
protected static final long COLUMN_INFO_EXPIRATION_MSTime within which column info is valid (millisecs). Set to 5 mins.- See Also:
-
rdbmsStoreMgr
-
TYPE_TYPES
- See Also:
-
TYPE_TABLES
- See Also:
-
TYPE_FKS
- See Also:
-
TYPE_PKS
- See Also:
-
TYPE_INDICES
- See Also:
-
TYPE_COLUMNS
- See Also:
-
TYPE_COLUMN
- See Also:
-
TYPE_SCHEMA
- See Also:
-
TYPE_CATALOG
- See Also:
-
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 Details
-
RDBMSSchemaHandler
public RDBMSSchemaHandler(org.datanucleus.store.StoreManager storeMgr)
-
-
Method Details
-
getDatastoreAdapter
-
clear
public void clear()Method to clear out any cached schema information.- Specified by:
clear
in interfaceorg.datanucleus.store.schema.StoreSchemaHandler
- Overrides:
clear
in classorg.datanucleus.store.schema.AbstractStoreSchemaHandler
-
createDatabase
public void createDatabase(String catalogName, String schemaName, Properties props, Object connection) - Specified by:
createDatabase
in interfaceorg.datanucleus.store.schema.StoreSchemaHandler
- Overrides:
createDatabase
in classorg.datanucleus.store.schema.AbstractStoreSchemaHandler
-
deleteDatabase
public void deleteDatabase(String catalogName, String schemaName, Properties props, Object connection) - Specified by:
deleteDatabase
in interfaceorg.datanucleus.store.schema.StoreSchemaHandler
- Overrides:
deleteDatabase
in classorg.datanucleus.store.schema.AbstractStoreSchemaHandler
-
createSchemaForClasses
- Specified by:
createSchemaForClasses
in interfaceorg.datanucleus.store.schema.StoreSchemaHandler
- Overrides:
createSchemaForClasses
in classorg.datanucleus.store.schema.AbstractStoreSchemaHandler
-
deleteSchemaForClasses
- Specified by:
deleteSchemaForClasses
in interfaceorg.datanucleus.store.schema.StoreSchemaHandler
- Overrides:
deleteSchemaForClasses
in classorg.datanucleus.store.schema.AbstractStoreSchemaHandler
-
validateSchema
- Specified by:
validateSchema
in interfaceorg.datanucleus.store.schema.StoreSchemaHandler
- Overrides:
validateSchema
in classorg.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.
- 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.
- 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
- 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 interfaceorg.datanucleus.store.schema.StoreSchemaHandler
- Overrides:
getSchemaData
in classorg.datanucleus.store.schema.AbstractStoreSchemaHandler
- Parameters:
connection
- Connection to the datastorename
- 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
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
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 datastoreschemaName
- Name of the schema to check forcatalogName
- Name of the catalog to check for- Returns:
- The RDBMSTypesInfo
-
getNameWithoutQuotes
-
getRDBMSTableFKInfoForTable
Convenience method to get the ForeignKey info for the specified table from the datastore.- Parameters:
conn
- Connection to usetable
- 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 usecatalogName
- CatalogschemaName
- SchematableName
- Name of the table- Returns:
- The foreign key info
-
getRDBMSTablePKInfoForTable
Convenience method to get the PrimaryKey info for the specified table from the datastore.- Parameters:
conn
- Connection to usetable
- 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 usecatalogName
- CatalogschemaName
- SchematableName
- Name of the table- Returns:
- The primary key info
-
getRDBMSTableIndexInfoForTable
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 usetable
- 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 usecatalogName
- CatalogschemaName
- SchematableName
- 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
- Connectioncatalog
- Catalogschema
- Schema- Returns:
- Schema information
-
getRDBMSTableInfoForTable
Convenience method to get the column info for the specified table from the datastore.- Parameters:
conn
- Connection to usetable
- 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 usecatalogName
- CatalogschemaName
- SchematableName
- 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 usetable
- The tablecolumnName
- 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 datastorecatalog
- Catalog to refreshschema
- Schema to refreshtableNames
- Collection of table names (String) to refresh
-
getTableKeyInRDBMSSchemaInfo
Convenience accessor for the key that we use to store a tables information in RDBMSSchemaInfo.- Parameters:
catalog
- The catalog nameschema
- The schema nametable
- The table name- Returns:
- Its key (fully-qualified table name)
-
splitTableIdentifierName
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 charactername
- The fully qualified name.- Returns:
- The separated parts of the name (catalog, schema, table)
-
getIdentifierForUseWithDatabaseMetaData
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.
-