Class EntityOperator<B extends TopiaEntity>

java.lang.Object
org.nuiton.topia.persistence.util.EntityOperator<B>
Type Parameters:
B - type de l'entite

public class EntityOperator<B extends TopiaEntity>
extends java.lang.Object
Un objet qui permet d'effecuter des operations de manipulation des donnees dans les entites du type donne. L'objet connait la liste des proprietes et des associations du type donne et permet de modifier ces valeurs : get(String, TopiaEntity) set(String, TopiaEntity, Object) copy(String, TopiaEntity, TopiaEntity) getChild(String, TopiaEntity, String) addChild(String, TopiaEntity, Object) removeChild(String, TopiaEntity, Object) ... D'autres methodes permettent d'effectuer des operations en lot (sur plusieurs proprietes en meme temps) sur les proprietes : copyProperties(TopiaEntity, TopiaEntity, boolean, String...) obtainProperties(TopiaEntity, String...) clearProperties(TopiaEntity, String...) Note : cet objet ne permet pas d'operation vers les bases.
Since:
2.2.0
Author:
tchemit <chemit@codelutin.com>
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected java.util.List<java.lang.String> associationProperties
    list of association names available on the entity.
    protected java.lang.reflect.Method[] childAddAllMethods
    cache of assocation addAll methods.
    protected java.lang.reflect.Method[] childAddMethods
    cache of assocation add methods.
    protected java.lang.reflect.Method[] childClearMethods
    cache of assocation clearmethods.
    protected java.lang.reflect.Method[] childGetMethods
    cache of assocation get methods.
    protected java.lang.reflect.Method[] childIsEmptyMethods
    cache of assocation isEmpty methods.
    protected java.lang.reflect.Method[] childRemoveMethods
    cache of assocation remove methods.
    protected java.lang.reflect.Method[] childSizeMethods
    cache of assocation size methods.
    protected TopiaEntityEnum contract
    the constant of the entity
    protected java.lang.reflect.Method[] getMethods
    cache of getter methods.
    protected java.util.Set<java.lang.String> naturalIdsOnNotNullsProperties
    list of property names available on the entity used in a natural ids or marked as not-null.
    protected java.util.List<java.lang.String> properties
    list of property names available on the entity.
    protected java.lang.reflect.Method[] setMethods
    cache of setter methods.
    protected static java.lang.Integer ZERO
    Deprecated.
    protected static java.lang.Byte ZEROB
    Deprecated.
    protected static java.lang.Character ZEROC
    Deprecated.
    protected static java.lang.Double ZEROD
    Deprecated.
    protected static java.lang.Float ZEROF
    Deprecated.
    protected static java.lang.Long ZEROL
    Deprecated.
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected EntityOperator​(TopiaEntityEnum contract)  
  • Method Summary

    Modifier and Type Method Description
    void addAllChild​(java.lang.String name, B bean, java.util.Collection<?> childs)
    Ajoute toutes les entites d'association.
    void addChild​(java.lang.String name, B bean, java.lang.Object child)
    Ajoute une entite d'association.
    void clearChild​(java.lang.String name, B bean)
    Retire toutes les entites d'association.
    void clearProperties​(B from, java.lang.String... properties)
    Met a null toutes les proprietes donnees.
    java.lang.Object clone()  
    void copy​(java.lang.String name, B from, B dst)
    Copie une propriete de src vers dst.
    void copyProperties​(B from, B dst, boolean tech, java.lang.String... properties)
    Recopie toutes les proprietes donnes depuis src vers dst.
    boolean equals​(java.lang.Object obj)  
    protected void finalize()  
    java.lang.Object get​(java.lang.String name, B bean)
    Recupere la valeur de la propriete donnee.
    java.util.List<java.lang.String> getAssociationProperties()  
    protected java.lang.Class<?> getAssociationPropertyType​(int index)  
    java.lang.Class<?> getAssociationPropertyType​(java.lang.String name)  
    java.lang.Object getChild​(java.lang.String name, B bean, java.lang.String topiaId)
    Recupere une entite d'association a partir de son id.
    java.lang.Class<B> getClazz()  
    java.util.Map<java.lang.String,​java.lang.Object> getNaturalId​(B bean)
    Pour obtenir un dictionnaire de la clef naturelle (clef métier) du bean donne.
    java.lang.String[] getNaturalIdsOnNotNullsProperties()
    Get all properties from a natural id or marked as not-null.
    java.util.Map<java.lang.String,​java.lang.Object> getNaturalIsdAndNotNulls​(B bean)
    Pour obtenir un dictionnaire des propriétés marqués not-null et la clef naturelle du bean donne.
    java.util.Map<java.lang.String,​java.lang.Object> getNotNull​(B bean)
    Pour obtenir un dictionnaire des propriétés marqués not-null du bean donne.
    static java.lang.Object getNullValue​(java.lang.Class<?> type)
    Deprecated.
    since 2.6 (there is some other library which does it
    java.util.List<java.lang.String> getProperties()  
    protected java.util.Collection<java.lang.String> getProperties​(java.lang.String[] properties)  
    protected java.lang.Class<?> getPropertyType​(int index)  
    java.lang.Class<?> getPropertyType​(java.lang.String name)  
    int hashCode()  
    protected void init()  
    protected void init​(java.lang.Class<?> entityClass, java.util.Set<java.lang.Class<?>> explored, java.util.List<java.lang.String> properties, java.util.List<java.lang.String> associationProperties, java.util.List<java.lang.reflect.Method> getters, java.util.List<java.lang.reflect.Method> setters, java.util.List<java.lang.reflect.Method> childGetters, java.util.List<java.lang.reflect.Method> childAdders, java.util.List<java.lang.reflect.Method> childAddersAll, java.util.List<java.lang.reflect.Method> childRemovers, java.util.List<java.lang.reflect.Method> childSize, java.util.List<java.lang.reflect.Method> childClearers, java.util.List<java.lang.reflect.Method> childIsEmpty)  
    protected static void invoke​(java.lang.reflect.Method m, java.lang.Object bean, java.lang.Object... args)  
    protected static <V> V invokeWithResult​(java.lang.reflect.Method m, java.lang.Object bean, java.lang.Object... args)  
    boolean isChildEmpty​(java.lang.String name, B bean)
    Test s'il existe des entites d'association pour la propriete donnee.
    protected B newInstance()  
    java.util.Map<java.lang.String,​java.lang.Object> obtainProperties​(B from, java.lang.String... properties)
    Obtenir dans un dictionnaire, les valeurs des proprietes donnees.
    void removeChild​(java.lang.String name, B bean, java.lang.Object child)
    Retire une entite d'association.
    void set​(java.lang.String name, B bean, java.lang.Object value)
    Positionner la valeur donne de la propriete donnee.
    void setNull​(java.lang.String name, B bean)
    Positionner la valeur nulle de la propriete donnee.
    int sizeChild​(java.lang.String name, B bean)
    Retourne le nombre d'entite d'association.
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • contract

      protected final TopiaEntityEnum contract
      the constant of the entity
    • properties

      protected java.util.List<java.lang.String> properties
      list of property names available on the entity.
    • naturalIdsOnNotNullsProperties

      protected java.util.Set<java.lang.String> naturalIdsOnNotNullsProperties
      list of property names available on the entity used in a natural ids or marked as not-null.
      Since:
      2.6.9
    • associationProperties

      protected java.util.List<java.lang.String> associationProperties
      list of association names available on the entity.
    • getMethods

      protected java.lang.reflect.Method[] getMethods
      cache of getter methods.
    • setMethods

      protected java.lang.reflect.Method[] setMethods
      cache of setter methods.
    • childGetMethods

      protected java.lang.reflect.Method[] childGetMethods
      cache of assocation get methods.
    • childAddMethods

      protected java.lang.reflect.Method[] childAddMethods
      cache of assocation add methods.
    • childAddAllMethods

      protected java.lang.reflect.Method[] childAddAllMethods
      cache of assocation addAll methods.
    • childRemoveMethods

      protected java.lang.reflect.Method[] childRemoveMethods
      cache of assocation remove methods.
    • childSizeMethods

      protected java.lang.reflect.Method[] childSizeMethods
      cache of assocation size methods.
    • childIsEmptyMethods

      protected java.lang.reflect.Method[] childIsEmptyMethods
      cache of assocation isEmpty methods.
    • childClearMethods

      protected java.lang.reflect.Method[] childClearMethods
      cache of assocation clearmethods.
    • ZERO

      @Deprecated protected static final java.lang.Integer ZERO
      Deprecated.
    • ZEROC

      @Deprecated protected static final java.lang.Character ZEROC
      Deprecated.
    • ZEROF

      @Deprecated protected static final java.lang.Float ZEROF
      Deprecated.
    • ZEROL

      @Deprecated protected static final java.lang.Long ZEROL
      Deprecated.
    • ZEROD

      @Deprecated protected static final java.lang.Double ZEROD
      Deprecated.
    • ZEROB

      @Deprecated protected static final java.lang.Byte ZEROB
      Deprecated.
  • Constructor Details

  • Method Details

    • get

      public java.lang.Object get​(java.lang.String name, B bean)
      Recupere la valeur de la propriete donnee. Note : cela apellera la methode getXXX().
      Parameters:
      name - le nom de la propriete
      bean - l'instance a interroger
      Returns:
      la valeur de la propriete
    • set

      public void set​(java.lang.String name, B bean, java.lang.Object value)
      Positionner la valeur donne de la propriete donnee. Note : cela apellera la methode setXXX(value).
      Parameters:
      name - le nom de la propriete
      bean - l'instance a mettre a jour
      value - la valeur a positionner
    • getNaturalId

      public java.util.Map<java.lang.String,​java.lang.Object> getNaturalId​(B bean)
      Pour obtenir un dictionnaire de la clef naturelle (clef métier) du bean donne.
      Parameters:
      bean - le bean a inspecter
      Returns:
      le dictionnaire de la clef naturel du bean
      Since:
      2.4.1
      See Also:
      TopiaEntityEnum.getNaturalIds()
    • getNotNull

      public java.util.Map<java.lang.String,​java.lang.Object> getNotNull​(B bean)
      Pour obtenir un dictionnaire des propriétés marqués not-null du bean donne.
      Parameters:
      bean - le bean a inspecter
      Returns:
      le dictionnaire des propriétés marquées not-null du bean
      Since:
      2.6.9
      See Also:
      TopiaEntityEnum.getNotNulls()
    • getNaturalIdsOnNotNullsProperties

      public java.lang.String[] getNaturalIdsOnNotNullsProperties()
      Get all properties from a natural id or marked as not-null.
      Returns:
      all property names froma natural id or marked as not-null
      Since:
      2.6.9
    • getNaturalIsdAndNotNulls

      public java.util.Map<java.lang.String,​java.lang.Object> getNaturalIsdAndNotNulls​(B bean)
      Pour obtenir un dictionnaire des propriétés marqués not-null et la clef naturelle du bean donne. Cette methode est utilisée pour faire un dao.create, pour s'assurer que tout ce qui ne doit pas pas être à null est bien fourni à la création de l'objet, sinon on obtient des erreurs.
      Parameters:
      bean - le bean a inspecter
      Returns:
      le dictionnaire des propriétés marquées not-null + la clef naturelle du bean
      Since:
      2.6.9
      See Also:
      TopiaEntityEnum.getNotNulls(), TopiaEntityEnum.getNaturalIds()
    • copy

      public void copy​(java.lang.String name, B from, B dst)
      Copie une propriete de src vers dst. Note : cela apellera la methode setXXX(value).
      Parameters:
      name - le nom de la propriete
      from - l'instance a interroger
      dst - l'instance a mettre a jour
    • setNull

      public void setNull​(java.lang.String name, B bean)
      Positionner la valeur nulle de la propriete donnee. Note : cela apellera la methode setXXX(nullValue).
      Parameters:
      name - le nom de la propriete
      bean - l'instance a mettre a jour
    • getNullValue

      @Deprecated public static java.lang.Object getNullValue​(java.lang.Class<?> type)
      Deprecated.
      since 2.6 (there is some other library which does it
      Obtains the null value for the given type (works too with primitive types).
      Parameters:
      type - the type to test
      Returns:
      the null value or default value for primitive types
      Since:
      1.1.5
      See Also:
      Defaults
    • getChild

      public java.lang.Object getChild​(java.lang.String name, B bean, java.lang.String topiaId)
      Recupere une entite d'association a partir de son id. Note : cela apellera la methode getXXXByTopiaId(topiaId).
      Parameters:
      name - le nom de la propriete d'association
      bean - l'instance a interroger
      topiaId - l'id de l'entite recherchee
      Returns:
      l'entite
    • isChildEmpty

      public boolean isChildEmpty​(java.lang.String name, B bean)
      Test s'il existe des entites d'association pour la propriete donnee. Note : cela apellera la methode isXXXEmpty().
      Parameters:
      name - le nom de la propriete d'association
      bean - l'instance a interroger
      Returns:
      true si pas d'entite d'association
    • addChild

      public void addChild​(java.lang.String name, B bean, java.lang.Object child)
      Ajoute une entite d'association. Note : cela apellera la methode addXXX(child).
      Parameters:
      name - le nom de la propriete d'association
      bean - l'instance a mettre a jour
      child - l'entite a ajouter
    • addAllChild

      public void addAllChild​(java.lang.String name, B bean, java.util.Collection<?> childs)
      Ajoute toutes les entites d'association. Note : cela apellera la methode addXXX(child).
      Parameters:
      name - le nom de la propriete d'association
      bean - l'instance a mettre a jour
      childs - les entites a ajouter
    • removeChild

      public void removeChild​(java.lang.String name, B bean, java.lang.Object child)
      Retire une entite d'association. Note : cela apellera la methode removeXXX(child).
      Parameters:
      name - le nom de la propriete d'association
      bean - l'instance a mettre a jour
      child - l'entite a retirer
    • sizeChild

      public int sizeChild​(java.lang.String name, B bean)
      Retourne le nombre d'entite d'association. Note : cela apellera la methode sizeXXX(childs).
      Parameters:
      name - le nom de la propriete d'association
      bean - l'instance a mettre a jour
      Returns:
      le nombre d'entite d'associaotion
    • clearChild

      public void clearChild​(java.lang.String name, B bean)
      Retire toutes les entites d'association. Note : cela apellera la methode clearXXX(childs).
      Parameters:
      name - le nom de la propriete d'association
      bean - l'instance a mettre a jour
    • copyProperties

      public void copyProperties​(B from, B dst, boolean tech, java.lang.String... properties)
      Recopie toutes les proprietes donnes depuis src vers dst. Note : si aucune propriete n'est donnee, on utilise toutes les proprietes connues par l'operateur.
      Parameters:
      from - l'entite a interroger
      dst - l'entite a mettre a jour
      tech - un drapeau pour recopier aussi les infos techniques
      properties - les proprietes a recopier
    • obtainProperties

      public java.util.Map<java.lang.String,​java.lang.Object> obtainProperties​(B from, java.lang.String... properties)
      Obtenir dans un dictionnaire, les valeurs des proprietes donnees. Si aucune proropiete n'est donne, alors on utilise toutes les proprietes connu par l'operateur.
      Parameters:
      from - l'object a scanne
      properties - les proprietes a retenir (vide si on les veut toutes)
      Returns:
      le dictionnaire des valeurs des proprietes
    • clearProperties

      public void clearProperties​(B from, java.lang.String... properties)
      Met a null toutes les proprietes donnees. Si aucune proropiete n'est donnee, alors on utilise toutes les proprietes connu par l'operateur.
      Parameters:
      from - l'object a scanne
      properties - les proprietes a retenir (vide si on les veut toutes)
    • getProperties

      public java.util.List<java.lang.String> getProperties()
    • getAssociationProperties

      public java.util.List<java.lang.String> getAssociationProperties()
    • getPropertyType

      public java.lang.Class<?> getPropertyType​(java.lang.String name)
    • getAssociationPropertyType

      public java.lang.Class<?> getAssociationPropertyType​(java.lang.String name)
    • getClazz

      public java.lang.Class<B> getClazz()
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • clone

      public java.lang.Object clone()
      Overrides:
      clone in class java.lang.Object
    • finalize

      protected void finalize() throws java.lang.Throwable
      Overrides:
      finalize in class java.lang.Object
      Throws:
      java.lang.Throwable
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • getProperties

      protected java.util.Collection<java.lang.String> getProperties​(java.lang.String[] properties)
    • getPropertyType

      protected java.lang.Class<?> getPropertyType​(int index)
    • getAssociationPropertyType

      protected java.lang.Class<?> getAssociationPropertyType​(int index)
    • newInstance

      protected B newInstance()
    • init

      protected void init()
    • invoke

      protected static void invoke​(java.lang.reflect.Method m, java.lang.Object bean, java.lang.Object... args)
    • invokeWithResult

      protected static <V> V invokeWithResult​(java.lang.reflect.Method m, java.lang.Object bean, java.lang.Object... args)
    • init

      protected void init​(java.lang.Class<?> entityClass, java.util.Set<java.lang.Class<?>> explored, java.util.List<java.lang.String> properties, java.util.List<java.lang.String> associationProperties, java.util.List<java.lang.reflect.Method> getters, java.util.List<java.lang.reflect.Method> setters, java.util.List<java.lang.reflect.Method> childGetters, java.util.List<java.lang.reflect.Method> childAdders, java.util.List<java.lang.reflect.Method> childAddersAll, java.util.List<java.lang.reflect.Method> childRemovers, java.util.List<java.lang.reflect.Method> childSize, java.util.List<java.lang.reflect.Method> childClearers, java.util.List<java.lang.reflect.Method> childIsEmpty) throws java.beans.IntrospectionException
      Throws:
      java.beans.IntrospectionException