Author: steve.ebersole(a)jboss.com
Date: 2010-06-30 09:25:04 -0400 (Wed, 30 Jun 2010)
New Revision: 19860
Modified:
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/configuration/metadata/BasicMetadataGenerator.java
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/entities/EntityConfiguration.java
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java
Log:
pulled over the latest changes from trunk to get envers tests running
Modified:
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/configuration/metadata/BasicMetadataGenerator.java
===================================================================
---
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/configuration/metadata/BasicMetadataGenerator.java 2010-06-30
11:50:41 UTC (rev 19859)
+++
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/configuration/metadata/BasicMetadataGenerator.java 2010-06-30
13:25:04 UTC (rev 19860)
@@ -34,8 +34,6 @@
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Value;
import org.hibernate.type.BasicType;
-import org.hibernate.type.CompositeCustomType;
-import org.hibernate.type.CustomType;
import org.hibernate.type.Type;
/**
@@ -43,66 +41,40 @@
* @author Adam Warski (adam at warski dot org)
*/
public final class BasicMetadataGenerator {
+ @SuppressWarnings({"unchecked"})
boolean addBasic(Element parent, PropertyAuditingData propertyAuditingData,
Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
Type type = value.getType();
- if ( type instanceof BasicType ) {
- addSimpleValue(parent, propertyAuditingData, value, mapper, insertable, key);
- } else if (type instanceof CustomType || type instanceof CompositeCustomType) {
- addCustomValue(parent, propertyAuditingData, value, mapper, insertable, key);
- } else if
("org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName()))
{
- addSimpleValue(parent, propertyAuditingData, value, mapper, insertable, key);
- } else {
- return false;
- }
+ if (type instanceof BasicType ||
"org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName()))
{
+ if (parent != null) {
+ boolean addNestedType = (value instanceof SimpleValue) &&
((SimpleValue) value).getTypeParameters() != null;
- return true;
- }
+ Element prop_mapping = MetadataTools.addProperty(parent,
propertyAuditingData.getName(),
+ addNestedType ? null : value.getType().getName(),
propertyAuditingData.isForceInsertable() || insertable, key);
+ MetadataTools.addColumns(prop_mapping, (Iterator<Column>)
value.getColumnIterator());
- @SuppressWarnings({"unchecked"})
- private void addSimpleValue(Element parent, PropertyAuditingData propertyAuditingData,
- Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
- if (parent != null) {
- Element prop_mapping = MetadataTools.addProperty(parent,
propertyAuditingData.getName(),
- value.getType().getName(), propertyAuditingData.isForceInsertable() || insertable,
key);
- MetadataTools.addColumns(prop_mapping, (Iterator<Column>)
value.getColumnIterator());
- }
+ if (addNestedType) {
+ Properties typeParameters = ((SimpleValue)
value).getTypeParameters();
+ Element type_mapping = prop_mapping.addElement("type");
+ type_mapping.addAttribute("name",
value.getType().getName());
- // A null mapper means that we only want to add xml mappings
- if (mapper != null) {
- mapper.add(propertyAuditingData.getPropertyData());
- }
- }
+ 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());
+ }
+ }
+ }
- @SuppressWarnings({"unchecked"})
- private void addCustomValue(Element parent, PropertyAuditingData propertyAuditingData,
- Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
- if (parent != null) {
- Element prop_mapping = MetadataTools.addProperty(parent,
propertyAuditingData.getName(),
- null, insertable, key);
-
- //CustomType propertyType = (CustomType) value.getType();
-
- Element type_mapping = prop_mapping.addElement("type");
- type_mapping.addAttribute("name", value.getType().getName());
-
- 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());
+ // A null mapper means that we only want to add xml mappings
+ if (mapper != null) {
+ mapper.add(propertyAuditingData.getPropertyData());
+ }
+ } else {
+ return false;
}
- if (mapper != null) {
- mapper.add(propertyAuditingData.getPropertyData());
- }
+ return true;
}
}
Modified:
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/entities/EntityConfiguration.java
===================================================================
---
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/entities/EntityConfiguration.java 2010-06-30
11:50:41 UTC (rev 19859)
+++
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/entities/EntityConfiguration.java 2010-06-30
13:25:04 UTC (rev 19860)
@@ -100,12 +100,12 @@
return propertyMapper;
}
- // For use by EntitiesConfigurations
-
- String getParentEntityName() {
+ public String getParentEntityName() {
return parentEntityName;
}
+ // For use by EntitiesConfigurations
+
String getVersionsEntityName() {
return versionsEntityName;
}
Modified:
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java
===================================================================
---
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java 2010-06-30
11:50:41 UTC (rev 19859)
+++
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java 2010-06-30
13:25:04 UTC (rev 19860)
@@ -27,16 +27,15 @@
import java.util.List;
import java.util.Map;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.envers.configuration.AuditConfiguration;
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.Setter;
import org.hibernate.util.ReflectHelper;
-import org.hibernate.engine.SessionImplementor;
/**
* @author Adam Warski (adam at warski dot org)
@@ -84,8 +83,11 @@
}
}
- // And we don't have to set anything on the object - the default value is null
- if (!allNullAndSingle) {
+ if (allNullAndSingle) {
+ // single property, but default value need not be null, so we'll set it to null
anyway
+ setter.set(obj, null, null);
+ } else {
+ // set the component
try {
Object subObj = ReflectHelper.getDefaultConstructor(
Thread.currentThread().getContextClassLoader().loadClass(componentClassName)).newInstance();
@@ -97,7 +99,7 @@
}
}
- public List<PersistentCollectionChangeData> mapCollectionChanges(String
referencingPropertyName,
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String
referencingPropertyName,
PersistentCollection newColl,
Serializable oldColl,
Serializable id) {
Modified:
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java
===================================================================
---
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2010-06-30
11:50:41 UTC (rev 19859)
+++
core/branches/gradle2/hibernate-envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2010-06-30
13:25:04 UTC (rev 19860)
@@ -27,6 +27,7 @@
import java.util.List;
import org.hibernate.envers.configuration.AuditConfiguration;
+import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.entities.RelationDescription;
import org.hibernate.envers.entities.RelationType;
import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData;
@@ -264,7 +265,7 @@
// Checking if this is not a "fake" many-to-one bidirectional
relation. The relation description may be
// null in case of collections of non-entities.
- RelationDescription rd =
verCfg.getEntCfg().get(entityName).getRelationDescription(referencingPropertyName);
+ RelationDescription rd = searchForRelationDescription(entityName,
referencingPropertyName);
if (rd != null && rd.getMappedByPropertyName() != null) {
generateFakeBidirecationalRelationWorkUnits(auditProcess, newColl,
oldColl, entityName,
referencingPropertyName, event, rd);
@@ -285,6 +286,24 @@
}
}
+ /**
+ * Looks up a relation description corresponding to the given property in the given
entity. If no description is
+ * found in the given entity, the parent entity is checked (so that inherited
relations work).
+ * @param entityName Name of the entity, in which to start looking.
+ * @param referencingPropertyName The name of the property.
+ * @return A found relation description corresponding to the given entity or {@code
null}, if no description can
+ * be found.
+ */
+ private RelationDescription searchForRelationDescription(String entityName, String
referencingPropertyName) {
+ EntityConfiguration configuration = verCfg.getEntCfg().get(entityName);
+ RelationDescription rd =
configuration.getRelationDescription(referencingPropertyName);
+ if (rd == null && configuration.getParentEntityName() != null) {
+ return searchForRelationDescription(configuration.getParentEntityName(),
referencingPropertyName);
+ }
+
+ return rd;
+ }
+
private CollectionEntry getCollectionEntry(AbstractCollectionEvent event) {
return
event.getSession().getPersistenceContext().getCollectionEntry(event.getCollection());
}