public final class MetadataManager
extends java.lang.Object
isMetaDMO(Class)
method, however, is meant to be used by callers who need to
determine whether a particular DMO interface is metadata-related.Modifier and Type | Class and Description |
---|---|
private static class |
MetadataManager.Helper
Helper class for calling DMO setter methods when populating a metaschema record.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
baseDir
Base directory for DMO resources in jar file
|
private static java.util.Map<java.lang.String,java.lang.reflect.Constructor<?>> |
ctorMap
Map of short data type names to constructors which instantiate those types
|
private static java.lang.String |
DDL_INDEX
Well-known name of DDL script to create indexes
|
private static java.lang.String |
DDL_TABLE
Well-known name of DDL script to create tables
|
private static java.util.Set<java.lang.Class<?>> |
dmoMetaTypes
Set of DMO interfaces which are metadata DMOs
|
private static java.util.Map<java.lang.String,java.lang.Class<?>> |
fieldClassMap
Map of short data type names to associated wrapper classes
|
private static java.util.Map<java.lang.String,MetadataManager.Helper> |
helpers
Map of short meta DMO names to helper objects
|
private static boolean |
inUse
Stores the status of the metadata server.
|
private static java.util.logging.Logger |
log
Logger
|
private static java.lang.String |
META_PREFIX
Well-known prefix of metadata DMOs
|
static java.lang.String |
META_SCHEMA
Well-known name of metadata schema
|
private static java.util.Map<java.lang.Class<?>,java.lang.Long> |
templateRecords
Cached the template records (
_file._template values) for fast access. |
Modifier | Constructor and Description |
---|---|
private |
MetadataManager()
Private constructor; this class is not instantiated.
|
Modifier and Type | Method and Description |
---|---|
private static void |
executeDDLScript(Database database,
java.sql.Connection connection,
java.lang.String script)
Execute a script containing DDL SQL statements.
|
static java.lang.Long |
getTemplateRowid(java.lang.Class<?> table)
Return the rowid of the template record for a permanent table.
|
static boolean |
initialize()
Initialize this class and start up a secure database server to allow remote P2J servers to
access metadata.
|
static boolean |
inUse()
Checks the status of the metadata subsystem.
|
static boolean |
isMetaDMO(java.lang.Class<?> dmoIface)
Indicate whether the given DMO interface represents a metaschema table.
|
static void |
populateDatabase(Database database,
java.lang.String schema)
Populate the specified, embedded database with metaschema information read from XML files
stored in the application jar file with a well-known naming/pathing convention:
|
static void |
prepareDatabase(Database database)
Create and load the embedded metadata database for the associated primary database.
|
private static Persistable |
prepareRecord(org.w3c.dom.Element record,
java.lang.String schema)
Given an XML element describing an individual metaschema table record, instantiate a DMO
and initialize its fields for the purpose of inserting the record into the metaschema
database.
|
static void |
setupIdentityManager(Database database,
org.hibernate.dialect.Dialect dialect)
Set up sequence identity mManager for this database by creating the fresh instance of
p2j_id_generator_sequence . |
public static final java.lang.String META_SCHEMA
private static final java.lang.String META_PREFIX
private static final java.lang.String DDL_TABLE
private static final java.lang.String DDL_INDEX
private static final java.util.logging.Logger log
private static final java.util.Map<java.lang.String,java.lang.Class<?>> fieldClassMap
private static final java.util.Map<java.lang.String,java.lang.reflect.Constructor<?>> ctorMap
private static final java.util.Map<java.lang.String,MetadataManager.Helper> helpers
private static java.util.Set<java.lang.Class<?>> dmoMetaTypes
private static java.lang.String baseDir
private static boolean inUse
private static final java.util.Map<java.lang.Class<?>,java.lang.Long> templateRecords
_file._template
values) for fast access. The keys are
the DMO implementation classes of the tables from permanent database. The values are the
rowid
values as Long
data.private MetadataManager()
public static boolean isMetaDMO(java.lang.Class<?> dmoIface)
dmoIface
- DMO interface to test.true
if dmoIface
represents a metaschema table, else false
.public static boolean initialize() throws PersistenceException
true
if the metadata manager was initialized; false
if
there are no metadata classes found.PersistenceException
- if there is any error initializing the class or starting the server.public static boolean inUse()
true
from
the moment the initialize()
has finished with success. At that moment the whole
metadata system is not yet ready as the metadata tables are not yet populated.
Use this method to check if the project was not configured with this feature or if metadata initialization failed, and quickly leave the calling method in these cases.
true
if the MetadataManager
was successfully initialized and
queries on internal data are possible and false
if the initialization
failed and the metadata is not "in use".public static void prepareDatabase(Database database) throws PersistenceException
database
- Database information object.PersistenceException
- if there is any error creating or loading the database.public static void setupIdentityManager(Database database, org.hibernate.dialect.Dialect dialect) throws PersistenceException
p2j_id_generator_sequence
. Because it is repopulated at each startup the start value
of the sequence is not crucial; the value is hardcoded to 10000.database
- The database to set up the identity manager for.dialect
- The dialect for the database. It is used to build the DDL for the sequence create
statement.PersistenceException
- if something goes wrong with database connection.public static void populateDatabase(Database database, java.lang.String schema) throws PersistenceException
{base DMO package}.{database name}.meta.xml
database
- Metaschema database to populate.schema
- Name of the associated, primary database's schema.PersistenceException
- if there is any problem reading the XML file, instantiating DMO instances, or
inserting records into the database.public static java.lang.Long getTemplateRowid(java.lang.Class<?> table)
table
- The permanent table to lookup.rowid
of the template record. If metadata is not enabled
for this project or _file
metatable is not configured or table
is
an invalid name null
is returned.private static Persistable prepareRecord(org.w3c.dom.Element record, java.lang.String schema) throws PersistenceException, java.lang.NoSuchMethodException, java.lang.InstantiationException, java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException
record
- XML element describing the record to be inserted.schema
- Name of the associated, primary database's schema.PersistenceException
- if a data value to be set into the DMO is invalid/illegal for the associated setter
method.java.lang.NoSuchMethodException
- if a DMO setter method cannot be found.java.lang.InstantiationException
- if a DMO or data wrapper class cannot be instantiated.java.lang.reflect.InvocationTargetException
- if the underlying methods called with reflection throw an exception.java.lang.IllegalAccessException
- if a method called with reflection cannot be accessed.private static void executeDDLScript(Database database, java.sql.Connection connection, java.lang.String script) throws PersistenceException
database
- Target database.connection
- Connection to target database.script
- Short name of script file, which is expected to be found in the application jar
file. The following path is implied:
{base DMO package}._meta.{script name}
PersistenceException
- if there is any error connecting to the target database or executing the DDL
statements.