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 java.util.Map<java.lang.String,org.datanucleus.store.schema.StoreSchemaData>schemaDataByNameMap of schema data, keyed by its symbolic name where the data is cached.static java.lang.StringTYPE_CATALOGstatic java.lang.StringTYPE_COLUMNstatic java.lang.StringTYPE_COLUMNSstatic java.lang.StringTYPE_FKSstatic java.lang.StringTYPE_INDICESstatic java.lang.StringTYPE_PKSstatic java.lang.StringTYPE_SCHEMAstatic java.lang.StringTYPE_TABLESstatic java.lang.StringTYPE_TYPES
-
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 voidclear()Method to clear out any cached schema information.voidcreateDatabase(java.lang.String catalogName, java.lang.String schemaName, java.util.Properties props, java.lang.Object connection)voidcreateSchemaForClasses(java.util.Set<java.lang.String> classNames, java.util.Properties props, java.lang.Object connection)voiddeleteDatabase(java.lang.String catalogName, java.lang.String schemaName, java.util.Properties props, java.lang.Object connection)voiddeleteSchemaForClasses(java.util.Set<java.lang.String> classNames, java.util.Properties props, java.lang.Object connection)protected DatastoreAdaptergetDatastoreAdapter()private java.lang.StringgetIdentifierForUseWithDatabaseMetaData(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.StringgetNameWithoutQuotes(java.lang.String name)protected RDBMSColumnInfogetRDBMSColumnInfoForColumn(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 RDBMSSchemaInfogetRDBMSSchemaInfoForCatalogSchema(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 RDBMSSchemaInfogetRDBMSSchemasInfo(java.sql.Connection conn, java.lang.String schemaName, java.lang.String catalogName)Convenience method to read the schemas information for this datastore.protected RDBMSTableFKInfogetRDBMSTableFKInfoForTable(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 RDBMSTableFKInfogetRDBMSTableFKInfoForTable(java.sql.Connection conn, Table table)Convenience method to get the ForeignKey info for the specified table from the datastore.protected RDBMSTableIndexInfogetRDBMSTableIndexInfoForTable(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 RDBMSTableIndexInfogetRDBMSTableIndexInfoForTable(java.sql.Connection conn, Table table)Convenience method to get the index info for the specified table from the datastore.protected RDBMSTableInfogetRDBMSTableInfoForTable(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 RDBMSTableInfogetRDBMSTableInfoForTable(java.sql.Connection conn, Table table)Convenience method to get the column info for the specified table from the datastore.protected RDBMSTablePKInfogetRDBMSTablePKInfoForTable(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 RDBMSTablePKInfogetRDBMSTablePKInfoForTable(java.sql.Connection conn, Table table)Convenience method to get the PrimaryKey info for the specified table from the datastore.protected RDBMSTypesInfogetRDBMSTypesInfo(java.sql.Connection conn)Convenience method to read and cache the types information for this datastore.org.datanucleus.store.schema.StoreSchemaDatagetSchemaData(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.StringgetTableKeyInRDBMSSchemaInfo(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.StringgetTableType(java.sql.Connection conn, Table table)Returns the type of a database table/view in the datastore.private booleanidentifiersCaseInsensitive()Convenience method to return if identifiers for this datastore should be treated as case insensitive.private voidrefreshTableData(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).voidvalidateSchema(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
-
-
-
-
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 java.lang.String TYPE_TYPES
- See Also:
- Constant Field Values
-
TYPE_TABLES
public static final java.lang.String TYPE_TABLES
- See Also:
- Constant Field Values
-
TYPE_FKS
public static final java.lang.String TYPE_FKS
- See Also:
- Constant Field Values
-
TYPE_PKS
public static final java.lang.String TYPE_PKS
- See Also:
- Constant Field Values
-
TYPE_INDICES
public static final java.lang.String TYPE_INDICES
- See Also:
- Constant Field Values
-
TYPE_COLUMNS
public static final java.lang.String TYPE_COLUMNS
- See Also:
- Constant Field Values
-
TYPE_COLUMN
public static final java.lang.String TYPE_COLUMN
- See Also:
- Constant Field Values
-
TYPE_SCHEMA
public static final java.lang.String TYPE_SCHEMA
- See Also:
- Constant Field Values
-
TYPE_CATALOG
public static final java.lang.String TYPE_CATALOG
- 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.
-
-
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(java.lang.String catalogName, java.lang.String schemaName, java.util.Properties props, java.lang.Object connection)- Specified by:
createDatabasein interfaceorg.datanucleus.store.schema.StoreSchemaHandler- Overrides:
createDatabasein classorg.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:
deleteDatabasein interfaceorg.datanucleus.store.schema.StoreSchemaHandler- Overrides:
deleteDatabasein classorg.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:
createSchemaForClassesin interfaceorg.datanucleus.store.schema.StoreSchemaHandler- Overrides:
createSchemaForClassesin classorg.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:
deleteSchemaForClassesin interfaceorg.datanucleus.store.schema.StoreSchemaHandler- Overrides:
deleteSchemaForClassesin classorg.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:
validateSchemain interfaceorg.datanucleus.store.schema.StoreSchemaHandler- Overrides:
validateSchemain classorg.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.
- 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 java.lang.String getTableType(java.sql.Connection conn, Table table) throws java.sql.SQLExceptionReturns 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 datastoreschemaName- Name of the schema to check forcatalogName- 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 usetable- 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 usecatalogName- CatalogschemaName- SchematableName- 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 usetable- 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 usecatalogName- CatalogschemaName- SchematableName- 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 usetable- 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 usecatalogName- CatalogschemaName- SchematableName- 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- Connectioncatalog- Catalogschema- 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 usetable- 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 usecatalogName- CatalogschemaName- SchematableName- 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 usetable- The tablecolumnName- 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 datastorecatalog- Catalog to refreshschema- Schema to refreshtableNames- 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 nameschema- The schema nametable- 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 charactername- 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.
-
-