|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jenkov.mrpersister.PersistenceManager
public class PersistenceManager
This class is the starting point of all Mr. Persister use. Create an instance of PersistenceManager, then ask for
its factories, then create an IGenericDao instance and start reading and writing objects. Many things are cached
inside the PersistenceManager, so you should reuse the same instance once you have created it. Assign it to a
constant, or make it a singleton, like this:
public static final PERSISTENCE_MANAGER = new PersistenceManager();
IGenericDao dao = PERSISTENCE_MANAGER.getGenericDaoFactory().createDao(connection);
The PersistenceManager instance
should be reused throughout the application lifetime. Each application should create it's own PersistenceManager
instance.
It is safe to share PersistenceManager instances if:
1) The components sharing them are reading the same type of objects from the same database.
2) The components sharing them are reading different types of objects from the same or different databases.
When sharing PersistenceManager instance be aware of what persistence configurations are used by the components
sharing the PersistenceManager instance.
Constructor Summary | |
---|---|
PersistenceManager()
Creates an empty PersistenceManager instance. |
|
PersistenceManager(javax.sql.DataSource dataSource)
Creates a PersistenceManager instance and stores the given DataSource in the default persistence configuration. |
Method Summary | |
---|---|
IDaos |
createDaos()
Equivalent to calling getDaosFactory().createDao(); |
IDaos |
createDaos(java.sql.Connection connection)
Equivalent to calling getDaosFactory().createDao(connection); |
java.lang.Object |
execute(IDaoCommand daoCommand)
Equivalent to calling getDaoCommandExecutor().execute(daoCommand); |
java.lang.Object |
executeTransaction(IDaoCommand daoCommand)
Equivalent to calling getDaoCommandExecutor().executeTransaction(daoCommand); |
java.lang.Object |
executeTransactionUnchecked(IDaoCommand daoCommand)
Equivalent to calling getDaoCommandExecutorUnchecked().executeTransaction(daoCommand); |
java.lang.Object |
executeUnchecked(IDaoCommand daoCommand)
Equivalent to calling getDaoCommandExecutorUnchecked().execute(daoCommand); |
IPersistenceConfigurationFactory |
getConfigurationFactory()
Returns the persistence configuration factory currently in use. |
IDaoCommandExecutor |
getDaoCommandExecutor()
|
IDaoCommandExecutorUnchecked |
getDaoCommandExecutorUnchecked()
|
IDaosFactory |
getDaosFactory()
|
IPersistenceConfiguration |
getDefaultConfiguration()
Returns the default persistence configuration of this PersistenceManager. |
IGenericDaoFactory |
getGenericDaoFactory()
Returns the generic dao factory currently used by Mr Persister. |
IObjectMappingFactory |
getObjectMappingFactory()
Returns the object method factory set for the Mr Persister API. |
void |
setConfigurationFactory(IPersistenceConfigurationFactory factory)
Sets the persistence configuration factory to be used with Mr. |
void |
setDaoCommandExecutor(IDaoCommandExecutor daoCommandExecutor)
|
void |
setDaoCommandExecutorUnchecked(IDaoCommandExecutorUnchecked daoCommandExecutorUnchecked)
|
void |
setDaosFactory(IDaosFactory daosFactory)
|
void |
setDataSource(javax.sql.DataSource dataSource)
Sets the default data source used by this PeristenceManager instance, and used by the default IPersistenceConfiguration instance too. |
void |
setDataSource(javax.sql.DataSource dataSource,
java.lang.Object configKey)
Sets the data source to be used by the IPersistenceConfiguration stored by configKey in the configuration factory of this PersistenceManager. |
void |
setGenericDaoFactory(IGenericDaoFactory factory)
Sets the generic dao factory to be used with Mr Persister. |
void |
setObjectMappingFactory(IObjectMappingFactory factory)
Sets the object method factory set for the Mr Persister API. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PersistenceManager()
public PersistenceManager(javax.sql.DataSource dataSource)
dataSource
- Method Detail |
---|
public IPersistenceConfigurationFactory getConfigurationFactory()
MrPersister.createConfiguration()
methods.
Note: You will hardly ever need to access the persistence configuration factory directly.
public void setConfigurationFactory(IPersistenceConfigurationFactory factory)
MrPersister.createConfiguration()
methods.
You should never have to change the persistence factory. Only do so if you know what you
are doing.
Note: You will hardly ever need to set the persistence configuration factory yourself.
factory
- The persistence factory to use.public IPersistenceConfiguration getDefaultConfiguration()
public IObjectMappingFactory getObjectMappingFactory()
public void setObjectMappingFactory(IObjectMappingFactory factory)
factory
- The object method factory to be used with the Mr. Persister API.public IGenericDaoFactory getGenericDaoFactory()
public void setGenericDaoFactory(IGenericDaoFactory factory)
factory
- The generic dao factory to be used with Mr. Persister.public IDaosFactory getDaosFactory()
public void setDaosFactory(IDaosFactory daosFactory)
public IDaoCommandExecutor getDaoCommandExecutor()
public void setDaoCommandExecutor(IDaoCommandExecutor daoCommandExecutor)
public IDaoCommandExecutorUnchecked getDaoCommandExecutorUnchecked()
public void setDaoCommandExecutorUnchecked(IDaoCommandExecutorUnchecked daoCommandExecutorUnchecked)
public void setDataSource(javax.sql.DataSource dataSource)
dataSource
- The data source to set as default.public void setDataSource(javax.sql.DataSource dataSource, java.lang.Object configKey)
getConfigurationFactory().getOrCreateConfiguration(configKey).setDataSource(dataSource);
dataSource
- The data source to set on the persistence configuration.configKey
- The key the persistence configuration is stored by in the configuration factory.public IDaos createDaos() throws PersistenceException
PersistenceException
- If opening the connection fails.public IDaos createDaos(java.sql.Connection connection)
connection
- The Connection to use in the IDaos instance.
public java.lang.Object execute(IDaoCommand daoCommand) throws PersistenceException
daoCommand
- The dao command to execute.
PersistenceException
- If anything goes wrong during the execution of the dao command.public java.lang.Object executeTransaction(IDaoCommand daoCommand) throws PersistenceException
daoCommand
- The dao command to execute.
PersistenceException
- If anything goes wrong during the execution of the dao command.public java.lang.Object executeUnchecked(IDaoCommand daoCommand)
daoCommand
- The dao command to execute.
public java.lang.Object executeTransactionUnchecked(IDaoCommand daoCommand)
daoCommand
- The dao command to execute.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |