org.azzyzt.jee.runtime.eao
Class EaoBase

java.lang.Object
  extended by org.azzyzt.jee.runtime.eao.EaoBase

public abstract class EaoBase
extends java.lang.Object

The abstract base class of the generated generic entity access objects. The generated generic EAO is a stateless session bean, and its only purpose is to be a target for injection. All interaction with JPA happens here.


Constructor Summary
EaoBase()
           
 
Method Summary
<I,T extends EntityBase<I>>
java.util.List<T>
all(java.lang.Class<T> clazz)
          Returns all entities of a certain class
<I,T extends EntityBase<I>>
java.util.List<T>
allOrdered(java.lang.Class<T> clazz, OrderByClause orderBy)
          Returns all entities of a certain class, ordered according to an OrderByClause.
<I,T extends EntityBase<I>>
void
delete(java.lang.Class<T> clazz, I id)
          Deletes an entity of a given class and ID.
 void delete(java.lang.Object id, java.lang.Class<?> clazz)
          Another version needed in cases when we are definite about the classes, but have no way to prove it to the compiler.
<I,T extends EntityBase<I>>
void
deleteByName(java.lang.Class<T> clazz, java.lang.String nameWc)
          Deletes all entities with a name matching a certain wildcard.
<I,T extends EntityBase<I>>
T
findOrCreate(java.lang.Class<T> clazz, I id)
          Fetches an entity by ID or, if it does not exist, creates it.
<I,T extends EntityBase<I>>
T
findOrFail(java.lang.Class<T> clazz, I id)
          Fetches an entity by ID or, if it does not exist, fails with an exception.
 java.lang.Object findOrFail(java.lang.Object id, java.lang.Class<?> clazz)
          A raw version of findOrFail(Class, Object) needed in cases when we are definite about the classes, but have no way to prove it to the compiler.
<I,T extends EntityBase<I>>
T
findOrInvalidId(java.lang.Class<T> clazz, I id)
          Fetches an entity by ID or, if the ID is invalid or null, fails.
<I,T extends EntityBase<I>>
T
findOrNull(java.lang.Class<T> clazz, I id)
          Fetches an entity by ID or, if not found, returns null.
 void flush()
           
abstract  javax.persistence.EntityManager getEm()
          The EntityManager is injected into the concrete generated child class.
<I,T extends EntityBase<I>>
java.util.List<T>
list(QuerySpec qs, java.lang.Class<T> clazz, TypeMetaInfoInterface tmi)
          Returns the result of a typed query.
<I,T extends EntityBase<I>>
void
persist(T entity)
          Stores an entity.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EaoBase

public EaoBase()
Method Detail

getEm

public abstract javax.persistence.EntityManager getEm()
The EntityManager is injected into the concrete generated child class. This abstract method lets the generic methods access the persistence context.

Returns:
the EntityManager

flush

public void flush()

findOrFail

public <I,T extends EntityBase<I>> T findOrFail(java.lang.Class<T> clazz,
                                                I id)
                                   throws EntityNotFoundException
Fetches an entity by ID or, if it does not exist, fails with an exception.

Parameters:
clazz - an entity class
id - the ID of an entity
Returns:
the entity
Throws:
EntityNotFoundException

findOrFail

public java.lang.Object findOrFail(java.lang.Object id,
                                   java.lang.Class<?> clazz)
                            throws EntityNotFoundException
A raw version of findOrFail(Class, Object) needed in cases when we are definite about the classes, but have no way to prove it to the compiler. Used for the "delete" part of "storeDelete()". Order changed because of otherwise identical erasure.

Parameters:
clazz - an entity class
id - the ID of an entity
Returns:
the entity
Throws:
EntityNotFoundException

findOrCreate

public <I,T extends EntityBase<I>> T findOrCreate(java.lang.Class<T> clazz,
                                                  I id)
                                     throws EntityNotFoundException,
                                            EntityInstantiationException
Fetches an entity by ID or, if it does not exist, creates it.

Parameters:
clazz - an entity class
id - the ID of an entity
Returns:
the entity
Throws:
EntityNotFoundException
EntityInstantiationException

findOrInvalidId

public <I,T extends EntityBase<I>> T findOrInvalidId(java.lang.Class<T> clazz,
                                                     I id)
                                        throws EntityNotFoundException,
                                               InvalidIdException
Fetches an entity by ID or, if the ID is invalid or null, fails.

Parameters:
clazz - an entity class
id - the ID of an entity
Returns:
the entity
Throws:
EntityNotFoundException
InvalidIdException

findOrNull

public <I,T extends EntityBase<I>> T findOrNull(java.lang.Class<T> clazz,
                                                I id)
                                   throws InvalidIdException
Fetches an entity by ID or, if not found, returns null.

Parameters:
clazz - an entity class
id - the ID of an entity
Returns:
the entity or null
Throws:
InvalidIdException

persist

public <I,T extends EntityBase<I>> void persist(T entity)
Stores an entity.

Parameters:
entity - the entity

delete

public <I,T extends EntityBase<I>> void delete(java.lang.Class<T> clazz,
                                               I id)
            throws EntityNotFoundException
Deletes an entity of a given class and ID.

Parameters:
clazz - an entity class
id - the ID of an entity
Throws:
EntityNotFoundException

delete

public void delete(java.lang.Object id,
                   java.lang.Class<?> clazz)
            throws EntityNotFoundException
Another version needed in cases when we are definite about the classes, but have no way to prove it to the compiler. Used for the "delete" part of "storeDelete()". Order changed because of otherwise identical erasure.

Parameters:
id - the ID of an entity
clazz - an entity class
Throws:
EntityNotFoundException

deleteByName

public <I,T extends EntityBase<I>> void deleteByName(java.lang.Class<T> clazz,
                                                     java.lang.String nameWc)
Deletes all entities with a name matching a certain wildcard.

Parameters:
clazz - an entity class
nameWc - a name wildcard string

all

public <I,T extends EntityBase<I>> java.util.List<T> all(java.lang.Class<T> clazz)
Returns all entities of a certain class

Parameters:
clazz - an entity class
Returns:
a list of entities

list

public <I,T extends EntityBase<I>> java.util.List<T> list(QuerySpec qs,
                                                          java.lang.Class<T> clazz,
                                                          TypeMetaInfoInterface tmi)
                                             throws InvalidFieldException,
                                                    AccessDeniedException,
                                                    QuerySyntaxException,
                                                    NotYetImplementedException
Returns the result of a typed query. The query is built by a QueryBuilder from a QuerySpec.

Parameters:
qs - a query specification
clazz - an entity class
tmi - type meta information generated by Azzyzt JEE Tools
Returns:
Throws:
InvalidFieldException
AccessDeniedException
QuerySyntaxException
NotYetImplementedException

allOrdered

public <I,T extends EntityBase<I>> java.util.List<T> allOrdered(java.lang.Class<T> clazz,
                                                                OrderByClause orderBy)
Returns all entities of a certain class, ordered according to an OrderByClause.

Parameters:
clazz - an entity class
orderBy - an OrderByClause
Returns:
an ordered list of all entities of the given class