public abstract class DAO<E extends Entity,D extends DAO<E,D>> extends Object
Usually an instance of a DAO is obtained using
LocalRepoTransaction.getDAO(...).
| Constructor and Description |
|---|
DAO()
Instantiate the DAO.
|
| Modifier and Type | Method and Description |
|---|---|
void |
deletePersistent(E entity) |
void |
deletePersistentAll(Collection<? extends E> entities) |
protected <T extends DAO<?,?>> |
getDAO(Class<T> daoClass) |
Class<E> |
getEntityClass()
Get the type of the entity.
|
E |
getObjectByIdOrFail(long id)
Get the entity-instance referenced by the specified identifier.
|
E |
getObjectByIdOrNull(long id)
Get the entity-instance referenced by the specified identifier.
|
Collection<E> |
getObjects() |
long |
getObjectsCount() |
PersistenceManager |
getPersistenceManager()
Gets the
PersistenceManager assigned to this DAO. |
protected Collection<E> |
load(Collection<E> entities) |
<P extends E> |
makePersistent(P entity) |
D |
persistenceManager(PersistenceManager persistenceManager)
Assigns the given
PersistenceManager to this DAO and returns this. |
protected PersistenceManager |
pm() |
void |
setPersistenceManager(PersistenceManager persistenceManager)
Assigns the given
PersistenceManager to this DAO. |
protected D |
thisDAO() |
public DAO()
It is recommended not to invoke this constructor directly, but instead use
LocalRepoTransaction.getDAO(...),
if a LocalRepoTransaction is available (which should be in most situations).
After constructing, you must assign a PersistenceManager,
before you can use the DAO. This is already done when using the LocalRepoTransaction's factory method.
public PersistenceManager getPersistenceManager()
PersistenceManager assigned to this DAO.PersistenceManager assigned to this DAO. May be null, if none
was assigned, yet.setPersistenceManager(PersistenceManager),
persistenceManager(PersistenceManager)public void setPersistenceManager(PersistenceManager persistenceManager)
PersistenceManager to this DAO.
The DAO cannot be used, before a non-null value was set using this method.
persistenceManager - the PersistenceManager to be used by this DAO. May be null,
but a non-null value must be set to make this DAO usable.persistenceManager(PersistenceManager)protected PersistenceManager pm()
public D persistenceManager(PersistenceManager persistenceManager)
PersistenceManager to this DAO and returns this.
This method delegates to setPersistenceManager(PersistenceManager).
persistenceManager - the PersistenceManager to be used by this DAO. May be null,
but a non-null value must be set to make this DAO usable.this for a fluent API.setPersistenceManager(PersistenceManager)public Class<E> getEntityClass()
null.public E getObjectByIdOrFail(long id) throws JDOObjectNotFoundException
id - the identifier referencing the desired entity. Must not be null.null.JDOObjectNotFoundException - if the entity referenced by the given identifier does not exist.public E getObjectByIdOrNull(long id)
id - the identifier referencing the desired entity. Must not be null.null, if no
such entity exists.public Collection<E> getObjects()
public long getObjectsCount()
public <P extends E> P makePersistent(P entity)
public void deletePersistent(E entity)
public void deletePersistentAll(Collection<? extends E> entities)
protected Collection<E> load(Collection<E> entities)
Copyright © 2013-2014. All Rights Reserved.