org.loom.persistence
Class TransactionalService

java.lang.Object
  extended by org.loom.persistence.TransactionalService
All Implemented Interfaces:
javax.persistence.EntityManager, ExtendedEntityManager

@Service
public class TransactionalService
extends java.lang.Object
implements ExtendedEntityManager

An ExtendedEntityManager wrapper that offer transactional access to address common needs.


Constructor Summary
TransactionalService()
           
 
Method Summary
 void clear()
           
 void close()
           
 boolean contains(java.lang.Object entity)
           
 javax.persistence.Query createNamedQuery(java.lang.String name)
           
 javax.persistence.Query createNativeQuery(java.lang.String sqlString)
           
 javax.persistence.Query createNativeQuery(java.lang.String sqlString, java.lang.Class resultClass)
           
 javax.persistence.Query createNativeQuery(java.lang.String sqlString, java.lang.String resultSetMapping)
           
 javax.persistence.Query createQuery(java.lang.String qlString)
           
 void evict(java.lang.Object entity)
          Remove this instance from the session cache.
<T> T
find(java.lang.Class<T> entityClass, java.lang.Object primaryKey)
          Retrieves a single persistent instance from the database
<T> java.util.List<T>
find(java.lang.String queryString, java.lang.Object... params)
          Retrieves a non-paged query.
<T> java.util.List<T>
findAll(java.lang.Class<T> clazz)
          Retrieves all records for a specified persistent class This method should be used with care, as it could instantiate huge amounts of data.
<T> java.util.List<T>
findNamed(java.lang.String namedQuery, java.lang.Object... params)
          Retrieves a non-paged query This method should be used with care, as it could instantiate huge amounts of data.
<T> T
findNamedSingle(java.lang.String namedQuery, java.lang.Object... params)
          Execute a query that retrieves a single object.
<T> T
findSingle(java.lang.String queryString, java.lang.Object... params)
           
 void flush()
           
 java.lang.Object getDelegate()
           
 javax.persistence.FlushModeType getFlushMode()
           
 java.lang.String getIdPropertyName(java.lang.Class<?> clazz)
           
<T> T
getReference(java.lang.Class<T> entityClass, java.lang.Object primaryKey)
           
 javax.persistence.EntityTransaction getTransaction()
           
 java.lang.String getVersionPropertyName(java.lang.Class<?> clazz)
           
<T> T
getVersionValue(java.lang.Object entity)
           
 boolean isOpen()
           
 void joinTransaction()
           
 void lock(java.lang.Object entity, javax.persistence.LockModeType lockMode)
           
<T> T
merge(T entity)
           
 void persist(java.lang.Object entity)
           
<T> PagedListData<T>
query(PagedListCriteria criteria)
          Retrieve a paged query.
 void refresh(java.lang.Object entity)
           
<T> T
remove(java.lang.Class<T> clazz, java.lang.Object id)
          Removes a persistent instance
 void remove(java.lang.Object entity)
           
 void setEntityManager(ExtendedEntityManager entityManager)
           
 void setFlushMode(javax.persistence.FlushModeType flushMode)
           
 void setReadOnly(java.lang.Object entity, boolean readOnly)
          Sets an instance to readOnly.
 int update(java.lang.String queryString, java.lang.Object... params)
          Execute a query that updates the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionalService

public TransactionalService()
Method Detail

flush

@Transactional
public void flush()
Specified by:
flush in interface javax.persistence.EntityManager

lock

@Transactional
public void lock(java.lang.Object entity,
                               javax.persistence.LockModeType lockMode)
Specified by:
lock in interface javax.persistence.EntityManager

merge

@Transactional
public <T> T merge(T entity)
Specified by:
merge in interface javax.persistence.EntityManager

persist

@Transactional
public void persist(java.lang.Object entity)
Specified by:
persist in interface javax.persistence.EntityManager

remove

@Transactional
public <T> T remove(java.lang.Class<T> clazz,
                                  java.lang.Object id)
Description copied from interface: ExtendedEntityManager
Removes a persistent instance

Specified by:
remove in interface ExtendedEntityManager
Type Parameters:
T - The persistent class
Parameters:
clazz - The persistent class
id - the primary key to remove
Returns:
the removed instance

remove

@Transactional
public void remove(java.lang.Object entity)
Specified by:
remove in interface javax.persistence.EntityManager

update

@Transactional
public int update(java.lang.String queryString,
                                java.lang.Object... params)
Description copied from interface: ExtendedEntityManager
Execute a query that updates the database.

Specified by:
update in interface ExtendedEntityManager
Parameters:
queryString - the update/delete/insert query to execute
params - the parameters to be added to the query, in order
Returns:
the number of records that were modified

clear

public void clear()
Specified by:
clear in interface javax.persistence.EntityManager

contains

public boolean contains(java.lang.Object entity)
Specified by:
contains in interface javax.persistence.EntityManager

evict

public void evict(java.lang.Object entity)
Description copied from interface: ExtendedEntityManager
Remove this instance from the session cache. Changes to the instance will not be synchronized with the database.

Specified by:
evict in interface ExtendedEntityManager
Parameters:
entity - a persistent instance

find

public <T> T find(java.lang.Class<T> entityClass,
                  java.lang.Object primaryKey)
Description copied from interface: ExtendedEntityManager
Retrieves a single persistent instance from the database

Specified by:
find in interface javax.persistence.EntityManager
Specified by:
find in interface ExtendedEntityManager
Type Parameters:
T - The class to retrieve
Parameters:
entityClass - The class to retrieve
primaryKey - The primary key to retrieve
Returns:
The retrieved object

find

public <T> java.util.List<T> find(java.lang.String queryString,
                                  java.lang.Object... params)
Description copied from interface: ExtendedEntityManager
Retrieves a non-paged query. Use with care, this method could potentially instantiate large amounts of data.

Specified by:
find in interface ExtendedEntityManager
Type Parameters:
T - The type of the result items
Parameters:
queryString - the query to execute
params - the parameters to be added to the query, in order
Returns:
The result of executing the query

findAll

public <T> java.util.List<T> findAll(java.lang.Class<T> clazz)
Description copied from interface: ExtendedEntityManager
Retrieves all records for a specified persistent class This method should be used with care, as it could instantiate huge amounts of data.

Specified by:
findAll in interface ExtendedEntityManager
Type Parameters:
T - The persistent class to retrieve
Parameters:
clazz - The persistent class to retrieve
Returns:
The list of all records found on the database

findNamed

public <T> java.util.List<T> findNamed(java.lang.String namedQuery,
                                       java.lang.Object... params)
Description copied from interface: ExtendedEntityManager
Retrieves a non-paged query This method should be used with care, as it could instantiate huge amounts of data.

Specified by:
findNamed in interface ExtendedEntityManager
Type Parameters:
T - The type of the result items
Parameters:
namedQuery - the named query to execute
params - the parameters to be added to the query, in order
Returns:
The result of executing the query

findNamedSingle

public <T> T findNamedSingle(java.lang.String namedQuery,
                             java.lang.Object... params)
Description copied from interface: ExtendedEntityManager
Execute a query that retrieves a single object. This method should be used with care, as it could instantiate huge amounts of data.

Specified by:
findNamedSingle in interface ExtendedEntityManager
Type Parameters:
T - The type of the result items
Parameters:
namedQuery - the named query to execute
params - the parameters to be added to the query, in order
Returns:
a single object that satisfies the named query.

findSingle

public <T> T findSingle(java.lang.String queryString,
                        java.lang.Object... params)
Specified by:
findSingle in interface ExtendedEntityManager
Parameters:
queryString - the query to execute
params - the parameters to be added to the query, in order
Returns:
a single object that satisfies the query.

getFlushMode

public javax.persistence.FlushModeType getFlushMode()
Specified by:
getFlushMode in interface javax.persistence.EntityManager

getIdPropertyName

public java.lang.String getIdPropertyName(java.lang.Class<?> clazz)
Specified by:
getIdPropertyName in interface ExtendedEntityManager
Parameters:
clazz - the persistent class
Returns:
the name of the id property of a persistent class

getReference

public <T> T getReference(java.lang.Class<T> entityClass,
                          java.lang.Object primaryKey)
Specified by:
getReference in interface javax.persistence.EntityManager

getDelegate

public java.lang.Object getDelegate()
Specified by:
getDelegate in interface javax.persistence.EntityManager

getVersionPropertyName

public java.lang.String getVersionPropertyName(java.lang.Class<?> clazz)
Specified by:
getVersionPropertyName in interface ExtendedEntityManager
Parameters:
clazz - the persistent class
Returns:
the version property name of a persistent class if it has defined one, null otherwise

getVersionValue

public <T> T getVersionValue(java.lang.Object entity)
Specified by:
getVersionValue in interface ExtendedEntityManager
Parameters:
entity - the persistent entity to inspect
Returns:
the version value of a persistent instance, or null if not versioned

query

public <T> PagedListData<T> query(PagedListCriteria criteria)
Description copied from interface: ExtendedEntityManager
Retrieve a paged query. The query can include a sorting order, which would then be appended to the sort indicated by the page object, if any.

Specified by:
query in interface ExtendedEntityManager
Type Parameters:
T - The type of the result items
Parameters:
criteria - The criteria of the paged query: page index, page size, sorting, etc.
Returns:
The paged result, sorted and paged according to the provided arguments.

refresh

public void refresh(java.lang.Object entity)
Specified by:
refresh in interface javax.persistence.EntityManager

setReadOnly

public void setReadOnly(java.lang.Object entity,
                        boolean readOnly)
Description copied from interface: ExtendedEntityManager
Sets an instance to readOnly. ReadOnly instances do not write any changes to the database when flushing.

Specified by:
setReadOnly in interface ExtendedEntityManager
Parameters:
entity - a persistent instance
readOnly - true to set the entity to readOnly

setEntityManager

public void setEntityManager(ExtendedEntityManager entityManager)

createNamedQuery

public javax.persistence.Query createNamedQuery(java.lang.String name)
Specified by:
createNamedQuery in interface javax.persistence.EntityManager

createNativeQuery

public javax.persistence.Query createNativeQuery(java.lang.String sqlString,
                                                 java.lang.Class resultClass)
Specified by:
createNativeQuery in interface javax.persistence.EntityManager

createNativeQuery

public javax.persistence.Query createNativeQuery(java.lang.String sqlString,
                                                 java.lang.String resultSetMapping)
Specified by:
createNativeQuery in interface javax.persistence.EntityManager

createNativeQuery

public javax.persistence.Query createNativeQuery(java.lang.String sqlString)
Specified by:
createNativeQuery in interface javax.persistence.EntityManager

createQuery

public javax.persistence.Query createQuery(java.lang.String qlString)
Specified by:
createQuery in interface javax.persistence.EntityManager

getTransaction

public javax.persistence.EntityTransaction getTransaction()
Specified by:
getTransaction in interface javax.persistence.EntityManager

close

public void close()
Specified by:
close in interface javax.persistence.EntityManager

setFlushMode

public void setFlushMode(javax.persistence.FlushModeType flushMode)
Specified by:
setFlushMode in interface javax.persistence.EntityManager

isOpen

public boolean isOpen()
Specified by:
isOpen in interface javax.persistence.EntityManager

joinTransaction

public void joinTransaction()
Specified by:
joinTransaction in interface javax.persistence.EntityManager