Example usage for org.hibernate.type Type isDirty

List of usage examples for org.hibernate.type Type isDirty

Introduction

In this page you can find the example usage for org.hibernate.type Type isDirty.

Prototype

boolean isDirty(Object old, Object current, SharedSessionContractImplementor session) throws HibernateException;

Source Link

Document

Should the parent be considered dirty, given both the old and current value?

Usage

From source file:org.babyfish.hibernate.collection.spi.persistence.ListBasePersistence.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  ww w.  j ava 2  s  .co  m*/
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
    List<E> baseList = this.getBase();
    List<E> sn = (List<E>) getSnapshot();
    Type elementType = persister.getElementType();
    if (sn.size() != baseList.size()) {
        return false;
    }
    Iterator<E> iter = baseList.iterator();
    Iterator<E> sniter = sn.iterator();
    while (iter.hasNext()) {
        if (elementType.isDirty(iter.next(), sniter.next(), getSession())) {
            return false;
        }
    }
    return true;
}

From source file:org.babyfish.hibernate.collection.spi.persistence.ListBasePersistence.java

License:Open Source License

@SuppressWarnings("unchecked")
public boolean needsUpdating(Object entry, int i, Type elemType) throws HibernateException {
    final List<E> sn = (List<E>) this.getSnapshot();
    List<E> list = this.getBase();
    return i < sn.size() && sn.get(i) != null && list.get(i) != null
            && elemType.isDirty(list.get(i), sn.get(i), getSession());
}

From source file:org.babyfish.hibernate.collection.spi.persistence.MapBasePersistence.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  w w w .ja  va2s . c o m*/
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
    Type elementType = persister.getElementType();
    XMap<K, V> snapshotMap = (XMap<K, V>) this.getSnapshot();
    MAMap<K, V> baseMap = this.getBase();
    if (snapshotMap.size() != baseMap.size()) {
        return false;
    }
    Iterator<Entry<K, V>> iter = baseMap.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<K, V> entry = iter.next();
        if (elementType.isDirty(entry.getValue(), snapshotMap.get(entry.getKey()), this.getSession())) {
            return false;
        }
    }
    return true;
}

From source file:org.babyfish.hibernate.collection.spi.persistence.MapBasePersistence.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from  w w w.  j  a v  a2 s.c  o m
public boolean needsUpdating(Object entry, int i, Type elemType) throws HibernateException {
    final XMap<K, V> sn = (XMap<K, V>) this.getSnapshot();
    Entry<K, V> e = (Entry<K, V>) entry;
    V snValue = sn.get(e.getKey());
    return e.getValue() != null && snValue != null
            && elemType.isDirty(snValue, e.getValue(), this.getSession());
}

From source file:org.babyfish.hibernate.collection.spi.persistence.SetBasePersistence.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//w w w.j a  va 2s.  c o  m
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
    Set<E> baseSet = this.getBase();
    Type elementType = persister.getElementType();
    java.util.Map<E, E> sn = (java.util.Map<E, E>) this.getSnapshot();
    if (sn.size() != baseSet.size()) {
        return false;
    } else {
        Iterator<E> iter = baseSet.iterator();
        while (iter.hasNext()) {
            Object test = iter.next();
            Object oldValue = sn.get(test);
            if (oldValue == null || elementType.isDirty(oldValue, test, this.getSession())) {
                return false;
            }
        }
        return true;
    }
}

From source file:org.babyfish.hibernate.collection.spi.persistence.SetBasePersistence.java

License:Open Source License

@Override
public boolean needsInserting(Object entry, int i, Type elemType) throws HibernateException {
    Map<?, ?> sn = (Map<?, ?>) getSnapshot();
    Object oldValue = sn.get(entry);
    // note that it might be better to iterate the snapshot but this is safe,
    // assuming the user implements equals() properly, as required by the Set
    // contract!/*w ww . j a  v  a 2  s . c o m*/
    return oldValue == null || elemType.isDirty(oldValue, entry, this.getSession());
}

From source file:org.babyfish.hibernate.collection.spi.persistence.SetBasePersistence.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w w w. j  av  a 2 s. c  o  m*/
public Iterator<?> getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
    Set<E> baseSet = this.getBase();
    Type elementType = persister.getElementType();
    final Map<E, E> sn = (Map<E, E>) this.getSnapshot();
    List<E> deletes = new ArrayList<E>(this.unifiedComparator(), sn.size());
    Iterator<E> iter = sn.keySet().iterator();
    while (iter.hasNext()) {
        E test = iter.next();
        if (!baseSet.contains(test)) {
            // the element has been removed from the set
            deletes.add(test);
        }
    }
    iter = baseSet.iterator();
    while (iter.hasNext()) {
        E test = iter.next();
        E oldValue = sn.get(test);
        if (oldValue != null && elementType.isDirty(test, oldValue, this.getSession())) {
            // the element has changed
            deletes.add(oldValue);
        }
    }
    return deletes.iterator();
}