parent
179837554f
commit
5b782a83ea
|
@ -1,75 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Middleware LLC.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.envers.test.integration.superclass;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
|
||||||
import org.testng.annotations.BeforeClass;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adam Warski (adam at warski dot org)
|
|
||||||
*/
|
|
||||||
public class MappedSubclassing extends AbstractEntityTest {
|
|
||||||
private Integer id1;
|
|
||||||
|
|
||||||
public void configure(Ejb3Configuration cfg) {
|
|
||||||
cfg.addAnnotatedClass(SubclassEntity.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeClass(dependsOnMethods = "init")
|
|
||||||
public void initData() {
|
|
||||||
// Revision 1
|
|
||||||
EntityManager em = getEntityManager();
|
|
||||||
em.getTransaction().begin();
|
|
||||||
SubclassEntity se1 = new SubclassEntity("x");
|
|
||||||
em.persist(se1);
|
|
||||||
id1 = se1.getId();
|
|
||||||
em.getTransaction().commit();
|
|
||||||
|
|
||||||
// Revision 2
|
|
||||||
em.getTransaction().begin();
|
|
||||||
se1 = em.find(SubclassEntity.class, id1);
|
|
||||||
se1.setStr("y");
|
|
||||||
em.getTransaction().commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRevisionsCounts() {
|
|
||||||
assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SubclassEntity.class, id1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHistoryOfId1() {
|
|
||||||
SubclassEntity ver1 = new SubclassEntity(id1, "x");
|
|
||||||
SubclassEntity ver2 = new SubclassEntity(id1, "y");
|
|
||||||
|
|
||||||
assert getAuditReader().find(SubclassEntity.class, id1, 1).equals(ver1);
|
|
||||||
assert getAuditReader().find(SubclassEntity.class, id1, 2).equals(ver2);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,76 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Middleware LLC.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.envers.test.integration.superclass;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adam Warski (adam at warski dot org)
|
|
||||||
*/
|
|
||||||
@Entity
|
|
||||||
public class SubclassEntity extends SuperclassOfEntity {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
public SubclassEntity() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public SubclassEntity(Integer id, String str) {
|
|
||||||
super(str);
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SubclassEntity(String str) {
|
|
||||||
super(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 SubclassEntity)) return false;
|
|
||||||
if (!super.equals(o)) return false;
|
|
||||||
|
|
||||||
SubclassEntity that = (SubclassEntity) o;
|
|
||||||
|
|
||||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
int result = super.hashCode();
|
|
||||||
result = 31 * result + (id != null ? id.hashCode() : 0);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Middleware LLC.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.envers.test.integration.superclass;
|
|
||||||
|
|
||||||
import javax.persistence.MappedSuperclass;
|
|
||||||
|
|
||||||
import org.hibernate.envers.Audited;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adam Warski (adam at warski dot org)
|
|
||||||
*/
|
|
||||||
@MappedSuperclass
|
|
||||||
public class SuperclassOfEntity {
|
|
||||||
@Audited
|
|
||||||
private String str;
|
|
||||||
|
|
||||||
public SuperclassOfEntity() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperclassOfEntity(String str) {
|
|
||||||
this.str = str;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStr() {
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStr(String str) {
|
|
||||||
this.str = str;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (!(o instanceof SuperclassOfEntity)) return false;
|
|
||||||
|
|
||||||
SuperclassOfEntity that = (SuperclassOfEntity) o;
|
|
||||||
|
|
||||||
if (str != null ? !str.equals(that.str) : that.str != null) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
return (str != null ? str.hashCode() : 0);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue