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

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

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

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.

Author:
poussin

Field Summary
protected  TopiaContextImplementor context
           
protected  java.lang.Class<Entity> entityClass
           
 
Constructor Summary
TopiaDAOImpl()
           
 
Method Summary
 void addTopiaEntityListener(TopiaEntityListener listener)
           
 void addTopiaEntityVetoable(TopiaEntityVetoable vetoable)
           
 void commitTransaction()
          Callback method when context was commit.
 Entity 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.
 Entity create(java.lang.Object... properties)
          Construit une nouvelle instance de l'objet géré par ce DAO
 void delete(Entity e)
           
 java.util.List<Entity> findAll()
           
 java.util.List<Entity> findAllByProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
           
 java.util.List<Entity> findAllByProperties(java.lang.String propertyName, java.lang.Object value, java.lang.Object... others)
           
 java.util.List<Entity> findAllByProperty(java.lang.String propertyName, java.lang.Object value)
           
 java.util.List<Entity> findAllContainsProperties(java.util.Map<java.lang.String,java.util.Collection> properties)
          Find all entities with a specific rule : When the entity have a Collection type property, you want to find all entites where some values are contained in the collection type property.
 java.util.List<Entity> findAllContainsProperties(java.lang.String propertyName, java.util.Collection values, java.lang.Object... others)
          Cherche et renvoie toutes les entités trouvées dont la propriété propertyName contient values, ainsi de suite avec others.
 java.util.List<java.lang.String> findAllIds()
          Recuperation de tous les ids en base pour le type d'entite du dao.
 java.util.List<Entity> findAllWithOrder(java.lang.String... propertyNames)
           
 Entity 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.
 Entity 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
 Entity findByProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
           
 Entity findByProperties(java.lang.String propertyName, java.lang.Object value, java.lang.Object... others)
           
 Entity findByProperty(java.lang.String propertyName, java.lang.Object value)
           
 Entity findByTopiaId(java.lang.String k)
           
 Entity findContainsProperties(java.util.Map<java.lang.String,java.util.Collection> properties)
          Cherche et renvoie la première entité trouvée dont les propriétés en clé de Map contiennent toutes les valeurs de la Collection.
 Entity findContainsProperties(java.lang.String propertyName, java.util.Collection values, java.lang.Object... others)
          Cherche et renvoie la première entité trouvée dont la propriété propertyName contient values, ainsi de suite avec others.
 TopiaContextImplementor getContext()
           
 java.lang.Class<Entity> getEntityClass()
          Return class of entity managed by this DAO
protected  java.io.Serializable getId(Entity 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<Entity> entityClass)
          When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just after
protected  Entity instanciateNew()
           
 void removeTopiaEntityListener(TopiaEntityListener listener)
           
 void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable)
           
 void rollbackTransaction()
          Callback method when context was rollback.
 long size()
          Utilisation du count(*) en HQL pour recuperer le nombre d'entites du type lie au DAO
 Entity update(Entity 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<Entity extends TopiaEntity> entityClass

context

protected TopiaContextImplementor context
Constructor Detail

TopiaDAOImpl

public TopiaDAOImpl()
Method Detail

getEntityClass

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

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

getId

protected java.io.Serializable getId(Entity 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<Entity> entityClass)
          throws TopiaException
When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just after

Specified by:
init in interface TopiaDAO<Entity extends TopiaEntity>
Parameters:
entityClass -
context - context
Throws:
TopiaException

getContext

public TopiaContextImplementor getContext()
Specified by:
getContext in interface TopiaDAO<Entity extends TopiaEntity>
Returns:
Returns the context.

instanciateNew

protected Entity instanciateNew()
                                             throws TopiaException
Throws:
TopiaException

commitTransaction

public void commitTransaction()
                       throws TopiaException
Callback method when context was commit. By default, the method does nothing

Specified by:
commitTransaction in interface TopiaDAO<Entity extends TopiaEntity>
Throws:
TopiaException

rollbackTransaction

public void rollbackTransaction()
                         throws TopiaException
Callback method when context was rollback. By default, the method does nothing

Specified by:
rollbackTransaction in interface TopiaDAO<Entity extends TopiaEntity>
Throws:
TopiaException

create

public Entity 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<Entity 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

findByPrimaryKey

public Entity 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<Entity extends TopiaEntity>
Parameters:
keys - la liste des champs de la cle naturelle avec leur valeur
Returns:
l'entite trouvé
Throws:
TopiaException

findByPrimaryKey

public Entity 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<Entity extends TopiaEntity>
Parameters:
k - l'objet cle naturelle de la classe
Returns:
l'entité trouvé
Throws:
TopiaException

findByProperties

public Entity findByProperties(java.lang.String propertyName,
                               java.lang.Object value,
                               java.lang.Object... others)
                                            throws TopiaException
Specified by:
findByProperties in interface TopiaDAO<Entity extends TopiaEntity>
others - les autres proprietes doivent aller par 2 propertyName, value
Returns:
l'entité trouvé
Throws:
TopiaException

findAllByProperties

public java.util.List<Entity> findAllByProperties(java.lang.String propertyName,
                                                  java.lang.Object value,
                                                  java.lang.Object... others)
                                                               throws TopiaException
Specified by:
findAllByProperties in interface TopiaDAO<Entity extends TopiaEntity>
others - les autres proprietes doivent aller par 2 propertyName, value
Returns:
l'entité trouvé
Throws:
TopiaException

findContainsProperties

public Entity findContainsProperties(java.util.Map<java.lang.String,java.util.Collection> properties)
                                                  throws TopiaException
Description copied from interface: TopiaDAO
Cherche et renvoie la première entité trouvée dont les propriétés en clé de Map contiennent toutes les valeurs de la Collection.

Specified by:
findContainsProperties in interface TopiaDAO<Entity extends TopiaEntity>
Returns:
l'entité trouvé
Throws:
TopiaException

findContainsProperties

public Entity findContainsProperties(java.lang.String propertyName,
                                     java.util.Collection values,
                                     java.lang.Object... others)
                                                  throws TopiaException
Description copied from interface: TopiaDAO
Cherche et renvoie la première entité trouvée dont la propriété propertyName contient values, ainsi de suite avec others.

Specified by:
findContainsProperties in interface TopiaDAO<Entity extends TopiaEntity>
Returns:
l'entité trouvé
Throws:
TopiaException

findAllContainsProperties

public java.util.List<Entity> findAllContainsProperties(java.util.Map<java.lang.String,java.util.Collection> properties)
                                                                     throws TopiaException
Find all entities with a specific rule : When the entity have a Collection type property, you want to find all entites where some values are contained in the collection type property. Example entity parameter : private Collection historicalDates; You want some dates to be contained in historicalDates. Collection myDates... myDates.add(date1) ... Map properties = new HashMap(); properties.put("historicalDates",myDates); findAllContainsProperties(properties);

Specified by:
findAllContainsProperties in interface TopiaDAO<Entity extends TopiaEntity>
Parameters:
properties -
Returns:
the list of entities corresponding to the request
Throws:
TopiaException - if any pb

findAllContainsProperties

public java.util.List<Entity> findAllContainsProperties(java.lang.String propertyName,
                                                        java.util.Collection values,
                                                        java.lang.Object... others)
                                                                     throws TopiaException
Description copied from interface: TopiaDAO
Cherche et renvoie toutes les entités trouvées dont la propriété propertyName contient values, ainsi de suite avec others.

Specified by:
findAllContainsProperties in interface TopiaDAO<Entity extends TopiaEntity>
Returns:
l'entité trouvé
Throws:
TopiaException

findAllByProperty

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

findByProperty

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

addTopiaEntityListener

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

addTopiaEntityVetoable

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

removeTopiaEntityListener

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

removeTopiaEntityVetoable

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

create

public Entity 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<Entity 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 Entity update(Entity 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<Entity extends TopiaEntity>
Parameters:
e - l'entite a ajouter ou mettre a jour
Returns:
l'entity passé en paramètre.
Throws:
TopiaException

delete

public void delete(Entity e)
            throws TopiaException
Specified by:
delete in interface TopiaDAO<Entity extends TopiaEntity>
Throws:
TopiaException

findByTopiaId

public Entity findByTopiaId(java.lang.String k)
                                         throws TopiaException
Specified by:
findByTopiaId in interface TopiaDAO<Entity extends TopiaEntity>
Throws:
TopiaException

findAll

public java.util.List<Entity> findAll()
                                                   throws TopiaException
Specified by:
findAll in interface TopiaDAO<Entity 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<Entity extends TopiaEntity>
Returns:
la liste de tous les ids
Throws:
TopiaException - si pb en base

findAllWithOrder

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

size

public long size()
          throws TopiaException
Utilisation du count(*) en HQL pour recuperer le nombre d'entites du type lie au DAO

Specified by:
size in interface TopiaDAO<Entity extends TopiaEntity>
Returns:
un long correspondant au nombre d'entités existantes en base
Throws:
TopiaException

findByProperties

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

findAllByProperties

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

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<Entity extends TopiaEntity>
Parameters:
topiaId - topiaId d'une entite
Returns:
la liste des permissions
Throws:
TopiaException


Copyright © 2004-2009 CodeLutin. All Rights Reserved.