public abstract class Dao<E extends Entity,D extends Dao<E,D>> extends Object implements ContextWithPersistenceManager
Usually an instance of a Dao is obtained using
LocalRepoTransaction.getDao(...)
.
Modifier and Type | Class and Description |
---|---|
protected static class |
Dao.IdRange |
Constructor and Description |
---|
Dao()
Instantiate the Dao.
|
Modifier and Type | Method and Description |
---|---|
protected String |
buildIdRangePackageFilter(int idRangePackageSize) |
protected Map<String,Object> |
buildIdRangePackageQueryMap(List<Dao.IdRange> idRangePackage)
Build the query-argument-map corresponding to
#buildIdRangePackageFilter() . |
protected static List<List<Dao.IdRange>> |
buildIdRangePackages(SortedSet<Long> entityIds)
Organise the given entity-IDs in
Dao.IdRange s, which itself are grouped into packages. |
protected static List<List<Dao.IdRange>> |
buildIdRangePackages(SortedSet<Long> entityIds,
int idRangePackageSize)
Deprecated.
Only used for junit-test! Use
buildIdRangePackages(SortedSet) instead! Don't use this method directly! |
protected void |
clearFetchGroups() |
void |
deletePersistent(E entity) |
void |
deletePersistentAll(Collection<? extends E> entities) |
protected <T extends Dao<?,?>> |
getDao(Class<T> daoClass) |
DaoProvider |
getDaoProvider() |
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) |
protected <T> List<T> |
loadDtos(Collection<E> entities,
Class<T> dtoClass,
String queryResult) |
<P extends E> |
makePersistent(P entity) |
D |
persistenceManager(PersistenceManager persistenceManager)
Assigns the given
PersistenceManager to this Dao and returns this . |
protected PersistenceManager |
pm() |
void |
setDaoProvider(DaoProvider daoProvider) |
void |
setPersistenceManager(PersistenceManager persistenceManager)
Assigns the given
PersistenceManager to this Dao. |
protected static int |
shrinkIdRangePackageSizeIfPossible(List<List<Dao.IdRange>> idRangePackages) |
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.getPersistenceManager
in interface ContextWithPersistenceManager
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 DaoProvider getDaoProvider()
public void setDaoProvider(DaoProvider daoProvider)
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)
protected <T> List<T> loadDtos(Collection<E> entities, Class<T> dtoClass, String queryResult)
protected static int shrinkIdRangePackageSizeIfPossible(List<List<Dao.IdRange>> idRangePackages)
protected String buildIdRangePackageFilter(int idRangePackageSize)
protected Map<String,Object> buildIdRangePackageQueryMap(List<Dao.IdRange> idRangePackage)
#buildIdRangePackageFilter()
.idRangePackage
- the id-range-package for which to build the argument-map. Never null
.Query.executeWithMap(Map)
. Never null
.protected static List<List<Dao.IdRange>> buildIdRangePackages(SortedSet<Long> entityIds)
Dao.IdRange
s, which itself are grouped into packages.
Each package, i.e. each element in the returned main List
has a fixed size of
elements.
entityIds
- entity-IDs to be organised in ranges. Must not be null
.null
.@Deprecated protected static List<List<Dao.IdRange>> buildIdRangePackages(SortedSet<Long> entityIds, int idRangePackageSize)
buildIdRangePackages(SortedSet)
instead! Don't use this method directly!protected void clearFetchGroups()
Copyright © 2013–2019. All rights reserved.