org.nuiton.topia.persistence
Class TopiaDAOImpl<E extends TopiaEntity>

java.lang.Object
  extended by org.nuiton.topia.persistence.TopiaDAOImpl<E>
Type Parameters:
E - le type de l'entite
All Implemented Interfaces:
TopiaDAO<E>
Direct Known Subclasses:
TopiaDAOLegacy

public class TopiaDAOImpl<E extends TopiaEntity>
extends java.lang.Object
implements TopiaDAO<E>

TODO-fdesbois-20100508 : Need translation of javadoc.

Cette classe permet d'avoir un ensemble de méthode implantée de façon standard et plus spécifiquement pour Hibernate.

Certains accès à Hibernate sont tout de même fait ici, car on a pris le choix de se baser entièrement sur hibernate pour la persistence, et il est ainsi possible d'accèder au meta information hibernate sur les classes lorque l'on en a besoin.

Version:
$Id: TopiaDAOImpl.java 2055 2010-07-09 14:01:56Z fdesbois $
Author:
poussin

Field Summary
protected  TopiaContextImplementor context
           
protected  java.lang.Class<E> entityClass
           
 
Constructor Summary
TopiaDAOImpl()
           
 
Method Summary
 void addTopiaEntityListener(TopiaEntityListener listener)
           
 void addTopiaEntityVetoable(TopiaEntityVetoable vetoable)
           
 int count()
          Count the number of existing entities.
 int countByQuery(TopiaQuery query)
          Count the number of entities based on query.
 E create(E entity)
          Permet de sauver un object instancié sans le DAO.
 E create(java.util.Map<java.lang.String,java.lang.Object> properties)
          Cette methode appelle fireVetoableCreate et fireOnCreated Si vous la surchargé, faites attention a appeler le super ou a appeler vous aussi ces deux methodes.
 E create(java.lang.Object... properties)
          Construit une nouvelle instance de l'objet géré par ce DAO
 TopiaQuery createQuery()
          Crée une requete basé sur l'entité lié au DAO.
 TopiaQuery createQuery(java.lang.String entityAlias)
          Crée une requête basé sur l'entité lié au DAO et lui assigne un alias valable dans la requête..
 void delete(E e)
          Permet de supprimer une entite.
 boolean existByProperties(java.lang.String propertyName, java.lang.Object propertyValue, java.lang.Object... others)
          Check the existence of an entity with propertyName with propertyValue.
 boolean existByQuery(TopiaQuery query)
          Check the existence of an entity using a query.
 boolean existByTopiaId(java.lang.String id)
          Check the existence of an entity with technical id.
 java.util.List<E> findAll()
           
 java.util.List<E> findAllByProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
           
 java.util.List<E> findAllByProperties(java.lang.String propertyName, java.lang.Object value, java.lang.Object... others)
           
 java.util.List<E> findAllByProperty(java.lang.String propertyName, java.lang.Object value)
           
 java.util.List<E> findAllByQuery(TopiaQuery query)
          Execute une requête basé sur l'entité du DAO.
 java.util.List<java.lang.String> findAllIds()
          Recuperation de tous les ids en base pour le type d'entite du dao.
 java.util.Map<java.lang.String,E> findAllMappedByQuery(TopiaQuery query)
          Execute une requête basé sur l'entité du DAO.
<K> java.util.Map<K,E>
findAllMappedByQuery(TopiaQuery query, java.lang.String keyName, java.lang.Class<K> keyClass)
          Execute une requête basé sur l'entité du DAO.
 java.util.Map<java.lang.Class<? extends TopiaEntity>,java.util.List<? extends TopiaEntity>> findAllUsages(E e)
          Find all usages of the given entity.
 java.util.List<E> findAllWithOrder(java.lang.String... propertyNames)
           
 E findByPrimaryKey(java.util.Map<java.lang.String,java.lang.Object> keys)
          Recherche la classe en utilisant la cle naturelle, chaque champs de la cle naturelle est une entre de la map passe en argument.
 E findByPrimaryKey(java.lang.Object... k)
          Recherche la classe en utilisant la cle naturelle, si la cle naturelle est composé de plusieurs champs alors les arguments passés doivent être dans l'ordre de declaration dans le fichier de mapping
 E findByProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
           
 E findByProperties(java.lang.String propertyName, java.lang.Object value, java.lang.Object... others)
           
 E findByProperty(java.lang.String propertyName, java.lang.Object value)
           
 E findByQuery(TopiaQuery query)
          Execute une requête basé sur l'entité du DAO.
 E findByTopiaId(java.lang.String id)
          Find an entity corresponding to the id.
<U extends TopiaEntity>
java.util.List<U>
findUsages(java.lang.Class<U> type, E e)
          Find usages of the given entity in the entities of the given type.
 TopiaContextImplementor getContext()
          Return context used by this DAO.
 java.lang.Class<E> getEntityClass()
          Return class of entity managed by this DAO.
protected  java.io.Serializable getId(E e)
          Retourne l'id de l'entity
protected  java.io.Serializable getId(java.util.Map map)
          Retourne l'id de l'entity representer comme une map
 java.util.List<java.security.Permission> getRequestPermission(java.lang.String topiaId, int actions)
          Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas.
 void init(TopiaContextImplementor context, java.lang.Class<E> entityClass)
          When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just after.
 E newInstance()
          Create a new instance of managed entity.
 void removeTopiaEntityListener(TopiaEntityListener listener)
           
 void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable)
           
 long size()
          Deprecated. since 2.3.4 ambiguous name, use count() instead.
 E update(E e)
          Permet d'ajouter ou de mettre a jour un objet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entityClass

protected java.lang.Class<E extends TopiaEntity> entityClass

context

protected TopiaContextImplementor context
Constructor Detail

TopiaDAOImpl

public TopiaDAOImpl()
Method Detail

getEntityClass

public java.lang.Class<E> getEntityClass()
Description copied from interface: TopiaDAO
Return class of entity managed by this DAO.

Specified by:
getEntityClass in interface TopiaDAO<E extends TopiaEntity>
Returns:
entity managed by this DAO

getId

protected java.io.Serializable getId(E e)
                              throws TopiaException
Retourne l'id de l'entity

Parameters:
e - l'entity
Returns:
l'id de l'entity ou null si pas trouvé
Throws:
TopiaException - Si une erreur survient durant la recherche

getId

protected java.io.Serializable getId(java.util.Map map)
                              throws TopiaException
Retourne l'id de l'entity representer comme une map

Parameters:
map - l'entity en representation map
Returns:
l'id de l'entity ou null si pas trouvé
Throws:
TopiaException - Si une erreur survient durant la recherche

init

public void init(TopiaContextImplementor context,
                 java.lang.Class<E> entityClass)
          throws TopiaException
When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just after.

Specified by:
init in interface TopiaDAO<E extends TopiaEntity>
Parameters:
entityClass -
context - context
Throws:
TopiaException - if any pb while init

getContext

public TopiaContextImplementor getContext()
Description copied from interface: TopiaDAO
Return context used by this DAO.

Specified by:
getContext in interface TopiaDAO<E extends TopiaEntity>
Returns:
Returns the context.

newInstance

public E newInstance()
                                  throws TopiaException
Description copied from interface: TopiaDAO
Create a new instance of managed entity.

Specified by:
newInstance in interface TopiaDAO<E extends TopiaEntity>
Returns:
new entity instance
Throws:
TopiaException - if any pb while creating the entitie

findUsages

public <U extends TopiaEntity> java.util.List<U> findUsages(java.lang.Class<U> type,
                                                            E e)
                                                 throws TopiaException
Description copied from interface: TopiaDAO
Find usages of the given entity in the entities of the given type.

Specified by:
findUsages in interface TopiaDAO<E extends TopiaEntity>
Type Parameters:
U - tthe type of entity to search
Parameters:
type - the type of entity to search
e - the entity
Returns:
the list of entities of the given type which uses the given entity
Throws:
TopiaException - if any problem while getting data

findAllUsages

public java.util.Map<java.lang.Class<? extends TopiaEntity>,java.util.List<? extends TopiaEntity>> findAllUsages(E e)
                                                                                                          throws TopiaException
Description copied from interface: TopiaDAO
Find all usages of the given entity.

Specified by:
findAllUsages in interface TopiaDAO<E extends TopiaEntity>
Parameters:
e - the entity
Returns:
the dictionnary of usages of the given entities (keys are entity usage container, values are the list of this type of entity to use the given entity).
Throws:
TopiaException - if any pb while getting data

getRequestPermission

public java.util.List<java.security.Permission> getRequestPermission(java.lang.String topiaId,
                                                                     int actions)
                                                              throws TopiaException
Description copied from interface: TopiaDAO
Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas.

Specified by:
getRequestPermission in interface TopiaDAO<E extends TopiaEntity>
Parameters:
topiaId - topiaId d'une entite
actions - encoded actions
Returns:
la liste des permissions
Throws:
TopiaException - if any pb while getting datas

addTopiaEntityListener

public void addTopiaEntityListener(TopiaEntityListener listener)
Specified by:
addTopiaEntityListener in interface TopiaDAO<E extends TopiaEntity>

addTopiaEntityVetoable

public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable)
Specified by:
addTopiaEntityVetoable in interface TopiaDAO<E extends TopiaEntity>

removeTopiaEntityListener

public void removeTopiaEntityListener(TopiaEntityListener listener)
Specified by:
removeTopiaEntityListener in interface TopiaDAO<E extends TopiaEntity>

removeTopiaEntityVetoable

public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable)
Specified by:
removeTopiaEntityVetoable in interface TopiaDAO<E extends TopiaEntity>

create

public E create(E entity)
                             throws TopiaException
Description copied from interface: TopiaDAO
Permet de sauver un object instancié sans le DAO.

Specified by:
create in interface TopiaDAO<E extends TopiaEntity>
Parameters:
entity - l'entité instanciée à sauver
Returns:
l'entité avec son topiaID valorisé
Throws:
TopiaException - if any pb while creating datas

create

public E create(java.lang.Object... properties)
                             throws TopiaException
Description copied from interface: TopiaDAO
Construit une nouvelle instance de l'objet géré par ce DAO

Specified by:
create in interface TopiaDAO<E extends TopiaEntity>
Parameters:
properties - la liste des propriétés que doit avoir l'objet créé les arguments vont par paire (propertyName, value)
Returns:
un nouvel objet
Throws:
TopiaException - si un problème est rencontré durant l'instanciation

create

public E create(java.util.Map<java.lang.String,java.lang.Object> properties)
                             throws TopiaException
Cette methode appelle fireVetoableCreate et fireOnCreated Si vous la surchargé, faites attention a appeler le super ou a appeler vous aussi ces deux methodes.

Specified by:
create in interface TopiaDAO<E extends TopiaEntity>
Parameters:
properties - la liste des propriétés que doit avoir l'objet créé
Returns:
un nouvel objet
Throws:
TopiaException - si un problème est rencontré durant l'instanciation

update

public E update(E e)
                             throws TopiaException
Description copied from interface: TopiaDAO
Permet d'ajouter ou de mettre a jour un objet. Cela permet d'ajouter par exemple un objet provenant d'un autre context mais du meme type de DAO.

Specified by:
update in interface TopiaDAO<E extends TopiaEntity>
Parameters:
e - l'entite a ajouter ou mettre a jour
Returns:
l'entity passé en paramètre.
Throws:
TopiaException - if any pb while updating datas

delete

public void delete(E e)
            throws TopiaException
Description copied from interface: TopiaDAO
Permet de supprimer une entite.

Specified by:
delete in interface TopiaDAO<E extends TopiaEntity>
Parameters:
e - l'entite a supprimer
Throws:
TopiaException - if any pb while deleting datas

createQuery

public TopiaQuery createQuery()
Description copied from interface: TopiaDAO
Crée une requete basé sur l'entité lié au DAO. Résultat attendu : "FROM E"

Specified by:
createQuery in interface TopiaDAO<E extends TopiaEntity>
Returns:
une nouvelle TopiaQuery vide. (uniquement avec le From sur le type d'entité)

createQuery

public TopiaQuery createQuery(java.lang.String entityAlias)
Description copied from interface: TopiaDAO
Crée une requête basé sur l'entité lié au DAO et lui assigne un alias valable dans la requête..

Résultat attendu : "FROM E AS entityAlias"

Specified by:
createQuery in interface TopiaDAO<E extends TopiaEntity>
Parameters:
entityAlias - alias permettant de manipuler l'entité dans la requête
Returns:
une nouvelle TopiaQuery

findByTopiaId

public E findByTopiaId(java.lang.String id)
                                    throws TopiaException
Description copied from interface: TopiaDAO
Find an entity corresponding to the id. If the id is null, nothing will be search.

Specified by:
findByTopiaId in interface TopiaDAO<E extends TopiaEntity>
Parameters:
id - topiaId of the entity to found
Returns:
the entity found or null if not
Throws:
TopiaException - for Topia errors on query

findByProperty

public E findByProperty(java.lang.String propertyName,
                        java.lang.Object value)
                                     throws TopiaException
Specified by:
findByProperty in interface TopiaDAO<E extends TopiaEntity>
Throws:
TopiaException

findByProperties

public E findByProperties(java.lang.String propertyName,
                          java.lang.Object value,
                          java.lang.Object... others)
                                       throws TopiaException
Specified by:
findByProperties in interface TopiaDAO<E extends TopiaEntity>
Parameters:
propertyName - le nom de la propriété
value - la valeur à tester
others - les autres proprietes doivent aller par 2 propertyName, value
Returns:
l'entité trouvé
Throws:
TopiaException - if any pb while getting datas

findByProperties

public E findByProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
                                       throws TopiaException
Specified by:
findByProperties in interface TopiaDAO<E extends TopiaEntity>
Throws:
TopiaException

findByQuery

public E findByQuery(TopiaQuery query)
                                  throws TopiaException
Description copied from interface: TopiaDAO
Execute une requête basé sur l'entité du DAO. Permet de récupérer une entité correspondant à la requête.

Specified by:
findByQuery in interface TopiaDAO<E extends TopiaEntity>
Parameters:
query - la requête
Returns:
l'entité correspondant à la recherche ou null si aucune entité n'a été trouvée
Throws:
TopiaException - if any pb while getting datas
See Also:
TopiaQuery.executeToEntity(TopiaContext, Class)

findAll

public java.util.List<E> findAll()
                                              throws TopiaException
Specified by:
findAll in interface TopiaDAO<E extends TopiaEntity>
Throws:
TopiaException

findAllIds

public java.util.List<java.lang.String> findAllIds()
                                            throws TopiaException
Description copied from interface: TopiaDAO
Recuperation de tous les ids en base pour le type d'entite du dao.

Specified by:
findAllIds in interface TopiaDAO<E extends TopiaEntity>
Returns:
la liste de tous les ids
Throws:
TopiaException - si pb en base

findAllByProperty

public java.util.List<E> findAllByProperty(java.lang.String propertyName,
                                           java.lang.Object value)
                                                        throws TopiaException
Specified by:
findAllByProperty in interface TopiaDAO<E extends TopiaEntity>
Throws:
TopiaException

findAllByProperties

public java.util.List<E> findAllByProperties(java.lang.String propertyName,
                                             java.lang.Object value,
                                             java.lang.Object... others)
                                                          throws TopiaException
Specified by:
findAllByProperties in interface TopiaDAO<E extends TopiaEntity>
Parameters:
propertyName - le nom de la propriété
value - la valeur à tester
others - les autres proprietes doivent aller par 2 propertyName, value
Returns:
l'entité trouvé
Throws:
TopiaException - if any pb while getting datas

findAllByProperties

public java.util.List<E> findAllByProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
                                                          throws TopiaException
Specified by:
findAllByProperties in interface TopiaDAO<E extends TopiaEntity>
Throws:
TopiaException

findAllByQuery

public java.util.List<E> findAllByQuery(TopiaQuery query)
                                                     throws TopiaException
Description copied from interface: TopiaDAO
Execute une requête basé sur l'entité du DAO. Permet de récupérer une liste d'entités correspondant à la requête.

Specified by:
findAllByQuery in interface TopiaDAO<E extends TopiaEntity>
Parameters:
query - la requête
Returns:
la liste d'entités correspondant à la recherche
Throws:
TopiaException - if any pb while getting datas
See Also:
TopiaQuery.executeToEntityList(TopiaContext, Class)

findAllMappedByQuery

public java.util.Map<java.lang.String,E> findAllMappedByQuery(TopiaQuery query)
                                                                           throws TopiaException
Description copied from interface: TopiaDAO
Execute une requête basé sur l'entité du DAO. Permet de récupérer une map d'entités correspondant à la requête. La clé de la map étant le topiaId de l'entité.

Specified by:
findAllMappedByQuery in interface TopiaDAO<E extends TopiaEntity>
Parameters:
query - la requête
Returns:
la map d'entités correspondant à la recherche
Throws:
TopiaException - if any pb while getting datas
See Also:
TopiaQuery.executeToEntityMap(TopiaContext, Class)

findAllMappedByQuery

public <K> java.util.Map<K,E> findAllMappedByQuery(TopiaQuery query,
                                                   java.lang.String keyName,
                                                   java.lang.Class<K> keyClass)
                                                            throws TopiaException
Description copied from interface: TopiaDAO
Execute une requête basé sur l'entité du DAO. Permet de récupérer une map d'entités correspondant à la requête. Le type et le nom de la propriété utilisé comme clé de la map doit être passé en argument.

Specified by:
findAllMappedByQuery in interface TopiaDAO<E extends TopiaEntity>
Type Parameters:
K - type de la clé de la map
Parameters:
query - la requête
keyName - nom de la propriété de l'entité utilisée comme clé
keyClass - type de la propriété de l'entité utilisée comme clé
Returns:
la map d'entités correspondant à la recherche
Throws:
TopiaException - if any pb while getting datas
See Also:
TopiaQuery.executeToEntityMap(TopiaContext, Class)

findAllWithOrder

public java.util.List<E> findAllWithOrder(java.lang.String... propertyNames)
                                                       throws TopiaException
Specified by:
findAllWithOrder in interface TopiaDAO<E extends TopiaEntity>
Throws:
TopiaException

existByTopiaId

public boolean existByTopiaId(java.lang.String id)
                       throws TopiaException
Description copied from interface: TopiaDAO
Check the existence of an entity with technical id.

Specified by:
existByTopiaId in interface TopiaDAO<E extends TopiaEntity>
Parameters:
id - unique id of the entity to test existence.
Returns:
true if entity exists, false otherwise
Throws:
TopiaException - for Topia errors

existByProperties

public boolean existByProperties(java.lang.String propertyName,
                                 java.lang.Object propertyValue,
                                 java.lang.Object... others)
                          throws TopiaException
Description copied from interface: TopiaDAO
Check the existence of an entity with propertyName with propertyValue. others properties can be added to test existence.

Specified by:
existByProperties in interface TopiaDAO<E extends TopiaEntity>
Parameters:
propertyName - first property name to test existence
propertyValue - first property value to test existence
others - altern propertyName and propertyValue
Returns:
true if entity exists, false otherwise
Throws:
TopiaException - for Topia errors

existByQuery

public boolean existByQuery(TopiaQuery query)
                     throws TopiaException
Description copied from interface: TopiaDAO
Check the existence of an entity using a query.

Specified by:
existByQuery in interface TopiaDAO<E extends TopiaEntity>
Parameters:
query - query used to test existence
Returns:
true if entity exists, false otherwise
Throws:
TopiaException

size

@Deprecated
public long size()
          throws TopiaException
Deprecated. since 2.3.4 ambiguous name, use count() instead.

Count number of existing entities using TopiaQuery.executeCount(TopiaContext)

Specified by:
size in interface TopiaDAO<E extends TopiaEntity>
Returns:
a long for the number of entities in database
Throws:
TopiaException - if any pb while getting datas

count

public int count()
          throws TopiaException
Description copied from interface: TopiaDAO
Count the number of existing entities.

Specified by:
count in interface TopiaDAO<E extends TopiaEntity>
Returns:
number of total entities
Throws:
TopiaException - if any pb while getting datas

countByQuery

public int countByQuery(TopiaQuery query)
                 throws TopiaException
Description copied from interface: TopiaDAO
Count the number of entities based on query.

Specified by:
countByQuery in interface TopiaDAO<E extends TopiaEntity>
Returns:
number of entities filtered by the query
Throws:
TopiaException - if any pb while getting datas

findByPrimaryKey

public E findByPrimaryKey(java.util.Map<java.lang.String,java.lang.Object> keys)
                                       throws TopiaException
Description copied from interface: TopiaDAO
Recherche la classe en utilisant la cle naturelle, chaque champs de la cle naturelle est une entre de la map passe en argument.

Specified by:
findByPrimaryKey in interface TopiaDAO<E extends TopiaEntity>
Parameters:
keys - la liste des champs de la cle naturelle avec leur valeur
Returns:
l'entite trouvé
Throws:
TopiaException - if any pb while getting datas

findByPrimaryKey

public E findByPrimaryKey(java.lang.Object... k)
                                       throws TopiaException
Description copied from interface: TopiaDAO
Recherche la classe en utilisant la cle naturelle, si la cle naturelle est composé de plusieurs champs alors les arguments passés doivent être dans l'ordre de declaration dans le fichier de mapping

Specified by:
findByPrimaryKey in interface TopiaDAO<E extends TopiaEntity>
Parameters:
k - l'objet cle naturelle de la classe
Returns:
l'entité trouvé
Throws:
TopiaException - if any pb while getting datas


Copyright © 2004-2010 CodeLutin. All Rights Reserved.