org.springframework.beans.factory.FactoryBean that creates a
JDO
javax.jdo.PersistenceManagerFactory . This is the usual way to
set up a shared JDO PersistenceManagerFactory in a Spring application context;
the PersistenceManagerFactory can then be passed to JDO-based DAOs via
dependency injection. Note that switching to a JNDI lookup or to a bean-style
PersistenceManagerFactory instance is just a matter of configuration!
Configuration settings can either be read from a properties file,
specified as "configLocation", or completely via this class. Properties
specified as "jdoProperties" here will override any settings in a file.
This PersistenceManager handling strategy is most appropriate for
applications which solely use JDO for data access. In this case,
JdoTransactionManager is more convenient than setting up your
JDO provider for JTA transactions (which might involve a JCA connector).
NOTE: This class is compatible with both JDO 1.0 and JDO 2.0,
as far as possible. It uses reflection to adapt to the actual API present
on the class path (concretely: for the getPersistenceManagerFactory
method with either a Properties or a Map argument).
Make sure that the JDO API jar on your class path matches the one that
your JDO provider has been compiled against!
This class also implements the
org.springframework.dao.support.PersistenceExceptionTranslator interface, as autodetected by Spring's
org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor ,
for AOP-based translation of native exceptions to Spring DataAccessExceptions.
Hence, the presence of a LocalPersistenceManagerFactoryBean automatically enables
a PersistenceExceptionTranslationPostProcessor to translate JDO exceptions.
Alternative: Configuration of a PersistenceManagerFactory provider bean
As alternative to the properties-driven approach that this FactoryBean offers
(which is analogous to using the standard JDOHelper class with a Properties
object that is populated with standard JDO properties), you can set up an
instance of your PersistenceManagerFactory implementation class directly.
Like a DataSource, a PersistenceManagerFactory is encouraged to
support bean-style configuration, which makes it very easy to set up as
Spring-managed bean. The implementation class becomes the bean class;
the remaining properties are applied as bean properties (starting with
lower-case characters, in contrast to the corresponding JDO properties).
For example, in case of JPOX:
<bean id="persistenceManagerFactory" class="org.jpox.PersistenceManagerFactoryImpl" destroy-method="close">
<property name="connectionFactory" ref="dataSource"/>
<property name="nontransactionalRead" value="true"/>
</bean>
Note that such direct setup of a PersistenceManagerFactory implementation
is the only way to pass an external connection factory (i.e. a JDBC DataSource)
into a JDO PersistenceManagerFactory. With the standard properties-driven approach,
you can only use an internal connection pool or a JNDI DataSource.
The close() method is standardized as of JDO 1.0.1; don't forget to
specify it as "destroy-method" for any PersistenceManagerFactory instance.
Note that this FactoryBean will automatically invoke close() for
the PersistenceManagerFactory that it creates, without any special configuration.
author: Juergen Hoeller since: 03.06.2003 See Also: JdoTemplate.setPersistenceManagerFactory See Also: JdoTransactionManager.setPersistenceManagerFactory See Also: org.springframework.jndi.JndiObjectFactoryBean See Also: javax.jdo.JDOHelper.getPersistenceManagerFactory See Also: javax.jdo.PersistenceManagerFactory.setConnectionFactory See Also: javax.jdo.PersistenceManagerFactory.close See Also: org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor |