HHH-6349 - Test cleanup

This commit is contained in:
Lukasz Antoniak 2012-10-30 17:30:34 +01:00
parent 9d84c8dea8
commit 55e8efc8f0
4 changed files with 298 additions and 355 deletions

View File

@ -3,7 +3,6 @@ package org.hibernate.envers.test.entities.collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -15,10 +14,12 @@ import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Version;
@Entity
@org.hibernate.envers.Audited
public class MultipleCollectionEntity {
import org.hibernate.envers.AuditJoinTable;
import org.hibernate.envers.Audited;
@Entity
@Audited
public class MultipleCollectionEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID", length = 10)
@ -33,12 +34,12 @@ public class MultipleCollectionEntity {
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "MCE_ID", nullable = false)
@org.hibernate.envers.AuditJoinTable(name = "MCE_RE1_AUD", inverseJoinColumns = @JoinColumn(name = "RE1_ID"))
@AuditJoinTable(name = "MCE_RE1_AUD", inverseJoinColumns = @JoinColumn(name = "RE1_ID"))
private List<MultipleCollectionRefEntity1> refEntities1 = new ArrayList<MultipleCollectionRefEntity1>();
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "MCE_ID", nullable = false)
@org.hibernate.envers.AuditJoinTable(name = "MCE_RE2_AUD", inverseJoinColumns = @JoinColumn(name = "RE2_ID"))
@AuditJoinTable(name = "MCE_RE2_AUD", inverseJoinColumns = @JoinColumn(name = "RE2_ID"))
private List<MultipleCollectionRefEntity2> refEntities2 = new ArrayList<MultipleCollectionRefEntity2>();
public Long getId() {
@ -89,42 +90,34 @@ public class MultipleCollectionEntity {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((text == null) ? 0 : text.hashCode());
result = prime * result
+ ((refEntities1 == null) ? 0 : refEntities1.hashCode());
result = prime * result
+ ((refEntities2 == null) ? 0 : refEntities2.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
public boolean equals(Object o) {
if ( this == o ) {
return true;
if (obj == null)
}
if ( ! ( o instanceof MultipleCollectionEntity ) ) {
return false;
if (getClass() != obj.getClass())
}
MultipleCollectionEntity that = (MultipleCollectionEntity) o;
if ( refEntities1 != null ? !refEntities1.equals( that.refEntities1 ) : that.refEntities1 != null ) {
return false;
MultipleCollectionEntity other = (MultipleCollectionEntity) obj;
if (text == null) {
if (other.text != null)
return false;
} else if (!text.equals(other.text))
}
if ( refEntities2 != null ? !refEntities2.equals( that.refEntities2 ) : that.refEntities2 != null ) {
return false;
if (refEntities1 == null) {
if (other.refEntities1 != null)
return false;
} else if (!refEntities1.equals(other.refEntities1))
return false;
if (refEntities2 == null) {
if (other.refEntities2 != null)
return false;
} else if (!refEntities2.equals(other.refEntities2))
}
if ( text != null ? !text.equals( that.text ) : that.text != null ) {
return false;
}
return true;
}
}
@Override
public int hashCode() {
int result = text != null ? text.hashCode() : 0;
result = 31 * result + ( refEntities1 != null ? refEntities1.hashCode() : 0 );
result = 31 * result + ( refEntities2 != null ? refEntities2.hashCode() : 0 );
return result;
}
}

View File

@ -9,12 +9,13 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Version;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.envers.Audited;
import org.hibernate.envers.NotAudited;
@Entity
@org.hibernate.envers.Audited
@Audited
public class MultipleCollectionRefEntity1 {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID", length = 10)
@ -29,7 +30,7 @@ public class MultipleCollectionRefEntity1 {
@ManyToOne
@JoinColumn(name = "MCE_ID", nullable = false, insertable = false, updatable = false)
@org.hibernate.annotations.ForeignKey(name = "FK_RE1_MCE")
@ForeignKey(name = "FK_RE1_MCE")
@NotAudited
private MultipleCollectionEntity multipleCollectionEntity;
@ -57,8 +58,7 @@ public class MultipleCollectionRefEntity1 {
return multipleCollectionEntity;
}
public void setMultipleCollectionEntity(
MultipleCollectionEntity multipleCollectionEntity) {
public void setMultipleCollectionEntity(MultipleCollectionEntity multipleCollectionEntity) {
this.multipleCollectionEntity = multipleCollectionEntity;
}
@ -78,28 +78,25 @@ public class MultipleCollectionRefEntity1 {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((text == null) ? 0 : text.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
public boolean equals(Object o) {
if ( this == o ) {
return true;
if (obj == null)
}
if ( ! ( o instanceof MultipleCollectionRefEntity1 ) ) {
return false;
if (getClass() != obj.getClass())
return false;
MultipleCollectionRefEntity1 other = (MultipleCollectionRefEntity1) obj;
if (text == null) {
if (other.text != null)
return false;
} else if (!text.equals(other.text))
}
MultipleCollectionRefEntity1 that = (MultipleCollectionRefEntity1) o;
if ( text != null ? !text.equals( that.text ) : that.text != null ) {
return false;
}
return true;
}
}
@Override
public int hashCode() {
return text != null ? text.hashCode() : 0;
}
}

View File

@ -9,12 +9,13 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Version;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.envers.Audited;
import org.hibernate.envers.NotAudited;
@Entity
@org.hibernate.envers.Audited
@Audited
public class MultipleCollectionRefEntity2 {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID", length = 10)
@ -29,7 +30,7 @@ public class MultipleCollectionRefEntity2 {
@ManyToOne
@JoinColumn(name = "MCE_ID", nullable = false, insertable = false, updatable = false)
@org.hibernate.annotations.ForeignKey(name = "FK_RE2_MCE")
@ForeignKey(name = "FK_RE2_MCE")
@NotAudited
private MultipleCollectionEntity multipleCollectionEntity;
@ -57,8 +58,7 @@ public class MultipleCollectionRefEntity2 {
return multipleCollectionEntity;
}
public void setMultipleCollectionEntity(
MultipleCollectionEntity multipleCollectionEntity) {
public void setMultipleCollectionEntity(MultipleCollectionEntity multipleCollectionEntity) {
this.multipleCollectionEntity = multipleCollectionEntity;
}
@ -78,28 +78,25 @@ public class MultipleCollectionRefEntity2 {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((text == null) ? 0 : text.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
public boolean equals(Object o) {
if ( this == o ) {
return true;
if (obj == null)
}
if ( ! ( o instanceof MultipleCollectionRefEntity2 ) ) {
return false;
if (getClass() != obj.getClass())
return false;
MultipleCollectionRefEntity2 other = (MultipleCollectionRefEntity2) obj;
if (text == null) {
if (other.text != null)
return false;
} else if (!text.equals(other.text))
}
MultipleCollectionRefEntity2 that = (MultipleCollectionRefEntity2) o;
if ( text != null ? !text.equals( that.text ) : that.text != null ) {
return false;
}
return true;
}
}
@Override
public int hashCode() {
return text != null ? text.hashCode() : 0;
}
}

View File

@ -1,63 +1,62 @@
package org.hibernate.envers.test.integration.collection;
import static org.hibernate.envers.test.EnversTestingJtaBootstrap.tryCommit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.transaction.Status;
import javax.transaction.TransactionManager;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.DefaultRevisionEntity;
import org.junit.Test;
import org.hibernate.envers.RevisionType;
import org.hibernate.envers.internal.EnversMessageLogger;
import org.hibernate.envers.test.AbstractEntityTest;
import org.hibernate.envers.test.EnversTestingJtaBootstrap;
import org.hibernate.envers.enhanced.SequenceIdRevisionEntity;
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
import org.hibernate.envers.test.Priority;
import org.hibernate.envers.test.entities.collection.MultipleCollectionEntity;
import org.hibernate.envers.test.entities.collection.MultipleCollectionRefEntity1;
import org.hibernate.envers.test.entities.collection.MultipleCollectionRefEntity2;
import org.jboss.logging.Logger;
import org.junit.Test;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.jta.TestingJtaBootstrap;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* Test the audit history of a detached entity with multiple collections that is
* merged back into the persistence context.
*
*
* @author Erik-Berndt Scheper
*/
public class DetachedMultipleCollectionChangeTest extends AbstractEntityTest {
@TestForIssue(jiraKey = "HHH-6349")
public class DetachedMultipleCollectionChangeTest extends BaseEnversJPAFunctionalTestCase {
private TransactionManager tm = null;
public static final EnversMessageLogger LOG = Logger.getMessageLogger(
EnversMessageLogger.class,
DetachedMultipleCollectionChangeTest.class.getName());
private Long mceId1 = null;
private Long re1Id1 = null;
private Long re1Id2 = null;
private Long re1Id3 = null;
private Long re2Id1 = null;
private Long re2Id2 = null;
private Long re2Id3 = null;
private TransactionManager tm;
private Long mceId1;
private Long re1Id1;
private Long re1Id2;
private Long re1Id3;
private Long re2Id1;
private Long re2Id2;
private Long re2Id3;
public void configure(Ejb3Configuration cfg) {
cfg.addAnnotatedClass(MultipleCollectionEntity.class);
cfg.addAnnotatedClass(MultipleCollectionRefEntity1.class);
cfg.addAnnotatedClass(MultipleCollectionRefEntity2.class);
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
MultipleCollectionEntity.class,
MultipleCollectionRefEntity1.class,
MultipleCollectionRefEntity2.class
};
}
@Override
public void addConfigurationProperties(Properties configuration) {
super.addConfigurationProperties(configuration);
tm = EnversTestingJtaBootstrap.updateConfigAndCreateTM(configuration);
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
TestingJtaBootstrap.prepare( options );
tm = TestingJtaPlatformImpl.INSTANCE.getTransactionManager();
}
@Test
@ -69,187 +68,150 @@ public class DetachedMultipleCollectionChangeTest extends AbstractEntityTest {
MultipleCollectionRefEntity2 re2_1, updatedRe2_1, re2_2, re2_3;
tm.begin();
try {
newEntityManager();
em = getEntityManager();
em = createIsolatedEntityManager();
em.joinTransaction();
mce = new MultipleCollectionEntity();
mce.setText("MultipleCollectionEntity-1");
em.persist(mce);
mce.setText( "MultipleCollectionEntity-1" );
em.persist( mce );
mceId1 = mce.getId();
} finally {
tryCommit(tm);
}
assertNotNull(mceId1);
//
finally {
tryCommit( tm );
}
assertNotNull( mceId1 );
tm.begin();
try {
newEntityManager();
em = getEntityManager();
em = createIsolatedEntityManager();
em.joinTransaction();
// mce = em.find(MultipleCollectionEntity.class, mceId1);
// mce = em.merge(mce);
re1_1 = new MultipleCollectionRefEntity1();
re1_1.setText("MultipleCollectionRefEntity1-1");
re1_1.setMultipleCollectionEntity(mce);
re1_1.setText( "MultipleCollectionRefEntity1-1" );
re1_1.setMultipleCollectionEntity( mce );
re1_2 = new MultipleCollectionRefEntity1();
re1_2.setText("MultipleCollectionRefEntity1-2");
re1_2.setMultipleCollectionEntity(mce);
re1_2.setText( "MultipleCollectionRefEntity1-2" );
re1_2.setMultipleCollectionEntity( mce );
mce.addRefEntity1(re1_1);
mce.addRefEntity1(re1_2);
mce.addRefEntity1( re1_1 );
mce.addRefEntity1( re1_2 );
re2_1 = new MultipleCollectionRefEntity2();
re2_1.setText("MultipleCollectionRefEntity2-1");
re2_1.setMultipleCollectionEntity(mce);
re2_1.setText( "MultipleCollectionRefEntity2-1" );
re2_1.setMultipleCollectionEntity( mce );
re2_2 = new MultipleCollectionRefEntity2();
re2_2.setText("MultipleCollectionRefEntity2-2");
re2_2.setMultipleCollectionEntity(mce);
re2_2.setText( "MultipleCollectionRefEntity2-2" );
re2_2.setMultipleCollectionEntity( mce );
mce.addRefEntity2(re2_1);
mce.addRefEntity2(re2_2);
mce.addRefEntity2( re2_1 );
mce.addRefEntity2( re2_2 );
mce = em.merge(mce);
} finally {
tryCommit(tm);
mce = em.merge( mce );
}
// re1Id1 = re1_1.getId();
// re1Id2 = re1_2.getId();
// re2Id1 = re2_1.getId();
// re2Id2 = re2_2.getId();
for (MultipleCollectionRefEntity1 refEnt1 : mce.getRefEntities1()) {
if (refEnt1.equals(re1_1)) {
finally {
tryCommit( tm );
}
for ( MultipleCollectionRefEntity1 refEnt1 : mce.getRefEntities1() ) {
if ( refEnt1.equals( re1_1 ) ) {
re1Id1 = refEnt1.getId();
} else if (refEnt1.equals(re1_2)) {
}
else if ( refEnt1.equals( re1_2 ) ) {
re1Id2 = refEnt1.getId();
} else {
throw new IllegalStateException("unexpected instance");
}
else {
throw new IllegalStateException( "unexpected instance" );
}
}
for (MultipleCollectionRefEntity2 refEnt2 : mce.getRefEntities2()) {
if (refEnt2.equals(re2_1)) {
for ( MultipleCollectionRefEntity2 refEnt2 : mce.getRefEntities2() ) {
if ( refEnt2.equals( re2_1 ) ) {
re2Id1 = refEnt2.getId();
} else if (refEnt2.equals(re2_2)) {
}
else if ( refEnt2.equals( re2_2 ) ) {
re2Id2 = refEnt2.getId();
} else {
throw new IllegalStateException("unexpected instance");
}
else {
throw new IllegalStateException( "unexpected instance" );
}
}
assertNotNull(re1Id1);
assertNotNull(re1Id2);
assertNotNull(re2Id1);
assertNotNull(re2Id2);
//
assertNotNull( re1Id1 );
assertNotNull( re1Id2 );
assertNotNull( re2Id1 );
assertNotNull( re2Id2 );
tm.begin();
try {
newEntityManager();
em = getEntityManager();
em = createIsolatedEntityManager();
em.joinTransaction();
// mce = em.find(MultipleCollectionEntity.class, mceId1);
// mce = em.merge(mce);
assertEquals( 2, mce.getRefEntities1().size() );
assertEquals(2, mce.getRefEntities1().size());
mce.removeRefEntity1( re1_2 );
assertEquals( 1, mce.getRefEntities1().size() );
mce.removeRefEntity1(re1_2);
assertEquals(1, mce.getRefEntities1().size());
updatedRe1_1 = mce.getRefEntities1().get(0);
assertEquals(re1_1, updatedRe1_1);
updatedRe1_1.setText("MultipleCollectionRefEntity1-1-updated");
updatedRe1_1 = mce.getRefEntities1().get( 0 );
assertEquals( re1_1, updatedRe1_1 );
updatedRe1_1.setText( "MultipleCollectionRefEntity1-1-updated" );
re1_3 = new MultipleCollectionRefEntity1();
re1_3.setText("MultipleCollectionRefEntity1-3");
re1_3.setMultipleCollectionEntity(mce);
mce.addRefEntity1(re1_3);
assertEquals(2, mce.getRefEntities1().size());
re1_3.setText( "MultipleCollectionRefEntity1-3" );
re1_3.setMultipleCollectionEntity( mce );
mce.addRefEntity1( re1_3 );
assertEquals( 2, mce.getRefEntities1().size() );
// -------------
assertEquals( 2, mce.getRefEntities2().size() );
assertEquals(2, mce.getRefEntities2().size());
mce.removeRefEntity2( re2_2 );
assertEquals( 1, mce.getRefEntities2().size() );
mce.removeRefEntity2(re2_2);
assertEquals(1, mce.getRefEntities2().size());
updatedRe2_1 = mce.getRefEntities2().get(0);
assertEquals(re2_1, updatedRe2_1);
updatedRe2_1.setText("MultipleCollectionRefEntity2-1-updated");
updatedRe2_1 = mce.getRefEntities2().get( 0 );
assertEquals( re2_1, updatedRe2_1 );
updatedRe2_1.setText( "MultipleCollectionRefEntity2-1-updated" );
re2_3 = new MultipleCollectionRefEntity2();
re2_3.setText("MultipleCollectionRefEntity2-3");
re2_3.setMultipleCollectionEntity(mce);
mce.addRefEntity2(re2_3);
assertEquals(2, mce.getRefEntities2().size());
re2_3.setText( "MultipleCollectionRefEntity2-3" );
re2_3.setMultipleCollectionEntity( mce );
mce.addRefEntity2( re2_3 );
assertEquals( 2, mce.getRefEntities2().size() );
mce = em.merge(mce);
mce = em.merge( mce );
} finally {
tryCommit(tm);
}
// re1Id3 = re1_3.getId();
// re2Id3 = re2_3.getId();
for (MultipleCollectionRefEntity1 adres : mce.getRefEntities1()) {
if (adres.equals(re1_3)) {
finally {
tryCommit( tm );
}
for ( MultipleCollectionRefEntity1 adres : mce.getRefEntities1() ) {
if ( adres.equals( re1_3 ) ) {
re1Id3 = adres.getId();
}
}
for (MultipleCollectionRefEntity2 partner : mce.getRefEntities2()) {
if (partner.equals(re2_3)) {
for ( MultipleCollectionRefEntity2 partner : mce.getRefEntities2() ) {
if ( partner.equals( re2_3 ) ) {
re2Id3 = partner.getId();
}
}
assertNotNull(re1Id3);
assertNotNull(re2Id3);
assertNotNull( re1Id3 );
assertNotNull( re2Id3 );
}
@Test
public void testRevisionsCounts() throws Exception {
List<Number> mceId1Revs = getAuditReader().getRevisions( MultipleCollectionEntity.class, mceId1 );
List<Number> re1Id1Revs = getAuditReader().getRevisions( MultipleCollectionRefEntity1.class, re1Id1 );
List<Number> re1Id2Revs = getAuditReader().getRevisions( MultipleCollectionRefEntity1.class, re1Id2 );
List<Number> re1Id3Revs = getAuditReader().getRevisions( MultipleCollectionRefEntity1.class, re1Id3 );
List<Number> re2Id1Revs = getAuditReader().getRevisions( MultipleCollectionRefEntity2.class, re2Id1 );
List<Number> re2Id2Revs = getAuditReader().getRevisions( MultipleCollectionRefEntity2.class, re2Id2 );
List<Number> re2Id3Revs = getAuditReader().getRevisions( MultipleCollectionRefEntity2.class, re2Id3 );
List<Number> mceId1Revs = getAuditReader().getRevisions(
MultipleCollectionEntity.class, mceId1);
List<Number> re1Id1Revs = getAuditReader().getRevisions(
MultipleCollectionRefEntity1.class, re1Id1);
List<Number> re1Id2Revs = getAuditReader().getRevisions(
MultipleCollectionRefEntity1.class, re1Id2);
List<Number> re1Id3Revs = getAuditReader().getRevisions(
MultipleCollectionRefEntity1.class, re1Id3);
List<Number> re2Id1Revs = getAuditReader().getRevisions(
MultipleCollectionRefEntity2.class, re2Id1);
List<Number> re2Id2Revs = getAuditReader().getRevisions(
MultipleCollectionRefEntity2.class, re2Id2);
List<Number> re2Id3Revs = getAuditReader().getRevisions(
MultipleCollectionRefEntity2.class, re2Id3);
assertEquals(Arrays.asList(1, 2, 3), mceId1Revs);
assertEquals(Arrays.asList(2, 3), re1Id1Revs);
assertEquals(Arrays.asList(2, 3), re1Id2Revs);
assertEquals(Arrays.asList(3), re1Id3Revs);
assertEquals(Arrays.asList(2, 3), re2Id1Revs);
assertEquals(Arrays.asList(2, 3), re2Id2Revs);
assertEquals(Arrays.asList(3), re2Id3Revs);
assertEquals( Arrays.asList( 1, 2, 3 ), mceId1Revs );
assertEquals( Arrays.asList( 2, 3 ), re1Id1Revs );
assertEquals( Arrays.asList( 2, 3 ), re1Id2Revs );
assertEquals( Arrays.asList( 3 ), re1Id3Revs );
assertEquals( Arrays.asList( 2, 3 ), re2Id1Revs );
assertEquals( Arrays.asList( 2, 3 ), re2Id2Revs );
assertEquals( Arrays.asList( 3 ), re2Id3Revs );
}
@Test
@ -258,93 +220,92 @@ public class DetachedMultipleCollectionChangeTest extends AbstractEntityTest {
"MCE_RE1_AUD", "MCE_ID",
"aud.originalId.MultipleCollectionEntity_id", "RE1_ID",
"aud.originalId.refEntities1_id", "aud.originalId.REV",
"aud.originalId.REV.id", "aud.REVTYPE");
"aud.originalId.REV.id", "aud.REVTYPE"
);
List<AuditJoinTableInfo> mceRe2AuditJoinTableInfos = getAuditJoinTableRows(
"MCE_RE2_AUD", "MCE_ID",
"aud.originalId.MultipleCollectionEntity_id", "RE2_ID",
"aud.originalId.refEntities2_id", "aud.originalId.REV",
"aud.originalId.REV.id", "aud.REVTYPE");
"aud.originalId.REV.id", "aud.REVTYPE"
);
assertEquals(4, mceRe1AuditJoinTableInfos.size());
assertEquals(4, mceRe2AuditJoinTableInfos.size());
assertEquals( 4, mceRe1AuditJoinTableInfos.size() );
assertEquals( 4, mceRe2AuditJoinTableInfos.size() );
DefaultRevisionEntity rev2 = new DefaultRevisionEntity();
rev2.setId(2);
DefaultRevisionEntity rev3 = new DefaultRevisionEntity();
rev3.setId(3);
SequenceIdRevisionEntity rev2 = new SequenceIdRevisionEntity();
rev2.setId( 2 );
SequenceIdRevisionEntity rev3 = new SequenceIdRevisionEntity();
rev3.setId( 3 );
assertEquals(new AuditJoinTableInfo("MCE_RE1_AUD", rev2,
RevisionType.ADD, "MCE_ID", 1L, "RE1_ID", 1L),
mceRe1AuditJoinTableInfos.get(0));
assertEquals(new AuditJoinTableInfo("MCE_RE1_AUD", rev2,
RevisionType.ADD, "MCE_ID", 1L, "RE1_ID", 2L),
mceRe1AuditJoinTableInfos.get(1));
assertEquals(new AuditJoinTableInfo("MCE_RE1_AUD", rev3,
RevisionType.DEL, "MCE_ID", 1L, "RE1_ID", 2L),
mceRe1AuditJoinTableInfos.get(2));
assertEquals(new AuditJoinTableInfo("MCE_RE1_AUD", rev3,
RevisionType.ADD, "MCE_ID", 1L, "RE1_ID", 3L),
mceRe1AuditJoinTableInfos.get(3));
assertEquals(new AuditJoinTableInfo("MCE_RE2_AUD", rev2,
RevisionType.ADD, "MCE_ID", 1L, "RE2_ID", 1L),
mceRe2AuditJoinTableInfos.get(0));
assertEquals(new AuditJoinTableInfo("MCE_RE2_AUD", rev2,
RevisionType.ADD, "MCE_ID", 1L, "RE2_ID", 2L),
mceRe2AuditJoinTableInfos.get(1));
assertEquals(new AuditJoinTableInfo("MCE_RE2_AUD", rev3,
RevisionType.DEL, "MCE_ID", 1L, "RE2_ID", 2L),
mceRe2AuditJoinTableInfos.get(2));
assertEquals(new AuditJoinTableInfo("MCE_RE2_AUD", rev3,
RevisionType.ADD, "MCE_ID", 1L, "RE2_ID", 3L),
mceRe2AuditJoinTableInfos.get(3));
assertEquals(
new AuditJoinTableInfo( "MCE_RE1_AUD", rev2, RevisionType.ADD, "MCE_ID", 1L, "RE1_ID", 1L ),
mceRe1AuditJoinTableInfos.get( 0 )
);
assertEquals(
new AuditJoinTableInfo( "MCE_RE1_AUD", rev2, RevisionType.ADD, "MCE_ID", 1L, "RE1_ID", 2L ),
mceRe1AuditJoinTableInfos.get( 1 )
);
assertEquals(
new AuditJoinTableInfo( "MCE_RE1_AUD", rev3, RevisionType.DEL, "MCE_ID", 1L, "RE1_ID", 2L ),
mceRe1AuditJoinTableInfos.get( 2 )
);
assertEquals(
new AuditJoinTableInfo( "MCE_RE1_AUD", rev3, RevisionType.ADD, "MCE_ID", 1L, "RE1_ID", 3L ),
mceRe1AuditJoinTableInfos.get( 3 )
);
assertEquals(
new AuditJoinTableInfo( "MCE_RE2_AUD", rev2, RevisionType.ADD, "MCE_ID", 1L, "RE2_ID", 1L ),
mceRe2AuditJoinTableInfos.get( 0 )
);
assertEquals(
new AuditJoinTableInfo( "MCE_RE2_AUD", rev2, RevisionType.ADD, "MCE_ID", 1L, "RE2_ID", 2L ),
mceRe2AuditJoinTableInfos.get( 1 )
);
assertEquals(
new AuditJoinTableInfo( "MCE_RE2_AUD", rev3, RevisionType.DEL, "MCE_ID", 1L, "RE2_ID", 2L ),
mceRe2AuditJoinTableInfos.get( 2 )
);
assertEquals(
new AuditJoinTableInfo( "MCE_RE2_AUD", rev3, RevisionType.ADD, "MCE_ID", 1L, "RE2_ID", 3L ),
mceRe2AuditJoinTableInfos.get( 3 )
);
}
private List<AuditJoinTableInfo> getAuditJoinTableRows(
String middleEntityName, String joinColumnIdName,
String joinColumnIdProp, String inverseJoinColumnIdName,
String inverseJoinColumnIdProp, String revProp, String revIdProp,
String revTypeProp) throws Exception {
StringBuilder qryBuilder = new StringBuilder("select ");
qryBuilder.append("aud ");
qryBuilder.append(", ").append(joinColumnIdProp)
.append(" as joinColumnId");
qryBuilder.append(", ").append(inverseJoinColumnIdProp)
.append(" as inverseJoinColumnId");
qryBuilder.append(", ").append(revProp).append(" as rev");
qryBuilder.append(", ").append(revIdProp).append(" as revId");
qryBuilder.append(", ").append(revTypeProp).append(" as revType");
qryBuilder.append(" from ").append(middleEntityName).append(" aud ");
qryBuilder
.append(" order by joinColumnId asc, inverseJoinColumnId asc, revId asc");
private List<AuditJoinTableInfo> getAuditJoinTableRows(String middleEntityName, String joinColumnIdName,
String joinColumnIdProp, String inverseJoinColumnIdName,
String inverseJoinColumnIdProp, String revProp, String revIdProp,
String revTypeProp) throws Exception {
StringBuilder qryBuilder = new StringBuilder( "select " );
qryBuilder.append( "aud " );
qryBuilder.append( ", " ).append( joinColumnIdProp ).append( " as joinColumnId" );
qryBuilder.append( ", " ).append( inverseJoinColumnIdProp ).append( " as inverseJoinColumnId" );
qryBuilder.append( ", " ).append( revProp ).append( " as rev" );
qryBuilder.append( ", " ).append( revIdProp ).append( " as revId" );
qryBuilder.append( ", " ).append( revTypeProp ).append( " as revType" );
qryBuilder.append( " from " ).append( middleEntityName ).append( " aud " );
qryBuilder.append( " order by joinColumnId asc, inverseJoinColumnId asc, revId asc" );
String query = qryBuilder.toString();
newEntityManager();
EntityManager em = getEntityManager();
Query qry = em.createQuery(query);
EntityManager em = createIsolatedEntityManager();
Query qry = em.createQuery( query );
@SuppressWarnings("unchecked")
List<Object[]> auditJoinTableRows = qry.getResultList();
List<AuditJoinTableInfo> result = new ArrayList<AuditJoinTableInfo>(
auditJoinTableRows.size());
List<AuditJoinTableInfo> result = new ArrayList<AuditJoinTableInfo>( auditJoinTableRows.size() );
for (Object[] auditJoinTableRow : auditJoinTableRows) {
for ( Object[] auditJoinTableRow : auditJoinTableRows ) {
Long joinColumnId = (Long) auditJoinTableRow[1];
Long inverseJoinColumnId = (Long) auditJoinTableRow[2];
DefaultRevisionEntity rev = (DefaultRevisionEntity) auditJoinTableRow[3];
SequenceIdRevisionEntity rev = (SequenceIdRevisionEntity) auditJoinTableRow[3];
RevisionType revType = (RevisionType) auditJoinTableRow[5];
AuditJoinTableInfo info = new AuditJoinTableInfo(middleEntityName,
rev, revType, joinColumnIdName, joinColumnId,
inverseJoinColumnIdName, inverseJoinColumnId);
result.add(info);
LOG.error("Found: " + info);
AuditJoinTableInfo info = new AuditJoinTableInfo(
middleEntityName, rev, revType, joinColumnIdName, joinColumnId,
inverseJoinColumnIdName, inverseJoinColumnId
);
result.add( info );
}
return result;
@ -359,10 +320,9 @@ public class DetachedMultipleCollectionChangeTest extends AbstractEntityTest {
private final String inverseJoinColumnName;
private final Long inverseJoinColumnId;
private AuditJoinTableInfo(String name, DefaultRevisionEntity rev,
RevisionType revType, String joinColumnName, Long joinColumnId,
String inverseJoinColumnName, Long inverseJoinColumnId) {
super();
private AuditJoinTableInfo(String name, SequenceIdRevisionEntity rev,
RevisionType revType, String joinColumnName, Long joinColumnId,
String inverseJoinColumnName, Long inverseJoinColumnId) {
this.name = name;
this.revId = rev.getId();
this.revType = revType;
@ -381,56 +341,52 @@ public class DetachedMultipleCollectionChangeTest extends AbstractEntityTest {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime
* result
+ ((inverseJoinColumnId == null) ? 0 : inverseJoinColumnId
.hashCode());
result = prime * result
+ ((joinColumnId == null) ? 0 : joinColumnId.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((revId == null) ? 0 : revId.hashCode());
result = prime * result
+ ((revType == null) ? 0 : revType.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
public boolean equals(Object o) {
if ( this == o ) {
return true;
if (obj == null)
}
if ( !( o instanceof AuditJoinTableInfo ) ) {
return false;
if (getClass() != obj.getClass())
}
AuditJoinTableInfo that = (AuditJoinTableInfo) o;
if ( inverseJoinColumnId != null ? !inverseJoinColumnId.equals( that.inverseJoinColumnId ) : that.inverseJoinColumnId != null ) {
return false;
AuditJoinTableInfo other = (AuditJoinTableInfo) obj;
if (inverseJoinColumnId == null) {
if (other.inverseJoinColumnId != null)
return false;
} else if (!inverseJoinColumnId.equals(other.inverseJoinColumnId))
}
if ( joinColumnId != null ? !joinColumnId.equals( that.joinColumnId ) : that.joinColumnId != null ) {
return false;
if (joinColumnId == null) {
if (other.joinColumnId != null)
return false;
} else if (!joinColumnId.equals(other.joinColumnId))
}
if ( name != null ? !name.equals( that.name ) : that.name != null ) {
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
}
if ( revId != null ? !revId.equals( that.revId ) : that.revId != null ) {
return false;
if (revId == null) {
if (other.revId != null)
return false;
} else if (!revId.equals(other.revId))
return false;
if (revType != other.revType)
}
if ( revType != that.revType ) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + ( revId != null ? revId.hashCode() : 0 );
result = 31 * result + ( revType != null ? revType.hashCode() : 0 );
result = 31 * result + ( joinColumnId != null ? joinColumnId.hashCode() : 0 );
result = 31 * result + ( inverseJoinColumnId != null ? inverseJoinColumnId.hashCode() : 0 );
return result;
}
}
}
public static void tryCommit(TransactionManager tm) throws Exception {
if ( tm.getStatus() == Status.STATUS_MARKED_ROLLBACK ) {
tm.rollback();
}
else {
tm.commit();
}
}
}