CollectionPropertyDelta.javaprojectforge-business/src/main/java/de/micromata/hibernate/history/delta/CollectionPropertyDelta.java contenant du code Java pour la couche Composant.Paquetage : de.micromata.hibernate.history.delta
Classes : CollectionPropertyDelta
Étend : PropertyDelta
Méthodes (5) : calculateAdditionsAndRemovals, toString, getNewObjectValue, splitElements, getOldObjectValue
Importations : 4 paquetages
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.*;
/**
* Héritage utilisé pour la persistance XML de la base de données.
*
* @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()
{
// ne rien faire
}
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)
{
// //////////////////////////////////////////////////////////////////////
// D'abord, déterminer les ajouts
if (newValue != null) {
additions.addAll(newValue);
}
if (oldValue != null) {
additions.removeAll(oldValue);
}
// //////////////////////////////////////////////////////////////////////
// Ensuite, déterminer les suppressions
if (oldValue != null) {
removals.addAll(oldValue);
}
if (newValue != null) {
removals.removeAll(newValue);
}
}
@Override
public String toString()
{
return "modifications de " + propertyName + " nouveau=" + newValue + " ancien=" + 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 En-têtes des fichiers source : 2024 -> 2025. b6092df09 Droits d'auteur 2023 -> 2024 ab45d51fa Droits d'auteur 2001-2022 -> 2001-2023. 5f7ef41b8 Droits d'auteur 2021 -> 2022