List of usage examples for org.hibernate.collection.internal PersistentList setSnapshot
@Override
public void setSnapshot(Serializable key, String role, Serializable snapshot)
From source file:org.jspresso.framework.application.backend.persistence.hibernate.HibernateBackendController.java
License:Open Source License
/** * This method wraps transient collections in the equivalent hibernate ones. * {@inheritDoc}// w ww. ja v a 2s. c o m */ @SuppressWarnings("unchecked") @Override protected <E> Collection<E> wrapDetachedCollection(IEntity owner, Collection<E> detachedCollection, Collection<E> snapshotCollection, String role) { Collection<E> varSnapshotCollection = snapshotCollection; if (!(detachedCollection instanceof PersistentCollection)) { String collectionRoleName = HibernateHelper.getHibernateRoleName(getComponentContract(owner), role); if (collectionRoleName == null) { // it is not an hibernate managed collection (e.g. "detachedEntities") return detachedCollection; } if (detachedCollection instanceof Set) { PersistentSet persistentSet = new PersistentSet(null, (Set<?>) detachedCollection); changeCollectionOwner(persistentSet, owner); HashMap<Object, Object> snapshot = new HashMap<>(); if (varSnapshotCollection == null) { persistentSet.clearDirty(); varSnapshotCollection = detachedCollection; } for (Object snapshotCollectionElement : varSnapshotCollection) { snapshot.put(snapshotCollectionElement, snapshotCollectionElement); } persistentSet.setSnapshot(owner.getId(), collectionRoleName, snapshot); return persistentSet; } else if (detachedCollection instanceof List) { PersistentList persistentList = new PersistentList(null, (List<?>) detachedCollection); changeCollectionOwner(persistentList, owner); ArrayList<Object> snapshot = new ArrayList<>(); if (varSnapshotCollection == null) { persistentList.clearDirty(); varSnapshotCollection = detachedCollection; } for (Object snapshotCollectionElement : varSnapshotCollection) { snapshot.add(snapshotCollectionElement); } persistentList.setSnapshot(owner.getId(), collectionRoleName, snapshot); return persistentList; } } else { if (varSnapshotCollection == null) { ((PersistentCollection) detachedCollection).clearDirty(); } else { ((PersistentCollection) detachedCollection).dirty(); } } return detachedCollection; }