|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.perfectjpattern.jee.integration.dao.JpaBaseDao<Id,Element>
public class JpaBaseDao<Id extends Serializable,Element>
Abstract reusable JPA partial implementation of IGenericReadOnlyDao
that provides automatic handling of EntityManager
within a
EJB container
Constructor Summary | |
---|---|
protected |
JpaBaseDao(Class<Element> aPersistentClass,
ISessionStrategy aSessionStrategy,
ITransactionStrategy aTransactionStrategy)
Constructs a HibernateGenericReadOnlyDao instance from the
persistent class type, the ISessionStrategy that creates
ISession instances and the ITransactionStrategy that
creates ITransaction instances |
Method Summary | |
---|---|
boolean |
contains(Element anElement)
Returns true if the specified Element exists in the persistent storage, false otherwise. |
int |
count()
Returns the total number of records. |
Id |
create(Element anElement)
Returns the ID of the newly created Element. |
boolean |
delete(Element anElement)
Returns true if the Element was deleted, false otherwise i.e. |
void |
deleteAll()
Deletes all Element from the persistent storage. |
List<Element> |
findAll()
Returns all Elements from the persistent storage. |
Element |
findById(Id anId)
Returns the Element matching the given ID. |
protected Class<Element> |
getPersistentClass()
Returns the persistentClass |
ISession |
getSession()
Returns the ISession adapted from the implementation-specific |
protected ISessionStrategy |
getSessionStrategy()
Returns the sessionStrategy |
ITransaction |
getTransaction()
Returns the ITransaction adapted from the implementation-specific |
protected ITransactionStrategy |
getTransactionStrategy()
Returns the transactionStrategy |
protected void |
setEntityManager(javax.persistence.EntityManager anEntityManager)
Sets the EntityManager , called from a managed EJB that exposes
IGenericReadOnlyDao or IGenericDao remotely. |
boolean |
update(Element anElement)
Returns true if the Element was updated, false otherwise i.e. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected JpaBaseDao(Class<Element> aPersistentClass, ISessionStrategy aSessionStrategy, ITransactionStrategy aTransactionStrategy) throws IllegalArgumentException
HibernateGenericReadOnlyDao
instance from the
persistent class type, the ISessionStrategy
that creates
ISession
instances and the ITransactionStrategy
that
creates ITransaction
instances
aPersistentClass
- The persistent Java Bean classaSessionStrategy
- Factory that creates SessionsaTransactionStrategy
- Factory that creates Transaction
IllegalArgumentException
Method Detail |
---|
public boolean contains(Element anElement) throws DaoException, IllegalArgumentException
contains
in interface IBaseReadOnlyDao<Id extends Serializable,Element>
anElement
- Element to find in this persistent storage.
DaoException
IllegalArgumentException
- 'anId' must not be null.public int count() throws DaoException
"SELECT * FROM ..."
. Noteworthy that every call to
this function will trigger a new execution of a statement. Therefore if
the count value is needed several times in the client code it is a good
idea to cache it there.
count
in interface IBaseReadOnlyDao<Id extends Serializable,Element>
DaoException
public Element findById(Id anId) throws DaoException, IllegalArgumentException
findById
in interface IBaseReadOnlyDao<Id extends Serializable,Element>
anId
- ID of the Element to retrieve.
DaoException
IllegalArgumentException
- 'anId' must not be null.public List<Element> findAll() throws DaoException
findAll
in interface IBaseReadOnlyDao<Id extends Serializable,Element>
DaoException
public Id create(Element anElement) throws DaoException, IllegalArgumentException
create
in interface IBaseDao<Id extends Serializable,Element>
anElement
- Element to create
DaoException
IllegalArgumentException
- 'anElement' must not be null.public boolean update(Element anElement) throws DaoException
update
in interface IBaseDao<Id extends Serializable,Element>
anElement
- Element to update
DaoException
public boolean delete(Element anElement) throws DaoException
delete
in interface IBaseDao<Id extends Serializable,Element>
anElement
- Element to delete
DaoException
public void deleteAll() throws DaoException
deleteAll
in interface IBaseDao<Id extends Serializable,Element>
DaoException
public ITransaction getTransaction()
ITransaction
adapted from the implementation-specific
getTransaction
in interface IBaseReadOnlyDao<Id extends Serializable,Element>
ITransaction
adapted from the implementation-specificIAdapter
public ISession getSession()
ISession
adapted from the implementation-specific
getSession
in interface IBaseReadOnlyDao<Id extends Serializable,Element>
ISession
adapted from the implementation-specificIAdapter
protected void setEntityManager(javax.persistence.EntityManager anEntityManager) throws IllegalArgumentException
EntityManager
, called from a managed EJB that exposes
IGenericReadOnlyDao
or IGenericDao
remotely.
anEntityManager
- The EntityManager
to set
IllegalArgumentException
- 'anEntityManager' must not be nullprotected final Class<Element> getPersistentClass()
protected final ISessionStrategy getSessionStrategy()
protected final ITransactionStrategy getTransactionStrategy()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |