JBoss Envers SVN: r116 - in trunk/src: main/org/jboss/envers/entities and 10 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-21 06:19:09 -0400 (Thu, 21 Aug 2008)
New Revision: 116
Added:
trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyBidirectionalMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/UnidirectionalRelationQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyBidirectionalInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyUnidirectionalInitializor.java
Removed:
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyInitializor.java
trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/EntityInstantiator.java
trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/SubclassPropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/id/QueryParameterData.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyUnidirectionalMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java
trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.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/reader/VersionsReaderImpl.java
trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
trunk/src/main/org/jboss/envers/tools/StringTools.java
trunk/src/test/org/jboss/envers/test/working/WorkingMain.java
Log:
ENVERS-26: retrieving versions of unidirectional one-to-many associations
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -37,7 +37,7 @@
import org.jboss.envers.entities.mapper.id.*;
import org.jboss.envers.entities.mapper.relation.ToOneIdMapper;
import org.jboss.envers.entities.mapper.relation.OneToOneIdMapper;
-import org.jboss.envers.entities.mapper.relation.OneToManyIdMapper;
+import org.jboss.envers.entities.mapper.relation.OneToManyBidirectionalMapper;
import org.jboss.envers.entities.mapper.relation.OneToManyUnidirectionalMapper;
import org.jboss.envers.tools.StringTools;
import org.jboss.envers.tools.Tools;
@@ -315,7 +315,7 @@
owningEntityName, ownedIdMapper);
// Adding mapper for the id
- mapper.addComposite(propertyName, new OneToManyIdMapper(owningReferencePropertyName, owningEntityName,
+ mapper.addComposite(propertyName, new OneToManyBidirectionalMapper(owningReferencePropertyName, owningEntityName,
propertyName));
}
@@ -340,7 +340,7 @@
IdMappingData referencingIdMapping = configuration.getIdMappingData();
IdMappingData referencedIdMapping = referencedConfiguration.getIdMappingData();
- String referencingPrefix = entityName + "_";
+ String referencingPrefix = StringTools.getLastComponent(entityName) + "_";
String referencedPrefix = property.getName() + "_";
// Name of the entity that will be used to store the relation between the two entities.
@@ -374,10 +374,11 @@
addRevisionType(middleEntity);
// Adding the property mapper
- mapper.addComposite(property.getName(), new OneToManyUnidirectionalMapper(verEntCfg, property.getName(),
- referencedEntityName, versionsMiddleEntityName,
- referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
- referencedIdMapping.getIdMapper().prefixMappedProperties(referencedPrefix)));
+ mapper.addComposite(property.getName(), new OneToManyUnidirectionalMapper(verEntCfg, entityName,
+ referencedEntityName, property.getName(), verEntCfg.getVersionsEntityName(referencedEntityName),
+ versionsMiddleEntityName, referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
+ referencedIdMapping.getIdMapper().prefixMappedProperties(referencedPrefix),
+ entitiesConfigurations.get(referencedEntityName).getIdMapper()));
// TODO: ???
}
Modified: trunk/src/main/org/jboss/envers/entities/EntityInstantiator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/EntityInstantiator.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/EntityInstantiator.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -29,6 +29,7 @@
import java.util.Map;
import java.util.List;
+import java.util.Collection;
/**
* @author Adam Warski (adam at warski dot org)
@@ -75,7 +76,7 @@
Object primaryKey = idMapper.mapToIdFromMap(originalId);
- verCfg.getEntCfg().get(entityName).getPropertyMapper().mapToEntityFromMap(ret, versionsEntity, primaryKey,
+ verCfg.getEntCfg().get(entityName).getPropertyMapper().mapToEntityFromMap(verCfg, ret, versionsEntity, primaryKey,
versionsReader, revision);
idMapper.mapToEntityFromMap(ret, originalId);
@@ -83,9 +84,9 @@
}
@SuppressWarnings({"unchecked"})
- public void addInstancesFromVersionsEntities(String entityName, List list, List<Map> versionsEntities, Number revision) {
+ public void addInstancesFromVersionsEntities(String entityName, Collection addTo, List<Map> versionsEntities, Number revision) {
for (Map versionsEntity : versionsEntities) {
- list.add(createInstanceFromVersionsEntity(entityName, versionsEntity, revision));
+ addTo.add(createInstanceFromVersionsEntity(entityName, versionsEntity, revision));
}
}
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -22,6 +22,7 @@
package org.jboss.envers.entities.mapper;
import org.jboss.envers.ModificationStore;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
@@ -66,7 +67,7 @@
return delegate.mapToMapFromEntity(newData, newObj, oldObj);
}
- public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
+ public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
if (data == null || obj == null) {
return;
}
@@ -77,17 +78,17 @@
try {
Object subObj = ReflectHelper.getDefaultConstructor(getter.getReturnType()).newInstance();
setter.set(obj, subObj, null);
- delegate.mapToEntityFromMap(subObj, (Map) data.get(propertyName), primaryKey, versionsReader, revision);
+ delegate.mapToEntityFromMap(verCfg, subObj, (Map) data.get(propertyName), primaryKey, versionsReader, revision);
} catch (Exception e) {
throw new VersionsException(e);
}
}
- public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
PersistentCollection newColl,
Serializable oldColl,
Serializable id) {
- return delegate.mapCollectionChangesFromCollections(referencingPropertyName, newColl, oldColl, id);
+ return delegate.mapCollectionChanges(referencingPropertyName, newColl, oldColl, id);
}
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -25,6 +25,7 @@
import org.hibernate.MappingException;
import org.hibernate.collection.PersistentCollection;
import org.jboss.envers.ModificationStore;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
@@ -101,19 +102,19 @@
return ret;
}
- public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
+ public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
for (String propertyName : properties.keySet()) {
- properties.get(propertyName).mapToEntityFromMap(obj, data, primaryKey, versionsReader, revision);
+ properties.get(propertyName).mapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision);
}
}
- public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
PersistentCollection newColl,
Serializable oldColl,
Serializable id) {
PropertyMapper mapper = properties.get(referencingPropertyName);
if (mapper != null) {
- return mapper.mapCollectionChangesFromCollections(referencingPropertyName, newColl, oldColl, id);
+ return mapper.mapCollectionChanges(referencingPropertyName, newColl, oldColl, id);
} else {
return null;
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -22,6 +22,7 @@
package org.jboss.envers.entities.mapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.collection.PersistentCollection;
import java.util.Map;
@@ -44,14 +45,15 @@
/**
* Maps properties from the given map to the given object.
+ * @param verCfg Versions configuration.
* @param obj Object to map to.
* @param data Data to map from.
* @param primaryKey Primary key of the object to which we map (for relations)
* @param versionsReader VersionsReader for reading relations
* @param revision Revision at which the obejct is read, for reading relations
*/
- public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader,
- Number revision);
+ public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey,
+ VersionsReaderImplementor versionsReader, Number revision);
/**
* Maps collection changes
@@ -61,8 +63,7 @@
* @param id Id of the object owning the collection.
* @return List of changes that need to be performed on the persistent store.
*/
- public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
- PersistentCollection newColl,
- Serializable oldColl,
- Serializable id);
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl, Serializable id);
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -22,6 +22,7 @@
package org.jboss.envers.entities.mapper;
import org.jboss.envers.ModificationStore;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.tools.Tools;
@@ -60,7 +61,7 @@
return !Tools.objectsEqual(newObj, oldObj);
}
- public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
+ public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
if (data == null || obj == null) {
return;
}
@@ -69,7 +70,7 @@
setter.set(obj, data.get(propertyName), null);
}
- public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
PersistentCollection newColl,
Serializable oldColl,
Serializable id) {
Modified: trunk/src/main/org/jboss/envers/entities/mapper/SubclassPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/SubclassPropertyMapper.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/mapper/SubclassPropertyMapper.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -23,6 +23,7 @@
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.ModificationStore;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.collection.PersistentCollection;
import java.util.Map;
@@ -57,20 +58,20 @@
return parentDiffs || mainDiffs;
}
- public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
- parentMapper.mapToEntityFromMap(obj, data, primaryKey, versionsReader, revision);
- main.mapToEntityFromMap(obj, data, primaryKey, versionsReader, revision);
+ public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
+ parentMapper.mapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision);
+ main.mapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision);
}
- public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
PersistentCollection newColl,
Serializable oldColl,
Serializable id) {
- List<PersistentCollectionChangeData> collectionChanges = parentMapper.mapCollectionChangesFromCollections(
+ List<PersistentCollectionChangeData> collectionChanges = parentMapper.mapCollectionChanges(
referencingPropertyName, newColl, oldColl, id);
if (collectionChanges == null) {
- return main.mapCollectionChangesFromCollections(referencingPropertyName, newColl, oldColl, id);
+ return main.mapCollectionChanges(referencingPropertyName, newColl, oldColl, id);
} else {
return collectionChanges;
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -26,6 +26,7 @@
import org.hibernate.criterion.Conjunction;
import java.util.Set;
+import java.util.Iterator;
/**
* @author Adam Warski (adam at warski dot org)
@@ -50,6 +51,71 @@
}
}
+ public String getIdsEqualQuery(String prefix1, String prefix2) {
+ Set<QueryParameterData> paramDatas = mapToQueryParametersFromId(null);
+
+ StringBuilder query = new StringBuilder();
+
+ Iterator<QueryParameterData> paramDataIter = paramDatas.iterator();
+
+ while (paramDataIter.hasNext()) {
+ QueryParameterData paramData = paramDataIter.next();
+ query.append(paramData.getProperty(prefix1)).append(" = ").append(paramData.getProperty(prefix2));
+ if (paramDataIter.hasNext()) {
+ query.append(" AND ");
+ }
+ }
+
+ return query.toString();
+ }
+
+ public String getIdsEqualQuery(String prefix1, IdMapper mapper2, String prefix2) {
+ Set<QueryParameterData> paramDatas1 = mapToQueryParametersFromId(null);
+ Set<QueryParameterData> paramDatas2 = mapper2.mapToQueryParametersFromId(null);
+
+ StringBuilder query = new StringBuilder();
+
+ Iterator<QueryParameterData> paramDataIter1 = paramDatas1.iterator();
+ Iterator<QueryParameterData> paramDataIter2 = paramDatas2.iterator();
+ while (paramDataIter1.hasNext()) {
+ QueryParameterData paramData1 = paramDataIter1.next();
+ QueryParameterData paramData2 = paramDataIter2.next();
+ query.append(paramData1.getProperty(prefix1)).append(" = ").append(paramData2.getProperty(prefix2));
+
+ if (paramDataIter1.hasNext()) {
+ query.append(" AND ");
+ }
+ }
+
+ return query.toString();
+ }
+
+ public String getIdEqualsQuery(String prefix, boolean equals) {
+ Set<QueryParameterData> paramDatas = mapToQueryParametersFromId(null);
+
+ StringBuilder query = new StringBuilder();
+
+ Iterator<QueryParameterData> paramDataIter = paramDatas.iterator();
+
+ while (paramDataIter.hasNext()) {
+ QueryParameterData paramData = paramDataIter.next();
+
+ query.append(paramData.getProperty(prefix));
+ if (equals) {
+ query.append(" = ");
+ } else {
+ query.append(" != ");
+ }
+ query.append(":").append(paramData.getQueryParameterName());
+
+ if (paramDataIter.hasNext()) {
+ query.append(" AND ");
+ }
+ }
+
+ return query.toString();
+ }
+
public Criterion getIdEqualsCriterion(Object id, String prefix, boolean equals) {
Set<QueryParameterData> paramDatas = mapToQueryParametersFromId(id);
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -65,6 +65,15 @@
public Criterion getIdsEqualCriterion(String prefix1, String prefix2);
/**
+ * Gets a query string, which contains equalities, which express the property that the id of the entity
+ * with alias prefix1, is equal to the id of the entity with alias prefix2 (the entity is the same).
+ * @param prefix1 First alias of the entity.
+ * @param prefix2 Second alias of the entity.
+ * @return A query string expressing the property described above.
+ */
+ public String getIdsEqualQuery(String prefix1, String prefix2);
+
+ /**
* Gets a criteria object, which contains restrictions, which express the property that the id of the entity
* with alias prefix, is equal to the given object.
* @param id Value of id.
@@ -73,4 +82,26 @@
* @return A criterion object expressing the property described above.
*/
public Criterion getIdEqualsCriterion(Object id, String prefix, boolean equals);
+
+ /**
+ * Gets a query string, which contains equalities, which express the property that the id of the entity
+ * with alias prefix, is equal to some values (which are left to be specified later, by specifiying parameter
+ * values)
+ * @param prefix Alias of the entity (may be null).
+ * @param equals Should this query express the "=" relation or the "<>" relation.
+ * @return A query string expressing the property described above.
+ */
+ public String getIdEqualsQuery(String prefix, boolean equals);
+
+ /**
+ * Gets a query string, which contains equalities, which express the property that the id of the entity
+ * with alias prefix1, is equal to the id of the entity with alias prefix2, mapped by the second mapper
+ * (the second mapper must be for the same entity, but it can have, for example, prefixed properties).
+ * @param prefix1 First alias of the entity.
+ * @param mapper2 Second mapper for the same entity, which will be used to get properties for the right side
+ * of the equation.
+ * @param prefix2 Second alias of the entity.
+ * @return A query string expressing the property described above.
+ */
+ public String getIdsEqualQuery(String prefix1, IdMapper mapper2, String prefix2);
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/QueryParameterData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/QueryParameterData.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/QueryParameterData.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -21,6 +21,8 @@
*/
package org.jboss.envers.entities.mapper.id;
+import org.hibernate.Query;
+
/**
* @author Adam Warski (adam at warski dot org)
*/
@@ -44,4 +46,28 @@
public Object getValue() {
return value;
}
+
+ public void setParameterValue(Query query) {
+ query.setParameter(flatEntityPropertyName, value);
+ }
+
+ public String getQueryParameterName() {
+ return flatEntityPropertyName;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof QueryParameterData)) return false;
+
+ QueryParameterData that = (QueryParameterData) o;
+
+ if (flatEntityPropertyName != null ? !flatEntityPropertyName.equals(that.flatEntityPropertyName) : that.flatEntityPropertyName != null)
+ return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return (flatEntityPropertyName != null ? flatEntityPropertyName.hashCode() : 0);
+ }
}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -0,0 +1,58 @@
+package org.jboss.envers.entities.mapper.relation;
+
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.tools.reflection.ReflectionTools;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.ListProxy;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.SetProxy;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
+import org.jboss.envers.entities.mapper.PropertyMapper;
+import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
+import org.hibernate.property.Getter;
+import org.hibernate.property.Setter;
+
+import java.util.*;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public abstract class AbstractOneToManyMapper implements PropertyMapper {
+ private final String owningEntityName;
+ private final String propertyName;
+
+ protected AbstractOneToManyMapper(String owningEntityName, String propertyName) {
+ this.owningEntityName = owningEntityName;
+ this.propertyName = propertyName;
+ }
+
+ protected abstract <T extends Collection> Initializor<T> getInitializator(VersionsConfiguration verCfg,
+ VersionsReaderImplementor versionsReader,
+ Class<?> entityClass, Object primaryKey,
+ Number revision, Class<T> collectionClass);
+
+ @SuppressWarnings({"unchecked"})
+ public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey,
+ VersionsReaderImplementor versionsReader, Number revision) {
+ if (obj == null) {
+ return;
+ }
+
+ Class<?> entityClass = ReflectionTools.loadClass(owningEntityName);
+
+ Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyName);
+ Class collectionClass = getter.getReturnType();
+
+ // todo: investigate generics
+ Object value;
+ if (List.class.isAssignableFrom(collectionClass)) {
+ value = new ListProxy(getInitializator(verCfg, versionsReader, entityClass, primaryKey, revision, ArrayList.class));
+ } else if (Set.class.isAssignableFrom(collectionClass) || Collection.class.isAssignableFrom(collectionClass)) {
+ value = new SetProxy(getInitializator(verCfg, versionsReader, entityClass, primaryKey, revision, HashSet.class));
+ } else {
+ throw new VersionsException("Unsupported versioned collection type: " + collectionClass.getName());
+ }
+
+ Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyName);
+ setter.set(obj, value, null);
+ }
+}
Copied: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyBidirectionalMapper.java (from rev 115, trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyIdMapper.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyBidirectionalMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyBidirectionalMapper.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -0,0 +1,64 @@
+/*
+ * 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.entities.mapper.relation;
+
+import org.jboss.envers.entities.mapper.PropertyMapper;
+import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.entities.mapper.relation.lazy.OneToManyBidirectionalInitializor;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
+import org.jboss.envers.configuration.VersionsConfiguration;
+import org.hibernate.collection.PersistentCollection;
+
+import java.util.*;
+import java.io.Serializable;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class OneToManyBidirectionalMapper extends AbstractOneToManyMapper implements PropertyMapper {
+ private final String owningReferencePropertyName;
+
+ public OneToManyBidirectionalMapper(String owningReferencePropertyName, String owningEntityName, String propertyName) {
+ super(owningEntityName, propertyName);
+
+ this.owningReferencePropertyName = owningReferencePropertyName;
+ }
+
+ public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj) {
+ return false;
+ }
+
+ protected <T extends Collection> Initializor<T> getInitializator(VersionsConfiguration verCfg,
+ VersionsReaderImplementor versionsReader,
+ Class<?> entityClass, Object primaryKey,
+ Number revision,
+ Class<T> collectionClass) {
+ return new OneToManyBidirectionalInitializor<T>(versionsReader, entityClass, owningReferencePropertyName, primaryKey,
+ revision, collectionClass);
+ }
+
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName, PersistentCollection newColl,
+ Serializable oldColl, Serializable id) {
+ return null;
+ }
+}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyUnidirectionalMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyUnidirectionalMapper.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyUnidirectionalMapper.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -2,9 +2,12 @@
import org.jboss.envers.entities.mapper.PropertyMapper;
import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
+import org.jboss.envers.entities.mapper.relation.lazy.OneToManyUnidirectionalInitializor;
import org.jboss.envers.entities.mapper.id.IdMapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.RevisionType;
import org.hibernate.collection.PersistentCollection;
@@ -14,24 +17,34 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class OneToManyUnidirectionalMapper implements PropertyMapper {
+public class OneToManyUnidirectionalMapper extends AbstractOneToManyMapper implements PropertyMapper {
private final VersionsEntitiesConfiguration verEntCfg;
+ private final String referencedEntityName;
private final String collectionReferencingPropertyName;
- private final String referencedEntityName;
+ private final String versionsReferencedEntityName;
private final String versionsMiddleEntityName;
private final IdMapper referencingMiddleIdMapper;
private final IdMapper referencedMiddleIdMapper;
- public OneToManyUnidirectionalMapper(VersionsEntitiesConfiguration verEntCfg,
- String collectionReferencingPropertyName,
- String referencedEntityName, String versionsMiddleEntityName,
- IdMapper referencingMiddleIdMapper, IdMapper referencedMiddleIdMapper) {
+ private final UnidirectionalRelationQueryGenerator queryGenerator;
+
+ public OneToManyUnidirectionalMapper(VersionsEntitiesConfiguration verEntCfg, String referencingEntityName,
+ String referencedEntityName, String collectionReferencingPropertyName,
+ String versionsReferencedEntityName, String versionsMiddleEntityName,
+ IdMapper referencingMiddleIdMapper, IdMapper referencedMiddleIdMapper,
+ IdMapper referencedIdMapper) {
+ super(referencingEntityName, collectionReferencingPropertyName);
+
this.verEntCfg = verEntCfg;
+ this.referencedEntityName = referencedEntityName;
this.collectionReferencingPropertyName = collectionReferencingPropertyName;
- this.referencedEntityName = referencedEntityName;
+ this.versionsReferencedEntityName = versionsReferencedEntityName;
this.versionsMiddleEntityName = versionsMiddleEntityName;
this.referencingMiddleIdMapper = referencingMiddleIdMapper;
this.referencedMiddleIdMapper = referencedMiddleIdMapper;
+
+ queryGenerator = new UnidirectionalRelationQueryGenerator(verEntCfg, versionsReferencedEntityName,
+ versionsMiddleEntityName, referencingMiddleIdMapper, referencedMiddleIdMapper, referencedIdMapper);
}
private Collection getOldCollection(Serializable oldColl) {
@@ -60,10 +73,9 @@
}
@SuppressWarnings({"unchecked"})
- public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
- PersistentCollection newColl,
- Serializable oldColl,
- Serializable id) {
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl, Serializable id) {
if (!collectionReferencingPropertyName.equals(referencingPropertyName)) {
return null;
}
@@ -90,10 +102,15 @@
@SuppressWarnings({"unchecked"})
public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj) {
+ // Changes are mapped in the "mapCollectionChanges" method.
return false;
}
- public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
- System.out.println("XXX");
+ protected <T extends Collection> Initializor<T> getInitializator(VersionsConfiguration verCfg,
+ VersionsReaderImplementor versionsReader,
+ Class<?> entityClass, Object primaryKey,
+ Number revision, Class<T> collectionClass) {
+ return new OneToManyUnidirectionalInitializor<T>(verCfg, referencedEntityName, queryGenerator,
+ versionsReader, primaryKey, revision, collectionClass);
}
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneIdMapper.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneIdMapper.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -27,6 +27,7 @@
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.query.VersionsRestrictions;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.property.Setter;
import org.hibernate.NonUniqueResultException;
import org.hibernate.collection.PersistentCollection;
@@ -54,7 +55,7 @@
return false;
}
- public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
+ public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
if (obj == null) {
return;
}
@@ -77,7 +78,7 @@
setter.set(obj, value, null);
}
- public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
PersistentCollection newColl,
Serializable oldColl,
Serializable id) {
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -28,6 +28,7 @@
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.property.Setter;
import org.hibernate.collection.PersistentCollection;
@@ -59,7 +60,7 @@
return !Tools.objectsEqual(newObj, oldObj);
}
- public void mapToEntityFromMap(Object obj, Map data, Object primaryKey,
+ public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey,
VersionsReaderImplementor versionsReader, Number revision) {
if (obj == null) {
return;
@@ -80,7 +81,7 @@
setter.set(obj, value, null);
}
- public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
PersistentCollection newColl,
Serializable oldColl,
Serializable id) {
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/UnidirectionalRelationQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/UnidirectionalRelationQueryGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/UnidirectionalRelationQueryGenerator.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -0,0 +1,93 @@
+package org.jboss.envers.entities.mapper.relation;
+
+import org.jboss.envers.entities.mapper.id.QueryParameterData;
+import org.jboss.envers.entities.mapper.id.IdMapper;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.RevisionType;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.hibernate.Query;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class UnidirectionalRelationQueryGenerator {
+ private final String queryString;
+ private final IdMapper referencingMiddleIdMapper;
+
+ public UnidirectionalRelationQueryGenerator(VersionsEntitiesConfiguration verEntCfg,
+ String versionsReferencedEntityName, String versionsMiddleEntityName,
+ IdMapper referencingMiddleIdMapper, IdMapper referencedMiddleIdMapper,
+ IdMapper referencedIdMapper) {
+ this.referencingMiddleIdMapper = referencingMiddleIdMapper;
+
+ /*
+ * The query that we need to create:
+ * SELECT e FROM versionsReferencedEntity e, middleEntity ee
+ * WHERE
+ * (selecting e entities at revision :revision)
+ * e.revision = (SELECT max(e2.revision) FROM referencedEntity e2
+ * WHERE e2.revision <= :revision AND e2.id1 = e.id1) AND
+ * (only entities referenced by the association)
+ * ee.id1 = e.id1 AND
+ * ee.id2 = :id2 AND
+ * (the association at revision :revision)
+ * ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2
+ * WHERE ee2.revision <= :revision AND ee2.id2 = :id2 AND ee2.id1 = ee.id1) AND
+ * (only non-deleted entities and associations)
+ * ee.revision_type != DEL AND
+ * e.revision_type != DEL
+ */
+ String revisionPropertyPath = verEntCfg.getRevisionPropPath();
+ String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
+
+ StringBuilder querySB = new StringBuilder();
+ querySB
+ .append("SELECT e FROM ").append(versionsReferencedEntityName).append(" e")
+ .append(", ").append(versionsMiddleEntityName).append(" ee ")
+ .append("WHERE ")
+ // e.revision = (SELECT max(e2.revision) ...
+ .append("e.").append(revisionPropertyPath).append(" = (SELECT max(e2.").append(revisionPropertyPath)
+ .append(") FROM ").append(versionsReferencedEntityName).append(" e2 ")
+ // e2.revision <= :revision
+ .append("WHERE e2.").append(revisionPropertyPath).append(" <= :revision AND ")
+ // e2.id1 = e.id1)
+ .append(referencedIdMapper.getIdsEqualQuery("e." + originalIdPropertyName, "e2." + originalIdPropertyName))
+ .append(") AND ")
+ // ee.id1 = e.id1
+ .append(referencedMiddleIdMapper.getIdsEqualQuery("ee." + originalIdPropertyName,
+ referencedIdMapper, "e." + originalIdPropertyName))
+ .append(" AND ")
+ // ee.id2 = :id2
+ .append(referencingMiddleIdMapper.getIdEqualsQuery("ee." + originalIdPropertyName, true))
+ .append(" AND ")
+ // ee.revision = (SELECT max(ee2.revision) ...
+ .append("ee.").append(revisionPropertyPath).append(" = (SELECT max(ee2.").append(revisionPropertyPath)
+ .append(") FROM ").append(versionsMiddleEntityName).append(" ee2 ")
+ // ee2.revision <= :revision
+ .append("WHERE ee2.").append(revisionPropertyPath).append(" <= :revision AND ")
+ // ee2.id2 = :id2)
+ .append(referencingMiddleIdMapper.getIdEqualsQuery("ee2." + originalIdPropertyName, true))
+ .append(" AND ")
+ // ee2.id1 = ee.id1)
+ .append(referencedMiddleIdMapper.getIdsEqualQuery("ee." + originalIdPropertyName, "ee2." + originalIdPropertyName))
+ .append(") AND ")
+ // e.revision_type != DEL AND
+ .append("e.").append(verEntCfg.getRevisionTypePropName()).append(" != ").append(":delrevisiontype")
+ .append(" AND ")
+ // ee.revision_type != DEL
+ .append("ee.").append(verEntCfg.getRevisionTypePropName()).append(" != ").append(":delrevisiontype");
+
+ queryString = querySB.toString();
+ }
+
+ public Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey, Number revision) {
+ Query query = versionsReader.getSession().createQuery(queryString);
+ query.setParameter("revision", revision);
+ query.setParameter("delrevisiontype", RevisionType.DEL);
+ for (QueryParameterData paramData: referencingMiddleIdMapper.mapToQueryParametersFromId(primaryKey)) {
+ paramData.setParameterValue(query);
+ }
+
+ return query;
+ }
+}
Copied: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyBidirectionalInitializor.java (from rev 113, trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyInitializor.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyBidirectionalInitializor.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyBidirectionalInitializor.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -0,0 +1,74 @@
+/*
+ * 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.entities.mapper.relation.lazy;
+
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
+import org.jboss.envers.query.VersionsRestrictions;
+import org.jboss.envers.exception.VersionsException;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class OneToManyBidirectionalInitializor<T extends Collection> implements Initializor<T> {
+ private VersionsReaderImplementor versionsReader;
+ private Class<?> entityClass;
+ private String owningReferencePropertyName;
+ private Object primaryKey;
+ private Number revision;
+ private Class<T> collectionClass;
+
+ public OneToManyBidirectionalInitializor(VersionsReaderImplementor versionsReader, Class<?> entityClass,
+ String owningReferencePropertyName, Object primaryKey, Number revision,
+ Class<T> collectionClass) {
+ this.versionsReader = versionsReader;
+ this.entityClass = entityClass;
+ this.owningReferencePropertyName = owningReferencePropertyName;
+ this.primaryKey = primaryKey;
+ this.revision = revision;
+ this.collectionClass = collectionClass;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public T initialize() {
+ List queryResult = versionsReader.createQuery().forEntitiesAtRevision(entityClass, revision)
+ .add(VersionsRestrictions.relatedIdEq(owningReferencePropertyName, primaryKey)).getResultList();
+
+ if (collectionClass.isAssignableFrom(queryResult.getClass())) {
+ return (T) queryResult;
+ } else {
+ Collection result;
+ try {
+ result = collectionClass.newInstance();
+ } catch (Exception e) {
+ throw new VersionsException(e);
+ }
+
+ result.addAll(queryResult);
+
+ return (T) result;
+ }
+ }
+}
Deleted: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyInitializor.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyInitializor.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -1,74 +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.entities.mapper.relation.lazy;
-
-import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
-import org.jboss.envers.query.VersionsRestrictions;
-import org.jboss.envers.exception.VersionsException;
-
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class OneToManyInitializor<T extends Collection> implements Initializor<T> {
- private VersionsReaderImplementor versionsReader;
- private Class<?> entityClass;
- private String owningReferencePropertyName;
- private Object primaryKey;
- private Number revision;
- private Class<T> collectionClass;
-
- public OneToManyInitializor(VersionsReaderImplementor versionsReader, Class<?> entityClass,
- String owningReferencePropertyName, Object primaryKey, Number revision,
- Class<T> collectionClass) {
- this.versionsReader = versionsReader;
- this.entityClass = entityClass;
- this.owningReferencePropertyName = owningReferencePropertyName;
- this.primaryKey = primaryKey;
- this.revision = revision;
- this.collectionClass = collectionClass;
- }
-
- @SuppressWarnings({"unchecked"})
- public T initialize() {
- List queryResult = versionsReader.createQuery().forEntitiesAtRevision(entityClass, revision)
- .add(VersionsRestrictions.relatedIdEq(owningReferencePropertyName, primaryKey)).getResultList();
-
- if (collectionClass.isAssignableFrom(queryResult.getClass())) {
- return (T) queryResult;
- } else {
- Collection result;
- try {
- result = collectionClass.newInstance();
- } catch (Exception e) {
- throw new VersionsException(e);
- }
-
- result.addAll(queryResult);
-
- return (T) result;
- }
- }
-}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyUnidirectionalInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyUnidirectionalInitializor.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyUnidirectionalInitializor.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -0,0 +1,55 @@
+package org.jboss.envers.entities.mapper.relation.lazy;
+
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
+import org.jboss.envers.entities.mapper.relation.UnidirectionalRelationQueryGenerator;
+import org.jboss.envers.entities.EntityInstantiator;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class OneToManyUnidirectionalInitializor<T extends Collection> implements Initializor<T> {
+ private final VersionsConfiguration verCfg;
+ private final String entityName;
+ private final UnidirectionalRelationQueryGenerator queryGenerator;
+ private final VersionsReaderImplementor versionsReader;
+ private final Object primaryKey;
+ private final Number revision;
+ private final Class<T> collectionClass;
+
+ public OneToManyUnidirectionalInitializor(VersionsConfiguration verCfg, String entityName,
+ UnidirectionalRelationQueryGenerator queryGenerator,
+ VersionsReaderImplementor versionsReader, Object primaryKey,
+ Number revision, Class<T> collectionClass) {
+ this.verCfg = verCfg;
+ this.entityName = entityName;
+ this.queryGenerator = queryGenerator;
+ this.versionsReader = versionsReader;
+ this.primaryKey = primaryKey;
+ this.revision = revision;
+ this.collectionClass = collectionClass;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public T initialize() {
+ EntityInstantiator entityInstantiator = new EntityInstantiator(verCfg, versionsReader);
+
+ List queryResult = queryGenerator.getQuery(versionsReader, primaryKey, revision).list();
+
+ T result;
+ try {
+ result = collectionClass.newInstance();
+ } catch (Exception e) {
+ throw new VersionsException(e);
+ }
+
+ entityInstantiator.addInstancesFromVersionsEntities(entityName, result, queryResult, revision);
+
+ return result;
+ }
+}
Modified: trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -26,19 +26,16 @@
import org.jboss.envers.query.impl.RevisionsOfEntityQuery;
import static org.jboss.envers.tools.ArgumentsTools.*;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.hibernate.Session;
/**
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsQueryCreator {
private final VersionsConfiguration verCfg;
- private final Session session;
private final VersionsReaderImplementor versionsReaderImplementor;
- public VersionsQueryCreator(VersionsConfiguration verCfg, Session session, VersionsReaderImplementor versionsReaderImplementor) {
+ public VersionsQueryCreator(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReaderImplementor) {
this.verCfg = verCfg;
- this.session = session;
this.versionsReaderImplementor = versionsReaderImplementor;
}
@@ -54,7 +51,7 @@
public VersionsQuery forEntitiesAtRevision(Class<?> c, Number revision) {
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
- return new EntitiesAtRevisionQuery(verCfg, session, versionsReaderImplementor, c, revision);
+ return new EntitiesAtRevisionQuery(verCfg, versionsReaderImplementor, c, revision);
}
/**
@@ -73,6 +70,6 @@
* unless an order or projection is added.
*/
public VersionsQuery forRevisionsOfEntity(Class<?> c, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
- return new RevisionsOfEntityQuery(verCfg, session, versionsReaderImplementor, c, selectEntitiesOnly,selectDeletedEntities);
+ return new RevisionsOfEntityQuery(verCfg, versionsReaderImplementor, c, selectEntitiesOnly,selectDeletedEntities);
}
}
Modified: trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -55,8 +55,8 @@
protected final VersionsConfiguration verCfg;
- protected AbstractVersionsQuery(VersionsConfiguration verCfg, Session session,
- VersionsReaderImplementor versionsReader, Class<?> cls) {
+ protected AbstractVersionsQuery(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader,
+ Class<?> cls) {
this.verCfg = verCfg;
criterions = new ArrayList<VersionsCriterion>();
@@ -64,7 +64,7 @@
entityName = cls.getName();
versionsEntityName = verCfg.getVerEntCfg().getVersionsEntityName(entityName);
- versionsCriteria = session.createCriteria(versionsEntityName, "e");
+ versionsCriteria = versionsReader.getSession().createCriteria(versionsEntityName, "e");
}
public abstract List list() throws VersionsException;
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -27,7 +27,6 @@
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.criterion.*;
-import org.hibernate.Session;
import java.util.List;
import java.util.ArrayList;
@@ -38,10 +37,10 @@
public class EntitiesAtRevisionQuery extends AbstractVersionsQuery {
private final Number revision;
- public EntitiesAtRevisionQuery(VersionsConfiguration verCfg, Session session,
+ public EntitiesAtRevisionQuery(VersionsConfiguration verCfg,
VersionsReaderImplementor versionsReader, Class<?> cls,
Number revision) {
- super(verCfg, session, versionsReader, cls);
+ super(verCfg, versionsReader, cls);
this.revision = revision;
}
Modified: trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -29,7 +29,6 @@
import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Property;
-import org.hibernate.Session;
import java.util.List;
import java.util.ArrayList;
@@ -42,11 +41,11 @@
private final boolean selectEntitiesOnly;
private final boolean selectDeletedEntities;
- public RevisionsOfEntityQuery(VersionsConfiguration verCfg, Session session,
+ public RevisionsOfEntityQuery(VersionsConfiguration verCfg,
VersionsReaderImplementor versionsReader,
Class<?> cls, boolean selectEntitiesOnly,
boolean selectDeletedEntities) {
- super(verCfg, session, versionsReader, cls);
+ super(verCfg, versionsReader, cls);
this.selectEntitiesOnly = selectEntitiesOnly;
this.selectDeletedEntities = selectDeletedEntities;
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -64,6 +64,10 @@
return sessionImplementor;
}
+ public Session getSession() {
+ return session;
+ }
+
@SuppressWarnings({"unchecked"})
public <T> T find(Class<T> cls, Object primaryKey, Number revision) throws
IllegalArgumentException, NotVersionedException, IllegalStateException {
@@ -170,6 +174,6 @@
}
public VersionsQueryCreator createQuery() {
- return new VersionsQueryCreator(verCfg, session, this);
+ return new VersionsQueryCreator(verCfg, this);
}
}
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -22,6 +22,7 @@
package org.jboss.envers.reader;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.Session;
import org.jboss.envers.VersionsReader;
/**
@@ -30,4 +31,5 @@
*/
public interface VersionsReaderImplementor extends VersionsReader {
SessionImplementor getSessionImplementor();
+ Session getSession();
}
Deleted: trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -1,78 +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.synchronization.work;
-
-import org.hibernate.Session;
-import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.RevisionType;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class CollectionChangeWorkUnit extends AbstractVersionsWorkUnit implements VersionsWorkUnit {
- private final Object entity;
-
- public CollectionChangeWorkUnit(String entityName, VersionsConfiguration verCfg, Serializable id, Object entity) {
- super(entityName, verCfg, id);
-
- this.entity = entity;
- }
-
- public boolean containsWork() {
- return true;
- }
-
- public void perform(Session session, Number revision) {
- Map<String, Object> data = new HashMap<String, Object>();
- fillDataWithId(data, revision, RevisionType.MOD);
-
- verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().mapToMapFromEntity(data, entity, null);
-
- session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()), data);
-
- setPerformed(data);
- }
-
- public KeepCheckResult check(AddWorkUnit second) {
- return KeepCheckResult.SECOND;
- }
-
- public KeepCheckResult check(ModWorkUnit second) {
- return KeepCheckResult.SECOND;
- }
-
- public KeepCheckResult check(DelWorkUnit second) {
- return KeepCheckResult.SECOND;
- }
-
- public KeepCheckResult check(CollectionChangeWorkUnit second) {
- return KeepCheckResult.FIRST;
- }
-
- public KeepCheckResult dispatch(KeepCheckVisitor first) {
- return first.check(this);
- }
-}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -24,7 +24,7 @@
String referencingPropertyName = role.substring(entityName.length() + 1);
collectionChanges = verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
- .mapCollectionChangesFromCollections(referencingPropertyName, collection, snapshot, id);
+ .mapCollectionChanges(referencingPropertyName, collection, snapshot, id);
}
public boolean containsWork() {
Modified: trunk/src/main/org/jboss/envers/tools/StringTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/StringTools.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/main/org/jboss/envers/tools/StringTools.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -28,4 +28,17 @@
public static boolean isEmpty(String s) {
return s == null || "".equals(s);
}
+
+ public static String getLastComponent(String s) {
+ if (s == null) {
+ return null;
+ }
+
+ int lastDot = s.lastIndexOf(".");
+ if (lastDot == -1) {
+ return s;
+ } else {
+ return s.substring(lastDot + 1);
+ }
+ }
}
Modified: trunk/src/test/org/jboss/envers/test/working/WorkingMain.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/working/WorkingMain.java 2008-08-20 11:44:45 UTC (rev 115)
+++ trunk/src/test/org/jboss/envers/test/working/WorkingMain.java 2008-08-21 10:19:09 UTC (rev 116)
@@ -116,6 +116,12 @@
entityManager.getTransaction().begin();
VersionsReader vr = VersionsReaderFactory.get(entityManager);
+ System.out.println("1 " + vr.find(WorkingEntity2.class, we2.getId2(), 1).getWe1s());
+ System.out.println("2 " + vr.find(WorkingEntity2.class, we2.getId2(), 2).getWe1s());
+ System.out.println("3 " + vr.find(WorkingEntity2.class, we2.getId2(), 3).getWe1s());
+ System.out.println("4 " + vr.find(WorkingEntity2.class, we2.getId2(), 4).getWe1s());
+ System.out.println("5 " + vr.find(WorkingEntity2.class, we2.getId2(), 5).getWe1s());
+ System.out.println("6 " + vr.find(WorkingEntity2.class, we2.getId2(), 6).getWe1s());
entityManager.getTransaction().commit();
}
16 years, 4 months
JBoss Envers SVN: r115 - in trunk: src/main/org/jboss/envers/configuration and 7 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-20 07:44:45 -0400 (Wed, 20 Aug 2008)
New Revision: 115
Added:
trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyUnidirectionalMapper.java
trunk/src/main/org/jboss/envers/synchronization/work/BidirectionalCollectionChangeWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
Modified:
trunk/resources/test/hibernate.test.cfg.xml
trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/SubclassPropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java
trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java
trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/KeepCheckVisitor.java
trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java
trunk/src/test/org/jboss/envers/test/working/WorkingEntity1.java
trunk/src/test/org/jboss/envers/test/working/WorkingEntity2.java
trunk/src/test/org/jboss/envers/test/working/WorkingMain.java
Log:
ENVERS-26: storing changes in unidirectional one-to-many associations, set valued
Modified: trunk/resources/test/hibernate.test.cfg.xml
===================================================================
--- trunk/resources/test/hibernate.test.cfg.xml 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/resources/test/hibernate.test.cfg.xml 2008-08-20 11:44:45 UTC (rev 115)
@@ -24,5 +24,14 @@
<event type="post-delete">
<listener class="org.jboss.envers.event.VersionsEventListener" />
</event>
+ <event type="pre-collection-update">
+ <listener class="org.jboss.envers.event.VersionsEventListener" />
+ </event>
+ <event type="pre-collection-remove">
+ <listener class="org.jboss.envers.event.VersionsEventListener" />
+ </event>
+ <event type="post-collection-recreate">
+ <listener class="org.jboss.envers.event.VersionsEventListener" />
+ </event>
</session-factory>
</hibernate-configuration>
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -68,14 +68,14 @@
versionsMetaGen.generateSecondPass(pc, pcDatas.get(pc), mappingData);
- //TODO
- //writeDocument(document);
try {
cfg.addDocument(writer.write(mappingData.getMainMapping()));
+ writeDocument(mappingData.getMainMapping());
for (Document additionalMapping : mappingData.getAdditionalMappings()) {
- cfg.addDocument(writer.write(additionalMapping));
+ cfg.addDocument(writer.write(additionalMapping));
+ writeDocument(additionalMapping);
}
} catch (DocumentException e) {
throw new MappingException(e);
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -67,6 +67,7 @@
String tableName, String schema, String catalog,
String discriminatorValue) {
Element hibernate_mapping = document.addElement("hibernate-mapping");
+ hibernate_mapping.addAttribute("auto-import", "false");
Element class_mapping = hibernate_mapping.addElement(type);
class_mapping.addAttribute("entity-name", entityName);
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -21,10 +21,11 @@
*/
package org.jboss.envers.configuration.metadata;
-import org.hibernate.mapping.*;
import org.hibernate.type.*;
import org.hibernate.util.StringHelper;
import org.hibernate.MappingException;
+import org.hibernate.mapping.*;
+import org.hibernate.mapping.Collection;
import org.dom4j.Element;
import org.dom4j.Attribute;
import org.dom4j.tree.DefaultElement;
@@ -37,6 +38,7 @@
import org.jboss.envers.entities.mapper.relation.ToOneIdMapper;
import org.jboss.envers.entities.mapper.relation.OneToOneIdMapper;
import org.jboss.envers.entities.mapper.relation.OneToManyIdMapper;
+import org.jboss.envers.entities.mapper.relation.OneToManyUnidirectionalMapper;
import org.jboss.envers.tools.StringTools;
import org.jboss.envers.tools.Tools;
import org.jboss.envers.tools.HibernateVersion;
@@ -45,10 +47,9 @@
import org.jboss.envers.tools.log.YLogManager;
import org.jboss.envers.exception.VersionsException;
-import java.util.Iterator;
+import java.util.*;
+import java.util.List;
import java.util.Map;
-import java.util.Collections;
-import java.util.HashMap;
/**
* @author Adam Warski (adam at warski dot org)
@@ -87,6 +88,18 @@
}
}
+ private void addRevisionNumber(Element any_mapping) {
+ Element rev_mapping = MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionPropName(),
+ verEntCfg.getRevisionPropType(), true);
+ MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionPropName(), null);
+ }
+
+ private void addRevisionType(Element any_mapping) {
+ Element revTypeProperty = MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionTypePropName(),
+ verEntCfg.getRevisionTypePropType(), false);
+ revTypeProperty.addAttribute("type", "org.jboss.envers.entities.RevisionTypeType");
+ }
+
@SuppressWarnings({"unchecked"})
private void addSimpleProperty(Element parent, Property property, SimpleMapperBuilder mapper,
ModificationStore store, boolean key) {
@@ -126,7 +139,7 @@
@SuppressWarnings({"unchecked"})
private void addComponent(Element parent, Property property, CompositeMapperBuilder mapper, ModificationStore store,
- String entityName, boolean firstPass) {
+ String entityName, EntityMappingData mappingData, boolean firstPass) {
Element component_mapping = null;
Component prop_component = (Component) property.getValue();
@@ -153,7 +166,7 @@
addProperties(component_mapping, (Iterator<Property>) prop_component.getPropertyIterator(),
mapper.addComposite(property.getName()), new PropertyStoreInfo(store, EMPTY_STORE), entityName,
- firstPass);
+ mappingData, firstPass);
}
@SuppressWarnings({"unchecked"})
@@ -172,7 +185,8 @@
}
@SuppressWarnings({"unchecked"})
- private void prefixNamesInPropertyElement(Element element, String prefix, Iterator<Column> columnIterator) {
+ private void prefixNamesInPropertyElement(Element element, String prefix, Iterator<Column> columnIterator,
+ boolean changeToKey) {
Iterator<Element> properties = element.elementIterator();
while (properties.hasNext()) {
Element property = properties.next();
@@ -184,6 +198,10 @@
}
changeNamesInColumnElement(property, columnIterator);
+
+ if (changeToKey) {
+ property.setName("key-property");
+ }
}
}
}
@@ -212,7 +230,7 @@
Element properties = (Element) idMapping.getXmlRelationMapping().clone();
properties.addAttribute("name", propertyName);
- prefixNamesInPropertyElement(properties, lastPropertyPrefix, property.getValue().getColumnIterator());
+ prefixNamesInPropertyElement(properties, lastPropertyPrefix, property.getValue().getColumnIterator(), false);
parent.add(properties);
// Adding mapper for the id
@@ -302,7 +320,8 @@
}
@SuppressWarnings({"unchecked"})
- private void addOneToManyUnidirectional(Property property, CompositeMapperBuilder mapper, String entityName) {
+ private void addOneToManyUnidirectional(Property property, CompositeMapperBuilder mapper, String entityName,
+ EntityMappingData mappingData) {
Collection propertyValue = (Collection) property.getValue();
ManyToOne mto = (ManyToOne) propertyValue.getElement();
@@ -321,12 +340,45 @@
IdMappingData referencingIdMapping = configuration.getIdMappingData();
IdMappingData referencedIdMapping = referencedConfiguration.getIdMappingData();
+ String referencingPrefix = entityName + "_";
+ String referencedPrefix = property.getName() + "_";
+
// Name of the entity that will be used to store the relation between the two entities.
- String middleEntityName = entityName + "_" + referencedEntityName;
+ String middleEntityName = referencingPrefix + referencedEntityName;
+ String versionsMiddleEntityName = verEntCfg.getVersionsEntityName(middleEntityName);
+ String versionsMiddleTableName = verEntCfg.getVersionsTableName(middleEntityName, mto.getTable().getName());
- MetadataTools.createEntity(null, middleEntityName, mto.getTable().getName(), mto.getTable().getSchema(),
- mto.getTable().getCatalog(), null);
+ Element middleEntity = MetadataTools.createEntity(mappingData.newAdditionalMapping(), versionsMiddleEntityName,
+ versionsMiddleTableName, mto.getTable().getSchema(), mto.getTable().getCatalog(), null);
+ Element middleEntityId = middleEntity.addElement("composite-id");
+ middleEntityId.addAttribute("name", verEntCfg.getOriginalIdPropName());
+
+ Iterator columnIterator = mto.getTable().getColumnIterator();
+
+ // Adding elements to the mapping corresponding to the referencing entity id's
+ Element properties = (Element) referencingIdMapping.getXmlRelationMapping().clone();
+ prefixNamesInPropertyElement(properties, referencingPrefix, columnIterator, true);
+ for (Element idProperty : (List<Element>) properties.elements()) {
+ middleEntityId.add((Element) idProperty.clone());
+ }
+
+ // Adding elements to the mapping corresponding to the referenced entity id's
+ properties = (Element) referencedIdMapping.getXmlRelationMapping().clone();
+ prefixNamesInPropertyElement(properties, referencedPrefix, columnIterator, true);
+ for (Element idProperty : (List<Element>) properties.elements()) {
+ middleEntityId.add((Element) idProperty.clone());
+ }
+
+ addRevisionNumber(middleEntityId);
+ addRevisionType(middleEntity);
+
+ // Adding the property mapper
+ mapper.addComposite(property.getName(), new OneToManyUnidirectionalMapper(verEntCfg, property.getName(),
+ referencedEntityName, versionsMiddleEntityName,
+ referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
+ referencedIdMapping.getIdMapper().prefixMappedProperties(referencedPrefix)));
+
// TODO: ???
}
@@ -363,7 +415,8 @@
@SuppressWarnings({"unchecked"})
private void addProperties(Element parent, Iterator<Property> properties, CompositeMapperBuilder currentMapper,
- PropertyStoreInfo propertyStoreInfo, String entityName, boolean firstPass) {
+ PropertyStoreInfo propertyStoreInfo, String entityName, EntityMappingData mappingData,
+ boolean firstPass) {
while (properties.hasNext()) {
Property property = properties.next();
Type propertyType = property.getType();
@@ -374,7 +427,7 @@
if (propertyType instanceof ComponentType) {
// only first pass
if (firstPass) {
- addComponent(parent, property, currentMapper, store, entityName, firstPass);
+ addComponent(parent, property, currentMapper, store, entityName, mappingData, firstPass);
}
} else if (propertyType instanceof ImmutableType || propertyType instanceof MutableType) {
// only first pass
@@ -420,7 +473,7 @@
((((Collection) property.getValue()).getElement() instanceof ManyToOne))) {
// only second pass
if (!firstPass) {
- addOneToManyUnidirectional(property, currentMapper, entityName);
+ addOneToManyUnidirectional(property, currentMapper, entityName, mappingData);
}
} else {
String message = "Type not supported for versioning: " + propertyType.getClass().getName() +
@@ -475,7 +528,7 @@
@SuppressWarnings({"unchecked"})
private void addJoins(PersistentClass pc, CompositeMapperBuilder currentMapper, PropertyStoreInfo propertyStoreInfo,
- String entityName, boolean firstPass) {
+ String entityName, EntityMappingData mappingData, boolean firstPass) {
Iterator<Join> joins = pc.getJoinIterator();
while (joins.hasNext()) {
@@ -483,7 +536,7 @@
Element joinElement = entitiesJoins.get(entityName).get(join);
addProperties(joinElement, join.getPropertyIterator(), currentMapper, propertyStoreInfo, entityName,
- firstPass);
+ mappingData, firstPass);
}
}
@@ -524,9 +577,7 @@
orig_id_mapping.addAttribute("name", verEntCfg.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);
+ addRevisionNumber(orig_id_mapping);
return new IdMappingData(mapper, orig_id_mapping, rel_id_mapping);
}
@@ -544,7 +595,7 @@
@SuppressWarnings({"unchecked"})
public void generateFirstPass(PersistentClass pc, PersistentClassVersioningData versioningData,
- EntityMappingData mappingData) {
+ EntityMappingData mappingData) {
String schema = versioningData.schema;
if (StringTools.isEmpty(schema)) {
schema = pc.getTable().getSchema();
@@ -588,9 +639,7 @@
class_mapping.add((Element) idMapper.getXmlMapping().clone());
// Adding the "revision type" property
- Element revTypeProperty = MetadataTools.addProperty(class_mapping, verEntCfg.getRevisionTypePropName(),
- verEntCfg.getRevisionTypePropType(), false);
- revTypeProperty.addAttribute("type", "org.jboss.envers.entities.RevisionTypeType");
+ addRevisionType(class_mapping);
break;
case SINGLE:
@@ -618,14 +667,14 @@
// Mapping unjoined properties
addProperties(class_mapping, (Iterator<Property>) pc.getUnjoinedPropertyIterator(), propertyMapper,
- versioningData.propertyStoreInfo, pc.getEntityName(), true);
+ versioningData.propertyStoreInfo, pc.getEntityName(), mappingData, true);
// Creating and mapping joins (first pass)
createJoins(pc, class_mapping, versioningData);
- addJoins(pc, propertyMapper, versioningData.propertyStoreInfo, pc.getEntityName(), true);
+ addJoins(pc, propertyMapper, versioningData.propertyStoreInfo, pc.getEntityName(), mappingData, true);
// Storing the generated configuration
- EntityConfiguration entityCfg = new EntityConfiguration(entityName, versionsEntityName, idMapper,
+ EntityConfiguration entityCfg = new EntityConfiguration(entityName, versionsEntityName, idMapper,
propertyMapper, parentEntityName);
entitiesConfigurations.put(pc.getEntityName(), entityCfg);
}
@@ -642,12 +691,12 @@
if (parent == null) {
parent = mappingData.getMainMapping().getRootElement().element("subclass");
}
-
+
addProperties(parent, (Iterator<Property>) pc.getUnjoinedPropertyIterator(),
- propertyMapper, versioningData.propertyStoreInfo, entityName, false);
+ propertyMapper, versioningData.propertyStoreInfo, entityName, mappingData, false);
// Mapping joins (second pass)
- addJoins(pc, propertyMapper, versioningData.propertyStoreInfo, entityName, false);
+ addJoins(pc, propertyMapper, versioningData.propertyStoreInfo, entityName, mappingData, false);
}
public Map<String, EntityConfiguration> getEntitiesConfigurations() {
Modified: trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -28,9 +28,12 @@
import org.hibernate.property.Getter;
import org.hibernate.property.Setter;
import org.hibernate.util.ReflectHelper;
+import org.hibernate.collection.PersistentCollection;
import java.util.Map;
import java.util.HashMap;
+import java.util.List;
+import java.io.Serializable;
/**
* @author Adam Warski (adam at warski dot org)
@@ -80,4 +83,11 @@
}
}
+ public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl,
+ Serializable id) {
+ return delegate.mapCollectionChangesFromCollections(referencingPropertyName, newColl, oldColl, id);
+ }
+
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -23,12 +23,15 @@
import org.hibernate.property.Getter;
import org.hibernate.MappingException;
+import org.hibernate.collection.PersistentCollection;
import org.jboss.envers.ModificationStore;
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
import java.util.Map;
import java.util.HashMap;
+import java.util.List;
+import java.io.Serializable;
/**
* @author Adam Warski (adam at warski dot org)
@@ -104,4 +107,15 @@
}
}
+ public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl,
+ Serializable id) {
+ PropertyMapper mapper = properties.get(referencingPropertyName);
+ if (mapper != null) {
+ return mapper.mapCollectionChangesFromCollections(referencingPropertyName, newColl, oldColl, id);
+ } else {
+ return null;
+ }
+ }
}
Added: trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -0,0 +1,24 @@
+package org.jboss.envers.entities.mapper;
+
+import java.util.Map;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class PersistentCollectionChangeData {
+ private String entityName;
+ private Map<String, Object> data;
+
+ public PersistentCollectionChangeData(String entityName, Map<String, Object> data) {
+ this.entityName = entityName;
+ this.data = data;
+ }
+
+ public String getEntityName() {
+ return entityName;
+ }
+
+ public Map<String, Object> getData() {
+ return data;
+ }
+}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -22,8 +22,11 @@
package org.jboss.envers.entities.mapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.hibernate.collection.PersistentCollection;
import java.util.Map;
+import java.util.List;
+import java.io.Serializable;
/**
* @author Adam Warski (adam at warski dot org)
@@ -49,4 +52,17 @@
*/
public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader,
Number revision);
+
+ /**
+ * Maps collection changes
+ * @param referencingPropertyName Name of the field, which holds the collection in the entity.
+ * @param newColl New collection, after updates.
+ * @param oldColl Old collection, before updates.
+ * @param id Id of the object owning the collection.
+ * @return List of changes that need to be performed on the persistent store.
+ */
+ public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl,
+ Serializable id);
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -27,8 +27,11 @@
import org.jboss.envers.tools.Tools;
import org.jboss.envers.exception.VersionsException;
import org.hibernate.property.Setter;
+import org.hibernate.collection.PersistentCollection;
import java.util.Map;
+import java.util.List;
+import java.io.Serializable;
/**
* TODO: diff
@@ -66,4 +69,11 @@
setter.set(obj, data.get(propertyName), null);
}
+ public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl,
+ Serializable id) {
+ return null;
+ }
+
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/SubclassPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/SubclassPropertyMapper.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/entities/mapper/SubclassPropertyMapper.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -23,8 +23,11 @@
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.ModificationStore;
+import org.hibernate.collection.PersistentCollection;
import java.util.Map;
+import java.util.List;
+import java.io.Serializable;
/**
* A mapper which maps from a parent mapper and a "main" one, but adds only to the "main". The "main" mapper
@@ -59,6 +62,20 @@
main.mapToEntityFromMap(obj, data, primaryKey, versionsReader, revision);
}
+ public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl,
+ Serializable id) {
+ List<PersistentCollectionChangeData> collectionChanges = parentMapper.mapCollectionChangesFromCollections(
+ referencingPropertyName, newColl, oldColl, id);
+
+ if (collectionChanges == null) {
+ return main.mapCollectionChangesFromCollections(referencingPropertyName, newColl, oldColl, id);
+ } else {
+ return collectionChanges;
+ }
+ }
+
public CompositeMapperBuilder addComposite(String propertyName) {
return main.addComposite(propertyName);
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyIdMapper.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyIdMapper.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -22,6 +22,7 @@
package org.jboss.envers.entities.mapper.relation;
import org.jboss.envers.entities.mapper.PropertyMapper;
+import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.entities.mapper.relation.lazy.OneToManyInitializor;
import org.jboss.envers.entities.mapper.relation.lazy.proxy.ListProxy;
@@ -30,8 +31,10 @@
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.hibernate.property.Setter;
import org.hibernate.property.Getter;
+import org.hibernate.collection.PersistentCollection;
import java.util.*;
+import java.io.Serializable;
/**
* @author Adam Warski (adam at warski dot org)
@@ -77,4 +80,11 @@
Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyName);
setter.set(obj, value, null);
}
+
+ public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl,
+ Serializable id) {
+ return null;
+ }
}
\ No newline at end of file
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyUnidirectionalMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyUnidirectionalMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyUnidirectionalMapper.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -0,0 +1,99 @@
+package org.jboss.envers.entities.mapper.relation;
+
+import org.jboss.envers.entities.mapper.PropertyMapper;
+import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
+import org.jboss.envers.entities.mapper.id.IdMapper;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.RevisionType;
+import org.hibernate.collection.PersistentCollection;
+
+import java.util.*;
+import java.io.Serializable;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class OneToManyUnidirectionalMapper implements PropertyMapper {
+ private final VersionsEntitiesConfiguration verEntCfg;
+ private final String collectionReferencingPropertyName;
+ private final String referencedEntityName;
+ private final String versionsMiddleEntityName;
+ private final IdMapper referencingMiddleIdMapper;
+ private final IdMapper referencedMiddleIdMapper;
+
+ public OneToManyUnidirectionalMapper(VersionsEntitiesConfiguration verEntCfg,
+ String collectionReferencingPropertyName,
+ String referencedEntityName, String versionsMiddleEntityName,
+ IdMapper referencingMiddleIdMapper, IdMapper referencedMiddleIdMapper) {
+ this.verEntCfg = verEntCfg;
+ this.collectionReferencingPropertyName = collectionReferencingPropertyName;
+ this.referencedEntityName = referencedEntityName;
+ this.versionsMiddleEntityName = versionsMiddleEntityName;
+ this.referencingMiddleIdMapper = referencingMiddleIdMapper;
+ this.referencedMiddleIdMapper = referencedMiddleIdMapper;
+ }
+
+ private Collection getOldCollection(Serializable oldColl) {
+ if (oldColl instanceof Map) {
+ return ((Map) oldColl).keySet();
+ } else {
+ return (Collection) oldColl;
+ }
+ }
+
+ private void addCollectionChanges(List<PersistentCollectionChangeData> collectionChanges, Set<Object> changed,
+ RevisionType revisionType, Serializable id) {
+ for (Object changedEntity : changed) {
+ Map<String, Object> entityData = new HashMap<String, Object>();
+ Map<String, Object> originalId = new HashMap<String, Object>();
+ entityData.put(verEntCfg.getOriginalIdPropName(), originalId);
+
+ collectionChanges.add(new PersistentCollectionChangeData(versionsMiddleEntityName, entityData));
+ referencingMiddleIdMapper.mapToMapFromId(originalId, id);
+ referencedMiddleIdMapper.mapToMapFromEntity(originalId, changedEntity);
+
+ entityData.put(verEntCfg.getRevisionTypePropName(), revisionType);
+
+ System.out.println("entityData = " + entityData);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl,
+ Serializable id) {
+ if (!collectionReferencingPropertyName.equals(referencingPropertyName)) {
+ return null;
+ }
+
+ List<PersistentCollectionChangeData> collectionChanges = new ArrayList<PersistentCollectionChangeData>();
+
+ Collection newCollection = (Collection) newColl;
+ Collection oldCollection = getOldCollection(oldColl);
+
+ Set<Object> added = new HashSet<Object>();
+ if (newColl != null) { added.addAll(newCollection); }
+ if (oldColl != null) { added.removeAll(oldCollection); }
+
+ addCollectionChanges(collectionChanges, added, RevisionType.ADD, id);
+
+ Set<Object> deleted = new HashSet<Object>();
+ if (oldColl != null) { deleted.addAll(oldCollection); }
+ if (newColl != null) { deleted.removeAll(newCollection); }
+
+ addCollectionChanges(collectionChanges, deleted, RevisionType.DEL, id);
+
+ return collectionChanges;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj) {
+ return false;
+ }
+
+ public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
+ System.out.println("XXX");
+ }
+}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneIdMapper.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneIdMapper.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -22,15 +22,19 @@
package org.jboss.envers.entities.mapper.relation;
import org.jboss.envers.entities.mapper.PropertyMapper;
+import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.query.VersionsRestrictions;
import org.jboss.envers.exception.VersionsException;
import org.hibernate.property.Setter;
import org.hibernate.NonUniqueResultException;
+import org.hibernate.collection.PersistentCollection;
import javax.persistence.NoResultException;
import java.util.Map;
+import java.util.List;
+import java.io.Serializable;
/**
* @author Adam Warski (adam at warski dot org)
@@ -72,4 +76,11 @@
Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyName);
setter.set(obj, value, null);
}
+
+ public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl,
+ Serializable id) {
+ return null;
+ }
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -22,15 +22,19 @@
package org.jboss.envers.entities.mapper.relation;
import org.jboss.envers.entities.mapper.PropertyMapper;
+import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
import org.jboss.envers.entities.mapper.id.IdMapper;
import org.jboss.envers.tools.Tools;
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor;
import org.hibernate.property.Setter;
+import org.hibernate.collection.PersistentCollection;
import java.util.Map;
import java.util.HashMap;
+import java.util.List;
+import java.io.Serializable;
/**
* @author Adam Warski (adam at warski dot org)
@@ -62,10 +66,6 @@
}
Object entityId = delegate.mapToIdFromMap((Map) data.get(propertyName));
- doMap(obj, versionsReader, revision, entityId);
- }
-
- private void doMap(Object obj, VersionsReaderImplementor versionsReader, Number revision, Object entityId) {
Object value;
if (entityId == null) {
value = null;
@@ -79,4 +79,11 @@
Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyName);
setter.set(obj, value, null);
}
+
+ public List<PersistentCollectionChangeData> mapCollectionChangesFromCollections(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl,
+ Serializable id) {
+ return null;
+ }
}
Modified: trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
===================================================================
--- trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -24,14 +24,13 @@
import org.hibernate.event.*;
import org.hibernate.cfg.Configuration;
import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.engine.CollectionEntry;
+import org.hibernate.collection.PersistentCollection;
import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.entities.RelationType;
import org.jboss.envers.synchronization.VersionsSync;
-import org.jboss.envers.synchronization.work.AddWorkUnit;
-import org.jboss.envers.synchronization.work.ModWorkUnit;
-import org.jboss.envers.synchronization.work.DelWorkUnit;
-import org.jboss.envers.synchronization.work.CollectionChangeWorkUnit;
+import org.jboss.envers.synchronization.work.*;
import org.jboss.envers.tools.Tools;
import org.jboss.envers.entities.mapper.id.IdMapper;
@@ -41,7 +40,8 @@
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsEventListener implements PostInsertEventListener, PostUpdateEventListener,
- PostDeleteEventListener, Initializable {
+ PostDeleteEventListener, PreCollectionUpdateEventListener, PreCollectionRemoveEventListener,
+ PostCollectionRecreateEventListener, Initializable {
private VersionsConfiguration verCfg;
private void generateCollectionChangeWorkUnits(VersionsSync verSync, EntityPersister entityPersister,
@@ -71,12 +71,12 @@
// (size increases).
if (newValue != null) {
Serializable id = (Serializable) idMapper.mapToIdFromEntity(newValue);
- verSync.addWorkUnit(new CollectionChangeWorkUnit(relDesc.getToEntityName(), verCfg, id, newValue));
+ verSync.addWorkUnit(new BidirectionalCollectionChangeWorkUnit(relDesc.getToEntityName(), verCfg, id, newValue));
}
if (oldValue != null) {
Serializable id = (Serializable) idMapper.mapToIdFromEntity(oldValue);
- verSync.addWorkUnit(new CollectionChangeWorkUnit(relDesc.getToEntityName(), verCfg, id, oldValue));
+ verSync.addWorkUnit(new BidirectionalCollectionChangeWorkUnit(relDesc.getToEntityName(), verCfg, id, oldValue));
}
}
}
@@ -121,6 +121,36 @@
}
}
+ private void onCollectionAction(AbstractCollectionEvent event, PersistentCollection newColl, Serializable oldColl,
+ CollectionEntry collectionEntry) {
+ String entityName = event.getAffectedOwnerEntityName();
+
+ if (verCfg.getEntCfg().isVersioned(entityName)) {
+ VersionsSync verSync = verCfg.getSyncManager().get(event.getSession());
+
+ verSync.addWorkUnit(new PersistentCollectionChangeWorkUnit(entityName, verCfg, newColl,
+ collectionEntry.getRole(), oldColl, event.getAffectedOwnerIdOrNull()));
+ }
+ }
+
+ private CollectionEntry getCollectionEntry(AbstractCollectionEvent event) {
+ return event.getSession().getPersistenceContext().getCollectionEntry(event.getCollection());
+ }
+
+ public void onPreUpdateCollection(PreCollectionUpdateEvent event) {
+ CollectionEntry collectionEntry = getCollectionEntry(event);
+ onCollectionAction(event, event.getCollection(), collectionEntry.getSnapshot(), collectionEntry);
+ }
+
+ public void onPreRemoveCollection(PreCollectionRemoveEvent event) {
+ CollectionEntry collectionEntry = getCollectionEntry(event);
+ onCollectionAction(event, null, collectionEntry.getSnapshot(), collectionEntry);
+ }
+
+ public void onPostRecreateCollection(PostCollectionRecreateEvent event) {
+ onCollectionAction(event, event.getCollection(), null, getCollectionEntry(event));
+ }
+
@SuppressWarnings({"unchecked"})
public void initialize(Configuration cfg) {
verCfg = VersionsConfiguration.getFor(cfg);
Modified: trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -38,7 +38,7 @@
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;
@@ -56,7 +56,7 @@
undoQueue = new LinkedList<VersionsWorkUnit>();
usedIds = new HashMap<Pair<String, Object>, VersionsWorkUnit>();
}
-
+
private void removeWorkUnit(VersionsWorkUnit vwu) {
workUnits.remove(vwu);
if (vwu.isPerformed()) {
@@ -68,30 +68,37 @@
public void addWorkUnit(VersionsWorkUnit vwu) {
if (vwu.containsWork()) {
Object entityId = vwu.getEntityId();
- String entityName = vwu.getEntityName();
- Pair<String, Object> usedIdsKey = Pair.make(entityName, entityId);
- if (usedIds.containsKey(usedIdsKey)) {
- VersionsWorkUnit other = usedIds.get(usedIdsKey);
+ if (entityId == null) {
+ // Just adding the work unit - it's not associated with any persistent entity.
+ workUnits.offer(vwu);
+ } else {
+ String entityName = vwu.getEntityName();
+ Pair<String, Object> usedIdsKey = Pair.make(entityName, entityId);
- // The entity with entityId has two work units; checking which one should be kept.
- switch (vwu.dispatch(other)) {
- case FIRST:
- // Simply not adding the second
- break;
+ if (usedIds.containsKey(usedIdsKey)) {
+ VersionsWorkUnit other = usedIds.get(usedIdsKey);
- case SECOND:
- removeWorkUnit(other);
- usedIds.put(usedIdsKey, vwu);
- workUnits.offer(vwu);
- break;
+ // The entity with entityId has two work units; checking which one should be kept.
+ switch (vwu.dispatch(other)) {
+ case FIRST:
+ // Simply not adding the second
+ break;
- case NONE:
- removeWorkUnit(other);
+ case SECOND:
+ removeWorkUnit(other);
+ usedIds.put(usedIdsKey, vwu);
+ workUnits.offer(vwu);
+ break;
+
+ case NONE:
+ removeWorkUnit(other);
+ break;
+ }
+ } else {
+ usedIds.put(usedIdsKey, vwu);
+ workUnits.offer(vwu);
}
- } else {
- usedIds.put(usedIdsKey, vwu);
- workUnits.offer(vwu);
}
}
}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -72,7 +72,7 @@
return KeepCheckResult.NONE;
}
- public KeepCheckResult check(CollectionChangeWorkUnit second) {
+ public KeepCheckResult check(BidirectionalCollectionChangeWorkUnit second) {
return KeepCheckResult.FIRST;
}
Copied: trunk/src/main/org/jboss/envers/synchronization/work/BidirectionalCollectionChangeWorkUnit.java (from rev 114, trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java)
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/BidirectionalCollectionChangeWorkUnit.java (rev 0)
+++ trunk/src/main/org/jboss/envers/synchronization/work/BidirectionalCollectionChangeWorkUnit.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -0,0 +1,78 @@
+/*
+ * 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.synchronization.work;
+
+import org.hibernate.Session;
+import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.RevisionType;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BidirectionalCollectionChangeWorkUnit extends AbstractVersionsWorkUnit implements VersionsWorkUnit {
+ private final Object entity;
+
+ public BidirectionalCollectionChangeWorkUnit(String entityName, VersionsConfiguration verCfg, Serializable id, Object entity) {
+ super(entityName, verCfg, id);
+
+ this.entity = entity;
+ }
+
+ public boolean containsWork() {
+ return true;
+ }
+
+ public void perform(Session session, Number revision) {
+ Map<String, Object> data = new HashMap<String, Object>();
+ fillDataWithId(data, revision, RevisionType.MOD);
+
+ verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().mapToMapFromEntity(data, entity, null);
+
+ session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()), data);
+
+ setPerformed(data);
+ }
+
+ public KeepCheckResult check(AddWorkUnit second) {
+ return KeepCheckResult.SECOND;
+ }
+
+ public KeepCheckResult check(ModWorkUnit second) {
+ return KeepCheckResult.SECOND;
+ }
+
+ public KeepCheckResult check(DelWorkUnit second) {
+ return KeepCheckResult.SECOND;
+ }
+
+ public KeepCheckResult check(BidirectionalCollectionChangeWorkUnit second) {
+ return KeepCheckResult.FIRST;
+ }
+
+ public KeepCheckResult dispatch(KeepCheckVisitor first) {
+ return first.check(this);
+ }
+}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -62,7 +62,7 @@
return KeepCheckResult.FIRST;
}
- public KeepCheckResult check(CollectionChangeWorkUnit second) {
+ public KeepCheckResult check(BidirectionalCollectionChangeWorkUnit second) {
return KeepCheckResult.FIRST;
}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/KeepCheckVisitor.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/KeepCheckVisitor.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/synchronization/work/KeepCheckVisitor.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -29,5 +29,5 @@
KeepCheckResult check(AddWorkUnit second);
KeepCheckResult check(ModWorkUnit second);
KeepCheckResult check(DelWorkUnit second);
- KeepCheckResult check(CollectionChangeWorkUnit second);
+ KeepCheckResult check(BidirectionalCollectionChangeWorkUnit second);
}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -70,7 +70,7 @@
return KeepCheckResult.SECOND;
}
- public KeepCheckResult check(CollectionChangeWorkUnit second) {
+ public KeepCheckResult check(BidirectionalCollectionChangeWorkUnit second) {
return KeepCheckResult.FIRST;
}
Added: trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java (rev 0)
+++ trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -0,0 +1,66 @@
+package org.jboss.envers.synchronization.work;
+
+import org.hibernate.Session;
+import org.hibernate.collection.PersistentCollection;
+import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class PersistentCollectionChangeWorkUnit extends AbstractVersionsWorkUnit implements VersionsWorkUnit {
+ private final List<PersistentCollectionChangeData> collectionChanges;
+
+ public PersistentCollectionChangeWorkUnit(String entityName, VersionsConfiguration verCfg,
+ PersistentCollection collection, String role,
+ Serializable snapshot, Serializable id) {
+ super(entityName, verCfg, null);
+
+ String referencingPropertyName = role.substring(entityName.length() + 1);
+
+ collectionChanges = verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
+ .mapCollectionChangesFromCollections(referencingPropertyName, collection, snapshot, id);
+ }
+
+ public boolean containsWork() {
+ return collectionChanges == null || collectionChanges.size() != 0;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void perform(Session session, Number revision) {
+ VersionsEntitiesConfiguration entitiesCfg = verCfg.getVerEntCfg();
+
+ for (PersistentCollectionChangeData persistentCollectionChangeData : collectionChanges) {
+ // Setting the revision number
+ ((Map<String, Object>) persistentCollectionChangeData.getData().get(entitiesCfg.getOriginalIdPropName()))
+ .put(entitiesCfg.getRevisionPropName(), revision);
+
+ session.save(persistentCollectionChangeData.getEntityName(), persistentCollectionChangeData.getData());
+ }
+ }
+
+ public KeepCheckResult check(AddWorkUnit second) {
+ return null;
+ }
+
+ public KeepCheckResult check(ModWorkUnit second) {
+ return null;
+ }
+
+ public KeepCheckResult check(DelWorkUnit second) {
+ return null;
+ }
+
+ public KeepCheckResult check(BidirectionalCollectionChangeWorkUnit second) {
+ return null;
+ }
+
+ public KeepCheckResult dispatch(KeepCheckVisitor first) {
+ return null;
+ }
+}
Modified: trunk/src/test/org/jboss/envers/test/working/WorkingEntity1.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/working/WorkingEntity1.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/test/org/jboss/envers/test/working/WorkingEntity1.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -25,10 +25,10 @@
//@Column(table = "second_table", name = "cc_second")
private String cc;
- @Versioned
+ //@Versioned
//@OneToOne
- @ManyToOne
- //@Transient
+ //@ManyToOne
+ @Transient
private WorkingEntity2 we2;
public WorkingEntity1() {
Modified: trunk/src/test/org/jboss/envers/test/working/WorkingEntity2.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/working/WorkingEntity2.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/test/org/jboss/envers/test/working/WorkingEntity2.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -22,7 +22,7 @@
private String str2;
@Versioned
- @OneToMany(mappedBy="we2")
+ @OneToMany //(mappedBy="we2")
//@ManyToMany
//@Transient
private Set<WorkingEntity1> we1s;
Modified: trunk/src/test/org/jboss/envers/test/working/WorkingMain.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/working/WorkingMain.java 2008-08-18 07:44:39 UTC (rev 114)
+++ trunk/src/test/org/jboss/envers/test/working/WorkingMain.java 2008-08-20 11:44:45 UTC (rev 115)
@@ -60,43 +60,64 @@
// Rev 1
entityManager.getTransaction().begin();
- WorkingEntity2 we2 = new WorkingEntity2("s");
- entityManager.persist(we2);
-
WorkingEntity1 we1 = new WorkingEntity1("b", "c");
- we1.setWe2(we2);
entityManager.persist(we1);
WorkingEntity1 we1_2 = new WorkingEntity1("b2", "c2");
- we1_2.setWe2(we2);
entityManager.persist(we1_2);
+ WorkingEntity1 we1_3 = new WorkingEntity1("b3", "c3");
+ entityManager.persist(we1_3);
+
+ WorkingEntity2 we2 = new WorkingEntity2("s");
+ Set<WorkingEntity1> we1s = new HashSet<WorkingEntity1>();
+ we1s.add(we1_3);
+ we2.setWe1s(we1s);
+ entityManager.persist(we2);
+
entityManager.getTransaction().commit();
// Rev 2
entityManager.getTransaction().begin();
we1 = entityManager.find(WorkingEntity1.class, we1.getId1());
- entityManager.remove(we1);
+ we2 = entityManager.find(WorkingEntity2.class, we2.getId2());
+ we2.getWe1s().add(we1);
entityManager.getTransaction().commit();
// Rev 3
entityManager.getTransaction().begin();
- VersionsReader vr = VersionsReaderFactory.get(entityManager);
+ we1_2 = entityManager.find(WorkingEntity1.class, we1_2.getId1());
+ we2 = entityManager.find(WorkingEntity2.class, we2.getId2());
+ we2.getWe1s().add(we1_2);
- System.out.println(vr.createQuery().forEntitiesAtRevision(WorkingEntity1.class, 1)
- .getResultList());
- System.out.println(vr.createQuery().forEntitiesAtRevision(WorkingEntity1.class, 1)
- .setProjection(Projections.count("originalId.id1")).getResultList());
+ entityManager.getTransaction().commit();
- System.out.println(vr.createQuery().forEntitiesAtRevision(WorkingEntity1.class, 2)
- .getResultList());
- System.out.println(vr.createQuery().forEntitiesAtRevision(WorkingEntity1.class, 2)
- .setProjection(Projections.count("originalId.id1")).getResultList());
+ // Rev 4
+ entityManager.getTransaction().begin();
+ we1_2 = entityManager.find(WorkingEntity1.class, we1_2.getId1());
+ we2 = entityManager.find(WorkingEntity2.class, we2.getId2());
+ we2.getWe1s().remove(we1_2);
+
entityManager.getTransaction().commit();
+
+ // Rev 5
+ entityManager.getTransaction().begin();
+
+ we2 = entityManager.find(WorkingEntity2.class, we2.getId2());
+ we2.setWe1s(null);
+
+ entityManager.getTransaction().commit();
+
+ // Rev 6
+ entityManager.getTransaction().begin();
+
+ VersionsReader vr = VersionsReaderFactory.get(entityManager);
+
+ entityManager.getTransaction().commit();
}
}
16 years, 4 months
JBoss Envers SVN: r114 - in trunk/src/main/org/jboss/envers: configuration/metadata and 7 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-18 03:44:39 -0400 (Mon, 18 Aug 2008)
New Revision: 114
Added:
trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
trunk/src/main/org/jboss/envers/configuration/metadata/EntityMappingData.java
trunk/src/main/org/jboss/envers/entities/RelationType.java
Removed:
trunk/src/main/org/jboss/envers/reader/lazy/
Modified:
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java
trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
trunk/src/main/org/jboss/envers/entities/EntityInstantiator.java
trunk/src/main/org/jboss/envers/entities/RelationDescription.java
trunk/src/main/org/jboss/envers/event/VersionsEventListener.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/NotNullVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java
trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.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/ModWorkUnit.java
trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java
Log:
ENVERS-37: restructing metdata configuration
Added: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -0,0 +1,116 @@
+package org.jboss.envers.configuration;
+
+import org.jboss.envers.entities.EntitiesConfigurations;
+import org.jboss.envers.configuration.metadata.VersionsMetadataGenerator;
+import org.jboss.envers.configuration.metadata.PersistentClassVersioningData;
+import org.jboss.envers.configuration.metadata.AnnotationsMetadataReader;
+import org.jboss.envers.configuration.metadata.EntityMappingData;
+import org.jboss.envers.tools.graph.GraphTopologicalSort;
+import org.jboss.envers.tools.reflection.YReflectionManager;
+import org.dom4j.io.DOMWriter;
+import org.dom4j.io.XMLWriter;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.MappingException;
+import org.hibernate.cfg.Configuration;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.ByteArrayOutputStream;
+import java.io.Writer;
+import java.io.PrintWriter;
+import java.io.IOException;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class EntitiesConfigurator {
+ public EntitiesConfigurations configure(Configuration cfg, YReflectionManager reflectionManager,
+ GlobalConfiguration globalCfg, VersionsEntitiesConfiguration verEntCfg,
+ Document revisionInfoXmlMapping) {
+ VersionsMetadataGenerator versionsMetaGen = new VersionsMetadataGenerator(globalCfg, verEntCfg);
+ DOMWriter writer = new DOMWriter();
+
+ // Sorting the persistent class topologically - superclass always before subclass
+ Iterator<PersistentClass> classes = GraphTopologicalSort.sort(new PersistentClassGraphDefiner(cfg)).iterator();
+
+ Map<PersistentClass, PersistentClassVersioningData> pcDatas =
+ new HashMap<PersistentClass, PersistentClassVersioningData>();
+ Map<PersistentClass, EntityMappingData> xmlMappings = new HashMap<PersistentClass, EntityMappingData>();
+
+ // First pass
+ AnnotationsMetadataReader annotationsMetadataReader = new AnnotationsMetadataReader();
+ while (classes.hasNext()) {
+ PersistentClass pc = classes.next();
+ // Collecting information from annotations on the persistent class pc
+ PersistentClassVersioningData versioningData =
+ annotationsMetadataReader.getVersioningData(pc, reflectionManager);
+
+ if (versioningData.isVersioned()) {
+ pcDatas.put(pc, versioningData);
+
+ if (versioningData.versionsTableName != null) {
+ verEntCfg.addCustomVersionsTableName(pc.getEntityName(), versioningData.versionsTableName);
+ }
+
+ EntityMappingData mappingData = new EntityMappingData();
+ versionsMetaGen.generateFirstPass(pc, versioningData, mappingData);
+ xmlMappings.put(pc, mappingData);
+ }
+ }
+
+ // Second pass
+ for (PersistentClass pc : pcDatas.keySet()) {
+ EntityMappingData mappingData = xmlMappings.get(pc);
+
+ versionsMetaGen.generateSecondPass(pc, pcDatas.get(pc), mappingData);
+
+ //TODO
+ //writeDocument(document);
+
+ try {
+ cfg.addDocument(writer.write(mappingData.getMainMapping()));
+
+ for (Document additionalMapping : mappingData.getAdditionalMappings()) {
+ cfg.addDocument(writer.write(additionalMapping));
+ }
+ } catch (DocumentException e) {
+ throw new MappingException(e);
+ }
+ }
+
+ // Only if there are any versioned classes
+ if (pcDatas.size() > 0) {
+ try {
+ if (revisionInfoXmlMapping != null) {
+ cfg.addDocument(writer.write(revisionInfoXmlMapping));
+ }
+ } catch (DocumentException e) {
+ throw new MappingException(e);
+ }
+ }
+
+ return new EntitiesConfigurations(versionsMetaGen.getEntitiesConfigurations());
+ }
+
+ // 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/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -22,27 +22,12 @@
package org.jboss.envers.configuration;
import org.hibernate.cfg.Configuration;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.MappingException;
-import org.jboss.envers.configuration.metadata.VersionsMetadataGenerator;
-import org.jboss.envers.configuration.metadata.AnnotationsMetadataReader;
-import org.jboss.envers.configuration.metadata.PersistentClassVersioningData;
import org.jboss.envers.entities.EntitiesConfigurations;
import org.jboss.envers.synchronization.VersionsSyncManager;
-import org.jboss.envers.tools.graph.GraphTopologicalSort;
import org.jboss.envers.tools.reflection.YReflectionManager;
import org.jboss.envers.revisioninfo.RevisionInfoQueryCreator;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.io.XMLWriter;
-import org.dom4j.io.OutputFormat;
-import org.dom4j.io.DOMWriter;
import java.util.*;
-import java.io.ByteArrayOutputStream;
-import java.io.Writer;
-import java.io.PrintWriter;
-import java.io.IOException;
/**
* @author Adam Warski (adam at warski dot org)
@@ -74,85 +59,19 @@
return revisionInfoQueryCreator;
}
- private YReflectionManager getReflectionManager(Configuration cfg) {
- try {
- return new YReflectionManager(cfg);
- } catch (Exception e) {
- throw new MappingException(e);
- }
- }
-
@SuppressWarnings({"unchecked"})
public VersionsConfiguration(Configuration cfg) {
Properties properties = cfg.getProperties();
- YReflectionManager reflectionManager = getReflectionManager(cfg);
+ YReflectionManager reflectionManager = YReflectionManager.get(cfg);
RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration();
RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg, reflectionManager);
verEntCfg = new VersionsEntitiesConfiguration(properties, revInfoCfgResult.getRevisionPropType());
globalCfg = new GlobalConfiguration(properties);
versionsSyncManager = new VersionsSyncManager(revInfoCfgResult.getRevisionNumberGenerator());
revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
-
- VersionsMetadataGenerator versionsMetaGen = new VersionsMetadataGenerator(this);
- DOMWriter writer = new DOMWriter();
-
- // Sorting the persistent class topologically - superclass always before subclass
- Iterator<PersistentClass> classes = GraphTopologicalSort.sort(new PersistentClassGraphDefiner(cfg)).iterator();
-
- Map<PersistentClass, PersistentClassVersioningData> pcDatas =
- new HashMap<PersistentClass, PersistentClassVersioningData>();
- Map<PersistentClass, Document> documents = new HashMap<PersistentClass, Document>();
-
- // First pass
- AnnotationsMetadataReader annotationsMetadataReader = new AnnotationsMetadataReader();
- while (classes.hasNext()) {
- PersistentClass pc = classes.next();
- // Collecting information from annotations on the persistent class pc
- PersistentClassVersioningData versioningData =
- annotationsMetadataReader.getVersioningData(pc, reflectionManager);
-
- if (versioningData.isVersioned()) {
- pcDatas.put(pc, versioningData);
-
- if (versioningData.versionsTableName != null) {
- verEntCfg.addCustomVersionsTableName(pc.getEntityName(), versioningData.versionsTableName);
- }
-
- Document genData = versionsMetaGen.generateFirstPass(pc, versioningData);
- documents.put(pc, genData);
- }
- }
-
- // Second pass
- for (PersistentClass pc : pcDatas.keySet()) {
- Document document = documents.get(pc);
-
- versionsMetaGen.generateSecondPass(pc, pcDatas.get(pc), document);
-
- //TODO
- //writeDocument(document);
-
- try {
- cfg.addDocument(writer.write(document));
- } catch (DocumentException e) {
- throw new MappingException(e);
- }
- }
-
- // Getting the entities configurations
- entCfg = new EntitiesConfigurations(versionsMetaGen.getEntitiesConfigurations());
-
- // Only if there are any versioned classes
- if (pcDatas.size() > 0) {
- try {
- if (revInfoCfgResult.getRevisionInfoXmlMapping() != null) {
- cfg.addDocument(writer.write(revInfoCfgResult.getRevisionInfoXmlMapping()));
- }
- } catch (DocumentException e) {
- throw new MappingException(e);
- }
- }
+ entCfg = new EntitiesConfigurator().configure(cfg, reflectionManager, globalCfg, verEntCfg,
+ revInfoCfgResult.getRevisionInfoXmlMapping());
}
//
@@ -172,22 +91,4 @@
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("-----------");
- }
}
Added: trunk/src/main/org/jboss/envers/configuration/metadata/EntityMappingData.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/EntityMappingData.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/EntityMappingData.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -0,0 +1,35 @@
+package org.jboss.envers.configuration.metadata;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class EntityMappingData {
+ private Document mainMapping;
+ private List<Document> additionalMappings;
+
+ public EntityMappingData() {
+ mainMapping = DocumentHelper.createDocument();
+ additionalMappings = new ArrayList<Document>();
+ }
+
+ public Document getMainMapping() {
+ return mainMapping;
+ }
+
+ public List<Document> getAdditionalMappings() {
+ return additionalMappings;
+ }
+
+ public Document newAdditionalMapping() {
+ Document additionalMapping = DocumentHelper.createDocument();
+ additionalMappings.add(additionalMapping);
+
+ return additionalMapping;
+ }
+}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -26,13 +26,12 @@
import org.hibernate.util.StringHelper;
import org.hibernate.MappingException;
import org.dom4j.Element;
-import org.dom4j.Document;
-import org.dom4j.DocumentHelper;
import org.dom4j.Attribute;
import org.dom4j.tree.DefaultElement;
import org.jboss.envers.entities.EntityConfiguration;
import org.jboss.envers.entities.IdMappingData;
-import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.configuration.GlobalConfiguration;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import org.jboss.envers.entities.mapper.*;
import org.jboss.envers.entities.mapper.id.*;
import org.jboss.envers.entities.mapper.relation.ToOneIdMapper;
@@ -44,8 +43,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.PersistentClassVersioningData;
-import org.jboss.envers.configuration.metadata.PropertyStoreInfo;
import org.jboss.envers.exception.VersionsException;
import java.util.Iterator;
@@ -59,7 +56,9 @@
public class VersionsMetadataGenerator {
private final static Map<String, ModificationStore> EMPTY_STORE = Collections.emptyMap();
- private VersionsConfiguration verCfg;
+ private final GlobalConfiguration globalCfg;
+ private final VersionsEntitiesConfiguration verEntCfg;
+
private Map<String, EntityConfiguration> entitiesConfigurations;
// Map entity name -> (join descriptor -> element describing the "versioned" join)
@@ -67,8 +66,9 @@
private YLog log = YLogManager.getLogManager().getLog(VersionsMetadataGenerator.class);
- public VersionsMetadataGenerator(VersionsConfiguration verCfg) {
- this.verCfg = verCfg;
+ public VersionsMetadataGenerator(GlobalConfiguration globalCfg, VersionsEntitiesConfiguration verEntCfg) {
+ this.globalCfg = globalCfg;
+ this.verEntCfg = verEntCfg;
entitiesConfigurations = new HashMap<String, EntityConfiguration>();
entitiesJoins = new HashMap<String, Map<Join, Element>>();
@@ -425,7 +425,7 @@
} else {
String message = "Type not supported for versioning: " + propertyType.getClass().getName() +
", on entity " + entityName + ", property '" + property.getName() + "'.";
- if (verCfg.getGlobalCfg().isWarnOnUnsupportedTypes()) {
+ if (globalCfg.isWarnOnUnsupportedTypes()) {
log.warn(message);
} else {
throw new MappingException(message);
@@ -451,7 +451,7 @@
String originalTableName = join.getTable().getName();
String versionedTableName = versioningData.secondaryTableDictionary.get(originalTableName);
if (versionedTableName == null) {
- versionedTableName = verCfg.getVerEntCfg().getVersionsEntityName(originalTableName);
+ versionedTableName = verEntCfg.getVersionsEntityName(originalTableName);
}
String schema = versioningData.schema;
@@ -469,7 +469,7 @@
Element joinKey = joinElement.addElement("key");
addColumns(joinKey, join.getKey().getColumnIterator());
- MetadataTools.addColumn(joinKey, verCfg.getVerEntCfg().getRevisionPropName(), null);
+ MetadataTools.addColumn(joinKey, verEntCfg.getRevisionPropName(), null);
}
}
@@ -521,12 +521,12 @@
addSimpleProperty(orig_id_mapping, id_prop, null, ModificationStore.FULL, true);
}
- orig_id_mapping.addAttribute("name", verCfg.getVerEntCfg().getOriginalIdPropName());
+ orig_id_mapping.addAttribute("name", verEntCfg.getOriginalIdPropName());
// Adding the "revision number" property
- Element rev_mapping = MetadataTools.addProperty(orig_id_mapping, verCfg.getVerEntCfg().getRevisionPropName(),
- verCfg.getVerEntCfg().getRevisionPropType(), true);
- MetadataTools.addColumn(rev_mapping, verCfg.getVerEntCfg().getRevisionPropName(), null);
+ Element rev_mapping = MetadataTools.addProperty(orig_id_mapping, verEntCfg.getRevisionPropName(),
+ verEntCfg.getRevisionPropType(), true);
+ MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionPropName(), null);
return new IdMappingData(mapper, orig_id_mapping, rel_id_mapping);
}
@@ -543,9 +543,8 @@
}
@SuppressWarnings({"unchecked"})
- public Document generateFirstPass(PersistentClass pc, PersistentClassVersioningData versioningData) {
- Document document = DocumentHelper.createDocument();
-
+ public void generateFirstPass(PersistentClass pc, PersistentClassVersioningData versioningData,
+ EntityMappingData mappingData) {
String schema = versioningData.schema;
if (StringTools.isEmpty(schema)) {
schema = pc.getTable().getSchema();
@@ -557,8 +556,8 @@
}
String entityName = pc.getEntityName();
- String versionsEntityName = verCfg.getVerEntCfg().getVersionsEntityName(entityName);
- String versionsTableName = verCfg.getVerEntCfg().getVersionsTableName(entityName, pc.getTable().getName());
+ String versionsEntityName = verEntCfg.getVersionsEntityName(entityName);
+ String versionsTableName = verEntCfg.getVersionsTableName(entityName, pc.getTable().getName());
// Generating a mapping for the id
IdMappingData idMapper = addId(pc);
@@ -571,7 +570,7 @@
switch (inheritanceType) {
case NONE:
- class_mapping = MetadataTools.createEntity(document, versionsEntityName, versionsTableName,
+ class_mapping = MetadataTools.createEntity(mappingData.getMainMapping(), versionsEntityName, versionsTableName,
schema, catalog, pc.getDiscriminatorValue());
propertyMapper = new MultiPropertyMapper();
@@ -589,15 +588,15 @@
class_mapping.add((Element) idMapper.getXmlMapping().clone());
// Adding the "revision type" property
- Element revTypeProperty = MetadataTools.addProperty(class_mapping, verCfg.getVerEntCfg().getRevisionTypePropName(),
- verCfg.getVerEntCfg().getRevisionTypePropType(), false);
+ Element revTypeProperty = MetadataTools.addProperty(class_mapping, verEntCfg.getRevisionTypePropName(),
+ verEntCfg.getRevisionTypePropType(), false);
revTypeProperty.addAttribute("type", "org.jboss.envers.entities.RevisionTypeType");
break;
case SINGLE:
- String extendsEntityName = verCfg.getVerEntCfg().getVersionsEntityName(pc.getSuperclass().getEntityName());
- class_mapping = MetadataTools.createSubclassEntity(document, versionsEntityName, versionsTableName,
- schema, catalog, extendsEntityName, pc.getDiscriminatorValue());
+ String extendsEntityName = verEntCfg.getVersionsEntityName(pc.getSuperclass().getEntityName());
+ class_mapping = MetadataTools.createSubclassEntity(mappingData.getMainMapping(), versionsEntityName,
+ versionsTableName, schema, catalog, extendsEntityName, pc.getDiscriminatorValue());
addPersisterHack(class_mapping);
@@ -629,21 +628,19 @@
EntityConfiguration entityCfg = new EntityConfiguration(entityName, versionsEntityName, idMapper,
propertyMapper, parentEntityName);
entitiesConfigurations.put(pc.getEntityName(), entityCfg);
-
- return document;
}
@SuppressWarnings({"unchecked"})
public void generateSecondPass(PersistentClass pc, PersistentClassVersioningData versioningData,
- Document document) {
+ EntityMappingData mappingData) {
String entityName = pc.getEntityName();
CompositeMapperBuilder propertyMapper = entitiesConfigurations.get(entityName).getPropertyMapper();
// Mapping unjoined properties
- Element parent = document.getRootElement().element("class");
+ Element parent = mappingData.getMainMapping().getRootElement().element("class");
if (parent == null) {
- parent = document.getRootElement().element("subclass");
+ parent = mappingData.getMainMapping().getRootElement().element("subclass");
}
addProperties(parent, (Iterator<Property>) pc.getUnjoinedPropertyIterator(),
Modified: trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -21,9 +21,6 @@
*/
package org.jboss.envers.entities;
-import org.jboss.envers.entities.mapper.id.IdMapper;
-import org.jboss.envers.entities.mapper.ExtendedPropertyMapper;
-
import java.util.Map;
import java.util.HashMap;
@@ -61,12 +58,12 @@
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;
+ if (relDesc.getRelationType() == RelationType.TO_ONE) {
+ for (RelationDescription other : entitiesConfigurations.get(relDesc.getToEntityName()).getRelationsIterator()) {
+ if (relDesc.getFromPropertyName().equals(other.getMappedByPropertyName()) &&
+ (entityName.equals(other.getToEntityName()))) {
+ relDesc.setBidirectional(true);
+ other.setBidirectional(true);
}
}
}
@@ -86,14 +83,6 @@
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);
Modified: trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -21,7 +21,6 @@
*/
package org.jboss.envers.entities;
-import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.entities.mapper.ExtendedPropertyMapper;
import org.jboss.envers.entities.mapper.id.IdMapper;
@@ -52,30 +51,26 @@
}
public void addToOneRelation(String fromPropertyName, String toEntityName, IdMapper idMapper) {
- relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationDescription.RelationType.TO_ONE,
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName, 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,
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName, 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,
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName, 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);
}
@@ -84,19 +79,29 @@
return idMappingData;
}
+ public IdMapper getIdMapper() {
+ return idMappingData.getIdMapper();
+ }
+
public ExtendedPropertyMapper getPropertyMapper() {
return propertyMapper;
}
- public String getParentEntityName() {
- return parentEntityName;
- }
-
public String getEntityName() {
return entityName;
}
- public String getVersionsEntityName() {
+ // For use by EntitiesConfigurations
+
+ String getParentEntityName() {
+ return parentEntityName;
+ }
+
+ String getVersionsEntityName() {
return versionsEntityName;
}
+
+ Iterable<RelationDescription> getRelationsIterator() {
+ return relations.values();
+ }
}
Modified: trunk/src/main/org/jboss/envers/entities/EntityInstantiator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/EntityInstantiator.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/entities/EntityInstantiator.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -70,12 +70,13 @@
throw new VersionsException(e);
}
- IdMapper idMapper = verCfg.getEntCfg().getIdMapper(entityName);
+ IdMapper idMapper = verCfg.getEntCfg().get(entityName).getIdMapper();
Map originalId = (Map) versionsEntity.get(verCfg.getVerEntCfg().getOriginalIdPropName());
Object primaryKey = idMapper.mapToIdFromMap(originalId);
- verCfg.getEntCfg().getPropertyMapper(entityName).mapToEntityFromMap(ret, versionsEntity, primaryKey, versionsReader, revision);
+ verCfg.getEntCfg().get(entityName).getPropertyMapper().mapToEntityFromMap(ret, versionsEntity, primaryKey,
+ versionsReader, revision);
idMapper.mapToEntityFromMap(ret, originalId);
return ret;
Modified: trunk/src/main/org/jboss/envers/entities/RelationDescription.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/RelationDescription.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/entities/RelationDescription.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -27,12 +27,12 @@
* @author Adam Warski (adam at warski dot org)
*/
public class RelationDescription {
- public final String fromPropertyName;
- public final RelationType relationType;
- public final String toEntityName;
- public final String mappedByPropertyName;
- public final IdMapper idMapper;
- public boolean bidirectional;
+ private final String fromPropertyName;
+ private final RelationType relationType;
+ private final String toEntityName;
+ private final String mappedByPropertyName;
+ private final IdMapper idMapper;
+ private boolean bidirectional;
public RelationDescription(String fromPropertyName, RelationType relationType, String toEntityName,
String mappedByPropertyName, IdMapper idMapper) {
@@ -45,9 +45,31 @@
this.bidirectional = false;
}
- public static enum RelationType {
- TO_ONE,
- ONE_TO_ONE,
- ONE_TO_MANY
+ public String getFromPropertyName() {
+ return fromPropertyName;
}
+
+ public RelationType getRelationType() {
+ return relationType;
+ }
+
+ public String getToEntityName() {
+ return toEntityName;
+ }
+
+ public String getMappedByPropertyName() {
+ return mappedByPropertyName;
+ }
+
+ public IdMapper getIdMapper() {
+ return idMapper;
+ }
+
+ public boolean isBidirectional() {
+ return bidirectional;
+ }
+
+ void setBidirectional(boolean bidirectional) {
+ this.bidirectional = bidirectional;
+ }
}
Added: trunk/src/main/org/jboss/envers/entities/RelationType.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/RelationType.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/RelationType.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -0,0 +1,10 @@
+package org.jboss.envers.entities;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+*/
+public enum RelationType {
+ TO_ONE,
+ ONE_TO_ONE,
+ ONE_TO_MANY
+}
Modified: trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
===================================================================
--- trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -26,6 +26,7 @@
import org.hibernate.persister.entity.EntityPersister;
import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.entities.RelationDescription;
+import org.jboss.envers.entities.RelationType;
import org.jboss.envers.synchronization.VersionsSync;
import org.jboss.envers.synchronization.work.AddWorkUnit;
import org.jboss.envers.synchronization.work.ModWorkUnit;
@@ -58,24 +59,24 @@
for (int i=0; i<propertyNames.length; i++) {
String propertyName = propertyNames[i];
RelationDescription relDesc = verCfg.getEntCfg().getRelationDescription(entityName, propertyName);
- if (relDesc != null && relDesc.bidirectional && relDesc.relationType == RelationDescription.RelationType.TO_ONE) {
+ if (relDesc != null && relDesc.isBidirectional() && relDesc.getRelationType() == 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.getEntCfg().getIdMapper(relDesc.toEntityName);
+ IdMapper idMapper = verCfg.getEntCfg().get(relDesc.getToEntityName()).getIdMapper();
// We have to generate changes both in the old collection (size decreses) and new collection
// (size increases).
if (newValue != null) {
Serializable id = (Serializable) idMapper.mapToIdFromEntity(newValue);
- verSync.addWorkUnit(new CollectionChangeWorkUnit(relDesc.toEntityName, verCfg, id, newValue));
+ verSync.addWorkUnit(new CollectionChangeWorkUnit(relDesc.getToEntityName(), verCfg, id, newValue));
}
if (oldValue != null) {
Serializable id = (Serializable) idMapper.mapToIdFromEntity(oldValue);
- verSync.addWorkUnit(new CollectionChangeWorkUnit(relDesc.toEntityName, verCfg, id, oldValue));
+ verSync.addWorkUnit(new CollectionChangeWorkUnit(relDesc.getToEntityName(), verCfg, id, oldValue));
}
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -23,6 +23,7 @@
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.entities.RelationDescription;
+import org.jboss.envers.entities.RelationType;
import org.jboss.envers.configuration.VersionsConfiguration;
/**
@@ -47,7 +48,7 @@
return null;
}
- if (relationDesc.relationType == RelationDescription.RelationType.TO_ONE) {
+ if (relationDesc.getRelationType() == RelationType.TO_ONE) {
return relationDesc;
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -37,7 +37,7 @@
public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- return verCfg.getEntCfg().getIdMapper(entityName)
+ return verCfg.getEntCfg().get(entityName).getIdMapper()
.getIdEqualsCriterion(id, verCfg.getVerEntCfg().getOriginalIdPropName(), true);
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -44,7 +44,7 @@
if (relatedEntity == null) {
return Restrictions.isNotNull(propertyName);
} else {
- return relatedEntity.idMapper.getIdEqualsCriterion(null, propertyName, false);
+ return relatedEntity.getIdMapper().getIdEqualsCriterion(null, propertyName, false);
}
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -44,7 +44,7 @@
if (relatedEntity == null) {
return Restrictions.isNull(propertyName);
} else {
- return relatedEntity.idMapper.getIdEqualsCriterion(null, propertyName, true);
+ return relatedEntity.getIdMapper().getIdEqualsCriterion(null, propertyName, true);
}
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -48,7 +48,7 @@
throw new VersionsException("This criterion can only be used on a property that is " +
"a relation to another property.");
} else {
- return relatedEntity.idMapper.getIdEqualsCriterion(id, propertyName, equals);
+ return relatedEntity.getIdMapper().getIdEqualsCriterion(id, propertyName, equals);
}
}
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -60,9 +60,9 @@
") isn't supported and can't be used in queries.");
}
- Object id = relatedEntity.idMapper.mapToIdFromEntity(value);
+ Object id = relatedEntity.getIdMapper().mapToIdFromEntity(value);
- return relatedEntity.idMapper.getIdEqualsCriterion(id, propertyName, "=".equals(op));
+ return relatedEntity.getIdMapper().getIdEqualsCriterion(id, propertyName, "=".equals(op));
}
}
}
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -68,7 +68,7 @@
// e2.revision <= :revision
maxRevCriteria.add(Restrictions.le(revisionPropertyPath, revision));
// e2.id = e.id
- maxRevCriteria.add(verCfg.getEntCfg().getIdMapper(entityName).getIdsEqualCriterion(
+ maxRevCriteria.add(verCfg.getEntCfg().get(entityName).getIdMapper().getIdsEqualCriterion(
"e." + originalIdPropertyName, "e2." + originalIdPropertyName));
// e.revision_type != DEL AND
Modified: trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -53,7 +53,7 @@
Map<String, Object> originalId = new HashMap<String, Object>();
originalId.put(entitiesCfg.getRevisionPropName(), revision);
- verCfg.getEntCfg().getIdMapper(getEntityName()).mapToMapFromId(originalId, id);
+ verCfg.getEntCfg().get(getEntityName()).getIdMapper().mapToMapFromId(originalId, id);
data.put(entitiesCfg.getRevisionTypePropName(), revisionType);
data.put(entitiesCfg.getOriginalIdPropName(), originalId);
}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -53,7 +53,7 @@
Map<String, Object> data = new HashMap<String, Object>();
fillDataWithId(data, revision, RevisionType.ADD);
- verCfg.getEntCfg().getPropertyMapper(getEntityName()).map(data, propertyNames, state, null);
+ verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().map(data, propertyNames, state, null);
session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()), data);
Modified: trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -49,7 +49,7 @@
Map<String, Object> data = new HashMap<String, Object>();
fillDataWithId(data, revision, RevisionType.MOD);
- verCfg.getEntCfg().getPropertyMapper(getEntityName()).mapToMapFromEntity(data, entity, null);
+ verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().mapToMapFromEntity(data, entity, null);
session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()), data);
Modified: trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -42,7 +42,7 @@
super(entityName, verCfg, id);
data = new HashMap<String, Object>();
- changes = verCfg.getEntCfg().getPropertyMapper(getEntityName()).map(data, entityPersister.getPropertyNames(),
+ changes = verCfg.getEntCfg().get(getEntityName()).getPropertyMapper().map(data, entityPersister.getPropertyNames(),
newState, oldState);
}
Modified: trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java 2008-08-17 14:24:36 UTC (rev 113)
+++ trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java 2008-08-18 07:44:39 UTC (rev 114)
@@ -22,6 +22,7 @@
package org.jboss.envers.tools.reflection;
import org.hibernate.cfg.Configuration;
+import org.hibernate.MappingException;
import org.jboss.envers.exception.VersionsException;
import java.lang.reflect.InvocationTargetException;
@@ -59,4 +60,12 @@
throw new VersionsException(e);
}
}
+
+ public static YReflectionManager get(Configuration cfg) {
+ try {
+ return new YReflectionManager(cfg);
+ } catch (Exception e) {
+ throw new MappingException(e);
+ }
+ }
}
16 years, 4 months
JBoss Envers SVN: r113 - in trunk/src/main/org/jboss/envers: configuration and 13 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-17 10:24:36 -0400 (Sun, 17 Aug 2008)
New Revision: 113
Added:
trunk/src/main/org/jboss/envers/entities/EntityInstantiator.java
trunk/src/main/org/jboss/envers/entities/RevisionTypeType.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/
Removed:
trunk/src/main/org/jboss/envers/entity/
Modified:
trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/IdMappingData.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/Initializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/ListProxy.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SetProxy.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/order/RevisionVersionsOrder.java
trunk/src/main/org/jboss/envers/query/projection/DistinctVersionsProjection.java
trunk/src/main/org/jboss/envers/query/projection/ProjectionWrapper.java
trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java
trunk/src/main/org/jboss/envers/query/projection/VersionsProjectionList.java
trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/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/ModWorkUnit.java
trunk/src/main/org/jboss/envers/tools/graph/Vertex.java
trunk/src/main/org/jboss/envers/tools/log/YLog.java
trunk/src/main/org/jboss/envers/tools/log/YLogManager.java
trunk/src/main/org/jboss/envers/tools/reflection/YClass.java
trunk/src/main/org/jboss/envers/tools/reflection/YMethodsAndClasses.java
trunk/src/main/org/jboss/envers/tools/reflection/YProperty.java
trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java
Log:
ENVERS-37: moving packages to more logical places, adding final to variables
Modified: trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -170,10 +170,6 @@
revisionInfoXmlMapping,
new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdName, revisionInfoTimestampName));
}
-
- public boolean isRevisionInfoEntityName(String entityName) {
- return revisionInfoEntityName.equals(entityName);
- }
}
class RevisionInfoConfigurationResult {
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -52,7 +52,6 @@
private final VersionsEntitiesConfiguration verEntCfg;
private final VersionsSyncManager versionsSyncManager;
private final EntitiesConfigurations entCfg;
- private final RevisionInfoConfiguration revInfoCfg;
private final RevisionInfoQueryCreator revisionInfoQueryCreator;
public VersionsEntitiesConfiguration getVerEntCfg() {
@@ -63,10 +62,6 @@
return versionsSyncManager;
}
- public RevisionInfoConfiguration getRevInfoCfg() {
- return revInfoCfg;
- }
-
public GlobalConfiguration getGlobalCfg() {
return globalCfg;
}
@@ -92,7 +87,7 @@
Properties properties = cfg.getProperties();
YReflectionManager reflectionManager = getReflectionManager(cfg);
- revInfoCfg = new RevisionInfoConfiguration();
+ RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration();
RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg, reflectionManager);
verEntCfg = new VersionsEntitiesConfiguration(properties, revInfoCfgResult.getRevisionPropType());
globalCfg = new GlobalConfiguration(properties);
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -591,7 +591,7 @@
// Adding the "revision type" property
Element revTypeProperty = MetadataTools.addProperty(class_mapping, verCfg.getVerEntCfg().getRevisionTypePropName(),
verCfg.getVerEntCfg().getRevisionTypePropType(), false);
- revTypeProperty.addAttribute("type", "org.jboss.envers.entity.RevisionTypeType");
+ revTypeProperty.addAttribute("type", "org.jboss.envers.entities.RevisionTypeType");
break;
case SINGLE:
Copied: trunk/src/main/org/jboss/envers/entities/EntityInstantiator.java (from rev 112, trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/EntityInstantiator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/EntityInstantiator.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -0,0 +1,90 @@
+/*
+ * 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.entities;
+
+import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.entities.mapper.id.IdMapper;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.tools.reflection.ReflectionTools;
+
+import java.util.Map;
+import java.util.List;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class EntityInstantiator {
+ private final VersionsConfiguration verCfg;
+ private final VersionsReaderImplementor versionsReader;
+
+ public EntityInstantiator(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader) {
+ this.verCfg = verCfg;
+ this.versionsReader = versionsReader;
+ }
+
+ /**
+ * Creates an entity instance based on an entry from the versions table.
+ * @param entityName Name of the entity, which instances should be read
+ * @param versionsEntity An entry in the versions table, from which data should be mapped.
+ * @param revision Revision at which this entity was read.
+ * @return An entity instance, with versioned properties set as in the versionsEntity map, and proxies
+ * created for collections.
+ */
+ public Object createInstanceFromVersionsEntity(String entityName, Map versionsEntity, Number revision) {
+ if (versionsEntity == null) {
+ return null;
+ }
+
+ // The $type$ property holds the name of the (versions) entity
+ String type = verCfg.getEntCfg().getEntityNameForVersionsEntityName((String) versionsEntity.get("$type$"));
+
+ if (type != null) {
+ entityName = type;
+ }
+
+ Object ret;
+ try {
+ Class<?> cls = ReflectionTools.loadClass(entityName);
+ ret = cls.newInstance();
+ } catch (Exception e) {
+ throw new VersionsException(e);
+ }
+
+ IdMapper idMapper = verCfg.getEntCfg().getIdMapper(entityName);
+ Map originalId = (Map) versionsEntity.get(verCfg.getVerEntCfg().getOriginalIdPropName());
+
+ Object primaryKey = idMapper.mapToIdFromMap(originalId);
+
+ verCfg.getEntCfg().getPropertyMapper(entityName).mapToEntityFromMap(ret, versionsEntity, primaryKey, versionsReader, revision);
+ idMapper.mapToEntityFromMap(ret, originalId);
+
+ return ret;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void addInstancesFromVersionsEntities(String entityName, List list, List<Map> versionsEntities, Number revision) {
+ for (Map versionsEntity : versionsEntities) {
+ list.add(createInstanceFromVersionsEntity(entityName, versionsEntity, revision));
+ }
+ }
+}
Modified: trunk/src/main/org/jboss/envers/entities/IdMappingData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/IdMappingData.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/entities/IdMappingData.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -28,11 +28,11 @@
* @author Adam Warski (adam at warski dot org)
*/
public class IdMappingData {
- private IdMapper idMapper;
+ private final IdMapper idMapper;
// Mapping which will be used to generate the entity
- private Element xmlMapping;
+ private final Element xmlMapping;
// Mapping which will be used to generate references to the entity in related entities
- private Element xmlRelationMapping;
+ private final Element xmlRelationMapping;
public IdMappingData(IdMapper idMapper, Element xmlMapping, Element xmlRelationMapping) {
this.idMapper = idMapper;
Copied: trunk/src/main/org/jboss/envers/entities/RevisionTypeType.java (from rev 111, trunk/src/main/org/jboss/envers/entity/RevisionTypeType.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/RevisionTypeType.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/RevisionTypeType.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -0,0 +1,85 @@
+package org.jboss.envers.entities;
+
+import org.hibernate.usertype.UserType;
+import org.hibernate.HibernateException;
+import org.jboss.envers.RevisionType;
+
+import java.sql.ResultSet;
+import java.sql.Types;
+import java.sql.SQLException;
+import java.sql.PreparedStatement;
+import java.io.Serializable;
+
+/**
+ * A hibernate type for the {@link RevisionType} enum.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class RevisionTypeType implements UserType {
+ private static final int[] SQL_TYPES = { Types.TINYINT };
+
+ public int[] sqlTypes() {
+ return SQL_TYPES;
+ }
+
+ public Class returnedClass() {
+ return RevisionType.class;
+ }
+
+ public RevisionType nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException {
+ byte representation = (byte) resultSet.getInt(names[0]);
+ RevisionType result = null;
+
+ if (!resultSet.wasNull()) {
+ result = RevisionType.fromRepresentation(representation);
+ }
+
+ return result;
+ }
+
+ public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException {
+ if (null == value) {
+ preparedStatement.setNull(index, Types.TINYINT);
+ } else {
+ preparedStatement.setInt(index, ((RevisionType) value).getRepresentation());
+ }
+ }
+
+ public Object deepCopy(Object value) throws HibernateException{
+ return value;
+ }
+
+ public boolean isMutable() {
+ return false;
+ }
+
+ public Object assemble(Serializable cached, Object owner) throws HibernateException {
+ return cached;
+ }
+
+ public Serializable disassemble(Object value) throws HibernateException {
+ return (Serializable)value;
+ }
+
+ public Object replace(Object original, Object target, Object owner) throws HibernateException {
+ return original;
+ }
+
+ public int hashCode(Object x) throws HibernateException {
+ return x.hashCode();
+ }
+
+ public boolean equals(Object x, Object y) throws HibernateException {
+ //noinspection ObjectEquality
+ if (x == y) {
+ return true;
+ }
+
+ if (null == x || null == y) {
+ return false;
+ }
+
+ return x.equals(y);
+ }
+}
+
+
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyIdMapper.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyIdMapper.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -23,9 +23,9 @@
import org.jboss.envers.entities.mapper.PropertyMapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.reader.lazy.OneToManyInitializor;
-import org.jboss.envers.reader.lazy.proxy.ListProxy;
-import org.jboss.envers.reader.lazy.proxy.SetProxy;
+import org.jboss.envers.entities.mapper.relation.lazy.OneToManyInitializor;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.ListProxy;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.SetProxy;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.hibernate.property.Setter;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -26,7 +26,7 @@
import org.jboss.envers.tools.Tools;
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.reader.lazy.ToOneDelegateSessionImplementor;
+import org.jboss.envers.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor;
import org.hibernate.property.Setter;
import java.util.Map;
Copied: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy (from rev 111, trunk/src/main/org/jboss/envers/reader/lazy)
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/lazy/AbstractDelegateSessionImplementor.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.reader.lazy;
+package org.jboss.envers.entities.mapper.relation.lazy;
import org.hibernate.engine.*;
import org.hibernate.engine.query.sql.NativeSQLQuerySpecification;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/lazy/OneToManyInitializor.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyInitializor.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -19,10 +19,10 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.reader.lazy;
+package org.jboss.envers.entities.mapper.relation.lazy;
import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.reader.lazy.proxy.Initializor;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
import org.jboss.envers.query.VersionsRestrictions;
import org.jboss.envers.exception.VersionsException;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/lazy/ToOneDelegateSessionImplementor.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.reader.lazy;
+package org.jboss.envers.entities.mapper.relation.lazy;
import org.hibernate.HibernateException;
import org.jboss.envers.reader.VersionsReaderImplementor;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/lazy/proxy/CollectionProxy.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.reader.lazy.proxy;
+package org.jboss.envers.entities.mapper.relation.lazy.proxy;
import java.util.Collection;
import java.util.Iterator;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/Initializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/lazy/proxy/Initializor.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/Initializor.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.reader.lazy.proxy;
+package org.jboss.envers.entities.mapper.relation.lazy.proxy;
import java.util.Collection;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/ListProxy.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/lazy/proxy/ListProxy.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/ListProxy.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.reader.lazy.proxy;
+package org.jboss.envers.entities.mapper.relation.lazy.proxy;
import java.util.List;
import java.util.Collection;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SetProxy.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/lazy/proxy/SetProxy.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SetProxy.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.reader.lazy.proxy;
+package org.jboss.envers.entities.mapper.relation.lazy.proxy;
import java.util.Set;
Modified: trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -22,7 +22,7 @@
package org.jboss.envers.query.impl;
import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.entity.EntityInstantiator;
+import org.jboss.envers.entities.EntityInstantiator;
import org.jboss.envers.query.criteria.VersionsCriterion;
import org.jboss.envers.query.VersionsQuery;
import org.jboss.envers.query.projection.VersionsProjection;
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -36,7 +36,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public class EntitiesAtRevisionQuery extends AbstractVersionsQuery {
- private Number revision;
+ private final Number revision;
public EntitiesAtRevisionQuery(VersionsConfiguration verCfg, Session session,
VersionsReaderImplementor versionsReader, Class<?> cls,
Modified: trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -28,7 +28,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public class RevisionVersionsOrder implements VersionsOrder {
- private boolean asc;
+ private final boolean asc;
public RevisionVersionsOrder(boolean asc) {
this.asc = asc;
Modified: trunk/src/main/org/jboss/envers/query/projection/DistinctVersionsProjection.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/DistinctVersionsProjection.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/query/projection/DistinctVersionsProjection.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -29,7 +29,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public class DistinctVersionsProjection implements VersionsProjection {
- private VersionsProjection projection;
+ private final VersionsProjection projection;
public DistinctVersionsProjection(VersionsProjection projection) {
this.projection = projection;
Modified: trunk/src/main/org/jboss/envers/query/projection/ProjectionWrapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/ProjectionWrapper.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/query/projection/ProjectionWrapper.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -29,7 +29,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public class ProjectionWrapper implements VersionsProjection {
- private Projection wrapped;
+ private final Projection wrapped;
public ProjectionWrapper(Projection wrapped) {
this.wrapped = wrapped;
Modified: trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -36,7 +36,7 @@
COUNT_DISTINCT
}
- private ProjectionType type;
+ private final ProjectionType type;
public RevisionVersionsProjection(ProjectionType type) {
this.type = type;
Modified: trunk/src/main/org/jboss/envers/query/projection/VersionsProjectionList.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/VersionsProjectionList.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/query/projection/VersionsProjectionList.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -33,7 +33,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsProjectionList implements VersionsProjection {
- private List<VersionsProjection> projections;
+ private final List<VersionsProjection> projections;
public VersionsProjectionList() {
projections = new ArrayList<VersionsProjection>();
Modified: trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -30,9 +30,9 @@
* @author Adam Warski (adam at warski dot org)
*/
public class CustomRevisionInfoGenerator implements RevisionInfoGenerator {
- private RevisionListener listener;
- private Setter revisionTimestampSetter;
- private Class<?> entityClass;
+ private final RevisionListener listener;
+ private final Setter revisionTimestampSetter;
+ private final Class<?> entityClass;
public CustomRevisionInfoGenerator(Class<?> entityClass,
Class<? extends RevisionListener> listenerClass,
@@ -50,6 +50,9 @@
} catch (IllegalAccessException e) {
throw new MappingException(e);
}
+ } else {
+ // Default listener - none
+ listener = null;
}
}
Modified: trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -28,7 +28,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public class DefaultRevisionInfoGenerator implements RevisionInfoGenerator {
- private String revisionInfoTimestampName;
+ private final String revisionInfoTimestampName;
public DefaultRevisionInfoGenerator(String revisionInfoTimestampName) {
this.revisionInfoTimestampName = revisionInfoTimestampName;
Modified: trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -34,11 +34,12 @@
* @author Adam Warski (adam at warski dot org)
*/
public abstract class AbstractVersionsWorkUnit implements VersionsWorkUnit {
- protected VersionsConfiguration verCfg;
- protected Serializable id;
+ protected final VersionsConfiguration verCfg;
+ protected final Serializable id;
+ private final String entityName;
+
private Object performedData;
- private String entityName;
protected AbstractVersionsWorkUnit(String entityName, VersionsConfiguration verCfg, Serializable id) {
this.verCfg = verCfg;
Modified: trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -34,8 +34,8 @@
* @author Adam Warski (adam at warski dot org)
*/
public class AddWorkUnit extends AbstractVersionsWorkUnit implements VersionsWorkUnit {
- private Object[] state;
- private String[] propertyNames;
+ private final Object[] state;
+ private final String[] propertyNames;
public AddWorkUnit(String entityName, VersionsConfiguration verCfg, Serializable id,
EntityPersister entityPersister, Object[] state) {
Modified: trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -33,7 +33,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public class CollectionChangeWorkUnit extends AbstractVersionsWorkUnit implements VersionsWorkUnit {
- private Object entity;
+ private final Object entity;
public CollectionChangeWorkUnit(String entityName, VersionsConfiguration verCfg, Serializable id, Object entity) {
super(entityName, verCfg, id);
Modified: trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -34,8 +34,8 @@
* @author Adam Warski (adam at warski dot org)
*/
public class ModWorkUnit extends AbstractVersionsWorkUnit implements VersionsWorkUnit {
- private Map<String, Object> data;
- private boolean changes;
+ private final Map<String, Object> data;
+ private final boolean changes;
public ModWorkUnit(String entityName, VersionsConfiguration verCfg, Serializable id,
EntityPersister entityPersister, Object[] newState, Object[] oldState) {
Modified: trunk/src/main/org/jboss/envers/tools/graph/Vertex.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/graph/Vertex.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/tools/graph/Vertex.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -29,8 +29,9 @@
* @author Adam Warski (adam at warski dot org)
*/
public class Vertex<R> {
- private R representation;
- private List<Vertex<R>> neighbours;
+ private final R representation;
+ private final List<Vertex<R>> neighbours;
+
private int startTime;
private int endTime;
Modified: trunk/src/main/org/jboss/envers/tools/log/YLog.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/log/YLog.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/tools/log/YLog.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -31,10 +31,10 @@
* @author Adam Warski (adam at warski dot org)
*/
public class YLog {
- private Object delegate;
- private Method errorMethod;
- private Method warnMethod;
- private Method infoMethod;
+ private final Object delegate;
+ private final Method errorMethod;
+ private final Method warnMethod;
+ private final Method infoMethod;
public YLog(Object delegate, Class<?> argClass) {
this.delegate = delegate;
Modified: trunk/src/main/org/jboss/envers/tools/log/YLogManager.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/log/YLogManager.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/tools/log/YLogManager.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -37,10 +37,6 @@
private Class argClass;
private YLogManager() {
- initMethod();
- }
-
- private void initMethod() {
ClassLoader cl = YLogManager.class.getClassLoader();
try {
Modified: trunk/src/main/org/jboss/envers/tools/reflection/YClass.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/reflection/YClass.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/tools/reflection/YClass.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -32,8 +32,8 @@
* @author Adam Warski (adam at warski dot org)
*/
public class YClass {
- private YMethodsAndClasses ymc;
- private Object delegate;
+ private final YMethodsAndClasses ymc;
+ private final Object delegate;
public YClass(YMethodsAndClasses ymc, Object delegate) {
this.ymc = ymc;
Modified: trunk/src/main/org/jboss/envers/tools/reflection/YMethodsAndClasses.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/reflection/YMethodsAndClasses.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/tools/reflection/YMethodsAndClasses.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -29,46 +29,23 @@
* @author Adam Warski (adam at warski dot org)
*/
public class YMethodsAndClasses {
- private Method reflectionManager_classForNameMethod;
- private Method reflectionManager_equalsMethod;
+ private final Method reflectionManager_classForNameMethod;
+ private final Method reflectionManager_equalsMethod;
- private Method xClass_getNameMethod;
- private Method xClass_getSuperclassMethod;
- private Method xClass_getDeclaredPropertiesMethod;
- private Method xClass_getAnnotationMethod;
+ private final Method xClass_getNameMethod;
+ private final Method xClass_getSuperclassMethod;
+ private final Method xClass_getDeclaredPropertiesMethod;
+ private final Method xClass_getAnnotationMethod;
- private Method xProperty_getNameMethod;
- private Method xProperty_getAnnotationMethod;
- private Method xProperty_getTypeMethod;
+ private final Method xProperty_getNameMethod;
+ private final Method xProperty_getAnnotationMethod;
+ private final Method xProperty_getTypeMethod;
- private Class reflectionManagerClass;
- private Class xClassClass;
- private Class xPropertyClass;
-
public YMethodsAndClasses(Class<?> delegateClass) throws Exception {
- initClasses(delegateClass);
- initMethods();
- }
-
- private void initMethods() throws Exception {
- reflectionManager_classForNameMethod = reflectionManagerClass.getMethod("classForName", String.class, Class.class);
- reflectionManager_equalsMethod = reflectionManagerClass.getMethod("equals", xClassClass, Class.class);
-
- xClass_getNameMethod = xClassClass.getMethod("getName");
- xClass_getSuperclassMethod = xClassClass.getMethod("getSuperclass");
- xClass_getDeclaredPropertiesMethod = xClassClass.getMethod("getDeclaredProperties", String.class);
- xClass_getAnnotationMethod = xClassClass.getMethod("getAnnotation", Class.class);
-
- xProperty_getNameMethod = xPropertyClass.getMethod("getName");
- xProperty_getTypeMethod = xPropertyClass.getMethod("getType");
- xProperty_getAnnotationMethod = xPropertyClass.getMethod("getAnnotation", Class.class);
- }
-
- private void initClasses(Class<?> delegateClass) {
+ // Initializing classes
ClassLoader cl = YMethodsAndClasses.class.getClassLoader();
- reflectionManagerClass = delegateClass;
-
+ Class xClassClass;
try {
xClassClass = cl.loadClass("org.hibernate.annotations.common.reflection.XClass");
} catch (ClassNotFoundException e) {
@@ -79,6 +56,7 @@
}
}
+ Class xPropertyClass;
try {
xPropertyClass = cl.loadClass("org.hibernate.annotations.common.reflection.XProperty");
} catch (ClassNotFoundException e) {
@@ -88,6 +66,19 @@
throw new VersionsException("No XProperty found.");
}
}
+
+ // Initializing methods
+ reflectionManager_classForNameMethod = delegateClass.getMethod("classForName", String.class, Class.class);
+ reflectionManager_equalsMethod = delegateClass.getMethod("equals", xClassClass, Class.class);
+
+ xClass_getNameMethod = xClassClass.getMethod("getName");
+ xClass_getSuperclassMethod = xClassClass.getMethod("getSuperclass");
+ xClass_getDeclaredPropertiesMethod = xClassClass.getMethod("getDeclaredProperties", String.class);
+ xClass_getAnnotationMethod = xClassClass.getMethod("getAnnotation", Class.class);
+
+ xProperty_getNameMethod = xPropertyClass.getMethod("getName");
+ xProperty_getTypeMethod = xPropertyClass.getMethod("getType");
+ xProperty_getAnnotationMethod = xPropertyClass.getMethod("getAnnotation", Class.class);
}
public Method getXClass_getNameMethod() {
Modified: trunk/src/main/org/jboss/envers/tools/reflection/YProperty.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/reflection/YProperty.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/tools/reflection/YProperty.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -30,8 +30,8 @@
* @author Adam Warski (adam at warski dot org)
*/
public class YProperty {
- private YMethodsAndClasses ymc;
- private Object delegate;
+ private final YMethodsAndClasses ymc;
+ private final Object delegate;
public YProperty(YMethodsAndClasses ymc, Object delegate) {
this.ymc = ymc;
Modified: trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java 2008-08-16 17:42:15 UTC (rev 112)
+++ trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java 2008-08-17 14:24:36 UTC (rev 113)
@@ -32,8 +32,8 @@
* @author Adam Warski (adam at warski dot org)
*/
public class YReflectionManager {
- private Object delegate;
- private YMethodsAndClasses ymc;
+ private final Object delegate;
+ private final YMethodsAndClasses ymc;
public YReflectionManager(Configuration cfg) throws Exception {
delegate = cfg.getClass().getMethod("getReflectionManager").invoke(cfg);
16 years, 4 months
JBoss Envers SVN: r112 - in trunk/src/main/org/jboss/envers: configuration and 7 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-16 13:42:15 -0400 (Sat, 16 Aug 2008)
New Revision: 112
Added:
trunk/src/main/org/jboss/envers/entities/mapper/
trunk/src/main/org/jboss/envers/entities/mapper/id/QueryParameterData.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/
Removed:
trunk/src/main/org/jboss/envers/configuration/RelationDescription.java
trunk/src/main/org/jboss/envers/entities/mapper/id/QueryParameterData.java
trunk/src/main/org/jboss/envers/entities/mapper/id/relation/
trunk/src/main/org/jboss/envers/mapper/
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java
trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
trunk/src/main/org/jboss/envers/entities/IdMappingData.java
trunk/src/main/org/jboss/envers/entities/RelationDescription.java
trunk/src/main/org/jboss/envers/entities/mapper/CompositeMapperBuilder.java
trunk/src/main/org/jboss/envers/entities/mapper/CompositePropertyMapperBuilder.java
trunk/src/main/org/jboss/envers/entities/mapper/ExtendedPropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/SimpleMapperBuilder.java
trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/SubclassPropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractCompositeIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/id/EmbeddedIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/id/MultipleIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/id/SimpleIdMapperBuilder.java
trunk/src/main/org/jboss/envers/entities/mapper/id/SingleIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java
trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
Log:
ENVERS-37: moving packages to more logical places
Deleted: trunk/src/main/org/jboss/envers/configuration/RelationDescription.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RelationDescription.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/configuration/RelationDescription.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -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;
-
-import org.jboss.envers.mapper.id.IdMapper;
-
-/**
- * @author Adam Warski (adam at warski dot org)
-*/
-public class RelationDescription {
- public String fromPropertyName;
- public RelationType relationType;
- public String toEntityName;
- public String mappedByPropertyName;
- public IdMapper idMapper;
- public boolean bidirectional;
-
- public RelationDescription(String fromPropertyName, RelationType relationType, String toEntityName,
- String mappedByPropertyName, IdMapper idMapper) {
- this.fromPropertyName = fromPropertyName;
- this.relationType = relationType;
- this.toEntityName = toEntityName;
- this.mappedByPropertyName = mappedByPropertyName;
- this.idMapper = idMapper;
-
- this.bidirectional = false;
- }
-
- public static enum RelationType {
- TO_ONE,
- ONE_TO_ONE,
- ONE_TO_MANY
- }
-}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -33,11 +33,11 @@
import org.jboss.envers.entities.EntityConfiguration;
import org.jboss.envers.entities.IdMappingData;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.mapper.*;
-import org.jboss.envers.mapper.id.*;
-import org.jboss.envers.mapper.relation.ToOneIdMapper;
-import org.jboss.envers.mapper.relation.OneToOneIdMapper;
-import org.jboss.envers.mapper.relation.OneToManyIdMapper;
+import org.jboss.envers.entities.mapper.*;
+import org.jboss.envers.entities.mapper.id.*;
+import org.jboss.envers.entities.mapper.relation.ToOneIdMapper;
+import org.jboss.envers.entities.mapper.relation.OneToOneIdMapper;
+import org.jboss.envers.entities.mapper.relation.OneToManyIdMapper;
import org.jboss.envers.tools.StringTools;
import org.jboss.envers.tools.Tools;
import org.jboss.envers.tools.HibernateVersion;
Modified: trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -21,8 +21,8 @@
*/
package org.jboss.envers.entities;
-import org.jboss.envers.mapper.id.IdMapper;
-import org.jboss.envers.mapper.ExtendedPropertyMapper;
+import org.jboss.envers.entities.mapper.id.IdMapper;
+import org.jboss.envers.entities.mapper.ExtendedPropertyMapper;
import java.util.Map;
import java.util.HashMap;
Modified: trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -22,8 +22,8 @@
package org.jboss.envers.entities;
import org.jboss.envers.entities.RelationDescription;
-import org.jboss.envers.mapper.ExtendedPropertyMapper;
-import org.jboss.envers.mapper.id.IdMapper;
+import org.jboss.envers.entities.mapper.ExtendedPropertyMapper;
+import org.jboss.envers.entities.mapper.id.IdMapper;
import java.util.Map;
import java.util.HashMap;
Modified: trunk/src/main/org/jboss/envers/entities/IdMappingData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/IdMappingData.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/IdMappingData.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -21,7 +21,7 @@
*/
package org.jboss.envers.entities;
-import org.jboss.envers.mapper.id.IdMapper;
+import org.jboss.envers.entities.mapper.id.IdMapper;
import org.dom4j.Element;
/**
Modified: trunk/src/main/org/jboss/envers/entities/RelationDescription.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/RelationDescription.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/RelationDescription.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -21,7 +21,7 @@
*/
package org.jboss.envers.entities;
-import org.jboss.envers.mapper.id.IdMapper;
+import org.jboss.envers.entities.mapper.id.IdMapper;
/**
* @author Adam Warski (adam at warski dot org)
Copied: trunk/src/main/org/jboss/envers/entities/mapper (from rev 110, trunk/src/main/org/jboss/envers/mapper)
Modified: trunk/src/main/org/jboss/envers/entities/mapper/CompositeMapperBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/CompositeMapperBuilder.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/CompositeMapperBuilder.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper;
+package org.jboss.envers.entities.mapper;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/entities/mapper/CompositePropertyMapperBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/CompositePropertyMapperBuilder.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/CompositePropertyMapperBuilder.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper;
+package org.jboss.envers.entities.mapper;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/entities/mapper/ExtendedPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/ExtendedPropertyMapper.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/ExtendedPropertyMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper;
+package org.jboss.envers.entities.mapper;
import java.util.Map;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/MapPropertyMapper.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper;
+package org.jboss.envers.entities.mapper;
import org.jboss.envers.ModificationStore;
import org.jboss.envers.tools.reflection.ReflectionTools;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/MultiPropertyMapper.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper;
+package org.jboss.envers.entities.mapper;
import org.hibernate.property.Getter;
import org.hibernate.MappingException;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/PropertyMapper.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper;
+package org.jboss.envers.entities.mapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/SimpleMapperBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/SimpleMapperBuilder.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/SimpleMapperBuilder.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper;
+package org.jboss.envers.entities.mapper;
import org.jboss.envers.ModificationStore;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/SinglePropertyMapper.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper;
+package org.jboss.envers.entities.mapper;
import org.jboss.envers.ModificationStore;
import org.jboss.envers.tools.reflection.ReflectionTools;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/SubclassPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/SubclassPropertyMapper.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/SubclassPropertyMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper;
+package org.jboss.envers.entities.mapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.ModificationStore;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractCompositeIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/AbstractCompositeIdMapper.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractCompositeIdMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper.id;
+package org.jboss.envers.entities.mapper.id;
import org.jboss.envers.ModificationStore;
import org.jboss.envers.exception.VersionsException;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/AbstractIdMapper.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper.id;
+package org.jboss.envers.entities.mapper.id;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.Criterion;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/EmbeddedIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/EmbeddedIdMapper.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/EmbeddedIdMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper.id;
+package org.jboss.envers.entities.mapper.id;
import org.hibernate.property.Getter;
import org.hibernate.property.Setter;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/IdMapper.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper.id;
+package org.jboss.envers.entities.mapper.id;
import org.hibernate.criterion.Criterion;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/MultipleIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/MultipleIdMapper.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/MultipleIdMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper.id;
+package org.jboss.envers.entities.mapper.id;
import org.jboss.envers.exception.VersionsException;
Deleted: trunk/src/main/org/jboss/envers/entities/mapper/id/QueryParameterData.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/QueryParameterData.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/QueryParameterData.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -1,63 +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.mapper.id;
-
-import org.hibernate.Query;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class QueryParameterData {
- private String flatEntityPropertyName;
- private Object value;
-
- public QueryParameterData(String flatEntityPropertyName, Object value) {
- this.flatEntityPropertyName = flatEntityPropertyName;
- this.value = value;
- }
-
- public void appendProperty(StringBuilder queryStr, String prefix) {
- queryStr.append(prefix).append(".");
- queryStr.append(flatEntityPropertyName);
- }
-
- public String getProperty(String prefix) {
- if (prefix != null) {
- return prefix + "." + flatEntityPropertyName;
- } else {
- return flatEntityPropertyName;
- }
- }
-
- public Object getValue() {
- return value;
- }
-
- public void appendPropertyWithParameter(StringBuilder queryStr, String prefix) {
- appendProperty(queryStr, prefix);
- queryStr.append(" = :").append(flatEntityPropertyName);
- }
-
- public void setQueryParameter(Query query) {
- query.setParameter(flatEntityPropertyName, value);
- }
-}
Copied: trunk/src/main/org/jboss/envers/entities/mapper/id/QueryParameterData.java (from rev 111, trunk/src/main/org/jboss/envers/mapper/id/QueryParameterData.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/QueryParameterData.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/QueryParameterData.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -0,0 +1,47 @@
+/*
+ * 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.entities.mapper.id;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class QueryParameterData {
+ private String flatEntityPropertyName;
+ private Object value;
+
+ public QueryParameterData(String flatEntityPropertyName, Object value) {
+ this.flatEntityPropertyName = flatEntityPropertyName;
+ this.value = value;
+ }
+
+ public String getProperty(String prefix) {
+ if (prefix != null) {
+ return prefix + "." + flatEntityPropertyName;
+ } else {
+ return flatEntityPropertyName;
+ }
+ }
+
+ public Object getValue() {
+ return value;
+ }
+}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/SimpleIdMapperBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/SimpleIdMapperBuilder.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/SimpleIdMapperBuilder.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,9 +19,9 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper.id;
+package org.jboss.envers.entities.mapper.id;
-import org.jboss.envers.mapper.SimpleMapperBuilder;
+import org.jboss.envers.entities.mapper.SimpleMapperBuilder;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/SingleIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/SingleIdMapper.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/SingleIdMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper.id;
+package org.jboss.envers.entities.mapper.id;
import org.jboss.envers.ModificationStore;
import org.jboss.envers.tools.reflection.ReflectionTools;
Copied: trunk/src/main/org/jboss/envers/entities/mapper/relation (from rev 111, trunk/src/main/org/jboss/envers/mapper/relation)
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/relation/OneToManyIdMapper.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyIdMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,9 +19,9 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper.relation;
+package org.jboss.envers.entities.mapper.relation;
-import org.jboss.envers.mapper.PropertyMapper;
+import org.jboss.envers.entities.mapper.PropertyMapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.reader.lazy.OneToManyInitializor;
import org.jboss.envers.reader.lazy.proxy.ListProxy;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/relation/OneToOneIdMapper.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneIdMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,9 +19,9 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper.relation;
+package org.jboss.envers.entities.mapper.relation;
-import org.jboss.envers.mapper.PropertyMapper;
+import org.jboss.envers.entities.mapper.PropertyMapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.query.VersionsRestrictions;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/relation/ToOneIdMapper.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/ToOneIdMapper.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -19,10 +19,10 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper.relation;
+package org.jboss.envers.entities.mapper.relation;
-import org.jboss.envers.mapper.PropertyMapper;
-import org.jboss.envers.mapper.id.IdMapper;
+import org.jboss.envers.entities.mapper.PropertyMapper;
+import org.jboss.envers.entities.mapper.id.IdMapper;
import org.jboss.envers.tools.Tools;
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
Modified: trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -23,7 +23,7 @@
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.mapper.id.IdMapper;
+import org.jboss.envers.entities.mapper.id.IdMapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.tools.reflection.ReflectionTools;
Modified: trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
===================================================================
--- trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-16 17:39:05 UTC (rev 111)
+++ trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-16 17:42:15 UTC (rev 112)
@@ -32,7 +32,7 @@
import org.jboss.envers.synchronization.work.DelWorkUnit;
import org.jboss.envers.synchronization.work.CollectionChangeWorkUnit;
import org.jboss.envers.tools.Tools;
-import org.jboss.envers.mapper.id.IdMapper;
+import org.jboss.envers.entities.mapper.id.IdMapper;
import java.io.Serializable;
16 years, 4 months
JBoss Envers SVN: r111 - in trunk/src/main/org/jboss/envers: configuration and 7 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-16 13:39:05 -0400 (Sat, 16 Aug 2008)
New Revision: 111
Added:
trunk/src/main/org/jboss/envers/entities/
trunk/src/main/org/jboss/envers/entities/RelationDescription.java
trunk/src/main/org/jboss/envers/mapper/relation/
trunk/src/main/org/jboss/envers/mapper/relation/OneToManyIdMapper.java
trunk/src/main/org/jboss/envers/mapper/relation/ToOneIdMapper.java
Removed:
trunk/src/main/org/jboss/envers/configuration/entities/
trunk/src/main/org/jboss/envers/mapper/id/relation/
trunk/src/main/org/jboss/envers/mapper/relation/OneToManyIdMapper.java
trunk/src/main/org/jboss/envers/mapper/relation/ToOneIdMapper.java
Modified:
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java
trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
trunk/src/main/org/jboss/envers/entities/IdMappingData.java
trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
trunk/src/main/org/jboss/envers/mapper/id/QueryParameterData.java
trunk/src/main/org/jboss/envers/mapper/relation/OneToOneIdMapper.java
trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java
trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java
Log:
ENVERS-37: moving packages to more logical places
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -27,7 +27,7 @@
import org.jboss.envers.configuration.metadata.VersionsMetadataGenerator;
import org.jboss.envers.configuration.metadata.AnnotationsMetadataReader;
import org.jboss.envers.configuration.metadata.PersistentClassVersioningData;
-import org.jboss.envers.configuration.entities.EntitiesConfigurations;
+import org.jboss.envers.entities.EntitiesConfigurations;
import org.jboss.envers.synchronization.VersionsSyncManager;
import org.jboss.envers.tools.graph.GraphTopologicalSort;
import org.jboss.envers.tools.reflection.YReflectionManager;
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -30,14 +30,14 @@
import org.dom4j.DocumentHelper;
import org.dom4j.Attribute;
import org.dom4j.tree.DefaultElement;
-import org.jboss.envers.configuration.entities.EntityConfiguration;
-import org.jboss.envers.configuration.entities.IdMappingData;
+import org.jboss.envers.entities.EntityConfiguration;
+import org.jboss.envers.entities.IdMappingData;
import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.mapper.*;
import org.jboss.envers.mapper.id.*;
-import org.jboss.envers.mapper.id.relation.ToOneIdMapper;
-import org.jboss.envers.mapper.id.relation.OneToOneIdMapper;
-import org.jboss.envers.mapper.id.relation.OneToManyIdMapper;
+import org.jboss.envers.mapper.relation.ToOneIdMapper;
+import org.jboss.envers.mapper.relation.OneToOneIdMapper;
+import org.jboss.envers.mapper.relation.OneToManyIdMapper;
import org.jboss.envers.tools.StringTools;
import org.jboss.envers.tools.Tools;
import org.jboss.envers.tools.HibernateVersion;
Copied: trunk/src/main/org/jboss/envers/entities (from rev 109, trunk/src/main/org/jboss/envers/configuration/entities)
Modified: trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/entities/EntitiesConfigurations.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -19,11 +19,10 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.configuration.entities;
+package org.jboss.envers.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;
Modified: trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/entities/EntityConfiguration.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -19,9 +19,9 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.configuration.entities;
+package org.jboss.envers.entities;
-import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.mapper.ExtendedPropertyMapper;
import org.jboss.envers.mapper.id.IdMapper;
Modified: trunk/src/main/org/jboss/envers/entities/IdMappingData.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/entities/IdMappingData.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/entities/IdMappingData.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.configuration.entities;
+package org.jboss.envers.entities;
import org.jboss.envers.mapper.id.IdMapper;
import org.dom4j.Element;
Copied: trunk/src/main/org/jboss/envers/entities/RelationDescription.java (from rev 109, trunk/src/main/org/jboss/envers/configuration/RelationDescription.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/RelationDescription.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/RelationDescription.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -0,0 +1,53 @@
+/*
+ * 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.entities;
+
+import org.jboss.envers.mapper.id.IdMapper;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+*/
+public class RelationDescription {
+ public final String fromPropertyName;
+ public final RelationType relationType;
+ public final String toEntityName;
+ public final String mappedByPropertyName;
+ public final IdMapper idMapper;
+ public boolean bidirectional;
+
+ public RelationDescription(String fromPropertyName, RelationType relationType, String toEntityName,
+ String mappedByPropertyName, IdMapper idMapper) {
+ this.fromPropertyName = fromPropertyName;
+ this.relationType = relationType;
+ this.toEntityName = toEntityName;
+ this.mappedByPropertyName = mappedByPropertyName;
+ this.idMapper = idMapper;
+
+ this.bidirectional = false;
+ }
+
+ public static enum RelationType {
+ TO_ONE,
+ ONE_TO_ONE,
+ ONE_TO_MANY
+ }
+}
Modified: trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
===================================================================
--- trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -25,7 +25,7 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.persister.entity.EntityPersister;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.synchronization.VersionsSync;
import org.jboss.envers.synchronization.work.AddWorkUnit;
import org.jboss.envers.synchronization.work.ModWorkUnit;
Modified: trunk/src/main/org/jboss/envers/mapper/id/QueryParameterData.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/QueryParameterData.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/mapper/id/QueryParameterData.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -21,8 +21,6 @@
*/
package org.jboss.envers.mapper.id;
-import org.hibernate.Query;
-
/**
* @author Adam Warski (adam at warski dot org)
*/
@@ -35,11 +33,6 @@
this.value = value;
}
- public void appendProperty(StringBuilder queryStr, String prefix) {
- queryStr.append(prefix).append(".");
- queryStr.append(flatEntityPropertyName);
- }
-
public String getProperty(String prefix) {
if (prefix != null) {
return prefix + "." + flatEntityPropertyName;
@@ -51,13 +44,4 @@
public Object getValue() {
return value;
}
-
- public void appendPropertyWithParameter(StringBuilder queryStr, String prefix) {
- appendProperty(queryStr, prefix);
- queryStr.append(" = :").append(flatEntityPropertyName);
- }
-
- public void setQueryParameter(Query query) {
- query.setParameter(flatEntityPropertyName, value);
- }
}
Copied: trunk/src/main/org/jboss/envers/mapper/relation (from rev 109, trunk/src/main/org/jboss/envers/mapper/id/relation)
Deleted: trunk/src/main/org/jboss/envers/mapper/relation/OneToManyIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/mapper/relation/OneToManyIdMapper.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -1,80 +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.mapper.id.relation;
-
-import org.jboss.envers.mapper.PropertyMapper;
-import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.reader.lazy.OneToManyInitializor;
-import org.jboss.envers.reader.lazy.proxy.ListProxy;
-import org.jboss.envers.reader.lazy.proxy.SetProxy;
-import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.tools.reflection.ReflectionTools;
-import org.hibernate.property.Setter;
-import org.hibernate.property.Getter;
-
-import java.util.*;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class OneToManyIdMapper implements PropertyMapper {
- private String owningReferencePropertyName;
- private String owningEntityName;
- private String propertyName;
-
- public OneToManyIdMapper(String owningReferencePropertyName, String owningEntityName, String propertyName) {
- this.owningReferencePropertyName = owningReferencePropertyName;
- this.owningEntityName = owningEntityName;
- this.propertyName = propertyName;
- }
-
- public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj) {
- return false;
- }
-
- @SuppressWarnings({"unchecked"})
- public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
- if (obj == null) {
- return;
- }
-
- Class<?> entityClass = ReflectionTools.loadClass(owningEntityName);
-
- Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyName);
- Class collectionClass = getter.getReturnType();
-
- // todo: investigate generics
- Object value;
- if (List.class.isAssignableFrom(collectionClass)) {
- value = new ListProxy(new OneToManyInitializor<ArrayList>(versionsReader, entityClass,
- owningReferencePropertyName, primaryKey, revision, ArrayList.class));
- } else if (Set.class.isAssignableFrom(collectionClass) || Collection.class.isAssignableFrom(collectionClass)) {
- value = new SetProxy(new OneToManyInitializor<HashSet>(versionsReader, entityClass,
- owningReferencePropertyName, primaryKey, revision, HashSet.class));
- } else {
- throw new VersionsException("Unsupported versioned collection type: " + collectionClass.getName());
- }
-
- Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyName);
- setter.set(obj, value, null);
- }
-}
\ No newline at end of file
Copied: trunk/src/main/org/jboss/envers/mapper/relation/OneToManyIdMapper.java (from rev 110, trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java)
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/relation/OneToManyIdMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/mapper/relation/OneToManyIdMapper.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -0,0 +1,80 @@
+/*
+ * 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.mapper.relation;
+
+import org.jboss.envers.mapper.PropertyMapper;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.reader.lazy.OneToManyInitializor;
+import org.jboss.envers.reader.lazy.proxy.ListProxy;
+import org.jboss.envers.reader.lazy.proxy.SetProxy;
+import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.tools.reflection.ReflectionTools;
+import org.hibernate.property.Setter;
+import org.hibernate.property.Getter;
+
+import java.util.*;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class OneToManyIdMapper implements PropertyMapper {
+ private final String owningReferencePropertyName;
+ private final String owningEntityName;
+ private final String propertyName;
+
+ public OneToManyIdMapper(String owningReferencePropertyName, String owningEntityName, String propertyName) {
+ this.owningReferencePropertyName = owningReferencePropertyName;
+ this.owningEntityName = owningEntityName;
+ this.propertyName = propertyName;
+ }
+
+ public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj) {
+ return false;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
+ if (obj == null) {
+ return;
+ }
+
+ Class<?> entityClass = ReflectionTools.loadClass(owningEntityName);
+
+ Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyName);
+ Class collectionClass = getter.getReturnType();
+
+ // todo: investigate generics
+ Object value;
+ if (List.class.isAssignableFrom(collectionClass)) {
+ value = new ListProxy(new OneToManyInitializor<ArrayList>(versionsReader, entityClass,
+ owningReferencePropertyName, primaryKey, revision, ArrayList.class));
+ } else if (Set.class.isAssignableFrom(collectionClass) || Collection.class.isAssignableFrom(collectionClass)) {
+ value = new SetProxy(new OneToManyInitializor<HashSet>(versionsReader, entityClass,
+ owningReferencePropertyName, primaryKey, revision, HashSet.class));
+ } else {
+ throw new VersionsException("Unsupported versioned collection type: " + collectionClass.getName());
+ }
+
+ Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyName);
+ setter.set(obj, value, null);
+ }
+}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/mapper/relation/OneToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/mapper/relation/OneToOneIdMapper.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.mapper.id.relation;
+package org.jboss.envers.mapper.relation;
import org.jboss.envers.mapper.PropertyMapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
Deleted: trunk/src/main/org/jboss/envers/mapper/relation/ToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/relation/ToOneIdMapper.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/mapper/relation/ToOneIdMapper.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -1,82 +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.mapper.id.relation;
-
-import org.jboss.envers.mapper.PropertyMapper;
-import org.jboss.envers.mapper.id.IdMapper;
-import org.jboss.envers.tools.Tools;
-import org.jboss.envers.tools.reflection.ReflectionTools;
-import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.reader.lazy.ToOneDelegateSessionImplementor;
-import org.hibernate.property.Setter;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class ToOneIdMapper implements PropertyMapper {
- private IdMapper delegate;
- private String propertyName;
- private String referencedEntityName;
-
- public ToOneIdMapper(IdMapper delegate, String propertyName, String referencedEntityName) {
- this.delegate = delegate;
- this.propertyName = propertyName;
- this.referencedEntityName = referencedEntityName;
- }
-
- public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj) {
- HashMap<String, Object> newData = new HashMap<String, Object>();
- data.put(propertyName, newData);
-
- delegate.mapToMapFromEntity(newData, newObj);
-
- return !Tools.objectsEqual(newObj, oldObj);
- }
-
- public void mapToEntityFromMap(Object obj, Map data, Object primaryKey,
- VersionsReaderImplementor versionsReader, Number revision) {
- if (obj == null) {
- return;
- }
-
- Object entityId = delegate.mapToIdFromMap((Map) data.get(propertyName));
- doMap(obj, versionsReader, revision, entityId);
- }
-
- private void doMap(Object obj, VersionsReaderImplementor versionsReader, Number revision, Object entityId) {
- Object value;
- if (entityId == null) {
- value = null;
- } else {
- Class<?> entityClass = ReflectionTools.loadClass(referencedEntityName);
-
- value = versionsReader.getSessionImplementor().getFactory().getEntityPersister(referencedEntityName).
- createProxy(null, new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision));
- }
-
- Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyName);
- setter.set(obj, value, null);
- }
-}
Copied: trunk/src/main/org/jboss/envers/mapper/relation/ToOneIdMapper.java (from rev 110, trunk/src/main/org/jboss/envers/mapper/id/relation/ToOneIdMapper.java)
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/relation/ToOneIdMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/mapper/relation/ToOneIdMapper.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -0,0 +1,82 @@
+/*
+ * 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.mapper.relation;
+
+import org.jboss.envers.mapper.PropertyMapper;
+import org.jboss.envers.mapper.id.IdMapper;
+import org.jboss.envers.tools.Tools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.reader.lazy.ToOneDelegateSessionImplementor;
+import org.hibernate.property.Setter;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ToOneIdMapper implements PropertyMapper {
+ private final IdMapper delegate;
+ private final String propertyName;
+ private final String referencedEntityName;
+
+ public ToOneIdMapper(IdMapper delegate, String propertyName, String referencedEntityName) {
+ this.delegate = delegate;
+ this.propertyName = propertyName;
+ this.referencedEntityName = referencedEntityName;
+ }
+
+ public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj) {
+ HashMap<String, Object> newData = new HashMap<String, Object>();
+ data.put(propertyName, newData);
+
+ delegate.mapToMapFromEntity(newData, newObj);
+
+ return !Tools.objectsEqual(newObj, oldObj);
+ }
+
+ public void mapToEntityFromMap(Object obj, Map data, Object primaryKey,
+ VersionsReaderImplementor versionsReader, Number revision) {
+ if (obj == null) {
+ return;
+ }
+
+ Object entityId = delegate.mapToIdFromMap((Map) data.get(propertyName));
+ doMap(obj, versionsReader, revision, entityId);
+ }
+
+ private void doMap(Object obj, VersionsReaderImplementor versionsReader, Number revision, Object entityId) {
+ Object value;
+ if (entityId == null) {
+ value = null;
+ } else {
+ Class<?> entityClass = ReflectionTools.loadClass(referencedEntityName);
+
+ value = versionsReader.getSessionImplementor().getFactory().getEntityPersister(referencedEntityName).
+ createProxy(null, new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision));
+ }
+
+ Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyName);
+ setter.set(obj, value, null);
+ }
+}
Modified: trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -22,7 +22,7 @@
package org.jboss.envers.query.criteria;
import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
/**
Modified: trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -24,7 +24,7 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
/**
Modified: trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -24,7 +24,7 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
/**
Modified: trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -23,7 +23,7 @@
import org.hibernate.criterion.Criterion;
import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
/**
Modified: trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java 2008-08-16 12:44:50 UTC (rev 110)
+++ trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java 2008-08-16 17:39:05 UTC (rev 111)
@@ -23,7 +23,7 @@
import org.hibernate.criterion.Criterion;
import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
/**
16 years, 4 months
JBoss Envers SVN: r110 - in trunk/src/main/org/jboss/envers: configuration/metadata and 6 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-16 08:44:50 -0400 (Sat, 16 Aug 2008)
New Revision: 110
Added:
trunk/src/main/org/jboss/envers/configuration/metadata/PersistentClassVersioningData.java
trunk/src/main/org/jboss/envers/configuration/metadata/PropertyStoreInfo.java
Removed:
trunk/src/main/org/jboss/envers/configuration/metadata/data/
Modified:
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.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/mapper/id/relation/OneToManyIdMapper.java
trunk/src/main/org/jboss/envers/mapper/id/relation/ToOneIdMapper.java
trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.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/reader/VersionsReaderImpl.java
trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java
trunk/src/main/org/jboss/envers/reader/lazy/ToOneDelegateSessionImplementor.java
trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoQueryCreator.java
Log:
ENVERS-37: versions reader no longer is a holder of Session
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -26,7 +26,7 @@
import org.hibernate.MappingException;
import org.jboss.envers.configuration.metadata.VersionsMetadataGenerator;
import org.jboss.envers.configuration.metadata.AnnotationsMetadataReader;
-import org.jboss.envers.configuration.metadata.data.PersistentClassVersioningData;
+import org.jboss.envers.configuration.metadata.PersistentClassVersioningData;
import org.jboss.envers.configuration.entities.EntitiesConfigurations;
import org.jboss.envers.synchronization.VersionsSyncManager;
import org.jboss.envers.tools.graph.GraphTopologicalSort;
@@ -75,7 +75,7 @@
return entCfg;
}
- public RevisionInfoQueryCreator getRevisionInfoQueryGenerator() {
+ public RevisionInfoQueryCreator getRevisionInfoQueryCreator() {
return revisionInfoQueryCreator;
}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -24,7 +24,7 @@
import org.jboss.envers.tools.reflection.YClass;
import org.jboss.envers.tools.reflection.YProperty;
import org.jboss.envers.tools.reflection.YReflectionManager;
-import org.jboss.envers.configuration.metadata.data.PersistentClassVersioningData;
+import org.jboss.envers.configuration.metadata.PersistentClassVersioningData;
import org.jboss.envers.Versioned;
import org.jboss.envers.VersionsTable;
import org.jboss.envers.SecondaryVersionsTable;
Copied: trunk/src/main/org/jboss/envers/configuration/metadata/PersistentClassVersioningData.java (from rev 104, trunk/src/main/org/jboss/envers/configuration/metadata/data/PersistentClassVersioningData.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/PersistentClassVersioningData.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/PersistentClassVersioningData.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -0,0 +1,49 @@
+/*
+ * 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.jboss.envers.ModificationStore;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+*/
+public class PersistentClassVersioningData {
+ public PersistentClassVersioningData() {
+ propertyStoreInfo = new PropertyStoreInfo(new HashMap<String, ModificationStore>());
+ secondaryTableDictionary = new HashMap<String, String>();
+ }
+
+ public PropertyStoreInfo propertyStoreInfo;
+ public String versionsTableName;
+ 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;
+ }
+}
Copied: trunk/src/main/org/jboss/envers/configuration/metadata/PropertyStoreInfo.java (from rev 103, trunk/src/main/org/jboss/envers/configuration/metadata/data/PropertyStoreInfo.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/PropertyStoreInfo.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/PropertyStoreInfo.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -0,0 +1,46 @@
+/*
+ * 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.jboss.envers.ModificationStore;
+
+import java.util.Map;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+*/
+public class PropertyStoreInfo {
+ // Not null if the whole class is versioned
+ public ModificationStore defaultStore;
+
+ // Maps property names to their stores defined in per-field versioned annotations
+ public Map<String, ModificationStore> propertyStores;
+
+ public PropertyStoreInfo(Map<String, ModificationStore> propertyStores) {
+ this.propertyStores = propertyStores;
+ }
+
+ public PropertyStoreInfo(ModificationStore defaultStore, Map<String, ModificationStore> propertyStores) {
+ this.defaultStore = defaultStore;
+ this.propertyStores = propertyStores;
+ }
+}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -44,8 +44,8 @@
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.PersistentClassVersioningData;
-import org.jboss.envers.configuration.metadata.data.PropertyStoreInfo;
+import org.jboss.envers.configuration.metadata.PersistentClassVersioningData;
+import org.jboss.envers.configuration.metadata.PropertyStoreInfo;
import org.jboss.envers.exception.VersionsException;
import java.util.Iterator;
Modified: trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -37,9 +37,9 @@
* @author Adam Warski (adam at warski dot org)
*/
public class OneToManyIdMapper implements PropertyMapper {
- private String owningReferencePropertyName;
- private String owningEntityName;
- private String propertyName;
+ private final String owningReferencePropertyName;
+ private final String owningEntityName;
+ private final String propertyName;
public OneToManyIdMapper(String owningReferencePropertyName, String owningEntityName, String propertyName) {
this.owningReferencePropertyName = owningReferencePropertyName;
Modified: trunk/src/main/org/jboss/envers/mapper/id/relation/ToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/relation/ToOneIdMapper.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/mapper/id/relation/ToOneIdMapper.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -36,9 +36,9 @@
* @author Adam Warski (adam at warski dot org)
*/
public class ToOneIdMapper implements PropertyMapper {
- private IdMapper delegate;
- private String propertyName;
- private String referencedEntityName;
+ private final IdMapper delegate;
+ private final String propertyName;
+ private final String referencedEntityName;
public ToOneIdMapper(IdMapper delegate, String propertyName, String referencedEntityName) {
this.delegate = delegate;
Modified: trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -26,16 +26,19 @@
import org.jboss.envers.query.impl.RevisionsOfEntityQuery;
import static org.jboss.envers.tools.ArgumentsTools.*;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.hibernate.Session;
/**
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsQueryCreator {
private final VersionsConfiguration verCfg;
+ private final Session session;
private final VersionsReaderImplementor versionsReaderImplementor;
- public VersionsQueryCreator(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReaderImplementor) {
+ public VersionsQueryCreator(VersionsConfiguration verCfg, Session session, VersionsReaderImplementor versionsReaderImplementor) {
this.verCfg = verCfg;
+ this.session = session;
this.versionsReaderImplementor = versionsReaderImplementor;
}
@@ -51,7 +54,7 @@
public VersionsQuery forEntitiesAtRevision(Class<?> c, Number revision) {
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
- return new EntitiesAtRevisionQuery(verCfg, versionsReaderImplementor, c, revision);
+ return new EntitiesAtRevisionQuery(verCfg, session, versionsReaderImplementor, c, revision);
}
/**
@@ -70,6 +73,6 @@
* unless an order or projection is added.
*/
public VersionsQuery forRevisionsOfEntity(Class<?> c, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
- return new RevisionsOfEntityQuery(verCfg, versionsReaderImplementor, c, selectEntitiesOnly,selectDeletedEntities);
+ return new RevisionsOfEntityQuery(verCfg, session, versionsReaderImplementor, c, selectEntitiesOnly,selectDeletedEntities);
}
}
Modified: trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -31,10 +31,7 @@
import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.Order;
-import org.hibernate.Criteria;
-import org.hibernate.FlushMode;
-import org.hibernate.CacheMode;
-import org.hibernate.LockMode;
+import org.hibernate.*;
import javax.persistence.NonUniqueResultException;
import javax.persistence.NoResultException;
@@ -58,7 +55,8 @@
protected final VersionsConfiguration verCfg;
- protected AbstractVersionsQuery(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader, Class<?> cls) {
+ protected AbstractVersionsQuery(VersionsConfiguration verCfg, Session session,
+ VersionsReaderImplementor versionsReader, Class<?> cls) {
this.verCfg = verCfg;
criterions = new ArrayList<VersionsCriterion>();
@@ -66,7 +64,7 @@
entityName = cls.getName();
versionsEntityName = verCfg.getVerEntCfg().getVersionsEntityName(entityName);
- versionsCriteria = versionsReader.getSession().createCriteria(versionsEntityName, "e");
+ versionsCriteria = session.createCriteria(versionsEntityName, "e");
}
public abstract List list() throws VersionsException;
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -27,6 +27,7 @@
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.criterion.*;
+import org.hibernate.Session;
import java.util.List;
import java.util.ArrayList;
@@ -37,9 +38,10 @@
public class EntitiesAtRevisionQuery extends AbstractVersionsQuery {
private Number revision;
- public EntitiesAtRevisionQuery(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader, Class<?> cls,
+ public EntitiesAtRevisionQuery(VersionsConfiguration verCfg, Session session,
+ VersionsReaderImplementor versionsReader, Class<?> cls,
Number revision) {
- super(verCfg, versionsReader, cls);
+ super(verCfg, session, versionsReader, cls);
this.revision = revision;
}
Modified: trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -29,6 +29,7 @@
import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Property;
+import org.hibernate.Session;
import java.util.List;
import java.util.ArrayList;
@@ -41,9 +42,11 @@
private final boolean selectEntitiesOnly;
private final boolean selectDeletedEntities;
- public RevisionsOfEntityQuery(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader,
- Class<?> cls, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
- super(verCfg, versionsReader, cls);
+ public RevisionsOfEntityQuery(VersionsConfiguration verCfg, Session session,
+ VersionsReaderImplementor versionsReader,
+ Class<?> cls, boolean selectEntitiesOnly,
+ boolean selectDeletedEntities) {
+ super(verCfg, session, versionsReader, cls);
this.selectEntitiesOnly = selectEntitiesOnly;
this.selectDeletedEntities = selectDeletedEntities;
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -64,10 +64,6 @@
return sessionImplementor;
}
- public Session getSession() {
- return session;
- }
-
@SuppressWarnings({"unchecked"})
public <T> T find(Class<T> cls, Object primaryKey, Number revision) throws
IllegalArgumentException, NotVersionedException, IllegalStateException {
@@ -119,7 +115,7 @@
checkPositive(revision, "Entity revision");
checkSession();
- Query query = verCfg.getRevisionInfoQueryGenerator().getRevisionDateQuery(session, revision);
+ Query query = verCfg.getRevisionInfoQueryCreator().getRevisionDateQuery(session, revision);
try {
Long timestamp = (Long) query.uniqueResult();
@@ -137,7 +133,7 @@
checkNotNull(date, "Date of revision");
checkSession();
- Query query = verCfg.getRevisionInfoQueryGenerator().getRevisionNumberForDateQuery(session, date);
+ Query query = verCfg.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery(session, date);
try {
Number res = (Number) query.uniqueResult();
@@ -158,7 +154,7 @@
checkPositive(revision, "Entity revision");
checkSession();
- Query query = verCfg.getRevisionInfoQueryGenerator().getRevisionQuery(session, revision);
+ Query query = verCfg.getRevisionInfoQueryCreator().getRevisionQuery(session, revision);
try {
T revisionData = (T) query.uniqueResult();
@@ -174,6 +170,6 @@
}
public VersionsQueryCreator createQuery() {
- return new VersionsQueryCreator(verCfg, this);
+ return new VersionsQueryCreator(verCfg, session, this);
}
}
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -22,9 +22,7 @@
package org.jboss.envers.reader;
import org.hibernate.engine.SessionImplementor;
-import org.hibernate.Session;
import org.jboss.envers.VersionsReader;
-import org.jboss.envers.configuration.VersionsConfiguration;
/**
* An interface exposed by a VersionsReader to library-facing classes.
@@ -32,6 +30,4 @@
*/
public interface VersionsReaderImplementor extends VersionsReader {
SessionImplementor getSessionImplementor();
-
- Session getSession();
}
Modified: trunk/src/main/org/jboss/envers/reader/lazy/ToOneDelegateSessionImplementor.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/lazy/ToOneDelegateSessionImplementor.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/reader/lazy/ToOneDelegateSessionImplementor.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -28,10 +28,10 @@
* @author Adam Warski (adam at warski dot org)
*/
public class ToOneDelegateSessionImplementor extends AbstractDelegateSessionImplementor {
- private VersionsReaderImplementor versionsReader;
- private Class<?> entityClass;
- private Object entityId;
- private Number revision;
+ private final VersionsReaderImplementor versionsReader;
+ private final Class<?> entityClass;
+ private final Object entityId;
+ private final Number revision;
public ToOneDelegateSessionImplementor(VersionsReaderImplementor versionsReader,
Class<?> entityClass, Object entityId, Number revision) {
Modified: trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoQueryCreator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoQueryCreator.java 2008-08-16 12:33:03 UTC (rev 109)
+++ trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoQueryCreator.java 2008-08-16 12:44:50 UTC (rev 110)
@@ -14,7 +14,7 @@
private final String revisionQuery;
public RevisionInfoQueryCreator(String revisionInfoEntityName, String revisionInfoIdName,
- String revisionInfoTimestampName) {
+ String revisionInfoTimestampName) {
revisionDateQuery = new StringBuilder()
.append("select rev.").append(revisionInfoTimestampName)
.append(" from ").append(revisionInfoEntityName)
16 years, 4 months
JBoss Envers SVN: r109 - trunk/lib/hibernate-3.3.0.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-16 08:33:03 -0400 (Sat, 16 Aug 2008)
New Revision: 109
Modified:
trunk/lib/hibernate-3.3.0/hibernate3.jar
Log:
ENVERS-38: upgrading to hibernate 3.3.0.GA
Modified: trunk/lib/hibernate-3.3.0/hibernate3.jar
===================================================================
(Binary files differ)
16 years, 4 months
JBoss Envers SVN: r108 - in trunk/src/main/org/jboss/envers: query and 4 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-16 08:12:37 -0400 (Sat, 16 Aug 2008)
New Revision: 108
Modified:
trunk/src/main/org/jboss/envers/entity/EntityInstantiator.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/VersionsQueryCreator.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/order/VersionsOrder.java
trunk/src/main/org/jboss/envers/query/projection/DistinctVersionsProjection.java
trunk/src/main/org/jboss/envers/query/projection/ProjectionWrapper.java
trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java
trunk/src/main/org/jboss/envers/query/projection/VersionsProjection.java
trunk/src/main/org/jboss/envers/query/projection/VersionsProjectionList.java
trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java
Log:
ENVERS-37: versions configuration explicitly passed as an argument, not taken from versions reader
Modified: trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -34,13 +34,12 @@
* @author Adam Warski (adam at warski dot org)
*/
public class EntityInstantiator {
- private VersionsReaderImplementor versionsReader;
- private VersionsConfiguration verCfg;
+ private final VersionsConfiguration verCfg;
+ private final VersionsReaderImplementor versionsReader;
- public EntityInstantiator(VersionsReaderImplementor versionsReader) {
+ public EntityInstantiator(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader) {
+ this.verCfg = verCfg;
this.versionsReader = versionsReader;
-
- verCfg = versionsReader.getVerCfg();
}
/**
Modified: trunk/src/main/org/jboss/envers/query/RevisionProperty.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/RevisionProperty.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/RevisionProperty.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -27,7 +27,7 @@
import org.jboss.envers.query.order.RevisionVersionsOrder;
import org.jboss.envers.query.projection.VersionsProjection;
import org.jboss.envers.query.projection.RevisionVersionsProjection;
-import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.Projections;
@@ -115,7 +115,7 @@
return new RevisionProperty();
}
- public Projection getProjection(String entityName, VersionsReaderImplementor versionsReader) {
- return Projections.property(versionsReader.getVerCfg().getVerEntCfg().getRevisionPropPath());
+ public Projection getProjection(VersionsConfiguration verCfg, String entityName) {
+ return Projections.property(verCfg.getVerEntCfg().getRevisionPropPath());
}
}
Modified: trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -22,7 +22,7 @@
package org.jboss.envers.query;
import org.jboss.envers.query.projection.VersionsProjection;
-import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.Projections;
@@ -40,7 +40,7 @@
return new RevisionTypeProperty();
}
- public Projection getProjection(String entityName, VersionsReaderImplementor versionsReader) {
- return Projections.property(versionsReader.getVerCfg().getVerEntCfg().getRevisionTypePropName());
+ public Projection getProjection(VersionsConfiguration verCfg, String entityName) {
+ return Projections.property(verCfg.getVerEntCfg().getRevisionTypePropName());
}
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -25,14 +25,17 @@
import org.jboss.envers.query.impl.EntitiesAtRevisionQuery;
import org.jboss.envers.query.impl.RevisionsOfEntityQuery;
import static org.jboss.envers.tools.ArgumentsTools.*;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsQueryCreator {
- private VersionsReaderImplementor versionsReaderImplementor;
+ private final VersionsConfiguration verCfg;
+ private final VersionsReaderImplementor versionsReaderImplementor;
- public VersionsQueryCreator(VersionsReaderImplementor versionsReaderImplementor) {
+ public VersionsQueryCreator(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReaderImplementor) {
+ this.verCfg = verCfg;
this.versionsReaderImplementor = versionsReaderImplementor;
}
@@ -48,7 +51,7 @@
public VersionsQuery forEntitiesAtRevision(Class<?> c, Number revision) {
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
- return new EntitiesAtRevisionQuery(versionsReaderImplementor, c, revision);
+ return new EntitiesAtRevisionQuery(verCfg, versionsReaderImplementor, c, revision);
}
/**
@@ -67,6 +70,6 @@
* unless an order or projection is added.
*/
public VersionsQuery forRevisionsOfEntity(Class<?> c, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
- return new RevisionsOfEntityQuery(versionsReaderImplementor, c, selectEntitiesOnly,selectDeletedEntities);
+ return new RevisionsOfEntityQuery(verCfg, versionsReaderImplementor, c, selectEntitiesOnly,selectDeletedEntities);
}
}
Modified: trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -28,6 +28,7 @@
import org.jboss.envers.query.projection.VersionsProjection;
import org.jboss.envers.query.order.VersionsOrder;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.Order;
import org.hibernate.Criteria;
@@ -44,7 +45,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public abstract class AbstractVersionsQuery implements VersionsQuery {
- protected VersionsReaderImplementor versionsReader;
+ //protected VersionsReaderImplementor versionsReader;
protected EntityInstantiator entityInstantiator;
protected List<VersionsCriterion> criterions;
@@ -55,14 +56,16 @@
protected boolean hasProjection;
protected boolean hasOrder;
- protected AbstractVersionsQuery(VersionsReaderImplementor versionsReader, Class<?> cls) {
- this.versionsReader = versionsReader;
+ protected final VersionsConfiguration verCfg;
+ protected AbstractVersionsQuery(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader, Class<?> cls) {
+ this.verCfg = verCfg;
+
criterions = new ArrayList<VersionsCriterion>();
- entityInstantiator = new EntityInstantiator(versionsReader);
+ entityInstantiator = new EntityInstantiator(verCfg, versionsReader);
entityName = cls.getName();
- versionsEntityName = versionsReader.getVerCfg().getVerEntCfg().getVersionsEntityName(entityName);
+ versionsEntityName = verCfg.getVerEntCfg().getVersionsEntityName(entityName);
versionsCriteria = versionsReader.getSession().createCriteria(versionsEntityName, "e");
}
@@ -101,7 +104,7 @@
public VersionsQuery setProjection(VersionsProjection projection) {
hasProjection = true;
- versionsCriteria.setProjection(projection.getProjection(entityName, versionsReader));
+ versionsCriteria.setProjection(projection.getProjection(verCfg, entityName));
return this;
}
@@ -113,7 +116,7 @@
public VersionsQuery addOrder(VersionsOrder order) {
hasOrder = true;
- versionsCriteria.addOrder(order.getOrder(entityName, versionsReader));
+ versionsCriteria.addOrder(order.getOrder(verCfg, entityName));
return this;
}
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -25,6 +25,7 @@
import org.jboss.envers.query.criteria.VersionsCriterion;
import org.jboss.envers.RevisionType;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.criterion.*;
import java.util.List;
@@ -36,8 +37,9 @@
public class EntitiesAtRevisionQuery extends AbstractVersionsQuery {
private Number revision;
- public EntitiesAtRevisionQuery(VersionsReaderImplementor versionsReader, Class<?> cls, Number revision) {
- super(versionsReader, cls);
+ public EntitiesAtRevisionQuery(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader, Class<?> cls,
+ Number revision) {
+ super(verCfg, versionsReader, cls);
this.revision = revision;
}
@@ -54,7 +56,7 @@
DetachedCriteria maxRevCriteria = DetachedCriteria.forEntityName(versionsEntityName, "e2");
- VersionsEntitiesConfiguration verEntCfg = versionsReader.getVerCfg().getVerEntCfg();
+ VersionsEntitiesConfiguration verEntCfg = verCfg.getVerEntCfg();
String revisionPropertyPath = verEntCfg.getRevisionPropPath();
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
@@ -64,7 +66,7 @@
// e2.revision <= :revision
maxRevCriteria.add(Restrictions.le(revisionPropertyPath, revision));
// e2.id = e.id
- maxRevCriteria.add(versionsReader.getVerCfg().getEntCfg().getIdMapper(entityName).getIdsEqualCriterion(
+ maxRevCriteria.add(verCfg.getEntCfg().getIdMapper(entityName).getIdsEqualCriterion(
"e." + originalIdPropertyName, "e2." + originalIdPropertyName));
// e.revision_type != DEL AND
@@ -73,7 +75,7 @@
versionsCriteria.add(Property.forName(revisionPropertyPath).eq(maxRevCriteria));
// all specified conditions, transformed
for (VersionsCriterion criterion : criterions) {
- versionsCriteria.add(criterion.toVersionsCriterion(versionsReader.getVerCfg(), entityName));
+ versionsCriteria.add(criterion.toVersionsCriterion(verCfg, entityName));
}
List queryResult = versionsCriteria.list();
Modified: trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -26,6 +26,7 @@
import org.jboss.envers.query.criteria.VersionsCriterion;
import org.jboss.envers.RevisionType;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Property;
@@ -40,9 +41,9 @@
private final boolean selectEntitiesOnly;
private final boolean selectDeletedEntities;
- public RevisionsOfEntityQuery(VersionsReaderImplementor versionsReader, Class<?> cls, boolean selectEntitiesOnly,
- boolean selectDeletedEntities) {
- super(versionsReader, cls);
+ public RevisionsOfEntityQuery(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader,
+ Class<?> cls, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
+ super(verCfg, versionsReader, cls);
this.selectEntitiesOnly = selectEntitiesOnly;
this.selectDeletedEntities = selectDeletedEntities;
@@ -50,7 +51,7 @@
@SuppressWarnings({"unchecked"})
public List list() throws VersionsException {
- VersionsEntitiesConfiguration verEntCfg = versionsReader.getVerCfg().getVerEntCfg();
+ VersionsEntitiesConfiguration verEntCfg = verCfg.getVerEntCfg();
/*
The query that should be executed in the versions table:
@@ -68,7 +69,7 @@
// all specified conditions, transformed
for (VersionsCriterion criterion : criterions) {
- versionsCriteria.add(criterion.toVersionsCriterion(versionsReader.getVerCfg(), entityName));
+ versionsCriteria.add(criterion.toVersionsCriterion(verCfg, entityName));
}
if (!hasProjection && !hasOrder) {
Modified: trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -22,7 +22,7 @@
package org.jboss.envers.query.order;
import org.hibernate.criterion.Order;
-import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -34,8 +34,8 @@
this.asc = asc;
}
- public Order getOrder(String entityName, VersionsReaderImplementor versionsReader) {
- String revisionPropPath = versionsReader.getVerCfg().getVerEntCfg().getRevisionPropPath();
+ public Order getOrder(VersionsConfiguration verCfg, String entityName) {
+ String revisionPropPath = verCfg.getVerEntCfg().getRevisionPropPath();
if (asc) {
return Order.asc(revisionPropPath);
Modified: trunk/src/main/org/jboss/envers/query/order/VersionsOrder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/order/VersionsOrder.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/order/VersionsOrder.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -23,10 +23,11 @@
import org.hibernate.criterion.Order;
import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
*/
public interface VersionsOrder {
- public Order getOrder(String entityName, VersionsReaderImplementor versionsReader);
+ public Order getOrder(VersionsConfiguration verCfg, String entityName);
}
Modified: trunk/src/main/org/jboss/envers/query/projection/DistinctVersionsProjection.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/DistinctVersionsProjection.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/projection/DistinctVersionsProjection.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -23,7 +23,7 @@
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.Projections;
-import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -35,7 +35,7 @@
this.projection = projection;
}
- public Projection getProjection(String entityName, VersionsReaderImplementor versionsReader) {
- return Projections.distinct(projection.getProjection(entityName, versionsReader));
+ public Projection getProjection(VersionsConfiguration verCfg, String entityName) {
+ return Projections.distinct(projection.getProjection(verCfg, entityName));
}
}
Modified: trunk/src/main/org/jboss/envers/query/projection/ProjectionWrapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/ProjectionWrapper.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/projection/ProjectionWrapper.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -22,7 +22,7 @@
package org.jboss.envers.query.projection;
import org.hibernate.criterion.Projection;
-import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* Wraps a hibernate projection so that it can be used as a versions projection.
@@ -35,7 +35,7 @@
this.wrapped = wrapped;
}
- public Projection getProjection(String entityName, VersionsReaderImplementor versionsReader) {
+ public Projection getProjection(VersionsConfiguration verCfg, String entityName) {
return wrapped;
}
}
Modified: trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -23,7 +23,7 @@
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.Projections;
-import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -42,8 +42,8 @@
this.type = type;
}
- public Projection getProjection(String entityName, VersionsReaderImplementor versionsReader) {
- String revisionPropPath = versionsReader.getVerCfg().getVerEntCfg().getRevisionPropPath();
+ public Projection getProjection(VersionsConfiguration verCfg, String entityName) {
+ String revisionPropPath = verCfg.getVerEntCfg().getRevisionPropPath();
switch (type) {
case MAX: return Projections.max(revisionPropPath);
Modified: trunk/src/main/org/jboss/envers/query/projection/VersionsProjection.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/VersionsProjection.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/projection/VersionsProjection.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -21,12 +21,12 @@
*/
package org.jboss.envers.query.projection;
-import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.criterion.Projection;
/**
* @author Adam Warski (adam at warski dot org)
*/
public interface VersionsProjection {
- public Projection getProjection(String entityName, VersionsReaderImplementor versionsReader);
+ public Projection getProjection(VersionsConfiguration verCfg, String entityName);
}
Modified: trunk/src/main/org/jboss/envers/query/projection/VersionsProjectionList.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/VersionsProjectionList.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/query/projection/VersionsProjectionList.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -24,7 +24,7 @@
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.ProjectionList;
-import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
import java.util.List;
import java.util.ArrayList;
@@ -49,11 +49,11 @@
return this;
}
- public Projection getProjection(String entityName, VersionsReaderImplementor versionsReader) {
+ public Projection getProjection(VersionsConfiguration verCfg, String entityName) {
ProjectionList list = Projections.projectionList();
for (VersionsProjection projection : projections) {
- list.add(projection.getProjection(entityName, versionsReader));
+ list.add(projection.getProjection(verCfg, entityName));
}
return list;
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -43,9 +43,9 @@
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsReaderImpl implements VersionsReaderImplementor {
- private VersionsConfiguration verCfg;
- private SessionImplementor sessionImplementor;
- private Session session;
+ private final VersionsConfiguration verCfg;
+ private final SessionImplementor sessionImplementor;
+ private final Session session;
public VersionsReaderImpl(VersionsConfiguration verCfg, Session session,
SessionImplementor sessionImplementor) {
@@ -68,10 +68,6 @@
return session;
}
- public VersionsConfiguration getVerCfg() {
- return verCfg;
- }
-
@SuppressWarnings({"unchecked"})
public <T> T find(Class<T> cls, Object primaryKey, Number revision) throws
IllegalArgumentException, NotVersionedException, IllegalStateException {
@@ -178,6 +174,6 @@
}
public VersionsQueryCreator createQuery() {
- return new VersionsQueryCreator(this);
+ return new VersionsQueryCreator(verCfg, this);
}
}
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java 2008-08-16 12:03:50 UTC (rev 107)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java 2008-08-16 12:12:37 UTC (rev 108)
@@ -34,6 +34,4 @@
SessionImplementor getSessionImplementor();
Session getSession();
-
- VersionsConfiguration getVerCfg();
}
16 years, 4 months
JBoss Envers SVN: r107 - in trunk/src/main/org/jboss/envers/query: impl and 1 other directory.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-16 08:03:50 -0400 (Sat, 16 Aug 2008)
New Revision: 107
Modified:
trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/BetweenVersionsExpression.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/IlikeVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/InVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/LogicalVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/NotVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/PropertyVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java
trunk/src/main/org/jboss/envers/query/criteria/VersionsCriterion.java
trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java
trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
Log:
ENVERS-37: componentizing configuration - criterions do not depend on VersionsReader
Modified: trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.hibernate.criterion.*;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
import java.util.List;
import java.util.ArrayList;
@@ -52,11 +52,11 @@
return this;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- CriteriaTools.checkPropertyNotARelation(versionsReader, entityName, propertyName);
+ CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
- String versionsEntityName = versionsReader.getVerCfg().getVerEntCfg().getVersionsEntityName(entityName);
+ String versionsEntityName = verCfg.getVerEntCfg().getVersionsEntityName(entityName);
// This will be the aggregated criteria, containing all the specified conditions
DetachedCriteria aggregatedCriteria = DetachedCriteria.forEntityName(versionsEntityName);
@@ -68,7 +68,7 @@
// First adding all specified conditions both to the main criteria, as well as to the
// aggregated one.
for (VersionsCriterion versionsCriteria : criterions) {
- Criterion transformedCriterion = versionsCriteria.toVersionsCriterion(entityName, versionsReader);
+ Criterion transformedCriterion = versionsCriteria.toVersionsCriterion(verCfg, entityName);
conjunction.add(transformedCriterion);
aggregatedCriteria.add(transformedCriterion);
Modified: trunk/src/main/org/jboss/envers/query/criteria/BetweenVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/BetweenVersionsExpression.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/BetweenVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -23,8 +23,8 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -40,9 +40,9 @@
this.hi = hi;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- CriteriaTools.checkPropertyNotARelation(versionsReader, entityName, propertyName);
+ CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
return Restrictions.between(propertyName, lo, hi);
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -21,9 +21,9 @@
*/
package org.jboss.envers.query.criteria;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -31,18 +31,17 @@
public class CriteriaTools {
private CriteriaTools() { }
- public static void checkPropertyNotARelation(VersionsReaderImplementor versionsReader, String entityName,
+ public static void checkPropertyNotARelation(VersionsConfiguration verCfg, String entityName,
String propertyName) throws VersionsException {
- if (versionsReader.getVerCfg().getEntCfg().get(entityName).isRelation(propertyName)) {
+ if (verCfg.getEntCfg().get(entityName).isRelation(propertyName)) {
throw new VersionsException("This criterion cannot be used on a property that is " +
"a relation to another property.");
}
}
- public static RelationDescription getRelatedEntity(VersionsReaderImplementor versionsReader, String entityName,
+ public static RelationDescription getRelatedEntity(VersionsConfiguration verCfg, String entityName,
String propertyName) throws VersionsException {
- RelationDescription relationDesc = versionsReader.getVerCfg()
- .getEntCfg().get(entityName).getRelationDescription(propertyName);
+ RelationDescription relationDesc = verCfg.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-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.hibernate.criterion.Criterion;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -35,9 +35,9 @@
this.id = id;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- return versionsReader.getVerCfg().getEntCfg().getIdMapper(entityName)
- .getIdEqualsCriterion(id, versionsReader.getVerCfg().getVerEntCfg().getOriginalIdPropName(), true);
+ return verCfg.getEntCfg().getIdMapper(entityName)
+ .getIdEqualsCriterion(id, verCfg.getVerEntCfg().getOriginalIdPropName(), true);
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/IlikeVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/IlikeVersionsExpression.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/IlikeVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -24,8 +24,8 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -43,9 +43,9 @@
this(propertyName, matchMode.toMatchString(value));
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- CriteriaTools.checkPropertyNotARelation(versionsReader, entityName, propertyName);
+ CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
return Restrictions.ilike(propertyName, value);
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/InVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/InVersionsExpression.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/InVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -23,8 +23,8 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -38,9 +38,9 @@
this.values = values;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- CriteriaTools.checkPropertyNotARelation(versionsReader, entityName, propertyName);
+ CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
return Restrictions.in(propertyName, values);
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/LogicalVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/LogicalVersionsExpression.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/LogicalVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.hibernate.criterion.Criterion;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -39,9 +39,9 @@
this.op = op;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- return new PublicLogicalExpression(lhs.toVersionsCriterion(null, versionsReader),
- rhs.toVersionsCriterion(null, versionsReader), op);
+ return new PublicLogicalExpression(lhs.toVersionsCriterion(verCfg, null),
+ rhs.toVersionsCriterion(verCfg, null), op);
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -23,9 +23,9 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -37,9 +37,9 @@
this.propertyName = propertyName;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(versionsReader, entityName, propertyName);
+ RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName);
if (relatedEntity == null) {
return Restrictions.isNotNull(propertyName);
Modified: trunk/src/main/org/jboss/envers/query/criteria/NotVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NotVersionsExpression.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/NotVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -23,8 +23,8 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -36,8 +36,8 @@
this.criterion = criterion;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- return Restrictions.not(criterion.toVersionsCriterion(null, versionsReader));
+ return Restrictions.not(criterion.toVersionsCriterion(verCfg, null));
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -23,9 +23,9 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -37,9 +37,9 @@
this.propertyName = propertyName;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(versionsReader, entityName, propertyName);
+ RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName);
if (relatedEntity == null) {
return Restrictions.isNull(propertyName);
Modified: trunk/src/main/org/jboss/envers/query/criteria/PropertyVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/PropertyVersionsExpression.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/PropertyVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.hibernate.criterion.Criterion;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -39,10 +39,10 @@
this.op = op;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- CriteriaTools.checkPropertyNotARelation(versionsReader, entityName, propertyName);
- CriteriaTools.checkPropertyNotARelation(versionsReader, entityName, otherPropertyName);
+ CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
+ CriteriaTools.checkPropertyNotARelation(verCfg, entityName, otherPropertyName);
return new PublicPropertyExpression(propertyName, otherPropertyName, op);
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -22,9 +22,9 @@
package org.jboss.envers.query.criteria;
import org.hibernate.criterion.Criterion;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -40,9 +40,9 @@
this.equals = equals;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(versionsReader, entityName, propertyName);
+ RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName);
if (relatedEntity == null) {
throw new VersionsException("This criterion can only be used on a property that is " +
Modified: trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.hibernate.criterion.Criterion;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -37,9 +37,9 @@
this.op = op;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- return new PublicSimpleExpression(versionsReader.getVerCfg().getVerEntCfg().getRevisionPropPath(),
+ return new PublicSimpleExpression(verCfg.getVerEntCfg().getRevisionPropPath(),
value, op, false);
}
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -22,9 +22,9 @@
package org.jboss.envers.query.criteria;
import org.hibernate.criterion.Criterion;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
@@ -48,9 +48,9 @@
this.ignoreCase = ignoreCase;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
- RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(versionsReader, entityName, propertyName);
+ RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName);
if (relatedEntity == null) {
return new PublicSimpleExpression(propertyName, value, op, ignoreCase);
Modified: trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -24,8 +24,8 @@
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Conjunction;
import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
import java.util.ArrayList;
import java.util.List;
@@ -45,12 +45,12 @@
return this;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
Conjunction conjunction = Restrictions.conjunction();
for (VersionsCriterion criterion : criterions) {
- conjunction.add(criterion.toVersionsCriterion(null, versionsReader));
+ conjunction.add(criterion.toVersionsCriterion(verCfg, null));
}
return conjunction;
Modified: trunk/src/main/org/jboss/envers/query/criteria/VersionsCriterion.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/VersionsCriterion.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/VersionsCriterion.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -23,11 +23,11 @@
import org.hibernate.criterion.Criterion;
import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
*/
public interface VersionsCriterion {
- Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader) throws VersionsException;
+ Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName) throws VersionsException;
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -24,8 +24,8 @@
import org.hibernate.criterion.Disjunction;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
import java.util.List;
import java.util.ArrayList;
@@ -45,12 +45,12 @@
return this;
}
- public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
+ public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
throws VersionsException {
Disjunction conjunction = Restrictions.disjunction();
for (VersionsCriterion criterion : criterions) {
- conjunction.add(criterion.toVersionsCriterion(null, versionsReader));
+ conjunction.add(criterion.toVersionsCriterion(verCfg, null));
}
return conjunction;
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -73,7 +73,7 @@
versionsCriteria.add(Property.forName(revisionPropertyPath).eq(maxRevCriteria));
// all specified conditions, transformed
for (VersionsCriterion criterion : criterions) {
- versionsCriteria.add(criterion.toVersionsCriterion(entityName, versionsReader));
+ versionsCriteria.add(criterion.toVersionsCriterion(versionsReader.getVerCfg(), entityName));
}
List queryResult = versionsCriteria.list();
Modified: trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-15 14:00:41 UTC (rev 106)
+++ trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-16 12:03:50 UTC (rev 107)
@@ -68,7 +68,7 @@
// all specified conditions, transformed
for (VersionsCriterion criterion : criterions) {
- versionsCriteria.add(criterion.toVersionsCriterion(entityName, versionsReader));
+ versionsCriteria.add(criterion.toVersionsCriterion(versionsReader.getVerCfg(), entityName));
}
if (!hasProjection && !hasOrder) {
16 years, 4 months