public final class DatabaseManager
extends java.lang.Object
Persistence
class, but since it
contains generally useful methods, it has been made public.
During server bootstrap, this class reads configuration data from the directory service. This information includes the names of databases which must be configured and be permanently accessible, as well as those which are considered "transient". A transient database is one which can be connected to and disconnected from (in the Progress sense) on demand, from application code.
When a database is initialized for use via Hibernate, whether permanent
or transient, additional configuration data, including Hibernate's
configuration properties, is read from the directory service. This is
assembled into a Properties
object and passed to Hibernate's
configuration subsystem.
Each database is represented by a Hibernate SessionFactory
object, which is the object which the Persistence
class uses
to create database Session
s lazily. In addition to the
configuration options read from the directory, each session factory
requires the list of ORM mapping classes which will be used to represent
database tables in any session established with that database. These are
retrieved from a DMOIndex
, one of which is created for each
physical database to which we must connect.
SessionFactory
objects for transient databases are created on
demand, which can be an expensive process. A session factory for a
transient database is required when at least one client session connects
dynamically to that database. A reference count is maintained across
client sessions for each transient database, such that a session factory
need not be created for one client context, if another is already using it.
Session factory objects for transient databases thus are not discarded
while any context is connected to the associated database.
This class can both register remote databases for local use, as well as
serve requests from remote servers to provide access to local databases.
Whether a database is remote or local is transparent to users of this
class. Both are registered using the registerDatabase(Database)
method.
Implementation Note: several methods of this class synchronizes on two objects:
configLock
sessionFactories
configLock
is the less granular of these. It is important
that any code path which requires access to both locks simultaneously
always acquire configLock
first, then
sessionFactories
, to avoid deadlock.
Modifier and Type | Class and Description |
---|---|
private static class |
DatabaseManager.Context
A class containing context-specific data.
|
static interface |
DatabaseManager.DatabaseConfigFetcher
Interface for a remote object whose purpose is to fetch a local
DatabaseConfig
object and deliver it to the remote caller. |
static class |
DatabaseManager.DatabaseConfigFetcherImpl
Concrete implementation of the
DatabaseConfigFetcher interface. |
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.Boolean>> |
compCharColInfo
Map of computed column base property names to ignore-case booleans
|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.String>> |
composites
Map of DMO classes to maps of property names to composite names
|
private static java.util.Map<java.lang.String,org.hibernate.cfg.Configuration> |
configBySchema
Map of Hibernate configuration, keyed by schema.
|
private static java.lang.Object |
configLock
Object upon which configuration routines synchronize
|
private static ContextLocal<DatabaseManager.Context> |
context
Context local data
|
private static java.util.Map<Database,DatabaseConfig> |
dbConfigs
Map of local DatabaseConfig objects, keyed by database info objects
|
private static java.util.Map<Database,org.hibernate.dialect.Dialect> |
dialects
Map of databases to Hibernate
Dialect s |
private static java.util.Map<java.lang.String,java.util.Set<org.hibernate.internal.util.xml.XmlDocument>> |
dirtyHibernateMappings
Map of dirty Hibernate mappings, keyed by database schema
|
private static java.util.Map<Database,java.util.Deque<java.sql.Connection>> |
earlyConnections
Deques of JDBC connections in use during initialization, by database
|
private static java.lang.Object |
earlyCpLock
Lock object to synchronize access to early connection pool
|
private static java.util.Map<Database,org.hibernate.cfg.Configuration> |
hibernateConfigs
Map of Hibernate configuration, keyed by database.
|
private static java.util.Map<java.lang.String,java.util.Set<org.hibernate.internal.util.xml.XmlDocument>> |
hibernateMappings
Map of Hibernate mappings, keyed by database schema.
|
private static java.util.Map<Database,LockTableUpdater> |
lockTableUpdaters
Map of LockTableUpdater instances, keyed by database
|
private static java.util.logging.Logger |
log
Logger
|
private static java.util.Set<Database> |
managed
Set of all databases managed by the local P2J server instance
|
static int |
MIXED_MODE_SSL_PORT
Port for mixed mode, remote, SSL connections to embedded databases
|
private static java.util.Map<java.lang.Class<?>,java.util.ArrayList<java.lang.String>> |
notNullProperties
Map of DMO classes to lists of non-nullable properties in those DMOs
|
private static java.util.Set<Database> |
permanentConnections
Set of databases auto-connected at bootstrap
|
static java.lang.String |
PRIMARY_KEY
Reserved name of primary key identifier column/property
|
private static java.util.Set<java.lang.String> |
readOnly
Set of DMO entity names which correspond to read-only tables
|
private static java.util.Map<Database,java.lang.String> |
schemaByDatabase
Map of schema names, keyed by database
|
private static java.util.Map<java.lang.Class<?>,java.lang.String> |
schemaByDMOClass
Map of schema names, keyed by DMO implementation class
|
private static java.util.Map<java.lang.Class<?>,java.lang.String> |
schemaByDMOIface
Map of schema names, keyed by DMO interface
|
private static java.util.Map<Database,java.util.Map<java.lang.String,java.util.List<org.hibernate.mapping.Table>>> |
secondaryTables
Map of databases to maps of primary table names to lists of Hibernate
Table
objects (whew!) |
private static java.util.Map<Database,org.hibernate.SessionFactory> |
sessionFactories
Map of Hibernate session factories, keyed by database.
|
private static java.util.Map<Database,java.util.Map<java.lang.String,java.lang.String>> |
tablesToEntities
Map of databases to maps of table names to entity names for these databases
|
static Database |
TEMP_TABLE_DB
Temp table database information object
|
static java.lang.String |
TEMP_TABLE_SCHEMA
Reserved name of temp table schema
|
private static java.util.Map<Database,java.lang.Integer> |
transientDatabases
Map of transient databases to reference counts of registrations
|
Modifier | Constructor and Description |
---|---|
private |
DatabaseManager()
This class cannot be instantiated; all methods are static.
|
Modifier and Type | Method and Description |
---|---|
static void |
checkInConnection(java.sql.Connection connection,
Database database)
Check in a JDBC connection previously obtained with
checkOutConnection(Database) . |
static java.sql.Connection |
checkOutConnection(Database database)
Get a JDBC connection, either from the appropriate
Persistence
instance, or if during persistence initialization, directly from the
JDBC driver. |
private static void |
checkRemoteConnectURL(Database database,
java.util.Properties props)
Validate and possibly modify the remote connection URL.
|
private static java.util.Properties |
createDefaultTempProperties()
This method returns the Hibernate properties which should be used when connecting to the
primary temp-table database.
|
private static java.util.Properties |
createEmbeddedProperties(Database database)
This method returns the Hibernate properties which should be used when connecting to a
secondary (e.g., dirty or metadata) database associated with a normal database.
|
(package private) static boolean |
deregisterDatabase(Database database)
Deregister the specified, transient database, if and only if all other
contexts using the database have deregistered it.
|
(package private) static void |
deregisterDynamicTable(java.lang.Class<?> dmoIface,
org.hibernate.mapping.PersistentClass persistentClass)
Deregister dynamic table represented by the given DMO interface and persistent class.
|
static RecordLockInfo[] |
getAllRecordLockInfo()
Gather snapshots of all record locks for all, non-temporary, permanently
connected databases which are authoritatively managed by this P2J server
instance.
|
(package private) static org.hibernate.mapping.Table |
getBackingTable(Database database,
java.lang.Class<?> dmoClass)
Look up the Hibernate configuration helper object for a table.
|
static java.lang.String |
getBackingTableName(java.lang.Class<?> dmoClass,
org.xml.sax.EntityResolver resolver)
Retrieve the database table name for a given DMO implementation class,
by reading it directly from the .hbm.xml document.
|
static java.lang.String |
getBackingTableName(Database database,
java.lang.Class<?> dmoClass)
Retrieve the database table name for a given database and DMO
implementation class.
|
(package private) static org.hibernate.mapping.PersistentClass |
getClassMapping(Database database,
java.lang.Class<?> dmoClass)
Retrieve the Hibernate configuration object associated with the given
database and DMO implementation class.
|
static java.util.Map<java.lang.String,java.lang.String> |
getColumnToPropertyMap(Database database,
java.lang.Class<?> dmoClass,
java.util.Set<java.lang.String> columnNames,
boolean includePK)
Get a mapping of column names to property names for the given DMO in the
given database.
|
(package private) static java.lang.String |
getComposite(java.lang.Class<?> dmoClass,
java.lang.String property)
If the given combination of DMO class and property indicate a property
of a composite element of a collection associated with the DMO class,
return the name of the collection as defined in the Hibernate mapping
for the DMO class.
|
static org.hibernate.cfg.Configuration |
getConfigBySchema(java.lang.String schema)
Get Hibernate
Configuration object for the given schema (however note that
from Hibernate 4 we do not share the same Configuration for multiple
databases). |
static java.util.List<java.lang.String> |
getDatabaseTables(Database database)
Get the tables of the given database.
|
static org.hibernate.dialect.Dialect |
getDialect(Database database)
Report the database dialect in use for the given database.
|
private static java.util.Set<org.hibernate.internal.util.xml.XmlDocument> |
getDirtyHibernateMappings(java.lang.String schema)
Retrieve the dirty Hibernate configuration for the given database schema.
|
(package private) static java.sql.Connection |
getEarlyConnection(Database database)
Obtain a JDBC connection for the given database during persistence initialization.
|
static java.lang.String |
getEntityNameByTableName(Database database,
java.lang.String table)
Get the entity name which corresponds the given table of the given
database.
|
static org.hibernate.cfg.Configuration |
getHibernateConfiguration(Database database)
Get Hibernate
Configuration object for the given database. |
private static java.util.Set<org.hibernate.internal.util.xml.XmlDocument> |
getHibernateMappings(java.lang.String schema)
Retrieve the Hibernate configuration for the given database schema.
|
(package private) static java.lang.Boolean |
getIgnoreCase(java.lang.Class<?> dmoClass,
java.lang.String property)
For a given DMO property which may represent an indexed text column, indicate whether that
column is set to ignore case.
|
private static DatabaseConfig |
getLocalConfiguration(Database database)
Get all data necessary to configure a database managed by the current
P2J server instance.
|
(package private) static LockTableUpdater |
getLockTableUpdater(Database database)
Return the lock table updater associated with the given database, if any.
|
static java.util.List<Database> |
getManagedDatabases()
Get a list of all configured databases managed by this P2J server
instance.
|
private static DatabaseConfig |
getRemoteConfiguration(Database database)
Get all data necessary to configure a database managed by a remote P2J server instance.
|
static java.lang.String |
getSchema(Database database)
Lookup the schema name associated with the given physical database
name.
|
static java.lang.String |
getSchemaByClass(java.lang.Class<?> dmoClass)
Lookup the schema name associated with the given DMO implementation
class.
|
static java.lang.String |
getSchemaByInterface(java.lang.Class<?> dmoIface)
Lookup the schema name associated with the given DMO interface.
|
(package private) static java.util.List<org.hibernate.mapping.Table> |
getSecondaryTables(Database database,
java.lang.String primaryTable)
Get a list of secondary (associated) temporary tables for the given
primary, temporary table.
|
static org.hibernate.SessionFactory |
getSessionFactory(Database database)
Retrieve the session factory for the given database.
|
(package private) static void |
initialize()
Initialize the persistence framework.
|
(package private) static boolean |
isAuthoritative(Database database)
Indicate whether this P2J server instance is authoritative for the given
database.
|
(package private) static boolean |
isInitializing()
Indicate whether the database manager is currently initializing.
|
(package private) static boolean |
isPermamentDB(Database database)
Check if the specified database is a permanent database.
|
static boolean |
isReadOnly(java.lang.String entity)
Check if the DMO class corresponds to the read-only table
|
(package private) static boolean |
isTempTable(java.lang.Class<?> dmoClass)
Helper method to determine whether the specified class or interface
represents the DMO front-end for temp table records.
|
private static java.util.Properties |
loadConfigProperties(Database database)
Load configuration properties from the P2J directory service and
return them as a
Properties object. |
private static void |
mapCompositeProperties(org.hibernate.mapping.Collection collection,
org.hibernate.mapping.Component component,
boolean dynamic)
Organize the information in a
composite-element collection
mapping for fast access later by the HQLPreprocessor . |
private static void |
mapCompositeProperties(org.hibernate.cfg.Configuration config)
Examine all collection mappings in a Hibernate configuration and
organize those which represent collections of
composite-element s for fast access later by the HQLPreprocessor when rewriting where clauses. |
private static void |
mapComputedCharacterColumns(java.lang.String schema,
Database database,
org.hibernate.cfg.Configuration config)
For each character column which must be represented within a database index as a computed
column (certain dialects only), map the name of the associated DMO property to a
Boolean indicating whether that computed column is designed to ignore case in
its ordering. |
private static void |
mapComputedCharacterColumnsImpl(java.lang.String schema,
Database database,
org.hibernate.mapping.PersistentClass persistentClass,
java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.Boolean>> cccInfo)
For each character column which must be represented within a database index as a computed
column (certain dialects only), map the name of the associated DMO property to a
Boolean indicating whether that computed column is designed to ignore case in
its ordering. |
private static void |
mapSecondaryTables(Database database,
org.hibernate.cfg.Configuration config)
Examine all collection mappings in a Hibernate configuration and group
them into lists of secondary temp tables, mapped by the names of primary
temp tables.
|
static java.lang.Class<?> |
normalizeDMOClass(java.lang.Class<?> dmoClass)
Given a DMO implementation class, return the associated class which is
registered with the
DatabaseManager . |
(package private) static java.util.Iterator<java.lang.String> |
notNullProperties(Database database,
java.lang.Class<?> dmoClass)
Get an iterator on the names of all properties for a given DMO class,
for which the mapped column is not nullable.
|
static java.util.Iterator<Database> |
permanentConnections()
Get an iterator on all configured, permanent databases.
|
private static DatabaseConfig |
readDatabaseConfig(Database database)
Read from the directory all data necessary to configure a database
managed by the current P2J server instance.
|
private static void |
readHibernateProperties(DirectoryService ds,
java.lang.String id,
java.util.Properties props)
Read hibernate configuration properties from the directory and populate
a properties file which will be passed to Hibernate's configuration API.
|
(package private) static boolean |
registerDatabase(Database database)
Register an individual database with the persistence framework.
|
private static boolean |
registerDatabase(DatabaseConfig dbConfig,
Database database,
boolean bootstrap,
boolean updateRefCount)
Register an individual database with the persistence framework.
|
(package private) static boolean |
registerDirtyDatabase(Database database)
Given a normal database, this method will register its associated dirty database with the
persistence framework.
|
private static boolean |
registerDirtyDatabase(DatabaseConfig dbConfig,
Database database,
Database.Type type,
boolean bootstrap)
Given a normal database, this method will register its associated
dirty database; the created dirty database will have the same name as
the original database.
|
(package private) static void |
registerDynamicTable(java.lang.Class<?> dmoIface,
org.hibernate.mapping.PersistentClass persistentClass)
Register dynamic table represented by the given DMO interface and persistent class.
|
private static int |
updateTransientRefCount(Database database,
boolean increment)
Update the reference count of registrations of the specified database
across all contexts.
|
private static int |
updateTransientRefCountWorker(Database database,
int delta)
Update the reference count of registrations of the specified database.
|
public static final java.lang.String TEMP_TABLE_SCHEMA
public static final Database TEMP_TABLE_DB
public static final java.lang.String PRIMARY_KEY
public static final int MIXED_MODE_SSL_PORT
private static final java.util.logging.Logger log
private static final java.util.Map<Database,DatabaseConfig> dbConfigs
private static final java.util.Map<Database,org.hibernate.SessionFactory> sessionFactories
private static final java.util.Map<Database,org.hibernate.cfg.Configuration> hibernateConfigs
private static final java.util.Map<java.lang.String,org.hibernate.cfg.Configuration> configBySchema
private static final java.util.Map<java.lang.String,java.util.Set<org.hibernate.internal.util.xml.XmlDocument>> hibernateMappings
private static final java.util.Map<java.lang.String,java.util.Set<org.hibernate.internal.util.xml.XmlDocument>> dirtyHibernateMappings
private static final java.util.Map<Database,java.lang.String> schemaByDatabase
private static final java.util.Map<java.lang.Class<?>,java.lang.String> schemaByDMOClass
private static final java.util.Map<java.lang.Class<?>,java.lang.String> schemaByDMOIface
private static final java.util.Set<Database> permanentConnections
private static final java.util.Map<Database,org.hibernate.dialect.Dialect> dialects
Dialect
sprivate static final java.util.Map<Database,java.lang.Integer> transientDatabases
private static final java.util.Set<Database> managed
private static final java.util.Map<java.lang.Class<?>,java.util.ArrayList<java.lang.String>> notNullProperties
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.String>> composites
private static final java.util.Set<java.lang.String> readOnly
private static final java.util.Map<Database,java.util.Map<java.lang.String,java.util.List<org.hibernate.mapping.Table>>> secondaryTables
Table
objects (whew!)private static final ContextLocal<DatabaseManager.Context> context
private static final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.Boolean>> compCharColInfo
private static final java.lang.Object configLock
private static final java.util.Map<Database,java.util.Map<java.lang.String,java.lang.String>> tablesToEntities
private static java.util.Map<Database,LockTableUpdater> lockTableUpdaters
private static java.util.Map<Database,java.util.Deque<java.sql.Connection>> earlyConnections
private static final java.lang.Object earlyCpLock
private DatabaseManager()
public static org.hibernate.SessionFactory getSessionFactory(Database database)
database
- Database information object.null
if there is no factory
registered for database
.public static org.hibernate.cfg.Configuration getHibernateConfiguration(Database database)
Configuration
object for the given database.database
- Database which Configuration
we want to get.Configuration
object.public static org.hibernate.cfg.Configuration getConfigBySchema(java.lang.String schema)
Configuration
object for the given schema (however note that
from Hibernate 4 we do not share the same Configuration
for multiple
databases).schema
- Schema which Configuration
we want to get.Configuration
object.public static org.hibernate.dialect.Dialect getDialect(Database database)
database
- Database information object.database
.public static java.lang.String getSchema(Database database)
database
- Database information object. May be null
if
dmoClass
represents a temporary table.public static java.lang.String getSchemaByClass(java.lang.Class<?> dmoClass)
dmoClass
- A DMO implementation class; if a temporary DMO, the temp
table schema name is returned.public static java.lang.String getSchemaByInterface(java.lang.Class<?> dmoIface)
dmoIface
- A DMO interface; if a temporary DMO, the temp table schema
name is returned.public static java.lang.String getBackingTableName(java.lang.Class<?> dmoClass, org.xml.sax.EntityResolver resolver) throws PersistenceException
dmoClass
- DMO implementation class to which the table is mapped via ORM,
or null
if couldn't be determined.PersistenceException
public static java.lang.String getBackingTableName(Database database, java.lang.Class<?> dmoClass)
database
- Database in which the table resides.dmoClass
- DMO implementation class to which the table is mapped via ORM.null
if no match is found.public static java.util.Iterator<Database> permanentConnections()
Although this method returns a technically thread-unsafe iterator, the set of permanent databases over which it iterates is established during server bootstrap and is not changed thereafter. Thus, so long as this method is invoked after bootstrap, the iterator effectively will be thread-safe.
public static java.util.List<Database> getManagedDatabases()
public static RecordLockInfo[] getAllRecordLockInfo()
public static java.lang.String getEntityNameByTableName(Database database, java.lang.String table)
database
- Database which contains the target table.table
- Target tablepublic static java.util.List<java.lang.String> getDatabaseTables(Database database)
database
- Target database.public static java.lang.Class<?> normalizeDMOClass(java.lang.Class<?> dmoClass)
DatabaseManager
. In most cases, the
class returned will be the same as the dmoClass
argument.
However, there is a possibility that this argument is actually a
Hibernate CBLIB proxy class injected as a proxy subclass of the
"primary", registered class. This could have happened if the caller
tried to divine dmoClass by invoking getClass() on a DMO instance
created by Hibernate. In this case, we need to walk up the superclass
chain until we find the primary class.dmoClass
- DMO implementation class to be normalized.dmoClass
. This may be dmoClass
or its superclass.java.lang.IllegalArgumentException
- if no class associated with dmoClass
is
registered.public static java.util.Map<java.lang.String,java.lang.String> getColumnToPropertyMap(Database database, java.lang.Class<?> dmoClass, java.util.Set<java.lang.String> columnNames, boolean includePK)
database
- Target database.dmoClass
- Target DMO implementation class.columnNames
- Set of column names to be mapped to properties. If
null
, all of the table's columns will be mapped to
DMO property names.includePK
- true
to include the reserved mapping of primary
"id" to reserved property name "id"; false
to
omit this mapping.public static java.sql.Connection checkOutConnection(Database database) throws PersistenceException
Persistence
instance, or if during persistence initialization, directly from the
JDBC driver.
Note: since early connections are recycled using a crude connection
pool, the caller must not call close()
on the returned
connection; rather, checkInConnection(Connection, Database)
must be used. All open connections are closed when the persistence
runtime is finished initializing.
database
- Database to which a connection is needed.PersistenceException
- if there is any database error.public static void checkInConnection(java.sql.Connection connection, Database database) throws PersistenceException
checkOutConnection(Database)
. This will close the connection if it is
not otherwise in use.connection
- JDBC connection which is no longer needed by the caller.database
- Database associated with the returned connection.PersistenceException
- if there is an error closing the session associated with the
connection.public static boolean isReadOnly(java.lang.String entity)
entity
- DMO entity name.true
if the DMO entity corresponds to a read-only table.static java.lang.String getComposite(java.lang.Class<?> dmoClass, java.lang.String property)
dmoClass
- A DMO implementation class.property
- A property of dmoClass
or of the component stored
in the associated collection.static boolean isTempTable(java.lang.Class<?> dmoClass)
dmoClass
- A DMO interface or implementation class.true
if dmoClass
is assignable from
the Temporary
marker interface; else
false
.static boolean isPermamentDB(Database database)
true
only if
the database is neither a dirty database nor the temporary database.database
- The database to be checked.true
if this database object is configured for a
permanent DB.static java.util.Iterator<java.lang.String> notNullProperties(Database database, java.lang.Class<?> dmoClass)
database
- Database in which the table mapped to the DMO represented by
dmoClass
resides.dmoClass
- DMO implementation class.static void initialize() throws PersistenceException
Remote database service provider exports are registered at this time as well. This includes services to fetch database configurations for remote requesters, record locking services, and the tracking of dirty records within uncommitted transactions.
Databases and the DMO classes associated with them are determined by reading the DMO index configuration file. The location of this file is read from the P2J directory. Hibernate configuration properties for each session factory are read from the directory as well.
The logic flow is:
Configuration
;
SessionFactory
from the
configuration and store it in a map, keyed by the database
name (not the schema name, which may be different)
java.lang.IllegalStateException
- if invoked more than once.PersistenceException
- if any error is encountered initializing the persistence
framework.static boolean isInitializing()
true
if database manager is initializing, else
false
if initialization is complete.static java.sql.Connection getEarlyConnection(Database database) throws PersistenceException
database
- Database to which a connection is needed.PersistenceException
- if there is any database error.java.lang.IllegalStateException
- if this method is invoked after the persistence layer or specific database is no
longer initializing.static boolean registerDatabase(Database database) throws PersistenceException
Configuration
;
SessionFactory
from the
configuration and store it in a map, keyed by the database
name (not the schema name, which may be different)
database
- Database to be configured.true
if the database was newly registered;
false
if the database was already registered,
and only the reference count was incremented, or if this
registration attempt was redundant in the local context.PersistenceException
- if database
is not recognized, based upon
configuration information in the directory.static boolean registerDirtyDatabase(Database database) throws PersistenceException
Configuration
;
SessionFactory
from the
configuration and store it in a map, keyed by the database
name (not the schema name, which may be different)
database
- Database to be configured.true
if the database was newly registered;
false
if the database was already registered,
and only the reference count was incremented, or if this
registration attempt was redundant in the local context.PersistenceException
- if database
is not recognized, based upon
configuration information in the directory.static void registerDynamicTable(java.lang.Class<?> dmoIface, org.hibernate.mapping.PersistentClass persistentClass) throws PersistenceException
dmoIface
- DMO interface class.persistentClass
- Persistent class.PersistenceException
static void deregisterDynamicTable(java.lang.Class<?> dmoIface, org.hibernate.mapping.PersistentClass persistentClass)
dmoIface
- DMO interface class.persistentClass
- Persistent class.static LockTableUpdater getLockTableUpdater(Database database)
database
- A primary database for which the lock table updater is needed.null
if lock metadata is not used by the
current application.java.lang.IllegalArgumentException
- if lock metadata is used by the current application, but no lock table updater is
found for the given database.private static java.util.Set<org.hibernate.internal.util.xml.XmlDocument> getHibernateMappings(java.lang.String schema)
schema
- Database schema name.null
if there is none
registered for database
.private static java.util.Set<org.hibernate.internal.util.xml.XmlDocument> getDirtyHibernateMappings(java.lang.String schema)
schema
- Database schema name.null
if there is none
registered for database
.private static DatabaseConfig getLocalConfiguration(Database database) throws PersistenceException
database
- A locally managed database.PersistenceException
- if an error occurs accessing configuration data.private static DatabaseConfig getRemoteConfiguration(Database database) throws PersistenceException
database
- A remotely managed database.PersistenceException
- if the specified database is not managed by the remote server.private static void checkRemoteConnectURL(Database database, java.util.Properties props) throws PersistenceException
props
object and confirming it begins with the necessary
jdbc:
prefix.
It is modified in the event it specifies a localhost/loopback address.
Such an address specification is relative to the remote server and is
most likely invalid for the requesting server. The host in such a case
is replaced the host name specified in database
, and the
modified URL is set back into props
under the appropriate
key.
NOTE: this approach assumes the local and remote servers share a DNS and will resolve the given connection URL to the same physical address.
database
- Object containing address information for the remotely managed
database.props
- Hibernate configuration properties as reported by the remote
server.PersistenceException
- if the connection URL specified in props
is
missing or invalid.private static DatabaseConfig readDatabaseConfig(Database database) throws PersistenceException
database
- A locally managed database.PersistenceException
- if an error occurs accessing configuration data.static boolean deregisterDatabase(Database database)
database
, without
first building a new session factory (an expensive process).database
- Database to be deregistered.true
if database
was deregistered;
else false
. Note that the latter does not
represent an error condition, but rather indicates that the
database could not be deregistered because other contexts
still referenced it, or because it is a permanent database.java.lang.IllegalArgumentException
- if database
is not currently registered.static boolean isAuthoritative(Database database)
database
- Database information object.true
if this server instance is authoritative for
the specified database.static org.hibernate.mapping.Table getBackingTable(Database database, java.lang.Class<?> dmoClass)
database
- Database in which table resides.dmoClass
- DMO implementation class to which the table is mapped via ORM.null
if it cannot be
found.static java.util.List<org.hibernate.mapping.Table> getSecondaryTables(Database database, java.lang.String primaryTable)
database
- Database containing primary table.primaryTable
- Name of the primary temporary table.null
if none exist.static org.hibernate.mapping.PersistentClass getClassMapping(Database database, java.lang.Class<?> dmoClass)
database
- Database information object.dmoClass
- DMO implementation class which the object represents in the
ORM configuration.null
if
no match was found.static java.lang.Boolean getIgnoreCase(java.lang.Class<?> dmoClass, java.lang.String property)
dmoClass
- DMO implementation class.property
- DMO property name.true
to ignore case, false
to preserve case sensitivity,
null
if the property does not represent an indexed text column.private static boolean registerDirtyDatabase(DatabaseConfig dbConfig, Database database, Database.Type type, boolean bootstrap) throws PersistenceException
The dirty database is hard-coded to be an in-memory H2 database. See
createEmbeddedProperties(Database)
method for the Hibernate settings
used.
dbConfig
- Configuration properties for the given database.database
- Database to be configured.bootstrap
- true
if this method is invoked during bootstrap
initialization at server start-up; false
if
invoked otherwise. If false
, it is assumed that
database
represents a transient database.true
if the dirty database was newly registered;
false
if the database was already registered, and
only the reference count was incremented (transient only), or
if this registration attempt was redundant in the local
context.PersistenceException
- If there is an error configuring the Hibernate framework.java.lang.IllegalStateException
- if database
is permanent and already has been
registered.java.lang.IllegalArgumentException
- if database
is not recognized, based upon
configuration information in the directory.private static boolean registerDatabase(DatabaseConfig dbConfig, Database database, boolean bootstrap, boolean updateRefCount) throws PersistenceException
Configuration
;
SessionFactory
from the
configuration and store it in a map, keyed by the database
name (not the schema name, which may be different)
This method may be invoked during bootstrap initialization, to register a permanent database, or after initialization, to dynamically register a transient database.
dbConfig
- Configuration properties for the given database.database
- Database to be configured.bootstrap
- true
if this method is invoked during bootstrap
initialization at server start-up; false
if
invoked otherwise. If false
, it is assumed that
database
represents a transient database.updateRefCount
- true
if the transient reference count should be updated;
else false
.true
if the (permanent or transient) database was
newly registered;
false
if the database was already registered, and
only the reference count was incremented (transient only), or
if this registration attempt was redundant in the local
context.PersistenceException
- If there is an error configuring the Hibernate framework.java.lang.IllegalStateException
- if database
is permanent and already has been
registered.private static void mapComputedCharacterColumns(java.lang.String schema, Database database, org.hibernate.cfg.Configuration config) throws PersistenceException
Boolean
indicating whether that computed column is designed to ignore case in
its ordering. This allows runtime code (such as SortCriterion
and the HQLPreprocessor
to quickly find this information later.
A multi-level mapping is created: the first level maps each DMO implementation class to another map of property names to ignore-case values.
schema
- Database schema.database
- Database information object.config
- Hibernate ORM configuration.PersistenceException
- if there is an error querying index information from the JDBC driver.private static void mapComputedCharacterColumnsImpl(java.lang.String schema, Database database, org.hibernate.mapping.PersistentClass persistentClass, java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.lang.Boolean>> cccInfo) throws PersistenceException
Boolean
indicating whether that computed column is designed to ignore case in
its ordering. This allows runtime code (such as SortCriterion
and the HQLPreprocessor
to quickly find this information later.
A multi-level mapping is created: the first level maps each DMO implementation class to another map of property names to ignore-case values.
schema
- Database schema.database
- Database information object.persistentClass
- Hibernate persistent class which contains the ORM mapping for a particular DMO.cccInfo
- Computed character column map into which the derived information is stored.PersistenceException
- if there is an error querying index information from the JDBC driver.private static void mapCompositeProperties(org.hibernate.cfg.Configuration config)
composite-element
s for fast access later by the HQLPreprocessor
when rewriting where clauses.config
- Hibernate configuration for all DMO classes loaded for a
particular physical database.private static void mapCompositeProperties(org.hibernate.mapping.Collection collection, org.hibernate.mapping.Component component, boolean dynamic)
composite-element
collection
mapping for fast access later by the HQLPreprocessor
. The
preprocessor needs to look up the name of a composite element
collection, given a DMO implementation class and the name of a property
within the composite-element.
The data structure we create to enable this is a map within a map. The inner map contains composite element collection names as values, and is indexed by property name keys. These inner maps are the values stored within the outer map, whose keys are the DMO classes which contain these collections. A single outer map is shared across all schemae, since DMO implementation classes are unique within this space.
collection
- The Hibernate mapping object which defines the collection of
composite elements.component
- The Hibernate mapping object which defines the composite
elements stored in the collection.dynamic
- true
if DMO class is dynamic, false
if
it is static.private static void mapSecondaryTables(Database database, org.hibernate.cfg.Configuration config)
It is expected that this method is only called for the special database which backs temp tables. The mapping is created at P2J server initialization, and is used when creating and dropping temp tables at runtime.
config
- Hibernate configuration for all DMO classes loaded for a
particular physical database.private static int updateTransientRefCount(Database database, boolean increment)
The reference count is either incremented by 1, decremented by 1, or left unchanged, based upon the following rules:
increment
is true
:
database
is already registered in the local
context, no change is made;
increment
is false
:
database
is not registered in the local
context, no change is made;
This logic ensures that attempts to register and deregister the same database, if not properly bracketed, will not corrupt the global reference count.
database
- A transient database.increment
- true
to increment reference count by 1;
false
to decrement reference count by 1;
See above for the implications of this.database
after the update; or -1 if
database
was not recognized.private static int updateTransientRefCountWorker(Database database, int delta)
delta
have been correctly computed,
respectively updateTransientRefCount()
where the current context is inspected
to see if incrementation is needed, or from context clean when all databases from context
should be de-ref counted (and delta
is -1).database
- A transient database.delta
- Specifies the direction of change (1 = increment, -1 decrement, 0 = no change);
See updateTransientRefCount() for details.database
after the update; or -1 if
database
was not recognized.private static java.util.Properties loadConfigProperties(Database database) throws PersistenceException
Properties
object. The contents of this
object must match the properties expected by a Hibernate
Configuration
object.database
- Database for which properties are to be loaded. This
differentiates the directory key by database name.PersistenceException
- if no configuration properties for the specified database
were found; if the directory service is unavailable.private static java.util.Properties createEmbeddedProperties(Database database)
database
- The database information object for the embedded database.private static java.util.Properties createDefaultTempProperties()
private static void readHibernateProperties(DirectoryService ds, java.lang.String id, java.util.Properties props)
/meta/class/string
directory entry
terminus.
This method does not know or care about the names of individual properties; it simply performs a depth-first enumeration of a directory subtree and composes the property names from the directory entry names it encounters. Error checking of property names and values is left to the Hibernate configuration subsystem.
ds
- Directory service instance.id
- Directory entry key for the node currently being visited.props
- Object to which properties are added.