Author: adamw
Date: 2008-09-24 08:06:48 -0400 (Wed, 24 Sep 2008)
New Revision: 168
Added:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java
trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/
trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMap.java
trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMapEntity.java
Removed:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
Log:
ENVERS-25: @MapKeyManyToMany support in ternary associations
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-09-24
11:17:25 UTC (rev 167)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-09-24
12:06:48 UTC (rev 168)
@@ -4,8 +4,8 @@
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
import org.jboss.envers.entities.mapper.relation.query.RelationQueryGenerator;
import org.jboss.envers.entities.mapper.relation.query.OneEntityQueryGenerator;
-import org.jboss.envers.entities.mapper.relation.query.TwoEntityQueryGenerator;
import org.jboss.envers.entities.mapper.relation.query.ThreeEntityQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.query.TwoEntityQueryGenerator;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import java.util.List;
@@ -42,10 +42,9 @@
} else if (idDatas.size() == 1) {
return new TwoEntityQueryGenerator(verEntCfg, versionsMiddleEntityName,
referencingIdData,
idDatas.get(0), componentDatas);
- } else if (idDatas.size() == 1) {
- // TODO: add componentDatas
+ } else if (idDatas.size() == 2) {
return new ThreeEntityQueryGenerator(verEntCfg, versionsMiddleEntityName,
referencingIdData,
- idDatas.get(0), idDatas.get(1));
+ idDatas.get(0), idDatas.get(1), componentDatas);
} else {
throw new IllegalStateException("Illegal number of related
entities.");
}
Deleted:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java 2008-09-24
11:17:25 UTC (rev 167)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java 2008-09-24
12:06:48 UTC (rev 168)
@@ -1,14 +0,0 @@
-package org.jboss.envers.entities.mapper.relation.query;
-
-import org.hibernate.Query;
-import org.jboss.envers.reader.VersionsReaderImplementor;
-
-/**
- * Implementations of this interface provide a method to generate queries on a
middle-table (a table used
- * for mapping relations). The query can select, apart from selecting the middle table,
select also other "related"
- * entities.
- * @author Adam Warski (adam at warski dot org)
- */
-public interface MiddleTableQueryGenerator {
- Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey, Number
revision);
-}
Added:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java
(rev 0)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2008-09-24
12:06:48 UTC (rev 168)
@@ -0,0 +1,51 @@
+package org.jboss.envers.entities.mapper.relation.query;
+
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
+import org.jboss.envers.entities.mapper.relation.MiddleIdData;
+import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class QueryGeneratorTools {
+ public static void addEntityAtRevision(QueryBuilder qb, Parameters rootParameters,
MiddleIdData idData,
+ String revisionPropertyPath, String
originalIdPropertyName,
+ String alias1, String alias2) {
+ // SELECT max(e.revision) FROM versionsReferencedEntity e2
+ QueryBuilder maxERevQb = qb.newSubQueryBuilder(idData.getVersionsEntityName(),
alias2);
+ maxERevQb.addProjection("max", revisionPropertyPath, false);
+ // WHERE
+ Parameters maxERevQbParameters = maxERevQb.getRootParameters();
+ // e2.revision <= :revision
+ maxERevQbParameters.addWhereWithNamedParam(revisionPropertyPath,
"<=", "revision");
+ // e2.id_ref_ed = e.id_ref_ed
+ idData.getOriginalMapper().addIdsEqualToQuery(maxERevQbParameters,
+ alias1 + "." + originalIdPropertyName, alias2 +"." +
originalIdPropertyName);
+
+ // e.revision = (SELECT max(...) ...)
+ rootParameters.addWhere("e." + revisionPropertyPath, false,
"=", maxERevQb);
+ }
+
+ public static void addAssociationAtRevision(QueryBuilder qb, Parameters
rootParameters,
+ MiddleIdData referencingIdData, String
versionsMiddleEntityName,
+ String eeOriginalIdPropertyPath, String
revisionPropertyPath,
+ String originalIdPropertyName,
MiddleComponentData... componentDatas) {
+ // SELECT max(ee2.revision) FROM middleEntity ee2
+ QueryBuilder maxEeRevQb = qb.newSubQueryBuilder(versionsMiddleEntityName,
"ee2");
+ maxEeRevQb.addProjection("max", revisionPropertyPath, false);
+ // WHERE
+ Parameters maxEeRevQbParameters = maxEeRevQb.getRootParameters();
+ // ee2.revision <= :revision
+ maxEeRevQbParameters.addWhereWithNamedParam(revisionPropertyPath,
"<=", "revision");
+ // ee2.originalId.* = ee.originalId.*
+ String ee2OriginalIdPropertyPath = "ee2." + originalIdPropertyName;
+ referencingIdData.getPrefixedMapper().addIdsEqualToQuery(maxEeRevQbParameters,
eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
+ for (MiddleComponentData componentData : componentDatas) {
+
componentData.getComponentMapper().addMiddleEqualToQuery(maxEeRevQbParameters,
eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
+ }
+
+ // ee.revision = (SELECT max(...) ...)
+ rootParameters.addWhere(revisionPropertyPath, "=", maxEeRevQb);
+ }
+}
Modified:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-09-24
11:17:25 UTC (rev 167)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-09-24
12:06:48 UTC (rev 168)
@@ -1,11 +1,19 @@
package org.jboss.envers.entities.mapper.relation.query;
-import org.hibernate.Query;
-import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.entities.mapper.id.QueryParameterData;
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
+import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.RevisionType;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
+import org.hibernate.Query;
+import java.util.Collections;
+
/**
+ * Selects data from a relation middle-table and a two related versions entity.
* @author Adam Warski (adam at warski dot org)
*/
public final class ThreeEntityQueryGenerator implements RelationQueryGenerator {
@@ -15,15 +23,88 @@
public ThreeEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg,
String versionsMiddleEntityName,
MiddleIdData referencingIdData,
- MiddleIdData referencedIdData1,
- MiddleIdData referencedIdData2) {
+ MiddleIdData referencedIdData,
+ MiddleIdData indexIdData,
+ MiddleComponentData... componentDatas) {
this.referencingIdData = referencingIdData;
- // TODO
- queryString = "";
+ /*
+ * The query that we need to create:
+ * SELECT new list(ee, e, f) FROM versionsReferencedEntity e,
versionsIndexEntity f, middleEntity ee
+ * WHERE
+ * (entities referenced by the middle table; id_ref_ed = id of the referenced
entity)
+ * ee.id_ref_ed = e.id_ref_ed AND
+ * (entities referenced by the middle table; id_ref_ind = id of the index
entity)
+ * ee.id_ref_ind = f.id_ref_ind AND
+ * (only entities referenced by the association; id_ref_ing = id of the
referencing entity)
+ * ee.id_ref_ing = :id_ref_ing AND
+ * (selecting e entities at revision :revision)
+ * e.revision = (SELECT max(e2.revision) FROM versionsReferencedEntity e2
+ * WHERE e2.revision <= :revision AND e2.id_ref_ed = e.id_ref_ed) AND
+ * (selecting f entities at revision :revision)
+ * f.revision = (SELECT max(f2.revision) FROM versionsIndexEntity f2
+ * WHERE f2.revision <= :revision AND f2.id_ref_ed = f.id_ref_ed) AND
+ * (the association at revision :revision)
+ * ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2
+ * WHERE ee2.revision <= :revision AND ee2.originalId.* =
ee.originalId.*) AND
+ * (only non-deleted entities and associations)
+ * ee.revision_type != DEL AND
+ * e.revision_type != DEL AND
+ * f.revision_type != DEL
+ */
+ String revisionPropertyPath = verEntCfg.getRevisionPropPath();
+ String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
+
+ String eeOriginalIdPropertyPath = "ee." + originalIdPropertyName;
+
+ // SELECT new list(ee) FROM middleEntity ee
+ QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee");
+ qb.addFrom(referencedIdData.getVersionsEntityName(), "e");
+ qb.addFrom(indexIdData.getVersionsEntityName(), "f");
+ qb.addProjection("new list", "ee, e, f", false, false);
+ // WHERE
+ Parameters rootParameters = qb.getRootParameters();
+ // ee.id_ref_ed = e.id_ref_ed
+ referencedIdData.getPrefixedMapper().addIdsEqualToQuery(rootParameters,
eeOriginalIdPropertyPath,
+ referencedIdData.getOriginalMapper(), "e." +
originalIdPropertyName);
+ // ee.id_ref_ind = f.id_ref_ind
+ indexIdData.getPrefixedMapper().addIdsEqualToQuery(rootParameters,
eeOriginalIdPropertyPath,
+ indexIdData.getOriginalMapper(), "f." +
originalIdPropertyName);
+ // ee.originalId.id_ref_ing = :id_ref_ing
+ referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters,
originalIdPropertyName, true);
+
+ // e.revision = (SELECT max(...) ...)
+ QueryGeneratorTools.addEntityAtRevision(qb, rootParameters, referencedIdData,
revisionPropertyPath,
+ originalIdPropertyName, "e", "e2");
+
+ // f.revision = (SELECT max(...) ...)
+ QueryGeneratorTools.addEntityAtRevision(qb, rootParameters, indexIdData,
revisionPropertyPath,
+ originalIdPropertyName, "f", "f2");
+
+ // ee.revision = (SELECT max(...) ...)
+ QueryGeneratorTools.addAssociationAtRevision(qb, rootParameters,
referencingIdData, versionsMiddleEntityName,
+ eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName,
componentDatas);
+
+ // ee.revision_type != DEL
+ rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(),
"!=", "delrevisiontype");
+ // e.revision_type != DEL
+ rootParameters.addWhereWithNamedParam("e." +
verEntCfg.getRevisionTypePropName(), false, "!=", "delrevisiontype");
+ // f.revision_type != DEL
+ rootParameters.addWhereWithNamedParam("f." +
verEntCfg.getRevisionTypePropName(), false, "!=", "delrevisiontype");
+
+ StringBuilder sb = new StringBuilder();
+ qb.build(sb, Collections.<String, Object>emptyMap());
+ queryString = sb.toString();
}
public Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey,
Number revision) {
- throw new RuntimeException();
+ Query query = versionsReader.getSession().createQuery(queryString);
+ query.setParameter("revision", revision);
+ query.setParameter("delrevisiontype", RevisionType.DEL);
+ for (QueryParameterData paramData:
referencingIdData.getPrefixedMapper().mapToQueryParametersFromId(primaryKey)) {
+ paramData.setParameterValue(query);
+ }
+
+ return query;
}
}
Modified:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-09-24
11:17:25 UTC (rev 167)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-09-24
12:06:48 UTC (rev 168)
@@ -62,35 +62,13 @@
// ee.originalId.id_ref_ing = :id_ref_ing
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters,
originalIdPropertyName, true);
- // SELECT max(e.revision) FROM versionsReferencedEntity e2
- QueryBuilder maxERevQb =
qb.newSubQueryBuilder(referencedIdData.getVersionsEntityName(), "e2");
- maxERevQb.addProjection("max", revisionPropertyPath, false);
- // WHERE
- Parameters maxERevQbParameters = maxERevQb.getRootParameters();
- // e2.revision <= :revision
- maxERevQbParameters.addWhereWithNamedParam(revisionPropertyPath,
"<=", "revision");
- // e2.id_ref_ed = e.id_ref_ed
- referencedIdData.getOriginalMapper().addIdsEqualToQuery(maxERevQbParameters,
"e." + originalIdPropertyName, "e2." + originalIdPropertyName);
-
// e.revision = (SELECT max(...) ...)
- rootParameters.addWhere("e." + revisionPropertyPath, false,
"=", maxERevQb);
+ QueryGeneratorTools.addEntityAtRevision(qb, rootParameters, referencedIdData,
revisionPropertyPath,
+ originalIdPropertyName, "e", "e2");
- // SELECT max(ee2.revision) FROM middleEntity ee2
- QueryBuilder maxEeRevQb = qb.newSubQueryBuilder(versionsMiddleEntityName,
"ee2");
- maxEeRevQb.addProjection("max", revisionPropertyPath, false);
- // WHERE
- Parameters maxEeRevQbParameters = maxEeRevQb.getRootParameters();
- // ee2.revision <= :revision
- maxEeRevQbParameters.addWhereWithNamedParam(revisionPropertyPath,
"<=", "revision");
- // ee2.originalId.* = ee.originalId.*
- String ee2OriginalIdPropertyPath = "ee2." + originalIdPropertyName;
- referencingIdData.getPrefixedMapper().addIdsEqualToQuery(maxEeRevQbParameters,
eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
- for (MiddleComponentData componentData : componentDatas) {
-
componentData.getComponentMapper().addMiddleEqualToQuery(maxEeRevQbParameters,
eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
- }
-
// ee.revision = (SELECT max(...) ...)
- rootParameters.addWhere(revisionPropertyPath, "=", maxEeRevQb);
+ QueryGeneratorTools.addAssociationAtRevision(qb, rootParameters,
referencingIdData, versionsMiddleEntityName,
+ eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName,
componentDatas);
// ee.revision_type != DEL
rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(),
"!=", "delrevisiontype");
Copied:
trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMap.java (from
rev 156, trunk/src/test/org/jboss/envers/test/integration/manytomany/BasicMap.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMap.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMap.java 2008-09-24
12:06:48 UTC (rev 168)
@@ -0,0 +1,176 @@
+package org.jboss.envers.test.integration.manytomany.ternary;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.StrTestEntity;
+import org.jboss.envers.test.entities.IntTestEntity;
+import org.jboss.envers.test.tools.TestTools;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.hibernate.ejb.Ejb3Configuration;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class TernaryMap extends AbstractEntityTest {
+ private Integer str1_id;
+ private Integer str2_id;
+
+ private Integer int1_id;
+ private Integer int2_id;
+
+ private Integer map1_id;
+ private Integer map2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(TernaryMapEntity.class);
+ cfg.addAnnotatedClass(StrTestEntity.class);
+ cfg.addAnnotatedClass(IntTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ StrTestEntity str1 = new StrTestEntity("a");
+ StrTestEntity str2 = new StrTestEntity("b");
+
+ IntTestEntity int1 = new IntTestEntity(1);
+ IntTestEntity int2 = new IntTestEntity(2);
+
+ TernaryMapEntity map1 = new TernaryMapEntity();
+ TernaryMapEntity map2 = new TernaryMapEntity();
+
+ // Revision 1 (map1: initialy one mapping int1 -> str1, map2: empty)
+ em.getTransaction().begin();
+
+ em.persist(str1);
+ em.persist(str2);
+ em.persist(int1);
+ em.persist(int2);
+
+ map1.getMap().put(int1, str1);
+
+ em.persist(map1);
+ em.persist(map2);
+
+ em.getTransaction().commit();
+
+ // Revision 2 (map1: replacing the mapping, map2: adding two mappings)
+
+ em.getTransaction().begin();
+
+ map1 = em.find(TernaryMapEntity.class, map1.getId());
+ map2 = em.find(TernaryMapEntity.class, map2.getId());
+
+ str1 = em.find(StrTestEntity.class, str1.getId());
+ str2 = em.find(StrTestEntity.class, str2.getId());
+
+ int1 = em.find(IntTestEntity.class, int1.getId());
+ int2 = em.find(IntTestEntity.class, int2.getId());
+
+ map1.getMap().put(int1, str2);
+
+ map2.getMap().put(int1, str1);
+ map2.getMap().put(int2, str1);
+
+ em.getTransaction().commit();
+
+ // Revision 3 (map1: removing a non-existing mapping, adding an existing mapping
- no changes, map2: removing a mapping)
+ em.getTransaction().begin();
+
+ map1 = em.find(TernaryMapEntity.class, map1.getId());
+ map2 = em.find(TernaryMapEntity.class, map2.getId());
+
+ str2 = em.find(StrTestEntity.class, str2.getId());
+
+ int1 = em.find(IntTestEntity.class, int1.getId());
+ int2 = em.find(IntTestEntity.class, int2.getId());
+
+ map1.getMap().remove(int2);
+ map1.getMap().put(int1, str2);
+
+ map2.getMap().remove(int1);
+
+ em.getTransaction().commit();
+
+ // Revision 4 (map1: adding a mapping, map2: adding a mapping)
+ em.getTransaction().begin();
+
+ map1 = em.find(TernaryMapEntity.class, map1.getId());
+ map2 = em.find(TernaryMapEntity.class, map2.getId());
+
+ str2 = em.find(StrTestEntity.class, str2.getId());
+
+ int1 = em.find(IntTestEntity.class, int1.getId());
+ int2 = em.find(IntTestEntity.class, int2.getId());
+
+ map1.getMap().put(int2, str2);
+
+ map2.getMap().put(int1, str2);
+
+ em.getTransaction().commit();
+ //
+
+ map1_id = map1.getId();
+ map2_id = map2.getId();
+
+ str1_id = str1.getId();
+ str2_id = str2.getId();
+
+ int1_id = int1.getId();
+ int2_id = int2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2,
4).equals(getVersionsReader().getRevisions(TernaryMapEntity.class, map1_id));
+ assert Arrays.asList(1, 2, 3,
4).equals(getVersionsReader().getRevisions(TernaryMapEntity.class, map2_id));
+
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str1_id));
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str2_id));
+
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(IntTestEntity.class, int1_id));
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(IntTestEntity.class, int2_id));
+ }
+
+ @Test
+ public void testHistoryOfMap1() {
+ StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
+ StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
+
+ IntTestEntity int1 = getEntityManager().find(IntTestEntity.class, int1_id);
+ IntTestEntity int2 = getEntityManager().find(IntTestEntity.class, int2_id);
+
+ TernaryMapEntity rev1 = getVersionsReader().find(TernaryMapEntity.class, map1_id,
1);
+ TernaryMapEntity rev2 = getVersionsReader().find(TernaryMapEntity.class, map1_id,
2);
+ TernaryMapEntity rev3 = getVersionsReader().find(TernaryMapEntity.class, map1_id,
3);
+ TernaryMapEntity rev4 = getVersionsReader().find(TernaryMapEntity.class, map1_id,
4);
+
+ assert rev1.getMap().equals(TestTools.makeMap(int1, str1));
+ assert rev2.getMap().equals(TestTools.makeMap(int1, str2));
+ assert rev3.getMap().equals(TestTools.makeMap(int1, str2));
+ assert rev4.getMap().equals(TestTools.makeMap(int1, str2, int2, str2));
+ }
+
+ @Test
+ public void testHistoryOfMap2() {
+ StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
+ StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
+
+ IntTestEntity int1 = getEntityManager().find(IntTestEntity.class, int1_id);
+ IntTestEntity int2 = getEntityManager().find(IntTestEntity.class, int2_id);
+
+ TernaryMapEntity rev1 = getVersionsReader().find(TernaryMapEntity.class, map2_id,
1);
+ TernaryMapEntity rev2 = getVersionsReader().find(TernaryMapEntity.class, map2_id,
2);
+ TernaryMapEntity rev3 = getVersionsReader().find(TernaryMapEntity.class, map2_id,
3);
+ TernaryMapEntity rev4 = getVersionsReader().find(TernaryMapEntity.class, map2_id,
4);
+
+ assert rev1.getMap().equals(TestTools.makeMap());
+ assert rev2.getMap().equals(TestTools.makeMap(int1, str1, int2, str1));
+ assert rev3.getMap().equals(TestTools.makeMap(int2, str1));
+ assert rev4.getMap().equals(TestTools.makeMap(int1, str2, int2, str1));
+ }
+}
\ No newline at end of file
Copied:
trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMapEntity.java
(from rev 148, trunk/src/test/org/jboss/envers/test/entities/StrIntTestEntity.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMapEntity.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMapEntity.java 2008-09-24
12:06:48 UTC (rev 168)
@@ -0,0 +1,67 @@
+package org.jboss.envers.test.integration.manytomany.ternary;
+
+import org.jboss.envers.Versioned;
+import org.jboss.envers.test.entities.IntTestEntity;
+import org.jboss.envers.test.entities.StrTestEntity;
+import org.hibernate.annotations.MapKeyManyToMany;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.ManyToMany;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class TernaryMapEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Versioned
+ @ManyToMany
+ @MapKeyManyToMany
+ private Map<IntTestEntity, StrTestEntity> map;
+
+ public TernaryMapEntity() {
+ map = new HashMap<IntTestEntity, StrTestEntity>();
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Map<IntTestEntity, StrTestEntity> getMap() {
+ return map;
+ }
+
+ public void setMap(Map<IntTestEntity, StrTestEntity> map) {
+ this.map = map;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof TernaryMapEntity)) return false;
+
+ TernaryMapEntity that = (TernaryMapEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return (id != null ? id.hashCode() : 0);
+ }
+
+ public String toString() {
+ return "TME(id = " + id + ", map = " + map + ")";
+ }
+}
\ No newline at end of file
Property changes on:
trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMapEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+