Hibernate SVN: r15744 - in core/trunk/envers/src/main/java/org/hibernate/envers: configuration/metadata and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2008-12-31 06:29:37 -0500 (Wed, 31 Dec 2008)
New Revision: 15744
Added:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/ComponentMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentComponentPropertyAuditingData.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java
Removed:
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MapPropertyMapper.java
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/BasicMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentPropertyAuditingData.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/PropertyData.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/CompositeMapperBuilder.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/SubclassPropertyMapper.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/id/EmbeddedIdMapper.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/id/MultipleIdMapper.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/id/SingleIdMapper.java
core/trunk/envers/src/main/java/org/hibernate/envers/tools/reflection/ReflectionTools.java
Log:
HHH-3563, HHH-3561: component handling rework
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -59,8 +59,8 @@
public RevisionInfoConfiguration() {
revisionInfoEntityName = "org.hibernate.envers.DefaultRevisionEntity";
- revisionInfoIdData = new PropertyData("id", "field", null);
- revisionInfoTimestampData = new PropertyData("timestamp", "field", null);
+ revisionInfoIdData = new PropertyData("id", "id", "field", null);
+ revisionInfoTimestampData = new PropertyData("timestamp", "timestamp", "field", null);
revisionInfoTimestampType = "long";
revisionPropType = "integer";
@@ -109,11 +109,11 @@
XClass revisionNumberClass = property.getType();
if (reflectionManager.equals(revisionNumberClass, Integer.class) ||
reflectionManager.equals(revisionNumberClass, Integer.TYPE)) {
- revisionInfoIdData = new PropertyData(property.getName(), accessType, null);
+ revisionInfoIdData = new PropertyData(property.getName(), property.getName(), accessType, null);
revisionNumberFound.set();
} else if (reflectionManager.equals(revisionNumberClass, Long.class) ||
reflectionManager.equals(revisionNumberClass, Long.TYPE)) {
- revisionInfoIdData = new PropertyData(property.getName(), accessType, null);
+ revisionInfoIdData = new PropertyData(property.getName(), property.getName(), accessType, null);
revisionNumberFound.set();
// The default is integer
@@ -132,7 +132,7 @@
XClass revisionTimestampClass = property.getType();
if (reflectionManager.equals(revisionTimestampClass, Long.class) ||
reflectionManager.equals(revisionTimestampClass, Long.TYPE)) {
- revisionInfoTimestampData = new PropertyData(property.getName(), accessType, null);
+ revisionInfoTimestampData = new PropertyData(property.getName(), property.getName(), accessType, null);
revisionTimestampFound.set();
} else {
throw new MappingException("The field annotated with @RevisionTimestamp must be of type " +
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -46,10 +46,7 @@
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Value;
-import org.hibernate.type.CollectionType;
-import org.hibernate.type.ManyToOneType;
-import org.hibernate.type.OneToOneType;
-import org.hibernate.type.Type;
+import org.hibernate.type.*;
/**
* @author Adam Warski (adam at warski dot org)
@@ -62,6 +59,7 @@
private final Element revisionInfoRelationMapping;
private final BasicMetadataGenerator basicMetadataGenerator;
+ private final ComponentMetadataGenerator componentMetadataGenerator;
private final IdMetadataGenerator idMetadataGenerator;
private final ToOneRelationMetadataGenerator toOneRelationMetadataGenerator;
@@ -79,6 +77,7 @@
this.revisionInfoRelationMapping = revisionInfoRelationMapping;
this.basicMetadataGenerator = new BasicMetadataGenerator();
+ this.componentMetadataGenerator = new ComponentMetadataGenerator(this);
this.idMetadataGenerator = new IdMetadataGenerator(this);
this.toOneRelationMetadataGenerator = new ToOneRelationMetadataGenerator(this);
@@ -109,13 +108,17 @@
// only first pass
if (firstPass) {
if (basicMetadataGenerator.addBasic(parent, persistentPropertyAuditingData, value, currentMapper,
- entityName, insertable, false)) {
+ insertable, false)) {
// The property was mapped by the basic generator.
return;
}
}
- if (type instanceof ManyToOneType) {
+ if (type instanceof ComponentType) {
+ // both passes
+ componentMetadataGenerator.addComponent(parent, persistentPropertyAuditingData, value, currentMapper,
+ entityName, xmlMappingData, firstPass);
+ } else if (type instanceof ManyToOneType) {
// only second pass
if (!firstPass) {
toOneRelationMetadataGenerator.addToOne(parent, persistentPropertyAuditingData, value, currentMapper,
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/BasicMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/BasicMetadataGenerator.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/BasicMetadataGenerator.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -27,149 +27,82 @@
import java.util.Properties;
import org.dom4j.Element;
-import org.hibernate.envers.ModificationStore;
-import org.hibernate.envers.entities.mapper.CompositeMapperBuilder;
import org.hibernate.envers.entities.mapper.SimpleMapperBuilder;
import org.hibernate.mapping.Column;
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.Property;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Value;
-import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeCustomType;
import org.hibernate.type.CustomType;
import org.hibernate.type.ImmutableType;
import org.hibernate.type.MutableType;
import org.hibernate.type.Type;
-import org.hibernate.util.StringHelper;
/**
- * Generates metadata for basic properties: immutable types (including enums) and components
+ * Generates metadata for basic properties: immutable types (including enums).
* @author Adam Warski (adam at warski dot org)
*/
public final class BasicMetadataGenerator {
- boolean addBasic(Element parent, PersistentPropertyAuditingData persistentPropertyAuditingData, Value value,
- CompositeMapperBuilder mapper, String entityName, boolean insertable, boolean key) {
- Type type = value.getType();
+ boolean addBasic(Element parent, PersistentPropertyAuditingData persistentPropertyAuditingData,
+ Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
+ Type type = value.getType();
- if (type instanceof ComponentType) {
- addComponent(parent, persistentPropertyAuditingData, value, mapper, entityName, key);
- return true;
- } else {
- return addBasicNoComponent(parent, persistentPropertyAuditingData, value, mapper, insertable, key);
- }
- }
+ if (type instanceof ImmutableType || type instanceof MutableType) {
+ addSimpleValue(parent, persistentPropertyAuditingData, value, mapper, insertable, key);
+ } else if (type instanceof CustomType || type instanceof CompositeCustomType) {
+ addCustomValue(parent, persistentPropertyAuditingData, value, mapper, insertable, key);
+ } else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName())) {
+ addSimpleValue(parent, persistentPropertyAuditingData, value, mapper, insertable, key);
+ } else {
+ return false;
+ }
- boolean addBasicNoComponent(Element parent, PersistentPropertyAuditingData persistentPropertyAuditingData,
- Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
- Type type = value.getType();
+ return true;
+ }
- if (type instanceof ImmutableType || type instanceof MutableType) {
- addSimpleValue(parent, persistentPropertyAuditingData, value, mapper, insertable, key);
- } else if (type instanceof CustomType || type instanceof CompositeCustomType) {
- addCustomValue(parent, persistentPropertyAuditingData, value, mapper, insertable, key);
- } else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName())) {
- addSimpleValue(parent, persistentPropertyAuditingData, value, mapper, insertable, key);
- } else {
- return false;
- }
+ @SuppressWarnings({"unchecked"})
+ private void addSimpleValue(Element parent, PersistentPropertyAuditingData persistentPropertyAuditingData,
+ Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
+ if (parent != null) {
+ Element prop_mapping = MetadataTools.addProperty(parent, persistentPropertyAuditingData.getName(),
+ value.getType().getName(), insertable, key);
+ MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
+ }
- return true;
- }
+ // A null mapper means that we only want to add xml mappings
+ if (mapper != null) {
+ mapper.add(persistentPropertyAuditingData.getPropertyData());
+ }
+ }
- @SuppressWarnings({"unchecked"})
- private void addSimpleValue(Element parent, PersistentPropertyAuditingData persistentPropertyAuditingData,
- Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
- if (parent != null) {
- Element prop_mapping = MetadataTools.addProperty(parent, persistentPropertyAuditingData.getName(),
- value.getType().getName(), insertable, key);
- MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
- }
+ @SuppressWarnings({"unchecked"})
+ private void addCustomValue(Element parent, PersistentPropertyAuditingData persistentPropertyAuditingData,
+ Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
+ if (parent != null) {
+ Element prop_mapping = MetadataTools.addProperty(parent, persistentPropertyAuditingData.getName(),
+ null, insertable, key);
- // A null mapper means that we only want to add xml mappings
- if (mapper != null) {
- mapper.add(persistentPropertyAuditingData.getPropertyData());
- }
- }
+ //CustomType propertyType = (CustomType) value.getType();
- @SuppressWarnings({"unchecked"})
- private void addCustomValue(Element parent, PersistentPropertyAuditingData persistentPropertyAuditingData,
- Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
- if (parent != null) {
- Element prop_mapping = MetadataTools.addProperty(parent, persistentPropertyAuditingData.getName(),
- null, insertable, key);
+ Element type_mapping = prop_mapping.addElement("type");
+ type_mapping.addAttribute("name", value.getType().getName());
- //CustomType propertyType = (CustomType) value.getType();
+ if (value instanceof SimpleValue) {
+ Properties typeParameters = ((SimpleValue) value).getTypeParameters();
+ if (typeParameters != null) {
+ for (java.util.Map.Entry paramKeyValue : typeParameters.entrySet()) {
+ Element type_param = type_mapping.addElement("param");
+ type_param.addAttribute("name", (String) paramKeyValue.getKey());
+ type_param.setText((String) paramKeyValue.getValue());
+ }
+ }
+ }
- Element type_mapping = prop_mapping.addElement("type");
- type_mapping.addAttribute("name", value.getType().getName());
+ MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
+ }
- if (value instanceof SimpleValue) {
- Properties typeParameters = ((SimpleValue) value).getTypeParameters();
- if (typeParameters != null) {
- for (java.util.Map.Entry paramKeyValue : typeParameters.entrySet()) {
- Element type_param = type_mapping.addElement("param");
- type_param.addAttribute("name", (String) paramKeyValue.getKey());
- type_param.setText((String) paramKeyValue.getValue());
- }
- }
- }
-
- MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
- }
-
- if (mapper != null) {
- mapper.add(persistentPropertyAuditingData.getPropertyData());
- }
- }
-
- private void addComponentClassName(Element any_mapping, Component comp) {
- if (StringHelper.isNotEmpty(comp.getComponentClassName())) {
- any_mapping.addAttribute("class", comp.getComponentClassName());
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private void addComponent(Element parent, PersistentPropertyAuditingData persistentPropertyAuditingData,
- Value value, CompositeMapperBuilder mapper, String entityName, boolean key) {
- Element component_mapping = null;
- Component prop_component = (Component) value;
-
- if (parent != null) {
- /*
- TODO: investigate relations inside components
- if (!firstPass) {
- // The required element already exists.
- Iterator<Element> iter = parent.elementIterator("component");
- while (iter.hasNext()) {
- Element child = iter.next();
- if (child.attribute("name").getText().equals(name)) {
- component_mapping = child;
- break;
- }
- }
-
- if (component_mapping == null) {
- throw new AuditException("Element for component not found during second pass!");
- }
- } else {
- */
-
- component_mapping = parent.addElement("component");
- component_mapping.addAttribute("name", persistentPropertyAuditingData.getName());
-
- addComponentClassName(component_mapping, prop_component);
- }
-
- CompositeMapperBuilder componentMapper = mapper.addComposite(persistentPropertyAuditingData.getPropertyData());
-
- Iterator<Property> properties = (Iterator<Property>) prop_component.getPropertyIterator();
- while (properties.hasNext()) {
- Property property = properties.next();
- addBasic(component_mapping,
- new PersistentPropertyAuditingData(property.getName(), property.getPropertyAccessorName(), ModificationStore.FULL),
- property.getValue(), componentMapper, entityName, property.isInsertable(), key);
- }
- }
+ if (mapper != null) {
+ mapper.add(persistentPropertyAuditingData.getPropertyData());
+ }
+ }
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -400,7 +400,7 @@
queryGeneratorBuilder.getCurrentIndex());
} else {
// Last but one parameter: collection components are always insertable
- boolean mapped = mainGenerator.getBasicMetadataGenerator().addBasicNoComponent(xmlMapping,
+ boolean mapped = mainGenerator.getBasicMetadataGenerator().addBasic(xmlMapping,
new PersistentPropertyAuditingData(prefix, "field", ModificationStore.FULL), value, null,
true, true);
Added: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/ComponentMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/ComponentMetadataGenerator.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/ComponentMetadataGenerator.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -0,0 +1,45 @@
+package org.hibernate.envers.configuration.metadata;
+
+import org.dom4j.Element;
+import org.hibernate.mapping.Value;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.Property;
+import org.hibernate.envers.entities.mapper.CompositeMapperBuilder;
+import org.hibernate.envers.ModificationStore;
+
+import java.util.Iterator;
+
+/**
+ * Generates metadata for components.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class ComponentMetadataGenerator {
+ private final AuditMetadataGenerator mainGenerator;
+
+ ComponentMetadataGenerator(AuditMetadataGenerator auditMetadataGenerator) {
+ mainGenerator = auditMetadataGenerator;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void addComponent(Element parent, PersistentPropertyAuditingData persistentPropertyAuditingData,
+ Value value, CompositeMapperBuilder mapper, String entityName,
+ EntityXmlMappingData xmlMappingData, boolean firstPass) {
+ Component prop_component = (Component) value;
+
+ CompositeMapperBuilder componentMapper = mapper.addComponent(persistentPropertyAuditingData.getPropertyData());
+
+ // Adding all properties of the component
+ Iterator<Property> properties = (Iterator<Property>) prop_component.getPropertyIterator();
+ while (properties.hasNext()) {
+ Property property = properties.next();
+ // The name of the property in the entity will consist of the name of the component property concatenated
+ // with the name of the property in the bean, to avoid conflicts.
+ PersistentPropertyAuditingData propertyAuditingData = new PersistentComponentPropertyAuditingData(
+ persistentPropertyAuditingData.getName() + "_" + property.getName(),
+ property.getName(), property.getPropertyAccessorName(), ModificationStore.FULL);
+
+ mainGenerator.addValue(parent, property.getValue(), componentMapper,
+ entityName, xmlMappingData, propertyAuditingData, property.isInsertable(), firstPass);
+ }
+ }
+}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -62,7 +62,7 @@
if (!"_identifierMapper".equals(property.getName())) {
if (propertyType instanceof ImmutableType) {
// Last but one parameter: ids are always insertable
- mainGenerator.getBasicMetadataGenerator().addBasicNoComponent(parent,
+ mainGenerator.getBasicMetadataGenerator().addBasic(parent,
getIdPersistentPropertyAuditingData(property),
property.getValue(), mapper, true, key);
} else {
@@ -107,12 +107,12 @@
mapper = new SingleIdMapper();
// Last but one parameter: ids are always insertable
- mainGenerator.getBasicMetadataGenerator().addBasicNoComponent(rel_id_mapping,
+ mainGenerator.getBasicMetadataGenerator().addBasic(rel_id_mapping,
getIdPersistentPropertyAuditingData(id_prop),
id_prop.getValue(), mapper, true, false);
// null mapper - the mapping where already added the first time, now we only want to generate the xml
- mainGenerator.getBasicMetadataGenerator().addBasicNoComponent(orig_id_mapping,
+ mainGenerator.getBasicMetadataGenerator().addBasic(orig_id_mapping,
getIdPersistentPropertyAuditingData(id_prop),
id_prop.getValue(), null, true, true);
}
@@ -126,7 +126,8 @@
}
private PropertyData getIdPropertyData(Property property) {
- return new PropertyData(property.getName(), property.getPropertyAccessorName(), ModificationStore.FULL);
+ return new PropertyData(property.getName(), property.getName(), property.getPropertyAccessorName(),
+ ModificationStore.FULL);
}
private PersistentPropertyAuditingData getIdPersistentPropertyAuditingData(Property property) {
Copied: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentComponentPropertyAuditingData.java (from rev 15742, core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentPropertyAuditingData.java)
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentComponentPropertyAuditingData.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentComponentPropertyAuditingData.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -0,0 +1,46 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.envers.configuration.metadata;
+
+import org.hibernate.envers.ModificationStore;
+import org.hibernate.envers.entities.PropertyData;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class PersistentComponentPropertyAuditingData extends PersistentPropertyAuditingData {
+ private final String beanName;
+
+ public PersistentComponentPropertyAuditingData(String name, String beanName, String accessType,
+ ModificationStore store) {
+ super(name, accessType, store);
+
+ this.beanName = beanName;
+ }
+
+ public PropertyData getPropertyData() {
+ return new PropertyData(getName(), beanName, getAccessType(), getStore());
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentComponentPropertyAuditingData.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentPropertyAuditingData.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentPropertyAuditingData.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentPropertyAuditingData.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -88,6 +88,6 @@
}
public PropertyData getPropertyData() {
- return new PropertyData(name, accessType, store);
+ return new PropertyData(name, name, accessType, store);
}
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/PropertyData.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/PropertyData.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/PropertyData.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -31,6 +31,10 @@
*/
public class PropertyData {
private final String name;
+ /**
+ * Name of the property in the bean.
+ */
+ private final String beanName;
private final String accessType;
private final ModificationStore store;
@@ -41,17 +45,20 @@
*/
public PropertyData(String newName, PropertyData propertyData) {
this.name = newName;
+ this.beanName = propertyData.beanName;
this.accessType = propertyData.accessType;
this.store = propertyData.store;
}
/**
* @param name Name of the property.
+ * @param beanName Name of the property in the bean.
* @param accessType Accessor type for this property.
* @param store How this property should be stored.
*/
- public PropertyData(String name, String accessType, ModificationStore store) {
+ public PropertyData(String name, String beanName, String accessType, ModificationStore store) {
this.name = name;
+ this.beanName = beanName;
this.accessType = accessType;
this.store = store;
}
@@ -60,11 +67,39 @@
return name;
}
- public String getAccessType() {
+ public String getBeanName() {
+ return beanName;
+ }
+
+ public String getAccessType() {
return accessType;
}
public ModificationStore getStore() {
return store;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ PropertyData that = (PropertyData) o;
+
+ if (accessType != null ? !accessType.equals(that.accessType) : that.accessType != null) return false;
+ if (beanName != null ? !beanName.equals(that.beanName) : that.beanName != null) return false;
+ if (name != null ? !name.equals(that.name) : that.name != null) return false;
+ if (store != that.store) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = name != null ? name.hashCode() : 0;
+ result = 31 * result + (beanName != null ? beanName.hashCode() : 0);
+ result = 31 * result + (accessType != null ? accessType.hashCode() : 0);
+ result = 31 * result + (store != null ? store.hashCode() : 0);
+ return result;
+ }
}
Copied: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java (from rev 15742, core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MapPropertyMapper.java)
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -0,0 +1,93 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.envers.entities.mapper;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.envers.entities.PropertyData;
+import org.hibernate.envers.configuration.AuditConfiguration;
+import org.hibernate.envers.exception.AuditException;
+import org.hibernate.envers.reader.AuditReaderImplementor;
+import org.hibernate.envers.tools.reflection.ReflectionTools;
+
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.property.Getter;
+import org.hibernate.property.Setter;
+import org.hibernate.util.ReflectHelper;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperBuilder {
+ private PropertyData propertyData;
+ private ExtendedPropertyMapper delegate;
+
+ public ComponentPropertyMapper(PropertyData propertyData) {
+ this.propertyData = propertyData;
+ this.delegate = new MultiPropertyMapper();
+ }
+
+ public void add(PropertyData propertyData) {
+ delegate.add(propertyData);
+ }
+
+ public CompositeMapperBuilder addComponent(PropertyData propertyData) {
+ return delegate.addComponent(propertyData);
+ }
+
+ public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper) {
+ delegate.addComposite(propertyData, propertyMapper);
+ }
+
+ public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj) {
+ return delegate.mapToMapFromEntity(data, newObj, oldObj);
+ }
+
+ public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) {
+ if (data == null || obj == null) {
+ return;
+ }
+
+ Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyData);
+ Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData);
+
+ try {
+ Object subObj = ReflectHelper.getDefaultConstructor(getter.getReturnType()).newInstance();
+ setter.set(obj, subObj, null);
+ delegate.mapToEntityFromMap(verCfg, subObj, data, primaryKey, versionsReader, revision);
+ } catch (Exception e) {
+ throw new AuditException(e);
+ }
+ }
+
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl,
+ Serializable id) {
+ return delegate.mapCollectionChanges(referencingPropertyName, newColl, oldColl, id);
+ }
+
+}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/CompositeMapperBuilder.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/CompositeMapperBuilder.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/CompositeMapperBuilder.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -29,6 +29,6 @@
* @author Adam Warski (adam at warski dot org)
*/
public interface CompositeMapperBuilder extends SimpleMapperBuilder {
- public CompositeMapperBuilder addComposite(PropertyData propertyData);
+ public CompositeMapperBuilder addComponent(PropertyData propertyData);
public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper);
}
Deleted: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MapPropertyMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MapPropertyMapper.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MapPropertyMapper.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -1,97 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.envers.entities.mapper;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.hibernate.envers.entities.PropertyData;
-import org.hibernate.envers.configuration.AuditConfiguration;
-import org.hibernate.envers.exception.AuditException;
-import org.hibernate.envers.reader.AuditReaderImplementor;
-import org.hibernate.envers.tools.reflection.ReflectionTools;
-
-import org.hibernate.collection.PersistentCollection;
-import org.hibernate.property.Getter;
-import org.hibernate.property.Setter;
-import org.hibernate.util.ReflectHelper;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class MapPropertyMapper implements PropertyMapper, CompositeMapperBuilder {
- private PropertyData propertyData;
- private ExtendedPropertyMapper delegate;
-
- public MapPropertyMapper(PropertyData propertyData) {
- this.propertyData = propertyData;
- this.delegate = new MultiPropertyMapper();
- }
-
- public void add(PropertyData propertyData) {
- delegate.add(propertyData);
- }
-
- public CompositeMapperBuilder addComposite(PropertyData propertyData) {
- return delegate.addComposite(propertyData);
- }
-
- public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper) {
- delegate.addComposite(propertyData, propertyMapper);
- }
-
- public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj) {
- Map<String, Object> newData = new HashMap<String, Object>();
- data.put(propertyData.getName(), newData);
-
- return delegate.mapToMapFromEntity(newData, newObj, oldObj);
- }
-
- public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) {
- if (data == null || obj == null) {
- return;
- }
-
- Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyData);
- Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData);
-
- try {
- Object subObj = ReflectHelper.getDefaultConstructor(getter.getReturnType()).newInstance();
- setter.set(obj, subObj, null);
- delegate.mapToEntityFromMap(verCfg, subObj, (Map) data.get(propertyData.getName()), primaryKey, versionsReader, revision);
- } catch (Exception e) {
- throw new AuditException(e);
- }
- }
-
- public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
- PersistentCollection newColl,
- Serializable oldColl,
- Serializable id) {
- return delegate.mapCollectionChanges(referencingPropertyName, newColl, oldColl, id);
- }
-
-}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -33,7 +33,6 @@
import org.hibernate.envers.tools.reflection.ReflectionTools;
import org.hibernate.envers.tools.Tools;
-import org.hibernate.MappingException;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.property.Getter;
@@ -56,16 +55,16 @@
propertyDatas.put(propertyData.getName(), propertyData);
}
- public CompositeMapperBuilder addComposite(PropertyData propertyData) {
+ public CompositeMapperBuilder addComponent(PropertyData propertyData) {
if (properties.get(propertyData) != null) {
- throw new MappingException("Mapping for " + propertyData.getName() + " already added!");
+ // This is needed for second pass to work properly in the components mapper
+ return (CompositeMapperBuilder) properties.get(propertyData);
}
- MapPropertyMapper mapperBuilder = new MapPropertyMapper(propertyData);
- properties.put(propertyData, mapperBuilder);
- propertyDatas.put(propertyData.getName(), propertyData);
+ ComponentPropertyMapper componentMapperBuilder = new ComponentPropertyMapper(propertyData);
+ addComposite(propertyData, componentMapperBuilder);
- return mapperBuilder;
+ return componentMapperBuilder;
}
public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper) {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/SubclassPropertyMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/SubclassPropertyMapper.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/SubclassPropertyMapper.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -70,18 +70,22 @@
PersistentCollection newColl,
Serializable oldColl,
Serializable id) {
- List<PersistentCollectionChangeData> collectionChanges = parentMapper.mapCollectionChanges(
+ List<PersistentCollectionChangeData> parentCollectionChanges = parentMapper.mapCollectionChanges(
referencingPropertyName, newColl, oldColl, id);
- if (collectionChanges == null) {
- return main.mapCollectionChanges(referencingPropertyName, newColl, oldColl, id);
+ List<PersistentCollectionChangeData> mainCollectionChanges = main.mapCollectionChanges(
+ referencingPropertyName, newColl, oldColl, id);
+
+ if (parentCollectionChanges == null) {
+ return mainCollectionChanges;
} else {
- return collectionChanges;
+ parentCollectionChanges.addAll(mainCollectionChanges);
+ return parentCollectionChanges;
}
}
- public CompositeMapperBuilder addComposite(PropertyData propertyData) {
- return main.addComposite(propertyData);
+ public CompositeMapperBuilder addComponent(PropertyData propertyData) {
+ return main.addComponent(propertyData);
}
public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper) {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/id/EmbeddedIdMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/id/EmbeddedIdMapper.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/id/EmbeddedIdMapper.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -88,8 +88,7 @@
for (PropertyData propertyData : ids.keySet()) {
String propertyName = propertyData.getName();
- ret.ids.put(propertyData, new SingleIdMapper(propertyName,
- new PropertyData(prefix + propertyName, propertyData)));
+ ret.ids.put(propertyData, new SingleIdMapper(new PropertyData(prefix + propertyName, propertyData)));
}
return ret;
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/id/MultipleIdMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/id/MultipleIdMapper.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/id/MultipleIdMapper.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -60,8 +60,7 @@
for (PropertyData propertyData : ids.keySet()) {
String propertyName = propertyData.getName();
- ret.ids.put(propertyData, new SingleIdMapper(propertyName,
- new PropertyData(prefix + propertyName, propertyData)));
+ ret.ids.put(propertyData, new SingleIdMapper(new PropertyData(prefix + propertyName, propertyData)));
}
return ret;
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/id/SingleIdMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/id/SingleIdMapper.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/id/SingleIdMapper.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -38,19 +38,12 @@
* @author Adam Warski (adam at warski dot org)
*/
public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBuilder {
- private String beanPropertyName;
private PropertyData propertyData;
public SingleIdMapper() {
}
- public SingleIdMapper(String beanPropertyName, PropertyData propertyData) {
- this.beanPropertyName = beanPropertyName;
- this.propertyData = propertyData;
- }
-
public SingleIdMapper(PropertyData propertyData) {
- this.beanPropertyName = propertyData.getName();
this.propertyData = propertyData;
}
@@ -60,7 +53,6 @@
}
this.propertyData = propertyData;
- this.beanPropertyName = propertyData.getName();
}
public void mapToEntityFromMap(Object obj, Map data) {
@@ -68,7 +60,7 @@
return;
}
- Setter setter = ReflectionTools.getSetter(obj.getClass(), beanPropertyName, propertyData.getAccessType());
+ Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData);
setter.set(obj, data.get(propertyData.getName()), null);
}
@@ -85,7 +77,7 @@
return null;
}
- Getter getter = ReflectionTools.getGetter(data.getClass(), beanPropertyName, propertyData.getAccessType());
+ Getter getter = ReflectionTools.getGetter(data.getClass(), propertyData);
return getter.get(data);
}
@@ -99,7 +91,7 @@
if (obj == null) {
data.put(propertyData.getName(), null);
} else {
- Getter getter = ReflectionTools.getGetter(obj.getClass(), beanPropertyName, propertyData.getAccessType());
+ Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyData);
data.put(propertyData.getName(), getter.get(obj));
}
}
@@ -109,14 +101,13 @@
return;
}
- Getter getter = ReflectionTools.getGetter(objFrom.getClass(), beanPropertyName, propertyData.getAccessType());
- Setter setter = ReflectionTools.getSetter(objTo.getClass(), beanPropertyName, propertyData.getAccessType());
+ Getter getter = ReflectionTools.getGetter(objFrom.getClass(), propertyData);
+ Setter setter = ReflectionTools.getSetter(objTo.getClass(), propertyData);
setter.set(objTo, getter.get(objFrom), null);
}
public IdMapper prefixMappedProperties(String prefix) {
- return new SingleIdMapper(propertyData.getName(),
- new PropertyData(prefix + propertyData.getName(), propertyData));
+ return new SingleIdMapper(new PropertyData(prefix + propertyData.getName(), propertyData));
}
public List<QueryParameterData> mapToQueryParametersFromId(Object obj) {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/tools/reflection/ReflectionTools.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/tools/reflection/ReflectionTools.java 2008-12-29 08:52:31 UTC (rev 15743)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/tools/reflection/ReflectionTools.java 2008-12-31 11:29:37 UTC (rev 15744)
@@ -59,7 +59,7 @@
}
public static Getter getGetter(Class cls, PropertyData propertyData) {
- return getGetter(cls, propertyData.getName(), propertyData.getAccessType());
+ return getGetter(cls, propertyData.getBeanName(), propertyData.getAccessType());
}
public static Getter getGetter(Class cls, String propertyName, String accessorType) {
@@ -75,10 +75,10 @@
}
public static Setter getSetter(Class cls, PropertyData propertyData) {
- return getSetter(cls, propertyData.getName(), propertyData.getAccessType());
+ return getSetter(cls, propertyData.getBeanName(), propertyData.getAccessType());
}
- public static Setter getSetter(Class cls, String propertyName, String accessorType) {
+ private static Setter getSetter(Class cls, String propertyName, String accessorType) {
Pair<Class, String> key = make(cls, propertyName);
Setter value = setterCache.get(key);
if (value == null) {
15 years, 10 months