Author: adamw
Date: 2008-08-25 05:32:06 -0400 (Mon, 25 Aug 2008)
New Revision: 130
Added:
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DoubleNotOwnedSet.java
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
Log:
ENVERS-26: support for multiple one-to-many detached relations, with test
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-25
08:53:52 UTC (rev 129)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-25
09:32:06 UTC (rev 130)
@@ -347,7 +347,7 @@
String referencedPrefix = property.getName() + "_";
// Name of the entity that will be used to store the relation between the two
entities.
- String middleEntityName = entityName + "_" + referencedEntityName;
+ String middleEntityName = entityName + "_" + referencedEntityName +
"_" + mto.getTable().getName();
String versionsMiddleEntityName =
verEntCfg.getVersionsEntityName(middleEntityName);
String versionsMiddleTableName = verEntCfg.getVersionsTableName(middleEntityName,
mto.getTable().getName());
Modified: trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
===================================================================
--- trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-25 08:53:52
UTC (rev 129)
+++ trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-25 09:32:06
UTC (rev 130)
@@ -133,10 +133,11 @@
// 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()) {
+ String relatedEntityName = relDesc.getToEntityName();
+ IdMapper relatedIdMapper =
verCfg.getEntCfg().get(relatedEntityName).getIdMapper();
+
for (PersistentCollectionChangeData changeData :
workUnit.getCollectionChanges()) {
Object relatedObj = changeData.getObj();
Serializable relatedId = (Serializable)
relatedIdMapper.mapToIdFromEntity(relatedObj);
Modified:
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
===================================================================
---
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-08-25
08:53:52 UTC (rev 129)
+++
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-08-25
09:32:06 UTC (rev 130)
@@ -29,7 +29,7 @@
}
public boolean containsWork() {
- return collectionChanges == null || collectionChanges.size() != 0;
+ return collectionChanges != null && collectionChanges.size() != 0;
}
@SuppressWarnings({"unchecked"})
Copied:
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java
(from rev 124,
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/SetRefCollEntity.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java 2008-08-25
09:32:06 UTC (rev 130)
@@ -0,0 +1,100 @@
+package org.jboss.envers.test.entities.onetomany.detached;
+
+import org.jboss.envers.Versioned;
+import org.jboss.envers.test.entities.StrTestEntity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.JoinTable;
+import java.util.Set;
+
+/**
+ * Set collection of references entity
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class DoubleSetRefCollEntity {
+ @Id
+ private Integer id;
+
+ @Versioned
+ private String data;
+
+ @Versioned
+ @OneToMany
+ @JoinTable(name = "DOUBLE_STR_1")
+ private Set<StrTestEntity> collection;
+
+ @Versioned
+ @OneToMany
+ @JoinTable(name = "DOUBLE_STR_2")
+ private Set<StrTestEntity> collection2;
+
+ public DoubleSetRefCollEntity() {
+ }
+
+ public DoubleSetRefCollEntity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public DoubleSetRefCollEntity(String data) {
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public Set<StrTestEntity> getCollection() {
+ return collection;
+ }
+
+ public void setCollection(Set<StrTestEntity> collection) {
+ this.collection = collection;
+ }
+
+ public Set<StrTestEntity> getCollection2() {
+ return collection2;
+ }
+
+ public void setCollection2(Set<StrTestEntity> collection2) {
+ this.collection2 = collection2;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof DoubleSetRefCollEntity)) return false;
+
+ DoubleSetRefCollEntity that = (DoubleSetRefCollEntity) o;
+
+ if (data != null ? !data.equals(that.data) : that.data != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "DoubleSetRefEdEntity(id = " + id + ", data = " + data
+ ")";
+ }
+}
\ No newline at end of file
Property changes on:
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied:
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DoubleNotOwnedSet.java
(from rev 124,
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSet.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DoubleNotOwnedSet.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DoubleNotOwnedSet.java 2008-08-25
09:32:06 UTC (rev 130)
@@ -0,0 +1,108 @@
+package org.jboss.envers.test.integration.onetomany.detached;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.onetomany.detached.DoubleSetRefCollEntity;
+import org.jboss.envers.test.entities.StrTestEntity;
+import org.jboss.envers.test.tools.TestTools;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class DoubleNotOwnedSet extends AbstractEntityTest {
+ private Integer str1_id;
+ private Integer str2_id;
+
+ private Integer coll1_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(StrTestEntity.class);
+ cfg.addAnnotatedClass(DoubleSetRefCollEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ StrTestEntity str1 = new StrTestEntity("str1");
+ StrTestEntity str2 = new StrTestEntity("str2");
+
+ DoubleSetRefCollEntity coll1 = new DoubleSetRefCollEntity(3, "coll1");
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ em.persist(str1);
+ em.persist(str2);
+
+ coll1.setCollection(new HashSet<StrTestEntity>());
+ coll1.getCollection().add(str1);
+ em.persist(coll1);
+
+ coll1.setCollection2(new HashSet<StrTestEntity>());
+ coll1.getCollection2().add(str2);
+ em.persist(coll1);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ str2 = em.find(StrTestEntity.class, str2.getId());
+ coll1 = em.find(DoubleSetRefCollEntity.class, coll1.getId());
+
+ coll1.getCollection().add(str2);
+
+ em.getTransaction().commit();
+
+ // Revision 3
+ em.getTransaction().begin();
+
+ str1 = em.find(StrTestEntity.class, str1.getId());
+ coll1 = em.find(DoubleSetRefCollEntity.class, coll1.getId());
+
+ coll1.getCollection().remove(str1);
+ coll1.getCollection2().add(str1);
+
+ em.getTransaction().commit();
+
+ //
+
+ str1_id = str1.getId();
+ str2_id = str2.getId();
+
+ coll1_id = coll1.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2,
3).equals(getVersionsReader().getRevisions(DoubleSetRefCollEntity.class, coll1_id));
+
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str1_id));
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str2_id));
+ }
+
+ @Test
+ public void testHistoryOfColl1() {
+ StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
+ StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
+
+ DoubleSetRefCollEntity rev1 =
getVersionsReader().find(DoubleSetRefCollEntity.class, coll1_id, 1);
+ DoubleSetRefCollEntity rev2 =
getVersionsReader().find(DoubleSetRefCollEntity.class, coll1_id, 2);
+ DoubleSetRefCollEntity rev3 =
getVersionsReader().find(DoubleSetRefCollEntity.class, coll1_id, 3);
+
+ assert rev1.getCollection().equals(TestTools.makeSet(str1));
+ assert rev2.getCollection().equals(TestTools.makeSet(str1, str2));
+ assert rev3.getCollection().equals(TestTools.makeSet(str2));
+
+ assert rev1.getCollection2().equals(TestTools.makeSet(str2));
+ assert rev2.getCollection2().equals(TestTools.makeSet(str2));
+ assert rev3.getCollection2().equals(TestTools.makeSet(str1, str2));
+ }
+}
\ No newline at end of file
Property changes on:
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DoubleNotOwnedSet.java
___________________________________________________________________
Name: svn:mergeinfo
+
Show replies by date