Author: adamw
Date: 2009-06-30 12:09:09 -0400 (Tue, 30 Jun 2009)
New Revision: 16982
Added:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/query/StoreDeletedData.java
Modified:
core/branches/envers-hibernate-3.3/pom.xml
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/AuditReaderFactory.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/DefaultRevisionEntity.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/event/AuditEventListener.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/synchronization/work/DelWorkUnit.java
Log:
svn merge -r 16710:16981
https://svn.jboss.org/repos/hibernate/core/trunk/envers .
Modified: core/branches/envers-hibernate-3.3/pom.xml
===================================================================
--- core/branches/envers-hibernate-3.3/pom.xml 2009-06-30 15:56:49 UTC (rev 16981)
+++ core/branches/envers-hibernate-3.3/pom.xml 2009-06-30 16:09:09 UTC (rev 16982)
@@ -110,13 +110,13 @@
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
- <version>2.2</version>
+ <version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
- <version>3.4.GA</version>
+ <version>3.4.GA</version>
<scope>test</scope>
</dependency>
</dependencies>
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/AuditReaderFactory.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/AuditReaderFactory.java 2009-06-30
15:56:49 UTC (rev 16981)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/AuditReaderFactory.java 2009-06-30
16:09:09 UTC (rev 16982)
@@ -86,10 +86,7 @@
}
if (entityManager.getDelegate() instanceof EntityManager) {
- entityManager = (EntityManager) entityManager.getDelegate();
- if (entityManager.getDelegate() instanceof Session) {
- return get((Session) entityManager.getDelegate());
- }
+ return get((EntityManager) entityManager.getDelegate());
}
throw new AuditException("Hibernate EntityManager not present!");
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/DefaultRevisionEntity.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/DefaultRevisionEntity.java 2009-06-30
15:56:49 UTC (rev 16981)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/DefaultRevisionEntity.java 2009-06-30
16:09:09 UTC (rev 16982)
@@ -25,6 +25,7 @@
import java.text.DateFormat;
import java.util.Date;
+import java.io.Serializable;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
@@ -34,7 +35,9 @@
* @author Adam Warski (adam at warski dot org)
*/
@MappedSuperclass
-public class DefaultRevisionEntity {
+public class DefaultRevisionEntity implements Serializable {
+ private static final long serialVersionUID = 8530213963961662300L;
+
@Id
@GeneratedValue
@RevisionNumber
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java 2009-06-30
15:56:49 UTC (rev 16981)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java 2009-06-30
16:09:09 UTC (rev 16982)
@@ -36,6 +36,9 @@
// Should the optimistic locking property of an entity be considered unversioned
private final boolean doNotAuditOptimisticLockingField;
+ // Should entity data be stored when it is deleted
+ private final boolean storeDataAtDelete;
+
/*
Which operator to use in correlated subqueries (when we want a property to be equal
to the result of
a correlated subquery, for example: e.p <operator> (select max(e2.p) where
e2.p2 = e.p2 ...).
@@ -53,6 +56,9 @@
"true");
doNotAuditOptimisticLockingField =
Boolean.parseBoolean(ignoreOptimisticLockingPropertyStr);
+ String storeDataDeletedEntityStr =
properties.getProperty("org.hibernate.envers.storeDataAtDelete",
"false");
+ storeDataAtDelete = Boolean.parseBoolean(storeDataDeletedEntityStr);
+
correlatedSubqueryOperator =
"org.hibernate.dialect.HSQLDialect".equals(
properties.getProperty("hibernate.dialect")) ? "in" :
"=";
}
@@ -68,4 +74,8 @@
public String getCorrelatedSubqueryOperator() {
return correlatedSubqueryOperator;
}
+
+ public boolean isStoreDataAtDelete() {
+ return storeDataAtDelete;
+ }
}
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/event/AuditEventListener.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2009-06-30
15:56:49 UTC (rev 16981)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2009-06-30
16:09:09 UTC (rev 16982)
@@ -175,7 +175,7 @@
AuditSync verSync = verCfg.getSyncManager().get(event.getSession());
verSync.addWorkUnit(new DelWorkUnit(event.getSession(),
event.getPersister().getEntityName(), verCfg,
- event.getId()));
+ event.getId(), event.getPersister(), event.getDeletedState()));
generateBidirectionalCollectionChangeWorkUnits(verSync, event.getPersister(),
entityName, null,
event.getDeletedState(), event.getSession());
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/synchronization/work/DelWorkUnit.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/synchronization/work/DelWorkUnit.java 2009-06-30
15:56:49 UTC (rev 16981)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/synchronization/work/DelWorkUnit.java 2009-06-30
16:09:09 UTC (rev 16982)
@@ -31,14 +31,22 @@
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.Session;
+import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.engine.SessionImplementor;
/**
* @author Adam Warski (adam at warski dot org)
*/
public class DelWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit {
- public DelWorkUnit(SessionImplementor sessionImplementor, String entityName,
AuditConfiguration verCfg, Serializable id) {
+ private final Object[] state;
+ private final String[] propertyNames;
+
+ public DelWorkUnit(SessionImplementor sessionImplementor, String entityName,
AuditConfiguration verCfg,
+ Serializable id, EntityPersister entityPersister, Object[] state) {
super(sessionImplementor, entityName, verCfg, id);
+
+ this.state = state;
+ this.propertyNames = entityPersister.getPropertyNames();
}
public boolean containsWork() {
@@ -49,6 +57,11 @@
Map<String, Object> data = new HashMap<String, Object>();
fillDataWithId(data, revisionData, RevisionType.DEL);
+ if (verCfg.getGlobalCfg().isStoreDataAtDelete()) {
+ verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().map(sessionImplementor,
data,
+ propertyNames, state, state);
+ }
+
session.save(verCfg.getAuditEntCfg().getAuditEntityName(getEntityName()), data);
setPerformed(data);
Copied:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/query/StoreDeletedData.java
(from rev 16981,
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/StoreDeletedData.java)
===================================================================
---
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/query/StoreDeletedData.java
(rev 0)
+++
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/query/StoreDeletedData.java 2009-06-30
16:09:09 UTC (rev 16982)
@@ -0,0 +1,82 @@
+/*
+ * 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.query;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.query.AuditEntity;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.StrIntTestEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.List;
+
+/**
+ * A test which checks if the data of a deleted entity is stored when the setting is on.
+ * @author Adam Warski (adam at warski dot org)
+ */
+@SuppressWarnings({"unchecked"})
+public class StoreDeletedData extends AbstractEntityTest {
+ private Integer id1;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(StrIntTestEntity.class);
+ cfg.setProperty("org.hibernate.envers.storeDataAtDelete", "true");
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ // Revision 1
+ EntityManager em = getEntityManager();
+ em.getTransaction().begin();
+
+ StrIntTestEntity site1 = new StrIntTestEntity("a", 10);
+
+ em.persist(site1);
+
+ id1 = site1.getId();
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ em.remove(site1);
+
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsPropertyEqQuery() {
+ List revs_id1 = getAuditReader().createQuery()
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
+ .add(AuditEntity.id().eq(id1))
+ .getResultList();
+
+ assert revs_id1.size() == 2;
+ assert ((Object[]) revs_id1.get(0))[0].equals(new StrIntTestEntity("a",
10, id1));
+ assert ((Object[]) revs_id1.get(1))[0].equals(new StrIntTestEntity("a",
10, id1));
+ }
+}
\ No newline at end of file