use of org.hibernate.annotations.common.reflection.ReflectionManager in project hibernate-orm by hibernate.
the class EnversServiceImpl method doInitialize.
private void doInitialize(final MetadataImplementor metadata, final MappingCollector mappingCollector, ServiceRegistry serviceRegistry) {
final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class);
final Properties properties = new Properties();
properties.putAll(cfgService.getSettings());
this.globalConfiguration = new GlobalConfiguration(this, properties);
final ReflectionManager reflectionManager = metadata.getMetadataBuildingOptions().getReflectionManager();
final RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration(globalConfiguration);
final RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(metadata, reflectionManager);
EnversServiceImpl.this.auditEntitiesConfiguration = new AuditEntitiesConfiguration(properties, revInfoCfgResult.getRevisionInfoEntityName(), this);
this.auditProcessManager = new AuditProcessManager(revInfoCfgResult.getRevisionInfoGenerator());
this.revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
this.revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader();
this.modifiedEntityNamesReader = revInfoCfgResult.getModifiedEntityNamesReader();
this.auditStrategy = initializeAuditStrategy(auditEntitiesConfiguration.getAuditStrategyName(), revInfoCfgResult.getRevisionInfoClass(), revInfoCfgResult.getRevisionInfoTimestampData(), serviceRegistry);
this.entitiesConfigurations = new EntitiesConfigurator().configure(metadata, serviceRegistry, reflectionManager, mappingCollector, globalConfiguration, auditEntitiesConfiguration, auditStrategy, revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping());
}
use of org.hibernate.annotations.common.reflection.ReflectionManager in project hibernate-orm by hibernate.
the class AttributeConverterDescriptorImpl method resolveMember.
private ResolvedMember resolveMember(XProperty xProperty, MetadataBuildingContext buildingContext) {
final ClassmateContext classmateContext = buildingContext.getMetadataCollector().getClassmateContext();
final ReflectionManager reflectionManager = buildingContext.getBuildingOptions().getReflectionManager();
final ResolvedType declaringClassType = classmateContext.getTypeResolver().resolve(reflectionManager.toClass(xProperty.getDeclaringClass()));
final ResolvedTypeWithMembers declaringClassWithMembers = classmateContext.getMemberResolver().resolve(declaringClassType, null, null);
final Member member = toMember(xProperty);
if (member instanceof Method) {
for (ResolvedMethod resolvedMember : declaringClassWithMembers.getMemberMethods()) {
if (resolvedMember.getName().equals(member.getName())) {
return resolvedMember;
}
}
} else if (member instanceof Field) {
for (ResolvedField resolvedMember : declaringClassWithMembers.getMemberFields()) {
if (resolvedMember.getName().equals(member.getName())) {
return resolvedMember;
}
}
} else {
throw new HibernateException("Unexpected java.lang.reflect.Member type from org.hibernate.annotations.common.reflection.java.JavaXMember : " + member);
}
throw new HibernateException("Could not locate resolved type information for attribute [" + member.getName() + "] from Classmate");
}
use of org.hibernate.annotations.common.reflection.ReflectionManager in project hibernate-orm by hibernate.
the class AutoApplicableConverterDescriptorStandardImpl method resolveMember.
private ResolvedMember resolveMember(XProperty xProperty, MetadataBuildingContext buildingContext) {
final ClassmateContext classmateContext = buildingContext.getBootstrapContext().getClassmateContext();
final ReflectionManager reflectionManager = buildingContext.getBootstrapContext().getReflectionManager();
final ResolvedType declaringClassType = classmateContext.getTypeResolver().resolve(reflectionManager.toClass(xProperty.getDeclaringClass()));
final ResolvedTypeWithMembers declaringClassWithMembers = classmateContext.getMemberResolver().resolve(declaringClassType, null, null);
final Member member = toMember(xProperty);
if (member instanceof Method) {
for (ResolvedMethod resolvedMember : declaringClassWithMembers.getMemberMethods()) {
if (resolvedMember.getName().equals(member.getName())) {
return resolvedMember;
}
}
} else if (member instanceof Field) {
for (ResolvedField resolvedMember : declaringClassWithMembers.getMemberFields()) {
if (resolvedMember.getName().equals(member.getName())) {
return resolvedMember;
}
}
} else {
throw new HibernateException("Unexpected java.lang.reflect.Member type from org.hibernate.annotations.common.reflection.java.JavaXMember : " + member);
}
throw new HibernateException("Could not locate resolved type information for attribute [" + member.getName() + "] from Classmate");
}
use of org.hibernate.annotations.common.reflection.ReflectionManager in project hibernate-orm by hibernate.
the class EntityBinder method setProxy.
@SuppressWarnings({ "unchecked" })
public void setProxy(Proxy proxy) {
if (proxy != null) {
lazy = proxy.lazy();
if (!lazy) {
proxyClass = null;
} else {
final ReflectionManager reflectionManager = context.getBootstrapContext().getReflectionManager();
if (AnnotationBinder.isDefault(reflectionManager.toXClass(proxy.proxyClass()), context)) {
proxyClass = annotatedClass;
} else {
proxyClass = reflectionManager.toXClass(proxy.proxyClass());
}
}
} else {
// needed to allow association lazy loading.
lazy = true;
proxyClass = annotatedClass;
}
}
use of org.hibernate.annotations.common.reflection.ReflectionManager in project hibernate-orm by hibernate.
the class CollectionMetadataGenerator method addValueToMiddleTable.
/**
* @param value Value, which should be mapped to the middle-table, either as a relation to another entity,
* or as a simple value.
* @param xmlMapping If not <code>null</code>, xml mapping for this value is added to this element.
* @param queryGeneratorBuilder In case <code>value</code> is a relation to another entity, information about it
* should be added to the given.
* @param prefix Prefix for proeprty names of related entities identifiers.
* @param joinColumns Names of columns to use in the xml mapping, if this array isn't null and has any elements.
*
* @return Data for mapping this component.
*/
@SuppressWarnings({ "unchecked" })
private MiddleComponentData addValueToMiddleTable(Value value, Element xmlMapping, QueryGeneratorBuilder queryGeneratorBuilder, String prefix, JoinColumn[] joinColumns, boolean key) {
final Type type = value.getType();
if (type instanceof ManyToOneType) {
final String prefixRelated = prefix + "_";
final String referencedEntityName = MappingTools.getReferencedEntityName(value);
final IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(referencingEntityName, referencedEntityName, propertyAuditingData, true);
// relation isn't inverse (so when <code>xmlMapping</code> is not null).
if (xmlMapping != null) {
addRelatedToXmlMapping(xmlMapping, prefixRelated, joinColumns != null && joinColumns.length > 0 ? MetadataTools.getColumnNameIterator(joinColumns) : MetadataTools.getColumnNameIterator(value.getColumnIterator()), referencedIdMapping);
}
// Storing the id data of the referenced entity: original mapper, prefixed mapper and entity name.
final MiddleIdData referencedIdData = createMiddleIdData(referencedIdMapping, prefixRelated, referencedEntityName);
// And adding it to the generator builder.
queryGeneratorBuilder.addRelation(referencedIdData);
return new MiddleComponentData(new MiddleRelatedComponentMapper(referencedIdData), queryGeneratorBuilder.getCurrentIndex());
} else if (type instanceof ComponentType) {
// Collection of embeddable elements.
final Component component = (Component) value;
final Class componentClass = ReflectionTools.loadClass(component.getComponentClassName(), mainGenerator.getClassLoaderService());
final MiddleEmbeddableComponentMapper componentMapper = new MiddleEmbeddableComponentMapper(new MultiPropertyMapper(), componentClass);
final Element parentXmlMapping = xmlMapping.getParent();
final ComponentAuditingData auditData = new ComponentAuditingData();
final ReflectionManager reflectionManager = mainGenerator.getMetadata().getMetadataBuildingOptions().getReflectionManager();
new ComponentAuditedPropertiesReader(ModificationStore.FULL, new AuditedPropertiesReader.ComponentPropertiesSource(reflectionManager, component), auditData, mainGenerator.getGlobalCfg(), reflectionManager, "").read();
// Emulating first pass.
for (String auditedPropertyName : auditData.getPropertyNames()) {
final PropertyAuditingData nestedAuditingData = auditData.getPropertyAuditingData(auditedPropertyName);
mainGenerator.addValue(parentXmlMapping, component.getProperty(auditedPropertyName).getValue(), componentMapper, prefix, xmlMappingData, nestedAuditingData, true, true, true);
}
// Emulating second pass so that the relations can be mapped too.
for (String auditedPropertyName : auditData.getPropertyNames()) {
final PropertyAuditingData nestedAuditingData = auditData.getPropertyAuditingData(auditedPropertyName);
mainGenerator.addValue(parentXmlMapping, component.getProperty(auditedPropertyName).getValue(), componentMapper, referencingEntityName, xmlMappingData, nestedAuditingData, true, false, true);
}
// Embeddable properties may contain null values, so cannot be stored within composite primary key.
if (propertyValue.isSet()) {
final String setOrdinalPropertyName = mainGenerator.getVerEntCfg().getEmbeddableSetOrdinalPropertyName();
final Element ordinalProperty = MetadataTools.addProperty(xmlMapping, setOrdinalPropertyName, "integer", true, true);
MetadataTools.addColumn(ordinalProperty, setOrdinalPropertyName, null, null, null, null, null, null, false);
}
return new MiddleComponentData(componentMapper, 0);
} else {
// Last but one parameter: collection components are always insertable
final boolean mapped = mainGenerator.getBasicMetadataGenerator().addBasic(key ? xmlMapping : xmlMapping.getParent(), new PropertyAuditingData(prefix, "field", ModificationStore.FULL, RelationTargetAuditMode.AUDITED, null, null, false), value, null, true, key);
if (mapped && key) {
// Simple values are always stored in the first item of the array returned by the query generator.
return new MiddleComponentData(new MiddleSimpleComponentMapper(mainGenerator.getVerEntCfg(), prefix), 0);
} else if (mapped && !key) {
// when mapped but not part of the key, its stored as a dummy mapper??
return new MiddleComponentData(new MiddleMapElementNotKeyComponentMapper(mainGenerator.getVerEntCfg(), prefix), 0);
} else {
mainGenerator.throwUnsupportedTypeException(type, referencingEntityName, propertyName);
// Impossible to get here.
throw new AssertionError();
}
}
}
Aggregations