org.jtheque.core.managers.persistence
Class GenericDao<T extends Entity>

java.lang.Object
  extended by org.jtheque.core.managers.persistence.GenericDao<T>
Type Parameters:
T - The class managed by the dao.
All Implemented Interfaces:
JThequeDao

public abstract class GenericDao<T extends Entity>
extends java.lang.Object
implements JThequeDao

A generic data access object.

Author:
Baptiste Wicht

Constructor Summary
GenericDao(java.lang.String table)
          Construct a new GenericDao.
 
Method Summary
 void addDataListener(DataListener listener)
          Add a data listener to dao.
 void clearAll()
          Delete all the entities.
 void create(T entity)
          Create the entity.
 boolean delete(int id)
          Delete the entity with the specified ID.
 boolean delete(T entity)
          Delete the entity.
 T get(int id)
          Return the entity of a specific id.
 java.util.List<T> getAll()
          Return all the entity managed by this dao.
protected  java.util.Map<java.lang.Integer,T> getCache()
          Return the cache of the DAO.
 java.util.List<T> getDatas()
          Return all the datas of the Dao.
protected abstract  QueryMapper getQueryMapper()
          Return the query mapper for the DAO.
protected abstract  org.springframework.jdbc.core.simple.ParameterizedRowMapper<T> getRowMapper()
          Return the row mapper for the DAO.
 boolean isNotInCache(int i)
          Indicate if the entity with the ID is in cache.
protected  void load()
          Load the DAO.
protected abstract  void load(int i)
          Load the entity.
protected abstract  void loadCache()
          Load the cache.
 void removeDataListener(DataListener listener)
          Remove a data listener from the dao.
 void save(T entity)
          Save the entity.
 void setCacheEntirelyLoaded(boolean cacheEntirelyLoaded)
          Set if the cache has been entirely loaded or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericDao

public GenericDao(java.lang.String table)
Construct a new GenericDao.

Parameters:
table - The database Table.
Method Detail

getAll

public final java.util.List<T> getAll()
Return all the entity managed by this dao.

Returns:
A List containing all the entities managed by the dao.

getCache

protected final java.util.Map<java.lang.Integer,T> getCache()
Return the cache of the DAO.

Returns:
The cache of the DAO.

load

protected final void load()
Load the DAO.


loadCache

protected abstract void loadCache()
Load the cache.


load

protected abstract void load(int i)
Load the entity.

Parameters:
i - The ID of the entity.

getRowMapper

protected abstract org.springframework.jdbc.core.simple.ParameterizedRowMapper<T> getRowMapper()
Return the row mapper for the DAO.

Returns:
The row mapper for the DAO.

getQueryMapper

protected abstract QueryMapper getQueryMapper()
Return the query mapper for the DAO.

Returns:
The query mapper for the DAO.

get

public final T get(int id)
Return the entity of a specific id.

Parameters:
id - The id for which we search the entity.
Returns:
The Entity.

getDatas

public final java.util.List<T> getDatas()
Description copied from interface: JThequeDao
Return all the datas of the Dao.

Specified by:
getDatas in interface JThequeDao
Returns:
A colleciton of all the datas contained on the dao.

create

public void create(T entity)
Create the entity.

Parameters:
entity - The entity to create.

save

public void save(T entity)
Save the entity.

Parameters:
entity - The entity to save.

delete

public boolean delete(T entity)
Delete the entity.

Parameters:
entity - The entity to delete.
Returns:
true if the object is deleted else false.

delete

public boolean delete(int id)
Delete the entity with the specified ID.

Parameters:
id - The id of the entity to delete.
Returns:
true if the entity has been deleted else false.

clearAll

public final void clearAll()
Delete all the entities.

Specified by:
clearAll in interface JThequeDao

isNotInCache

public final boolean isNotInCache(int i)
Indicate if the entity with the ID is in cache.

Parameters:
i - The ID of the entity.
Returns:
true if an entity with the ID is in cache.

setCacheEntirelyLoaded

public final void setCacheEntirelyLoaded(boolean cacheEntirelyLoaded)
Set if the cache has been entirely loaded or not.

Parameters:
cacheEntirelyLoaded - A boolean flag indicating if the cache is entirely loaded or not.

addDataListener

public final void addDataListener(DataListener listener)
Description copied from interface: JThequeDao
Add a data listener to dao.

Specified by:
addDataListener in interface JThequeDao
Parameters:
listener - The listener to add.

removeDataListener

public final void removeDataListener(DataListener listener)
Description copied from interface: JThequeDao
Remove a data listener from the dao.

Specified by:
removeDataListener in interface JThequeDao
Parameters:
listener - The listener to remove.


Copyright © 2009 JTheque. All Rights Reserved.