org.springframework.orm.jdo
Class LocalPersistenceManagerFactoryBean

java.lang.Object
  extended byorg.springframework.orm.jdo.LocalPersistenceManagerFactoryBean
All Implemented Interfaces:
DisposableBean, FactoryBean, InitializingBean

public class LocalPersistenceManagerFactoryBean
extends java.lang.Object
implements FactoryBean, InitializingBean, DisposableBean

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 JndiObjectFactoryBean 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).

Since:
03.06.2003
Author:
Juergen Hoeller
See Also:
JdoAccessor.setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory), JdoTransactionManager.setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory), JndiObjectFactoryBean

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 context shutdown.
 java.lang.Object getObject()
          Return the singleton PersistenceManagerFactory.
 java.lang.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? That is, will getObject() always return the same object?
protected  javax.jdo.PersistenceManagerFactory newPersistenceManagerFactory(java.util.Properties prop)
          Subclasses can override this to perform custom initialization of the PersistenceManagerFactory instance, creating it via the given Properties that got prepared by this LocalPersistenceManagerFactoryBean
 void setConfigLocation(Resource configLocation)
          Set the location of the JDO properties config file, for example as classpath resource "classpath:kodo.properties".
 void setDataSource(javax.sql.DataSource dataSource)
          Set the DataSource to be used by the PersistenceManagerFactory.
 void setJdoProperties(java.util.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

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

LocalPersistenceManagerFactoryBean

public LocalPersistenceManagerFactoryBean()
Method Detail

setConfigLocation

public void setConfigLocation(Resource configLocation)
Set the location of the JDO properties config file, for example as classpath resource "classpath:kodo.properties".

Note: Can be omitted when all necessary properties are specified locally via this bean.


setJdoProperties

public void setJdoProperties(java.util.Properties jdoProperties)
Set JDO properties, like "javax.jdo.PersistenceManagerFactoryClass".

Can be used to override values in a JDO properties config file, or to specify all necessary properties locally.


setDataSource

public void setDataSource(javax.sql.DataSource dataSource)
Set the DataSource to be used by the PersistenceManagerFactory. If set, this will override corresponding settings in JDO properties.

Note: If this is set, the JDO settings should not define a connection factory to avoid meaningless double configuration.


afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.IllegalArgumentException,
                               java.io.IOException,
                               javax.jdo.JDOException
Initialize the PersistenceManagerFactory for the given location.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
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 errors

newPersistenceManagerFactory

protected javax.jdo.PersistenceManagerFactory newPersistenceManagerFactory(java.util.Properties prop)
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. A custom implementation could prepare the instance in a specific way, or use a custom PersistenceManagerFactory implementation.

Parameters:
prop - Properties prepared by this LocalPersistenceManagerFactoryBean
Returns:
the PersistenceManagerFactory instance
See Also:
JDOHelper.getPersistenceManagerFactory(java.util.Properties)

getObject

public java.lang.Object getObject()
Return the singleton PersistenceManagerFactory.

Specified by:
getObject in interface FactoryBean
Returns:
an instance of the bean (should never be null)

getObjectType

public java.lang.Class getObjectType()
Description copied from interface: FactoryBean
Return the type of object that this FactoryBean creates, or null if not known in advance. This allows to check for specific types of beans without instantiating objects, e.g. on autowiring.

For a singleton, this can simply return getObject().getClass(), or even null, as autowiring will always check the actual objects for singletons. For prototypes, returning a meaningful type here is highly advisable, as autowiring will simply ignore them else.

Specified by:
getObjectType in interface FactoryBean
Returns:
the type of object that this FactoryBean creates, or null
See Also:
ListableBeanFactory.getBeansOfType(java.lang.Class, boolean, boolean)

isSingleton

public boolean isSingleton()
Description copied from interface: FactoryBean
Is the bean managed by this factory a singleton or a prototype? That is, will getObject() always return the same object?

The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory.

Specified by:
isSingleton in interface FactoryBean
Returns:
if this bean is a singleton

destroy

public void destroy()
Close the PersistenceManagerFactory on context shutdown.

Specified by:
destroy in interface DisposableBean


Copyright (C) 2003-2004 The Spring Framework Project.