Author: adamw
Date: 2008-08-14 06:19:45 -0400 (Thu, 14 Aug 2008)
New Revision: 102
Modified:
trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
trunk/src/main/org/jboss/envers/mapper/MapPropertyMapper.java
trunk/src/main/org/jboss/envers/mapper/MultiPropertyMapper.java
trunk/src/main/org/jboss/envers/mapper/SinglePropertyMapper.java
trunk/src/main/org/jboss/envers/mapper/id/EmbeddedIdMapper.java
trunk/src/main/org/jboss/envers/mapper/id/SingleIdMapper.java
trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java
trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.java
trunk/src/main/org/jboss/envers/mapper/id/relation/ToOneIdMapper.java
trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java
trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java
Log:
ENVERS-37: moving reflection and log facades to tools
Modified: trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java 2008-08-14
10:11:22 UTC (rev 101)
+++
trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java 2008-08-14
10:19:45 UTC (rev 102)
@@ -22,7 +22,7 @@
package org.jboss.envers.configuration;
import org.jboss.envers.RevisionListener;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.hibernate.MappingException;
import org.hibernate.property.Setter;
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-14
10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-14
10:19:45 UTC (rev 102)
@@ -32,7 +32,7 @@
import org.jboss.envers.mapper.ExtendedPropertyMapper;
import org.jboss.envers.mapper.id.IdMapper;
import org.jboss.envers.tools.graph.GraphTopologicalSort;
-import org.jboss.envers.reflection.YReflectionManager;
+import org.jboss.envers.tools.reflection.YReflectionManager;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.XMLWriter;
Modified:
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-08-14
10:11:22 UTC (rev 101)
+++
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-08-14
10:19:45 UTC (rev 102)
@@ -27,9 +27,9 @@
import org.jboss.envers.RevisionEntity;
import org.jboss.envers.RevisionNumber;
import org.jboss.envers.RevisionTimestamp;
-import org.jboss.envers.reflection.YReflectionManager;
-import org.jboss.envers.reflection.YClass;
-import org.jboss.envers.reflection.YProperty;
+import org.jboss.envers.tools.reflection.YReflectionManager;
+import org.jboss.envers.tools.reflection.YClass;
+import org.jboss.envers.tools.reflection.YProperty;
import org.jboss.envers.tools.MutableBoolean;
import java.util.*;
Modified: trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-14 10:11:22 UTC
(rev 101)
+++ trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-14 10:19:45 UTC
(rev 102)
@@ -25,7 +25,7 @@
import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.mapper.id.IdMapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import java.util.Map;
import java.util.List;
Modified: trunk/src/main/org/jboss/envers/mapper/MapPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/MapPropertyMapper.java 2008-08-14 10:11:22 UTC
(rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/MapPropertyMapper.java 2008-08-14 10:19:45 UTC
(rev 102)
@@ -22,7 +22,7 @@
package org.jboss.envers.mapper;
import org.jboss.envers.ModificationStore;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
import org.hibernate.property.Getter;
Modified: trunk/src/main/org/jboss/envers/mapper/MultiPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/MultiPropertyMapper.java 2008-08-14 10:11:22
UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/MultiPropertyMapper.java 2008-08-14 10:19:45
UTC (rev 102)
@@ -24,7 +24,7 @@
import org.hibernate.property.Getter;
import org.hibernate.MappingException;
import org.jboss.envers.ModificationStore;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
import java.util.Map;
Modified: trunk/src/main/org/jboss/envers/mapper/SinglePropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/SinglePropertyMapper.java 2008-08-14 10:11:22
UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/SinglePropertyMapper.java 2008-08-14 10:19:45
UTC (rev 102)
@@ -22,7 +22,7 @@
package org.jboss.envers.mapper;
import org.jboss.envers.ModificationStore;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.tools.Tools;
import org.jboss.envers.exception.VersionsException;
Modified: trunk/src/main/org/jboss/envers/mapper/id/EmbeddedIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/EmbeddedIdMapper.java 2008-08-14 10:11:22
UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/id/EmbeddedIdMapper.java 2008-08-14 10:19:45
UTC (rev 102)
@@ -25,7 +25,7 @@
import org.hibernate.property.Setter;
import org.hibernate.util.ReflectHelper;
import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import java.util.Map;
import java.util.Set;
Modified: trunk/src/main/org/jboss/envers/mapper/id/SingleIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/SingleIdMapper.java 2008-08-14 10:11:22 UTC
(rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/id/SingleIdMapper.java 2008-08-14 10:19:45 UTC
(rev 102)
@@ -22,7 +22,7 @@
package org.jboss.envers.mapper.id;
import org.jboss.envers.ModificationStore;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.exception.VersionsException;
import org.hibernate.property.Setter;
import org.hibernate.property.Getter;
Modified: trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java 2008-08-14
10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java 2008-08-14
10:19:45 UTC (rev 102)
@@ -27,7 +27,7 @@
import org.jboss.envers.reader.lazy.proxy.ListProxy;
import org.jboss.envers.reader.lazy.proxy.SetProxy;
import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.hibernate.property.Setter;
import org.hibernate.property.Getter;
Modified: trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.java 2008-08-14
10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.java 2008-08-14
10:19:45 UTC (rev 102)
@@ -23,7 +23,7 @@
import org.jboss.envers.mapper.PropertyMapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.hibernate.property.Setter;
import java.util.Map;
Modified: trunk/src/main/org/jboss/envers/mapper/id/relation/ToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/relation/ToOneIdMapper.java 2008-08-14
10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/id/relation/ToOneIdMapper.java 2008-08-14
10:19:45 UTC (rev 102)
@@ -24,7 +24,7 @@
import org.jboss.envers.mapper.PropertyMapper;
import org.jboss.envers.mapper.id.IdMapper;
import org.jboss.envers.tools.Tools;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.reader.lazy.ToOneDelegateSessionImplementor;
import org.hibernate.property.Setter;
Modified: trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java 2008-08-14
10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java 2008-08-14
10:19:45 UTC (rev 102)
@@ -21,9 +21,9 @@
*/
package org.jboss.envers.metadata;
-import org.jboss.envers.reflection.YClass;
-import org.jboss.envers.reflection.YProperty;
-import org.jboss.envers.reflection.YReflectionManager;
+import org.jboss.envers.tools.reflection.YClass;
+import org.jboss.envers.tools.reflection.YProperty;
+import org.jboss.envers.tools.reflection.YReflectionManager;
import org.jboss.envers.metadata.data.PersistentClassVersioningData;
import org.jboss.envers.Versioned;
import org.jboss.envers.VersionsTable;
Modified: trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java 2008-08-14
10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java 2008-08-14
10:19:45 UTC (rev 102)
@@ -42,8 +42,8 @@
import org.jboss.envers.tools.Tools;
import org.jboss.envers.tools.HibernateVersion;
import org.jboss.envers.ModificationStore;
-import org.jboss.envers.log.YLog;
-import org.jboss.envers.log.YLogManager;
+import org.jboss.envers.tools.log.YLog;
+import org.jboss.envers.tools.log.YLogManager;
import org.jboss.envers.metadata.data.IdMappingData;
import org.jboss.envers.metadata.data.PersistentClassVersioningData;
import org.jboss.envers.metadata.data.PropertyStoreInfo;
@@ -223,7 +223,7 @@
}
@SuppressWarnings({"unchecked"})
- private void addOneToOne(Property property, CompositeMapperBuilder mapper, String
entityName) {
+ private void addOneToOneBidirectional(Property property, CompositeMapperBuilder
mapper, String entityName) {
OneToOne propertyValue = (OneToOne) property.getValue();
String owningReferencePropertyName = propertyValue.getReferencedPropertyName();
// mappedBy
@@ -273,7 +273,7 @@
}
@SuppressWarnings({"unchecked"})
- private void addOneToMany(Property property, CompositeMapperBuilder mapper, String
entityName) {
+ private void addOneToManyBidirectional(Property property, CompositeMapperBuilder
mapper, String entityName) {
Collection propertyValue = (Collection) property.getValue();
String owningReferencePropertyName = getMappedBy(propertyValue);
@@ -304,6 +304,35 @@
propertyName));
}
+ @SuppressWarnings({"unchecked"})
+ private void addOneToManyUnidirectional(Property property, CompositeMapperBuilder
mapper, String entityName) {
+ Collection propertyValue = (Collection) property.getValue();
+ ManyToOne mto = (ManyToOne) propertyValue.getElement();
+
+ String referencedEntityName = mto.getReferencedEntityName();
+
+ EntityConfiguration configuration = entitiesConfigurations.get(entityName);
+ if (configuration == null) {
+ throw new MappingException("A versioned relation to a non-versioned
entity " + entityName + "!");
+ }
+
+ EntityConfiguration referencedConfiguration =
entitiesConfigurations.get(referencedEntityName);
+ if (referencedConfiguration == null) {
+ throw new MappingException("A versioned relation to a non-versioned
entity " + referencedEntityName + "!");
+ }
+
+ IdMappingData referencingIdMapping = configuration.getIdMappingData();
+ IdMappingData referencedIdMapping = referencedConfiguration.getIdMappingData();
+
+ // Name of the entity that will be used to store the relation between the two
entities.
+ String middleEntityName = entityName + "_" + referencedEntityName;
+
+ MetadataTools.createEntity(null, middleEntityName, mto.getTable().getName(),
mto.getTable().getSchema(),
+ mto.getTable().getCatalog(), null);
+
+ // TODO: ???
+ }
+
private ModificationStore getStoreForProperty(Property property, PropertyStoreInfo
propertyStoreInfo) {
/*
* Checks if a property is versioned, which is when:
@@ -369,7 +398,7 @@
} else if (propertyType instanceof OneToOneType) {
// only second pass
if (!firstPass) {
- addOneToOne(property, currentMapper, entityName);
+ addOneToOneBidirectional(property, currentMapper,
entityName);
}
} else if
("org.hibernate.type.PrimitiveByteArrayBlobType".equals(
propertyType.getClass().getName())) {
@@ -388,8 +417,14 @@
((((Collection) property.getValue()).getElement() instanceof
OneToMany))) {
// only second pass
if (!firstPass) {
- addOneToMany(property, currentMapper, entityName);
+ addOneToManyBidirectional(property, currentMapper,
entityName);
}
+ } else if ((propertyType instanceof BagType || propertyType
instanceof SetType) &&
+ ((((Collection) property.getValue()).getElement() instanceof
ManyToOne))) {
+ // only second pass
+ if (!firstPass) {
+ addOneToManyUnidirectional(property, currentMapper,
entityName);
+ }
} else {
String message = "Type not supported for versioning: "
+ propertyType.getClass().getName() +
", on entity " + entityName + ", property
'" + property.getName() + "'.";
@@ -457,9 +492,9 @@
@SuppressWarnings({"unchecked"})
private IdMappingData addId(PersistentClass pc) {
- // Mapping which will be used for relations
+ // Xml mapping which will be used for relations
Element rel_id_mapping = new DefaultElement("properties");
- // Mapping which will be used for the primary key of the versions table
+ // Xml mapping which will be used for the primary key of the versions table
Element orig_id_mapping = new DefaultElement("composite-id");
Property id_prop = pc.getIdentifierProperty();
@@ -491,7 +526,6 @@
orig_id_mapping.addAttribute("name",
verEntCfg.getOriginalIdPropName());
-
// Adding the "revision number" property
Element rev_mapping = MetadataTools.addProperty(orig_id_mapping,
verEntCfg.getRevisionPropName(),
verEntCfg.getRevisionPropType(), true);