Author: adamw
Date: 2008-07-28 11:19:50 -0400 (Mon, 28 Jul 2008)
New Revision: 96
Added:
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ChildIngEntity.java
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ParentNotIngEntity.java
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ReferencedEntity.java
Modified:
trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java
Log:
ENVERS-29: bug fix with test
Modified: trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java 2008-07-16
09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java 2008-07-28
15:19:50 UTC (rev 96)
@@ -609,7 +609,12 @@
CompositeMapperBuilder propertyMapper =
entitiesConfigurations.get(entityName).getPropertyMapper();
// Mapping unjoined properties
- addProperties(document.getRootElement().element("class"),
(Iterator<Property>) pc.getUnjoinedPropertyIterator(),
+ Element parent = document.getRootElement().element("class");
+ if (parent == null) {
+ parent = document.getRootElement().element("subclass");
+ }
+
+ addProperties(parent, (Iterator<Property>)
pc.getUnjoinedPropertyIterator(),
propertyMapper, versioningData.propertyStoreInfo, entityName, false);
// Mapping joins (second pass)
Copied:
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ChildIngEntity.java
(from rev 95,
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/relation/ChildIngEntity.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ChildIngEntity.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ChildIngEntity.java 2008-07-28
15:19:50 UTC (rev 96)
@@ -0,0 +1,70 @@
+package org.jboss.envers.test.integration.inheritance.single.childrelation;
+
+import org.jboss.envers.Versioned;
+
+import javax.persistence.*;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@DiscriminatorValue("2")
+@Versioned
+public class ChildIngEntity extends ParentNotIngEntity {
+ @Basic
+ private Long number;
+
+ @ManyToOne
+ private ReferencedEntity referenced;
+
+ public ChildIngEntity() {
+ }
+
+ public ChildIngEntity(String data, Long number) {
+ super(data);
+ this.number = number;
+ }
+
+ public ChildIngEntity(Integer id, String data, Long number) {
+ super(id, data);
+ this.number = number;
+ }
+
+ public Long getNumber() {
+ return number;
+ }
+
+ public void setNumber(Long number) {
+ this.number = number;
+ }
+
+ public ReferencedEntity getReferenced() {
+ return referenced;
+ }
+
+ public void setReferenced(ReferencedEntity referenced) {
+ this.referenced = referenced;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ChildIngEntity)) return false;
+ if (!super.equals(o)) return false;
+
+ ChildIngEntity childEntity = (ChildIngEntity) o;
+
+ if (number != null ? !number.equals(childEntity.number) : childEntity.number !=
null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = super.hashCode();
+ result = 31 * result + (number != null ? number.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "ChildIngEntity(id = " + getId() + ", data = " +
getData() + ", number = " + number + ")";
+ }
+}
\ No newline at end of file
Copied:
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java
(from rev 95,
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/relation/PolymorphicCollection.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java 2008-07-28
15:19:50 UTC (rev 96)
@@ -0,0 +1,98 @@
+package org.jboss.envers.test.integration.inheritance.single.childrelation;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.tools.TestTools;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ChildReferencing extends AbstractEntityTest {
+ private Integer re_id1;
+ private Integer re_id2;
+ private Integer c_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ChildIngEntity.class);
+ cfg.addAnnotatedClass(ParentNotIngEntity.class);
+ cfg.addAnnotatedClass(ReferencedEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ // Rev 1
+ em.getTransaction().begin();
+
+ ReferencedEntity re1 = new ReferencedEntity();
+ em.persist(re1);
+ re_id1 = re1.getId();
+
+ ReferencedEntity re2 = new ReferencedEntity();
+ em.persist(re2);
+ re_id2 = re2.getId();
+
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+
+ re1 = em.find(ReferencedEntity.class, re_id1);
+
+ ChildIngEntity cie = new ChildIngEntity("y", 1l);
+ cie.setReferenced(re1);
+ em.persist(cie);
+ c_id = cie.getId();
+
+ em.getTransaction().commit();
+
+ // Rev 3
+ em.getTransaction().begin();
+
+ re2 = em.find(ReferencedEntity.class, re_id2);
+ cie = em.find(ChildIngEntity.class, c_id);
+
+ System.out.println(re2.getId());
+ cie.setReferenced(re2);
+
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2,
3).equals(getVersionsReader().getRevisions(ReferencedEntity.class, re_id1));
+ assert Arrays.asList(1,
3).equals(getVersionsReader().getRevisions(ReferencedEntity.class, re_id2));
+ assert Arrays.asList(2,
3).equals(getVersionsReader().getRevisions(ChildIngEntity.class, c_id));
+ }
+
+ @Test
+ public void testHistoryOfReferencedCollection1() {
+ assert getVersionsReader().find(ReferencedEntity.class, re_id1,
1).getReferencing().size() == 0;
+ assert getVersionsReader().find(ReferencedEntity.class, re_id1,
2).getReferencing().equals(
+ TestTools.makeSet(new ChildIngEntity(c_id, "y", 1l)));
+ assert getVersionsReader().find(ReferencedEntity.class, re_id1,
3).getReferencing().size() == 0;
+ }
+
+ @Test
+ public void testHistoryOfReferencedCollection2() {
+ assert getVersionsReader().find(ReferencedEntity.class, re_id2,
1).getReferencing().size() == 0;
+ assert getVersionsReader().find(ReferencedEntity.class, re_id2,
2).getReferencing().size() == 0;
+ assert getVersionsReader().find(ReferencedEntity.class, re_id2,
3).getReferencing().equals(
+ TestTools.makeSet(new ChildIngEntity(c_id, "y", 1l)));
+ }
+
+ @Test
+ public void testChildHistory() {
+ assert getVersionsReader().find(ChildIngEntity.class, c_id, 1) == null;
+ assert getVersionsReader().find(ChildIngEntity.class, c_id,
2).getReferenced().equals(
+ new ReferencedEntity(re_id1));
+ assert getVersionsReader().find(ChildIngEntity.class, c_id,
3).getReferenced().equals(
+ new ReferencedEntity(re_id2));
+ }
+}
\ No newline at end of file
Copied:
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ParentNotIngEntity.java
(from rev 95,
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/relation/ParentIngEntity.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ParentNotIngEntity.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ParentNotIngEntity.java 2008-07-28
15:19:50 UTC (rev 96)
@@ -0,0 +1,73 @@
+package org.jboss.envers.test.integration.inheritance.single.childrelation;
+
+import org.jboss.envers.Versioned;
+
+import javax.persistence.*;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+@DiscriminatorColumn(name = "discriminator", discriminatorType =
DiscriminatorType.INTEGER)
+@DiscriminatorValue("1")
+@Versioned
+public class ParentNotIngEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Basic
+ private String data;
+
+ public ParentNotIngEntity() {
+ }
+
+ public ParentNotIngEntity(String data) {
+ this.data = data;
+ }
+
+ public ParentNotIngEntity(Integer id, String data) {
+ this.id = id;
+ 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 boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ParentNotIngEntity)) return false;
+
+ ParentNotIngEntity that = (ParentNotIngEntity) 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 "ParentNotIngEntity(id = " + getId() + ", data = " +
getData() + ")";
+ }
+}
\ No newline at end of file
Copied:
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ReferencedEntity.java
(from rev 95,
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/relation/ReferencedEntity.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ReferencedEntity.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ReferencedEntity.java 2008-07-28
15:19:50 UTC (rev 96)
@@ -0,0 +1,61 @@
+package org.jboss.envers.test.integration.inheritance.single.childrelation;
+
+import org.jboss.envers.Versioned;
+
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import java.util.Set;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Versioned
+public class ReferencedEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @OneToMany(mappedBy = "referenced")
+ private Set<ChildIngEntity> referencing;
+
+ public ReferencedEntity(Integer id) {
+ this.id = id;
+ }
+
+ public ReferencedEntity() {
+ }
+
+ public Set<ChildIngEntity> getReferencing() {
+ return referencing;
+ }
+
+ public void setReferencing(Set<ChildIngEntity> referencing) {
+ this.referencing = referencing;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ReferencedEntity)) return false;
+
+ ReferencedEntity that = (ReferencedEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return id;
+ }
+}
\ No newline at end of file