ch.elca.el4j.services.persistence.jpa.helper
Interface JpaHelper

All Known Implementing Classes:
JpaHelperImpl

public interface JpaHelper

Utility class and methods to make database access easier. Type safety is given under the following conditions: When searching, the class provided must be a domain class and any properties provided must be applicable to that class. For example, selectFrom(A.class).with("b", some_b) requires that A is a domain class with a property b of a type corresponding to the class of some_b.

Author:
David Bernhard (dab)
File-location:
JpaHelper
Last check-in date:
2010-08-19 13:27:36 +0200 (Do, 19. Aug 2010) by swrelca for revision 4122

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

Method Detail

selectFrom

<T> JpaQuery<T> selectFrom(Class<T> cls)
Initiate a select query.

Type Parameters:
T - Generic type parameter for the class to select from.
Parameters:
cls - The class to select from.
Returns:
The query object.

contains

<T> Boolean contains(T instance)
Contains an entry.

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

<T> T merge(T instance)
Merge the state of the given entity into the current persistence context. Transition from DETACHED to MANAGED.

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

<T> void detach(T instance)
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.

Type Parameters:
T - The type parameter.
Parameters:
instance - The object to detach.

persist

<T> void persist(T instance)
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.

Type Parameters:
T - The type parameter.
Parameters:
instance - The object to persist.

remove

<T> void remove(T instance)
Delete a MANAGED entity. Transition from state MANAGED to REMOVED. On the next flush or commit it is removed from the database.

Type Parameters:
T - The type parameter.
Parameters:
instance - The instance to delete.

refresh

<T> void refresh(T instance)
Refresh the state of the instance from the database, overwriting changes made to the entity, if any. Transition from state MANAGED to MANAGED again.

Type Parameters:
T - The type parameter.
Parameters:
instance - The instance to refresh.

findByKey

<T> T findByKey(Class<T> clazz,
                Integer key)
Finds an entity by its primary key. The returned entity is MANAGED.

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

void clear()
Clear the session.


flush

void flush()
Flush the session.


doInTransaction

void doInTransaction(Runnable r)


Copyright © 2005-2011 ELCA. All Rights Reserved.