Author: adamw
Date: 2008-08-25 03:04:48 -0400 (Mon, 25 Aug 2008)
New Revision: 126
Removed:
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyDetachedInitializor.java
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java
trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java
Log:
ENVERS-24: generating revision numbers for bidirectional many-to-many relations
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-23
10:59:58 UTC (rev 125)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-25
07:04:48 UTC (rev 126)
@@ -384,8 +384,6 @@
versionsMiddleEntityName,
referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
referencedIdMapping.getIdMapper().prefixMappedProperties(referencedPrefix),
entitiesConfigurations.get(referencedEntityName).getIdMapper()));
-
- // TODO: ???
}
@SuppressWarnings({"unchecked"})
@@ -405,8 +403,7 @@
return null;
}
- private void addManyToManyNotOwning(Property property, CompositeMapperBuilder mapper,
String entityName,
- EntityMappingData mappingData) {
+ private void addManyToManyNotOwning(Property property, CompositeMapperBuilder mapper,
String entityName) {
Collection propertyValue = (Collection) property.getValue();
ManyToOne mto = (ManyToOne) propertyValue.getElement();
@@ -448,8 +445,6 @@
versionsMiddleEntityName,
referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
referencedIdMapping.getIdMapper().prefixMappedProperties(referencedPrefix),
entitiesConfigurations.get(referencedEntityName).getIdMapper()));
-
- // TODO
}
private ModificationStore getStoreForProperty(Property property, PropertyStoreInfo
propertyStoreInfo,
@@ -558,7 +553,7 @@
((Collection) property.getValue()).isInverse()) {
// only second pass
if (!firstPass) {
- addManyToManyNotOwning(property, currentMapper, entityName,
mappingData);
+ addManyToManyNotOwning(property, currentMapper, entityName);
}
} else {
String message = "Type not supported for versioning: "
+ propertyType.getClass().getName() +
Modified:
trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java 2008-08-23
10:59:58 UTC (rev 125)
+++
trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java 2008-08-25
07:04:48 UTC (rev 126)
@@ -6,12 +6,14 @@
* @author Adam Warski (adam at warski dot org)
*/
public class PersistentCollectionChangeData {
- private String entityName;
- private Map<String, Object> data;
+ private final String entityName;
+ private final Map<String, Object> data;
+ private final Object obj;
- public PersistentCollectionChangeData(String entityName, Map<String, Object>
data) {
+ public PersistentCollectionChangeData(String entityName, Map<String, Object>
data, Object obj) {
this.entityName = entityName;
this.data = data;
+ this.obj = obj;
}
public String getEntityName() {
@@ -21,4 +23,8 @@
public Map<String, Object> getData() {
return data;
}
+
+ public Object getObj() {
+ return obj;
+ }
}
Modified:
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java 2008-08-23
10:59:58 UTC (rev 125)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java 2008-08-25
07:04:48 UTC (rev 126)
@@ -69,7 +69,7 @@
Map<String, Object> originalId = new HashMap<String, Object>();
entityData.put(verEntCfg.getOriginalIdPropName(), originalId);
- collectionChanges.add(new
PersistentCollectionChangeData(versionsMiddleEntityName, entityData));
+ collectionChanges.add(new
PersistentCollectionChangeData(versionsMiddleEntityName, entityData, changedEntity));
referencingMiddleIdMapper.mapToMapFromId(originalId, id);
referencedMiddleIdMapper.mapToMapFromEntity(originalId, changedEntity);
Deleted:
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyDetachedInitializor.java
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyDetachedInitializor.java 2008-08-23
10:59:58 UTC (rev 125)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyDetachedInitializor.java 2008-08-25
07:04:48 UTC (rev 126)
@@ -1,55 +0,0 @@
-package org.jboss.envers.entities.mapper.relation.lazy;
-
-import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
-import org.jboss.envers.entities.mapper.relation.DetachedRelationQueryGenerator;
-import org.jboss.envers.entities.EntityInstantiator;
-import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.configuration.VersionsConfiguration;
-
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class OneToManyDetachedInitializor<T extends Collection> implements
Initializor<T> {
- private final VersionsConfiguration verCfg;
- private final String entityName;
- private final DetachedRelationQueryGenerator queryGenerator;
- private final VersionsReaderImplementor versionsReader;
- private final Object primaryKey;
- private final Number revision;
- private final Class<T> collectionClass;
-
- public OneToManyDetachedInitializor(VersionsConfiguration verCfg, String entityName,
- DetachedRelationQueryGenerator
queryGenerator,
- VersionsReaderImplementor versionsReader,
Object primaryKey,
- Number revision, Class<T>
collectionClass) {
- this.verCfg = verCfg;
- this.entityName = entityName;
- this.queryGenerator = queryGenerator;
- this.versionsReader = versionsReader;
- this.primaryKey = primaryKey;
- this.revision = revision;
- this.collectionClass = collectionClass;
- }
-
- @SuppressWarnings({"unchecked"})
- public T initialize() {
- EntityInstantiator entityInstantiator = new EntityInstantiator(verCfg,
versionsReader);
-
- List queryResult = queryGenerator.getQuery(versionsReader, primaryKey,
revision).list();
-
- T result;
- try {
- result = collectionClass.newInstance();
- } catch (Exception e) {
- throw new VersionsException(e);
- }
-
- entityInstantiator.addInstancesFromVersionsEntities(entityName, result,
queryResult, revision);
-
- return result;
- }
-}
Modified: trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
===================================================================
--- trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-23 10:59:58
UTC (rev 125)
+++ trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-25 07:04:48
UTC (rev 126)
@@ -33,6 +33,7 @@
import org.jboss.envers.synchronization.work.*;
import org.jboss.envers.tools.Tools;
import org.jboss.envers.entities.mapper.id.IdMapper;
+import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
import java.io.Serializable;
@@ -121,6 +122,30 @@
}
}
+ private void generateBidirectionalCollectionChangeWorkUnits(VersionsSync verSync,
AbstractCollectionEvent event,
+
PersistentCollectionChangeWorkUnit workUnit) {
+ // Checking if this is enabled in configuration ...
+ if (!verCfg.getGlobalCfg().isGenerateRevisionsForCollections()) {
+ return;
+ }
+
+ // Checking if this is not a bidirectional relation - then, a revision needs also
be generated for
+ // the other side of the relation.
+ RelationDescription relDesc =
verCfg.getEntCfg().getRelationDescription(event.getAffectedOwnerEntityName(),
+ workUnit.getReferencingPropertyName());
+ String relatedEntityName = relDesc.getToEntityName();
+ IdMapper relatedIdMapper =
verCfg.getEntCfg().get(relatedEntityName).getIdMapper();
+
+ if (relDesc.isBidirectional()) {
+ for (PersistentCollectionChangeData changeData :
workUnit.getCollectionChanges()) {
+ Object relatedObj = changeData.getObj();
+ Serializable relatedId = (Serializable)
relatedIdMapper.mapToIdFromEntity(relatedObj);
+
+ verSync.addWorkUnit(new CollectionChangeWorkUnit(relatedEntityName,
verCfg, relatedId, relatedObj));
+ }
+ }
+ }
+
private void onCollectionAction(AbstractCollectionEvent event, PersistentCollection
newColl, Serializable oldColl,
CollectionEntry collectionEntry) {
String entityName = event.getAffectedOwnerEntityName();
@@ -137,13 +162,7 @@
verSync.addWorkUnit(new
CollectionChangeWorkUnit(event.getAffectedOwnerEntityName(), verCfg,
event.getAffectedOwnerIdOrNull(),
event.getAffectedOwnerOrNull()));
- // Checking if this is not a bidirectional relation - then, a revision
needs also be generated for
- // the other side of the relation.
- RelationDescription relDesc =
verCfg.getEntCfg().getRelationDescription(event.getAffectedOwnerEntityName(),
- workUnit.getReferencingPropertyName());
- if (relDesc.isBidirectional()) {
- // TODO: we have to add a revision for each changed element of the
collection
- }
+ generateBidirectionalCollectionChangeWorkUnits(verSync, event,
workUnit);
}
}
}
Modified:
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
===================================================================
---
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-08-23
10:59:58 UTC (rev 125)
+++
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-08-25
07:04:48 UTC (rev 126)
@@ -49,6 +49,10 @@
return referencingPropertyName;
}
+ public List<PersistentCollectionChangeData> getCollectionChanges() {
+ return collectionChanges;
+ }
+
public KeepCheckResult check(AddWorkUnit second) {
return null;
}
Modified:
trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java 2008-08-23
10:59:58 UTC (rev 125)
+++
trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java 2008-08-25
07:04:48 UTC (rev 126)
@@ -86,7 +86,7 @@
@Test
public void testJoinColumnName() {
Iterator<Column> columns =
-
getCfg().getClassMapping("org.jboss.envers.test.integration.naming..DetachedNamingTestEntity_org.jboss.envers.test.entities.StrTestEntity_versions")
+
getCfg().getClassMapping("org.jboss.envers.test.integration.naming.DetachedNamingTestEntity_org.jboss.envers.test.entities.StrTestEntity_versions")
.getTable().getColumnIterator();
boolean id1Found = false;