[hibernate-commits] Hibernate SVN: r15722 - in core/trunk: envers/src/main/java/org/hibernate/envers/configuration/metadata and 5 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Dec 22 14:16:28 EST 2008


Author: adamw
Date: 2008-12-22 14:16:28 -0500 (Mon, 22 Dec 2008)
New Revision: 15722

Added:
   core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/
   core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildAuditing.java
   core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildEntity.java
   core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/ParentEntity.java
   core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/AllPerformance.java
Modified:
   core/trunk/documentation/envers/src/main/docbook/en-US/content/migration.xml
   core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AnnotationsMetadataReader.java
   core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentClassAuditingData.java
   core/trunk/envers/src/test/java/org/hibernate/envers/test/AbstractEntityTest.java
   core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/ComplexInsertPerformance.java
   core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/InsertsPerformance.java
   core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/UpdatesPerformance.java
   core/trunk/envers/src/test/resources/testng.xml
Log:
HHH-3633: classes can be audited also if they don't contain any properties (w/ test)

Some corrections in the manual

Performance tests

Modified: core/trunk/documentation/envers/src/main/docbook/en-US/content/migration.xml
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/content/migration.xml	2008-12-20 00:37:02 UTC (rev 15721)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/content/migration.xml	2008-12-22 19:16:28 UTC (rev 15722)
@@ -51,7 +51,7 @@
 
         <para>
             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>
 
     </sect1>
@@ -91,7 +91,7 @@
 
    &lt;!-- Envers listeners --&gt;
 
-   &lt;property name="org.hibernate.envers.versionsTableSuffix" value="_versions" /&gt;
+   &lt;property name="org.hibernate.envers.auditTableSuffix" value="_versions" /&gt;
    &lt;property name="org.hibernate.envers.revisionFieldName" value="_revision" /&gt;
    &lt;property name="org.hibernate.envers.revisionTypeFieldName" value="_rev_type" /&gt;
    &lt;!-- other envers properties --&gt;
@@ -150,8 +150,6 @@
     @Column(name="revision_timestamp")
     private long timestamp;
 
-    private String username;
-
     // Getters, setters, equals, hashCode ...
 }]]></programlisting>
 

Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AnnotationsMetadataReader.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AnnotationsMetadataReader.java	2008-12-20 00:37:02 UTC (rev 15721)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AnnotationsMetadataReader.java	2008-12-22 19:16:28 UTC (rev 15722)
@@ -186,10 +186,12 @@
 
         if (defaultAudited != null) {
             defaultStore = defaultAudited.modStore();
+			auditData.setDefaultAudited(true);
         } else {
             Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
             if (defaultVersioned != null) {
                 defaultStore = translateModStore(defaultVersioned.modStore());
+				auditData.setDefaultAudited(true);
             }
         }
     }

Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentClassAuditingData.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentClassAuditingData.java	2008-12-20 00:37:02 UTC (rev 15721)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/PersistentClassAuditingData.java	2008-12-22 19:16:28 UTC (rev 15722)
@@ -41,6 +41,11 @@
     private Map<String, PersistentPropertyAuditingData> properties;
     private AuditTable auditTable;
     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() {
         return properties;
@@ -62,8 +67,12 @@
         this.auditTable = auditTable;
     }
 
-    public boolean isAudited() {
-        if (properties.size() > 0) {
+	public void setDefaultAudited(boolean defaultAudited) {
+		this.defaultAudited = defaultAudited;
+	}
+
+	public boolean isAudited() {
+        if (defaultAudited || properties.size() > 0) {
             return true;
         } else {
             return false;

Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/AbstractEntityTest.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/AbstractEntityTest.java	2008-12-20 00:37:02 UTC (rev 15721)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/AbstractEntityTest.java	2008-12-22 19:16:28 UTC (rev 15722)
@@ -49,7 +49,7 @@
 
     public abstract void configure(Ejb3Configuration cfg);
 
-    protected void initListeners() {
+    private void initListeners() {
         AuditEventListener listener = new AuditEventListener();
         cfg.getEventListeners().setPostInsertEventListeners(new PostInsertEventListener[] { listener });
         cfg.getEventListeners().setPostUpdateEventListeners(new PostUpdateEventListener[] { listener });

Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildAuditing.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildAuditing.java	                        (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildAuditing.java	2008-12-22 19:16:28 UTC (rev 15722)
@@ -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);
+    }
+}

Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildEntity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildEntity.java	                        (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/EmptyChildEntity.java	2008-12-22 19:16:28 UTC (rev 15722)
@@ -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)
+ */
+ at Entity
+ at Audited
+public class EmptyChildEntity extends ParentEntity {
+	public EmptyChildEntity() {
+	}
+
+	public EmptyChildEntity(Integer id, String data) {
+		super(id, data);
+	}
+}

Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/ParentEntity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/ParentEntity.java	                        (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/emptychild/ParentEntity.java	2008-12-22 19:16:28 UTC (rev 15722)
@@ -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)
+ */
+ at Entity
+ at Inheritance(strategy = InheritanceType.JOINED)
+ at 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() + ")";
+    }
+}

Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/AllPerformance.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/AllPerformance.java	                        (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/AllPerformance.java	2008-12-22 19:16:28 UTC (rev 15722)
@@ -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);
+	}
+}

Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/ComplexInsertPerformance.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/ComplexInsertPerformance.java	2008-12-20 00:37:02 UTC (rev 15721)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/ComplexInsertPerformance.java	2008-12-22 19:16:28 UTC (rev 15722)
@@ -45,7 +45,7 @@
         cfg.addAnnotatedClass(ChildEntity2.class);
     }
 
-    private final static int NUMBER_INSERTS = 100;
+    private final static int NUMBER_INSERTS = 1000;
 
     private long idCounter = 0;
 

Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/InsertsPerformance.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/InsertsPerformance.java	2008-12-20 00:37:02 UTC (rev 15721)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/InsertsPerformance.java	2008-12-22 19:16:28 UTC (rev 15722)
@@ -38,7 +38,7 @@
         cfg.addAnnotatedClass(StrTestEntity.class);
     }
 
-    private final static int NUMBER_INSERTS = 500;
+    private final static int NUMBER_INSERTS = 5000;
 
     protected void doTest() {
         for (int i=0; i<NUMBER_INSERTS; i++) {

Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/UpdatesPerformance.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/UpdatesPerformance.java	2008-12-20 00:37:02 UTC (rev 15721)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/performance/UpdatesPerformance.java	2008-12-22 19:16:28 UTC (rev 15722)
@@ -40,7 +40,7 @@
         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 Random random = new Random();
@@ -80,4 +80,4 @@
         UpdatesPerformance updatesPerformance = new UpdatesPerformance();
         updatesPerformance.test(3);
     }
-}
\ No newline at end of file
+}

Modified: core/trunk/envers/src/test/resources/testng.xml
===================================================================
--- core/trunk/envers/src/test/resources/testng.xml	2008-12-20 00:37:02 UTC (rev 15721)
+++ core/trunk/envers/src/test/resources/testng.xml	2008-12-22 19:16:28 UTC (rev 15722)
@@ -15,6 +15,7 @@
             <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.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.relation" />
             <package name="org.hibernate.envers.test.integration.inheritance.single" />
@@ -47,4 +48,4 @@
             <package name="org.hibernate.envers.test.integration.superclass" />
         </packages>
     </test>
-</suite>
\ No newline at end of file
+</suite>




More information about the hibernate-commits mailing list