Example usage for org.hibernate.collection.internal PersistentList clearDirty

List of usage examples for org.hibernate.collection.internal PersistentList clearDirty

Introduction

In this page you can find the example usage for org.hibernate.collection.internal PersistentList clearDirty.

Prototype

@Override
    public final void clearDirty() 

Source Link

Usage

From source file:com.erinors.hpb.server.handler.ListHandler.java

License:Apache License

@Override
public Object merge(MergingContext context, Object object) {
    if (!(object instanceof List)) {
        return null;
    }// w w w.  j  a  v  a 2  s  .c  o  m

    List<?> source = (List<?>) object;
    List<?> result;

    if (source instanceof UninitializedPersistentList) {
        result = new PersistentList(context.getSessionImplementor());
        context.addProcessedObject(object, result);
    } else if (source instanceof com.erinors.hpb.shared.impl.PersistentList) {
        PersistentList list = new PersistentList(context.getSessionImplementor(), new ArrayList<Object>());
        context.addProcessedObject(object, list);

        for (Object element : source) {
            list.add(context.merge(element));
        }

        if (((com.erinors.hpb.shared.impl.PersistentList<?>) source).isDirty()) {
            list.dirty();
        } else {
            list.clearDirty();
        }

        result = list;
    } else {
        List<Object> list = new ArrayList<Object>(source.size());
        context.addProcessedObject(object, list);

        for (Object element : source) {
            list.add(context.merge(element));
        }

        result = list;
    }

    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}/* w w w .j  a va2  s.  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;
}