Search in sources :

Example 1 with SetType

use of org.hibernate.type.SetType in project hibernate-orm by hibernate.

the class CollectionMetadataGenerator method addMapper.

private void addMapper(CommonCollectionMapperData commonCollectionMapperData, MiddleComponentData elementComponentData, MiddleComponentData indexComponentData) {
    final Type type = propertyValue.getType();
    final boolean embeddableElementType = isEmbeddableElementType();
    final boolean lobMapElementType = isLobMapElementType();
    if (type instanceof SortedSetType) {
        currentMapper.addComposite(propertyAuditingData.getPropertyData(), new SortedSetCollectionMapper(commonCollectionMapperData, TreeSet.class, SortedSetProxy.class, elementComponentData, propertyValue.getComparator(), embeddableElementType, embeddableElementType));
    } else if (type instanceof SetType) {
        currentMapper.addComposite(propertyAuditingData.getPropertyData(), new BasicCollectionMapper<Set>(commonCollectionMapperData, HashSet.class, SetProxy.class, elementComponentData, embeddableElementType, embeddableElementType));
    } else if (type instanceof SortedMapType) {
        // Indexed collection, so <code>indexComponentData</code> is not null.
        currentMapper.addComposite(propertyAuditingData.getPropertyData(), new SortedMapCollectionMapper(commonCollectionMapperData, TreeMap.class, SortedMapProxy.class, elementComponentData, indexComponentData, propertyValue.getComparator(), embeddableElementType || lobMapElementType));
    } else if (type instanceof MapType) {
        // Indexed collection, so <code>indexComponentData</code> is not null.
        currentMapper.addComposite(propertyAuditingData.getPropertyData(), new MapCollectionMapper<Map>(commonCollectionMapperData, HashMap.class, MapProxy.class, elementComponentData, indexComponentData, embeddableElementType || lobMapElementType));
    } else if (type instanceof BagType) {
        currentMapper.addComposite(propertyAuditingData.getPropertyData(), new BasicCollectionMapper<List>(commonCollectionMapperData, ArrayList.class, ListProxy.class, elementComponentData, embeddableElementType, embeddableElementType));
    } else if (type instanceof ListType) {
        // Indexed collection, so <code>indexComponentData</code> is not null.
        currentMapper.addComposite(propertyAuditingData.getPropertyData(), new ListCollectionMapper(commonCollectionMapperData, elementComponentData, indexComponentData, embeddableElementType));
    } else {
        mainGenerator.throwUnsupportedTypeException(type, referencingEntityName, propertyName);
    }
}
Also used : SortedSetType(org.hibernate.type.SortedSetType) SortedMapCollectionMapper(org.hibernate.envers.internal.entities.mapper.relation.SortedMapCollectionMapper) MapCollectionMapper(org.hibernate.envers.internal.entities.mapper.relation.MapCollectionMapper) SortedSetCollectionMapper(org.hibernate.envers.internal.entities.mapper.relation.SortedSetCollectionMapper) SortedSetProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.SortedSetProxy) ArrayList(java.util.ArrayList) ListCollectionMapper(org.hibernate.envers.internal.entities.mapper.relation.ListCollectionMapper) SortedMapCollectionMapper(org.hibernate.envers.internal.entities.mapper.relation.SortedMapCollectionMapper) TreeMap(java.util.TreeMap) MapType(org.hibernate.type.MapType) SortedMapType(org.hibernate.type.SortedMapType) ListType(org.hibernate.type.ListType) ManyToOneType(org.hibernate.type.ManyToOneType) MaterializedNClobType(org.hibernate.type.MaterializedNClobType) SetType(org.hibernate.type.SetType) MaterializedClobType(org.hibernate.type.MaterializedClobType) MapType(org.hibernate.type.MapType) ComponentType(org.hibernate.type.ComponentType) SortedSetType(org.hibernate.type.SortedSetType) SortedMapType(org.hibernate.type.SortedMapType) BagType(org.hibernate.type.BagType) Type(org.hibernate.type.Type) SortedMapProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.SortedMapProxy) SetType(org.hibernate.type.SetType) SortedSetType(org.hibernate.type.SortedSetType) TreeSet(java.util.TreeSet) BagType(org.hibernate.type.BagType) BasicCollectionMapper(org.hibernate.envers.internal.entities.mapper.relation.BasicCollectionMapper) SortedMapType(org.hibernate.type.SortedMapType) ListProxy(org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.ListProxy) ListType(org.hibernate.type.ListType) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with SetType

use of org.hibernate.type.SetType in project hibernate-orm by hibernate.

the class CollectionMetadataGenerator method addCollection.

void addCollection() {
    final Type type = propertyValue.getType();
    final Value value = propertyValue.getElement();
    final boolean oneToManyAttachedType = type instanceof BagType || type instanceof SetType || type instanceof MapType || type instanceof ListType;
    final boolean inverseOneToMany = (value instanceof OneToMany) && (propertyValue.isInverse());
    final boolean owningManyToOneWithJoinTableBidirectional = (value instanceof ManyToOne) && (propertyAuditingData.getRelationMappedBy() != null);
    final boolean fakeOneToManyBidirectional = (value instanceof OneToMany) && (propertyAuditingData.getAuditMappedBy() != null);
    if (oneToManyAttachedType && (inverseOneToMany || fakeOneToManyBidirectional || owningManyToOneWithJoinTableBidirectional)) {
        // A one-to-many relation mapped using @ManyToOne and @OneToMany(mappedBy="...")
        addOneToManyAttached(fakeOneToManyBidirectional);
    } else {
        // All other kinds of relations require a middle (join) table.
        addWithMiddleTable();
    }
}
Also used : ListType(org.hibernate.type.ListType) ManyToOneType(org.hibernate.type.ManyToOneType) MaterializedNClobType(org.hibernate.type.MaterializedNClobType) SetType(org.hibernate.type.SetType) MaterializedClobType(org.hibernate.type.MaterializedClobType) MapType(org.hibernate.type.MapType) ComponentType(org.hibernate.type.ComponentType) SortedSetType(org.hibernate.type.SortedSetType) SortedMapType(org.hibernate.type.SortedMapType) BagType(org.hibernate.type.BagType) Type(org.hibernate.type.Type) SetType(org.hibernate.type.SetType) SortedSetType(org.hibernate.type.SortedSetType) BagType(org.hibernate.type.BagType) ListType(org.hibernate.type.ListType) Value(org.hibernate.mapping.Value) OneToMany(org.hibernate.mapping.OneToMany) MapType(org.hibernate.type.MapType) SortedMapType(org.hibernate.type.SortedMapType) ManyToOne(org.hibernate.mapping.ManyToOne)

Example 3 with SetType

use of org.hibernate.type.SetType in project dhis2-core by dhis2.

the class AbstractPropertyIntrospectorService method updateJoinTables.

protected void updateJoinTables() {
    if (!roleToRole.isEmpty()) {
        return;
    }
    Map<String, List<String>> joinTableToRoles = new HashMap<>();
    SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory;
    Iterator<?> collectionIterator = sessionFactory.getAllCollectionMetadata().values().iterator();
    while (collectionIterator.hasNext()) {
        CollectionPersister collectionPersister = (CollectionPersister) collectionIterator.next();
        CollectionType collectionType = collectionPersister.getCollectionType();
        if (collectionPersister.isManyToMany() && collectionType.isAssociationType()) {
            Joinable associatedJoinable = collectionType.getAssociatedJoinable(sessionFactoryImplementor);
            if (!joinTableToRoles.containsKey(associatedJoinable.getTableName())) {
                joinTableToRoles.put(associatedJoinable.getTableName(), new ArrayList<>());
            }
            joinTableToRoles.get(associatedJoinable.getTableName()).add(collectionPersister.getRole());
        } else if (collectionPersister.isInverse()) {
            if (SetType.class.isInstance(collectionType)) {
                SetType setType = (SetType) collectionType;
                setType.getAssociatedJoinable(sessionFactoryImplementor);
            }
        }
    }
    Iterator<Map.Entry<String, List<String>>> entryIterator = joinTableToRoles.entrySet().iterator();
    while (entryIterator.hasNext()) {
        Map.Entry<String, List<String>> entry = entryIterator.next();
        if (entry.getValue().size() < 2) {
            entryIterator.remove();
        }
    }
    for (Map.Entry<String, List<String>> entry : joinTableToRoles.entrySet()) {
        roleToRole.put(entry.getValue().get(0), entry.getValue().get(1));
        roleToRole.put(entry.getValue().get(1), entry.getValue().get(0));
    }
}
Also used : HashMap(java.util.HashMap) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) SetType(org.hibernate.type.SetType) CollectionType(org.hibernate.type.CollectionType) Joinable(org.hibernate.persister.entity.Joinable) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

SetType (org.hibernate.type.SetType)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BagType (org.hibernate.type.BagType)2 ComponentType (org.hibernate.type.ComponentType)2 ListType (org.hibernate.type.ListType)2 ManyToOneType (org.hibernate.type.ManyToOneType)2 MapType (org.hibernate.type.MapType)2 MaterializedClobType (org.hibernate.type.MaterializedClobType)2 MaterializedNClobType (org.hibernate.type.MaterializedNClobType)2 SortedMapType (org.hibernate.type.SortedMapType)2 SortedSetType (org.hibernate.type.SortedSetType)2 Type (org.hibernate.type.Type)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 BasicCollectionMapper (org.hibernate.envers.internal.entities.mapper.relation.BasicCollectionMapper)1