Search in sources :

Example 11 with AnyType

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

the class AbstractPropertyMapping method addPropertyPath.

protected void addPropertyPath(String path, Type type, String[] columns, String[] columnReaders, String[] columnReaderTemplates, String[] formulaTemplates, Mapping factory) {
    Type existingType = typesByPropertyPath.get(path);
    if (existingType != null || duplicateIncompatiblePaths.contains(path)) {
        // If types match or the new type is not an association type, there is nothing for us to do
        if (type == existingType || existingType == null || !(type instanceof AssociationType)) {
            logDuplicateRegistration(path, existingType, type);
        } else if (!(existingType instanceof AssociationType)) {
            // Workaround for org.hibernate.cfg.annotations.PropertyBinder.bind() adding a component for *ToOne ids
            logDuplicateRegistration(path, existingType, type);
        } else {
            if (type instanceof AnyType && existingType instanceof AnyType) {
            // TODO: not sure how to handle any types. For now we just return and let the first type dictate what type the property has...
            } else {
                Type commonType = null;
                MetadataImplementor metadata = (MetadataImplementor) factory;
                if (type instanceof CollectionType && existingType instanceof CollectionType) {
                    Collection thisCollection = metadata.getCollectionBinding(((CollectionType) existingType).getRole());
                    Collection otherCollection = metadata.getCollectionBinding(((CollectionType) type).getRole());
                    if (thisCollection.isSame(otherCollection)) {
                        logDuplicateRegistration(path, existingType, type);
                        return;
                    } else {
                        logIncompatibleRegistration(path, existingType, type);
                    }
                } else if (type instanceof EntityType && existingType instanceof EntityType) {
                    EntityType entityType1 = (EntityType) existingType;
                    EntityType entityType2 = (EntityType) type;
                    if (entityType1.getAssociatedEntityName().equals(entityType2.getAssociatedEntityName())) {
                        logDuplicateRegistration(path, existingType, type);
                        return;
                    } else {
                        commonType = getCommonType(metadata, entityType1, entityType2);
                    }
                } else {
                    logIncompatibleRegistration(path, existingType, type);
                }
                if (commonType == null) {
                    duplicateIncompatiblePaths.add(path);
                    typesByPropertyPath.remove(path);
                    // Set everything to empty to signal action has to be taken!
                    // org.hibernate.hql.internal.ast.tree.DotNode.dereferenceEntityJoin() is reacting to this
                    String[] empty = new String[0];
                    columnsByPropertyPath.put(path, empty);
                    columnReadersByPropertyPath.put(path, empty);
                    columnReaderTemplatesByPropertyPath.put(path, empty);
                    if (formulaTemplates != null) {
                        formulaTemplatesByPropertyPath.put(path, empty);
                    }
                } else {
                    typesByPropertyPath.put(path, commonType);
                }
            }
        }
    } else {
        typesByPropertyPath.put(path, type);
        columnsByPropertyPath.put(path, columns);
        columnReadersByPropertyPath.put(path, columnReaders);
        columnReaderTemplatesByPropertyPath.put(path, columnReaderTemplates);
        if (formulaTemplates != null) {
            formulaTemplatesByPropertyPath.put(path, formulaTemplates);
        }
    }
}
Also used : EntityType(org.hibernate.type.EntityType) OneToOneType(org.hibernate.type.OneToOneType) AnyType(org.hibernate.type.AnyType) CollectionType(org.hibernate.type.CollectionType) EntityType(org.hibernate.type.EntityType) ManyToOneType(org.hibernate.type.ManyToOneType) SpecialOneToOneType(org.hibernate.type.SpecialOneToOneType) CompositeType(org.hibernate.type.CompositeType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) AssociationType(org.hibernate.type.AssociationType) CollectionType(org.hibernate.type.CollectionType) Collection(org.hibernate.mapping.Collection) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) AnyType(org.hibernate.type.AnyType)

Example 12 with AnyType

use of org.hibernate.type.AnyType in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testIsAnyType.

@Test
public void testIsAnyType() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    assertFalse(typeFacade.isAnyType());
    AnyType anyType = new AnyType(null, null, null);
    typeFacade = FACADE_FACTORY.createType(anyType);
    assertTrue(typeFacade.isAnyType());
}
Also used : ClassType(org.hibernate.type.ClassType) AnyType(org.hibernate.type.AnyType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.jupiter.api.Test)

Example 13 with AnyType

use of org.hibernate.type.AnyType in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testIsAnyType.

@Test
public void testIsAnyType() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    assertFalse(typeFacade.isAnyType());
    AnyType anyType = new AnyType(null, null, null, true);
    typeFacade = FACADE_FACTORY.createType(anyType);
    assertTrue(typeFacade.isAnyType());
}
Also used : ClassType(org.hibernate.type.ClassType) AnyType(org.hibernate.type.AnyType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.jupiter.api.Test)

Example 14 with AnyType

use of org.hibernate.type.AnyType in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testIsAnyType.

@Test
public void testIsAnyType() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    assertFalse(typeFacade.isAnyType());
    AnyType anyType = new AnyType(null, null, null, true);
    typeFacade = FACADE_FACTORY.createType(anyType);
    assertTrue(typeFacade.isAnyType());
}
Also used : ClassType(org.hibernate.type.ClassType) AnyType(org.hibernate.type.AnyType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.jupiter.api.Test)

Example 15 with AnyType

use of org.hibernate.type.AnyType in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testIsAnyType.

@Test
public void testIsAnyType() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    assertFalse(typeFacade.isAnyType());
    AnyType anyType = new AnyType(null, null, null, true);
    typeFacade = FACADE_FACTORY.createType(anyType);
    assertTrue(typeFacade.isAnyType());
}
Also used : ClassType(org.hibernate.type.ClassType) AnyType(org.hibernate.type.AnyType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.jupiter.api.Test)

Aggregations

AnyType (org.hibernate.type.AnyType)15 IType (org.jboss.tools.hibernate.runtime.spi.IType)12 ClassType (org.hibernate.type.ClassType)11 Test (org.junit.jupiter.api.Test)11 Type (org.hibernate.type.Type)3 AssociationType (org.hibernate.type.AssociationType)2 CompositeType (org.hibernate.type.CompositeType)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)1 FetchStrategy (org.hibernate.engine.FetchStrategy)1 LoadQueryInfluencers (org.hibernate.engine.spi.LoadQueryInfluencers)1 PropertyPath (org.hibernate.loader.PropertyPath)1 Collection (org.hibernate.mapping.Collection)1 AbstractEntityPersister (org.hibernate.persister.entity.AbstractEntityPersister)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 AssociationAttributeDefinition (org.hibernate.persister.walking.spi.AssociationAttributeDefinition)1 AssociationKey (org.hibernate.persister.walking.spi.AssociationKey)1 AttributeDefinition (org.hibernate.persister.walking.spi.AttributeDefinition)1