use of org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData in project hibernate-orm by hibernate.
the class AbstractCollectionMapper method mapCollectionChanges.
/**
* Map collection changes using the collection element type equality functionality.
*
* @param session The session.
* @param newColl The new persistent collection.
* @param oldColl The old collection.
* @param id The owning entity identifier.
* @param collectionPersister The collection persister.
* @return the persistent collection changes.
*/
private List<PersistentCollectionChangeData> mapCollectionChanges(SessionImplementor session, PersistentCollection newColl, Serializable oldColl, Serializable id, CollectionPersister collectionPersister) {
final List<PersistentCollectionChangeData> collectionChanges = new ArrayList<PersistentCollectionChangeData>();
// Comparing new and old collection content.
final Collection newCollection = getNewCollectionContent(newColl);
final Collection oldCollection = getOldCollectionContent(oldColl);
// take the new collection and remove any that exist in the old collection.
// take the resulting Set<> and generate ADD changes.
final Set<Object> added = buildCollectionChangeSet(newColl, newCollection);
if (oldColl != null && collectionPersister != null) {
for (Object object : oldCollection) {
for (Iterator addedIt = added.iterator(); addedIt.hasNext(); ) {
Object object2 = addedIt.next();
if (collectionPersister.getElementType().isSame(object, object2)) {
addedIt.remove();
break;
}
}
}
}
addCollectionChanges(session, collectionChanges, added, RevisionType.ADD, id);
// take the old collection and remove any that exist in the new collection.
// take the resulting Set<> and generate DEL changes.
final Set<Object> deleted = buildCollectionChangeSet(oldColl, oldCollection);
if (newColl != null && collectionPersister != null) {
for (Object object : newCollection) {
for (Iterator deletedIt = deleted.iterator(); deletedIt.hasNext(); ) {
Object object2 = deletedIt.next();
if (collectionPersister.getElementType().isSame(object, object2)) {
deletedIt.remove();
break;
}
}
}
}
addCollectionChanges(session, collectionChanges, deleted, RevisionType.DEL, id);
return collectionChanges;
}
use of org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData in project hibernate-orm by hibernate.
the class AbstractCollectionMapper method mapCollectionChanges.
/**
* Map collection changes using hash identity.
*
* @param session The session.
* @param newColl The new persistent collection.
* @param oldColl The old collection.
* @param id The owning entity identifier.
* @return the persistent collection changes.
*/
@SuppressWarnings("unchecked")
private List<PersistentCollectionChangeData> mapCollectionChanges(SessionImplementor session, PersistentCollection newColl, Serializable oldColl, Serializable id) {
final List<PersistentCollectionChangeData> collectionChanges = new ArrayList<PersistentCollectionChangeData>();
// Comparing new and old collection content.
final Collection newCollection = getNewCollectionContent(newColl);
final Collection oldCollection = getOldCollectionContent(oldColl);
final Set<Object> added = buildCollectionChangeSet(newColl, newCollection);
// removeAll in AbstractSet has an implementation that is hashcode-change sensitive (as opposed to addAll).
if (oldColl != null) {
added.removeAll(new HashSet(oldCollection));
}
addCollectionChanges(session, collectionChanges, added, RevisionType.ADD, id);
final Set<Object> deleted = buildCollectionChangeSet(oldColl, oldCollection);
// The same as above - re-hashing new collection.
if (newColl != null) {
deleted.removeAll(new HashSet(newCollection));
}
addCollectionChanges(session, collectionChanges, deleted, RevisionType.DEL, id);
return collectionChanges;
}
Aggregations