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);
}
}
}
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();
}
}
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());
}
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());
}
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);
}
}
Aggregations