com.xavax.xstore
Class PersistenceManager

Object
  extended byPersistenceManager

public class PersistenceManager
extends Object

PersistenceManager coordinates all persistence activity and is the public interface to the persistence framework. PersistenceManager is a singleton; therefore, the constructors are private. The user obtains a PersistenceManager by calling the getManager method and passing the filename for a properties file. Subsequent calls to getManager return the same singleton object. The property file must include the following properties.

java.naming.provider.url
The URL for JNDI name resolution (typically an LDAP server). When running within Weblogic, use t3://hostname:7001
java.naming.factory.initial
The initial context factory for name resolution. When running within Weblogic, use weblogic.jndi.WLInitialContextFactory. When running standalone with no name server, this can be set to com.xavax.xstore.test.MyInitialContextFactory.
com.xavax.xstore.poolSize
The maximum size of the pool of persistence contexts. As many as one context per user or thread may be needed.
com.xavax.xstore.lockStyle
The locking style for the metadata database. Valid choices are: MSS, MySQL, and Oracle.
com.xavax.xstore.url
The name of the metadata database.
com.xavax.xstore.username
Username for the metadata database (null when using data sources).
com.xavax.xstore.password
Password for the metadata database (null when using data sources).

The following properties are used when running without JNDI support. These properties are only examined if the initial context factory is com.xavax.xstore.util.InitialContextFactory.

com.xavax.xstore.driver
The classname of the JDBC driver.
com.xavax.xstore.sourceList
A list of data sources to be created and bound to names in the initial context.
com.xavax.xstore.*.url
The URL for a data source (where * is the data source name).
com.xavax.xstore.*.username
The username for a data source.
com.xavax.xstore.*.password
The password for a data source.
com.xavax.xstore.*.poolSize
The maximum number of connections in the pool.

See Also:
InitialContextFactory

Method Summary
 Iterator classes()
          Returns an iterator for the collection of persistent classes contained in the metadata.
 PersistenceContext currentContext()
          Returns the current persistence context.
 Iterator databases()
          Returns an iterator for the collection of databases contained in the metadata.
 ClassMap findClass(short id)
          Returns the class map for the class with the specified identifier.
 ClassMap findClass(String name)
          Returns the class map for the class with the specified name.
 ColumnMap findColumn(String tblname, String colname)
          Returns a column map for the specified column.
 DatabaseMap findDatabase(short id)
          Returns a database map for the database with the specified identifier.
 DatabaseMap findDatabase(String name)
          Returns a database map for the database with the specified name.
 TableMap findTable(String name)
          Returns a table map for table with the specified name.
 PersistenceContext getContext()
          Create a new persistence context and bind it to the current thread.
static PersistenceManager getManager()
          Returns the persistence manager, or null if no PersistenceManager is instantiated.
static PersistenceManager getManager(PersistenceProperties props, Context ctx)
          Returns the PersistenceManager.
static PersistenceManager getManager(String filename)
          Returns the PersistenceManager.
 Context namingContext()
          Returns the naming context used to resolve data source names.
 long nextOID()
          Returns the next object identifier.
 void outputXML(PrintWriter out)
          Output the metadata in XML format.
 boolean ready()
          Returns true if this persistence manager is ready.
 void showClasses()
          Display the metadata for each class in a user-friendly format.
 void showDatabases()
          Display the metadata for each database in a user-friendly format.
 void showTables()
          Display the metadata for all tables in a user-friendly format.
 void shutdown()
          Shut down the persistence manager.
 Iterator tables()
          Returns an iterator for the collection of tables in the metadata.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

currentContext

public PersistenceContext currentContext()
                                  throws PersistenceException
Returns the current persistence context.

Returns:
the current persistence context.
Throws:
PersistenceException

getContext

public PersistenceContext getContext()
                              throws PersistenceException
Create a new persistence context and bind it to the current thread.

Returns:
a persistence context.
Throws:
PersistenceException

getManager

public static PersistenceManager getManager(String filename)
                                     throws PersistenceException
Returns the PersistenceManager. A PersistenceManager is instantiated using the specified properties the first time this method is called. Subsequent calls return the same PersistenceManager object.

Parameters:
filename - the name of a properties file.
Returns:
the PersistenceManager.
Throws:
PersistenceException - if the properties file was not found, the properties could not be loaded, or a PersistenceManager was not instantiated successfully.

getManager

public static PersistenceManager getManager(PersistenceProperties props,
                                            Context ctx)
                                     throws PersistenceException
Returns the PersistenceManager. A PersistenceManager is instantiated using the specified properties and context the first time this method is called. Subsequent calls return the same object.

Parameters:
props - the persistence properties.
ctx - the Context to use for JNDI name resolution.
Returns:
the PersistenceManager.
Throws:
PersistenceException - if the properties file was not found, the properties could not be loaded, or a PersistenceManager was not instantiated successfully.

getManager

public static PersistenceManager getManager()
Returns the persistence manager, or null if no PersistenceManager is instantiated.

Returns:
the persistence manager

shutdown

public void shutdown()
Shut down the persistence manager. Stop responding to requests for PersistenceContexts. Close each ClassMap which results in closing all prepared statements. Close each DatabaseMap which results in shutting down the connection pool for each database.


nextOID

public long nextOID()
Returns the next object identifier. This method is temporarily made public for testing the OID sequencer and should be removed or made private for production.

Returns:
the next unique object identifier.

findClass

public ClassMap findClass(String name)
Returns the class map for the class with the specified name.

Parameters:
name - the name of the class to find.
Returns:
a ClassMap containing the metadata for the specified class.

findClass

public ClassMap findClass(short id)
Returns the class map for the class with the specified identifier.

Parameters:
id - the class identifier.
Returns:
a ClassMap containing the metadata for the specified class.

showClasses

public void showClasses()
Display the metadata for each class in a user-friendly format.


classes

public Iterator classes()
Returns an iterator for the collection of persistent classes contained in the metadata.

Returns:
an iterator for the collection of persistent classes.

findDatabase

public DatabaseMap findDatabase(short id)
Returns a database map for the database with the specified identifier.

Parameters:
id - the database identifier.
Returns:
the database with the specified identifier.

findDatabase

public DatabaseMap findDatabase(String name)
Returns a database map for the database with the specified name.

Parameters:
name - the database name.
Returns:
the database with the specified name.

showDatabases

public void showDatabases()
Display the metadata for each database in a user-friendly format.


databases

public Iterator databases()
Returns an iterator for the collection of databases contained in the metadata.

Returns:
an iterator for the collection of databases.

findTable

public TableMap findTable(String name)
Returns a table map for table with the specified name.

Parameters:
name - the table name.
Returns:
the table map for the specified table.

findColumn

public ColumnMap findColumn(String tblname,
                            String colname)
Returns a column map for the specified column.

Parameters:
tblname - the table name.
colname - the column name.
Returns:
a column map for the specified column.

showTables

public void showTables()
Display the metadata for all tables in a user-friendly format.


tables

public Iterator tables()
Returns an iterator for the collection of tables in the metadata.

Returns:
an iterator for a collection of tables.

namingContext

public Context namingContext()
Returns the naming context used to resolve data source names.

Returns:
the naming context used to resolve data source names.

ready

public boolean ready()
Returns true if this persistence manager is ready.

Returns:
true if this persistence manager is ready.

outputXML

public void outputXML(PrintWriter out)
Output the metadata in XML format.

Parameters:
out - the output writer.