HHH-3633: classes can be audited also if they don't contain any properties (w/ test)
Some corrections in the manual Performance tests git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@15722 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
4e5381eb9f
commit
76c4685117
|
@ -51,7 +51,7 @@
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Also, the query interface has changed slightly, mainly in the part for specifying restrictions,
|
Also, the query interface has changed slightly, mainly in the part for specifying restrictions,
|
||||||
projections and order. Please refer to the API for further details.
|
projections and order. Please refer to the Javadoc for further details.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
</sect1>
|
</sect1>
|
||||||
|
@ -91,7 +91,7 @@
|
||||||
|
|
||||||
<!-- Envers listeners -->
|
<!-- Envers listeners -->
|
||||||
|
|
||||||
<property name="org.hibernate.envers.versionsTableSuffix" value="_versions" />
|
<property name="org.hibernate.envers.auditTableSuffix" value="_versions" />
|
||||||
<property name="org.hibernate.envers.revisionFieldName" value="_revision" />
|
<property name="org.hibernate.envers.revisionFieldName" value="_revision" />
|
||||||
<property name="org.hibernate.envers.revisionTypeFieldName" value="_rev_type" />
|
<property name="org.hibernate.envers.revisionTypeFieldName" value="_rev_type" />
|
||||||
<!-- other envers properties -->
|
<!-- other envers properties -->
|
||||||
|
@ -150,8 +150,6 @@ public class ExampleRevEntity {
|
||||||
@Column(name="revision_timestamp")
|
@Column(name="revision_timestamp")
|
||||||
private long timestamp;
|
private long timestamp;
|
||||||
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
// Getters, setters, equals, hashCode ...
|
// Getters, setters, equals, hashCode ...
|
||||||
}]]></programlisting>
|
}]]></programlisting>
|
||||||
|
|
||||||
|
|
|
@ -186,10 +186,12 @@ public final class AnnotationsMetadataReader {
|
||||||
|
|
||||||
if (defaultAudited != null) {
|
if (defaultAudited != null) {
|
||||||
defaultStore = defaultAudited.modStore();
|
defaultStore = defaultAudited.modStore();
|
||||||
|
auditData.setDefaultAudited(true);
|
||||||
} else {
|
} else {
|
||||||
Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
|
Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
|
||||||
if (defaultVersioned != null) {
|
if (defaultVersioned != null) {
|
||||||
defaultStore = translateModStore(defaultVersioned.modStore());
|
defaultStore = translateModStore(defaultVersioned.modStore());
|
||||||
|
auditData.setDefaultAudited(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,11 @@ public class PersistentClassAuditingData {
|
||||||
private Map<String, PersistentPropertyAuditingData> properties;
|
private Map<String, PersistentPropertyAuditingData> properties;
|
||||||
private AuditTable auditTable;
|
private AuditTable auditTable;
|
||||||
private Map<String, String> secondaryTableDictionary;
|
private Map<String, String> secondaryTableDictionary;
|
||||||
|
/**
|
||||||
|
* True if the class is audited globally (this helps to cover the cases when there are no fields in the class,
|
||||||
|
* but it's still audited).
|
||||||
|
*/
|
||||||
|
private boolean defaultAudited;
|
||||||
|
|
||||||
public Map<String, PersistentPropertyAuditingData> getProperties() {
|
public Map<String, PersistentPropertyAuditingData> getProperties() {
|
||||||
return properties;
|
return properties;
|
||||||
|
@ -62,8 +67,12 @@ public class PersistentClassAuditingData {
|
||||||
this.auditTable = auditTable;
|
this.auditTable = auditTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAudited() {
|
public void setDefaultAudited(boolean defaultAudited) {
|
||||||
if (properties.size() > 0) {
|
this.defaultAudited = defaultAudited;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAudited() {
|
||||||
|
if (defaultAudited || properties.size() > 0) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -49,7 +49,7 @@ public abstract class AbstractEntityTest {
|
||||||
|
|
||||||
public abstract void configure(Ejb3Configuration cfg);
|
public abstract void configure(Ejb3Configuration cfg);
|
||||||
|
|
||||||
protected void initListeners() {
|
private void initListeners() {
|
||||||
AuditEventListener listener = new AuditEventListener();
|
AuditEventListener listener = new AuditEventListener();
|
||||||
cfg.getEventListeners().setPostInsertEventListeners(new PostInsertEventListener[] { listener });
|
cfg.getEventListeners().setPostInsertEventListeners(new PostInsertEventListener[] { listener });
|
||||||
cfg.getEventListeners().setPostUpdateEventListeners(new PostUpdateEventListener[] { listener });
|
cfg.getEventListeners().setPostUpdateEventListeners(new PostUpdateEventListener[] { listener });
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* 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.inheritance.joined.emptychild;
|
||||||
|
|
||||||
|
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 EmptyChildAuditing extends AbstractEntityTest {
|
||||||
|
private Integer id1;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(EmptyChildEntity.class);
|
||||||
|
cfg.addAnnotatedClass(ParentEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass(dependsOnMethods = "init")
|
||||||
|
public void initData() {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
|
||||||
|
id1 = 1;
|
||||||
|
|
||||||
|
// Rev 1
|
||||||
|
em.getTransaction().begin();
|
||||||
|
EmptyChildEntity pe = new EmptyChildEntity(id1, "x");
|
||||||
|
em.persist(pe);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Rev 2
|
||||||
|
em.getTransaction().begin();
|
||||||
|
pe = em.find(EmptyChildEntity.class, id1);
|
||||||
|
pe.setData("y");
|
||||||
|
em.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRevisionsCounts() {
|
||||||
|
assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(EmptyChildEntity.class, id1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHistoryOfChildId1() {
|
||||||
|
EmptyChildEntity ver1 = new EmptyChildEntity(id1, "x");
|
||||||
|
EmptyChildEntity ver2 = new EmptyChildEntity(id1, "y");
|
||||||
|
|
||||||
|
assert getAuditReader().find(EmptyChildEntity.class, id1, 1).equals(ver1);
|
||||||
|
assert getAuditReader().find(EmptyChildEntity.class, id1, 2).equals(ver2);
|
||||||
|
|
||||||
|
assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1);
|
||||||
|
assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPolymorphicQuery() {
|
||||||
|
EmptyChildEntity childVer1 = new EmptyChildEntity(id1, "x");
|
||||||
|
|
||||||
|
assert getAuditReader().createQuery().forEntitiesAtRevision(EmptyChildEntity.class, 1).getSingleResult()
|
||||||
|
.equals(childVer1);
|
||||||
|
|
||||||
|
assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult()
|
||||||
|
.equals(childVer1);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* 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.inheritance.joined.emptychild;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
|
import org.hibernate.envers.Audited;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Audited
|
||||||
|
public class EmptyChildEntity extends ParentEntity {
|
||||||
|
public EmptyChildEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public EmptyChildEntity(Integer id, String data) {
|
||||||
|
super(id, data);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
* 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.inheritance.joined.emptychild;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Inheritance;
|
||||||
|
import javax.persistence.InheritanceType;
|
||||||
|
|
||||||
|
import org.hibernate.envers.Audited;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Inheritance(strategy = InheritanceType.JOINED)
|
||||||
|
@Audited
|
||||||
|
public abstract class ParentEntity {
|
||||||
|
@Id
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Basic
|
||||||
|
private String data;
|
||||||
|
|
||||||
|
public ParentEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParentEntity(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 ParentEntity)) return false;
|
||||||
|
|
||||||
|
ParentEntity that = (ParentEntity) 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 "ParentEntity(id = " + getId() + ", data = " + getData() + ")";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package org.hibernate.envers.test.performance;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class AllPerformance {
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
new InsertsPerformance().test(10);
|
||||||
|
new ComplexInsertPerformance().test(10);
|
||||||
|
new UpdatesPerformance().test(10);
|
||||||
|
new InsertsOneTransactionPerformance().test(10);
|
||||||
|
}
|
||||||
|
}
|
|
@ -45,7 +45,7 @@ public class ComplexInsertPerformance extends AbstractPerformanceTest {
|
||||||
cfg.addAnnotatedClass(ChildEntity2.class);
|
cfg.addAnnotatedClass(ChildEntity2.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static int NUMBER_INSERTS = 100;
|
private final static int NUMBER_INSERTS = 1000;
|
||||||
|
|
||||||
private long idCounter = 0;
|
private long idCounter = 0;
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class InsertsPerformance extends AbstractPerformanceTest {
|
||||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static int NUMBER_INSERTS = 500;
|
private final static int NUMBER_INSERTS = 5000;
|
||||||
|
|
||||||
protected void doTest() {
|
protected void doTest() {
|
||||||
for (int i=0; i<NUMBER_INSERTS; i++) {
|
for (int i=0; i<NUMBER_INSERTS; i++) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class UpdatesPerformance extends AbstractPerformanceTest {
|
||||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static int NUMBER_UPDATES = 500;
|
private final static int NUMBER_UPDATES = 5000;
|
||||||
private final static int NUMBER_ENTITIES = 10;
|
private final static int NUMBER_ENTITIES = 10;
|
||||||
|
|
||||||
private Random random = new Random();
|
private Random random = new Random();
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
<package name="org.hibernate.envers.test.integration.ids" />
|
<package name="org.hibernate.envers.test.integration.ids" />
|
||||||
<package name="org.hibernate.envers.test.integration.inheritance.joined" />
|
<package name="org.hibernate.envers.test.integration.inheritance.joined" />
|
||||||
<package name="org.hibernate.envers.test.integration.inheritance.joined.childrelation" />
|
<package name="org.hibernate.envers.test.integration.inheritance.joined.childrelation" />
|
||||||
|
<package name="org.hibernate.envers.test.integration.inheritance.joined.emptychild" />
|
||||||
<package name="org.hibernate.envers.test.integration.inheritance.joined.notownedrelation" />
|
<package name="org.hibernate.envers.test.integration.inheritance.joined.notownedrelation" />
|
||||||
<package name="org.hibernate.envers.test.integration.inheritance.joined.relation" />
|
<package name="org.hibernate.envers.test.integration.inheritance.joined.relation" />
|
||||||
<package name="org.hibernate.envers.test.integration.inheritance.single" />
|
<package name="org.hibernate.envers.test.integration.inheritance.single" />
|
||||||
|
|
Loading…
Reference in New Issue