SessionFactory
can be used to create {@link Session} to execute commands.The {@link org.apache.karaf.shell.api.console.Registry} associatedwith this SessionFactory
will contain: 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.
@author Doug Clarke & John Braken
@version 10.1.3
@since Dec 10, 2006
Example:
public static void main(String[] args) throws Exception { SessionFactory factory = SessionFactory.getFactory(); Session session = factory.getSession(); session.init(""); session.exit(); }@author dan.templeton@sun.com @see Session @since 0.5 @version 1.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|