All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.avaje.ebean.common.ModifyHolder Maven / Gradle / Ivy

There is a newer version: 8.1.1
Show newest version
package com.avaje.ebean.common;

import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * Holds sets of additions and deletions from a 'owner' List Set or Map.
 * 

* These sets of additions and deletions are used to support persisting * ManyToMany relationships. The additions becoming inserts into the * intersection table and the removals becoming deletes from the intersection * table. *

*/ class ModifyHolder implements Serializable { private static final long serialVersionUID = 2572572897923801083L; /** * Deletions list for manyToMany persistence. */ private Set modifyDeletions = new LinkedHashSet(); /** * Additions list for manyToMany persistence. */ private Set modifyAdditions = new LinkedHashSet(); void reset() { modifyDeletions = new LinkedHashSet(); modifyAdditions = new LinkedHashSet(); } /** * Used by BeanList.addAll() methods. */ void modifyAdditionAll(Collection c) { if (c != null) { for (E e : c) { modifyAddition(e); } } } void modifyAddition(E bean) { if (bean != null) { // If it is to delete then just remove the deletion if (!modifyDeletions.remove(bean)) { // Insert modifyAdditions.add(bean); } } } @SuppressWarnings("unchecked") void modifyRemoval(Object bean) { if (bean != null) { // If it is to be added then just remove the addition if (!modifyAdditions.remove(bean)) { modifyDeletions.add((E) bean); } } } Set getModifyAdditions() { return modifyAdditions; } Set getModifyRemovals() { return modifyDeletions; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy