ch.elca.el4j.services.persistence.jpa.helper
Class JpaHelperImpl

java.lang.Object
  extended by ch.elca.el4j.services.persistence.jpa.helper.JpaHelperImpl
All Implemented Interfaces:
JpaHelper

public class JpaHelperImpl
extends Object
implements JpaHelper

Implementation of DataService.

Author:
David Bernhard (dab)
File-location:
JpaHelperImpl
Last check-in date:
2010-08-05 11:00:36 +0200 (Do, 05. Aug 2010) by swrelca for revision 4112

Constructor Summary
JpaHelperImpl()
           
 
Method Summary
 void clear()
          Clear the session.
<T> Boolean
contains(T instance)
          Contains an entry.
<T> void
detach(T instance)
          Remove the given entity from the persistence context, causing a managed entity to become detached.
 void doInTransaction(Runnable r)
           
<T> T
findByKey(Class<T> clazz, Integer key)
          Finds an entity by its primary key.
 void flush()
          Flush the session.
 javax.persistence.EntityManager getEntityManager()
          Getter for entity manager.
<T> T
merge(T instance)
          Merge the state of the given entity into the current persistence context.
<T> void
persist(T instance)
          Makes an entity managed and persistent.
<T> void
refresh(T instance)
          Refresh the state of the instance from the database, overwriting changes made to the entity, if any.
<T> void
remove(T instance)
          Delete a MANAGED entity.
<T> JpaQuery<T>
selectFrom(Class<T> cls)
          Initiate a select query.
 void setEntityManager(javax.persistence.EntityManager em)
          Set the entity manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JpaHelperImpl

public JpaHelperImpl()
Method Detail

selectFrom

public <T> JpaQuery<T> selectFrom(Class<T> cls)
Description copied from interface: JpaHelper
Initiate a select query.

Specified by:
selectFrom in interface JpaHelper
Type Parameters:
T - Generic type parameter for the class to select from.
Parameters:
cls - The class to select from.
Returns:
The query object.

contains

@Transactional
public <T> Boolean contains(T instance)
Description copied from interface: JpaHelper
Contains an entry.

Specified by:
contains in interface JpaHelper
Type Parameters:
T - The type parameter.
Parameters:
instance - The object to check if the entity manager contains it.
Returns:
Boolean, true it is contained.

merge

@Transactional
public <T> T merge(T instance)
Description copied from interface: JpaHelper
Merge the state of the given entity into the current persistence context. Transition from DETACHED to MANAGED.

Specified by:
merge in interface JpaHelper
Type Parameters:
T - The type parameter, to allow us to return the merged object.
Parameters:
instance - The object to merge.
Returns:
The managed entity.

detach

@Transactional
public <T> void detach(T instance)
Description copied from interface: JpaHelper
Remove the given entity from the persistence context, causing a managed entity to become detached. Unflushed changes made to the entity if any (including removal of the entity), will not be synchronized to the database. Entities which previously referenced the detached entity will continue to reference it. Transition from MANAGED to DETACHED.

Specified by:
detach in interface JpaHelper
Type Parameters:
T - The type parameter.
Parameters:
instance - The object to detach.

persist

@Transactional
public <T> void persist(T instance)
Description copied from interface: JpaHelper
Makes an entity managed and persistent. Transition from state NEW/REMOVED to MANAGED. On the next flush or commit it is inserted into the database.

Specified by:
persist in interface JpaHelper
Type Parameters:
T - The type parameter.
Parameters:
instance - The object to persist.

remove

@Transactional
public <T> void remove(T instance)
Description copied from interface: JpaHelper
Delete a MANAGED entity. Transition from state MANAGED to REMOVED. On the next flush or commit it is removed from the database.

Specified by:
remove in interface JpaHelper
Type Parameters:
T - The type parameter.
Parameters:
instance - The instance to delete.

refresh

@Transactional
public <T> void refresh(T instance)
Description copied from interface: JpaHelper
Refresh the state of the instance from the database, overwriting changes made to the entity, if any. Transition from state MANAGED to MANAGED again.

Specified by:
refresh in interface JpaHelper
Type Parameters:
T - The type parameter.
Parameters:
instance - The instance to refresh.

findByKey

@Transactional
public <T> T findByKey(Class<T> clazz,
                                     Integer key)
Description copied from interface: JpaHelper
Finds an entity by its primary key. The returned entity is MANAGED.

Specified by:
findByKey in interface JpaHelper
Type Parameters:
T - The type parameter, to allow us to return the searched object.
Parameters:
clazz - The entity class.
key - The primary key.
Returns:
The searched entity (MANAGED).

clear

public void clear()
Description copied from interface: JpaHelper
Clear the session.

Specified by:
clear in interface JpaHelper

flush

@Transactional
public void flush()
Description copied from interface: JpaHelper
Flush the session.

Specified by:
flush in interface JpaHelper

getEntityManager

public javax.persistence.EntityManager getEntityManager()
Getter for entity manager.


setEntityManager

public void setEntityManager(javax.persistence.EntityManager em)
Set the entity manager.

Parameters:
em - The entity manager.

doInTransaction

@Transactional
public void doInTransaction(Runnable r)
Specified by:
doInTransaction in interface JpaHelper


Copyright © 2005-2011 ELCA. All Rights Reserved.