Author: adamw
Date: 2008-08-14 11:39:48 -0400 (Thu, 14 Aug 2008)
New Revision: 104
Added:
trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
trunk/src/main/org/jboss/envers/configuration/entities/
trunk/src/main/org/jboss/envers/configuration/entities/EntitiesConfigurations.java
trunk/src/main/org/jboss/envers/configuration/entities/EntityConfiguration.java
trunk/src/main/org/jboss/envers/configuration/entities/IdMappingData.java
trunk/src/main/org/jboss/envers/revisioninfo/
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/revisioninfo/RevisionNumberGenerator.java
Removed:
trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/configuration/DefaultRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/configuration/RevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java
Modified:
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/AnnotationsMetadataReader.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/data/PersistentClassVersioningData.java
trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
trunk/src/main/org/jboss/envers/query/RevisionProperty.java
trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java
trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java
trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java
trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java
trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java
trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.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
Log:
ENVERS-37: componentizing configuration
Deleted: trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java 2008-08-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -1,73 +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.configuration;
-
-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 implements RevisionInfoGenerator {
- private RevisionListener listener;
- private Setter revisionTimestampSetter;
- private Class<?> entityClass;
-
- public CustomRevisionInfoGenerator(VersionsEntitiesConfiguration verEntCfg,
- Class<?> entityClass,
- Class<? extends RevisionListener>
listenerClass) {
- this.entityClass = entityClass;
-
- revisionTimestampSetter = ReflectionTools.getSetter(entityClass,
- verEntCfg.getRevisionsInfoTimestampName());
-
- 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);
- }
- }
- }
-
- 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/configuration/DefaultRevisionInfoGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/DefaultRevisionInfoGenerator.java 2008-08-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/configuration/DefaultRevisionInfoGenerator.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -1,43 +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.configuration;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class DefaultRevisionInfoGenerator implements RevisionInfoGenerator {
- private VersionsEntitiesConfiguration verEntCfg;
-
- public DefaultRevisionInfoGenerator(VersionsEntitiesConfiguration verEntCfg) {
- this.verEntCfg = verEntCfg;
- }
-
- public Object newRevision() {
- Map<String, Object> revisionInfo = new HashMap<String, Object>();
- revisionInfo.put(verEntCfg.getRevisionsInfoTimestampName(),
System.currentTimeMillis());
-
- return revisionInfo;
- }
-}
Added: trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
(rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -0,0 +1,32 @@
+package org.jboss.envers.configuration;
+
+import java.util.Properties;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class GlobalConfiguration {
+ // Should a revision be generated when a not-owned relation field changes
+ private final boolean generateRevisionsForCollections;
+
+ // Should a warning, instead of an error and an exception, be logged, when an
unsupported type is versioned
+ private final boolean warnOnUnsupportedTypes;
+
+ public GlobalConfiguration(Properties properties) {
+ String generateRevisionsForCollectionsStr =
properties.getProperty("org.jboss.envers.revisionOnCollectionChange",
+ "true");
+ generateRevisionsForCollections =
Boolean.parseBoolean(generateRevisionsForCollectionsStr);
+
+ String warnOnUnsupportedTypesStr =
properties.getProperty("org.jboss.envers.warnOnUnsupportedTypes",
+ "false");
+ warnOnUnsupportedTypes = Boolean.parseBoolean(warnOnUnsupportedTypesStr);
+ }
+
+ public boolean isGenerateRevisionsForCollections() {
+ return generateRevisionsForCollections;
+ }
+
+ public boolean isWarnOnUnsupportedTypes() {
+ return warnOnUnsupportedTypes;
+ }
+}
Added: trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
(rev 0)
+++
trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -0,0 +1,215 @@
+package org.jboss.envers.configuration;
+
+import org.jboss.envers.tools.reflection.YClass;
+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.configuration.metadata.MetadataTools;
+import org.jboss.envers.revisioninfo.CustomRevisionInfoGenerator;
+import org.jboss.envers.revisioninfo.DefaultRevisionInfoGenerator;
+import org.jboss.envers.revisioninfo.RevisionNumberGenerator;
+import org.jboss.envers.revisioninfo.RevisionInfoGenerator;
+import org.hibernate.MappingException;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.cfg.Configuration;
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+
+import java.util.Iterator;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class RevisionInfoConfiguration {
+ private String revisionInfoEntityName;
+ private String revisionInfoIdName;
+ private String revisionInfoTimestampName;
+ private String revisionInfoTimestampType;
+
+ private String revisionPropType;
+
+ public RevisionInfoConfiguration() {
+ revisionInfoEntityName = "_revisions_info";
+ revisionInfoIdName = "revision_id";
+ revisionInfoTimestampName = "revision_timestamp";
+ revisionInfoTimestampType = "long";
+
+ revisionPropType = "integer";
+ }
+
+ private Document generateDefaultRevisionInfoXmlMapping() {
+ Document document = DocumentHelper.createDocument();
+
+ Element class_mapping = MetadataTools.createEntity(document,
revisionInfoEntityName,
+ null, null, null, null);
+
+ MetadataTools.addNativelyGeneratedId(class_mapping, revisionInfoIdName,
+ revisionPropType);
+
+ MetadataTools.addProperty(class_mapping, revisionInfoTimestampName,
+ revisionInfoTimestampType, false);
+
+ return document;
+ }
+
+ private void searchForRevisionInfoCfg(YClass clazz, YReflectionManager
reflectionManager,
+ MutableBoolean revisionNumberFound,
MutableBoolean revisionTimestampFound) {
+ YClass superclazz = clazz.getSuperclass();
+ if (!"java.lang.Object".equals(superclazz.getName())) {
+ searchForRevisionInfoCfg(superclazz, reflectionManager, revisionNumberFound,
revisionTimestampFound);
+ }
+
+ for (YProperty property : clazz.getDeclaredProperties("field")) {
+ RevisionNumber revisionNumber =
property.getAnnotation(RevisionNumber.class);
+ RevisionTimestamp revisionTimestamp =
property.getAnnotation(RevisionTimestamp.class);
+
+ if (revisionNumber != null) {
+ if (revisionNumberFound.isSet()) {
+ throw new MappingException("Only one property may be annotated
with @RevisionNumber!");
+ }
+
+ YClass revisionNumberClass = property.getType();
+ if (reflectionManager.equals(revisionNumberClass, Integer.class) ||
+ reflectionManager.equals(revisionNumberClass, Integer.TYPE)) {
+ revisionInfoIdName = property.getName();
+ revisionNumberFound.set();
+ } else if (reflectionManager.equals(revisionNumberClass, Long.class) ||
+ reflectionManager.equals(revisionNumberClass, Long.TYPE)) {
+ revisionInfoIdName = property.getName();
+ revisionNumberFound.set();
+
+ // The default is integer
+ revisionPropType = "long";
+ } else {
+ throw new MappingException("The field annotated with
@RevisionNumber must be of type " +
+ "int, Integer, long or Long");
+ }
+ }
+
+ if (revisionTimestamp != null) {
+ if (revisionTimestampFound.isSet()) {
+ throw new MappingException("Only one property may be annotated
with @RevisionTimestamp!");
+ }
+
+ YClass revisionTimestampClass = property.getType();
+ if (reflectionManager.equals(revisionTimestampClass, Long.class) ||
+ reflectionManager.equals(revisionTimestampClass, Long.TYPE)) {
+ revisionInfoTimestampName = property.getName();
+ revisionTimestampFound.set();
+ } else {
+ throw new MappingException("The field annotated with
@RevisionTimestamp must be of type " +
+ "long or Long");
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public RevisionInfoConfigurationResult configure(Configuration cfg,
YReflectionManager reflectionManager) {
+ Iterator<PersistentClass> classes = (Iterator<PersistentClass>)
cfg.getClassMappings();
+ boolean revisionEntityFound = false;
+ RevisionInfoGenerator revisionInfoGenerator = null;
+
+ while (classes.hasNext()) {
+ PersistentClass pc = classes.next();
+ YClass clazz;
+ try {
+ clazz = reflectionManager.classForName(pc.getClassName(),
this.getClass());
+ } catch (ClassNotFoundException e) {
+ throw new MappingException(e);
+ }
+
+ RevisionEntity revisionEntity = clazz.getAnnotation(RevisionEntity.class);
+ if (revisionEntity != null) {
+ if (revisionEntityFound) {
+ throw new MappingException("Only one entity may be annotated
with @RevisionEntity!");
+ }
+
+ // Checking if custom revision entity isn't versioned
+ if (clazz.getAnnotation(Versioned.class) != null) {
+ throw new MappingException("An entity annotated with
@RevisionEntity cannot be versioned!");
+ }
+
+ revisionEntityFound = true;
+
+ MutableBoolean revisionNumberFound = new MutableBoolean();
+ MutableBoolean revisionTimestampFound = new MutableBoolean();
+
+ searchForRevisionInfoCfg(clazz, reflectionManager, revisionNumberFound,
revisionTimestampFound);
+
+ if (!revisionNumberFound.isSet()) {
+ throw new MappingException("An entity annotated with
@RevisionEntity must have a field annotated " +
+ "with @RevisionNumber!");
+ }
+
+ if (!revisionTimestampFound.isSet()) {
+ throw new MappingException("An entity annotated with
@RevisionEntity must have a field annotated " +
+ "with @RevisionTimestamp!");
+ }
+
+ revisionInfoEntityName = pc.getEntityName();
+
+ revisionInfoGenerator = new
CustomRevisionInfoGenerator(pc.getMappedClass(),
+ revisionEntity.value(), revisionInfoTimestampName);
+ }
+ }
+
+ // In case of a custom revision info generator, the mapping will be null.
+ Document revisionInfoXmlMapping = null;
+
+ if (revisionInfoGenerator == null) {
+ revisionInfoGenerator = new
DefaultRevisionInfoGenerator(revisionInfoTimestampName);
+ revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping();
+ }
+
+ return new RevisionInfoConfigurationResult(
+ new RevisionNumberGenerator(revisionInfoEntityName,
revisionInfoGenerator),
+ revisionPropType,
+ revisionInfoXmlMapping);
+ }
+
+ public boolean isRevisionInfoEntityName(String entityName) {
+ return revisionInfoEntityName.equals(entityName);
+ }
+
+ public String getRevisionInfoEntityName() {
+ return revisionInfoEntityName;
+ }
+
+ public String getRevisionInfoIdName() {
+ return revisionInfoIdName;
+ }
+
+ public String getRevisionInfoTimestampName() {
+ return revisionInfoTimestampName;
+ }
+}
+
+class RevisionInfoConfigurationResult {
+ private final RevisionNumberGenerator revisionNumberGenerator;
+ private final String revisionPropType;
+ private final Document revisionInfoXmlMapping;
+
+ RevisionInfoConfigurationResult(RevisionNumberGenerator revisionNumberGenerator,
String revisionPropType, Document revisionInfoXmlMapping) {
+ this.revisionNumberGenerator = revisionNumberGenerator;
+ this.revisionPropType = revisionPropType;
+ this.revisionInfoXmlMapping = revisionInfoXmlMapping;
+ }
+
+ public RevisionNumberGenerator getRevisionNumberGenerator() {
+ return revisionNumberGenerator;
+ }
+
+ public String getRevisionPropType() {
+ return revisionPropType;
+ }
+
+ public Document getRevisionInfoXmlMapping() {
+ return revisionInfoXmlMapping;
+ }
+}
\ No newline at end of file
Deleted: trunk/src/main/org/jboss/envers/configuration/RevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoGenerator.java 2008-08-14
11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/configuration/RevisionInfoGenerator.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -1,29 +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.configuration;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public interface RevisionInfoGenerator {
- public Object newRevision();
-}
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-14
11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -25,12 +25,10 @@
import org.hibernate.mapping.PersistentClass;
import org.hibernate.MappingException;
import org.jboss.envers.configuration.metadata.VersionsMetadataGenerator;
-import org.jboss.envers.configuration.metadata.RevisionsInfoMetadataGenerator;
import org.jboss.envers.configuration.metadata.AnnotationsMetadataReader;
import org.jboss.envers.configuration.metadata.data.PersistentClassVersioningData;
+import org.jboss.envers.configuration.entities.EntitiesConfigurations;
import org.jboss.envers.synchronization.VersionsSyncManager;
-import org.jboss.envers.mapper.ExtendedPropertyMapper;
-import org.jboss.envers.mapper.id.IdMapper;
import org.jboss.envers.tools.graph.GraphTopologicalSort;
import org.jboss.envers.tools.reflection.YReflectionManager;
import org.dom4j.Document;
@@ -49,19 +47,13 @@
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsConfiguration {
- private VersionsEntitiesConfiguration verEntCfg;
- private VersionsSyncManager versionsSyncManager;
- private EntitiesConfigurations entitiesConfigurations;
+ private final GlobalConfiguration globalCfg;
+ private final VersionsEntitiesConfiguration verEntCfg;
+ private final VersionsSyncManager versionsSyncManager;
+ private final EntitiesConfigurations entCfg;
+ private final RevisionInfoConfiguration revInfoCfg;
- // Should a revision be generated when a not-owned relation field changes
- private boolean generateRevisionsForCollections;
-
- // Should a warning, instead of an error and an exception, be logged, when an
unsupported type is versioned
- private boolean warnOnUnsupportedTypes;
-
- //
-
- public VersionsEntitiesConfiguration getEntitiesCfg() {
+ public VersionsEntitiesConfiguration getVerEntCfg() {
return verEntCfg;
}
@@ -69,22 +61,16 @@
return versionsSyncManager;
}
- // todo
- private void writeDocument(Document e) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Writer w = new PrintWriter(baos);
+ public RevisionInfoConfiguration getRevInfoCfg() {
+ return revInfoCfg;
+ }
- try {
- XMLWriter xw = new XMLWriter(w, new OutputFormat(" ", true));
- xw.write(e);
- w.flush();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
+ public GlobalConfiguration getGlobalCfg() {
+ return globalCfg;
+ }
- System.out.println("-----------");
- System.out.println(baos.toString());
- System.out.println("-----------");
+ public EntitiesConfigurations getEntCfg() {
+ return entCfg;
}
private YReflectionManager getReflectionManager(Configuration cfg) {
@@ -95,34 +81,18 @@
}
}
- private boolean isVersioned(PersistentClassVersioningData versioningData) {
- if (versioningData == null) { return false; }
- if (versioningData.propertyStoreInfo.propertyStores.size() > 0) { return true;
}
- if (versioningData.propertyStoreInfo.defaultStore != null) { return true; }
- return false;
- }
-
- private void configureFromProperties(Properties properties) {
- String generateRevisionsForCollectionsStr =
properties.getProperty("org.jboss.envers.revisionOnCollectionChange",
- "true");
- generateRevisionsForCollections =
Boolean.parseBoolean(generateRevisionsForCollectionsStr);
-
- String warnOnUnsupportedTypesStr =
properties.getProperty("org.jboss.envers.warnOnUnsupportedTypes",
- "false");
- warnOnUnsupportedTypes = Boolean.parseBoolean(warnOnUnsupportedTypesStr);
- }
-
@SuppressWarnings({"unchecked"})
- public void configure(Configuration cfg) {
- configureFromProperties(cfg.getProperties());
+ public VersionsConfiguration(Configuration cfg) {
+ Properties properties = cfg.getProperties();
YReflectionManager reflectionManager = getReflectionManager(cfg);
+ revInfoCfg = new RevisionInfoConfiguration();
+ RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg,
reflectionManager);
+ verEntCfg = new VersionsEntitiesConfiguration(properties,
revInfoCfgResult.getRevisionPropType());
+ globalCfg = new GlobalConfiguration(properties);
+ versionsSyncManager = new
VersionsSyncManager(revInfoCfgResult.getRevisionNumberGenerator());
- verEntCfg = VersionsEntitiesConfiguration.get(cfg, reflectionManager);
-
- versionsSyncManager = new VersionsSyncManager(verEntCfg);
-
- VersionsMetadataGenerator versionsMetaGen = new VersionsMetadataGenerator(this,
verEntCfg);
+ VersionsMetadataGenerator versionsMetaGen = new VersionsMetadataGenerator(this);
DOMWriter writer = new DOMWriter();
// Sorting the persistent class topologically - superclass always before
subclass
@@ -140,7 +110,7 @@
PersistentClassVersioningData versioningData =
annotationsMetadataReader.getVersioningData(pc, reflectionManager);
- if (isVersioned(versioningData)) {
+ if (versioningData.isVersioned()) {
pcDatas.put(pc, versioningData);
if (versioningData.versionsTableName != null) {
@@ -169,21 +139,13 @@
}
// Getting the entities configurations
- entitiesConfigurations = new
EntitiesConfigurations(versionsMetaGen.getEntitiesConfigurations());
+ entCfg = new
EntitiesConfigurations(versionsMetaGen.getEntitiesConfigurations());
- // Checking if custom revision entity isn't versioned
- if (entitiesConfigurations.get(verEntCfg.getRevisionsInfoEntityName()) != null)
{
- throw new MappingException("An entity annotated with @RevisionEntity
cannot be versioned!");
- }
-
// Only if there are any versioned classes
if (pcDatas.size() > 0) {
try {
- if (!verEntCfg.hasCustomRevisionInfoEntity()) {
- RevisionsInfoMetadataGenerator revisionsMetaGenInfo = new
RevisionsInfoMetadataGenerator(verEntCfg);
- Document helperEntity = revisionsMetaGenInfo.generate();
- //writeDocument(helperEntity);
- cfg.addDocument(writer.write(helperEntity));
+ if (revInfoCfgResult.getRevisionInfoXmlMapping() != null) {
+
cfg.addDocument(writer.write(revInfoCfgResult.getRevisionInfoXmlMapping()));
}
} catch (DocumentException e) {
throw new MappingException(e);
@@ -191,38 +153,6 @@
}
}
- public boolean isVersioned(String entityName) {
- return entitiesConfigurations.get(entityName) != null;
- }
-
- public IdMapper getIdMapper(String entityName) {
- return entitiesConfigurations.get(entityName).getIdMappingData().getIdMapper();
- }
-
- public ExtendedPropertyMapper getPropertyMapper(String entityName) {
- return entitiesConfigurations.get(entityName).getPropertyMapper();
- }
-
- public EntityConfiguration getEntityConfiguration(String entityName) {
- return entitiesConfigurations.get(entityName);
- }
-
- public String getEntityNameForVersionsEntityName(String versionsEntityName) {
- return
entitiesConfigurations.getEntityNameForVersionsEntityName(versionsEntityName);
- }
-
- public boolean isGenerateRevisionsForCollections() {
- return generateRevisionsForCollections;
- }
-
- public boolean isWarnOnUnsupportedTypes() {
- return warnOnUnsupportedTypes;
- }
-
- public RelationDescription getRelationDescription(String entityName, String
propertyName) {
- return entitiesConfigurations.getRelationDescription(entityName, propertyName);
- }
-
//
private static Map<Configuration, VersionsConfiguration> cfgs
@@ -232,13 +162,30 @@
VersionsConfiguration verCfg = cfgs.get(cfg);
if (verCfg == null) {
- verCfg = new VersionsConfiguration();
+ verCfg = new VersionsConfiguration(cfg);
cfgs.put(cfg, verCfg);
-
- verCfg.configure(cfg);
+
cfg.buildMappings();
}
return verCfg;
}
+
+ // todo
+ private void writeDocument(Document e) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Writer w = new PrintWriter(baos);
+
+ try {
+ XMLWriter xw = new XMLWriter(w, new OutputFormat(" ", true));
+ xw.write(e);
+ w.flush();
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+
+ System.out.println("-----------");
+ System.out.println(baos.toString());
+ System.out.println("-----------");
+ }
}
Modified:
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-08-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -21,75 +21,42 @@
*/
package org.jboss.envers.configuration;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.MappingException;
-import org.jboss.envers.RevisionEntity;
-import org.jboss.envers.RevisionNumber;
-import org.jboss.envers.RevisionTimestamp;
-import org.jboss.envers.tools.reflection.YReflectionManager;
-import org.jboss.envers.tools.reflection.YClass;
-import org.jboss.envers.tools.reflection.YProperty;
-import org.jboss.envers.tools.MutableBoolean;
-
import java.util.*;
/**
- * Configuration of versions entities - names of fields and entities created to store
versioning information, revision
- * info entity configuration etc.
+ * Configuration of versions entities - names of fields, entities and tables created to
store versioning information.
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsEntitiesConfiguration {
- private String versionsTablePrefix;
- private String versionsTableSuffix;
+ private final String versionsTablePrefix;
+ private final String versionsTableSuffix;
- private String originalIdPropName;
+ private final String originalIdPropName;
- private String revisionPropName;
- private String revisionPropType;
- private String revisionPropPath;
+ private final String revisionPropName;
+ private final String revisionPropType;
+ private final String revisionPropPath;
- private String revisionTypePropName;
- private String revisionTypePropType;
+ private final String revisionTypePropName;
+ private final String revisionTypePropType;
- private String revisionsInfoEntityName;
- private String revisionsInfoIdName;
- private String revisionsInfoTimestampName;
- private String revisionsInfoTimestampType;
- private boolean customRevisionsInfoEntity;
+ private final Map<String, String> customVersionsTablesNames;
- private RevisionInfoGenerator revisionInfoGenerator;
+ public VersionsEntitiesConfiguration(Properties properties, String revisionPropType)
{
+ versionsTablePrefix =
properties.getProperty("org.jboss.envers.versionsTablePrefix", "");
+ versionsTableSuffix =
properties.getProperty("org.jboss.envers.versionsTableSuffix",
"_versions");
- private Map<String, String> customVersionsTablesNames;
+ originalIdPropName = "originalId";
- public static VersionsEntitiesConfiguration get(Configuration cfg, YReflectionManager
reflectionManager) {
- Properties properties = cfg.getProperties();
+ revisionPropName =
properties.getProperty("org.jboss.envers.revisionFieldName",
"_revision");
+ this.revisionPropType = revisionPropType;
- VersionsEntitiesConfiguration verEntCfg = new VersionsEntitiesConfiguration();
+ revisionTypePropName =
properties.getProperty("org.jboss.envers.revisionTypeFieldName",
"_revision_type");
+ revisionTypePropType = "byte";
- verEntCfg.versionsTablePrefix =
properties.getProperty("org.jboss.envers.versionsTablePrefix", "");
- verEntCfg.versionsTableSuffix =
properties.getProperty("org.jboss.envers.versionsTableSuffix",
"_versions");
+ customVersionsTablesNames = new HashMap<String, String>();
- verEntCfg.originalIdPropName = "originalId";
-
- verEntCfg.revisionPropName =
properties.getProperty("org.jboss.envers.revisionFieldName",
"_revision");
- verEntCfg.revisionPropType = "integer";
-
- verEntCfg.revisionTypePropName =
properties.getProperty("org.jboss.envers.revisionTypeFieldName",
"_revision_type");
- verEntCfg.revisionTypePropType = "byte";
-
- verEntCfg.revisionsInfoEntityName = "_revisions_info";
- verEntCfg.revisionsInfoIdName = "revision_id";
- verEntCfg.revisionsInfoTimestampName = "revision_timestamp";
- verEntCfg.revisionsInfoTimestampType = "long";
-
- verEntCfg.customVersionsTablesNames = new HashMap<String, String>();
-
- verEntCfg.revisionPropPath = verEntCfg.originalIdPropName + "." +
verEntCfg.revisionPropName;
-
- verEntCfg.customRevisionsInfoEntity = verEntCfg.configureRevisionsEntity(cfg,
reflectionManager);
-
- return verEntCfg;
+ revisionPropPath = originalIdPropName + "." + revisionPropName;
}
public String getVersionsTablePrefix() {
@@ -124,26 +91,6 @@
return revisionTypePropType;
}
- public String getRevisionsInfoEntityName() {
- return revisionsInfoEntityName;
- }
-
- public String getRevisionsInfoIdName() {
- return revisionsInfoIdName;
- }
-
- public String getRevisionsInfoTimestampName() {
- return revisionsInfoTimestampName;
- }
-
- public String getRevisionsInfoTimestampType() {
- return revisionsInfoTimestampType;
- }
-
- public RevisionInfoGenerator getRevisionInfoGenerator() {
- return revisionInfoGenerator;
- }
-
//
public void addCustomVersionsTableName(String entityName, String tableName) {
@@ -173,117 +120,4 @@
return customHistoryTableName;
}
-
- public boolean isRevisionInfoEntityName(String entityName) {
- return revisionsInfoEntityName.equals(entityName);
- }
-
- public boolean hasCustomRevisionInfoEntity() {
- return customRevisionsInfoEntity;
- }
-
- //
-
- private void searchForRevisionInfoCfg(YClass clazz, YReflectionManager
reflectionManager,
- MutableBoolean revisionNumberFound,
MutableBoolean revisionTimestampFound) {
- YClass superclazz = clazz.getSuperclass();
- if (!"java.lang.Object".equals(superclazz.getName())) {
- searchForRevisionInfoCfg(superclazz, reflectionManager, revisionNumberFound,
revisionTimestampFound);
- }
-
- for (YProperty property : clazz.getDeclaredProperties("field")) {
- RevisionNumber revisionNumber =
property.getAnnotation(RevisionNumber.class);
- RevisionTimestamp revisionTimestamp =
property.getAnnotation(RevisionTimestamp.class);
-
- if (revisionNumber != null) {
- if (revisionNumberFound.isSet()) {
- throw new MappingException("Only one property may be annotated
with @RevisionNumber!");
- }
-
- YClass revisionNumberClass = property.getType();
- if (reflectionManager.equals(revisionNumberClass, Integer.class) ||
- reflectionManager.equals(revisionNumberClass, Integer.TYPE)) {
- revisionsInfoIdName = property.getName();
- revisionNumberFound.set();
- } else if (reflectionManager.equals(revisionNumberClass, Long.class) ||
- reflectionManager.equals(revisionNumberClass, Long.TYPE)) {
- revisionsInfoIdName = property.getName();
- revisionNumberFound.set();
-
- // The default is integer
- revisionPropType = "long";
- } else {
- throw new MappingException("The field annotated with
@RevisionNumber must be of type " +
- "int, Integer, long or Long");
- }
- }
-
- if (revisionTimestamp != null) {
- if (revisionTimestampFound.isSet()) {
- throw new MappingException("Only one property may be annotated
with @RevisionTimestamp!");
- }
-
- YClass revisionTimestampClass = property.getType();
- if (reflectionManager.equals(revisionTimestampClass, Long.class) ||
- reflectionManager.equals(revisionTimestampClass, Long.TYPE)) {
- revisionsInfoTimestampName = property.getName();
- revisionTimestampFound.set();
- } else {
- throw new MappingException("The field annotated with
@RevisionTimestamp must be of type " +
- "long or Long");
- }
- }
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private boolean configureRevisionsEntity(Configuration cfg, YReflectionManager
reflectionManager) {
- Iterator<PersistentClass> classes = (Iterator<PersistentClass>)
cfg.getClassMappings();
- boolean revisionEntityFound = false;
-
- while (classes.hasNext()) {
- PersistentClass pc = classes.next();
- YClass clazz;
- try {
- clazz = reflectionManager.classForName(pc.getClassName(),
this.getClass());
- } catch (ClassNotFoundException e) {
- throw new MappingException(e);
- }
-
- RevisionEntity revisionEntity = clazz.getAnnotation(RevisionEntity.class);
- if (revisionEntity != null) {
- if (revisionEntityFound) {
- throw new MappingException("Only one entity may be annotated
with @RevisionEntity!");
- }
-
- revisionEntityFound = true;
-
- MutableBoolean revisionNumberFound = new MutableBoolean();
- MutableBoolean revisionTimestampFound = new MutableBoolean();
-
- searchForRevisionInfoCfg(clazz, reflectionManager, revisionNumberFound,
revisionTimestampFound);
-
- if (!revisionNumberFound.isSet()) {
- throw new MappingException("An entity annotated with
@RevisionEntity must have a field annotated " +
- "with @RevisionNumber!");
- }
-
- if (!revisionTimestampFound.isSet()) {
- throw new MappingException("An entity annotated with
@RevisionEntity must have a field annotated " +
- "with @RevisionTimestamp!");
- }
-
- revisionsInfoEntityName = pc.getEntityName();
-
- revisionInfoGenerator = new CustomRevisionInfoGenerator(this,
pc.getMappedClass(),
- revisionEntity.value());
- }
- }
-
- if (revisionInfoGenerator == null) {
- revisionInfoGenerator = new DefaultRevisionInfoGenerator(this);
- }
-
- return revisionEntityFound;
- }
}
Copied: trunk/src/main/org/jboss/envers/configuration/entities/EntitiesConfigurations.java
(from rev 102, trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurations.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/entities/EntitiesConfigurations.java
(rev 0)
+++
trunk/src/main/org/jboss/envers/configuration/entities/EntitiesConfigurations.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -0,0 +1,110 @@
+/*
+ * 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.entities;
+
+import org.jboss.envers.mapper.id.IdMapper;
+import org.jboss.envers.mapper.ExtendedPropertyMapper;
+import org.jboss.envers.configuration.RelationDescription;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Configuration of the user entities: property mapping of the entities, relations,
inheritance.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class EntitiesConfigurations {
+ private Map<String, EntityConfiguration> entitiesConfigurations;
+
+ // Map versions entity name -> entity name
+ private Map<String, String> entityNamesForVersionsEntityNames = new
HashMap<String, String>();
+
+ public EntitiesConfigurations(Map<String, EntityConfiguration>
entitiesConfigurations) {
+ this.entitiesConfigurations = entitiesConfigurations;
+
+ generateBidirectionRelationInfo();
+ generateVersionsEntityToEntityNames();
+ }
+
+ private void generateVersionsEntityToEntityNames() {
+ entityNamesForVersionsEntityNames = new HashMap<String, String>();
+
+ for (String entityName : entitiesConfigurations.keySet()) {
+
entityNamesForVersionsEntityNames.put(entitiesConfigurations.get(entityName).getVersionsEntityName(),
+ entityName);
+ }
+ }
+
+ private void generateBidirectionRelationInfo() {
+ // Checking each relation if it is bidirectional. If so, storing that
information.
+ for (String entityName : entitiesConfigurations.keySet()) {
+ EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
+ // Iterating over all relations from that entity
+ for (RelationDescription relDesc : entCfg.getRelationsIterator()) {
+ // If this is an "owned" relation, checking the related entity,
if it has a relation that has
+ // a mapped-by attribute to the currently checked. If so, this is a
bidirectional relation.
+ if (relDesc.relationType == RelationDescription.RelationType.TO_ONE) {
+ for (RelationDescription other :
entitiesConfigurations.get(relDesc.toEntityName).getRelationsIterator()) {
+ if (relDesc.fromPropertyName.equals(other.mappedByPropertyName)
&&
+ (entityName.equals(other.toEntityName))) {
+ relDesc.bidirectional = true;
+ other.bidirectional= true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public EntityConfiguration get(String entityName) {
+ return entitiesConfigurations.get(entityName);
+ }
+
+ public String getEntityNameForVersionsEntityName(String versionsEntityName) {
+ return entityNamesForVersionsEntityNames.get(versionsEntityName);
+ }
+
+ public boolean isVersioned(String entityName) {
+ return get(entityName) != null;
+ }
+
+ public IdMapper getIdMapper(String entityName) {
+ return get(entityName).getIdMappingData().getIdMapper();
+ }
+
+ public ExtendedPropertyMapper getPropertyMapper(String entityName) {
+ return get(entityName).getPropertyMapper();
+ }
+
+ public RelationDescription getRelationDescription(String entityName, String
propertyName) {
+ EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
+ RelationDescription relDesc = entCfg.getRelationDescription(propertyName);
+ if (relDesc != null) {
+ return relDesc;
+ } else if (entCfg.getParentEntityName() != null) {
+ // The field may be declared in a superclass ...
+ return getRelationDescription(entCfg.getParentEntityName(), propertyName);
+ } else {
+ return null;
+ }
+ }
+}
Copied: trunk/src/main/org/jboss/envers/configuration/entities/EntityConfiguration.java
(from rev 103, trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/entities/EntityConfiguration.java
(rev 0)
+++
trunk/src/main/org/jboss/envers/configuration/entities/EntityConfiguration.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -0,0 +1,102 @@
+/*
+ * 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.entities;
+
+import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.mapper.ExtendedPropertyMapper;
+import org.jboss.envers.mapper.id.IdMapper;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class EntityConfiguration {
+ private String entityName;
+ private String versionsEntityName;
+ private IdMappingData idMappingData;
+ private ExtendedPropertyMapper propertyMapper;
+ // Maps from property name
+ private Map<String, RelationDescription> relations;
+ private String parentEntityName;
+
+ public EntityConfiguration(String entityName, String versionsEntityName,
IdMappingData idMappingData,
+ ExtendedPropertyMapper propertyMapper, String
parentEntityName) {
+ this.entityName = entityName;
+ this.versionsEntityName = versionsEntityName;
+ this.idMappingData = idMappingData;
+ this.propertyMapper = propertyMapper;
+ this.parentEntityName = parentEntityName;
+
+ this.relations = new HashMap<String, RelationDescription>();
+ }
+
+ public void addToOneRelation(String fromPropertyName, String toEntityName, IdMapper
idMapper) {
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName,
RelationDescription.RelationType.TO_ONE,
+ toEntityName, null, idMapper));
+ }
+
+ public void addOneToOneRelation(String fromPropertyName, String mappedByPropertyName,
String toEntityName,
+ IdMapper idMapper) {
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName,
RelationDescription.RelationType.ONE_TO_ONE,
+ toEntityName, mappedByPropertyName, idMapper));
+ }
+
+ public void addOneToManyRelation(String fromPropertyName, String
mappedByPropertyName, String toEntityName,
+ IdMapper idMapper) {
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName,
RelationDescription.RelationType.ONE_TO_MANY,
+ toEntityName, mappedByPropertyName, idMapper));
+ }
+
+ public boolean isRelation(String propertyName) {
+ return relations.get(propertyName) != null;
+ }
+
+ public Iterable<RelationDescription> getRelationsIterator() {
+ return relations.values();
+ }
+
+ public RelationDescription getRelationDescription(String propertyName) {
+ return relations.get(propertyName);
+ }
+
+ public IdMappingData getIdMappingData() {
+ return idMappingData;
+ }
+
+ public ExtendedPropertyMapper getPropertyMapper() {
+ return propertyMapper;
+ }
+
+ public String getParentEntityName() {
+ return parentEntityName;
+ }
+
+ public String getEntityName() {
+ return entityName;
+ }
+
+ public String getVersionsEntityName() {
+ return versionsEntityName;
+ }
+}
Copied: trunk/src/main/org/jboss/envers/configuration/entities/IdMappingData.java (from
rev 103, trunk/src/main/org/jboss/envers/configuration/metadata/data/IdMappingData.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/entities/IdMappingData.java
(rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/entities/IdMappingData.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -0,0 +1,54 @@
+/*
+ * 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.entities;
+
+import org.jboss.envers.mapper.id.IdMapper;
+import org.dom4j.Element;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class IdMappingData {
+ private IdMapper idMapper;
+ // Mapping which will be used to generate the entity
+ private Element xmlMapping;
+ // Mapping which will be used to generate references to the entity in related
entities
+ private Element xmlRelationMapping;
+
+ public IdMappingData(IdMapper idMapper, Element xmlMapping, Element
xmlRelationMapping) {
+ this.idMapper = idMapper;
+ this.xmlMapping = xmlMapping;
+ this.xmlRelationMapping = xmlRelationMapping;
+ }
+
+ public IdMapper getIdMapper() {
+ return idMapper;
+ }
+
+ public Element getXmlMapping() {
+ return xmlMapping;
+ }
+
+ public Element getXmlRelationMapping() {
+ return xmlRelationMapping;
+ }
+}
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-08-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -59,12 +59,12 @@
}
public PersistentClassVersioningData getVersioningData(PersistentClass pc,
YReflectionManager reflectionManager) {
+ PersistentClassVersioningData versioningData = new
PersistentClassVersioningData();
+
if (pc.getClassName() == null) {
- return null;
+ return versioningData;
}
- PersistentClassVersioningData versioningData = new
PersistentClassVersioningData();
-
try {
YClass clazz = reflectionManager.classForName(pc.getClassName(),
this.getClass());
Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
Deleted:
trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java 2008-08-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -1,53 +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.configuration.metadata;
-
-import org.dom4j.Document;
-import org.dom4j.DocumentHelper;
-import org.dom4j.Element;
-import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class RevisionsInfoMetadataGenerator {
- private VersionsEntitiesConfiguration verEntCfg;
-
- public RevisionsInfoMetadataGenerator(VersionsEntitiesConfiguration verEntCfg) {
- this.verEntCfg = verEntCfg;
- }
-
- public Document generate() {
- Document document = DocumentHelper.createDocument();
-
- Element class_mapping = MetadataTools.createEntity(document,
verEntCfg.getRevisionsInfoEntityName(),
- null, null, null, null);
-
- MetadataTools.addNativelyGeneratedId(class_mapping,
verEntCfg.getRevisionsInfoIdName(),
- verEntCfg.getRevisionPropType());
-
- MetadataTools.addProperty(class_mapping,
verEntCfg.getRevisionsInfoTimestampName(),
- verEntCfg.getRevisionsInfoTimestampType(), false);
-
- return document;
- }
-}
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -30,8 +30,8 @@
import org.dom4j.DocumentHelper;
import org.dom4j.Attribute;
import org.dom4j.tree.DefaultElement;
-import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
-import org.jboss.envers.configuration.EntityConfiguration;
+import org.jboss.envers.configuration.entities.EntityConfiguration;
+import org.jboss.envers.configuration.entities.IdMappingData;
import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.mapper.*;
import org.jboss.envers.mapper.id.*;
@@ -44,7 +44,6 @@
import org.jboss.envers.ModificationStore;
import org.jboss.envers.tools.log.YLog;
import org.jboss.envers.tools.log.YLogManager;
-import org.jboss.envers.configuration.metadata.data.IdMappingData;
import org.jboss.envers.configuration.metadata.data.PersistentClassVersioningData;
import org.jboss.envers.configuration.metadata.data.PropertyStoreInfo;
import org.jboss.envers.exception.VersionsException;
@@ -61,7 +60,6 @@
private final static Map<String, ModificationStore> EMPTY_STORE =
Collections.emptyMap();
private VersionsConfiguration verCfg;
- private VersionsEntitiesConfiguration verEntCfg;
private Map<String, EntityConfiguration> entitiesConfigurations;
// Map entity name -> (join descriptor -> element describing the
"versioned" join)
@@ -69,9 +67,8 @@
private YLog log =
YLogManager.getLogManager().getLog(VersionsMetadataGenerator.class);
- public VersionsMetadataGenerator(VersionsConfiguration verCfg,
VersionsEntitiesConfiguration verEntCfg) {
+ public VersionsMetadataGenerator(VersionsConfiguration verCfg) {
this.verCfg = verCfg;
- this.verEntCfg = verEntCfg;
entitiesConfigurations = new HashMap<String, EntityConfiguration>();
entitiesJoins = new HashMap<String, Map<Join, Element>>();
@@ -428,7 +425,7 @@
} else {
String message = "Type not supported for versioning: "
+ propertyType.getClass().getName() +
", on entity " + entityName + ", property
'" + property.getName() + "'.";
- if (verCfg.isWarnOnUnsupportedTypes()) {
+ if (verCfg.getGlobalCfg().isWarnOnUnsupportedTypes()) {
log.warn(message);
} else {
throw new MappingException(message);
@@ -454,7 +451,7 @@
String originalTableName = join.getTable().getName();
String versionedTableName =
versioningData.secondaryTableDictionary.get(originalTableName);
if (versionedTableName == null) {
- versionedTableName = verEntCfg.getVersionsEntityName(originalTableName);
+ versionedTableName =
verCfg.getVerEntCfg().getVersionsEntityName(originalTableName);
}
String schema = versioningData.schema;
@@ -472,7 +469,7 @@
Element joinKey = joinElement.addElement("key");
addColumns(joinKey, join.getKey().getColumnIterator());
- MetadataTools.addColumn(joinKey, verEntCfg.getRevisionPropName(), null);
+ MetadataTools.addColumn(joinKey, verCfg.getVerEntCfg().getRevisionPropName(),
null);
}
}
@@ -524,12 +521,12 @@
addSimpleProperty(orig_id_mapping, id_prop, null, ModificationStore.FULL,
true);
}
- orig_id_mapping.addAttribute("name",
verEntCfg.getOriginalIdPropName());
+ orig_id_mapping.addAttribute("name",
verCfg.getVerEntCfg().getOriginalIdPropName());
// Adding the "revision number" property
- Element rev_mapping = MetadataTools.addProperty(orig_id_mapping,
verEntCfg.getRevisionPropName(),
- verEntCfg.getRevisionPropType(), true);
- MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionPropName(), null);
+ Element rev_mapping = MetadataTools.addProperty(orig_id_mapping,
verCfg.getVerEntCfg().getRevisionPropName(),
+ verCfg.getVerEntCfg().getRevisionPropType(), true);
+ MetadataTools.addColumn(rev_mapping, verCfg.getVerEntCfg().getRevisionPropName(),
null);
return new IdMappingData(mapper, orig_id_mapping, rel_id_mapping);
}
@@ -560,8 +557,8 @@
}
String entityName = pc.getEntityName();
- String versionsEntityName = verEntCfg.getVersionsEntityName(entityName);
- String versionsTableName = verEntCfg.getVersionsTableName(entityName,
pc.getTable().getName());
+ String versionsEntityName =
verCfg.getVerEntCfg().getVersionsEntityName(entityName);
+ String versionsTableName = verCfg.getVerEntCfg().getVersionsTableName(entityName,
pc.getTable().getName());
// Generating a mapping for the id
IdMappingData idMapper = addId(pc);
@@ -592,13 +589,13 @@
class_mapping.add((Element) idMapper.getXmlMapping().clone());
// Adding the "revision type" property
- Element revTypeProperty = MetadataTools.addProperty(class_mapping,
verEntCfg.getRevisionTypePropName(),
- verEntCfg.getRevisionTypePropType(), false);
+ Element revTypeProperty = MetadataTools.addProperty(class_mapping,
verCfg.getVerEntCfg().getRevisionTypePropName(),
+ verCfg.getVerEntCfg().getRevisionTypePropType(), false);
revTypeProperty.addAttribute("type",
"org.jboss.envers.entity.RevisionTypeType");
break;
case SINGLE:
- String extendsEntityName =
verEntCfg.getVersionsEntityName(pc.getSuperclass().getEntityName());
+ String extendsEntityName =
verCfg.getVerEntCfg().getVersionsEntityName(pc.getSuperclass().getEntityName());
class_mapping = MetadataTools.createSubclassEntity(document,
versionsEntityName, versionsTableName,
schema, catalog, extendsEntityName, pc.getDiscriminatorValue());
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/data/PersistentClassVersioningData.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/data/PersistentClassVersioningData.java 2008-08-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/data/PersistentClassVersioningData.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -40,4 +40,10 @@
public String schema;
public String catalog;
public Map<String, String> secondaryTableDictionary;
+
+ public boolean isVersioned() {
+ if (propertyStoreInfo.propertyStores.size() > 0) { return true; }
+ if (propertyStoreInfo.defaultStore != null) { return true; }
+ return false;
+ }
}
Modified: trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-14 11:12:23 UTC
(rev 103)
+++ trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-14 15:39:48 UTC
(rev 104)
@@ -57,7 +57,7 @@
}
// The $type$ property holds the name of the (versions) entity
- String type = verCfg.getEntityNameForVersionsEntityName((String)
versionsEntity.get("$type$"));
+ String type = verCfg.getEntCfg().getEntityNameForVersionsEntityName((String)
versionsEntity.get("$type$"));
if (type != null) {
entityName = type;
@@ -71,12 +71,12 @@
throw new VersionsException(e);
}
- IdMapper idMapper = verCfg.getIdMapper(entityName);
- Map originalId = (Map)
versionsEntity.get(verCfg.getEntitiesCfg().getOriginalIdPropName());
+ IdMapper idMapper = verCfg.getEntCfg().getIdMapper(entityName);
+ Map originalId = (Map)
versionsEntity.get(verCfg.getVerEntCfg().getOriginalIdPropName());
Object primaryKey = idMapper.mapToIdFromMap(originalId);
- verCfg.getPropertyMapper(entityName).mapToEntityFromMap(ret, versionsEntity,
primaryKey, versionsReader, revision);
+ verCfg.getEntCfg().getPropertyMapper(entityName).mapToEntityFromMap(ret,
versionsEntity, primaryKey, versionsReader, revision);
idMapper.mapToEntityFromMap(ret, originalId);
return ret;
Modified: trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
===================================================================
--- trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-14 11:12:23
UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-14 15:39:48
UTC (rev 104)
@@ -46,7 +46,7 @@
private void generateCollectionChangeWorkUnits(VersionsSync verSync, EntityPersister
entityPersister,
String entityName, Object[] newState,
Object[] oldState) {
// Checking if this is enabled in configuration ...
- if (!verCfg.isGenerateRevisionsForCollections()) {
+ if (!verCfg.getGlobalCfg().isGenerateRevisionsForCollections()) {
return;
}
@@ -57,14 +57,14 @@
for (int i=0; i<propertyNames.length; i++) {
String propertyName = propertyNames[i];
- RelationDescription relDesc = verCfg.getRelationDescription(entityName,
propertyName);
+ RelationDescription relDesc =
verCfg.getEntCfg().getRelationDescription(entityName, propertyName);
if (relDesc != null && relDesc.bidirectional &&
relDesc.relationType == RelationDescription.RelationType.TO_ONE) {
// Checking for changes
Object oldValue = oldState == null ? null : oldState[i];
Object newValue = newState == null ? null : newState[i];
if (!Tools.objectsEqual(oldValue, newValue)) {
- IdMapper idMapper = verCfg.getIdMapper(relDesc.toEntityName);
+ IdMapper idMapper =
verCfg.getEntCfg().getIdMapper(relDesc.toEntityName);
// We have to generate changes both in the old collection (size
decreses) and new collection
// (size increases).
@@ -85,7 +85,7 @@
public void onPostInsert(PostInsertEvent event) {
String entityName = event.getPersister().getEntityName();
- if (verCfg.isVersioned(entityName)) {
+ if (verCfg.getEntCfg().isVersioned(entityName)) {
VersionsSync verSync = verCfg.getSyncManager().get(event.getSession());
verSync.addWorkUnit(new AddWorkUnit(event.getPersister().getEntityName(),
verCfg, event.getId(),
@@ -98,7 +98,7 @@
public void onPostUpdate(PostUpdateEvent event) {
String entityName = event.getPersister().getEntityName();
- if (verCfg.isVersioned(entityName)) {
+ if (verCfg.getEntCfg().isVersioned(entityName)) {
VersionsSync verSync = verCfg.getSyncManager().get(event.getSession());
verSync.addWorkUnit(new ModWorkUnit(event.getPersister().getEntityName(),
verCfg, event.getId(),
@@ -111,7 +111,7 @@
public void onPostDelete(PostDeleteEvent event) {
String entityName = event.getPersister().getEntityName();
- if (verCfg.isVersioned(entityName)) {
+ if (verCfg.getEntCfg().isVersioned(entityName)) {
VersionsSync verSync = verCfg.getSyncManager().get(event.getSession());
verSync.addWorkUnit(new DelWorkUnit(event.getPersister().getEntityName(),
verCfg, event.getId()));
Modified: trunk/src/main/org/jboss/envers/query/RevisionProperty.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/RevisionProperty.java 2008-08-14 11:12:23 UTC
(rev 103)
+++ trunk/src/main/org/jboss/envers/query/RevisionProperty.java 2008-08-14 15:39:48 UTC
(rev 104)
@@ -116,6 +116,6 @@
}
public Projection getProjection(String entityName, VersionsReaderImplementor
versionsReader) {
- return
Projections.property(versionsReader.getEntitiesCfg().getRevisionPropPath());
+ return
Projections.property(versionsReader.getVerCfg().getVerEntCfg().getRevisionPropPath());
}
}
Modified: trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java 2008-08-14 11:12:23
UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java 2008-08-14 15:39:48
UTC (rev 104)
@@ -41,6 +41,6 @@
}
public Projection getProjection(String entityName, VersionsReaderImplementor
versionsReader) {
- return
Projections.property(versionsReader.getEntitiesCfg().getRevisionTypePropName());
+ return
Projections.property(versionsReader.getVerCfg().getVerEntCfg().getRevisionTypePropName());
}
}
\ No newline at end of file
Modified:
trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java
===================================================================
---
trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java 2008-08-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -56,7 +56,7 @@
throws VersionsException {
CriteriaTools.checkPropertyNotARelation(versionsReader, entityName,
propertyName);
- String versionsEntityName =
versionsReader.getEntitiesCfg().getVersionsEntityName(entityName);
+ String versionsEntityName =
versionsReader.getVerCfg().getVerEntCfg().getVersionsEntityName(entityName);
// This will be the aggregated criteria, containing all the specified conditions
DetachedCriteria aggregatedCriteria =
DetachedCriteria.forEntityName(versionsEntityName);
Modified: trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java 2008-08-14 11:12:23
UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java 2008-08-14 15:39:48
UTC (rev 104)
@@ -33,7 +33,7 @@
public static void checkPropertyNotARelation(VersionsReaderImplementor
versionsReader, String entityName,
String propertyName) throws
VersionsException {
- if
(versionsReader.getVerCfg().getEntityConfiguration(entityName).isRelation(propertyName))
{
+ if
(versionsReader.getVerCfg().getEntCfg().get(entityName).isRelation(propertyName)) {
throw new VersionsException("This criterion cannot be used on a property
that is " +
"a relation to another property.");
}
@@ -42,7 +42,7 @@
public static RelationDescription getRelatedEntity(VersionsReaderImplementor
versionsReader, String entityName,
String propertyName) throws
VersionsException {
RelationDescription relationDesc = versionsReader.getVerCfg()
-
.getEntityConfiguration(entityName).getRelationDescription(propertyName);
+ .getEntCfg().get(entityName).getRelationDescription(propertyName);
if (relationDesc == null) {
return null;
Modified:
trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java
===================================================================
---
trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java 2008-08-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -37,7 +37,7 @@
public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor
versionsReader)
throws VersionsException {
- return versionsReader.getVerCfg().getIdMapper(entityName)
- .getIdEqualsCriterion(id,
versionsReader.getVerCfg().getEntitiesCfg().getOriginalIdPropName(), true);
+ return versionsReader.getVerCfg().getEntCfg().getIdMapper(entityName)
+ .getIdEqualsCriterion(id,
versionsReader.getVerCfg().getVerEntCfg().getOriginalIdPropName(), true);
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java
===================================================================
---
trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java 2008-08-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -39,7 +39,7 @@
public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor
versionsReader)
throws VersionsException {
- return new
PublicSimpleExpression(versionsReader.getEntitiesCfg().getRevisionPropPath(),
+ return new
PublicSimpleExpression(versionsReader.getVerCfg().getVerEntCfg().getRevisionPropPath(),
value, op, false);
}
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-14
11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -62,7 +62,7 @@
entityInstantiator = new EntityInstantiator(versionsReader);
entityName = cls.getName();
- versionsEntityName =
versionsReader.getEntitiesCfg().getVersionsEntityName(entityName);
+ versionsEntityName =
versionsReader.getVerCfg().getVerEntCfg().getVersionsEntityName(entityName);
versionsCriteria = versionsReader.getSession().createCriteria(versionsEntityName,
"e");
}
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-14
11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -24,6 +24,7 @@
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.query.criteria.VersionsCriterion;
import org.jboss.envers.RevisionType;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import org.hibernate.criterion.*;
import java.util.List;
@@ -53,19 +54,21 @@
DetachedCriteria maxRevCriteria =
DetachedCriteria.forEntityName(versionsEntityName, "e2");
- String revisionPropertyPath =
versionsReader.getEntitiesCfg().getRevisionPropPath();
- String originalIdPropertyName =
versionsReader.getEntitiesCfg().getOriginalIdPropName();
+ VersionsEntitiesConfiguration verEntCfg =
versionsReader.getVerCfg().getVerEntCfg();
+ String revisionPropertyPath = verEntCfg.getRevisionPropPath();
+ String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
+
// SELECT max(e2.revision)
maxRevCriteria.setProjection(Property.forName(revisionPropertyPath).max());
// e2.revision <= :revision
maxRevCriteria.add(Restrictions.le(revisionPropertyPath, revision));
// e2.id = e.id
-
maxRevCriteria.add(versionsReader.getVerCfg().getIdMapper(entityName).getIdsEqualCriterion(
+
maxRevCriteria.add(versionsReader.getVerCfg().getEntCfg().getIdMapper(entityName).getIdsEqualCriterion(
"e." + originalIdPropertyName, "e2." +
originalIdPropertyName));
// e.revision_type != DEL AND
-
versionsCriteria.add(Property.forName(versionsReader.getEntitiesCfg().getRevisionTypePropName()).ne(RevisionType.DEL));
+
versionsCriteria.add(Property.forName(verEntCfg.getRevisionTypePropName()).ne(RevisionType.DEL));
// e.revision = (SELECT max(...) ...)
versionsCriteria.add(Property.forName(revisionPropertyPath).eq(maxRevCriteria));
// all specified conditions, transformed
Modified: trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-14
11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -25,6 +25,7 @@
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.query.criteria.VersionsCriterion;
import org.jboss.envers.RevisionType;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Property;
@@ -49,6 +50,8 @@
@SuppressWarnings({"unchecked"})
public List list() throws VersionsException {
+ VersionsEntitiesConfiguration verEntCfg =
versionsReader.getVerCfg().getVerEntCfg();
+
/*
The query that should be executed in the versions table:
SELECT e (unless another projection is specified) FROM ent_ver e WHERE
@@ -56,11 +59,11 @@
(all specified conditions, transformed, on the "e" entity)
ORDER BY e.revision ASC (unless another order is specified)
*/
- String revisionPropertyPath =
versionsReader.getEntitiesCfg().getRevisionPropPath();
+ String revisionPropertyPath = verEntCfg.getRevisionPropPath();
if (!selectDeletedEntities) {
// e.revision_type != DEL AND
-
versionsCriteria.add(Property.forName(versionsReader.getEntitiesCfg().getRevisionTypePropName()).ne(RevisionType.DEL));
+
versionsCriteria.add(Property.forName(verEntCfg.getRevisionTypePropName()).ne(RevisionType.DEL));
}
// all specified conditions, transformed
@@ -77,9 +80,9 @@
return queryResult;
} else {
List entities = new ArrayList();
- String originalId = versionsReader.getEntitiesCfg().getOriginalIdPropName();
- String revisionPropertyName =
versionsReader.getEntitiesCfg().getRevisionPropName();
- String revisionTypePropertyName =
versionsReader.getEntitiesCfg().getRevisionTypePropName();
+ String originalId = verEntCfg.getOriginalIdPropName();
+ String revisionPropertyName = verEntCfg.getRevisionPropName();
+ String revisionTypePropertyName = verEntCfg.getRevisionTypePropName();
for (Map versionsEntity : queryResult) {
Number revision = (Number) ((Map)
versionsEntity.get(originalId)).get(revisionPropertyName);
Modified: trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java 2008-08-14
11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -35,7 +35,7 @@
}
public Order getOrder(String entityName, VersionsReaderImplementor versionsReader) {
- String revisionPropPath = versionsReader.getEntitiesCfg().getRevisionPropPath();
+ String revisionPropPath =
versionsReader.getVerCfg().getVerEntCfg().getRevisionPropPath();
if (asc) {
return Order.asc(revisionPropPath);
Modified:
trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java
===================================================================
---
trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java 2008-08-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -43,7 +43,7 @@
}
public Projection getProjection(String entityName, VersionsReaderImplementor
versionsReader) {
- String revisionPropPath = versionsReader.getEntitiesCfg().getRevisionPropPath();
+ String revisionPropPath =
versionsReader.getVerCfg().getVerEntCfg().getRevisionPropPath();
switch (type) {
case MAX: return Projections.max(revisionPropPath);
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-14 11:12:23 UTC
(rev 103)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-14 15:39:48 UTC
(rev 104)
@@ -27,6 +27,7 @@
import org.hibernate.engine.SessionImplementor;
import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.RevisionInfoConfiguration;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.exception.NotVersionedException;
import org.jboss.envers.exception.RevisionDoesNotExistException;
@@ -45,17 +46,18 @@
*/
public class VersionsReaderImpl implements VersionsReaderImplementor {
private VersionsConfiguration verCfg;
- private VersionsEntitiesConfiguration entitiesCfg;
private SessionImplementor sessionImplementor;
private Session session;
+ private final RevisionInfoConfiguration revInfoCfg;
+
public VersionsReaderImpl(VersionsConfiguration verCfg, Session session,
SessionImplementor sessionImplementor) {
this.verCfg = verCfg;
this.sessionImplementor = sessionImplementor;
this.session = session;
- entitiesCfg = verCfg.getEntitiesCfg();
+ revInfoCfg = verCfg.getRevInfoCfg();
}
private void checkSession() {
@@ -76,10 +78,6 @@
return verCfg;
}
- public VersionsEntitiesConfiguration getEntitiesCfg() {
- return entitiesCfg;
- }
-
@SuppressWarnings({"unchecked"})
public <T> T find(Class<T> cls, Object primaryKey, Number revision)
throws
IllegalArgumentException, NotVersionedException, IllegalStateException {
@@ -91,7 +89,7 @@
String entityName = cls.getName();
- if (!verCfg.isVersioned(entityName)) {
+ if (!verCfg.getEntCfg().isVersioned(entityName)) {
throw new NotVersionedException(entityName + " is not
versioned!");
}
@@ -150,7 +148,7 @@
String entityName = cls.getName();
- if (!verCfg.isVersioned(entityName)) {
+ if (!verCfg.getEntCfg().isVersioned(entityName)) {
throw new NotVersionedException(entityName + " is not
versioned!");
}
@@ -167,9 +165,9 @@
checkSession();
StringBuilder queryStr = new StringBuilder();
- queryStr.append("select
rev.").append(entitiesCfg.getRevisionsInfoTimestampName())
- .append(" from
").append(entitiesCfg.getRevisionsInfoEntityName())
- .append(" rev where
").append(entitiesCfg.getRevisionsInfoIdName()).append(" =
:_revision_number");
+ queryStr.append("select
rev.").append(revInfoCfg.getRevisionInfoTimestampName())
+ .append(" from
").append(revInfoCfg.getRevisionInfoEntityName())
+ .append(" rev where
").append(revInfoCfg.getRevisionInfoIdName()).append(" =
:_revision_number");
Query query =
session.createQuery(queryStr.toString()).setParameter("_revision_number",
revision);
@@ -190,9 +188,9 @@
checkSession();
StringBuilder queryStr = new StringBuilder();
- queryStr.append("select
max(rev.").append(entitiesCfg.getRevisionsInfoIdName())
- .append(") from
").append(entitiesCfg.getRevisionsInfoEntityName())
- .append(" rev where
").append(entitiesCfg.getRevisionsInfoTimestampName()).append(" <=
:_revision_date");
+ queryStr.append("select
max(rev.").append(revInfoCfg.getRevisionInfoIdName())
+ .append(") from
").append(revInfoCfg.getRevisionInfoEntityName())
+ .append(" rev where
").append(revInfoCfg.getRevisionInfoTimestampName()).append(" <=
:_revision_date");
Query query =
session.createQuery(queryStr.toString()).setParameter("_revision_date",
date.getTime());
@@ -217,9 +215,9 @@
StringBuilder queryStr = new StringBuilder();
queryStr.append("select rev from ")
- .append(entitiesCfg.getRevisionsInfoEntityName())
+ .append(revInfoCfg.getRevisionInfoEntityName())
.append(" rev where ")
- .append(entitiesCfg.getRevisionsInfoIdName())
+ .append(revInfoCfg.getRevisionInfoIdName())
.append(" = :_revision_number");
Query query =
session.createQuery(queryStr.toString()).setParameter("_revision_number",
revision);
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java 2008-08-14
11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -25,7 +25,6 @@
import org.hibernate.Session;
import org.jboss.envers.VersionsReader;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import java.util.Collection;
@@ -45,6 +44,4 @@
Class<? extends Collection> collectionClass);
VersionsConfiguration getVerCfg();
-
- VersionsEntitiesConfiguration getEntitiesCfg();
}
Added: trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java
(rev 0)
+++
trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -0,0 +1,72 @@
+/*
+ * 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 implements RevisionInfoGenerator {
+ private RevisionListener listener;
+ private Setter revisionTimestampSetter;
+ private Class<?> entityClass;
+
+ public CustomRevisionInfoGenerator(Class<?> entityClass,
+ Class<? extends RevisionListener>
listenerClass,
+ String revisionInfoTimestampName) {
+ 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);
+ }
+ }
+ }
+
+ 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;
+ }
+}
Added: trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java
(rev 0)
+++
trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -0,0 +1,43 @@
+/*
+ * 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 implements RevisionInfoGenerator {
+ private String revisionInfoTimestampName;
+
+ public DefaultRevisionInfoGenerator(String revisionInfoTimestampName) {
+ this.revisionInfoTimestampName = revisionInfoTimestampName;
+ }
+
+ public Object newRevision() {
+ Map<String, Object> revisionInfo = new HashMap<String, Object>();
+ revisionInfo.put(revisionInfoTimestampName, System.currentTimeMillis());
+
+ return revisionInfo;
+ }
+}
Added: trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoGenerator.java
(rev 0)
+++ trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoGenerator.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public interface RevisionInfoGenerator {
+ public Object newRevision();
+}
Added: trunk/src/main/org/jboss/envers/revisioninfo/RevisionNumberGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/RevisionNumberGenerator.java
(rev 0)
+++ trunk/src/main/org/jboss/envers/revisioninfo/RevisionNumberGenerator.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -0,0 +1,20 @@
+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/main/org/jboss/envers/synchronization/VersionsSync.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java 2008-08-14 11:12:23
UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java 2008-08-14 15:39:48
UTC (rev 104)
@@ -26,6 +26,7 @@
import org.hibernate.FlushMode;
import org.jboss.envers.synchronization.work.VersionsWorkUnit;
import org.jboss.envers.tools.Pair;
+import org.jboss.envers.revisioninfo.RevisionNumberGenerator;
import javax.transaction.Synchronization;
import java.util.*;
@@ -34,29 +35,28 @@
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsSync implements Synchronization {
- private VersionsSyncManager manager;
- private Session session;
+ private final RevisionNumberGenerator revisionNumberGenerator;
+ private final VersionsSyncManager manager;
+ private final Session session;
+
+ private final Transaction transaction;
+ private final LinkedList<VersionsWorkUnit> workUnits;
+ private final Queue<VersionsWorkUnit> undoQueue;
+ private final Map<Pair<String, Object>, VersionsWorkUnit> usedIds;
+
private Number revision;
- private Transaction transaction;
- private LinkedList<VersionsWorkUnit> workUnits;
- private Queue<VersionsWorkUnit> undoQueue;
- private Map<Pair<String, Object>, VersionsWorkUnit> usedIds;
- public VersionsSync(VersionsSyncManager manager, Session session) {
+ public VersionsSync(VersionsSyncManager manager, Session session,
RevisionNumberGenerator revisionNumberGenerator) {
this.manager = manager;
this.session = session;
+ this.revisionNumberGenerator = revisionNumberGenerator;
transaction = session.getTransaction();
workUnits = new LinkedList<VersionsWorkUnit>();
undoQueue = new LinkedList<VersionsWorkUnit>();
usedIds = new HashMap<Pair<String, Object>, VersionsWorkUnit>();
}
-
- private void generateRevision(Session session) {
- revision = (Number)
session.save(manager.getEntitiesCfg().getRevisionsInfoEntityName(),
- manager.getEntitiesCfg().getRevisionInfoGenerator().newRevision());
- }
-
+
private void removeWorkUnit(VersionsWorkUnit vwu) {
workUnits.remove(vwu);
if (vwu.isPerformed()) {
@@ -98,7 +98,7 @@
private void executeInSession(Session session) {
if (revision == null) {
- generateRevision(session);
+ revision = revisionNumberGenerator.generate(session);
}
VersionsWorkUnit vwu;
@@ -121,6 +121,7 @@
if (FlushMode.isManualFlushMode(session.getFlushMode())) {
Session temporarySession = null;
try {
+ //noinspection deprecation
temporarySession =
session.getSessionFactory().openSession(session.connection());
executeInSession(temporarySession);
Modified: trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java 2008-08-14
11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -22,7 +22,7 @@
package org.jboss.envers.synchronization;
import org.jboss.envers.tools.ConcurrentReferenceHashMap;
-import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.revisioninfo.RevisionNumberGenerator;
import org.hibernate.Session;
import org.hibernate.Transaction;
@@ -32,19 +32,15 @@
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsSyncManager {
- private VersionsEntitiesConfiguration verEntCfg;
- private Map<Transaction, VersionsSync> versionsSyncs;
+ private final Map<Transaction, VersionsSync> versionsSyncs;
+ private final RevisionNumberGenerator revisionNumberGenerator;
- public VersionsSyncManager(VersionsEntitiesConfiguration verEntCfg) {
- this.verEntCfg = verEntCfg;
-
+ public VersionsSyncManager(RevisionNumberGenerator revisionNumberGenerator) {
versionsSyncs = new ConcurrentReferenceHashMap<Transaction,
VersionsSync>(10,
ConcurrentReferenceHashMap.ReferenceType.WEAK,
ConcurrentReferenceHashMap.ReferenceType.STRONG);
- }
- public VersionsEntitiesConfiguration getEntitiesCfg() {
- return verEntCfg;
+ this.revisionNumberGenerator = revisionNumberGenerator;
}
public VersionsSync get(Session session) {
@@ -52,7 +48,7 @@
VersionsSync verSync = versionsSyncs.get(transaction);
if (verSync == null) {
- verSync = new VersionsSync(this, session);
+ verSync = new VersionsSync(this, session, revisionNumberGenerator);
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-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -47,12 +47,12 @@
}
protected void fillDataWithId(Map<String, Object> data, Number revision,
RevisionType revisionType) {
- VersionsEntitiesConfiguration entitiesCfg = verCfg.getEntitiesCfg();
+ VersionsEntitiesConfiguration entitiesCfg = verCfg.getVerEntCfg();
Map<String, Object> originalId = new HashMap<String, Object>();
originalId.put(entitiesCfg.getRevisionPropName(), revision);
- verCfg.getIdMapper(getEntityName()).mapToMapFromId(originalId, id);
+ verCfg.getEntCfg().getIdMapper(getEntityName()).mapToMapFromId(originalId, id);
data.put(entitiesCfg.getRevisionTypePropName(), revisionType);
data.put(entitiesCfg.getOriginalIdPropName(), originalId);
}
@@ -75,7 +75,7 @@
public void undo(Session session) {
if (isPerformed()) {
-
session.delete(verCfg.getEntitiesCfg().getVersionsEntityName(getEntityName()),
performedData);
+ session.delete(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()),
performedData);
session.flush();
}
}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java 2008-08-14
11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -53,9 +53,9 @@
Map<String, Object> data = new HashMap<String, Object>();
fillDataWithId(data, revision, RevisionType.ADD);
- verCfg.getPropertyMapper(getEntityName()).map(data, propertyNames, state, null);
+ verCfg.getEntCfg().getPropertyMapper(getEntityName()).map(data, propertyNames,
state, null);
- session.save(verCfg.getEntitiesCfg().getVersionsEntityName(getEntityName()),
data);
+ session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()),
data);
setPerformed(data);
}
Modified:
trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java
===================================================================
---
trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java 2008-08-14
11:12:23 UTC (rev 103)
+++
trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -49,9 +49,9 @@
Map<String, Object> data = new HashMap<String, Object>();
fillDataWithId(data, revision, RevisionType.MOD);
- verCfg.getPropertyMapper(getEntityName()).mapToMapFromEntity(data, entity,
null);
+ verCfg.getEntCfg().getPropertyMapper(getEntityName()).mapToMapFromEntity(data,
entity, null);
- session.save(verCfg.getEntitiesCfg().getVersionsEntityName(getEntityName()),
data);
+ session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()),
data);
setPerformed(data);
}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java 2008-08-14
11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -45,7 +45,7 @@
Map<String, Object> data = new HashMap<String, Object>();
fillDataWithId(data, revision, RevisionType.DEL);
- session.save(verCfg.getEntitiesCfg().getVersionsEntityName(getEntityName()),
data);
+ session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()),
data);
setPerformed(data);
}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java 2008-08-14
11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java 2008-08-14
15:39:48 UTC (rev 104)
@@ -42,7 +42,7 @@
super(entityName, verCfg, id);
data = new HashMap<String, Object>();
- changes = verCfg.getPropertyMapper(getEntityName()).map(data,
entityPersister.getPropertyNames(),
+ changes = verCfg.getEntCfg().getPropertyMapper(getEntityName()).map(data,
entityPersister.getPropertyNames(),
newState, oldState);
}
@@ -53,7 +53,7 @@
public void perform(Session session, Number revision) {
fillDataWithId(data, revision, RevisionType.MOD);
- session.save(verCfg.getEntitiesCfg().getVersionsEntityName(getEntityName()),
data);
+ session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()),
data);
setPerformed(data);
}