use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class AbstractEntityPersister method internalInitSubclassPropertyAliasesMap.
private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) {
while (propertyIterator.hasNext()) {
Property prop = (Property) propertyIterator.next();
String propname = path == null ? prop.getName() : path + "." + prop.getName();
if (prop.isComposite()) {
Component component = (Component) prop.getValue();
Iterator compProps = component.getPropertyIterator();
internalInitSubclassPropertyAliasesMap(propname, compProps);
} else {
String[] aliases = new String[prop.getColumnSpan()];
String[] cols = new String[prop.getColumnSpan()];
Iterator colIter = prop.getColumnIterator();
int l = 0;
while (colIter.hasNext()) {
Selectable thing = (Selectable) colIter.next();
aliases[l] = thing.getAlias(getFactory().getDialect(), prop.getValue().getTable());
// TODO: skip formulas?
cols[l] = thing.getText(getFactory().getDialect());
l++;
}
subclassPropertyAliases.put(propname, aliases);
subclassPropertyColumnNames.put(propname, cols);
}
}
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class PojoEntityTuplizer method buildProxyFactory.
@Override
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
// determine the id getter and setter methods from the proxy interface (if any)
// determine all interfaces needed by the resulting proxy
/*
* We need to preserve the order of the interfaces they were put into the set, since javassist will choose the
* first one's class-loader to construct the proxy class with. This is also the reason why HibernateProxy.class
* should be the last one in the order (on JBossAS7 its class-loader will be org.hibernate module's class-
* loader, which will not see the classes inside deployed apps. See HHH-3078
*/
Set<Class> proxyInterfaces = new java.util.LinkedHashSet<Class>();
Class mappedClass = persistentClass.getMappedClass();
Class proxyInterface = persistentClass.getProxyInterface();
if (proxyInterface != null && !mappedClass.equals(proxyInterface)) {
if (!proxyInterface.isInterface()) {
throw new MappingException("proxy must be either an interface, or the class itself: " + getEntityName());
}
proxyInterfaces.add(proxyInterface);
}
if (mappedClass.isInterface()) {
proxyInterfaces.add(mappedClass);
}
Iterator<Subclass> subclasses = persistentClass.getSubclassIterator();
while (subclasses.hasNext()) {
final Subclass subclass = subclasses.next();
final Class subclassProxy = subclass.getProxyInterface();
final Class subclassClass = subclass.getMappedClass();
if (subclassProxy != null && !subclassClass.equals(subclassProxy)) {
if (!subclassProxy.isInterface()) {
throw new MappingException("proxy must be either an interface, or the class itself: " + subclass.getEntityName());
}
proxyInterfaces.add(subclassProxy);
}
}
proxyInterfaces.add(HibernateProxy.class);
Iterator properties = persistentClass.getPropertyIterator();
Class clazz = persistentClass.getMappedClass();
while (properties.hasNext()) {
Property property = (Property) properties.next();
Method method = property.getGetter(clazz).getMethod();
if (method != null && Modifier.isFinal(method.getModifiers())) {
LOG.gettersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
}
method = property.getSetter(clazz).getMethod();
if (method != null && Modifier.isFinal(method.getModifiers())) {
LOG.settersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
}
}
Method idGetterMethod = idGetter == null ? null : idGetter.getMethod();
Method idSetterMethod = idSetter == null ? null : idSetter.getMethod();
Method proxyGetIdentifierMethod = idGetterMethod == null || proxyInterface == null ? null : ReflectHelper.getMethod(proxyInterface, idGetterMethod);
Method proxySetIdentifierMethod = idSetterMethod == null || proxyInterface == null ? null : ReflectHelper.getMethod(proxyInterface, idSetterMethod);
ProxyFactory pf = buildProxyFactoryInternal(persistentClass, idGetter, idSetter);
try {
pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod, proxySetIdentifierMethod, persistentClass.hasEmbeddedIdentifier() ? (CompositeType) persistentClass.getIdentifier().getType() : null);
} catch (HibernateException he) {
LOG.unableToCreateProxyFactory(getEntityName(), he);
pf = null;
}
return pf;
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class PropertyFactory method buildIdentifierAttribute.
/**
* Generates the attribute representation of the identifier for a given entity mapping.
*
* @param mappedEntity The mapping definition of the entity.
* @param generator The identifier value generator to use for this identifier.
*
* @return The appropriate IdentifierProperty definition.
*/
public static IdentifierProperty buildIdentifierAttribute(PersistentClass mappedEntity, IdentifierGenerator generator) {
String mappedUnsavedValue = mappedEntity.getIdentifier().getNullValue();
Type type = mappedEntity.getIdentifier().getType();
Property property = mappedEntity.getIdentifierProperty();
IdentifierValue unsavedValue = UnsavedValueFactory.getUnsavedIdentifierValue(mappedUnsavedValue, getGetter(property), type, getConstructor(mappedEntity));
if (property == null) {
// this is a virtual id property...
return new IdentifierProperty(type, mappedEntity.hasEmbeddedIdentifier(), mappedEntity.hasIdentifierMapper(), unsavedValue, generator);
} else {
return new IdentifierProperty(property.getName(), type, mappedEntity.hasEmbeddedIdentifier(), unsavedValue, generator);
}
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class ComponentMetadataGenerator method addComponent.
@SuppressWarnings({ "unchecked" })
public void addComponent(Element parent, PropertyAuditingData propertyAuditingData, Value value, CompositeMapperBuilder mapper, String entityName, EntityXmlMappingData xmlMappingData, boolean firstPass) {
final Component propComponent = (Component) value;
final Class componentClass;
if (propComponent.isDynamic()) {
componentClass = ReflectionTools.loadClass(Map.class.getCanonicalName(), mainGenerator.getClassLoaderService());
} else {
componentClass = ReflectionTools.loadClass(propComponent.getComponentClassName(), mainGenerator.getClassLoaderService());
}
final CompositeMapperBuilder componentMapper = mapper.addComponent(propertyAuditingData.getPropertyData(), componentClass);
// The property auditing data must be for a component.
final ComponentAuditingData componentAuditingData = (ComponentAuditingData) propertyAuditingData;
// Adding all properties of the component
final Iterator<Property> properties = (Iterator<Property>) propComponent.getPropertyIterator();
while (properties.hasNext()) {
final Property property = properties.next();
final PropertyAuditingData componentPropertyAuditingData = componentAuditingData.getPropertyAuditingData(property.getName());
// Checking if that property is audited
if (componentPropertyAuditingData != null) {
mainGenerator.addValue(parent, property.getValue(), componentMapper, entityName, xmlMappingData, componentPropertyAuditingData, property.isInsertable(), firstPass, false);
}
}
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class IdMetadataGenerator method addId.
@SuppressWarnings({ "unchecked" })
IdMappingData addId(PersistentClass pc, boolean audited) {
// Xml mapping which will be used for relations
final Element relIdMapping = new DefaultElement("properties");
// Xml mapping which will be used for the primary key of the versions table
final Element origIdMapping = new DefaultElement("composite-id");
final Property idProp = pc.getIdentifierProperty();
final Component idMapper = pc.getIdentifierMapper();
// Checking if the id mapping is supported
if (idMapper == null && idProp == null) {
return null;
}
SimpleIdMapperBuilder mapper;
if (idMapper != null) {
// Multiple id
final Class componentClass = ReflectionTools.loadClass(((Component) pc.getIdentifier()).getComponentClassName(), mainGenerator.getClassLoaderService());
mapper = new MultipleIdMapper(componentClass, pc.getServiceRegistry());
if (!addIdProperties(relIdMapping, (Iterator<Property>) idMapper.getPropertyIterator(), mapper, false, audited)) {
return null;
}
// null mapper - the mapping where already added the first time, now we only want to generate the xml
if (!addIdProperties(origIdMapping, (Iterator<Property>) idMapper.getPropertyIterator(), null, true, audited)) {
return null;
}
} else if (idProp.isComposite()) {
// Embedded id
final Component idComponent = (Component) idProp.getValue();
final Class embeddableClass = ReflectionTools.loadClass(idComponent.getComponentClassName(), mainGenerator.getClassLoaderService());
mapper = new EmbeddedIdMapper(getIdPropertyData(idProp), embeddableClass, pc.getServiceRegistry());
if (!addIdProperties(relIdMapping, (Iterator<Property>) idComponent.getPropertyIterator(), mapper, false, audited)) {
return null;
}
// null mapper - the mapping where already added the first time, now we only want to generate the xml
if (!addIdProperties(origIdMapping, (Iterator<Property>) idComponent.getPropertyIterator(), null, true, audited)) {
return null;
}
} else {
// Single id
mapper = new SingleIdMapper(pc.getServiceRegistry());
// Last but one parameter: ids are always insertable
mainGenerator.getBasicMetadataGenerator().addBasic(relIdMapping, getIdPersistentPropertyAuditingData(idProp), idProp.getValue(), mapper, true, false);
// null mapper - the mapping where already added the first time, now we only want to generate the xml
mainGenerator.getBasicMetadataGenerator().addBasic(origIdMapping, getIdPersistentPropertyAuditingData(idProp), idProp.getValue(), null, true, true);
}
origIdMapping.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
// Adding a relation to the revision entity (effectively: the "revision number" property)
mainGenerator.addRevisionInfoRelation(origIdMapping);
return new IdMappingData(mapper, origIdMapping, relIdMapping);
}
Aggregations