Search in sources :

Example 96 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor 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 97 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.

the class IndividuallySchemaValidatorImplConnectionTest method testMissingEntityContainsUnqualifiedEntityName.

@Test
public void testMissingEntityContainsUnqualifiedEntityName() throws Exception {
    MetadataSources metadataSources = new MetadataSources(ssr);
    metadataSources.addAnnotatedClass(UnqualifiedMissingEntity.class);
    MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    metadata.validate();
    Map<String, Object> settings = new HashMap<>();
    ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
    DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
    connectionProvider.configure(properties());
    final GenerationTargetToDatabase schemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, new JdbcConnectionAccessImpl(connectionProvider)));
    try {
        new SchemaCreatorImpl(ssr).doCreation(metadata, serviceRegistry, settings, true, schemaGenerator);
        metadataSources = new MetadataSources(ssr);
        metadataSources.addAnnotatedClass(UnqualifiedMissingEntity.class);
        metadata = (MetadataImplementor) metadataSources.buildMetadata();
        metadata.validate();
        SchemaValidator schemaValidator = new IndividuallySchemaValidatorImpl(tool, DefaultSchemaFilter.INSTANCE);
        assertFalse(connection.getAutoCommit());
        schemaValidator.doValidation(metadata, executionOptions);
        assertFalse(connection.getAutoCommit());
    } finally {
        new SchemaDropperImpl(serviceRegistry).doDrop(metadata, false, schemaGenerator);
        serviceRegistry.destroy();
        connectionProvider.stop();
    }
}
Also used : JdbcConnectionAccessImpl(org.hibernate.testing.boot.JdbcConnectionAccessImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) MetadataSources(org.hibernate.boot.MetadataSources) SchemaValidator(org.hibernate.tool.schema.spi.SchemaValidator) IndividuallySchemaValidatorImpl(org.hibernate.tool.schema.internal.IndividuallySchemaValidatorImpl) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) DdlTransactionIsolatorTestingImpl(org.hibernate.test.util.DdlTransactionIsolatorTestingImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) Test(org.junit.Test)

Example 98 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.

the class ConfigurationTest method testSharedCacheModeAll.

@Test
public void testSharedCacheModeAll() {
    MetadataImplementor metadata = buildMetadata(SharedCacheMode.ALL);
    PersistentClass pc = metadata.getEntityBinding(ExplicitlyCacheableEntity.class.getName());
    assertTrue(pc.isCached());
    pc = metadata.getEntityBinding(ExplicitlyNonCacheableEntity.class.getName());
    assertTrue(pc.isCached());
    pc = metadata.getEntityBinding(NoCacheableAnnotationEntity.class.getName());
    assertTrue(pc.isCached());
}
Also used : MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 99 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.

the class ConfigurationTest method testSharedCacheModeNone.

@Test
public void testSharedCacheModeNone() {
    MetadataImplementor metadata = buildMetadata(SharedCacheMode.NONE);
    PersistentClass pc = metadata.getEntityBinding(ExplicitlyCacheableEntity.class.getName());
    assertFalse(pc.isCached());
    pc = metadata.getEntityBinding(ExplicitlyNonCacheableEntity.class.getName());
    assertFalse(pc.isCached());
    pc = metadata.getEntityBinding(NoCacheableAnnotationEntity.class.getName());
    assertFalse(pc.isCached());
}
Also used : MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 100 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor in project dhis2-core by dhis2.

the class HibernatePropertyIntrospector method introspect.

@Override
public void introspect(Class<?> klass, Map<String, Property> properties) {
    updateJoinTables();
    MetamodelImplementor metamodelImplementor = getMetamodelImplementor();
    try {
        metamodelImplementor.entityPersister(klass);
    } catch (MappingException ex) {
        // Class is not persisted with Hibernate
        return;
    }
    MetadataImplementor metadataImplementor = HibernateMetadata.getMetadataImplementor();
    if (metadataImplementor == null) {
        return;
    }
    PersistentClass persistentClass = metadataImplementor.getEntityBinding(klass.getName());
    Iterator<?> propertyIterator = persistentClass.getPropertyClosureIterator();
    while (propertyIterator.hasNext()) {
        Property property = createProperty(klass, (org.hibernate.mapping.Property) propertyIterator.next(), metamodelImplementor);
        properties.put(property.getName(), property);
    }
}
Also used : MetamodelImplementor(org.hibernate.metamodel.spi.MetamodelImplementor) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Property(org.hisp.dhis.schema.Property) MappingException(org.hibernate.MappingException) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)113 MetadataSources (org.hibernate.boot.MetadataSources)80 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)62 Test (org.junit.Test)56 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)52 SimpleValue (org.hibernate.mapping.SimpleValue)32 RootClass (org.hibernate.mapping.RootClass)31 PersistentClass (org.hibernate.mapping.PersistentClass)27 TestForIssue (org.hibernate.testing.TestForIssue)26 Table (org.hibernate.mapping.Table)23 Test (org.junit.jupiter.api.Test)23 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)22 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)20 Column (org.hibernate.mapping.Column)17 ArrayList (java.util.ArrayList)15 ServiceRegistry (org.hibernate.service.ServiceRegistry)15 File (java.io.File)14 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)14 Configuration (org.hibernate.cfg.Configuration)12 Property (org.hibernate.mapping.Property)11