Java 类org.hibernate.type.MapType 实例源码

项目:ix3    文件:MetaDataImplHibernate.java   
@Override
public es.logongas.ix3.dao.metadata.CollectionType getCollectionType() {
    ClassMetadata classMetadata = getClassMetadata();
    if (classMetadata == null) {
        throw new RuntimeException("No existen los metadatos");
    }

    if (type instanceof SetType) {
        return es.logongas.ix3.dao.metadata.CollectionType.Set;
    } else if (type instanceof ListType) {
        return es.logongas.ix3.dao.metadata.CollectionType.List;
    } else if (type instanceof MapType) {
        return es.logongas.ix3.dao.metadata.CollectionType.Map;
    } else {
        return null;
    }
}
项目:hibernate-semantic-query    文件:PersisterHelper.java   
public static CollectionClassification interpretCollectionClassification(CollectionType collectionType) {
    if ( collectionType instanceof BagType
            || collectionType instanceof IdentifierBagType ) {
        return CollectionClassification.BAG;
    }
    else if ( collectionType instanceof ListType
            || collectionType instanceof ArrayType ) {
        return CollectionClassification.LIST;
    }
    else if ( collectionType instanceof SetType
            || collectionType instanceof OrderedSetType
            || collectionType instanceof SortedSetType ) {
        return CollectionClassification.SET;
    }
    else if ( collectionType instanceof MapType
            || collectionType instanceof OrderedMapType
            || collectionType instanceof SortedMapType ) {
        return CollectionClassification.MAP;
    }
    else {
        final Class javaType = collectionType.getReturnedClass();
        if ( Set.class.isAssignableFrom( javaType ) ) {
            return CollectionClassification.SET;
        }
        else if ( Map.class.isAssignableFrom( javaType ) ) {
            return CollectionClassification.MAP;
        }
        else if ( List.class.isAssignableFrom( javaType ) ) {
            return CollectionClassification.LIST;
        }

        return CollectionClassification.BAG;
    }
}
项目:open-cyclos    文件:HibernateQueryHandler.java   
@SuppressWarnings("unchecked")
public void resolveReferences(final Entity entity) {
    final ClassMetadata meta = getClassMetaData(entity);
    final String[] names = meta.getPropertyNames();
    final Type[] types = meta.getPropertyTypes();
    for (int i = 0; i < types.length; i++) {
        final Type type = types[i];
        final String name = names[i];
        if (type instanceof EntityType) {
            // Properties that are relationships to other entities
            Entity rel = PropertyHelper.get(entity, name);
            if (rel instanceof EntityReference) {
                rel = getHibernateTemplate().load(EntityHelper.getRealClass(rel), rel.getId());
                PropertyHelper.set(entity, name, rel);
            }
        } else if (type instanceof CollectionType && !(type instanceof MapType)) {
            // Properties that are collections of other entities
            final Collection<?> current = PropertyHelper.get(entity, name);
            if (current != null && !(current instanceof PersistentCollection)) {
                // We must check that the collection is made of entities, since Hibernate supports collections os values
                boolean isEntityCollection = true;
                final Collection<Entity> resolved = ClassHelper.instantiate(current.getClass());
                for (final Object object : current) {
                    if (object != null && !(object instanceof Entity)) {
                        isEntityCollection = false;
                        break;
                    }
                    Entity e = (Entity) object;
                    if (object instanceof EntityReference) {
                        e = getHibernateTemplate().load(EntityHelper.getRealClass(e), e.getId());
                    }
                    resolved.add(e);
                }
                if (isEntityCollection) {
                    PropertyHelper.set(entity, name, resolved);
                }
            }
        }
    }
}