CollectionPropertyDelta.javaprojectforge-business/src/main/java/de/micromata/hibernate/history/delta/CollectionPropertyDelta.java que contiene código Java para la capa de Componente.Paquete: de.micromata.hibernate.history.delta
Clases: CollectionPropertyDelta
Extiende: PropertyDelta
Métodos (5): calculateAdditionsAndRemovals, toString, getNewObjectValue, splitElements, getOldObjectValue
Importaciones: 4 paquetes
package de.micromata.hibernate.history.delta;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Session;
import java.util.*;
/**
* Legado utilizado para persistencia XML de BD.
*
* @author Wolfgang Jung (w.jung@micromata.de)
*
*/
public class CollectionPropertyDelta extends PropertyDelta
{
private transient Set<Object> additions = new HashSet<>();
private transient Set<Object> removals = new HashSet<>();
protected CollectionPropertyDelta()
{
// no hacer nada
}
public CollectionPropertyDelta(String propertyName, Class<?> propertyType, Collection<Object> oldValue,
Collection<Object> newValue)
{
this.propertyName = propertyName;
this.propertyType = ClassUtils.getShortClassName(propertyType);
calculateAdditionsAndRemovals(oldValue, newValue);
this.oldValue = StringUtils.join(removals.iterator(), ",");
this.newValue = StringUtils.join(additions.iterator(), ",");
}
private void calculateAdditionsAndRemovals(Collection<Object> oldValue, Collection<Object> newValue)
{
// //////////////////////////////////////////////////////////////////////
// Primero, determinar adiciones
if (newValue != null) {
additions.addAll(newValue);
}
if (oldValue != null) {
additions.removeAll(oldValue);
}
// //////////////////////////////////////////////////////////////////////
// Luego, determinar eliminaciones
if (oldValue != null) {
removals.addAll(oldValue);
}
if (newValue != null) {
removals.removeAll(newValue);
}
}
@Override
public String toString()
{
return "cambios de " + propertyName + " nuevo=" + newValue + " antiguo=" + oldValue;
}
@Override
public Object getNewObjectValue(final Session session)
{
return splitElements(getNewValue(), session);
}
private List<Object> splitElements(final String keyList, final Session session)
{
List<Object> entityList = new ArrayList<>();
if (!StringUtils.isEmpty(keyList)) {
for (String key : keyList.split(",")) {
if (StringUtils.isEmpty(key)) {
continue;
}
entityList.add(loadItem(propertyType, key, session));
}
}
return entityList;
}
@Override
public Object getOldObjectValue(final Session session)
{
return splitElements(getOldValue(), session);
}
}
868d6abb7 2025 -> 2026 63081666f Encabezados de archivos fuente: 2024-> 2025. b6092df09 Derechos de autor 2023 -> 2024 ab45d51fa Derechos de autor 2001-2022 -> 2001-2023. 5f7ef41b8 Derechos de autor 2021 -> 2022