Example usage for org.hibernate.persister.collection CollectionPersister getFactory

List of usage examples for org.hibernate.persister.collection CollectionPersister getFactory

Introduction

In this page you can find the example usage for org.hibernate.persister.collection CollectionPersister getFactory.

Prototype

SessionFactoryImplementor getFactory();

Source Link

Usage

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override//ww  w .  j av  a 2s.c om
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
    MAList<E> baseList = this.getBase();
    ArrayList<E> clonedList = new ArrayList<E>(baseList.unifiedComparator(), baseList.size());
    Iterator<E> iter = baseList.iterator();
    while (iter.hasNext()) {
        E deepCopy = (E) persister.getElementType().deepCopy(iter.next(), persister.getFactory());
        clonedList.add(deepCopy);
    }
    return clonedList;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override// w  ww.  ja  v  a2 s  . c  o m
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
    MAMap<K, V> baseMap = this.getBase();
    Map<K, V> clonedMap;
    UnifiedComparator<? super K> keyUnifiedComparator = baseMap.keyUnifiedComparator();
    if (keyUnifiedComparator.comparator() != null) {
        clonedMap = new TreeMap<K, V>(keyUnifiedComparator.comparator(), baseMap.valueUnifiedComparator());
    } else {
        clonedMap = new HashMap<K, V>(keyUnifiedComparator.equalityComparator(),
                baseMap.valueUnifiedComparator(), baseMap.size() + 1, 1.F);
    }
    Iterator<Entry<K, V>> iter = baseMap.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<K, V> e = (Entry<K, V>) iter.next();
        final V copy = (V) persister.getElementType().deepCopy(e.getValue(), persister.getFactory());
        clonedMap.put(e.getKey(), copy);
    }
    return (Serializable) clonedMap;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w ww.j  av a2 s.  c  o  m*/
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
    XSet<E> baseSet = this.getBase();
    UnifiedComparator<? super E> unifiedComparator = baseSet.unifiedComparator();
    Map<E, E> clonedMap;
    if (unifiedComparator.comparator() != null) {
        clonedMap = new TreeMap<E, E>(unifiedComparator.comparator(), unifiedComparator.comparator());
    } else {
        clonedMap = new HashMap<E, E>(unifiedComparator.equalityComparator(),
                unifiedComparator.equalityComparator(), baseSet.size() + 1, 1.F);
    }
    for (E e : baseSet) {
        E copied = (E) persister.getElementType().deepCopy(e, persister.getFactory());
        clonedMap.put(copied, copied);
    }
    return (Serializable) clonedMap;

}