EN · DE · RU · FR · ES

#360: DeltaSetCalculator.java

projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java Clase Java, projectforge-business/src/main/java/de/micromata/hibernate/history/delta/DeltaSetCalculator.java 378 líneas · 271 código · 81 comentarios · 26 en blanco
Propósito: Archivo fuente: hibernate/history/delta/DeltaSetCalculator.java. DeltaSetCalculator.java es parte de la aplicación de gestión de proyectos de código abierto ProjectForge.

Fuente (primeras 100 líneas)

/////////////////////////////////////////////////////////////////////////////
//
// Project ProjectForge Community Edition
//         www.projectforge.org
//
// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge tiene doble licencia.
//
// Esta edición comunitaria es software libre; puedes redistribuirla y/o
// modificarla bajo los términos de la Licencia Pública General GNU publicada
// por la Free Software Foundation; versión 3 de la Licencia.
//
// Esta edición comunitaria se distribuye con la esperanza de que sea útil,
// pero SIN NINGUNA GARANTÍA; sin siquiera la garantía implícita de
// COMERCIABILIDAD o IDONEIDAD PARA UN PROPÓSITO PARTICULAR. Consulte la Licencia General
// Pública de GNU para más detalles.
//
// Deberías haber recibido una copia de la Licencia Pública General GNU junto
// con este programa; si no, visita 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.*;

/**
 * Heredado para persistencia XML de BD.
 *
 * @author Wolfgang Jung (w.jung@micromata.de)
 */
public class DeltaSetCalculator {
    private static final Logger log = LoggerFactory.getLogger(DeltaSetCalculator.class);

    private DeltaSetCalculator() {
        // no hacer nada
    }

    /*
     * Un cálculo específico de Hibernate. Utiliza los valores pasados al método Hibernate Interceptor.onFlushDirty() para realizar el
     * cálculo.
     *
     * @param propertyNames Una matriz de cadenas con todos los nombres de propiedades pasados al método onFlushDirty. @param
     * previousState La matriz de objetos que representa el estado anterior de las propiedades nombradas en la matriz
     * propertyNames. @param currentState La matriz de objetos que representa el estado actual de las propiedades nombradas en la
     * matriz propertyNames. @return El DeltaSet que representa los cambios encontrados en los estados de las propiedades.
     */
    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("Las tres matrices pasadas para calcular un delta-set deben ser no nulas");
        }
        if (propertyNames.length != previousState.length && previousState.length != currentState.length) {
            throw new IllegalArgumentException("Las tres matrices pasadas para calcular un delta-set deben tener la misma longitud");
        }

        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("Error al determinar el delta-set", t);
        } finally {
            log.debug("Determinación del delta-set completada");
        }
        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) {

Historial Git

868d6abb7 2025 -> 2026
63081666f Encabezados de archivos fuente: 2024-> 2025.
5f9bbfbd3 Corrección de errores tipográficos en el directorio projectforge-business
a33f8f203 Migración en curso... (todas las pruebas de todos los paquetes: OK).
c1d14ecdb Migración en curso...

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 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

63081666f

Encabezados de archivos fuente: 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 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

5f9bbfbd3

Corrección de errores tipográficos en el directorio 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 {
 
             // Try to determine the property type from either currentState or,
             // previousState... Side-note: if both are null, we cannot determine
-            // the propertyType, but thats OK as no change has occurred (null==null)
+            // the propertyType, but that's OK as no change has occurred (null==null)
             if (!isCurrentNull) {
                 propertyType = propertyCurrentState.getClass();
             } else if (!wasPreviousNull) {
@@ -148,7 +148,7 @@ public class DeltaSetCalculator {
     }
 
     /**
-     * General use DeltaSet caluclator.
+     * General use DeltaSet calculator.
      */
     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 occured:" + ex, ex);
+      log.error("Exception occurred:" + ex, ex);
     }*/
 
         return obj1.equals(obj2);

a33f8f203

Migración en curso... (todas las pruebas de todos los paquetes: 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() {
-    // do nothing
-  }
-
-  /*
-   * A hibernate-specific calculation. Uses the values passed to the Hibernate Interceptor.onFlushDirty() to perform the
-   * calculation.
-   *
-   * @param propertyNames A string array of all the property names passed in to the obFlushDirty method. @param
-   * previousState The Object array representing the previous state of the properties named in the propertyNames
-   * array. @param currentState The Object array representing the current state of the properties named in the
-   * propertyNames array. @return The DeltaSet representing the changes encountered in the property states.
-   */
-  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("All three arrays passed to calculate a delta-set must be non-null");
-    }
-    if (propertyNames.length != previousState.length && previousState.length != currentState.length) {
-      throw new IllegalArgumentException("All three arrays passed to calculate a delta-set must be of the same length");
+    private DeltaSetCalculator() {
+        // no hacer nada
     }
 
-    DeltaSet deltaSet = new DeltaSet();
-    deltaSet.setEntity(entity.getClass());
-    deltaSet.setId(entityId);

c1d14ecdb

Migración en curso...
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("Encountered property is an array type");
         delta = getArrayDelta(sf, propertyName, propertyType, oldValue, newValue, delta);
-      } else if (sf.getClassMetadata(propertyType) != null) {
+      /*} else if (sf.getClassMetadata(propertyType) != null) {
         log.debug("Encountered property is an association type");
         if (!areEqual(oldValue, newValue, sf)) {
           delta = new AssociationPropertyDelta(sf, propertyName, propertyType, oldValue, newValue);
-        }
+        }*/
       } else {
         log.debug("Property was a simple property");
         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 encountered " + 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("One (or both) of a collection property was not previously initialized; have to skip");
     }
-    return delta;
+    return delta;*/
+    return null;
   }
 
   public static boolean areEqual(Object obj1, Object obj2, SessionFactory sf) {
@@ -360,20 +361,20 @@ public class DeltaSetCalculator {
    * @return
    */