JBoss Envers SVN: r136 - in trunk/src: main/org/jboss/envers/configuration/metadata and 3 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-31 04:46:36 -0400 (Sun, 31 Aug 2008)
New Revision: 136
Added:
trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoNumberReader.java
Removed:
trunk/src/main/org/jboss/envers/revisioninfo/AbstractRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/revisioninfo/RevisionNumberGenerator.java
Modified:
trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
trunk/src/test/org/jboss/envers/test/working/WorkingEntity1.java
trunk/src/test/org/jboss/envers/test/working/WorkingEntity2.java
trunk/src/test/org/jboss/envers/test/working/WorkingMain.java
Log:
ENVERS-47: revision info always mapped to a class, not as a dynamic model when a custom revision entity is missing
Modified: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -1,3 +1,24 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
package org.jboss.envers.configuration;
import org.jboss.envers.entities.EntitiesConfigurations;
@@ -12,6 +33,7 @@
import org.dom4j.io.OutputFormat;
import org.dom4j.Document;
import org.dom4j.DocumentException;
+import org.dom4j.Element;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.MappingException;
import org.hibernate.cfg.Configuration;
@@ -30,8 +52,9 @@
public class EntitiesConfigurator {
public EntitiesConfigurations configure(Configuration cfg, YReflectionManager reflectionManager,
GlobalConfiguration globalCfg, VersionsEntitiesConfiguration verEntCfg,
- Document revisionInfoXmlMapping) {
- VersionsMetadataGenerator versionsMetaGen = new VersionsMetadataGenerator(cfg, globalCfg, verEntCfg);
+ Document revisionInfoXmlMapping, Element revisionInfoRelationMapping) {
+ VersionsMetadataGenerator versionsMetaGen = new VersionsMetadataGenerator(cfg, globalCfg, verEntCfg,
+ revisionInfoRelationMapping);
DOMWriter writer = new DOMWriter();
// Sorting the persistent class topologically - superclass always before subclass
Modified: trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -4,10 +4,7 @@
import org.jboss.envers.tools.reflection.YReflectionManager;
import org.jboss.envers.tools.reflection.YProperty;
import org.jboss.envers.tools.MutableBoolean;
-import org.jboss.envers.RevisionNumber;
-import org.jboss.envers.RevisionTimestamp;
-import org.jboss.envers.RevisionEntity;
-import org.jboss.envers.Versioned;
+import org.jboss.envers.*;
import org.jboss.envers.configuration.metadata.MetadataTools;
import org.jboss.envers.revisioninfo.*;
import org.hibernate.MappingException;
@@ -31,9 +28,9 @@
private String revisionPropType;
public RevisionInfoConfiguration() {
- revisionInfoEntityName = "_revisions_info";
- revisionInfoIdName = "revision_id";
- revisionInfoTimestampName = "revision_timestamp";
+ revisionInfoEntityName = "org.jboss.envers.DefaultRevisionEntity";
+ revisionInfoIdName = "id";
+ revisionInfoTimestampName = "timestamp";
revisionInfoTimestampType = "long";
revisionPropType = "integer";
@@ -42,18 +39,31 @@
private Document generateDefaultRevisionInfoXmlMapping() {
Document document = DocumentHelper.createDocument();
- Element class_mapping = MetadataTools.createEntity(document, revisionInfoEntityName,
- null, null, null, null);
+ Element class_mapping = MetadataTools.createEntity(document, null, null, null, null, null);
- MetadataTools.addNativelyGeneratedId(class_mapping, revisionInfoIdName,
+ class_mapping.addAttribute("name", revisionInfoEntityName);
+ class_mapping.addAttribute("table", "_revisions_info");
+
+ Element idProperty = MetadataTools.addNativelyGeneratedId(class_mapping, revisionInfoIdName,
revisionPropType);
+ MetadataTools.addColumn(idProperty, "revision_id", null);
- MetadataTools.addProperty(class_mapping, revisionInfoTimestampName,
+ Element timestampProperty = MetadataTools.addProperty(class_mapping, revisionInfoTimestampName,
revisionInfoTimestampType, false);
+ MetadataTools.addColumn(timestampProperty, "revision_timestamp", null);
return document;
}
+ private Element generateRevisionInfoRelationMapping() {
+ Document document = DocumentHelper.createDocument();
+ Element rev_rel_mapping =document.addElement("key-many-to-one");
+ rev_rel_mapping.addAttribute("type", revisionPropType);
+ rev_rel_mapping.addAttribute("class", revisionInfoEntityName);
+
+ return rev_rel_mapping;
+ }
+
private void searchForRevisionInfoCfg(YClass clazz, YReflectionManager reflectionManager,
MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound) {
YClass superclazz = clazz.getSuperclass();
@@ -112,6 +122,8 @@
boolean revisionEntityFound = false;
RevisionInfoGenerator revisionInfoGenerator = null;
+ Class<?> revisionInfoClass = null;
+
while (classes.hasNext()) {
PersistentClass pc = classes.next();
YClass clazz;
@@ -151,7 +163,8 @@
revisionInfoEntityName = pc.getEntityName();
- revisionInfoGenerator = new CustomRevisionInfoGenerator(revisionInfoEntityName, pc.getMappedClass(),
+ revisionInfoClass = pc.getMappedClass();
+ revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, pc.getMappedClass(),
revisionEntity.value(), revisionInfoTimestampName);
}
}
@@ -160,14 +173,19 @@
Document revisionInfoXmlMapping = null;
if (revisionInfoGenerator == null) {
- revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoTimestampName);
+ // TODO - remove default
+ //revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoTimestampName);
+ revisionInfoClass = DefaultRevisionEntity.class;
+ revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, DefaultRevisionEntity.class,
+ RevisionListener.class, revisionInfoTimestampName);
revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping();
}
return new RevisionInfoConfigurationResult(
revisionInfoGenerator, revisionPropType, revisionInfoXmlMapping,
new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdName, revisionInfoTimestampName),
- revisionInfoEntityName, revisionInfoIdName);
+ generateRevisionInfoRelationMapping(), revisionInfoIdName,
+ new RevisionInfoNumberReader(revisionInfoClass, revisionInfoIdName));
}
}
@@ -176,18 +194,22 @@
private final String revisionPropType;
private final Document revisionInfoXmlMapping;
private final RevisionInfoQueryCreator revisionInfoQueryCreator;
- private final String revisionInfoEntityName;
+ private final Element revisionInfoRelationMapping;
+ // TODO - remove ?
private final String revisionInfoIdName;
+ private final RevisionInfoNumberReader revisionInfoNumberReader;
RevisionInfoConfigurationResult(RevisionInfoGenerator revisionInfoGenerator, String revisionPropType,
Document revisionInfoXmlMapping, RevisionInfoQueryCreator revisionInfoQueryCreator,
- String revisionInfoEntityName, String revisionInfoIdName) {
+ Element revisionInfoRelationMapping, String revisionInfoIdName,
+ RevisionInfoNumberReader revisionInfoNumberReader) {
this.revisionInfoGenerator = revisionInfoGenerator;
this.revisionPropType = revisionPropType;
this.revisionInfoXmlMapping = revisionInfoXmlMapping;
this.revisionInfoQueryCreator = revisionInfoQueryCreator;
- this.revisionInfoEntityName = revisionInfoEntityName;
+ this.revisionInfoRelationMapping = revisionInfoRelationMapping;
this.revisionInfoIdName = revisionInfoIdName;
+ this.revisionInfoNumberReader = revisionInfoNumberReader;
}
public RevisionInfoGenerator getRevisionInfoGenerator() {
@@ -206,11 +228,15 @@
return revisionInfoQueryCreator;
}
- public String getRevisionInfoEntityName() {
- return revisionInfoEntityName;
+ public Element getRevisionInfoRelationMapping() {
+ return revisionInfoRelationMapping;
}
public String getRevisionInfoIdName() {
return revisionInfoIdName;
}
+
+ public RevisionInfoNumberReader getRevisionInfoNumberReader() {
+ return revisionInfoNumberReader;
+ }
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -26,6 +26,7 @@
import org.jboss.envers.synchronization.VersionsSyncManager;
import org.jboss.envers.tools.reflection.YReflectionManager;
import org.jboss.envers.revisioninfo.RevisionInfoQueryCreator;
+import org.jboss.envers.revisioninfo.RevisionInfoNumberReader;
import java.util.*;
@@ -38,6 +39,7 @@
private final VersionsSyncManager versionsSyncManager;
private final EntitiesConfigurations entCfg;
private final RevisionInfoQueryCreator revisionInfoQueryCreator;
+ private final RevisionInfoNumberReader revisionInfoNumberReader;
public VersionsEntitiesConfiguration getVerEntCfg() {
return verEntCfg;
@@ -59,6 +61,10 @@
return revisionInfoQueryCreator;
}
+ public RevisionInfoNumberReader getRevisionInfoNumberReader() {
+ return revisionInfoNumberReader;
+ }
+
@SuppressWarnings({"unchecked"})
public VersionsConfiguration(Configuration cfg) {
Properties properties = cfg.getProperties();
@@ -67,12 +73,13 @@
RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration();
RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg, reflectionManager);
verEntCfg = new VersionsEntitiesConfiguration(properties, revInfoCfgResult.getRevisionPropType(),
- revInfoCfgResult.getRevisionInfoEntityName(), revInfoCfgResult.getRevisionInfoIdName());
+ revInfoCfgResult.getRevisionInfoIdName());
globalCfg = new GlobalConfiguration(properties);
versionsSyncManager = new VersionsSyncManager(revInfoCfgResult.getRevisionInfoGenerator());
revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
+ revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader();
entCfg = new EntitiesConfigurator().configure(cfg, reflectionManager, globalCfg, verEntCfg,
- revInfoCfgResult.getRevisionInfoXmlMapping());
+ revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping());
}
//
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -37,17 +37,16 @@
private final String revisionPropType;
private final String revisionPropPath;
+ private final String revisionEntityPath;
+
private final String revisionTypePropName;
private final String revisionTypePropType;
- private final String revisionInfoEntityName;
private final String revisionInfoIdName;
private final Map<String, String> customVersionsTablesNames;
- public VersionsEntitiesConfiguration(Properties properties, String revisionPropType, String revisionInfoEntityName,
- String revisionInfoIdName) {
- this.revisionInfoEntityName = revisionInfoEntityName;
+ public VersionsEntitiesConfiguration(Properties properties, String revisionPropType, String revisionInfoIdName) {
this.revisionInfoIdName = revisionInfoIdName;
versionsTablePrefix = properties.getProperty("org.jboss.envers.versionsTablePrefix", "");
@@ -63,7 +62,8 @@
customVersionsTablesNames = new HashMap<String, String>();
- revisionPropPath = originalIdPropName + "." + revisionPropName + ".id";
+ revisionEntityPath = originalIdPropName + "." + revisionPropName;
+ revisionPropPath = revisionEntityPath + ".id";
}
public String getOriginalIdPropName() {
@@ -90,14 +90,14 @@
return revisionTypePropType;
}
- public String getRevisionInfoEntityName() {
- return revisionInfoEntityName;
- }
-
public String getRevisionInfoIdName() {
return revisionInfoIdName;
}
+ public String getRevisionEntityPath() {
+ return revisionEntityPath;
+ }
+
//
public void addCustomVersionsTableName(String entityName, String tableName) {
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -70,8 +70,11 @@
hibernate_mapping.addAttribute("auto-import", "false");
Element class_mapping = hibernate_mapping.addElement(type);
- class_mapping.addAttribute("entity-name", entityName);
+ if (entityName != null) {
+ class_mapping.addAttribute("entity-name", entityName);
+ }
+
if (discriminatorValue != null) {
class_mapping.addAttribute("discriminator-value", discriminatorValue);
}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -59,6 +59,7 @@
private final Configuration cfg;
private final GlobalConfiguration globalCfg;
private final VersionsEntitiesConfiguration verEntCfg;
+ private final Element revisionInfoRelationMapping;
private Map<String, EntityConfiguration> entitiesConfigurations;
@@ -68,10 +69,12 @@
private YLog log = YLogManager.getLogManager().getLog(VersionsMetadataGenerator.class);
public VersionsMetadataGenerator(Configuration cfg, GlobalConfiguration globalCfg,
- VersionsEntitiesConfiguration verEntCfg) {
+ VersionsEntitiesConfiguration verEntCfg,
+ Element revisionInfoRelationMapping) {
this.cfg = cfg;
this.globalCfg = globalCfg;
this.verEntCfg = verEntCfg;
+ this.revisionInfoRelationMapping = revisionInfoRelationMapping;
entitiesConfigurations = new HashMap<String, EntityConfiguration>();
entitiesJoins = new HashMap<String, Map<Join, Element>>();
@@ -91,13 +94,11 @@
}
private void addRevisionInfoRelation(Element any_mapping) {
- Element rev_mapping = /*MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionPropName(),
- verEntCfg.getRevisionPropType(), true); */
- any_mapping.addElement("key-many-to-one");
+ Element rev_mapping = (Element) revisionInfoRelationMapping.clone();
rev_mapping.addAttribute("name", verEntCfg.getRevisionPropName());
- rev_mapping.addAttribute("type", verEntCfg.getRevisionPropType());
- rev_mapping.addAttribute("entity-name", verEntCfg.getRevisionInfoEntityName());
MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionPropName(), null);
+
+ any_mapping.add(rev_mapping);
}
private void addRevisionType(Element any_mapping) {
Modified: trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -63,7 +63,8 @@
if (revisionInfoObject instanceof HibernateProxy) {
return (Number) ((HibernateProxy) revisionInfoObject).getHibernateLazyInitializer().getIdentifier();
} else {
- return (Number) ((Map) revisionInfoObject).get(verEntCfg.getRevisionInfoIdName());
+ // Not a proxy - must be read from cache or with a join
+ return verCfg.getRevisionInfoNumberReader().getRevisionNumber(revisionInfoObject);
}
}
@@ -76,10 +77,8 @@
SELECT e (unless another projection is specified) FROM ent_ver e WHERE
e.revision_type != DEL AND (if selectDeletedEntities == false)
(all specified conditions, transformed, on the "e" entity)
- ORDER BY e.revision ASC (unless another order is specified)
- */
- String revisionPropertyPath = verEntCfg.getRevisionPropPath();
-
+ ORDER BY e.revision ASC (unless another order or projection is specified)
+ */
if (!selectDeletedEntities) {
// e.revision_type != DEL AND
versionsCriteria.add(Property.forName(verEntCfg.getRevisionTypePropName()).ne(RevisionType.DEL));
@@ -91,16 +90,21 @@
}
if (!hasProjection && !hasOrder) {
+ String revisionPropertyPath = verEntCfg.getRevisionPropPath();
versionsCriteria.addOrder(Order.asc(revisionPropertyPath));
}
+ // TODO
+ if (!selectEntitiesOnly) {
+ //versionsCriteria.setFetchMode("e._revision", FetchMode.JOIN);
+ //versionsCriteria.createCriteria("e.originalId._revision").add(Property.forName("revision_id").eq(1));
+ }
+
List<Map> queryResult = versionsCriteria.list();
if (hasProjection) {
return queryResult;
} else {
List entities = new ArrayList();
- String originalId = verEntCfg.getOriginalIdPropName();
- String revisionPropertyName = verEntCfg.getRevisionPropName();
String revisionTypePropertyName = verEntCfg.getRevisionTypePropName();
for (Map versionsEntity : queryResult) {
Deleted: trunk/src/main/org/jboss/envers/revisioninfo/AbstractRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/AbstractRevisionInfoGenerator.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/main/org/jboss/envers/revisioninfo/AbstractRevisionInfoGenerator.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -1,22 +0,0 @@
-package org.jboss.envers.revisioninfo;
-
-import org.hibernate.Session;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public abstract class AbstractRevisionInfoGenerator implements RevisionInfoGenerator {
- private final String revisionInfoEntityName;
-
- protected AbstractRevisionInfoGenerator(String revisionInfoEntityName) {
- this.revisionInfoEntityName = revisionInfoEntityName;
- }
-
- protected abstract Object newRevision();
-
- public Object generate(Session session) {
- Object revisionData = newRevision();
- session.save(revisionInfoEntityName, revisionData);
- return revisionData;
- }
-}
Deleted: trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -1,77 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * 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, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.revisioninfo;
-
-import org.jboss.envers.RevisionListener;
-import org.jboss.envers.tools.reflection.ReflectionTools;
-import org.hibernate.MappingException;
-import org.hibernate.property.Setter;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class CustomRevisionInfoGenerator extends AbstractRevisionInfoGenerator implements RevisionInfoGenerator {
- private final RevisionListener listener;
- private final Setter revisionTimestampSetter;
- private final Class<?> entityClass;
-
- public CustomRevisionInfoGenerator(String revisionInfoEntityName, Class<?> entityClass,
- Class<? extends RevisionListener> listenerClass,
- String revisionInfoTimestampName) {
- super(revisionInfoEntityName);
-
- this.entityClass = entityClass;
-
- revisionTimestampSetter = ReflectionTools.getSetter(entityClass, revisionInfoTimestampName);
-
- if (!listenerClass.equals(RevisionListener.class)) {
- // This is not the default value.
- try {
- listener = listenerClass.newInstance();
- } catch (InstantiationException e) {
- throw new MappingException(e);
- } catch (IllegalAccessException e) {
- throw new MappingException(e);
- }
- } else {
- // Default listener - none
- listener = null;
- }
- }
-
- public Object newRevision() {
- Object entity;
- try {
- entity = entityClass.newInstance();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- revisionTimestampSetter.set(entity, System.currentTimeMillis(), null);
-
- if (listener != null) {
- listener.newRevision(entity);
- }
-
- return entity;
- }
-}
Deleted: trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -1,45 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * 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, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.revisioninfo;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class DefaultRevisionInfoGenerator extends AbstractRevisionInfoGenerator implements RevisionInfoGenerator {
- private final String revisionInfoTimestampName;
-
- public DefaultRevisionInfoGenerator(String revisionInfoEntityName, String revisionInfoTimestampName) {
- super(revisionInfoEntityName);
-
- this.revisionInfoTimestampName = revisionInfoTimestampName;
- }
-
- public Object newRevision() {
- Map<String, Object> revisionInfo = new HashMap<String, Object>();
- revisionInfo.put(revisionInfoTimestampName, System.currentTimeMillis());
-
- return revisionInfo;
- }
-}
Copied: trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java (from rev 135, trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java)
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -0,0 +1,84 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.revisioninfo;
+
+import org.jboss.envers.RevisionListener;
+import org.jboss.envers.tools.reflection.ReflectionTools;
+import org.hibernate.MappingException;
+import org.hibernate.Session;
+import org.hibernate.property.Setter;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class DefaultRevisionInfoGenerator implements RevisionInfoGenerator {
+ private final String revisionInfoEntityName;
+ private final RevisionListener listener;
+ private final Setter revisionTimestampSetter;
+ private final Class<?> revisionInfoClass;
+
+ public DefaultRevisionInfoGenerator(String revisionInfoEntityName, Class<?> revisionInfoClass,
+ Class<? extends RevisionListener> listenerClass,
+ String revisionInfoTimestampName) {
+ this.revisionInfoEntityName = revisionInfoEntityName;
+ this.revisionInfoClass = revisionInfoClass;
+
+ revisionTimestampSetter = ReflectionTools.getSetter(revisionInfoClass, revisionInfoTimestampName);
+
+ if (!listenerClass.equals(RevisionListener.class)) {
+ // This is not the default value.
+ try {
+ listener = listenerClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new MappingException(e);
+ } catch (IllegalAccessException e) {
+ throw new MappingException(e);
+ }
+ } else {
+ // Default listener - none
+ listener = null;
+ }
+ }
+
+ private Object newRevision() {
+ Object revisionInfo;
+ try {
+ revisionInfo = revisionInfoClass.newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ revisionTimestampSetter.set(revisionInfo, System.currentTimeMillis(), null);
+
+ if (listener != null) {
+ listener.newRevision(revisionInfo);
+ }
+
+ return revisionInfo;
+ }
+
+ public Object generate(Session session) {
+ Object revisionData = newRevision();
+ session.save(revisionInfoEntityName, revisionData);
+ return revisionData;
+ }
+}
Property changes on: trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoNumberReader.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoNumberReader.java (rev 0)
+++ trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoNumberReader.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -0,0 +1,40 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.revisioninfo;
+
+import org.jboss.envers.tools.reflection.ReflectionTools;
+import org.hibernate.property.Getter;
+
+/**
+ * Gets a revision number from a persisted revision info entity.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class RevisionInfoNumberReader {
+ private final Getter revisionIdGetter;
+ public RevisionInfoNumberReader(Class<?> revisionInfoClass, String revisionInfoIdName) {
+ revisionIdGetter = ReflectionTools.getGetter(revisionInfoClass, revisionInfoIdName);
+ }
+
+ public Number getRevisionNumber(Object revision) {
+ return (Number) revisionIdGetter.get(revision);
+ }
+}
Deleted: trunk/src/main/org/jboss/envers/revisioninfo/RevisionNumberGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/RevisionNumberGenerator.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/main/org/jboss/envers/revisioninfo/RevisionNumberGenerator.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -1,20 +0,0 @@
-package org.jboss.envers.revisioninfo;
-
-import org.hibernate.Session;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class RevisionNumberGenerator {
- private final String revisionInfoEntityName;
- private final RevisionInfoGenerator revisionInfoGenerator;
-
- public RevisionNumberGenerator(String revisionInfoEntityName, RevisionInfoGenerator revisionInfoGenerator) {
- this.revisionInfoEntityName = revisionInfoEntityName;
- this.revisionInfoGenerator = revisionInfoGenerator;
- }
-
- public Number generate(Session session) {
- return (Number) session.save(revisionInfoEntityName, revisionInfoGenerator.newRevision());
- }
-}
Modified: trunk/src/test/org/jboss/envers/test/working/WorkingEntity1.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/working/WorkingEntity1.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/test/org/jboss/envers/test/working/WorkingEntity1.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -3,6 +3,7 @@
import org.jboss.envers.Versioned;
import org.jboss.envers.SecondaryVersionsTable;
import org.jboss.envers.SecondaryVersionsTables;
+import org.hibernate.annotations.CollectionOfElements;
import javax.persistence.*;
import java.util.Set;
@@ -33,10 +34,16 @@
@Transient
private WorkingEntity2 we2;
- @ManyToMany(mappedBy="we1s")
- @Versioned
+ //@ManyToMany(mappedBy="we1s")
+ //@Versioned
+ @Transient
private Set<WorkingEntity2> we2s;
+ //@CollectionOfElements
+ //@Versioned
+ @Transient
+ private Set<String> strs;
+
public WorkingEntity1() {
}
@@ -94,6 +101,14 @@
this.we2s = we2s;
}
+ public Set<String> getStrs() {
+ return strs;
+ }
+
+ public void setStrs(Set<String> strs) {
+ this.strs = strs;
+ }
+
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof WorkingEntity1)) return false;
Modified: trunk/src/test/org/jboss/envers/test/working/WorkingEntity2.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/working/WorkingEntity2.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/test/org/jboss/envers/test/working/WorkingEntity2.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -21,10 +21,10 @@
@Column
private String str2;
- @Versioned
- //@OneToMany //(mappedBy="we2")
- @ManyToMany
- //@Transient
+ //@Versioned
+ @OneToMany //(mappedBy="we2")
+ //@ManyToMany
+ @JoinColumn(name = "ID_2")
private Set<WorkingEntity1> we1s;
//@Versioned
Modified: trunk/src/test/org/jboss/envers/test/working/WorkingMain.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/working/WorkingMain.java 2008-08-30 14:41:47 UTC (rev 135)
+++ trunk/src/test/org/jboss/envers/test/working/WorkingMain.java 2008-08-31 08:46:36 UTC (rev 136)
@@ -49,7 +49,7 @@
Ejb3Configuration cfg = new Ejb3Configuration();
cfg.configure("hibernate.test.cfg.xml");
cfg.addAnnotatedClass(WorkingEntity1.class);
- cfg.addAnnotatedClass(WorkingEntity2.class);
+ //cfg.addAnnotatedClass(WorkingEntity2.class);
//cfg.addAnnotatedClass(RevEntity.class);
//cfg.addAnnotatedClass(PostalAddress.class);
//cfg.addAnnotatedClass(ContactMech.class);
@@ -63,30 +63,30 @@
WorkingEntity1 we1 = new WorkingEntity1("b", "c");
entityManager.persist(we1);
- WorkingEntity1 we1_2 = new WorkingEntity1("b2", "c2");
+ /*WorkingEntity1 we1_2 = new WorkingEntity1("b2", "c2");
entityManager.persist(we1_2);
WorkingEntity1 we1_3 = new WorkingEntity1("b3", "c3");
- entityManager.persist(we1_3);
+ entityManager.persist(we1_3);*/
- WorkingEntity2 we2 = new WorkingEntity2("s");
+ /*WorkingEntity2 we2 = new WorkingEntity2("s");
Set<WorkingEntity1> we1s = new HashSet<WorkingEntity1>();
we1s.add(we1_3);
we2.setWe1s(we1s);
- entityManager.persist(we2);
+ entityManager.persist(we2); */
entityManager.getTransaction().commit();
// Rev 2
entityManager.getTransaction().begin();
- we1_3 = entityManager.find(WorkingEntity1.class, we1_3.getId1());
+ /*we1_3 = entityManager.find(WorkingEntity1.class, we1_3.getId1());
WorkingEntity2 we2_1 = new WorkingEntity2("s2");
we1s = new HashSet<WorkingEntity1>();
we1s.add(we1_3);
we2_1.setWe1s(we1s);
- entityManager.persist(we2_1);
+ entityManager.persist(we2_1);*/
entityManager.getTransaction().commit();
@@ -94,11 +94,12 @@
entityManager.getTransaction().begin();
VersionsReader vr = VersionsReaderFactory.get(entityManager);
- System.out.println("1: " + vr.find(WorkingEntity1.class, we1_3.getId1(), 1).getWe2s());
- System.out.println("2: " + vr.find(WorkingEntity1.class, we1_3.getId1(), 2).getWe2s());
+ System.out.println("Revisions: ");
+ List results = vr.createQuery().forRevisionsOfEntity(WorkingEntity1.class, false, true).getResultList();
+ for (Object result : results) {
+ System.out.println(Arrays.toString((Object[]) result));
+ }
- System.out.println("Revs we1_3: " + vr.getRevisions(WorkingEntity1.class, we1_3.getId1()));
-
entityManager.getTransaction().commit();
}
}
16 years, 2 months
JBoss Envers SVN: r135 - in trunk/src: main/org/jboss/envers/configuration/metadata and 5 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-30 10:41:47 -0400 (Sat, 30 Aug 2008)
New Revision: 135
Added:
trunk/src/main/org/jboss/envers/revisioninfo/AbstractRevisionInfoGenerator.java
Modified:
trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java
trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java
trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/VersionsWorkUnit.java
trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
Log:
ENVERS-4: revision id as a foreign constraint
Modified: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -88,6 +88,8 @@
if (pcDatas.size() > 0) {
try {
if (revisionInfoXmlMapping != null) {
+ // TODO
+ //writeDocument(revisionInfoXmlMapping);
cfg.addDocument(writer.write(revisionInfoXmlMapping));
}
} catch (DocumentException e) {
Modified: trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -151,7 +151,7 @@
revisionInfoEntityName = pc.getEntityName();
- revisionInfoGenerator = new CustomRevisionInfoGenerator(pc.getMappedClass(),
+ revisionInfoGenerator = new CustomRevisionInfoGenerator(revisionInfoEntityName, pc.getMappedClass(),
revisionEntity.value(), revisionInfoTimestampName);
}
}
@@ -160,34 +160,38 @@
Document revisionInfoXmlMapping = null;
if (revisionInfoGenerator == null) {
- revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoTimestampName);
+ revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoTimestampName);
revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping();
}
return new RevisionInfoConfigurationResult(
- new RevisionNumberGenerator(revisionInfoEntityName, revisionInfoGenerator),
- revisionPropType,
- revisionInfoXmlMapping,
- new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdName, revisionInfoTimestampName));
+ revisionInfoGenerator, revisionPropType, revisionInfoXmlMapping,
+ new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdName, revisionInfoTimestampName),
+ revisionInfoEntityName, revisionInfoIdName);
}
}
class RevisionInfoConfigurationResult {
- private final RevisionNumberGenerator revisionNumberGenerator;
+ private final RevisionInfoGenerator revisionInfoGenerator;
private final String revisionPropType;
private final Document revisionInfoXmlMapping;
private final RevisionInfoQueryCreator revisionInfoQueryCreator;
+ private final String revisionInfoEntityName;
+ private final String revisionInfoIdName;
- RevisionInfoConfigurationResult(RevisionNumberGenerator revisionNumberGenerator, String revisionPropType,
- Document revisionInfoXmlMapping, RevisionInfoQueryCreator revisionInfoQueryCreator) {
- this.revisionNumberGenerator = revisionNumberGenerator;
+ RevisionInfoConfigurationResult(RevisionInfoGenerator revisionInfoGenerator, String revisionPropType,
+ Document revisionInfoXmlMapping, RevisionInfoQueryCreator revisionInfoQueryCreator,
+ String revisionInfoEntityName, String revisionInfoIdName) {
+ this.revisionInfoGenerator = revisionInfoGenerator;
this.revisionPropType = revisionPropType;
this.revisionInfoXmlMapping = revisionInfoXmlMapping;
this.revisionInfoQueryCreator = revisionInfoQueryCreator;
+ this.revisionInfoEntityName = revisionInfoEntityName;
+ this.revisionInfoIdName = revisionInfoIdName;
}
- public RevisionNumberGenerator getRevisionNumberGenerator() {
- return revisionNumberGenerator;
+ public RevisionInfoGenerator getRevisionInfoGenerator() {
+ return revisionInfoGenerator;
}
public String getRevisionPropType() {
@@ -201,4 +205,12 @@
public RevisionInfoQueryCreator getRevisionInfoQueryCreator() {
return revisionInfoQueryCreator;
}
+
+ public String getRevisionInfoEntityName() {
+ return revisionInfoEntityName;
+ }
+
+ public String getRevisionInfoIdName() {
+ return revisionInfoIdName;
+ }
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -66,9 +66,10 @@
YReflectionManager reflectionManager = YReflectionManager.get(cfg);
RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration();
RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg, reflectionManager);
- verEntCfg = new VersionsEntitiesConfiguration(properties, revInfoCfgResult.getRevisionPropType());
+ verEntCfg = new VersionsEntitiesConfiguration(properties, revInfoCfgResult.getRevisionPropType(),
+ revInfoCfgResult.getRevisionInfoEntityName(), revInfoCfgResult.getRevisionInfoIdName());
globalCfg = new GlobalConfiguration(properties);
- versionsSyncManager = new VersionsSyncManager(revInfoCfgResult.getRevisionNumberGenerator());
+ versionsSyncManager = new VersionsSyncManager(revInfoCfgResult.getRevisionInfoGenerator());
revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
entCfg = new EntitiesConfigurator().configure(cfg, reflectionManager, globalCfg, verEntCfg,
revInfoCfgResult.getRevisionInfoXmlMapping());
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -40,9 +40,16 @@
private final String revisionTypePropName;
private final String revisionTypePropType;
+ private final String revisionInfoEntityName;
+ private final String revisionInfoIdName;
+
private final Map<String, String> customVersionsTablesNames;
- public VersionsEntitiesConfiguration(Properties properties, String revisionPropType) {
+ public VersionsEntitiesConfiguration(Properties properties, String revisionPropType, String revisionInfoEntityName,
+ String revisionInfoIdName) {
+ this.revisionInfoEntityName = revisionInfoEntityName;
+ this.revisionInfoIdName = revisionInfoIdName;
+
versionsTablePrefix = properties.getProperty("org.jboss.envers.versionsTablePrefix", "");
versionsTableSuffix = properties.getProperty("org.jboss.envers.versionsTableSuffix", "_versions");
@@ -56,17 +63,9 @@
customVersionsTablesNames = new HashMap<String, String>();
- revisionPropPath = originalIdPropName + "." + revisionPropName;
+ revisionPropPath = originalIdPropName + "." + revisionPropName + ".id";
}
- public String getVersionsTablePrefix() {
- return versionsTablePrefix;
- }
-
- public String getVersionsTableSuffix() {
- return versionsTableSuffix;
- }
-
public String getOriginalIdPropName() {
return originalIdPropName;
}
@@ -91,6 +90,14 @@
return revisionTypePropType;
}
+ public String getRevisionInfoEntityName() {
+ return revisionInfoEntityName;
+ }
+
+ public String getRevisionInfoIdName() {
+ return revisionInfoIdName;
+ }
+
//
public void addCustomVersionsTableName(String entityName, String tableName) {
@@ -100,7 +107,7 @@
//
public String getVersionsEntityName(String entityName) {
- return getVersionsTablePrefix() + entityName + getVersionsTableSuffix();
+ return versionsTablePrefix + entityName + versionsTableSuffix;
}
public boolean isVersionsEntityName(String entityName) {
@@ -108,14 +115,14 @@
return false;
}
- return entityName.endsWith(getVersionsTableSuffix()) &&
- entityName.startsWith(getVersionsTablePrefix());
+ return entityName.endsWith(versionsTableSuffix) &&
+ entityName.startsWith(versionsTablePrefix);
}
public String getVersionsTableName(String entityName, String tableName) {
String customHistoryTableName = customVersionsTablesNames.get(entityName);
if (customHistoryTableName == null) {
- return getVersionsTablePrefix() + tableName + getVersionsTableSuffix();
+ return versionsTablePrefix + tableName + versionsTableSuffix;
}
return customHistoryTableName;
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -90,9 +90,13 @@
}
}
- private void addRevisionNumber(Element any_mapping) {
- Element rev_mapping = MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionPropName(),
- verEntCfg.getRevisionPropType(), true);
+ private void addRevisionInfoRelation(Element any_mapping) {
+ Element rev_mapping = /*MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionPropName(),
+ verEntCfg.getRevisionPropType(), true); */
+ any_mapping.addElement("key-many-to-one");
+ rev_mapping.addAttribute("name", verEntCfg.getRevisionPropName());
+ rev_mapping.addAttribute("type", verEntCfg.getRevisionPropType());
+ rev_mapping.addAttribute("entity-name", verEntCfg.getRevisionInfoEntityName());
MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionPropName(), null);
}
@@ -377,7 +381,7 @@
middleEntityId.add((Element) idProperty.clone());
}
- addRevisionNumber(middleEntityId);
+ addRevisionInfoRelation(middleEntityId);
addRevisionType(middleEntity);
entitiesConfigurations.get(entityName).addOneToManyDetachedRelation(property.getName(), referencedEntityName);
@@ -661,8 +665,8 @@
orig_id_mapping.addAttribute("name", verEntCfg.getOriginalIdPropName());
- // Adding the "revision number" property
- addRevisionNumber(orig_id_mapping);
+ // Adding a relation to the revision entity (effectively: the "revision number" property)
+ addRevisionInfoRelation(orig_id_mapping);
return new IdMappingData(mapper, orig_id_mapping, rel_id_mapping);
}
Modified: trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -29,6 +29,7 @@
import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Property;
+import org.hibernate.proxy.HibernateProxy;
import java.util.List;
import java.util.ArrayList;
@@ -51,6 +52,21 @@
this.selectDeletedEntities = selectDeletedEntities;
}
+ private Number getRevisionNumber(Map versionsEntity) {
+ VersionsEntitiesConfiguration verEntCfg = verCfg.getVerEntCfg();
+
+ String originalId = verEntCfg.getOriginalIdPropName();
+ String revisionPropertyName = verEntCfg.getRevisionPropName();
+
+ Object revisionInfoObject = ((Map) versionsEntity.get(originalId)).get(revisionPropertyName);
+
+ if (revisionInfoObject instanceof HibernateProxy) {
+ return (Number) ((HibernateProxy) revisionInfoObject).getHibernateLazyInitializer().getIdentifier();
+ } else {
+ return (Number) ((Map) revisionInfoObject).get(verEntCfg.getRevisionInfoIdName());
+ }
+ }
+
@SuppressWarnings({"unchecked"})
public List list() throws VersionsException {
VersionsEntitiesConfiguration verEntCfg = verCfg.getVerEntCfg();
@@ -88,7 +104,7 @@
String revisionTypePropertyName = verEntCfg.getRevisionTypePropName();
for (Map versionsEntity : queryResult) {
- Number revision = (Number) ((Map) versionsEntity.get(originalId)).get(revisionPropertyName);
+ Number revision = getRevisionNumber(versionsEntity);
Object entity = entityInstantiator.createInstanceFromVersionsEntity(entityName, versionsEntity, revision);
Added: trunk/src/main/org/jboss/envers/revisioninfo/AbstractRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/AbstractRevisionInfoGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/revisioninfo/AbstractRevisionInfoGenerator.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -0,0 +1,22 @@
+package org.jboss.envers.revisioninfo;
+
+import org.hibernate.Session;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public abstract class AbstractRevisionInfoGenerator implements RevisionInfoGenerator {
+ private final String revisionInfoEntityName;
+
+ protected AbstractRevisionInfoGenerator(String revisionInfoEntityName) {
+ this.revisionInfoEntityName = revisionInfoEntityName;
+ }
+
+ protected abstract Object newRevision();
+
+ public Object generate(Session session) {
+ Object revisionData = newRevision();
+ session.save(revisionInfoEntityName, revisionData);
+ return revisionData;
+ }
+}
Modified: trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -29,14 +29,16 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class CustomRevisionInfoGenerator implements RevisionInfoGenerator {
+public class CustomRevisionInfoGenerator extends AbstractRevisionInfoGenerator implements RevisionInfoGenerator {
private final RevisionListener listener;
private final Setter revisionTimestampSetter;
private final Class<?> entityClass;
- public CustomRevisionInfoGenerator(Class<?> entityClass,
+ public CustomRevisionInfoGenerator(String revisionInfoEntityName, Class<?> entityClass,
Class<? extends RevisionListener> listenerClass,
String revisionInfoTimestampName) {
+ super(revisionInfoEntityName);
+
this.entityClass = entityClass;
revisionTimestampSetter = ReflectionTools.getSetter(entityClass, revisionInfoTimestampName);
Modified: trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -27,10 +27,12 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class DefaultRevisionInfoGenerator implements RevisionInfoGenerator {
+public class DefaultRevisionInfoGenerator extends AbstractRevisionInfoGenerator implements RevisionInfoGenerator {
private final String revisionInfoTimestampName;
- public DefaultRevisionInfoGenerator(String revisionInfoTimestampName) {
+ public DefaultRevisionInfoGenerator(String revisionInfoEntityName, String revisionInfoTimestampName) {
+ super(revisionInfoEntityName);
+
this.revisionInfoTimestampName = revisionInfoTimestampName;
}
Modified: trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoGenerator.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoGenerator.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -21,9 +21,11 @@
*/
package org.jboss.envers.revisioninfo;
+import org.hibernate.Session;
+
/**
* @author Adam Warski (adam at warski dot org)
*/
public interface RevisionInfoGenerator {
- public Object newRevision();
+ Object generate(Session session);
}
Modified: trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -27,7 +27,7 @@
import org.hibernate.event.EventSource;
import org.jboss.envers.synchronization.work.VersionsWorkUnit;
import org.jboss.envers.tools.Pair;
-import org.jboss.envers.revisioninfo.RevisionNumberGenerator;
+import org.jboss.envers.revisioninfo.RevisionInfoGenerator;
import javax.transaction.Synchronization;
import java.util.*;
@@ -36,7 +36,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsSync implements Synchronization {
- private final RevisionNumberGenerator revisionNumberGenerator;
+ private final RevisionInfoGenerator revisionInfoGenerator;
private final VersionsSyncManager manager;
private final EventSource session;
@@ -45,12 +45,12 @@
private final Queue<VersionsWorkUnit> undoQueue;
private final Map<Pair<String, Object>, VersionsWorkUnit> usedIds;
- private Number revision;
+ private Object revisionData;
- public VersionsSync(VersionsSyncManager manager, EventSource session, RevisionNumberGenerator revisionNumberGenerator) {
+ public VersionsSync(VersionsSyncManager manager, EventSource session, RevisionInfoGenerator revisionInfoGenerator) {
this.manager = manager;
this.session = session;
- this.revisionNumberGenerator = revisionNumberGenerator;
+ this.revisionInfoGenerator = revisionInfoGenerator;
transaction = session.getTransaction();
workUnits = new LinkedList<VersionsWorkUnit>();
@@ -105,8 +105,8 @@
}
private void executeInSession(Session session) {
- if (revision == null) {
- revision = revisionNumberGenerator.generate(session);
+ if (revisionData == null) {
+ revisionData = revisionInfoGenerator.generate(session);
}
VersionsWorkUnit vwu;
@@ -117,7 +117,7 @@
}
while ((vwu = workUnits.poll()) != null) {
- vwu.perform(session, revision);
+ vwu.perform(session, revisionData);
}
}
@@ -126,8 +126,6 @@
return;
}
- System.out.println("FLUSH MODE: " + session.getFlushMode());
-
if (FlushMode.isManualFlushMode(session.getFlushMode())) {
Session temporarySession = null;
try {
Modified: trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -22,7 +22,7 @@
package org.jboss.envers.synchronization;
import org.jboss.envers.tools.ConcurrentReferenceHashMap;
-import org.jboss.envers.revisioninfo.RevisionNumberGenerator;
+import org.jboss.envers.revisioninfo.RevisionInfoGenerator;
import org.hibernate.Transaction;
import org.hibernate.event.EventSource;
@@ -33,14 +33,14 @@
*/
public class VersionsSyncManager {
private final Map<Transaction, VersionsSync> versionsSyncs;
- private final RevisionNumberGenerator revisionNumberGenerator;
+ private final RevisionInfoGenerator revisionInfoGenerator;
- public VersionsSyncManager(RevisionNumberGenerator revisionNumberGenerator) {
+ public VersionsSyncManager(RevisionInfoGenerator revisionInfoGenerator) {
versionsSyncs = new ConcurrentReferenceHashMap<Transaction, VersionsSync>(10,
ConcurrentReferenceHashMap.ReferenceType.WEAK,
ConcurrentReferenceHashMap.ReferenceType.STRONG);
- this.revisionNumberGenerator = revisionNumberGenerator;
+ this.revisionInfoGenerator = revisionInfoGenerator;
}
public VersionsSync get(EventSource session) {
@@ -48,7 +48,7 @@
VersionsSync verSync = versionsSyncs.get(transaction);
if (verSync == null) {
- verSync = new VersionsSync(this, session, revisionNumberGenerator);
+ verSync = new VersionsSync(this, session, revisionInfoGenerator);
versionsSyncs.put(transaction, verSync);
transaction.registerSynchronization(verSync);
Modified: trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -47,7 +47,7 @@
this.entityName = entityName;
}
- protected void fillDataWithId(Map<String, Object> data, Number revision, RevisionType revisionType) {
+ protected void fillDataWithId(Map<String, Object> data, Object revision, RevisionType revisionType) {
VersionsEntitiesConfiguration entitiesCfg = verCfg.getVerEntCfg();
Map<String, Object> originalId = new HashMap<String, Object>();
Modified: trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -49,9 +49,9 @@
return true;
}
- public void perform(Session session, Number revision) {
+ public void perform(Session session, Object revisionData) {
Map<String, Object> data = new HashMap<String, Object>();
- fillDataWithId(data, revision, RevisionType.ADD);
+ fillDataWithId(data, revisionData, RevisionType.ADD);
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().map(data, propertyNames, state, null);
Modified: trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -45,9 +45,9 @@
return true;
}
- public void perform(Session session, Number revision) {
+ public void perform(Session session, Object revisionData) {
Map<String, Object> data = new HashMap<String, Object>();
- fillDataWithId(data, revision, RevisionType.MOD);
+ fillDataWithId(data, revisionData, RevisionType.MOD);
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().mapToMapFromEntity(data, entity, null);
Modified: trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -41,9 +41,9 @@
return true;
}
- public void perform(Session session, Number revision) {
+ public void perform(Session session, Object revisionData) {
Map<String, Object> data = new HashMap<String, Object>();
- fillDataWithId(data, revision, RevisionType.DEL);
+ fillDataWithId(data, revisionData, RevisionType.DEL);
session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()), data);
Modified: trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -50,8 +50,8 @@
return changes;
}
- public void perform(Session session, Number revision) {
- fillDataWithId(data, revision, RevisionType.MOD);
+ public void perform(Session session, Object revisionData) {
+ fillDataWithId(data, revisionData, RevisionType.MOD);
session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()), data);
Modified: trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -33,13 +33,13 @@
}
@SuppressWarnings({"unchecked"})
- public void perform(Session session, Number revision) {
+ public void perform(Session session, Object revisionData) {
VersionsEntitiesConfiguration entitiesCfg = verCfg.getVerEntCfg();
for (PersistentCollectionChangeData persistentCollectionChangeData : collectionChanges) {
// Setting the revision number
((Map<String, Object>) persistentCollectionChangeData.getData().get(entitiesCfg.getOriginalIdPropName()))
- .put(entitiesCfg.getRevisionPropName(), revision);
+ .put(entitiesCfg.getRevisionPropName(), revisionData);
session.save(persistentCollectionChangeData.getEntityName(), persistentCollectionChangeData.getData());
}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/VersionsWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/VersionsWorkUnit.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/main/org/jboss/envers/synchronization/work/VersionsWorkUnit.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -34,6 +34,6 @@
boolean isPerformed();
- void perform(Session session, Number revision);
+ void perform(Session session, Object revisionData);
void undo(Session session);
}
Modified: trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java 2008-08-30 08:04:19 UTC (rev 134)
+++ trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java 2008-08-30 14:41:47 UTC (rev 135)
@@ -2,10 +2,7 @@
import org.jboss.envers.test.integration.AbstractEntityTest;
import org.jboss.envers.test.entities.StrIntTestEntity;
-import org.jboss.envers.test.tools.TestTools;
import org.jboss.envers.query.VersionsRestrictions;
-import org.jboss.envers.query.RevisionProperty;
-import org.jboss.envers.query.RevisionTypeProperty;
import org.jboss.envers.RevisionType;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.criterion.Projections;
@@ -14,14 +11,11 @@
import javax.persistence.EntityManager;
import java.util.List;
-import java.util.HashSet;
-import java.util.Arrays;
/**
* @author Adam Warski (adam at warski dot org)
*/
public class DeletedEntities extends AbstractEntityTest {
- private Integer id1;
private Integer id2;
public void configure(Ejb3Configuration cfg) {
@@ -40,7 +34,6 @@
em.persist(site1);
em.persist(site2);
- id1 = site1.getId();
id2 = site2.getId();
em.getTransaction().commit();
16 years, 2 months
JBoss Envers SVN: r134 - trunk.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-30 04:04:19 -0400 (Sat, 30 Aug 2008)
New Revision: 134
Modified:
trunk/build.xml
Log:
Small build fix - externalizing the project.version property
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2008-08-30 08:02:08 UTC (rev 133)
+++ trunk/build.xml 2008-08-30 08:04:19 UTC (rev 134)
@@ -7,7 +7,7 @@
<property file="${basedir}/build.properties" />
<property name="project.name" value="envers"/>
- <property name="project.version" value="1.1.0.ga"/>
+ <property name="project.version" value="preview-dev"/>
<property name="hibernate.32.version" value=""/>
<property name="hibernate.33.version" value="-hibernate-3.3"/>
16 years, 2 months
JBoss Envers SVN: r133 - trunk.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-30 04:02:08 -0400 (Sat, 30 Aug 2008)
New Revision: 133
Modified:
trunk/
trunk/build.xml
Log:
Small build fix - externalizing the project.version property
Property changes on: trunk
___________________________________________________________________
Name: svn:ignore
- target
build
dist
doc
+ build.properties
target
build
dist
doc
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2008-08-30 07:58:01 UTC (rev 132)
+++ trunk/build.xml 2008-08-30 08:02:08 UTC (rev 133)
@@ -2,8 +2,12 @@
<project name="versioning" default="build-32" basedir=".">
<!-- Properties -->
+ <!-- Give user a chance to override without editing this file or typing -D -->
+ <!-- project.version should be set in this file -->
+ <property file="${basedir}/build.properties" />
+
<property name="project.name" value="envers"/>
- <property name="project.version" value="1.0.0.ga"/>
+ <property name="project.version" value="1.1.0.ga"/>
<property name="hibernate.32.version" value=""/>
<property name="hibernate.33.version" value="-hibernate-3.3"/>
@@ -136,6 +140,8 @@
<javac classpathref="build.main32.classpath"
destdir="${build.main.dir}"
debug="true"
+ target="1.5"
+ source="1.5"
nowarn="on">
<src path="${src.main.dir}" />
</javac>
@@ -145,6 +151,8 @@
<javac classpathref="build.main32.classpath"
destdir="${build.main.dir}"
debug="true"
+ target="1.5"
+ source="1.5"
nowarn="on">
<src path="${src.main32.dir}" />
</javac>
@@ -154,6 +162,8 @@
<javac classpathref="build.main33.classpath"
destdir="${build.main.dir}"
debug="true"
+ target="1.5"
+ source="1.5"
nowarn="on">
<src path="${src.main33.dir}" />
</javac>
@@ -166,6 +176,8 @@
<javac classpathref="build.test32.classpath"
destdir="${build.test.dir}"
debug="true"
+ target="1.5"
+ source="1.5"
nowarn="on">
<src path="${src.test.dir}" />
</javac>
@@ -182,6 +194,8 @@
<javac classpathref="build.demo.classpath"
destdir="${build.demo.dir}"
debug="true"
+ target="1.5"
+ source="1.5"
nowarn="on">
<src path="${src.demo.dir}" />
</javac>
16 years, 2 months
JBoss Envers SVN: r132 - trunk/src/main/org/jboss/envers/synchronization.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-30 03:58:01 -0400 (Sat, 30 Aug 2008)
New Revision: 132
Modified:
trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java
trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java
Log:
ENVERS-46: manual flush mode exception fix
Modified: trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java 2008-08-25 09:40:59 UTC (rev 131)
+++ trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java 2008-08-30 07:58:01 UTC (rev 132)
@@ -24,6 +24,7 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.FlushMode;
+import org.hibernate.event.EventSource;
import org.jboss.envers.synchronization.work.VersionsWorkUnit;
import org.jboss.envers.tools.Pair;
import org.jboss.envers.revisioninfo.RevisionNumberGenerator;
@@ -37,7 +38,7 @@
public class VersionsSync implements Synchronization {
private final RevisionNumberGenerator revisionNumberGenerator;
private final VersionsSyncManager manager;
- private final Session session;
+ private final EventSource session;
private final Transaction transaction;
private final LinkedList<VersionsWorkUnit> workUnits;
@@ -46,7 +47,7 @@
private Number revision;
- public VersionsSync(VersionsSyncManager manager, Session session, RevisionNumberGenerator revisionNumberGenerator) {
+ public VersionsSync(VersionsSyncManager manager, EventSource session, RevisionNumberGenerator revisionNumberGenerator) {
this.manager = manager;
this.session = session;
this.revisionNumberGenerator = revisionNumberGenerator;
@@ -125,11 +126,14 @@
return;
}
+ System.out.println("FLUSH MODE: " + session.getFlushMode());
+
if (FlushMode.isManualFlushMode(session.getFlushMode())) {
Session temporarySession = null;
try {
//noinspection deprecation
- temporarySession = session.getSessionFactory().openSession(session.connection());
+ //temporarySession = session.getSessionFactory().openSession(session.connection());
+ temporarySession = session.getFactory().openTemporarySession();
executeInSession(temporarySession);
Modified: trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java 2008-08-25 09:40:59 UTC (rev 131)
+++ trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java 2008-08-30 07:58:01 UTC (rev 132)
@@ -23,8 +23,8 @@
import org.jboss.envers.tools.ConcurrentReferenceHashMap;
import org.jboss.envers.revisioninfo.RevisionNumberGenerator;
-import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.event.EventSource;
import java.util.Map;
@@ -43,7 +43,7 @@
this.revisionNumberGenerator = revisionNumberGenerator;
}
- public VersionsSync get(Session session) {
+ public VersionsSync get(EventSource session) {
Transaction transaction = session.getTransaction();
VersionsSync verSync = versionsSyncs.get(transaction);
16 years, 2 months
JBoss Envers SVN: r131 - in trunk/src: test/org/jboss/envers/test/integration/naming and 1 other directory.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-25 05:40:59 -0400 (Mon, 25 Aug 2008)
New Revision: 131
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java
Log:
ENVERS-26: fixing many-to-many relations
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-25 09:32:06 UTC (rev 130)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-25 09:40:59 UTC (rev 131)
@@ -322,6 +322,10 @@
propertyName));
}
+ private String getMiddleEntityName(String entityName, String referencedEntityName, ManyToOne mto) {
+ return entityName + "_" + referencedEntityName + "_" + mto.getTable().getName();
+ }
+
@SuppressWarnings({"unchecked"})
private void addOneToManyDetached(Property property, CompositeMapperBuilder mapper, String entityName,
EntityMappingData mappingData) {
@@ -347,7 +351,7 @@
String referencedPrefix = property.getName() + "_";
// Name of the entity that will be used to store the relation between the two entities.
- String middleEntityName = entityName + "_" + referencedEntityName + "_" + mto.getTable().getName();
+ String middleEntityName = getMiddleEntityName(entityName, referencedEntityName, mto);
String versionsMiddleEntityName = verEntCfg.getVersionsEntityName(middleEntityName);
String versionsMiddleTableName = verEntCfg.getVersionsTableName(middleEntityName, mto.getTable().getName());
@@ -433,7 +437,7 @@
// Name of the entity that will be used to store the relation between the two entities.
// The order is inverse, as the referenced and referencing entity names are swapped with respect to the
// name of the entity that was created on the owning side in <code>addOneToManyDetached</code>.
- String middleEntityName = referencedEntityName + "_" + entityName;
+ String middleEntityName = getMiddleEntityName(referencedEntityName, entityName, mto);
String versionsMiddleEntityName = verEntCfg.getVersionsEntityName(middleEntityName);
entitiesConfigurations.get(entityName).addManyToManyNotOwningRelation(property.getName(), mappedBy,
Modified: trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java 2008-08-25 09:32:06 UTC (rev 130)
+++ trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java 2008-08-25 09:40:59 UTC (rev 131)
@@ -75,19 +75,19 @@
assert "data1".equals(rev2.getData());
}
+ private final static String MIDDLE_VERSIONS_ENTITY_NAME =
+ "org.jboss.envers.test.integration.naming.DetachedNamingTestEntity_org.jboss.envers.test.entities.StrTestEntity_UNI_NAMING_TEST_versions";
@Test
public void testTableName() {
assert "UNI_NAMING_TEST_versions".equals(
- getCfg().getClassMapping("org.jboss.envers.test.integration.naming.DetachedNamingTestEntity_org.jboss.envers.test.entities.StrTestEntity_versions")
- .getTable().getName());
+ getCfg().getClassMapping(MIDDLE_VERSIONS_ENTITY_NAME).getTable().getName());
}
@SuppressWarnings({"unchecked"})
@Test
public void testJoinColumnName() {
Iterator<Column> columns =
- getCfg().getClassMapping("org.jboss.envers.test.integration.naming.DetachedNamingTestEntity_org.jboss.envers.test.entities.StrTestEntity_versions")
- .getTable().getColumnIterator();
+ getCfg().getClassMapping(MIDDLE_VERSIONS_ENTITY_NAME).getTable().getColumnIterator();
boolean id1Found = false;
boolean id2Found = false;
16 years, 2 months
JBoss Envers SVN: r130 - in trunk/src: main/org/jboss/envers/event and 3 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-25 05:32:06 -0400 (Mon, 25 Aug 2008)
New Revision: 130
Added:
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DoubleNotOwnedSet.java
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
Log:
ENVERS-26: support for multiple one-to-many detached relations, with test
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-25 08:53:52 UTC (rev 129)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-25 09:32:06 UTC (rev 130)
@@ -347,7 +347,7 @@
String referencedPrefix = property.getName() + "_";
// Name of the entity that will be used to store the relation between the two entities.
- String middleEntityName = entityName + "_" + referencedEntityName;
+ String middleEntityName = entityName + "_" + referencedEntityName + "_" + mto.getTable().getName();
String versionsMiddleEntityName = verEntCfg.getVersionsEntityName(middleEntityName);
String versionsMiddleTableName = verEntCfg.getVersionsTableName(middleEntityName, mto.getTable().getName());
Modified: trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
===================================================================
--- trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-25 08:53:52 UTC (rev 129)
+++ trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-25 09:32:06 UTC (rev 130)
@@ -133,10 +133,11 @@
// the other side of the relation.
RelationDescription relDesc = verCfg.getEntCfg().getRelationDescription(event.getAffectedOwnerEntityName(),
workUnit.getReferencingPropertyName());
- String relatedEntityName = relDesc.getToEntityName();
- IdMapper relatedIdMapper = verCfg.getEntCfg().get(relatedEntityName).getIdMapper();
if (relDesc.isBidirectional()) {
+ String relatedEntityName = relDesc.getToEntityName();
+ IdMapper relatedIdMapper = verCfg.getEntCfg().get(relatedEntityName).getIdMapper();
+
for (PersistentCollectionChangeData changeData : workUnit.getCollectionChanges()) {
Object relatedObj = changeData.getObj();
Serializable relatedId = (Serializable) relatedIdMapper.mapToIdFromEntity(relatedObj);
Modified: trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-08-25 08:53:52 UTC (rev 129)
+++ trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-08-25 09:32:06 UTC (rev 130)
@@ -29,7 +29,7 @@
}
public boolean containsWork() {
- return collectionChanges == null || collectionChanges.size() != 0;
+ return collectionChanges != null && collectionChanges.size() != 0;
}
@SuppressWarnings({"unchecked"})
Copied: trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java (from rev 124, trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/SetRefCollEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java 2008-08-25 09:32:06 UTC (rev 130)
@@ -0,0 +1,100 @@
+package org.jboss.envers.test.entities.onetomany.detached;
+
+import org.jboss.envers.Versioned;
+import org.jboss.envers.test.entities.StrTestEntity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.JoinTable;
+import java.util.Set;
+
+/**
+ * Set collection of references entity
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class DoubleSetRefCollEntity {
+ @Id
+ private Integer id;
+
+ @Versioned
+ private String data;
+
+ @Versioned
+ @OneToMany
+ @JoinTable(name = "DOUBLE_STR_1")
+ private Set<StrTestEntity> collection;
+
+ @Versioned
+ @OneToMany
+ @JoinTable(name = "DOUBLE_STR_2")
+ private Set<StrTestEntity> collection2;
+
+ public DoubleSetRefCollEntity() {
+ }
+
+ public DoubleSetRefCollEntity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public DoubleSetRefCollEntity(String data) {
+ 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 Set<StrTestEntity> getCollection() {
+ return collection;
+ }
+
+ public void setCollection(Set<StrTestEntity> collection) {
+ this.collection = collection;
+ }
+
+ public Set<StrTestEntity> getCollection2() {
+ return collection2;
+ }
+
+ public void setCollection2(Set<StrTestEntity> collection2) {
+ this.collection2 = collection2;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof DoubleSetRefCollEntity)) return false;
+
+ DoubleSetRefCollEntity that = (DoubleSetRefCollEntity) 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 "DoubleSetRefEdEntity(id = " + id + ", data = " + data + ")";
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/DoubleSetRefCollEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DoubleNotOwnedSet.java (from rev 124, trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSet.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DoubleNotOwnedSet.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DoubleNotOwnedSet.java 2008-08-25 09:32:06 UTC (rev 130)
@@ -0,0 +1,108 @@
+package org.jboss.envers.test.integration.onetomany.detached;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.onetomany.detached.DoubleSetRefCollEntity;
+import org.jboss.envers.test.entities.StrTestEntity;
+import org.jboss.envers.test.tools.TestTools;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class DoubleNotOwnedSet extends AbstractEntityTest {
+ private Integer str1_id;
+ private Integer str2_id;
+
+ private Integer coll1_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(StrTestEntity.class);
+ cfg.addAnnotatedClass(DoubleSetRefCollEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ StrTestEntity str1 = new StrTestEntity("str1");
+ StrTestEntity str2 = new StrTestEntity("str2");
+
+ DoubleSetRefCollEntity coll1 = new DoubleSetRefCollEntity(3, "coll1");
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ em.persist(str1);
+ em.persist(str2);
+
+ coll1.setCollection(new HashSet<StrTestEntity>());
+ coll1.getCollection().add(str1);
+ em.persist(coll1);
+
+ coll1.setCollection2(new HashSet<StrTestEntity>());
+ coll1.getCollection2().add(str2);
+ em.persist(coll1);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ str2 = em.find(StrTestEntity.class, str2.getId());
+ coll1 = em.find(DoubleSetRefCollEntity.class, coll1.getId());
+
+ coll1.getCollection().add(str2);
+
+ em.getTransaction().commit();
+
+ // Revision 3
+ em.getTransaction().begin();
+
+ str1 = em.find(StrTestEntity.class, str1.getId());
+ coll1 = em.find(DoubleSetRefCollEntity.class, coll1.getId());
+
+ coll1.getCollection().remove(str1);
+ coll1.getCollection2().add(str1);
+
+ em.getTransaction().commit();
+
+ //
+
+ str1_id = str1.getId();
+ str2_id = str2.getId();
+
+ coll1_id = coll1.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 3).equals(getVersionsReader().getRevisions(DoubleSetRefCollEntity.class, coll1_id));
+
+ assert Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str1_id));
+ assert Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str2_id));
+ }
+
+ @Test
+ public void testHistoryOfColl1() {
+ StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
+ StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
+
+ DoubleSetRefCollEntity rev1 = getVersionsReader().find(DoubleSetRefCollEntity.class, coll1_id, 1);
+ DoubleSetRefCollEntity rev2 = getVersionsReader().find(DoubleSetRefCollEntity.class, coll1_id, 2);
+ DoubleSetRefCollEntity rev3 = getVersionsReader().find(DoubleSetRefCollEntity.class, coll1_id, 3);
+
+ assert rev1.getCollection().equals(TestTools.makeSet(str1));
+ assert rev2.getCollection().equals(TestTools.makeSet(str1, str2));
+ assert rev3.getCollection().equals(TestTools.makeSet(str2));
+
+ assert rev1.getCollection2().equals(TestTools.makeSet(str2));
+ assert rev2.getCollection2().equals(TestTools.makeSet(str2));
+ assert rev3.getCollection2().equals(TestTools.makeSet(str1, str2));
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DoubleNotOwnedSet.java
___________________________________________________________________
Name: svn:mergeinfo
+
16 years, 2 months
JBoss Envers SVN: r129 - in trunk: src/test/org/jboss/envers/test/integration/inheritance/single/childrelation and 1 other directory.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-25 04:53:52 -0400 (Mon, 25 Aug 2008)
New Revision: 129
Modified:
trunk/lib/hibernate-3.3.0/hibernate-annotations.jar
trunk/lib/hibernate-3.3.0/hibernate-commons-annotations.jar
trunk/lib/hibernate-3.3.0/hibernate-entitymanager.jar
trunk/lib/hibernate-3.3.0/hibernate3.jar
trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java
Log:
ENVERS-38: hibernate core 3.3.0.SP1, entity manager and annotations 3.4.0
Modified: trunk/lib/hibernate-3.3.0/hibernate-annotations.jar
===================================================================
(Binary files differ)
Modified: trunk/lib/hibernate-3.3.0/hibernate-commons-annotations.jar
===================================================================
(Binary files differ)
Modified: trunk/lib/hibernate-3.3.0/hibernate-entitymanager.jar
===================================================================
(Binary files differ)
Modified: trunk/lib/hibernate-3.3.0/hibernate3.jar
===================================================================
(Binary files differ)
Modified: trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java 2008-08-25 07:25:19 UTC (rev 128)
+++ trunk/src/test/org/jboss/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java 2008-08-25 08:53:52 UTC (rev 129)
@@ -58,7 +58,6 @@
re2 = em.find(ReferencedEntity.class, re_id2);
cie = em.find(ChildIngEntity.class, c_id);
- System.out.println(re2.getId());
cie.setReferenced(re2);
em.getTransaction().commit();
16 years, 2 months
JBoss Envers SVN: r128 - in trunk/src: main/org/jboss/envers/configuration/metadata and 1 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-25 03:25:19 -0400 (Mon, 25 Aug 2008)
New Revision: 128
Added:
trunk/src/test/org/jboss/envers/test/integration/properties/UnversionedOptimisticLockingField.java
trunk/src/test/org/jboss/envers/test/integration/properties/UnversionedOptimisticLockingFieldEntity.java
Modified:
trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
Log:
ENVERS-31: applying patch contributed by Nicolas DC
Modified: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-08-25 07:10:44 UTC (rev 127)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-08-25 07:25:19 UTC (rev 128)
@@ -47,7 +47,7 @@
PersistentClass pc = classes.next();
// Collecting information from annotations on the persistent class pc
PersistentClassVersioningData versioningData =
- annotationsMetadataReader.getVersioningData(pc, reflectionManager);
+ annotationsMetadataReader.getVersioningData(pc, reflectionManager, globalCfg);
if (versioningData.isVersioned()) {
pcDatas.put(pc, versioningData);
Modified: trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java 2008-08-25 07:10:44 UTC (rev 127)
+++ trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java 2008-08-25 07:25:19 UTC (rev 128)
@@ -4,6 +4,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Nicolas Doroskevich
*/
public class GlobalConfiguration {
// Should a revision be generated when a not-owned relation field changes
@@ -11,6 +12,9 @@
// Should a warning, instead of an error and an exception, be logged, when an unsupported type is versioned
private final boolean warnOnUnsupportedTypes;
+
+ // Should the optimistic locking property of an entity be considered unversioned
+ private final boolean unversionedOptimisticLockingField;
public GlobalConfiguration(Properties properties) {
String generateRevisionsForCollectionsStr = properties.getProperty("org.jboss.envers.revisionOnCollectionChange",
@@ -20,6 +24,10 @@
String warnOnUnsupportedTypesStr = properties.getProperty("org.jboss.envers.warnOnUnsupportedTypes",
"false");
warnOnUnsupportedTypes = Boolean.parseBoolean(warnOnUnsupportedTypesStr);
+
+ String ignoreOptimisticLockingPropertyStr = properties.getProperty("org.jboss.envers.unversionedOptimisticLockingField",
+ "false");
+ unversionedOptimisticLockingField = Boolean.parseBoolean(ignoreOptimisticLockingPropertyStr);
}
public boolean isGenerateRevisionsForCollections() {
@@ -29,4 +37,9 @@
public boolean isWarnOnUnsupportedTypes() {
return warnOnUnsupportedTypes;
}
+
+ public boolean isUnversionedOptimisticLockingField() {
+ return unversionedOptimisticLockingField;
+ }
+
}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-08-25 07:10:44 UTC (rev 127)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-08-25 07:25:19 UTC (rev 128)
@@ -21,6 +21,9 @@
*/
package org.jboss.envers.configuration.metadata;
+import javax.persistence.Version;
+
+import org.jboss.envers.configuration.GlobalConfiguration;
import org.jboss.envers.tools.reflection.YClass;
import org.jboss.envers.tools.reflection.YProperty;
import org.jboss.envers.tools.reflection.YReflectionManager;
@@ -34,7 +37,8 @@
* @author Sebastian Komander
*/
public class AnnotationsMetadataReader {
- private void addFromProperties(Iterable<YProperty> properties, PersistentClassVersioningData versioningData) {
+ private void addFromProperties(Iterable<YProperty> properties, PersistentClassVersioningData versioningData,
+ GlobalConfiguration globalCfg) {
for (YProperty property : properties) {
Versioned ver = property.getAnnotation(Versioned.class);
if (ver != null) {
@@ -46,21 +50,32 @@
Unversioned unVer = property.getAnnotation(Unversioned.class);
if (unVer != null) {
versioningData.unversionedProperties.add(property.getName());
+ } else {
+ // if the optimistic locking field has to be unversioned and the current property
+ // is the optimistic locking field, add it to the unversioned properties list
+ if (globalCfg.isUnversionedOptimisticLockingField()) {
+ Version jpaVer = property.getAnnotation(Version.class);
+ if (jpaVer != null) {
+ versioningData.unversionedProperties.add(property.getName());
+ }
+ }
}
}
}
- private void addPropertiesFromClass(YClass clazz, PersistentClassVersioningData versioningData) {
+ private void addPropertiesFromClass(YClass clazz, PersistentClassVersioningData versioningData,
+ GlobalConfiguration globalCfg) {
YClass superclazz = clazz.getSuperclass();
if (!"java.lang.Object".equals(superclazz.getName())) {
- addPropertiesFromClass(superclazz, versioningData);
+ addPropertiesFromClass(superclazz, versioningData, globalCfg);
}
- addFromProperties(clazz.getDeclaredProperties("field"), versioningData);
- addFromProperties(clazz.getDeclaredProperties("property"), versioningData);
+ addFromProperties(clazz.getDeclaredProperties("field"), versioningData, globalCfg);
+ addFromProperties(clazz.getDeclaredProperties("property"), versioningData, globalCfg);
}
- public PersistentClassVersioningData getVersioningData(PersistentClass pc, YReflectionManager reflectionManager) {
+ public PersistentClassVersioningData getVersioningData(PersistentClass pc, YReflectionManager reflectionManager,
+ GlobalConfiguration globalCfg) {
PersistentClassVersioningData versioningData = new PersistentClassVersioningData();
if (pc.getClassName() == null) {
@@ -75,7 +90,7 @@
versioningData.propertyStoreInfo.defaultStore = defaultVersioned.modStore();
}
- addPropertiesFromClass(clazz, versioningData);
+ addPropertiesFromClass(clazz, versioningData, globalCfg);
VersionsTable versionsTable = clazz.getAnnotation(VersionsTable.class);
if (versionsTable != null) {
Added: trunk/src/test/org/jboss/envers/test/integration/properties/UnversionedOptimisticLockingField.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/properties/UnversionedOptimisticLockingField.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/properties/UnversionedOptimisticLockingField.java 2008-08-25 07:25:19 UTC (rev 128)
@@ -0,0 +1,70 @@
+package org.jboss.envers.test.integration.properties;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Nicolas Doroskevich
+ */
+public class UnversionedOptimisticLockingField extends AbstractEntityTest {
+ private Integer id1;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(UnversionedOptimisticLockingFieldEntity.class);
+
+ cfg.setProperty("org.jboss.envers.unversionedOptimisticLockingField", "true");
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+ em.getTransaction().begin();
+ UnversionedOptimisticLockingFieldEntity olfe = new UnversionedOptimisticLockingFieldEntity("x");
+ em.persist(olfe);
+ id1 = olfe.getId();
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ olfe = em.find(UnversionedOptimisticLockingFieldEntity.class, id1);
+ olfe.setStr("y");
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionCounts() {
+ assert Arrays.asList(1, 2).equals(
+ getVersionsReader().getRevisions(UnversionedOptimisticLockingFieldEntity.class,
+ id1));
+ }
+
+ @Test
+ public void testHistoryOfId1() {
+ UnversionedOptimisticLockingFieldEntity ver1 = new UnversionedOptimisticLockingFieldEntity(id1, "x");
+ UnversionedOptimisticLockingFieldEntity ver2 = new UnversionedOptimisticLockingFieldEntity(id1, "y");
+
+ assert getVersionsReader().find(UnversionedOptimisticLockingFieldEntity.class, id1, 1)
+ .equals(ver1);
+ assert getVersionsReader().find(UnversionedOptimisticLockingFieldEntity.class, id1, 2)
+ .equals(ver2);
+ }
+
+ @Test
+ public void testMapping() {
+ PersistentClass pc = getCfg().getClassMapping(UnversionedOptimisticLockingFieldEntity.class.getName() + "_versions");
+ Iterator pi = pc.getPropertyIterator();
+ while(pi.hasNext()) {
+ Property p = (Property) pi.next();
+ assert !"optLocking".equals(p.getName());
+ }
+ }
+}
Added: trunk/src/test/org/jboss/envers/test/integration/properties/UnversionedOptimisticLockingFieldEntity.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/properties/UnversionedOptimisticLockingFieldEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/properties/UnversionedOptimisticLockingFieldEntity.java 2008-08-25 07:25:19 UTC (rev 128)
@@ -0,0 +1,81 @@
+package org.jboss.envers.test.integration.properties;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+import org.jboss.envers.Versioned;
+
+/**
+ * @author Nicolas Doroskevich
+ */
+@Versioned
+@Entity
+public class UnversionedOptimisticLockingFieldEntity {
+
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ private String str;
+
+ @Version
+ private int optLocking;
+
+ public UnversionedOptimisticLockingFieldEntity() {
+ }
+
+ public UnversionedOptimisticLockingFieldEntity(String str) {
+ this.str = str;
+ }
+
+ public UnversionedOptimisticLockingFieldEntity(Integer id, String str) {
+ this.id = id;
+ this.str = str;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getStr() {
+ return str;
+ }
+
+ public void setStr(String str) {
+ this.str = str;
+ }
+
+ public int getOptLocking() {
+ return optLocking;
+ }
+
+ public void setOptLocking(int optLocking) {
+ this.optLocking = optLocking;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof UnversionedOptimisticLockingFieldEntity)) return false;
+
+ UnversionedOptimisticLockingFieldEntity that = (UnversionedOptimisticLockingFieldEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+ if (str != null ? !str.equals(that.str) : that.str != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (str != null ? str.hashCode() : 0);
+ return result;
+ }
+
+}
16 years, 2 months
JBoss Envers SVN: r127 - in trunk/src/test/org/jboss/envers/test: integration/manytomany and 1 other directory.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-25 03:10:44 -0400 (Mon, 25 Aug 2008)
New Revision: 127
Added:
trunk/src/test/org/jboss/envers/test/integration/manytomany/BasicList.java
Modified:
trunk/src/test/org/jboss/envers/test/entities/manytomany/ListOwnedEntity.java
Log:
ENVERS-24: additional test
Modified: trunk/src/test/org/jboss/envers/test/entities/manytomany/ListOwnedEntity.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/manytomany/ListOwnedEntity.java 2008-08-25 07:04:48 UTC (rev 126)
+++ trunk/src/test/org/jboss/envers/test/entities/manytomany/ListOwnedEntity.java 2008-08-25 07:10:44 UTC (rev 127)
@@ -20,7 +20,7 @@
private String data;
@Versioned
- @ManyToMany(mappedBy="referencing")
+ @ManyToMany(mappedBy="references")
private List<ListOwningEntity> referencing;
public ListOwnedEntity() {
Copied: trunk/src/test/org/jboss/envers/test/integration/manytomany/BasicList.java (from rev 125, trunk/src/test/org/jboss/envers/test/integration/manytomany/BasicSet.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/manytomany/BasicList.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/manytomany/BasicList.java 2008-08-25 07:10:44 UTC (rev 127)
@@ -0,0 +1,189 @@
+package org.jboss.envers.test.integration.manytomany;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.manytomany.ListOwningEntity;
+import org.jboss.envers.test.entities.manytomany.ListOwnedEntity;
+import org.jboss.envers.test.tools.TestTools;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.hibernate.ejb.Ejb3Configuration;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.ArrayList;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BasicList extends AbstractEntityTest {
+ private Integer ed1_id;
+ private Integer ed2_id;
+
+ private Integer ing1_id;
+ private Integer ing2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ListOwningEntity.class);
+ cfg.addAnnotatedClass(ListOwnedEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ ListOwnedEntity ed1 = new ListOwnedEntity(1, "data_ed_1");
+ ListOwnedEntity ed2 = new ListOwnedEntity(2, "data_ed_2");
+
+ ListOwningEntity ing1 = new ListOwningEntity(3, "data_ing_1");
+ ListOwningEntity ing2 = new ListOwningEntity(4, "data_ing_2");
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ em.persist(ed1);
+ em.persist(ed2);
+ em.persist(ing1);
+ em.persist(ing2);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+
+ em.getTransaction().begin();
+
+ ing1 = em.find(ListOwningEntity.class, ing1.getId());
+ ing2 = em.find(ListOwningEntity.class, ing2.getId());
+ ed1 = em.find(ListOwnedEntity.class, ed1.getId());
+ ed2 = em.find(ListOwnedEntity.class, ed2.getId());
+
+ ing1.setReferences(new ArrayList<ListOwnedEntity>());
+ ing1.getReferences().add(ed1);
+
+ ing2.setReferences(new ArrayList<ListOwnedEntity>());
+ ing2.getReferences().add(ed1);
+ ing2.getReferences().add(ed2);
+
+ em.getTransaction().commit();
+
+ // Revision 3
+ em.getTransaction().begin();
+
+ ing1 = em.find(ListOwningEntity.class, ing1.getId());
+ ed2 = em.find(ListOwnedEntity.class, ed2.getId());
+ ed1 = em.find(ListOwnedEntity.class, ed1.getId());
+
+ ing1.getReferences().add(ed2);
+
+ em.getTransaction().commit();
+
+ // Revision 4
+ em.getTransaction().begin();
+
+ ing1 = em.find(ListOwningEntity.class, ing1.getId());
+ ed2 = em.find(ListOwnedEntity.class, ed2.getId());
+ ed1 = em.find(ListOwnedEntity.class, ed1.getId());
+
+ ing1.getReferences().remove(ed1);
+
+ em.getTransaction().commit();
+
+ // Revision 5
+ em.getTransaction().begin();
+
+ ing1 = em.find(ListOwningEntity.class, ing1.getId());
+
+ ing1.setReferences(null);
+
+ em.getTransaction().commit();
+
+ //
+
+ ed1_id = ed1.getId();
+ ed2_id = ed2.getId();
+
+ ing1_id = ing1.getId();
+ ing2_id = ing2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 4).equals(getVersionsReader().getRevisions(ListOwnedEntity.class, ed1_id));
+ assert Arrays.asList(1, 2, 3, 5).equals(getVersionsReader().getRevisions(ListOwnedEntity.class, ed2_id));
+
+ assert Arrays.asList(1, 2, 3, 4, 5).equals(getVersionsReader().getRevisions(ListOwningEntity.class, ing1_id));
+ assert Arrays.asList(1, 2).equals(getVersionsReader().getRevisions(ListOwningEntity.class, ing2_id));
+ }
+
+ @Test
+ public void testHistoryOfEdId1() {
+ ListOwningEntity ing1 = getEntityManager().find(ListOwningEntity.class, ing1_id);
+ ListOwningEntity ing2 = getEntityManager().find(ListOwningEntity.class, ing2_id);
+
+ ListOwnedEntity rev1 = getVersionsReader().find(ListOwnedEntity.class, ed1_id, 1);
+ ListOwnedEntity rev2 = getVersionsReader().find(ListOwnedEntity.class, ed1_id, 2);
+ ListOwnedEntity rev3 = getVersionsReader().find(ListOwnedEntity.class, ed1_id, 3);
+ ListOwnedEntity rev4 = getVersionsReader().find(ListOwnedEntity.class, ed1_id, 4);
+ ListOwnedEntity rev5 = getVersionsReader().find(ListOwnedEntity.class, ed1_id, 5);
+
+ assert rev1.getReferencing().equals(Collections.EMPTY_LIST);
+ assert TestTools.checkList(rev2.getReferencing(), ing1, ing2);
+ assert TestTools.checkList(rev3.getReferencing(), ing1, ing2);
+ assert TestTools.checkList(rev4.getReferencing(), ing2);
+ assert TestTools.checkList(rev5.getReferencing(), ing2);
+ }
+
+ @Test
+ public void testHistoryOfEdId2() {
+ ListOwningEntity ing1 = getEntityManager().find(ListOwningEntity.class, ing1_id);
+ ListOwningEntity ing2 = getEntityManager().find(ListOwningEntity.class, ing2_id);
+
+ ListOwnedEntity rev1 = getVersionsReader().find(ListOwnedEntity.class, ed2_id, 1);
+ ListOwnedEntity rev2 = getVersionsReader().find(ListOwnedEntity.class, ed2_id, 2);
+ ListOwnedEntity rev3 = getVersionsReader().find(ListOwnedEntity.class, ed2_id, 3);
+ ListOwnedEntity rev4 = getVersionsReader().find(ListOwnedEntity.class, ed2_id, 4);
+ ListOwnedEntity rev5 = getVersionsReader().find(ListOwnedEntity.class, ed2_id, 5);
+
+ assert rev1.getReferencing().equals(Collections.EMPTY_LIST);
+ assert TestTools.checkList(rev2.getReferencing(), ing2);
+ assert TestTools.checkList(rev3.getReferencing(), ing1, ing2);
+ assert TestTools.checkList(rev4.getReferencing(), ing1, ing2);
+ assert TestTools.checkList(rev5.getReferencing(), ing2);
+ }
+
+ @Test
+ public void testHistoryOfEdIng1() {
+ ListOwnedEntity ed1 = getEntityManager().find(ListOwnedEntity.class, ed1_id);
+ ListOwnedEntity ed2 = getEntityManager().find(ListOwnedEntity.class, ed2_id);
+
+ ListOwningEntity rev1 = getVersionsReader().find(ListOwningEntity.class, ing1_id, 1);
+ ListOwningEntity rev2 = getVersionsReader().find(ListOwningEntity.class, ing1_id, 2);
+ ListOwningEntity rev3 = getVersionsReader().find(ListOwningEntity.class, ing1_id, 3);
+ ListOwningEntity rev4 = getVersionsReader().find(ListOwningEntity.class, ing1_id, 4);
+ ListOwningEntity rev5 = getVersionsReader().find(ListOwningEntity.class, ing1_id, 5);
+
+ assert rev1.getReferences().equals(Collections.EMPTY_LIST);
+ assert TestTools.checkList(rev2.getReferences(), ed1);
+ assert TestTools.checkList(rev3.getReferences(), ed1, ed2);
+ assert TestTools.checkList(rev4.getReferences(), ed2);
+ assert rev5.getReferences().equals(Collections.EMPTY_LIST);
+ }
+
+ @Test
+ public void testHistoryOfEdIng2() {
+ ListOwnedEntity ed1 = getEntityManager().find(ListOwnedEntity.class, ed1_id);
+ ListOwnedEntity ed2 = getEntityManager().find(ListOwnedEntity.class, ed2_id);
+
+ ListOwningEntity rev1 = getVersionsReader().find(ListOwningEntity.class, ing2_id, 1);
+ ListOwningEntity rev2 = getVersionsReader().find(ListOwningEntity.class, ing2_id, 2);
+ ListOwningEntity rev3 = getVersionsReader().find(ListOwningEntity.class, ing2_id, 3);
+ ListOwningEntity rev4 = getVersionsReader().find(ListOwningEntity.class, ing2_id, 4);
+ ListOwningEntity rev5 = getVersionsReader().find(ListOwningEntity.class, ing2_id, 5);
+
+ assert rev1.getReferences().equals(Collections.EMPTY_LIST);
+ assert TestTools.checkList(rev2.getReferences(), ed1, ed2);
+ assert TestTools.checkList(rev3.getReferences(), ed1, ed2);
+ assert TestTools.checkList(rev4.getReferences(), ed1, ed2);
+ assert TestTools.checkList(rev5.getReferences(), ed1, ed2);
+ }
+}
\ No newline at end of file
16 years, 2 months