se.vgregion.dao.domain.patterns.repository.db.jpa
Class AbstractJpaRepository<T extends Entity<T,ID>,ID extends Serializable,PK extends Serializable>

java.lang.Object
  extended by se.vgregion.dao.domain.patterns.repository.db.jpa.AbstractJpaRepository<T,ID,PK>
Type Parameters:
T - The Entity Type
ID - The ID of the Entity
PK - The type of the primary key
All Implemented Interfaces:
DatabaseRepository<T,ID,PK>, JpaRepository<T,ID,PK>, Repository<T,ID>
Direct Known Subclasses:
DefaultJpaRepository

public abstract class AbstractJpaRepository<T extends Entity<T,ID>,ID extends Serializable,PK extends Serializable>
extends Object
implements JpaRepository<T,ID,PK>

An abstract default implementation of a DatabaseRepository. This is an JPA implementation used with any JPA implementation such as Hibernate.

Author:
Anders Asplund - Callista Enterprise

Field Summary
protected  javax.persistence.EntityManager entityManager
          Entity manager ref.
protected  Class<T> type
          Entity class type.
 
Constructor Summary
AbstractJpaRepository()
          Default constructor.
AbstractJpaRepository(Class<T> type)
          Parameterized constructor.
 
Method Summary
 void clear()
          Clear the persistence context, causing all managed entities to become detached.
 boolean contains(T entity)
          Does entity manager contain entity?
 T find(ID id)
          
 List<T> findAll()
          
 List<T> findByNamedQuery(String queryName, Map<String,? extends Object> args)
          Find instances of T that match the criteria defined by query queryName.
 List<T> findByNamedQuery(String queryName, Object[] args)
          Find instances of T that match the criteria defined by query queryName.
 T findByPrimaryKey(PK pk)
          
 T findInstanceByNamedQuery(String queryName, Map<String,? extends Object> args)
          Find a single instance of T using the query named queryName and the arguments identified by args.
 T findInstanceByNamedQuery(String queryName, Object[] args)
          Find a single instance of T using the query named queryName and the arguments identified by args.
 void flush()
          
 T merge(T entity)
          
 T persist(T entity)
          
 void refresh(T entity)
          
 void remove(ID id)
          
 void remove(T entity)
          
 void removeByPrimaryKey(PK pk)
          
 void setType(Class<T> type)
           
 T store(T entity)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entityManager

protected javax.persistence.EntityManager entityManager
Entity manager ref.


type

protected Class<T extends Entity<T,ID>> type
Entity class type.

Constructor Detail

AbstractJpaRepository

public AbstractJpaRepository()
Default constructor.


AbstractJpaRepository

public AbstractJpaRepository(Class<T> type)
Parameterized constructor.

Parameters:
type - Entity class type
Method Detail

setType

public void setType(Class<T> type)

contains

@Transactional(propagation=SUPPORTS,
               readOnly=true)
public boolean contains(T entity)
Does entity manager contain entity?

Specified by:
contains in interface Repository<T extends Entity<T,ID>,ID extends Serializable>
Parameters:
entity - Entity to check for
Returns:
true if found

findAll

@Transactional(propagation=SUPPORTS,
               readOnly=true)
public List<T> findAll()

Specified by:
findAll in interface Repository<T extends Entity<T,ID>,ID extends Serializable>

findByNamedQuery

@Transactional(propagation=SUPPORTS,
               readOnly=true)
public List<T> findByNamedQuery(String queryName,
                                                                         Map<String,? extends Object> args)
Find instances of T that match the criteria defined by query queryName. args provide the values for any named parameters in the query identified by queryName.

Specified by:
findByNamedQuery in interface JpaRepository<T extends Entity<T,ID>,ID extends Serializable,PK extends Serializable>
Parameters:
queryName - the named query to execute
args - the values used by the query
Returns:
a list of T objects

findByNamedQuery

@Transactional(propagation=SUPPORTS,
               readOnly=true)
public List<T> findByNamedQuery(String queryName,
                                                                         Object[] args)
Find instances of T that match the criteria defined by query queryName. args provide values for positional arguments in the query identified by queryName.

Specified by:
findByNamedQuery in interface JpaRepository<T extends Entity<T,ID>,ID extends Serializable,PK extends Serializable>
Parameters:
queryName - the named query to execute
args - the positional values used in the query
Returns:
a list of T objects

findInstanceByNamedQuery

@Transactional(propagation=SUPPORTS,
               readOnly=true)
public T findInstanceByNamedQuery(String queryName,
                                                                           Object[] args)
Find a single instance of T using the query named queryName and the arguments identified by args.

Specified by:
findInstanceByNamedQuery in interface JpaRepository<T extends Entity<T,ID>,ID extends Serializable,PK extends Serializable>
Parameters:
queryName - the name of the query to use
args - the arguments for the named query
Returns:
T or null if no objects match the criteria if more than one instance is returned.

findInstanceByNamedQuery

@Transactional(propagation=SUPPORTS,
               readOnly=true)
public T findInstanceByNamedQuery(String queryName,
                                                                           Map<String,? extends Object> args)
Find a single instance of T using the query named queryName and the arguments identified by args.

Specified by:
findInstanceByNamedQuery in interface JpaRepository<T extends Entity<T,ID>,ID extends Serializable,PK extends Serializable>
Parameters:
queryName - the name of the query to use
args - a Map holding the named parameters of the query
Returns:
T or null if no objects match the criteria if more than one instance is returned.

find

@Transactional(propagation=SUPPORTS,
               readOnly=true)
public T find(ID id)

Specified by:
find in interface Repository<T extends Entity<T,ID>,ID extends Serializable>

findByPrimaryKey

@Transactional(propagation=SUPPORTS,
               readOnly=true)
public T findByPrimaryKey(PK pk)

Specified by:
findByPrimaryKey in interface DatabaseRepository<T extends Entity<T,ID>,ID extends Serializable,PK extends Serializable>

flush

@Transactional(propagation=MANDATORY)
public void flush()

Specified by:
flush in interface Repository<T extends Entity<T,ID>,ID extends Serializable>
Throws:
{@link - IllegalTransactionStateException} if the method is invoked without an existing transaction.

persist

@Transactional(propagation=MANDATORY)
public T persist(T entity)

Specified by:
persist in interface Repository<T extends Entity<T,ID>,ID extends Serializable>
Throws:
{@link - IllegalTransactionStateException} if the method is invoked without an existing transaction.

clear

@Transactional(propagation=SUPPORTS,
               readOnly=true)
public void clear()
Clear the persistence context, causing all managed entities to become detached. Changes made to entities that have not been flushed to the storage will not be persisted.

Specified by:
clear in interface JpaRepository<T extends Entity<T,ID>,ID extends Serializable,PK extends Serializable>
Throws:
{@link - IllegalTransactionStateException} if the method is invoked without an existing transaction.

remove

@Transactional(propagation=MANDATORY)
public void remove(T entity)

Specified by:
remove in interface Repository<T extends Entity<T,ID>,ID extends Serializable>
Throws:
{@link - IllegalTransactionStateException} if the method is invoked without an existing transaction.

remove

@Transactional(propagation=MANDATORY)
public void remove(ID id)

Specified by:
remove in interface Repository<T extends Entity<T,ID>,ID extends Serializable>
Throws:
{@link - IllegalTransactionStateException} if the method is invoked without an existing transaction.

removeByPrimaryKey

@Transactional(propagation=MANDATORY)
public void removeByPrimaryKey(PK pk)

Specified by:
removeByPrimaryKey in interface DatabaseRepository<T extends Entity<T,ID>,ID extends Serializable,PK extends Serializable>
Throws:
{@link - IllegalTransactionStateException} if the method is invoked without an existing transaction.

merge

@Transactional(propagation=MANDATORY)
public T merge(T entity)

Specified by:
merge in interface Repository<T extends Entity<T,ID>,ID extends Serializable>
Throws:
{@link - IllegalTransactionStateException} if the method is invoked without an existing transaction.

store

@Transactional(propagation=MANDATORY)
public T store(T entity)

Specified by:
store in interface Repository<T extends Entity<T,ID>,ID extends Serializable>
Throws:
{@link - IllegalTransactionStateException} if the method is invoked without an existing transaction.

refresh

@Transactional(propagation=SUPPORTS,
               readOnly=true)
public void refresh(T entity)

Specified by:
refresh in interface Repository<T extends Entity<T,ID>,ID extends Serializable>


Copyright © 2010. All Rights Reserved.