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.AbstractStoreSchemaHandlerHandler 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 longCOLUMN_INFO_EXPIRATION_MSTime within which column info is valid (millisecs).protected RDBMSStoreManagerrdbmsStoreMgrprotected Map<String,org.datanucleus.store.schema.StoreSchemaData>schemaDataByNameMap of schema data, keyed by its symbolic name where the data is cached.static StringTYPE_CATALOGstatic StringTYPE_COLUMNstatic StringTYPE_COLUMNSstatic StringTYPE_FKSstatic StringTYPE_INDICESstatic StringTYPE_PKSstatic StringTYPE_SCHEMAstatic StringTYPE_TABLESstatic StringTYPE_TYPES
-
Constructor Summary
Constructors Constructor Description RDBMSSchemaHandler(org.datanucleus.store.StoreManager storeMgr)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Method to clear out any cached schema information.voidcreateDatabase(String catalogName, String schemaName, Properties props, Object connection)voidcreateSchemaForClasses(Set<String> classNames, Properties props, Object connection)voiddeleteDatabase(String catalogName, String schemaName, Properties props, Object connection)voiddeleteSchemaForClasses(Set<String> classNames, Properties props, Object connection)protected DatastoreAdaptergetDatastoreAdapter()protected RDBMSColumnInfogetRDBMSColumnInfoForColumn(Connection conn, Table table, String columnName)Convenience method to get the column info from the datastore for the column in the specified table.protected RDBMSSchemaInfogetRDBMSSchemaInfoForCatalogSchema(Connection conn, String catalog, String schema)Convenience method to retrieve schema information for all tables in the specified catalog/schema.protected RDBMSSchemaInfogetRDBMSSchemasInfo(Connection conn, String schemaName, String catalogName)Convenience method to read the schemas information for this datastore.protected RDBMSTableFKInfogetRDBMSTableFKInfoForTable(Connection conn, String catalogName, String schemaName, String tableName)Convenience method to get the ForeignKey info for the specified table from the datastore.protected RDBMSTableFKInfogetRDBMSTableFKInfoForTable(Connection conn, Table table)Convenience method to get the ForeignKey info for the specified table from the datastore.protected RDBMSTableIndexInfogetRDBMSTableIndexInfoForTable(Connection conn, String catalogName, String schemaName, String tableName)Convenience method to get the index info for the catalog+schema+tableName in the datastore.protected RDBMSTableIndexInfogetRDBMSTableIndexInfoForTable(Connection conn, Table table)Convenience method to get the index info for the specified table from the datastore.protected RDBMSTableInfogetRDBMSTableInfoForTable(Connection conn, String catalogName, String schemaName, String tableName)Convenience method to get the column info for the catalog+schema+tableName in the datastore.protected RDBMSTableInfogetRDBMSTableInfoForTable(Connection conn, Table table)Convenience method to get the column info for the specified table from the datastore.protected RDBMSTablePKInfogetRDBMSTablePKInfoForTable(Connection conn, String catalogName, String schemaName, String tableName)Convenience method to get the PrimaryKey info for the specified table from the datastore.protected RDBMSTablePKInfogetRDBMSTablePKInfoForTable(Connection conn, Table table)Convenience method to get the PrimaryKey info for the specified table from the datastore.protected RDBMSTypesInfogetRDBMSTypesInfo(Connection conn)Convenience method to read and cache the types information for this datastore.org.datanucleus.store.schema.StoreSchemaDatagetSchemaData(Object connection, String name, Object[] values)Accessor for schema data store under the provided name and defined by the specified values.StringgetTableType(Connection conn, Table table)Returns the type of a database table/view in the datastore.voidvalidateSchema(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 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
-
rdbmsStoreMgr
protected final RDBMSStoreManager rdbmsStoreMgr
-
TYPE_TYPES
public static final String TYPE_TYPES
- See Also:
- Constant Field Values
-
TYPE_TABLES
public static final String TYPE_TABLES
- See Also:
- Constant Field Values
-
TYPE_FKS
public static final String TYPE_FKS
- See Also:
- Constant Field Values
-
TYPE_PKS
public static final String TYPE_PKS
- See Also:
- Constant Field Values
-
TYPE_INDICES
public static final String TYPE_INDICES
- See Also:
- Constant Field Values
-
TYPE_COLUMNS
public static final String TYPE_COLUMNS
- See Also:
- Constant Field Values
-
TYPE_COLUMN
public static final String TYPE_COLUMN
- See Also:
- Constant Field Values
-
TYPE_SCHEMA
public static final String TYPE_SCHEMA
- See Also:
- Constant Field Values
-
TYPE_CATALOG
public static final String TYPE_CATALOG
- See Also:
- Constant Field Values
-
-
Method Detail
-
getDatastoreAdapter
protected DatastoreAdapter getDatastoreAdapter()
-
clear
public void clear()
Method to clear out any cached schema information.- Specified by:
clearin interfaceorg.datanucleus.store.schema.StoreSchemaHandler- Overrides:
clearin classorg.datanucleus.store.schema.AbstractStoreSchemaHandler
-
createDatabase
public void createDatabase(String catalogName, String schemaName, Properties props, Object connection)
- Specified by:
createDatabasein interfaceorg.datanucleus.store.schema.StoreSchemaHandler- Overrides:
createDatabasein classorg.datanucleus.store.schema.AbstractStoreSchemaHandler
-
deleteDatabase
public void deleteDatabase(String catalogName, String schemaName, Properties props, Object connection)
- Specified by:
deleteDatabasein interfaceorg.datanucleus.store.schema.StoreSchemaHandler- Overrides:
deleteDatabasein classorg.datanucleus.store.schema.AbstractStoreSchemaHandler
-
createSchemaForClasses
public void createSchemaForClasses(Set<String> classNames, Properties props, Object connection)
- Specified by:
createSchemaForClassesin interfaceorg.datanucleus.store.schema.StoreSchemaHandler- Overrides:
createSchemaForClassesin classorg.datanucleus.store.schema.AbstractStoreSchemaHandler
-
deleteSchemaForClasses
public void deleteSchemaForClasses(Set<String> classNames, Properties props, Object connection)
- Specified by:
deleteSchemaForClassesin interfaceorg.datanucleus.store.schema.StoreSchemaHandler- Overrides:
deleteSchemaForClassesin classorg.datanucleus.store.schema.AbstractStoreSchemaHandler
-
validateSchema
public void validateSchema(Set<String> classNames, Properties props, Object connection)
- Specified by:
validateSchemain interfaceorg.datanucleus.store.schema.StoreSchemaHandler- Overrides:
validateSchemain 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:
getSchemaDatain interfaceorg.datanucleus.store.schema.StoreSchemaHandler- Overrides:
getSchemaDatain 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
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 datastoreschemaName- Name of the schema to check forcatalogName- Name of the catalog to check for- Returns:
- The RDBMSTypesInfo
-
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 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
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 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
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 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
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 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
-
-