|
spring-orm | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.orm.jdo.LocalPersistenceManagerFactoryBean
public class LocalPersistenceManagerFactoryBean
FactoryBean
that creates a
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!
NOTE: This class requires JDO 2.0 or higher, as of Spring 2.5.
Since JDO 2.1, it will also expose the JPA EntityManagerFactory
as long as the JDO provider creates a JDOEntityManagerFactory
reference
underneath, which means that this class can be used as a replacement for
LocalEntityManagerFactoryBean
in such a scenario.
Configuration settings can either be read from a properties file,
specified as "configLocation", or locally specified. Properties
specified as "jdoProperties" here will override any settings in a file.
On JDO 2.1, you may alternatively specify a "persistenceManagerFactoryName",
referring to a PMF definition in "META-INF/jdoconfig.xml"
(see setPersistenceManagerFactoryName(java.lang.String)
).
This class also implements the
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 in JDO; 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.
JdoAccessor.setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory)
,
JdoTransactionManager.setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory)
,
JndiObjectFactoryBean
,
JDOHelper.getPersistenceManagerFactory()
,
PersistenceManagerFactory.setConnectionFactory(java.lang.Object)
,
PersistenceManagerFactory.close()
,
org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
Field Summary | |
---|---|
protected org.apache.commons.logging.Log |
logger
|
Constructor Summary | |
---|---|
LocalPersistenceManagerFactoryBean()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Initialize the PersistenceManagerFactory for the given location. |
void |
destroy()
Close the PersistenceManagerFactory on bean factory shutdown. |
java.util.Map<java.lang.String,java.lang.Object> |
getJdoPropertyMap()
Allow Map access to the JDO properties to be passed to the JDOHelper, with the option to add or override specific entries. |
javax.jdo.PersistenceManagerFactory |
getObject()
Return the singleton PersistenceManagerFactory. |
java.lang.Class<? extends javax.jdo.PersistenceManagerFactory> |
getObjectType()
|
boolean |
isSingleton()
|
protected javax.jdo.PersistenceManagerFactory |
newPersistenceManagerFactory(java.util.Map props)
Subclasses can override this to perform custom initialization of the PersistenceManagerFactory instance, creating it via the given Properties that got prepared by this LocalPersistenceManagerFactoryBean. |
protected javax.jdo.PersistenceManagerFactory |
newPersistenceManagerFactory(java.lang.String name)
Subclasses can override this to perform custom initialization of the PersistenceManagerFactory instance, creating it for the specified name. |
void |
setBeanClassLoader(java.lang.ClassLoader beanClassLoader)
|
void |
setConfigLocation(org.springframework.core.io.Resource configLocation)
Set the location of the JDO properties config file, for example as classpath resource "classpath:kodo.properties". |
void |
setJdoDialect(JdoDialect jdoDialect)
Set the JDO dialect to use for the PersistenceExceptionTranslator functionality of this factory. |
void |
setJdoProperties(java.util.Properties jdoProperties)
Set JDO properties, such as"javax.jdo.PersistenceManagerFactoryClass". |
void |
setJdoPropertyMap(java.util.Map<java.lang.String,java.lang.Object> jdoProperties)
Specify JDO properties as a Map, to be passed into JDOHelper.getPersistenceManagerFactory (if any). |
void |
setPersistenceManagerFactoryName(java.lang.String persistenceManagerFactoryName)
Specify the name of the desired PersistenceManagerFactory. |
org.springframework.dao.DataAccessException |
translateExceptionIfPossible(java.lang.RuntimeException ex)
Implementation of the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final org.apache.commons.logging.Log logger
Constructor Detail |
---|
public LocalPersistenceManagerFactoryBean()
Method Detail |
---|
public void setPersistenceManagerFactoryName(java.lang.String persistenceManagerFactoryName)
This may either be a properties resource in the classpath if such a resource exists (JDO 2.0), or a PMF definition with that name from "META-INF/jdoconfig.xml" (JDO 2.1), or a JPA EntityManagerFactory cast to a PersistenceManagerFactory based on the persistence-unit name from "META-INF/persistence.xml" (JDO 2.1 / JPA 1.0).
Default is none: Either 'persistenceManagerFactoryName' or 'configLocation' or 'jdoProperties' needs to be specified.
setConfigLocation(org.springframework.core.io.Resource)
,
setJdoProperties(java.util.Properties)
public void setConfigLocation(org.springframework.core.io.Resource configLocation)
Note: Can be omitted when all necessary properties are specified locally via this bean.
public void setJdoProperties(java.util.Properties jdoProperties)
Can be used to override values in a JDO properties config file, or to specify all necessary properties locally.
Can be populated with a String "value" (parsed via PropertiesEditor) or a "props" element in XML bean definitions.
public void setJdoPropertyMap(java.util.Map<java.lang.String,java.lang.Object> jdoProperties)
JDOHelper.getPersistenceManagerFactory
(if any).
Can be populated with a "map" or "props" element in XML bean definitions.
JDOHelper.getPersistenceManagerFactory(java.util.Map)
public java.util.Map<java.lang.String,java.lang.Object> getJdoPropertyMap()
Useful for specifying entries directly, for example via "jdoPropertyMap[myKey]".
public void setJdoDialect(JdoDialect jdoDialect)
Default is a DefaultJdoDialect based on the PersistenceManagerFactory's underlying DataSource, if any.
JdoDialect.translateException(javax.jdo.JDOException)
,
translateExceptionIfPossible(java.lang.RuntimeException)
,
PersistenceExceptionTranslator
public void setBeanClassLoader(java.lang.ClassLoader beanClassLoader)
setBeanClassLoader
in interface org.springframework.beans.factory.BeanClassLoaderAware
public void afterPropertiesSet() throws java.lang.IllegalArgumentException, java.io.IOException, javax.jdo.JDOException
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.IllegalArgumentException
- in case of illegal property values
java.io.IOException
- if the properties could not be loaded from the given location
javax.jdo.JDOException
- in case of JDO initialization errorsprotected javax.jdo.PersistenceManagerFactory newPersistenceManagerFactory(java.lang.String name)
The default implementation invokes JDOHelper's
getPersistenceManagerFactory(String)
method.
A custom implementation could prepare the instance in a specific way,
or use a custom PersistenceManagerFactory implementation.
name
- the name of the desired PersistenceManagerFactory
JDOHelper.getPersistenceManagerFactory(String)
protected javax.jdo.PersistenceManagerFactory newPersistenceManagerFactory(java.util.Map props)
The default implementation invokes JDOHelper's
getPersistenceManagerFactory(Map)
method.
A custom implementation could prepare the instance in a specific way,
or use a custom PersistenceManagerFactory implementation.
props
- the merged properties prepared by this LocalPersistenceManagerFactoryBean
JDOHelper.getPersistenceManagerFactory(java.util.Map)
public javax.jdo.PersistenceManagerFactory getObject()
getObject
in interface org.springframework.beans.factory.FactoryBean<javax.jdo.PersistenceManagerFactory>
public java.lang.Class<? extends javax.jdo.PersistenceManagerFactory> getObjectType()
getObjectType
in interface org.springframework.beans.factory.FactoryBean<javax.jdo.PersistenceManagerFactory>
public boolean isSingleton()
isSingleton
in interface org.springframework.beans.factory.FactoryBean<javax.jdo.PersistenceManagerFactory>
public org.springframework.dao.DataAccessException translateExceptionIfPossible(java.lang.RuntimeException ex)
Converts the exception if it is a JDOException, preferably using a specified
JdoDialect. Else returns null
to indicate an unknown exception.
translateExceptionIfPossible
in interface org.springframework.dao.support.PersistenceExceptionTranslator
org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
,
JdoDialect.translateException(javax.jdo.JDOException)
,
PersistenceManagerFactoryUtils.convertJdoAccessException(javax.jdo.JDOException)
public void destroy()
destroy
in interface org.springframework.beans.factory.DisposableBean
|
spring-orm | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |