public static PersistenceManagerFactory getPersistenceManagerFactory (Properties props); public static PersistenceManagerFactory getPersistenceManagerFactory (Properties props, ClassLoader loader); public static PersistenceManagerFactory getPersistenceManagerFactory (String rsrc); public static PersistenceManagerFactory getPersistenceManagerFactory (String rsrc, ClassLoader loader); public static PersistenceManagerFactory getPersistenceManagerFactory (File file); public static PersistenceManagerFactory getPersistenceManagerFactory (File file, ClassLoader loader);
You can use the getPersistenceManagerFactory
methods of JDOHelper to obtain
PersistenceManagerFactory objects in
a vendor-neutral fashion. Each method accepts a
java.util.Properties instance, the name of a
CLASSPATH properties resource, or a properties file.
JDOHelper uses the
javax.jdo.PersistenceManagerFactoryClass property
value to invoke your vendor's PersistenceManagerFactory
class. It uses the rest of the properties to configure
the PersistenceManagerFactory
before returning it to you. Vendors may construct a new
PersistenceManagerFactory with each
invocation of this method, or may return a pooled instance that
matches the supplied properties.
The available configuration options and their associated property
names are discussed in Chapter 7, PersistenceManagerFactory.
![]() | Note |
|---|---|
Set the |
If the vendor's PersistenceManagerFactory
class is not visible to the current thread's class loader, you
can supply an alternative ClassLoader
to the JDOHelper when invoking each method.
public static PersistenceManagerFactory getPersistenceManagerFactory (String name,
Context jndiContext);
public static PersistenceManagerFactory getPersistenceManagerFactory (String name,
Context jndiContext, ClassLoader loader);
This is a convenience method to retrieve a previously-bound
PersistenceManagerFactory from the
Java Naming and Directory Interface (JNDI). If the given
Context is null, the
JDOHelper will create a new
InitialContext with which to perform the lookup.
Example 6.1. Obtaining a PersistenceManagerFactory from Properties
// this is usually just done once in your application somewhere, and then
// you cache the factory for easy retrieval by application components
Properties props = new Properties ();
// this property key tells the JDOHelper what factory class to instantiate
props.setProperty ("javax.jdo.PersistenceManagerFactoryClass",
"kodo.jdo.PersistenceManagerFactoryImpl");
// these properties define the default settings for PersistenceManagers
// produced by this factory; these settings are covered in the next chapter
props.setProperty ("javax.jdo.option.Optimistic", "true");
props.setProperty ("javax.jdo.option.RetainValues", "true");
props.setProperty ("javax.jdo.option.ConnectionUserName", "solarmetric");
props.setProperty ("javax.jdo.option.ConnectionPassword", "kodo");
props.setProperty ("javax.jdo.option.ConnectionURL", "jdbc:hsql:database");
props.setProperty ("javax.jdo.option.ConnectionDriverName",
"org.hsqldb.jdbcDriver");
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory (props);
Example 6.2. Obtaining a PersistenceManagerFactory from a Resource
// the jdo.properties resource sets the javax.jdo.PersistenceManagerFactory
// key to kodo.jdo.PersistenceManagerFactoryImpl, and includes other
// javax.jdo.option.* settings
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory ("jdo.properties");