List of usage examples for org.hibernate.collection.internal PersistentSet clearDirty
@Override
public final void clearDirty()
From source file:com.erinors.hpb.server.handler.SetHandler.java
License:Apache License
@Override public Object merge(MergingContext context, Object object) { if (!(object instanceof Set)) { return null; }/*from w w w .j a va 2 s . co m*/ Set<?> source = (Set<?>) object; Set<?> result; if (source instanceof UninitializedPersistentSet) { result = new PersistentSet(context.getSessionImplementor()); context.addProcessedObject(object, result); } else if (source instanceof com.erinors.hpb.shared.impl.PersistentSet) { PersistentSet set = new PersistentSet(context.getSessionImplementor(), new HashSet<Object>()); context.addProcessedObject(object, set); for (Object element : source) { set.add(context.merge(element)); } if (((com.erinors.hpb.shared.impl.PersistentSet<?>) source).isDirty()) { set.dirty(); } else { set.clearDirty(); } result = set; } else { Set<Object> set = new HashSet<Object>(source.size()); context.addProcessedObject(object, set); for (Object element : source) { set.add(context.merge(element)); } result = set; } return result; }
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}//from www. j a va2 s . co 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; }