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

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

Introduction

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

Prototype

Type getIndexType();

Source Link

Document

Get the "index" type for a list or map (optional operation)

Usage

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w  w w .  ja  va  2 s . c  om*/
public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner)
        throws HibernateException {
    Serializable[] array = (Serializable[]) disassembled;
    int size = array.length;
    beforeInitialize(persister, size);
    MAMap<K, V> baseMap = this.getBase();
    for (int i = 0; i < size; i += 2) {
        baseMap.put((K) persister.getIndexType().assemble(array[i], getSession(), owner),
                (V) persister.getElementType().assemble(array[i + 1], getSession(), owner));
    }
}

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

License:Open Source License

@Override
public Serializable disassemble(CollectionPersister persister) throws HibernateException {
    MAMap<K, V> baseMap = this.getBase();
    Serializable[] result = new Serializable[baseMap.size() << 1];
    Iterator<Entry<K, V>> iter = baseMap.entrySet().iterator();
    int i = 0;/*w ww.j a  va  2s  .  c  om*/
    while (iter.hasNext()) {
        Entry<K, V> e = iter.next();
        result[i++] = persister.getIndexType().disassemble(e.getKey(), getSession(), null);
        result[i++] = persister.getElementType().disassemble(e.getValue(), getSession(), null);
    }
    return result;
}

From source file:org.babyfish.hibernate.collection.type.AbstractMAMapType.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*from   w ww.  ja  v  a 2 s.c  o  m*/
public Object onReplaceElements(Object original, Object target, CollectionPersister persister, Object owner,
        Map copyCache, SessionImplementor session) throws HibernateException {

    // Must before result.clear()
    Iterator itr = this.getClonedIterator(((java.util.Map) original).entrySet());

    /*
     *  TODO:
     *  This code is copy from hibernate's CollectionType class.
     *  In its source code, hibernate's author have wrote another 
     *  _TODO_ comment "does not work for EntityMode.DOM4J yet!"
     *  So here, I must check the source code of newest version 
     *  hibernate to make sure whether these code should be changed. 
     */
    java.util.Map result = (java.util.Map) target;
    result.clear();

    while (itr.hasNext()) {
        java.util.Map.Entry me = (java.util.Map.Entry) itr.next();
        Object key = persister.getIndexType().replace(me.getKey(), null, session, owner, copyCache);
        Object value = persister.getElementType().replace(me.getValue(), null, session, owner, copyCache);
        result.put(key, value);
    }

    return result;
}

From source file:tools.xor.HibernateProperty.java

License:Apache License

@Override
public void init(DataAccessService das) {
    HibernateDAS hibernateDAS = (HibernateDAS) das;

    if (isMany()) {
        if (hibernateProperty.getType().isCollectionType()) {
            CollectionType collType = (CollectionType) hibernateProperty.getType();
            CollectionPersister cp = HibernateUtil.getCollectionPersister(hibernateDAS.getSessionFactory(),
                    collType);//from ww  w .j  a  va  2 s  .  com
            keyType = (cp.getIndexType() == null) ? null : das.getType(cp.getIndexType().getReturnedClass());

            elementType = das.getType(cp.getElementType().getReturnedClass());
        }
    }
}