|
EclipseLink 1.2.0, build 'v20091016-r5565' API Reference | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.persistence.sessions.factories.SessionFactory
public class SessionFactory
Helper class to simplify the development and generation of code that accesses TopLink through the SessionManager (sessions config XML). Responsibilities:
SessionFactory = sessionFactory = new SessionFactory("session-name");
...
public List read(Vector args) {
Session session = sessionFactory.acquireSession();
List results = (List) session.executeQuery("query-name", MyClass.class, args);
session.release();
return results;
}
public void write(MyClass detachedInstance) {
UnitOfWork uow = sessionFactory.acquireUnitOfWork();
MyClass workingCopy = (MyClass) uow.readObject(detachedInstance);
if (workingCopy == null) {
throw new MyException("Cannot write changes. Object does not exist");
}
uow.deepMergeClone(detachedInstance);
uow.commit();
}
Detachment: The detach helper methods are provided to assist with the
construction of applications. This helper class was designed for use within
session beans (SB) and in the case of local SBs the objects returned are not
serialized. Since EclipseLink's default behavior is to return the shared instance
from the cache and rely on developers to only modify instances within a
UnitOfWork this may be an issue. The client to the local session bean may
try to modify the instance and thus corrupt the cache. By detaching the object
the client to the session bean gets its own isolated copy that it can freely
modify. This provides the same functionality as with a remote session bean
and allows the developer the choice in how/when objects are detached.
Note: The above code example shows how a detached instance can have
changes made to it persisted through use of the UnitOfWork merge API.
Constructor Summary | |
---|---|
SessionFactory(java.lang.String sessionName)
|
|
SessionFactory(java.lang.String sessionsXMLPath,
java.lang.String sessionName)
Constructor for creating a new EclipseLinkSessionHelper instance. |
Method Summary | |
---|---|
Session |
acquireSession()
Returns the Session active for this specified helper. |
UnitOfWork |
acquireUnitOfWork()
Looks up the active UnitOfWork using either the global JTA TX or acquires a new one from the active session. |
UnitOfWork |
acquireUnitOfWork(Session session)
Looks up the active UnitOfWork using either the global JTA TX or acquires a new one from the active session. |
java.util.Collection |
detach(java.util.Collection entities)
|
java.lang.Object |
detach(java.lang.Object entity)
Build a detached copy using a one-off UnitOfWork. |
protected java.lang.ClassLoader |
getClassLoader()
The class-loader returned form this call will be used when loading the EclipseLink configuration. |
java.lang.String |
getSessionName()
|
java.lang.String |
getSessionXMLPath()
|
DatabaseSession |
getSharedSession()
Helper method that looks up the singleton session and ensure that if the application has been hot-deployed it gets a fresh version of the server. |
DatabaseSession |
getSharedSession(boolean login,
boolean refresh)
Used in place of getSharedSession() when the calling application needs access to the session prior to login or it wishes to force the session configuration to be re-loaded an applied. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SessionFactory(java.lang.String sessionsXMLPath, java.lang.String sessionName)
sessionsXMLPath
- - resource path of the sessions configuration xml.sessionName
- - name of the session to use.public SessionFactory(java.lang.String sessionName)
Method Detail |
---|
public java.lang.String getSessionName()
public java.lang.String getSessionXMLPath()
protected java.lang.ClassLoader getClassLoader()
public DatabaseSession getSharedSession()
public DatabaseSession getSharedSession(boolean login, boolean refresh)
public Session acquireSession()
public UnitOfWork acquireUnitOfWork()
public UnitOfWork acquireUnitOfWork(Session session)
public java.lang.Object detach(java.lang.Object entity)
entity
- an existing persistent entity
public java.util.Collection detach(java.util.Collection entities)
|
EclipseLink 1.2.0, build 'v20091016-r5565' API Reference | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |