Example usage for org.hibernate.collection.internal PersistentMap PersistentMap

List of usage examples for org.hibernate.collection.internal PersistentMap PersistentMap

Introduction

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

Prototype

@Deprecated
public PersistentMap(SessionImplementor session, Map map) 

Source Link

Document

Instantiates a non-lazy map (the underlying map is constructed from the incoming map reference).

Usage

From source file:org.granite.hibernate4.HibernateExternalizer.java

License:Open Source License

protected PersistentCollection newHibernateCollection(AbstractExternalizablePersistentCollection value,
        Property field) {/* w ww. j a v a2s. c  o m*/
    final Type target = field.getType();
    final boolean initialized = value.isInitialized();
    final String metadata = value.getMetadata();
    final boolean dirty = value.isDirty();
    final boolean sorted = (SortedSet.class.isAssignableFrom(TypeUtil.classOfType(target))
            || SortedMap.class.isAssignableFrom(TypeUtil.classOfType(target)));

    Comparator<?> comparator = null;
    if (sorted && field.isAnnotationPresent(Sort.class)) {
        Sort sort = field.getAnnotation(Sort.class);
        if (sort.type() == SortType.COMPARATOR) {
            try {
                comparator = TypeUtil.newInstance(sort.comparator(), Comparator.class);
            } catch (Exception e) {
                throw new RuntimeException("Could not create instance of Comparator: " + sort.comparator());
            }
        }
    }

    PersistentCollection coll = null;
    if (value instanceof ExternalizablePersistentSet) {
        if (initialized) {
            Set<?> set = ((ExternalizablePersistentSet) value).getContentAsSet(target, comparator);
            coll = (sorted ? new PersistentSortedSet(null, (SortedSet<?>) set) : new PersistentSet(null, set));
        } else
            coll = (sorted ? new PersistentSortedSet() : new PersistentSet());
    } else if (value instanceof ExternalizablePersistentBag) {
        if (initialized) {
            List<?> bag = ((ExternalizablePersistentBag) value).getContentAsList(target);
            coll = new PersistentBag(null, bag);
        } else
            coll = new PersistentBag();
    } else if (value instanceof ExternalizablePersistentList) {
        if (initialized) {
            List<?> list = ((ExternalizablePersistentList) value).getContentAsList(target);
            coll = new PersistentList(null, list);
        } else
            coll = new PersistentList();
    } else if (value instanceof ExternalizablePersistentMap) {
        if (initialized) {
            Map<?, ?> map = ((ExternalizablePersistentMap) value).getContentAsMap(target, comparator);
            coll = (sorted ? new PersistentSortedMap(null, (SortedMap<?, ?>) map)
                    : new PersistentMap(null, map));
        } else
            coll = (sorted ? new PersistentSortedMap() : new PersistentMap());
    } else
        throw new RuntimeException("Illegal externalizable persitent class: " + value);

    if (metadata != null && serializeMetadata != SerializeMetadata.NO
            && (serializeMetadata == SerializeMetadata.YES || !initialized)) {
        String[] toks = metadata.split(":", 3);
        if (toks.length != 3)
            throw new RuntimeException("Invalid collection metadata: " + metadata);
        Serializable key = deserializeSerializable(StringUtil.hexStringToBytes(toks[0]));
        Serializable snapshot = deserializeSerializable(StringUtil.hexStringToBytes(toks[1]));
        String role = toks[2];
        coll.setSnapshot(key, role, snapshot);
    }

    if (initialized && dirty)
        coll.dirty();

    return coll;
}

From source file:org.granite.hibernate4.jmf.PersistentMapCodec.java

License:Open Source License

public PersistentMap newInstance(ExtendedObjectInput in, String className)
        throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException,
        InvocationTargetException, SecurityException, NoSuchMethodException {

    PersistentCollectionSnapshot snapshot = new JMFPersistentCollectionSnapshot(null);
    snapshot.readInitializationData(in);
    return (snapshot.isInitialized() ? new PersistentMap(null, new HashMap<Object, Object>())
            : new PersistentMap(null));
}