|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean
FactoryBean that creates a local JDO PersistenceManager instance. Behaves like a PersistenceManagerFactory instance when used as bean reference, e.g. for JdoTemplate's "persistenceManagerFactory" property. Note that switching to a JndiObjectFactoryBean or a bean-style PersistenceManagerFactory instance is just a matter of configuration!
The typical usage will be to register this as singleton factory (for a certain underlying data source) in an application context, and give bean references to application services that need it.
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 that solely use JDO for data access. In this case, JdoTransactionManager is much more convenient than setting up your JDO implementation for JTA transactions (which might involve JCA).
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 respective JDO properties).
For example, in case of JPOX:
<bean id="persistenceManagerFactory" class="org.jpox.PersistenceManagerFactoryImpl" destroy-method="close"> <property name="connectionFactory"><ref bean="dataSource"/></property> <property name="nontransactionalRead"><value>true</value></property> </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 instance. 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 it creates, without any special configuration.
JdoAccessor.setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory)
,
JdoTransactionManager.setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory)
,
JndiObjectFactoryBean
,
JDOHelper.getPersistenceManagerFactory(java.util.Properties)
,
PersistenceManagerFactory.setConnectionFactory(java.lang.Object)
,
PersistenceManagerFactory.close()
Field Summary | |
protected Log |
logger
|
Constructor Summary | |
LocalPersistenceManagerFactoryBean()
|
Method Summary | |
void |
afterPropertiesSet()
Initialize the PersistenceManagerFactory for the given location. |
void |
destroy()
Close the PersistenceManagerFactory on context shutdown. |
Object |
getObject()
Return the singleton PersistenceManagerFactory. |
Class |
getObjectType()
Return the type of object that this FactoryBean creates, or null if not known in advance. |
boolean |
isSingleton()
Is the bean managed by this factory a singleton or a prototype? |
protected javax.jdo.PersistenceManagerFactory |
newPersistenceManagerFactory(Properties 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 The default implementation invokes JDOHelper's getPersistenceManagerFactory. |
void |
setConfigLocation(Resource configLocation)
Set the location of the JDO properties config file, for example as classpath resource "classpath:kodo.properties". |
void |
setJdoProperties(Properties jdoProperties)
Set JDO properties, like "javax.jdo.PersistenceManagerFactoryClass". |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final Log logger
Constructor Detail |
public LocalPersistenceManagerFactoryBean()
Method Detail |
public void setConfigLocation(Resource configLocation)
Note: Can be omitted when all necessary properties are specified locally via this bean.
public void setJdoProperties(Properties jdoProperties)
Can be used to override values in a JDO properties config file, or to specify all necessary properties locally.
public void afterPropertiesSet() throws IllegalArgumentException, IOException, javax.jdo.JDOException
afterPropertiesSet
in interface InitializingBean
IllegalArgumentException
- in case of illegal property values
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(Properties props)
The default implementation invokes JDOHelper's getPersistenceManagerFactory. A custom implementation could prepare the instance in a specific way, or use a custom PersistenceManagerFactory implementation.
props
- Properties prepared by this LocalPersistenceManagerFactoryBean
JDOHelper.getPersistenceManagerFactory(java.util.Properties)
public Object getObject()
getObject
in interface FactoryBean
public Class getObjectType()
FactoryBean
For a singleton, this should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too.
This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available.
NOTE: Autowiring will simply ignore FactoryBeans that return null here. Therefore it is highly recommended to implement this method properly, using the current state of the FactoryBean.
getObjectType
in interface FactoryBean
ListableBeanFactory.getBeansOfType(java.lang.Class)
public boolean isSingleton()
FactoryBean
The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there.
isSingleton
in interface FactoryBean
public void destroy()
destroy
in interface DisposableBean
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |