Author: adamw
Date: 2009-01-30 03:28:30 -0500 (Fri, 30 Jan 2009)
New Revision: 15833
Added:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/EnversJoinedSubclassEntityPersister.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/EnversSingleTableEntityPersister.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/EnversUnionSubclassEntityPersister.java
Modified:
core/branches/envers-hibernate-3.3/pom.xml
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/InheritanceType.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java
Log:
Hibernate-3.3-compatible Envers, also solving HHH-3737
Modified: core/branches/envers-hibernate-3.3/pom.xml
===================================================================
--- core/branches/envers-hibernate-3.3/pom.xml 2009-01-30 06:36:09 UTC (rev 15832)
+++ core/branches/envers-hibernate-3.3/pom.xml 2009-01-30 08:28:30 UTC (rev 15833)
@@ -8,15 +8,15 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
- <relativePath>../parent/pom.xml</relativePath>
</parent>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-envers</artifactId>
+ <groupId>org.jboss.envers</groupId>
+ <artifactId>jboss-envers</artifactId>
<packaging>jar</packaging>
- <name>Hibernate Envers</name>
+ <name>Envers</name>
<description>Support for entity auditing</description>
+ <version>1.2.0-hibernate-3.3</version>
<build>
<plugins>
@@ -156,7 +156,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
- <version>${version}</version>
+ <version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
@@ -166,18 +166,17 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
- <version>${version}</version>
+ <version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
- <version>${version}</version>
+ <version>3.3.0.ga</version>
</dependency>
- <!-- todo : change to work like hibernate-core after we import annotations
and em back into core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
- <version>3.3.1.ga</version>
+ <version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
@@ -191,10 +190,4 @@
</dependency>
</dependencies>
</dependencyManagement>
-
- <properties>
- <!-- for now, at least, lets aggregate them -->
- <jbossenvers.reports.aggregate>true</jbossenvers.reports.aggregate>
- </properties>
-
</project>
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-01-30
06:36:09 UTC (rev 15832)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-01-30
08:28:30 UTC (rev 15833)
@@ -215,21 +215,53 @@
}
}
+ private void addSingleInheritancePersisterHack(Element class_mapping) {
+ class_mapping.addAttribute("persister",
"org.hibernate.envers.entity.EnversSingleTableEntityPersister");
+ }
+
+ private void addJoinedInheritancePersisterHack(Element class_mapping) {
+ class_mapping.addAttribute("persister",
"org.hibernate.envers.entity.EnversJoinedSubclassEntityPersister");
+ }
+
+ private void addTablePerClassInheritancePersisterHack(Element class_mapping) {
+ class_mapping.addAttribute("persister",
"org.hibernate.envers.entity.EnversUnionSubclassEntityPersister");
+ }
+
@SuppressWarnings({"unchecked"})
private Triple<Element, ExtendedPropertyMapper, String> generateMappingData(
PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData
auditTableData,
IdMappingData idMapper) {
+ boolean hasDiscriminator = pc.getDiscriminator() != null;
+
Element class_mapping =
MetadataTools.createEntity(xmlMappingData.getMainXmlMapping(), auditTableData,
- pc.getDiscriminatorValue());
+ hasDiscriminator ? pc.getDiscriminatorValue() : null);
ExtendedPropertyMapper propertyMapper = new MultiPropertyMapper();
// Checking if there is a discriminator column
- if (pc.getDiscriminator() != null) {
+ if (hasDiscriminator) {
Element discriminator_element =
class_mapping.addElement("discriminator");
MetadataTools.addColumns(discriminator_element,
pc.getDiscriminator().getColumnIterator());
discriminator_element.addAttribute("type",
pc.getDiscriminator().getType().getName());
}
+ InheritanceType parentInheritance = InheritanceType.getForParent(pc);
+ switch (parentInheritance) {
+ case NONE:
+ break;
+
+ case SINGLE:
+ addSingleInheritancePersisterHack(class_mapping);
+ break;
+
+ case JOINED:
+ addJoinedInheritancePersisterHack(class_mapping);
+ break;
+
+ case TABLE_PER_CLASS:
+ addTablePerClassInheritancePersisterHack(class_mapping);
+ break;
+ }
+
// Adding the id mapping
class_mapping.add((Element) idMapper.getXmlMapping().clone());
@@ -278,7 +310,7 @@
// Generating a mapping for the id
IdMappingData idMapper = idMetadataGenerator.addId(pc);
- InheritanceType inheritanceType = InheritanceType.get(pc);
+ InheritanceType inheritanceType = InheritanceType.getForChild(pc);
// These properties will be read from the mapping data
final Element class_mapping;
@@ -300,6 +332,8 @@
case JOINED:
mappingData = generateInheritanceMappingData(pc, xmlMappingData,
auditTableData, "joined-subclass");
+ addJoinedInheritancePersisterHack(mappingData.getFirst());
+
// Adding the "key" element with all columns + the revision
number column
Element keyMapping = mappingData.getFirst().addElement("key");
MetadataTools.addColumns(keyMapping,
pc.getIdentifierProperty().getColumnIterator());
@@ -308,6 +342,9 @@
case TABLE_PER_CLASS:
mappingData = generateInheritanceMappingData(pc, xmlMappingData,
auditTableData, "union-subclass");
+
+ addTablePerClassInheritancePersisterHack(mappingData.getFirst());
+
break;
default:
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/InheritanceType.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/InheritanceType.java 2009-01-30
06:36:09 UTC (rev 15832)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/InheritanceType.java 2009-01-30
08:28:30 UTC (rev 15833)
@@ -44,16 +44,27 @@
* @return The inheritance type of this class. NONE, if this class does not inherit
from
* another persisten class.
*/
- public static InheritanceType get(PersistentClass pc) {
+ public static InheritanceType getForChild(PersistentClass pc) {
PersistentClass superclass = pc.getSuperclass();
if (superclass == null) {
return InheritanceType.NONE;
}
// We assume that every subclass is of the same type.
- Subclass subclass = (Subclass) superclass.getSubclassIterator().next();
+ return doGetForSubclass((Subclass) superclass.getSubclassIterator().next());
+ }
- if (subclass instanceof SingleTableSubclass) {
+ public static InheritanceType getForParent(PersistentClass pc) {
+ if (!pc.getSubclassIterator().hasNext()) {
+ return InheritanceType.NONE;
+ }
+
+ // We assume that every subclass is of the same type.
+ return doGetForSubclass((Subclass) pc.getSubclassIterator().next());
+ }
+
+ private static InheritanceType doGetForSubclass(Subclass subclass) {
+ if (subclass instanceof SingleTableSubclass) {
return InheritanceType.SINGLE;
} else if (subclass instanceof JoinedSubclass) {
return InheritanceType.JOINED;
@@ -62,5 +73,5 @@
}
throw new MappingException("Unknown subclass class: " +
subclass.getClass());
- }
+ }
}
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java 2009-01-30
06:36:09 UTC (rev 15832)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java 2009-01-30
08:28:30 UTC (rev 15833)
@@ -40,7 +40,6 @@
import org.hibernate.Transaction;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.EntityKey;
-import org.hibernate.engine.LoadQueryInfluencers;
import org.hibernate.engine.PersistenceContext;
import org.hibernate.engine.QueryParameters;
import org.hibernate.engine.SessionFactoryImplementor;
@@ -72,10 +71,6 @@
// Delegate methods
- public LoadQueryInfluencers getLoadQueryInfluencers() {
- return delegate.getLoadQueryInfluencers();
- }
-
public Interceptor getInterceptor() {
return delegate.getInterceptor();
}
Added:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/EnversJoinedSubclassEntityPersister.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/EnversJoinedSubclassEntityPersister.java
(rev 0)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/EnversJoinedSubclassEntityPersister.java 2009-01-30
08:28:30 UTC (rev 15833)
@@ -0,0 +1,47 @@
+/*
+ * 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.entity;
+
+import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.persister.entity.JoinedSubclassEntityPersister;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.cache.access.EntityRegionAccessStrategy;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.engine.Mapping;
+import org.hibernate.HibernateException;
+import org.hibernate.EntityMode;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class EnversJoinedSubclassEntityPersister extends JoinedSubclassEntityPersister {
+ public EnversJoinedSubclassEntityPersister(PersistentClass persistentClass,
EntityRegionAccessStrategy entityRegionAccessStrategy, SessionFactoryImplementor factory,
Mapping mapping) throws HibernateException {
+ super(persistentClass, entityRegionAccessStrategy, factory, mapping);
+ }
+
+ // A hack for
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3351
+ public EntityPersister getSubclassEntityPersister(Object instance,
SessionFactoryImplementor factory, EntityMode entityMode) {
+ return this;
+ }
+}
\ No newline at end of file
Added:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/EnversSingleTableEntityPersister.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/EnversSingleTableEntityPersister.java
(rev 0)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/EnversSingleTableEntityPersister.java 2009-01-30
08:28:30 UTC (rev 15833)
@@ -0,0 +1,47 @@
+/*
+ * 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.entity;
+
+import org.hibernate.persister.entity.SingleTableEntityPersister;
+import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.cache.access.EntityRegionAccessStrategy;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.engine.Mapping;
+import org.hibernate.HibernateException;
+import org.hibernate.EntityMode;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class EnversSingleTableEntityPersister extends SingleTableEntityPersister {
+ public EnversSingleTableEntityPersister(PersistentClass persistentClass,
EntityRegionAccessStrategy entityRegionAccessStrategy, SessionFactoryImplementor factory,
Mapping mapping) throws HibernateException {
+ super(persistentClass, entityRegionAccessStrategy, factory, mapping);
+ }
+
+ // A hack for
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3351
+ public EntityPersister getSubclassEntityPersister(Object instance,
SessionFactoryImplementor factory, EntityMode entityMode) {
+ return this;
+ }
+}
\ No newline at end of file
Added:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/EnversUnionSubclassEntityPersister.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/EnversUnionSubclassEntityPersister.java
(rev 0)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entity/EnversUnionSubclassEntityPersister.java 2009-01-30
08:28:30 UTC (rev 15833)
@@ -0,0 +1,47 @@
+/*
+ * 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.entity;
+
+import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.persister.entity.UnionSubclassEntityPersister;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.cache.access.EntityRegionAccessStrategy;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.engine.Mapping;
+import org.hibernate.HibernateException;
+import org.hibernate.EntityMode;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class EnversUnionSubclassEntityPersister extends UnionSubclassEntityPersister {
+ public EnversUnionSubclassEntityPersister(PersistentClass persistentClass,
EntityRegionAccessStrategy entityRegionAccessStrategy, SessionFactoryImplementor factory,
Mapping mapping) throws HibernateException {
+ super(persistentClass, entityRegionAccessStrategy, factory, mapping);
+ }
+
+ // A hack for
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3351
+ public EntityPersister getSubclassEntityPersister(Object instance,
SessionFactoryImplementor factory, EntityMode entityMode) {
+ return this;
+ }
+}
\ No newline at end of file