public final class PersistenceFactory
extends java.lang.Object
Persistence
objects. Manages a cache of
Persistence
objects, keyed by Database
. When an
instance is requested via one of the getInstance()
method
variants, the cache is checked for an existing instance. If none exists,
the factory determines what type of Persistence
implementation
is necessary for a particular database, instantiates it, initializes it,
caches it, and returns it.
Currently, this factory knows how to generate instances of:
Persistence
- used for locally managed databases.
RemotePersistence
- used for remotely managed databases.
Persistence objects can be removed from the cache by other persistence
framework classes via the remove(Database)
method.
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<Database,Persistence> |
cache
Cache of
Persistence instances by database |
Constructor and Description |
---|
PersistenceFactory() |
Modifier and Type | Method and Description |
---|---|
static Persistence |
getInstance(Database database)
Get the instance of this class associated with the given, physical database, creating it
first if necessary.
|
static Persistence |
getInstance(java.lang.String name)
Get the
Persistence instance associated with the given, physical database name,
creating it first if necessary. |
(package private) static Persistence |
remove(Database database)
Remove the
Persistence instance associated with the given
database from the global cache. |
private static final java.util.Map<Database,Persistence> cache
Persistence
instances by databasepublic static Persistence getInstance(java.lang.String name)
Persistence
instance associated with the given, physical database name,
creating it first if necessary. Assumes the name specifies a primary database. Newly
created instances are stored in a static cache.name
- Name of physical database with which the instance is
permanently associated.public static Persistence getInstance(Database database)
database
- Database with which the instance is permanently associated.java.lang.IllegalArgumentException
- if database
represents a dirty database.static Persistence remove(Database database)
Persistence
instance associated with the given
database from the global cache.
This method should be called with caution. It is provided primarily to support transient databases, which are connected explicitly, used for a time by one or more users, then disconnected.
database
- Database with which the instance is associated.Persistence
which was removed