EN · DE · RU · FR · ES

#360 : DeltaSetCalculator.java

projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java Classe Java, projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java 378 lignes · 271 code · 81 commentaires · 26 vides
Objectif : Fichier source : hibernate/history/delta/DeltaSetCalculator.java. DeltaSetCalculator.java fait partie de l'application open-source de gestion de projet ProjectForge.

Source (100 premières lignes)

/////////////////////////////////////////////////////////////////////////////
//
// Projet ProjectForge Community Edition
//         www.projectforge.org
//
// Copyright (C) 2001-2026 Micromata GmbH, Allemagne (www.micromata.com)
//
// ProjectForge est sous double licence.
//
// Cette édition communautaire est un logiciel libre ; vous pouvez la redistribuer et/ou
// la modifier selon les termes de la GNU General Public License telle que publiée
// par la Free Software Foundation ; version 3 de la Licence.
//
// Cette édition communautaire est distribuée dans l'espoir qu'elle sera utile,
// mais SANS AUCUNE GARANTIE ; sans même la garantie implicite de
// QUALITÉ MARCHANDE ou d'ADÉQUATION À UN USAGE PARTICULIER. Voir la GNU General
// Public License pour plus de détails.
//
// Vous devriez avoir reçu une copie de la GNU General Public License avec
// ce programme ; sinon, consultez http://www.gnu.org/licenses/.
//
/////////////////////////////////////////////////////////////////////////////

package de.micromata.hibernate.history.delta;

import org.projectforge.common.PropertyUtils;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.*;

/**
 * Héritage utilisé pour la persistance XML de la base de données.
 *
 * @author Wolfgang Jung (w.jung@micromata.de)
 */
public class DeltaSetCalculator {
    private static final Logger log = LoggerFactory.getLogger(DeltaSetCalculator.class);

    private DeltaSetCalculator() {
        // ne rien faire
    }

    /*
     * Un calcul spécifique à Hibernate. Utilise les valeurs passées à la méthode Hibernate Interceptor.onFlushDirty() pour effectuer le
     * calcul.
     *
     * @param propertyNames Un tableau de chaînes de tous les noms de propriétés passés à la méthode onFlushDirty. @param
     * previousState Le tableau d'objets représentant l'état précédent des propriétés nommées dans le tableau propertyNames. @param
     * currentState Le tableau d'objets représentant l'état actuel des propriétés nommées dans le tableau propertyNames. @return Le DeltaSet représentant les changements rencontrés dans les états des propriétés.
     */
    public static DeltaSet calculateDeltaSet(SessionFactory sf, Set<String> validPropertyNames,
                                             Set<String> invalidPropertyNames,
                                             Serializable entityId, Object entity, String[] propertyNames, Object[] previousState, Object[] currentState) {
        if (previousState == null) {
            previousState = new Object[currentState.length];
        }
        if (propertyNames == null || currentState == null) {
            throw new IllegalArgumentException("Les trois tableaux passés pour calculer un delta-set doivent être non nuls");
        }
        if (propertyNames.length != previousState.length && previousState.length != currentState.length) {
            throw new IllegalArgumentException("Les trois tableaux passés pour calculer un delta-set doivent avoir la même longueur");
        }

        DeltaSet deltaSet = new DeltaSet();
        deltaSet.setEntity(entity.getClass());
        deltaSet.setId(entityId);
        try {
            checkProperties(entity, sf, validPropertyNames, invalidPropertyNames, propertyNames, previousState, currentState,
                    deltaSet);
        } catch (Throwable t) {
            log.error("Erreur lors de la détermination du delta-set", t);
        } finally {
            log.debug("Détermination du delta-set terminée");
        }
        return deltaSet;
    }

    /**
     * @param propertyNames
     * @param previousState
     * @param currentState
     * @param deltaSet
     */
    private static void checkProperties(Object entity, SessionFactory sf, Set<String> validPropertyNames,
                                        Set<String> invalidPropertyNames,
                                        String[] propertyNames, Object[] previousState, Object[] currentState, DeltaSet deltaSet) {

Historique Git

868d6abb7 2025 -> 2026
63081666f En-têtes des fichiers source : 2024 -> 2025.
5f9bbfbd3 Correction de fautes de frappe dans le répertoire projectforge-business
a33f8f203 Travail de migration en cours... (tous les tests de tous les packages : OK).
c1d14ecdb Travail de migration en cours...

868d6abb7

2025 -> 2026
868d6abb75cd191a892911ac8e45058932cf9074
diff --git a/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java b/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
index 69c69bd30..92e57b247 100644
--- a/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
+++ b/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
@@ -3,7 +3,7 @@
 // Projet ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2025 Micromata GmbH, Allemagne (www.micromata.com)
+// Copyright (C) 2001-2026 Micromata GmbH, Allemagne (www.micromata.com)
 //
 // ProjectForge est sous double licence.
 //

63081666f

En-têtes des fichiers source : 2024 -> 2025.
63081666f620fb87315f01b817e560e0b2f6a33a
diff --git a/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java b/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
index c2d16521a..69c69bd30 100644
--- a/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
+++ b/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
@@ -3,7 +3,7 @@
 // Projet ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2024 Micromata GmbH, Allemagne (www.micromata.com)
+// Copyright (C) 2001-2025 Micromata GmbH, Allemagne (www.micromata.com)
 //
 // ProjectForge est sous double licence.
 //

5f9bbfbd3

Correction de fautes de frappe dans le répertoire projectforge-business
5f9bbfbd372a85f39c89de392a8565c5370a95cb
diff --git a/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java b/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
index 89634fe29..c2d16521a 100644
--- a/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
+++ b/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
@@ -125,7 +125,7 @@ public class DeltaSetCalculator {
 
             // Essayez de déterminer le type de propriété à partir de currentState ou,
             // previousState... Note : si les deux sont nuls, nous ne pouvons pas déterminer
-            // le propertyType, mais c'est OK car aucun changement n'a eu lieu (null==null)
+            // le propertyType, mais c'est correct car aucun changement n'a eu lieu (null==null)
             if (!isCurrentNull) {
                 propertyType = propertyCurrentState.getClass();
             } else if (!wasPreviousNull) {
@@ -148,7 +148,7 @@ public class DeltaSetCalculator {
     }
 
     /**
-     * Calculateur DeltaSet à usage général.
+     * Calculateur DeltaSet à usage général.
      */
     public static DeltaSet calculateDeltaSet(Object entity, SessionFactory sf, Serializable entityId, Class<?> entityType,
                                              Object obj1,
@@ -370,7 +370,7 @@ public class DeltaSetCalculator {
         }
       }
     } catch (Exception ex) {
-      log.error("Exception levée :" + ex, ex);
+      log.error("Exception levée :" + ex, ex);
     }*/
 
         return obj1.equals(obj2);

a33f8f203

Travail de migration en cours... (tous les tests de tous les packages : OK).
a33f8f203ba809d731307e4785e8ad761ab4bfc0
diff --git a/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java b/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
index 2d4f6b1ae..89634fe29 100644
--- a/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
+++ b/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
@@ -23,15 +23,12 @@
 
 package de.micromata.hibernate.history.delta;
 
-import org.apache.commons.beanutils.PropertyUtils;
+import org.projectforge.common.PropertyUtils;
 import org.hibernate.Hibernate;
 import org.hibernate.HibernateException;
-import org.hibernate.QueryException;
 import org.hibernate.SessionFactory;
 import org.hibernate.collection.spi.PersistentCollection;
 import org.hibernate.engine.spi.SessionFactoryImplementor;
-import org.hibernate.metadata.ClassMetadata;
-import org.hibernate.type.CollectionType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,185 +47,185 @@ import java.util.*;
  * @author Wolfgang Jung (w.jung@micromata.de)
  */
 public class DeltaSetCalculator {
-  private static final Logger log = LoggerFactory.getLogger(DeltaSetCalculator.class);
+    private static final Logger log = LoggerFactory.getLogger(DeltaSetCalculator.class);
 
-  private DeltaSetCalculator() {
-    // ne rien faire
-  }
-
-  /*
-   * Un calcul spécifique à Hibernate. Utilise les valeurs passées à la méthode Hibernate Interceptor.onFlushDirty() pour effectuer le
-   * calcul.
-   *
-   * @param propertyNames Un tableau de chaînes de tous les noms de propriétés passés à la méthode onFlushDirty. @param
-   * previousState Le tableau d'objets représentant l'état précédent des propriétés nommées dans le tableau propertyNames. @param
-   * currentState Le tableau d'objets représentant l'état actuel des propriétés nommées dans le tableau propertyNames. @return Le DeltaSet représentant les changements rencontrés dans les états des propriétés.
-   */
-  public static DeltaSet calculateDeltaSet(SessionFactory sf, Set<String> validPropertyNames,
-                                           Set<String> invalidPropertyNames,
-                                           Serializable entityId, Object entity, String[] propertyNames, Object[] previousState, Object[] currentState) {
-    if (previousState == null) {
-      previousState = new Object[currentState.length];
-    }
-    if (propertyNames == null || currentState == null) {
-      throw new IllegalArgumentException("Les trois tableaux passés pour calculer un delta-set doivent être non nuls");
-    }
-    if (propertyNames.length != previousState.length && previousState.length != currentState.length) {
-      throw new IllegalArgumentException("Les trois tableaux passés pour calculer un delta-set doivent avoir la même longueur");
+    private DeltaSetCalculator() {
+        // ne rien faire
     }
 
-    DeltaSet deltaSet = new DeltaSet();
-    deltaSet.setEntity(entity.getClass());
-    deltaSet.setId(entityId);

c1d14ecdb

Travail de migration en cours...
c1d14ecdb144fed4ddd60af928fa1c76c5074f62
diff --git a/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java b/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
index 34ffe9af3..2d4f6b1ae 100644
--- a/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
+++ b/projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java
@@ -203,11 +203,11 @@ public class DeltaSetCalculator {
       } else if (propertyType.isArray()) {
         log.debug("La propriété rencontrée est un type tableau");
         delta = getArrayDelta(sf, propertyName, propertyType, oldValue, newValue, delta);
-      } else if (sf.getClassMetadata(propertyType) != null) {
+      /*} else if (sf.getClassMetadata(propertyType) != null) {
         log.debug("La propriété rencontrée est un type d'association");
         if (!areEqual(oldValue, newValue, sf)) {
           delta = new AssociationPropertyDelta(sf, propertyName, propertyType, oldValue, newValue);
-        }
+        }*/
       } else {
         log.debug("La propriété était une propriété simple");
         if (!areEqual(oldValue, newValue, sf)) {
@@ -229,15 +229,15 @@ public class DeltaSetCalculator {
     if (element == null) {
       return null;
     }
-    try {
+/*    try {
       ClassMetadata classMetadata = factory.getClassMetadata(element.getClass());
       if (classMetadata != null) {
-        return classMetadata.getIdentifier(element/* , EntityMode.POJO */);
+        return classMetadata.getIdentifier(element/* , EntityMode.POJO * /);
       }
     } catch (HibernateException ex) {
       log.error("Exception rencontrée " + ex, ex);
       return null;
-    }
+    }*/
     return element;
   }
 
@@ -301,7 +301,7 @@ public class DeltaSetCalculator {
       }
     }
 
-    if (Hibernate.isInitialized(oldCollectionValue) && Hibernate.isInitialized(newCollectionValue)) {
+   /* if (Hibernate.isInitialized(oldCollectionValue) && Hibernate.isInitialized(newCollectionValue)) {
       CollectionPropertyDelta collectionDelta = null;
       Class returnedClass = Object.class;
       try {
@@ -327,7 +327,8 @@ public class DeltaSetCalculator {
     } else {
       log.debug("Une (ou les deux) propriété(s) de collection n'était pas initialisée auparavant ; doit être ignorée");
     }
-    return delta;
+    return delta;*/
+    return null;
   }
 
   public static boolean areEqual(Object obj1, Object obj2, SessionFactory sf) {
@@ -360,20 +361,20 @@ public class DeltaSetCalculator {
    * @return
    */