use of org.dom4j.Element 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);
}
use of org.dom4j.Element in project hibernate-orm by hibernate.
the class MetadataTools method createSubclassEntity.
public static Element createSubclassEntity(Document document, String subclassType, AuditTableData auditTableData, String extendsEntityName, String discriminatorValue, Boolean isAbstract) {
final Element classMapping = createEntityCommon(document, subclassType, auditTableData, discriminatorValue, isAbstract);
classMapping.addAttribute("extends", extendsEntityName);
return classMapping;
}
use of org.dom4j.Element in project hibernate-orm by hibernate.
the class MetadataTools method addColumn.
public static Element addColumn(Element parent, String name, Integer length, Integer scale, Integer precision, String sqlType, String customRead, String customWrite, boolean quoted) {
final Element columnMapping = parent.addElement("column");
columnMapping.addAttribute("name", quoted ? "`" + name + "`" : name);
if (length != null) {
columnMapping.addAttribute("length", length.toString());
}
if (scale != null) {
columnMapping.addAttribute("scale", Integer.toString(scale));
}
if (precision != null) {
columnMapping.addAttribute("precision", Integer.toString(precision));
}
if (!StringTools.isEmpty(sqlType)) {
columnMapping.addAttribute("sql-type", sqlType);
}
if (!StringTools.isEmpty(customRead)) {
columnMapping.addAttribute("read", customRead);
}
if (!StringTools.isEmpty(customWrite)) {
columnMapping.addAttribute("write", customWrite);
}
return columnMapping;
}
use of org.dom4j.Element in project hibernate-orm by hibernate.
the class MetadataTools method addProperty.
public static Element addProperty(Element parent, String name, String type, boolean insertable, boolean updateable, boolean key) {
final Element propMapping;
if (key) {
propMapping = parent.addElement("key-property");
} else {
propMapping = parent.addElement("property");
propMapping.addAttribute("insert", Boolean.toString(insertable));
propMapping.addAttribute("update", Boolean.toString(updateable));
}
propMapping.addAttribute("name", name);
if (type != null) {
propMapping.addAttribute("type", type);
}
return propMapping;
}
use of org.dom4j.Element in project hibernate-orm by hibernate.
the class ToOneRelationMetadataGenerator method addToOne.
@SuppressWarnings({ "unchecked" })
void addToOne(Element parent, PropertyAuditingData propertyAuditingData, Value value, CompositeMapperBuilder mapper, String entityName, boolean insertable) {
final String referencedEntityName = ((ToOne) value).getReferencedEntityName();
final IdMappingData idMapping = mainGenerator.getReferencedIdMappingData(entityName, referencedEntityName, propertyAuditingData, true);
final String lastPropertyPrefix = MappingTools.createToOneRelationPrefix(propertyAuditingData.getName());
// Generating the id mapper for the relation
final IdMapper relMapper = idMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
// Storing information about this relation
mainGenerator.getEntitiesConfigurations().get(entityName).addToOneRelation(propertyAuditingData.getName(), referencedEntityName, relMapper, insertable, MappingTools.ignoreNotFound(value));
// If the property isn't insertable, checking if this is not a "fake" bidirectional many-to-one relationship,
// that is, when the one side owns the relation (and is a collection), and the many side is non insertable.
// When that's the case and the user specified to store this relation without a middle table (using
// @AuditMappedBy), we have to make the property insertable for the purposes of Envers. In case of changes to
// the entity that didn't involve the relation, it's value will then be stored properly. In case of changes
// to the entity that did involve the relation, it's the responsibility of the collection side to store the
// proper data.
boolean nonInsertableFake;
if (!insertable && propertyAuditingData.isForceInsertable()) {
nonInsertableFake = true;
insertable = true;
} else {
nonInsertableFake = false;
}
// Adding an element to the mapping corresponding to the references entity id's
final Element properties = (Element) idMapping.getXmlRelationMapping().clone();
properties.addAttribute("name", propertyAuditingData.getName());
MetadataTools.prefixNamesInPropertyElement(properties, lastPropertyPrefix, MetadataTools.getColumnNameIterator(value.getColumnIterator()), false, insertable);
// Extracting related id properties from properties tag
for (Object o : properties.content()) {
final Element element = (Element) o;
element.setParent(null);
parent.add(element);
}
// Adding mapper for the id
final PropertyData propertyData = propertyAuditingData.getPropertyData();
mapper.addComposite(propertyData, new ToOneIdMapper(relMapper, propertyData, referencedEntityName, nonInsertableFake));
}
Aggregations