JBoss Envers SVN: r106 - in trunk/src/main/org/jboss/envers: reader and 1 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-15 10:00:41 -0400 (Fri, 15 Aug 2008)
New Revision: 106
Modified:
trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java
trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.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/OneToManyInitializor.java
Log:
ENVERS-37: componentizing configuration - moving some methods out of versions reader
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-15 13:27:21 UTC (rev 105)
+++ trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java 2008-08-15 14:00:41 UTC (rev 106)
@@ -51,12 +51,8 @@
return false;
}
- public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
- doMap(obj, primaryKey, versionsReader, revision);
- }
-
@SuppressWarnings({"unchecked"})
- private void doMap(Object obj, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
+ public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
if (obj == null) {
return;
}
Modified: trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.java 2008-08-15 13:27:21 UTC (rev 105)
+++ trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.java 2008-08-15 14:00:41 UTC (rev 106)
@@ -24,8 +24,12 @@
import org.jboss.envers.mapper.PropertyMapper;
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 javax.persistence.NoResultException;
import java.util.Map;
/**
@@ -47,19 +51,24 @@
}
public void mapToEntityFromMap(Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
- doMap(obj, primaryKey, versionsReader, revision);
- }
-
- private void doMap(Object obj, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
if (obj == null) {
return;
}
Class<?> entityClass = ReflectionTools.loadClass(owningEntityName);
- Object value = versionsReader.findOneReferencing(entityClass, owningEntityName, owningReferencePropertyName,
- primaryKey, revision);
+ Object value;
+ try {
+ value = versionsReader.createQuery().forEntitiesAtRevision(entityClass, revision)
+ .add(VersionsRestrictions.relatedIdEq(owningReferencePropertyName, primaryKey)).getSingleResult();
+ } catch (NoResultException e) {
+ value = null;
+ } catch (NonUniqueResultException e) {
+ throw new VersionsException("Many versions results for one-to-one relationship: (" + owningEntityName +
+ ", " + owningReferencePropertyName + ")");
+ }
+
Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyName);
setter.set(obj, value, null);
}
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-15 13:27:21 UTC (rev 105)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-15 14:00:41 UTC (rev 106)
@@ -97,42 +97,7 @@
}
}
- public Object findOneReferencing(Class<?> cls, String owningEntityName, String owningReferencePropertyName,
- Object ownedEntityId, Number revision) {
- try {
- return createQuery().forEntitiesAtRevision(cls, revision)
- .add(VersionsRestrictions.relatedIdEq(owningReferencePropertyName, ownedEntityId)).getSingleResult();
- } catch (NoResultException e) {
- return null;
- } catch (NonUniqueResultException e) {
- throw new VersionsException("Many versions results for one-to-one relationship: (" + owningEntityName +
- ", " + owningReferencePropertyName + ")");
- }
- }
-
@SuppressWarnings({"unchecked"})
- public Object findManyReferencing(Class<?> cls, String owningReferencePropertyName, Object ownedEntityId,
- Number revision, Class<? extends Collection> collectionClass) {
- List queryResult = createQuery().forEntitiesAtRevision(cls, revision)
- .add(VersionsRestrictions.relatedIdEq(owningReferencePropertyName, ownedEntityId)).getResultList();
-
- if (collectionClass.isAssignableFrom(queryResult.getClass())) {
- return queryResult;
- } else {
- Collection result;
- try {
- result = collectionClass.newInstance();
- } catch (Exception e) {
- throw new VersionsException(e);
- }
-
- result.addAll(queryResult);
-
- return result;
- }
- }
-
- @SuppressWarnings({"unchecked"})
public List<Number> getRevisions(Class<?> cls, Object primaryKey)
throws IllegalArgumentException, NotVersionedException, IllegalStateException {
// todo: if a class is not versioned from the beginning, there's a missing ADD rev - what then?
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java 2008-08-15 13:27:21 UTC (rev 105)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java 2008-08-15 14:00:41 UTC (rev 106)
@@ -26,8 +26,6 @@
import org.jboss.envers.VersionsReader;
import org.jboss.envers.configuration.VersionsConfiguration;
-import java.util.Collection;
-
/**
* An interface exposed by a VersionsReader to library-facing classes.
* @author Adam Warski (adam at warski dot org)
@@ -37,11 +35,5 @@
Session getSession();
- Object findOneReferencing(Class<?> cls, String owningEntityName, String owningReferencePropertyName,
- Object ownedEntityId, Number revision);
-
- Object findManyReferencing(Class<?> cls, String owningReferencePropertyName, Object ownedEntityId, Number revision,
- Class<? extends Collection> collectionClass);
-
VersionsConfiguration getVerCfg();
}
Modified: trunk/src/main/org/jboss/envers/reader/lazy/OneToManyInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/lazy/OneToManyInitializor.java 2008-08-15 13:27:21 UTC (rev 105)
+++ trunk/src/main/org/jboss/envers/reader/lazy/OneToManyInitializor.java 2008-08-15 14:00:41 UTC (rev 106)
@@ -23,8 +23,11 @@
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.reader.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)
@@ -50,7 +53,22 @@
@SuppressWarnings({"unchecked"})
public T initialize() {
- return (T) versionsReader.findManyReferencing(entityClass, owningReferencePropertyName,
- primaryKey, revision, collectionClass);
+ 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;
+ }
}
}
16 years, 4 months
JBoss Envers SVN: r105 - in trunk/src/main/org/jboss/envers: configuration/metadata/data and 2 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-15 09:27:21 -0400 (Fri, 15 Aug 2008)
New Revision: 105
Added:
trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoQueryCreator.java
Removed:
trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurations.java
trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/data/IdMappingData.java
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/reader/VersionsReaderImpl.java
Log:
ENVERS-37: componentizing configuration - factoring out creating revision queries
Deleted: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurations.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurations.java 2008-08-14 15:39:48 UTC (rev 104)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurations.java 2008-08-15 13:27:21 UTC (rev 105)
@@ -1,94 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.configuration;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * Configuration of the user entities: property mapping of the entities, relations, inheritance.
- * @author Adam Warski (adam at warski dot org)
- */
-public class EntitiesConfigurations {
- private Map<String, EntityConfiguration> entitiesConfigurations;
-
- // Map versions entity name -> entity name
- private Map<String, String> entityNamesForVersionsEntityNames = new HashMap<String, String>();
-
- public EntitiesConfigurations(Map<String, EntityConfiguration> entitiesConfigurations) {
- this.entitiesConfigurations = entitiesConfigurations;
-
- generateBidirectionRelationInfo();
- generateVersionsEntityToEntityNames();
- }
-
- private void generateVersionsEntityToEntityNames() {
- entityNamesForVersionsEntityNames = new HashMap<String, String>();
-
- for (String entityName : entitiesConfigurations.keySet()) {
- entityNamesForVersionsEntityNames.put(entitiesConfigurations.get(entityName).getVersionsEntityName(),
- entityName);
- }
- }
-
- private void generateBidirectionRelationInfo() {
- // Checking each relation if it is bidirectional. If so, storing that information.
- for (String entityName : entitiesConfigurations.keySet()) {
- EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
- // Iterating over all relations from that entity
- for (RelationDescription relDesc : entCfg.getRelationsIterator()) {
- // If this is an "owned" relation, checking the related entity, if it has a relation that has
- // a mapped-by attribute to the currently checked. If so, this is a bidirectional relation.
- if (relDesc.relationType == RelationDescription.RelationType.TO_ONE) {
- for (RelationDescription other : entitiesConfigurations.get(relDesc.toEntityName).getRelationsIterator()) {
- if (relDesc.fromPropertyName.equals(other.mappedByPropertyName) &&
- (entityName.equals(other.toEntityName))) {
- relDesc.bidirectional = true;
- other.bidirectional= true;
- }
- }
- }
- }
- }
- }
-
- public EntityConfiguration get(String entityName) {
- return entitiesConfigurations.get(entityName);
- }
-
- public String getEntityNameForVersionsEntityName(String versionsEntityName) {
- return entityNamesForVersionsEntityNames.get(versionsEntityName);
- }
-
- public RelationDescription getRelationDescription(String entityName, String propertyName) {
- EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
- RelationDescription relDesc = entCfg.getRelationDescription(propertyName);
- if (relDesc != null) {
- return relDesc;
- } else if (entCfg.getParentEntityName() != null) {
- // The field may be declared in a superclass ...
- return getRelationDescription(entCfg.getParentEntityName(), propertyName);
- } else {
- return null;
- }
- }
-}
Deleted: trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java 2008-08-14 15:39:48 UTC (rev 104)
+++ trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java 2008-08-15 13:27:21 UTC (rev 105)
@@ -1,103 +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.configuration.metadata.data.IdMappingData;
-import org.jboss.envers.mapper.ExtendedPropertyMapper;
-import org.jboss.envers.mapper.id.IdMapper;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class EntityConfiguration {
- private String entityName;
- private String versionsEntityName;
- private IdMappingData idMappingData;
- private ExtendedPropertyMapper propertyMapper;
- // Maps from property name
- private Map<String, RelationDescription> relations;
- private String parentEntityName;
-
- public EntityConfiguration(String entityName, String versionsEntityName, IdMappingData idMappingData,
- ExtendedPropertyMapper propertyMapper,
- String parentEntityName) {
- this.entityName = entityName;
- this.versionsEntityName = versionsEntityName;
- this.idMappingData = idMappingData;
- this.propertyMapper = propertyMapper;
- this.parentEntityName = parentEntityName;
-
- this.relations = new HashMap<String, RelationDescription>();
- }
-
- public void addToOneRelation(String fromPropertyName, String toEntityName, IdMapper idMapper) {
- relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationDescription.RelationType.TO_ONE,
- toEntityName, null, idMapper));
- }
-
- public void addOneToOneRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName,
- IdMapper idMapper) {
- relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationDescription.RelationType.ONE_TO_ONE,
- toEntityName, mappedByPropertyName, idMapper));
- }
-
- public void addOneToManyRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName,
- IdMapper idMapper) {
- relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationDescription.RelationType.ONE_TO_MANY,
- toEntityName, mappedByPropertyName, idMapper));
- }
-
- public boolean isRelation(String propertyName) {
- return relations.get(propertyName) != null;
- }
-
- public Iterable<RelationDescription> getRelationsIterator() {
- return relations.values();
- }
-
- public RelationDescription getRelationDescription(String propertyName) {
- return relations.get(propertyName);
- }
-
- public IdMappingData getIdMappingData() {
- return idMappingData;
- }
-
- public ExtendedPropertyMapper getPropertyMapper() {
- return propertyMapper;
- }
-
- public String getParentEntityName() {
- return parentEntityName;
- }
-
- public String getEntityName() {
- return entityName;
- }
-
- public String getVersionsEntityName() {
- return versionsEntityName;
- }
-}
Modified: trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-08-14 15:39:48 UTC (rev 104)
+++ trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-08-15 13:27:21 UTC (rev 105)
@@ -9,10 +9,7 @@
import org.jboss.envers.RevisionEntity;
import org.jboss.envers.Versioned;
import org.jboss.envers.configuration.metadata.MetadataTools;
-import org.jboss.envers.revisioninfo.CustomRevisionInfoGenerator;
-import org.jboss.envers.revisioninfo.DefaultRevisionInfoGenerator;
-import org.jboss.envers.revisioninfo.RevisionNumberGenerator;
-import org.jboss.envers.revisioninfo.RevisionInfoGenerator;
+import org.jboss.envers.revisioninfo.*;
import org.hibernate.MappingException;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.cfg.Configuration;
@@ -170,35 +167,27 @@
return new RevisionInfoConfigurationResult(
new RevisionNumberGenerator(revisionInfoEntityName, revisionInfoGenerator),
revisionPropType,
- revisionInfoXmlMapping);
+ revisionInfoXmlMapping,
+ new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdName, revisionInfoTimestampName));
}
public boolean isRevisionInfoEntityName(String entityName) {
return revisionInfoEntityName.equals(entityName);
}
-
- public String getRevisionInfoEntityName() {
- return revisionInfoEntityName;
- }
-
- public String getRevisionInfoIdName() {
- return revisionInfoIdName;
- }
-
- public String getRevisionInfoTimestampName() {
- return revisionInfoTimestampName;
- }
}
class RevisionInfoConfigurationResult {
private final RevisionNumberGenerator revisionNumberGenerator;
private final String revisionPropType;
private final Document revisionInfoXmlMapping;
+ private final RevisionInfoQueryCreator revisionInfoQueryCreator;
- RevisionInfoConfigurationResult(RevisionNumberGenerator revisionNumberGenerator, String revisionPropType, Document revisionInfoXmlMapping) {
+ RevisionInfoConfigurationResult(RevisionNumberGenerator revisionNumberGenerator, String revisionPropType,
+ Document revisionInfoXmlMapping, RevisionInfoQueryCreator revisionInfoQueryCreator) {
this.revisionNumberGenerator = revisionNumberGenerator;
this.revisionPropType = revisionPropType;
this.revisionInfoXmlMapping = revisionInfoXmlMapping;
+ this.revisionInfoQueryCreator = revisionInfoQueryCreator;
}
public RevisionNumberGenerator getRevisionNumberGenerator() {
@@ -212,4 +201,8 @@
public Document getRevisionInfoXmlMapping() {
return revisionInfoXmlMapping;
}
+
+ public RevisionInfoQueryCreator getRevisionInfoQueryCreator() {
+ return revisionInfoQueryCreator;
+ }
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-14 15:39:48 UTC (rev 104)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-15 13:27:21 UTC (rev 105)
@@ -31,6 +31,7 @@
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;
@@ -52,6 +53,7 @@
private final VersionsSyncManager versionsSyncManager;
private final EntitiesConfigurations entCfg;
private final RevisionInfoConfiguration revInfoCfg;
+ private final RevisionInfoQueryCreator revisionInfoQueryCreator;
public VersionsEntitiesConfiguration getVerEntCfg() {
return verEntCfg;
@@ -73,6 +75,10 @@
return entCfg;
}
+ public RevisionInfoQueryCreator getRevisionInfoQueryGenerator() {
+ return revisionInfoQueryCreator;
+ }
+
private YReflectionManager getReflectionManager(Configuration cfg) {
try {
return new YReflectionManager(cfg);
@@ -91,6 +97,7 @@
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();
Deleted: trunk/src/main/org/jboss/envers/configuration/metadata/data/IdMappingData.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/data/IdMappingData.java 2008-08-14 15:39:48 UTC (rev 104)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/data/IdMappingData.java 2008-08-15 13:27:21 UTC (rev 105)
@@ -1,54 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.configuration.metadata.data;
-
-import org.jboss.envers.mapper.id.IdMapper;
-import org.dom4j.Element;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class IdMappingData {
- private IdMapper idMapper;
- // Mapping which will be used to generate the entity
- private Element xmlMapping;
- // Mapping which will be used to generate references to the entity in related entities
- private Element xmlRelationMapping;
-
- public IdMappingData(IdMapper idMapper, Element xmlMapping, Element xmlRelationMapping) {
- this.idMapper = idMapper;
- this.xmlMapping = xmlMapping;
- this.xmlRelationMapping = xmlRelationMapping;
- }
-
- public IdMapper getIdMapper() {
- return idMapper;
- }
-
- public Element getXmlMapping() {
- return xmlMapping;
- }
-
- public Element getXmlRelationMapping() {
- return xmlRelationMapping;
- }
-}
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-14 15:39:48 UTC (rev 104)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-15 13:27:21 UTC (rev 105)
@@ -26,8 +26,6 @@
import org.hibernate.Query;
import org.hibernate.engine.SessionImplementor;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
-import org.jboss.envers.configuration.RevisionInfoConfiguration;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.exception.NotVersionedException;
import org.jboss.envers.exception.RevisionDoesNotExistException;
@@ -49,15 +47,11 @@
private SessionImplementor sessionImplementor;
private Session session;
- private final RevisionInfoConfiguration revInfoCfg;
-
public VersionsReaderImpl(VersionsConfiguration verCfg, Session session,
SessionImplementor sessionImplementor) {
this.verCfg = verCfg;
this.sessionImplementor = sessionImplementor;
this.session = session;
-
- revInfoCfg = verCfg.getRevInfoCfg();
}
private void checkSession() {
@@ -164,13 +158,8 @@
checkPositive(revision, "Entity revision");
checkSession();
- StringBuilder queryStr = new StringBuilder();
- queryStr.append("select rev.").append(revInfoCfg.getRevisionInfoTimestampName())
- .append(" from ").append(revInfoCfg.getRevisionInfoEntityName())
- .append(" rev where ").append(revInfoCfg.getRevisionInfoIdName()).append(" = :_revision_number");
+ Query query = verCfg.getRevisionInfoQueryGenerator().getRevisionDateQuery(session, revision);
- Query query = session.createQuery(queryStr.toString()).setParameter("_revision_number", revision);
-
try {
Long timestamp = (Long) query.uniqueResult();
if (timestamp == null) {
@@ -187,13 +176,8 @@
checkNotNull(date, "Date of revision");
checkSession();
- StringBuilder queryStr = new StringBuilder();
- queryStr.append("select max(rev.").append(revInfoCfg.getRevisionInfoIdName())
- .append(") from ").append(revInfoCfg.getRevisionInfoEntityName())
- .append(" rev where ").append(revInfoCfg.getRevisionInfoTimestampName()).append(" <= :_revision_date");
+ Query query = verCfg.getRevisionInfoQueryGenerator().getRevisionNumberForDateQuery(session, date);
- Query query = session.createQuery(queryStr.toString()).setParameter("_revision_date", date.getTime());
-
try {
Number res = (Number) query.uniqueResult();
if (res == null) {
@@ -213,15 +197,8 @@
checkPositive(revision, "Entity revision");
checkSession();
- StringBuilder queryStr = new StringBuilder();
- queryStr.append("select rev from ")
- .append(revInfoCfg.getRevisionInfoEntityName())
- .append(" rev where ")
- .append(revInfoCfg.getRevisionInfoIdName())
- .append(" = :_revision_number");
+ Query query = verCfg.getRevisionInfoQueryGenerator().getRevisionQuery(session, revision);
- Query query = session.createQuery(queryStr.toString()).setParameter("_revision_number", revision);
-
try {
T revisionData = (T) query.uniqueResult();
Added: trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoQueryCreator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoQueryCreator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoQueryCreator.java 2008-08-15 13:27:21 UTC (rev 105)
@@ -0,0 +1,48 @@
+package org.jboss.envers.revisioninfo;
+
+import org.hibernate.Session;
+import org.hibernate.Query;
+
+import java.util.Date;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class RevisionInfoQueryCreator {
+ private final String revisionDateQuery;
+ private final String revisionNumberForDateQuery;
+ private final String revisionQuery;
+
+ public RevisionInfoQueryCreator(String revisionInfoEntityName, String revisionInfoIdName,
+ String revisionInfoTimestampName) {
+ revisionDateQuery = new StringBuilder()
+ .append("select rev.").append(revisionInfoTimestampName)
+ .append(" from ").append(revisionInfoEntityName)
+ .append(" rev where ").append(revisionInfoIdName).append(" = :_revision_number")
+ .toString();
+
+ revisionNumberForDateQuery = new StringBuilder()
+ .append("select max(rev.").append(revisionInfoIdName)
+ .append(") from ").append(revisionInfoEntityName)
+ .append(" rev where ").append(revisionInfoTimestampName).append(" <= :_revision_date")
+ .toString();
+
+ revisionQuery = new StringBuilder()
+ .append("select rev from ").append(revisionInfoEntityName)
+ .append(" rev where ").append(revisionInfoIdName)
+ .append(" = :_revision_number")
+ .toString();
+ }
+
+ public Query getRevisionDateQuery(Session session, Number revision) {
+ return session.createQuery(revisionDateQuery).setParameter("_revision_number", revision);
+ }
+
+ public Query getRevisionNumberForDateQuery(Session session, Date date) {
+ return session.createQuery(revisionNumberForDateQuery).setParameter("_revision_date", date.getTime());
+ }
+
+ public Query getRevisionQuery(Session session, Number revision) {
+ return session.createQuery(revisionQuery).setParameter("_revision_number", revision);
+ }
+}
16 years, 4 months
JBoss Envers SVN: r104 - in trunk/src/main/org/jboss/envers: configuration and 14 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-14 11:39:48 -0400 (Thu, 14 Aug 2008)
New Revision: 104
Added:
trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
trunk/src/main/org/jboss/envers/configuration/entities/
trunk/src/main/org/jboss/envers/configuration/entities/EntitiesConfigurations.java
trunk/src/main/org/jboss/envers/configuration/entities/EntityConfiguration.java
trunk/src/main/org/jboss/envers/configuration/entities/IdMappingData.java
trunk/src/main/org/jboss/envers/revisioninfo/
trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/revisioninfo/RevisionNumberGenerator.java
Removed:
trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/configuration/DefaultRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/configuration/RevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java
Modified:
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/data/PersistentClassVersioningData.java
trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
trunk/src/main/org/jboss/envers/query/RevisionProperty.java
trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java
trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java
trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java
trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java
trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java
trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java
trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java
trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java
trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java
trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java
Log:
ENVERS-37: componentizing configuration
Deleted: trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -1,73 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.configuration;
-
-import org.jboss.envers.RevisionListener;
-import org.jboss.envers.tools.reflection.ReflectionTools;
-import org.hibernate.MappingException;
-import org.hibernate.property.Setter;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class CustomRevisionInfoGenerator implements RevisionInfoGenerator {
- private RevisionListener listener;
- private Setter revisionTimestampSetter;
- private Class<?> entityClass;
-
- public CustomRevisionInfoGenerator(VersionsEntitiesConfiguration verEntCfg,
- Class<?> entityClass,
- Class<? extends RevisionListener> listenerClass) {
- this.entityClass = entityClass;
-
- revisionTimestampSetter = ReflectionTools.getSetter(entityClass,
- verEntCfg.getRevisionsInfoTimestampName());
-
- if (!listenerClass.equals(RevisionListener.class)) {
- // This is not the default value.
- try {
- listener = listenerClass.newInstance();
- } catch (InstantiationException e) {
- throw new MappingException(e);
- } catch (IllegalAccessException e) {
- throw new MappingException(e);
- }
- }
- }
-
- public Object newRevision() {
- Object entity;
- try {
- entity = entityClass.newInstance();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- revisionTimestampSetter.set(entity, System.currentTimeMillis(), null);
-
- if (listener != null) {
- listener.newRevision(entity);
- }
-
- return entity;
- }
-}
Deleted: trunk/src/main/org/jboss/envers/configuration/DefaultRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/DefaultRevisionInfoGenerator.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/configuration/DefaultRevisionInfoGenerator.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -1,43 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.configuration;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class DefaultRevisionInfoGenerator implements RevisionInfoGenerator {
- private VersionsEntitiesConfiguration verEntCfg;
-
- public DefaultRevisionInfoGenerator(VersionsEntitiesConfiguration verEntCfg) {
- this.verEntCfg = verEntCfg;
- }
-
- public Object newRevision() {
- Map<String, Object> revisionInfo = new HashMap<String, Object>();
- revisionInfo.put(verEntCfg.getRevisionsInfoTimestampName(), System.currentTimeMillis());
-
- return revisionInfo;
- }
-}
Added: trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -0,0 +1,32 @@
+package org.jboss.envers.configuration;
+
+import java.util.Properties;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class GlobalConfiguration {
+ // Should a revision be generated when a not-owned relation field changes
+ private final boolean generateRevisionsForCollections;
+
+ // Should a warning, instead of an error and an exception, be logged, when an unsupported type is versioned
+ private final boolean warnOnUnsupportedTypes;
+
+ public GlobalConfiguration(Properties properties) {
+ String generateRevisionsForCollectionsStr = properties.getProperty("org.jboss.envers.revisionOnCollectionChange",
+ "true");
+ generateRevisionsForCollections = Boolean.parseBoolean(generateRevisionsForCollectionsStr);
+
+ String warnOnUnsupportedTypesStr = properties.getProperty("org.jboss.envers.warnOnUnsupportedTypes",
+ "false");
+ warnOnUnsupportedTypes = Boolean.parseBoolean(warnOnUnsupportedTypesStr);
+ }
+
+ public boolean isGenerateRevisionsForCollections() {
+ return generateRevisionsForCollections;
+ }
+
+ public boolean isWarnOnUnsupportedTypes() {
+ return warnOnUnsupportedTypes;
+ }
+}
Added: trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -0,0 +1,215 @@
+package org.jboss.envers.configuration;
+
+import org.jboss.envers.tools.reflection.YClass;
+import org.jboss.envers.tools.reflection.YReflectionManager;
+import org.jboss.envers.tools.reflection.YProperty;
+import org.jboss.envers.tools.MutableBoolean;
+import org.jboss.envers.RevisionNumber;
+import org.jboss.envers.RevisionTimestamp;
+import org.jboss.envers.RevisionEntity;
+import org.jboss.envers.Versioned;
+import org.jboss.envers.configuration.metadata.MetadataTools;
+import org.jboss.envers.revisioninfo.CustomRevisionInfoGenerator;
+import org.jboss.envers.revisioninfo.DefaultRevisionInfoGenerator;
+import org.jboss.envers.revisioninfo.RevisionNumberGenerator;
+import org.jboss.envers.revisioninfo.RevisionInfoGenerator;
+import org.hibernate.MappingException;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.cfg.Configuration;
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+
+import java.util.Iterator;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class RevisionInfoConfiguration {
+ private String revisionInfoEntityName;
+ private String revisionInfoIdName;
+ private String revisionInfoTimestampName;
+ private String revisionInfoTimestampType;
+
+ private String revisionPropType;
+
+ public RevisionInfoConfiguration() {
+ revisionInfoEntityName = "_revisions_info";
+ revisionInfoIdName = "revision_id";
+ revisionInfoTimestampName = "revision_timestamp";
+ revisionInfoTimestampType = "long";
+
+ revisionPropType = "integer";
+ }
+
+ private Document generateDefaultRevisionInfoXmlMapping() {
+ Document document = DocumentHelper.createDocument();
+
+ Element class_mapping = MetadataTools.createEntity(document, revisionInfoEntityName,
+ null, null, null, null);
+
+ MetadataTools.addNativelyGeneratedId(class_mapping, revisionInfoIdName,
+ revisionPropType);
+
+ MetadataTools.addProperty(class_mapping, revisionInfoTimestampName,
+ revisionInfoTimestampType, false);
+
+ return document;
+ }
+
+ private void searchForRevisionInfoCfg(YClass clazz, YReflectionManager reflectionManager,
+ MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound) {
+ YClass superclazz = clazz.getSuperclass();
+ if (!"java.lang.Object".equals(superclazz.getName())) {
+ searchForRevisionInfoCfg(superclazz, reflectionManager, revisionNumberFound, revisionTimestampFound);
+ }
+
+ for (YProperty property : clazz.getDeclaredProperties("field")) {
+ RevisionNumber revisionNumber = property.getAnnotation(RevisionNumber.class);
+ RevisionTimestamp revisionTimestamp = property.getAnnotation(RevisionTimestamp.class);
+
+ if (revisionNumber != null) {
+ if (revisionNumberFound.isSet()) {
+ throw new MappingException("Only one property may be annotated with @RevisionNumber!");
+ }
+
+ YClass revisionNumberClass = property.getType();
+ if (reflectionManager.equals(revisionNumberClass, Integer.class) ||
+ reflectionManager.equals(revisionNumberClass, Integer.TYPE)) {
+ revisionInfoIdName = property.getName();
+ revisionNumberFound.set();
+ } else if (reflectionManager.equals(revisionNumberClass, Long.class) ||
+ reflectionManager.equals(revisionNumberClass, Long.TYPE)) {
+ revisionInfoIdName = property.getName();
+ revisionNumberFound.set();
+
+ // The default is integer
+ revisionPropType = "long";
+ } else {
+ throw new MappingException("The field annotated with @RevisionNumber must be of type " +
+ "int, Integer, long or Long");
+ }
+ }
+
+ if (revisionTimestamp != null) {
+ if (revisionTimestampFound.isSet()) {
+ throw new MappingException("Only one property may be annotated with @RevisionTimestamp!");
+ }
+
+ YClass revisionTimestampClass = property.getType();
+ if (reflectionManager.equals(revisionTimestampClass, Long.class) ||
+ reflectionManager.equals(revisionTimestampClass, Long.TYPE)) {
+ revisionInfoTimestampName = property.getName();
+ revisionTimestampFound.set();
+ } else {
+ throw new MappingException("The field annotated with @RevisionTimestamp must be of type " +
+ "long or Long");
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public RevisionInfoConfigurationResult configure(Configuration cfg, YReflectionManager reflectionManager) {
+ Iterator<PersistentClass> classes = (Iterator<PersistentClass>) cfg.getClassMappings();
+ boolean revisionEntityFound = false;
+ RevisionInfoGenerator revisionInfoGenerator = null;
+
+ while (classes.hasNext()) {
+ PersistentClass pc = classes.next();
+ YClass clazz;
+ try {
+ clazz = reflectionManager.classForName(pc.getClassName(), this.getClass());
+ } catch (ClassNotFoundException e) {
+ throw new MappingException(e);
+ }
+
+ RevisionEntity revisionEntity = clazz.getAnnotation(RevisionEntity.class);
+ if (revisionEntity != null) {
+ if (revisionEntityFound) {
+ throw new MappingException("Only one entity may be annotated with @RevisionEntity!");
+ }
+
+ // Checking if custom revision entity isn't versioned
+ if (clazz.getAnnotation(Versioned.class) != null) {
+ throw new MappingException("An entity annotated with @RevisionEntity cannot be versioned!");
+ }
+
+ revisionEntityFound = true;
+
+ MutableBoolean revisionNumberFound = new MutableBoolean();
+ MutableBoolean revisionTimestampFound = new MutableBoolean();
+
+ searchForRevisionInfoCfg(clazz, reflectionManager, revisionNumberFound, revisionTimestampFound);
+
+ if (!revisionNumberFound.isSet()) {
+ throw new MappingException("An entity annotated with @RevisionEntity must have a field annotated " +
+ "with @RevisionNumber!");
+ }
+
+ if (!revisionTimestampFound.isSet()) {
+ throw new MappingException("An entity annotated with @RevisionEntity must have a field annotated " +
+ "with @RevisionTimestamp!");
+ }
+
+ revisionInfoEntityName = pc.getEntityName();
+
+ revisionInfoGenerator = new CustomRevisionInfoGenerator(pc.getMappedClass(),
+ revisionEntity.value(), revisionInfoTimestampName);
+ }
+ }
+
+ // In case of a custom revision info generator, the mapping will be null.
+ Document revisionInfoXmlMapping = null;
+
+ if (revisionInfoGenerator == null) {
+ revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoTimestampName);
+ revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping();
+ }
+
+ return new RevisionInfoConfigurationResult(
+ new RevisionNumberGenerator(revisionInfoEntityName, revisionInfoGenerator),
+ revisionPropType,
+ revisionInfoXmlMapping);
+ }
+
+ public boolean isRevisionInfoEntityName(String entityName) {
+ return revisionInfoEntityName.equals(entityName);
+ }
+
+ public String getRevisionInfoEntityName() {
+ return revisionInfoEntityName;
+ }
+
+ public String getRevisionInfoIdName() {
+ return revisionInfoIdName;
+ }
+
+ public String getRevisionInfoTimestampName() {
+ return revisionInfoTimestampName;
+ }
+}
+
+class RevisionInfoConfigurationResult {
+ private final RevisionNumberGenerator revisionNumberGenerator;
+ private final String revisionPropType;
+ private final Document revisionInfoXmlMapping;
+
+ RevisionInfoConfigurationResult(RevisionNumberGenerator revisionNumberGenerator, String revisionPropType, Document revisionInfoXmlMapping) {
+ this.revisionNumberGenerator = revisionNumberGenerator;
+ this.revisionPropType = revisionPropType;
+ this.revisionInfoXmlMapping = revisionInfoXmlMapping;
+ }
+
+ public RevisionNumberGenerator getRevisionNumberGenerator() {
+ return revisionNumberGenerator;
+ }
+
+ public String getRevisionPropType() {
+ return revisionPropType;
+ }
+
+ public Document getRevisionInfoXmlMapping() {
+ return revisionInfoXmlMapping;
+ }
+}
\ No newline at end of file
Deleted: trunk/src/main/org/jboss/envers/configuration/RevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoGenerator.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/configuration/RevisionInfoGenerator.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -1,29 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.configuration;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public interface RevisionInfoGenerator {
- public Object newRevision();
-}
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -25,12 +25,10 @@
import org.hibernate.mapping.PersistentClass;
import org.hibernate.MappingException;
import org.jboss.envers.configuration.metadata.VersionsMetadataGenerator;
-import org.jboss.envers.configuration.metadata.RevisionsInfoMetadataGenerator;
import org.jboss.envers.configuration.metadata.AnnotationsMetadataReader;
import org.jboss.envers.configuration.metadata.data.PersistentClassVersioningData;
+import org.jboss.envers.configuration.entities.EntitiesConfigurations;
import org.jboss.envers.synchronization.VersionsSyncManager;
-import org.jboss.envers.mapper.ExtendedPropertyMapper;
-import org.jboss.envers.mapper.id.IdMapper;
import org.jboss.envers.tools.graph.GraphTopologicalSort;
import org.jboss.envers.tools.reflection.YReflectionManager;
import org.dom4j.Document;
@@ -49,19 +47,13 @@
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsConfiguration {
- private VersionsEntitiesConfiguration verEntCfg;
- private VersionsSyncManager versionsSyncManager;
- private EntitiesConfigurations entitiesConfigurations;
+ private final GlobalConfiguration globalCfg;
+ private final VersionsEntitiesConfiguration verEntCfg;
+ private final VersionsSyncManager versionsSyncManager;
+ private final EntitiesConfigurations entCfg;
+ private final RevisionInfoConfiguration revInfoCfg;
- // Should a revision be generated when a not-owned relation field changes
- private boolean generateRevisionsForCollections;
-
- // Should a warning, instead of an error and an exception, be logged, when an unsupported type is versioned
- private boolean warnOnUnsupportedTypes;
-
- //
-
- public VersionsEntitiesConfiguration getEntitiesCfg() {
+ public VersionsEntitiesConfiguration getVerEntCfg() {
return verEntCfg;
}
@@ -69,22 +61,16 @@
return versionsSyncManager;
}
- // todo
- private void writeDocument(Document e) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Writer w = new PrintWriter(baos);
+ public RevisionInfoConfiguration getRevInfoCfg() {
+ return revInfoCfg;
+ }
- try {
- XMLWriter xw = new XMLWriter(w, new OutputFormat(" ", true));
- xw.write(e);
- w.flush();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
+ public GlobalConfiguration getGlobalCfg() {
+ return globalCfg;
+ }
- System.out.println("-----------");
- System.out.println(baos.toString());
- System.out.println("-----------");
+ public EntitiesConfigurations getEntCfg() {
+ return entCfg;
}
private YReflectionManager getReflectionManager(Configuration cfg) {
@@ -95,34 +81,18 @@
}
}
- private boolean isVersioned(PersistentClassVersioningData versioningData) {
- if (versioningData == null) { return false; }
- if (versioningData.propertyStoreInfo.propertyStores.size() > 0) { return true; }
- if (versioningData.propertyStoreInfo.defaultStore != null) { return true; }
- return false;
- }
-
- private void configureFromProperties(Properties properties) {
- String generateRevisionsForCollectionsStr = properties.getProperty("org.jboss.envers.revisionOnCollectionChange",
- "true");
- generateRevisionsForCollections = Boolean.parseBoolean(generateRevisionsForCollectionsStr);
-
- String warnOnUnsupportedTypesStr = properties.getProperty("org.jboss.envers.warnOnUnsupportedTypes",
- "false");
- warnOnUnsupportedTypes = Boolean.parseBoolean(warnOnUnsupportedTypesStr);
- }
-
@SuppressWarnings({"unchecked"})
- public void configure(Configuration cfg) {
- configureFromProperties(cfg.getProperties());
+ public VersionsConfiguration(Configuration cfg) {
+ Properties properties = cfg.getProperties();
YReflectionManager reflectionManager = getReflectionManager(cfg);
+ revInfoCfg = new RevisionInfoConfiguration();
+ RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg, reflectionManager);
+ verEntCfg = new VersionsEntitiesConfiguration(properties, revInfoCfgResult.getRevisionPropType());
+ globalCfg = new GlobalConfiguration(properties);
+ versionsSyncManager = new VersionsSyncManager(revInfoCfgResult.getRevisionNumberGenerator());
- verEntCfg = VersionsEntitiesConfiguration.get(cfg, reflectionManager);
-
- versionsSyncManager = new VersionsSyncManager(verEntCfg);
-
- VersionsMetadataGenerator versionsMetaGen = new VersionsMetadataGenerator(this, verEntCfg);
+ VersionsMetadataGenerator versionsMetaGen = new VersionsMetadataGenerator(this);
DOMWriter writer = new DOMWriter();
// Sorting the persistent class topologically - superclass always before subclass
@@ -140,7 +110,7 @@
PersistentClassVersioningData versioningData =
annotationsMetadataReader.getVersioningData(pc, reflectionManager);
- if (isVersioned(versioningData)) {
+ if (versioningData.isVersioned()) {
pcDatas.put(pc, versioningData);
if (versioningData.versionsTableName != null) {
@@ -169,21 +139,13 @@
}
// Getting the entities configurations
- entitiesConfigurations = new EntitiesConfigurations(versionsMetaGen.getEntitiesConfigurations());
+ entCfg = new EntitiesConfigurations(versionsMetaGen.getEntitiesConfigurations());
- // Checking if custom revision entity isn't versioned
- if (entitiesConfigurations.get(verEntCfg.getRevisionsInfoEntityName()) != null) {
- throw new MappingException("An entity annotated with @RevisionEntity cannot be versioned!");
- }
-
// Only if there are any versioned classes
if (pcDatas.size() > 0) {
try {
- if (!verEntCfg.hasCustomRevisionInfoEntity()) {
- RevisionsInfoMetadataGenerator revisionsMetaGenInfo = new RevisionsInfoMetadataGenerator(verEntCfg);
- Document helperEntity = revisionsMetaGenInfo.generate();
- //writeDocument(helperEntity);
- cfg.addDocument(writer.write(helperEntity));
+ if (revInfoCfgResult.getRevisionInfoXmlMapping() != null) {
+ cfg.addDocument(writer.write(revInfoCfgResult.getRevisionInfoXmlMapping()));
}
} catch (DocumentException e) {
throw new MappingException(e);
@@ -191,38 +153,6 @@
}
}
- public boolean isVersioned(String entityName) {
- return entitiesConfigurations.get(entityName) != null;
- }
-
- public IdMapper getIdMapper(String entityName) {
- return entitiesConfigurations.get(entityName).getIdMappingData().getIdMapper();
- }
-
- public ExtendedPropertyMapper getPropertyMapper(String entityName) {
- return entitiesConfigurations.get(entityName).getPropertyMapper();
- }
-
- public EntityConfiguration getEntityConfiguration(String entityName) {
- return entitiesConfigurations.get(entityName);
- }
-
- public String getEntityNameForVersionsEntityName(String versionsEntityName) {
- return entitiesConfigurations.getEntityNameForVersionsEntityName(versionsEntityName);
- }
-
- public boolean isGenerateRevisionsForCollections() {
- return generateRevisionsForCollections;
- }
-
- public boolean isWarnOnUnsupportedTypes() {
- return warnOnUnsupportedTypes;
- }
-
- public RelationDescription getRelationDescription(String entityName, String propertyName) {
- return entitiesConfigurations.getRelationDescription(entityName, propertyName);
- }
-
//
private static Map<Configuration, VersionsConfiguration> cfgs
@@ -232,13 +162,30 @@
VersionsConfiguration verCfg = cfgs.get(cfg);
if (verCfg == null) {
- verCfg = new VersionsConfiguration();
+ verCfg = new VersionsConfiguration(cfg);
cfgs.put(cfg, verCfg);
-
- verCfg.configure(cfg);
+
cfg.buildMappings();
}
return verCfg;
}
+
+ // todo
+ private void writeDocument(Document e) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Writer w = new PrintWriter(baos);
+
+ try {
+ XMLWriter xw = new XMLWriter(w, new OutputFormat(" ", true));
+ xw.write(e);
+ w.flush();
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+
+ System.out.println("-----------");
+ System.out.println(baos.toString());
+ System.out.println("-----------");
+ }
}
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -21,75 +21,42 @@
*/
package org.jboss.envers.configuration;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.MappingException;
-import org.jboss.envers.RevisionEntity;
-import org.jboss.envers.RevisionNumber;
-import org.jboss.envers.RevisionTimestamp;
-import org.jboss.envers.tools.reflection.YReflectionManager;
-import org.jboss.envers.tools.reflection.YClass;
-import org.jboss.envers.tools.reflection.YProperty;
-import org.jboss.envers.tools.MutableBoolean;
-
import java.util.*;
/**
- * Configuration of versions entities - names of fields and entities created to store versioning information, revision
- * info entity configuration etc.
+ * Configuration of versions entities - names of fields, entities and tables created to store versioning information.
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsEntitiesConfiguration {
- private String versionsTablePrefix;
- private String versionsTableSuffix;
+ private final String versionsTablePrefix;
+ private final String versionsTableSuffix;
- private String originalIdPropName;
+ private final String originalIdPropName;
- private String revisionPropName;
- private String revisionPropType;
- private String revisionPropPath;
+ private final String revisionPropName;
+ private final String revisionPropType;
+ private final String revisionPropPath;
- private String revisionTypePropName;
- private String revisionTypePropType;
+ private final String revisionTypePropName;
+ private final String revisionTypePropType;
- private String revisionsInfoEntityName;
- private String revisionsInfoIdName;
- private String revisionsInfoTimestampName;
- private String revisionsInfoTimestampType;
- private boolean customRevisionsInfoEntity;
+ private final Map<String, String> customVersionsTablesNames;
- private RevisionInfoGenerator revisionInfoGenerator;
+ public VersionsEntitiesConfiguration(Properties properties, String revisionPropType) {
+ versionsTablePrefix = properties.getProperty("org.jboss.envers.versionsTablePrefix", "");
+ versionsTableSuffix = properties.getProperty("org.jboss.envers.versionsTableSuffix", "_versions");
- private Map<String, String> customVersionsTablesNames;
+ originalIdPropName = "originalId";
- public static VersionsEntitiesConfiguration get(Configuration cfg, YReflectionManager reflectionManager) {
- Properties properties = cfg.getProperties();
+ revisionPropName = properties.getProperty("org.jboss.envers.revisionFieldName", "_revision");
+ this.revisionPropType = revisionPropType;
- VersionsEntitiesConfiguration verEntCfg = new VersionsEntitiesConfiguration();
+ revisionTypePropName = properties.getProperty("org.jboss.envers.revisionTypeFieldName", "_revision_type");
+ revisionTypePropType = "byte";
- verEntCfg.versionsTablePrefix = properties.getProperty("org.jboss.envers.versionsTablePrefix", "");
- verEntCfg.versionsTableSuffix = properties.getProperty("org.jboss.envers.versionsTableSuffix", "_versions");
+ customVersionsTablesNames = new HashMap<String, String>();
- verEntCfg.originalIdPropName = "originalId";
-
- verEntCfg.revisionPropName = properties.getProperty("org.jboss.envers.revisionFieldName", "_revision");
- verEntCfg.revisionPropType = "integer";
-
- verEntCfg.revisionTypePropName = properties.getProperty("org.jboss.envers.revisionTypeFieldName", "_revision_type");
- verEntCfg.revisionTypePropType = "byte";
-
- verEntCfg.revisionsInfoEntityName = "_revisions_info";
- verEntCfg.revisionsInfoIdName = "revision_id";
- verEntCfg.revisionsInfoTimestampName = "revision_timestamp";
- verEntCfg.revisionsInfoTimestampType = "long";
-
- verEntCfg.customVersionsTablesNames = new HashMap<String, String>();
-
- verEntCfg.revisionPropPath = verEntCfg.originalIdPropName + "." + verEntCfg.revisionPropName;
-
- verEntCfg.customRevisionsInfoEntity = verEntCfg.configureRevisionsEntity(cfg, reflectionManager);
-
- return verEntCfg;
+ revisionPropPath = originalIdPropName + "." + revisionPropName;
}
public String getVersionsTablePrefix() {
@@ -124,26 +91,6 @@
return revisionTypePropType;
}
- public String getRevisionsInfoEntityName() {
- return revisionsInfoEntityName;
- }
-
- public String getRevisionsInfoIdName() {
- return revisionsInfoIdName;
- }
-
- public String getRevisionsInfoTimestampName() {
- return revisionsInfoTimestampName;
- }
-
- public String getRevisionsInfoTimestampType() {
- return revisionsInfoTimestampType;
- }
-
- public RevisionInfoGenerator getRevisionInfoGenerator() {
- return revisionInfoGenerator;
- }
-
//
public void addCustomVersionsTableName(String entityName, String tableName) {
@@ -173,117 +120,4 @@
return customHistoryTableName;
}
-
- public boolean isRevisionInfoEntityName(String entityName) {
- return revisionsInfoEntityName.equals(entityName);
- }
-
- public boolean hasCustomRevisionInfoEntity() {
- return customRevisionsInfoEntity;
- }
-
- //
-
- private void searchForRevisionInfoCfg(YClass clazz, YReflectionManager reflectionManager,
- MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound) {
- YClass superclazz = clazz.getSuperclass();
- if (!"java.lang.Object".equals(superclazz.getName())) {
- searchForRevisionInfoCfg(superclazz, reflectionManager, revisionNumberFound, revisionTimestampFound);
- }
-
- for (YProperty property : clazz.getDeclaredProperties("field")) {
- RevisionNumber revisionNumber = property.getAnnotation(RevisionNumber.class);
- RevisionTimestamp revisionTimestamp = property.getAnnotation(RevisionTimestamp.class);
-
- if (revisionNumber != null) {
- if (revisionNumberFound.isSet()) {
- throw new MappingException("Only one property may be annotated with @RevisionNumber!");
- }
-
- YClass revisionNumberClass = property.getType();
- if (reflectionManager.equals(revisionNumberClass, Integer.class) ||
- reflectionManager.equals(revisionNumberClass, Integer.TYPE)) {
- revisionsInfoIdName = property.getName();
- revisionNumberFound.set();
- } else if (reflectionManager.equals(revisionNumberClass, Long.class) ||
- reflectionManager.equals(revisionNumberClass, Long.TYPE)) {
- revisionsInfoIdName = property.getName();
- revisionNumberFound.set();
-
- // The default is integer
- revisionPropType = "long";
- } else {
- throw new MappingException("The field annotated with @RevisionNumber must be of type " +
- "int, Integer, long or Long");
- }
- }
-
- if (revisionTimestamp != null) {
- if (revisionTimestampFound.isSet()) {
- throw new MappingException("Only one property may be annotated with @RevisionTimestamp!");
- }
-
- YClass revisionTimestampClass = property.getType();
- if (reflectionManager.equals(revisionTimestampClass, Long.class) ||
- reflectionManager.equals(revisionTimestampClass, Long.TYPE)) {
- revisionsInfoTimestampName = property.getName();
- revisionTimestampFound.set();
- } else {
- throw new MappingException("The field annotated with @RevisionTimestamp must be of type " +
- "long or Long");
- }
- }
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private boolean configureRevisionsEntity(Configuration cfg, YReflectionManager reflectionManager) {
- Iterator<PersistentClass> classes = (Iterator<PersistentClass>) cfg.getClassMappings();
- boolean revisionEntityFound = false;
-
- while (classes.hasNext()) {
- PersistentClass pc = classes.next();
- YClass clazz;
- try {
- clazz = reflectionManager.classForName(pc.getClassName(), this.getClass());
- } catch (ClassNotFoundException e) {
- throw new MappingException(e);
- }
-
- RevisionEntity revisionEntity = clazz.getAnnotation(RevisionEntity.class);
- if (revisionEntity != null) {
- if (revisionEntityFound) {
- throw new MappingException("Only one entity may be annotated with @RevisionEntity!");
- }
-
- revisionEntityFound = true;
-
- MutableBoolean revisionNumberFound = new MutableBoolean();
- MutableBoolean revisionTimestampFound = new MutableBoolean();
-
- searchForRevisionInfoCfg(clazz, reflectionManager, revisionNumberFound, revisionTimestampFound);
-
- if (!revisionNumberFound.isSet()) {
- throw new MappingException("An entity annotated with @RevisionEntity must have a field annotated " +
- "with @RevisionNumber!");
- }
-
- if (!revisionTimestampFound.isSet()) {
- throw new MappingException("An entity annotated with @RevisionEntity must have a field annotated " +
- "with @RevisionTimestamp!");
- }
-
- revisionsInfoEntityName = pc.getEntityName();
-
- revisionInfoGenerator = new CustomRevisionInfoGenerator(this, pc.getMappedClass(),
- revisionEntity.value());
- }
- }
-
- if (revisionInfoGenerator == null) {
- revisionInfoGenerator = new DefaultRevisionInfoGenerator(this);
- }
-
- return revisionEntityFound;
- }
}
Copied: trunk/src/main/org/jboss/envers/configuration/entities/EntitiesConfigurations.java (from rev 102, trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurations.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/entities/EntitiesConfigurations.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/entities/EntitiesConfigurations.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -0,0 +1,110 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.configuration.entities;
+
+import org.jboss.envers.mapper.id.IdMapper;
+import org.jboss.envers.mapper.ExtendedPropertyMapper;
+import org.jboss.envers.configuration.RelationDescription;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Configuration of the user entities: property mapping of the entities, relations, inheritance.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class EntitiesConfigurations {
+ private Map<String, EntityConfiguration> entitiesConfigurations;
+
+ // Map versions entity name -> entity name
+ private Map<String, String> entityNamesForVersionsEntityNames = new HashMap<String, String>();
+
+ public EntitiesConfigurations(Map<String, EntityConfiguration> entitiesConfigurations) {
+ this.entitiesConfigurations = entitiesConfigurations;
+
+ generateBidirectionRelationInfo();
+ generateVersionsEntityToEntityNames();
+ }
+
+ private void generateVersionsEntityToEntityNames() {
+ entityNamesForVersionsEntityNames = new HashMap<String, String>();
+
+ for (String entityName : entitiesConfigurations.keySet()) {
+ entityNamesForVersionsEntityNames.put(entitiesConfigurations.get(entityName).getVersionsEntityName(),
+ entityName);
+ }
+ }
+
+ private void generateBidirectionRelationInfo() {
+ // Checking each relation if it is bidirectional. If so, storing that information.
+ for (String entityName : entitiesConfigurations.keySet()) {
+ EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
+ // Iterating over all relations from that entity
+ for (RelationDescription relDesc : entCfg.getRelationsIterator()) {
+ // If this is an "owned" relation, checking the related entity, if it has a relation that has
+ // a mapped-by attribute to the currently checked. If so, this is a bidirectional relation.
+ if (relDesc.relationType == RelationDescription.RelationType.TO_ONE) {
+ for (RelationDescription other : entitiesConfigurations.get(relDesc.toEntityName).getRelationsIterator()) {
+ if (relDesc.fromPropertyName.equals(other.mappedByPropertyName) &&
+ (entityName.equals(other.toEntityName))) {
+ relDesc.bidirectional = true;
+ other.bidirectional= true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public EntityConfiguration get(String entityName) {
+ return entitiesConfigurations.get(entityName);
+ }
+
+ public String getEntityNameForVersionsEntityName(String versionsEntityName) {
+ return entityNamesForVersionsEntityNames.get(versionsEntityName);
+ }
+
+ public boolean isVersioned(String entityName) {
+ return get(entityName) != null;
+ }
+
+ public IdMapper getIdMapper(String entityName) {
+ return get(entityName).getIdMappingData().getIdMapper();
+ }
+
+ public ExtendedPropertyMapper getPropertyMapper(String entityName) {
+ return get(entityName).getPropertyMapper();
+ }
+
+ public RelationDescription getRelationDescription(String entityName, String propertyName) {
+ EntityConfiguration entCfg = entitiesConfigurations.get(entityName);
+ RelationDescription relDesc = entCfg.getRelationDescription(propertyName);
+ if (relDesc != null) {
+ return relDesc;
+ } else if (entCfg.getParentEntityName() != null) {
+ // The field may be declared in a superclass ...
+ return getRelationDescription(entCfg.getParentEntityName(), propertyName);
+ } else {
+ return null;
+ }
+ }
+}
Copied: trunk/src/main/org/jboss/envers/configuration/entities/EntityConfiguration.java (from rev 103, trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/entities/EntityConfiguration.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/entities/EntityConfiguration.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -0,0 +1,102 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.configuration.entities;
+
+import org.jboss.envers.configuration.RelationDescription;
+import org.jboss.envers.mapper.ExtendedPropertyMapper;
+import org.jboss.envers.mapper.id.IdMapper;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class EntityConfiguration {
+ private String entityName;
+ private String versionsEntityName;
+ private IdMappingData idMappingData;
+ private ExtendedPropertyMapper propertyMapper;
+ // Maps from property name
+ private Map<String, RelationDescription> relations;
+ private String parentEntityName;
+
+ public EntityConfiguration(String entityName, String versionsEntityName, IdMappingData idMappingData,
+ ExtendedPropertyMapper propertyMapper, String parentEntityName) {
+ this.entityName = entityName;
+ this.versionsEntityName = versionsEntityName;
+ this.idMappingData = idMappingData;
+ this.propertyMapper = propertyMapper;
+ this.parentEntityName = parentEntityName;
+
+ this.relations = new HashMap<String, RelationDescription>();
+ }
+
+ public void addToOneRelation(String fromPropertyName, String toEntityName, IdMapper idMapper) {
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationDescription.RelationType.TO_ONE,
+ toEntityName, null, idMapper));
+ }
+
+ public void addOneToOneRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName,
+ IdMapper idMapper) {
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationDescription.RelationType.ONE_TO_ONE,
+ toEntityName, mappedByPropertyName, idMapper));
+ }
+
+ public void addOneToManyRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName,
+ IdMapper idMapper) {
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationDescription.RelationType.ONE_TO_MANY,
+ toEntityName, mappedByPropertyName, idMapper));
+ }
+
+ public boolean isRelation(String propertyName) {
+ return relations.get(propertyName) != null;
+ }
+
+ public Iterable<RelationDescription> getRelationsIterator() {
+ return relations.values();
+ }
+
+ public RelationDescription getRelationDescription(String propertyName) {
+ return relations.get(propertyName);
+ }
+
+ public IdMappingData getIdMappingData() {
+ return idMappingData;
+ }
+
+ public ExtendedPropertyMapper getPropertyMapper() {
+ return propertyMapper;
+ }
+
+ public String getParentEntityName() {
+ return parentEntityName;
+ }
+
+ public String getEntityName() {
+ return entityName;
+ }
+
+ public String getVersionsEntityName() {
+ return versionsEntityName;
+ }
+}
Copied: trunk/src/main/org/jboss/envers/configuration/entities/IdMappingData.java (from rev 103, trunk/src/main/org/jboss/envers/configuration/metadata/data/IdMappingData.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/entities/IdMappingData.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/entities/IdMappingData.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -0,0 +1,54 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.configuration.entities;
+
+import org.jboss.envers.mapper.id.IdMapper;
+import org.dom4j.Element;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class IdMappingData {
+ private IdMapper idMapper;
+ // Mapping which will be used to generate the entity
+ private Element xmlMapping;
+ // Mapping which will be used to generate references to the entity in related entities
+ private Element xmlRelationMapping;
+
+ public IdMappingData(IdMapper idMapper, Element xmlMapping, Element xmlRelationMapping) {
+ this.idMapper = idMapper;
+ this.xmlMapping = xmlMapping;
+ this.xmlRelationMapping = xmlRelationMapping;
+ }
+
+ public IdMapper getIdMapper() {
+ return idMapper;
+ }
+
+ public Element getXmlMapping() {
+ return xmlMapping;
+ }
+
+ public Element getXmlRelationMapping() {
+ return xmlRelationMapping;
+ }
+}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -59,12 +59,12 @@
}
public PersistentClassVersioningData getVersioningData(PersistentClass pc, YReflectionManager reflectionManager) {
+ PersistentClassVersioningData versioningData = new PersistentClassVersioningData();
+
if (pc.getClassName() == null) {
- return null;
+ return versioningData;
}
- PersistentClassVersioningData versioningData = new PersistentClassVersioningData();
-
try {
YClass clazz = reflectionManager.classForName(pc.getClassName(), this.getClass());
Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
Deleted: trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -1,53 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.configuration.metadata;
-
-import org.dom4j.Document;
-import org.dom4j.DocumentHelper;
-import org.dom4j.Element;
-import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class RevisionsInfoMetadataGenerator {
- private VersionsEntitiesConfiguration verEntCfg;
-
- public RevisionsInfoMetadataGenerator(VersionsEntitiesConfiguration verEntCfg) {
- this.verEntCfg = verEntCfg;
- }
-
- public Document generate() {
- Document document = DocumentHelper.createDocument();
-
- Element class_mapping = MetadataTools.createEntity(document, verEntCfg.getRevisionsInfoEntityName(),
- null, null, null, null);
-
- MetadataTools.addNativelyGeneratedId(class_mapping, verEntCfg.getRevisionsInfoIdName(),
- verEntCfg.getRevisionPropType());
-
- MetadataTools.addProperty(class_mapping, verEntCfg.getRevisionsInfoTimestampName(),
- verEntCfg.getRevisionsInfoTimestampType(), false);
-
- return document;
- }
-}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -30,8 +30,8 @@
import org.dom4j.DocumentHelper;
import org.dom4j.Attribute;
import org.dom4j.tree.DefaultElement;
-import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
-import org.jboss.envers.configuration.EntityConfiguration;
+import org.jboss.envers.configuration.entities.EntityConfiguration;
+import org.jboss.envers.configuration.entities.IdMappingData;
import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.mapper.*;
import org.jboss.envers.mapper.id.*;
@@ -44,7 +44,6 @@
import org.jboss.envers.ModificationStore;
import org.jboss.envers.tools.log.YLog;
import org.jboss.envers.tools.log.YLogManager;
-import org.jboss.envers.configuration.metadata.data.IdMappingData;
import org.jboss.envers.configuration.metadata.data.PersistentClassVersioningData;
import org.jboss.envers.configuration.metadata.data.PropertyStoreInfo;
import org.jboss.envers.exception.VersionsException;
@@ -61,7 +60,6 @@
private final static Map<String, ModificationStore> EMPTY_STORE = Collections.emptyMap();
private VersionsConfiguration verCfg;
- private VersionsEntitiesConfiguration verEntCfg;
private Map<String, EntityConfiguration> entitiesConfigurations;
// Map entity name -> (join descriptor -> element describing the "versioned" join)
@@ -69,9 +67,8 @@
private YLog log = YLogManager.getLogManager().getLog(VersionsMetadataGenerator.class);
- public VersionsMetadataGenerator(VersionsConfiguration verCfg, VersionsEntitiesConfiguration verEntCfg) {
+ public VersionsMetadataGenerator(VersionsConfiguration verCfg) {
this.verCfg = verCfg;
- this.verEntCfg = verEntCfg;
entitiesConfigurations = new HashMap<String, EntityConfiguration>();
entitiesJoins = new HashMap<String, Map<Join, Element>>();
@@ -428,7 +425,7 @@
} else {
String message = "Type not supported for versioning: " + propertyType.getClass().getName() +
", on entity " + entityName + ", property '" + property.getName() + "'.";
- if (verCfg.isWarnOnUnsupportedTypes()) {
+ if (verCfg.getGlobalCfg().isWarnOnUnsupportedTypes()) {
log.warn(message);
} else {
throw new MappingException(message);
@@ -454,7 +451,7 @@
String originalTableName = join.getTable().getName();
String versionedTableName = versioningData.secondaryTableDictionary.get(originalTableName);
if (versionedTableName == null) {
- versionedTableName = verEntCfg.getVersionsEntityName(originalTableName);
+ versionedTableName = verCfg.getVerEntCfg().getVersionsEntityName(originalTableName);
}
String schema = versioningData.schema;
@@ -472,7 +469,7 @@
Element joinKey = joinElement.addElement("key");
addColumns(joinKey, join.getKey().getColumnIterator());
- MetadataTools.addColumn(joinKey, verEntCfg.getRevisionPropName(), null);
+ MetadataTools.addColumn(joinKey, verCfg.getVerEntCfg().getRevisionPropName(), null);
}
}
@@ -524,12 +521,12 @@
addSimpleProperty(orig_id_mapping, id_prop, null, ModificationStore.FULL, true);
}
- orig_id_mapping.addAttribute("name", verEntCfg.getOriginalIdPropName());
+ orig_id_mapping.addAttribute("name", verCfg.getVerEntCfg().getOriginalIdPropName());
// Adding the "revision number" property
- Element rev_mapping = MetadataTools.addProperty(orig_id_mapping, verEntCfg.getRevisionPropName(),
- verEntCfg.getRevisionPropType(), true);
- MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionPropName(), null);
+ Element rev_mapping = MetadataTools.addProperty(orig_id_mapping, verCfg.getVerEntCfg().getRevisionPropName(),
+ verCfg.getVerEntCfg().getRevisionPropType(), true);
+ MetadataTools.addColumn(rev_mapping, verCfg.getVerEntCfg().getRevisionPropName(), null);
return new IdMappingData(mapper, orig_id_mapping, rel_id_mapping);
}
@@ -560,8 +557,8 @@
}
String entityName = pc.getEntityName();
- String versionsEntityName = verEntCfg.getVersionsEntityName(entityName);
- String versionsTableName = verEntCfg.getVersionsTableName(entityName, pc.getTable().getName());
+ String versionsEntityName = verCfg.getVerEntCfg().getVersionsEntityName(entityName);
+ String versionsTableName = verCfg.getVerEntCfg().getVersionsTableName(entityName, pc.getTable().getName());
// Generating a mapping for the id
IdMappingData idMapper = addId(pc);
@@ -592,13 +589,13 @@
class_mapping.add((Element) idMapper.getXmlMapping().clone());
// Adding the "revision type" property
- Element revTypeProperty = MetadataTools.addProperty(class_mapping, verEntCfg.getRevisionTypePropName(),
- verEntCfg.getRevisionTypePropType(), false);
+ Element revTypeProperty = MetadataTools.addProperty(class_mapping, verCfg.getVerEntCfg().getRevisionTypePropName(),
+ verCfg.getVerEntCfg().getRevisionTypePropType(), false);
revTypeProperty.addAttribute("type", "org.jboss.envers.entity.RevisionTypeType");
break;
case SINGLE:
- String extendsEntityName = verEntCfg.getVersionsEntityName(pc.getSuperclass().getEntityName());
+ String extendsEntityName = verCfg.getVerEntCfg().getVersionsEntityName(pc.getSuperclass().getEntityName());
class_mapping = MetadataTools.createSubclassEntity(document, versionsEntityName, versionsTableName,
schema, catalog, extendsEntityName, pc.getDiscriminatorValue());
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/data/PersistentClassVersioningData.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/data/PersistentClassVersioningData.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/data/PersistentClassVersioningData.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -40,4 +40,10 @@
public String schema;
public String catalog;
public Map<String, String> secondaryTableDictionary;
+
+ public boolean isVersioned() {
+ if (propertyStoreInfo.propertyStores.size() > 0) { return true; }
+ if (propertyStoreInfo.defaultStore != null) { return true; }
+ return false;
+ }
}
Modified: trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -57,7 +57,7 @@
}
// The $type$ property holds the name of the (versions) entity
- String type = verCfg.getEntityNameForVersionsEntityName((String) versionsEntity.get("$type$"));
+ String type = verCfg.getEntCfg().getEntityNameForVersionsEntityName((String) versionsEntity.get("$type$"));
if (type != null) {
entityName = type;
@@ -71,12 +71,12 @@
throw new VersionsException(e);
}
- IdMapper idMapper = verCfg.getIdMapper(entityName);
- Map originalId = (Map) versionsEntity.get(verCfg.getEntitiesCfg().getOriginalIdPropName());
+ IdMapper idMapper = verCfg.getEntCfg().getIdMapper(entityName);
+ Map originalId = (Map) versionsEntity.get(verCfg.getVerEntCfg().getOriginalIdPropName());
Object primaryKey = idMapper.mapToIdFromMap(originalId);
- verCfg.getPropertyMapper(entityName).mapToEntityFromMap(ret, versionsEntity, primaryKey, versionsReader, revision);
+ verCfg.getEntCfg().getPropertyMapper(entityName).mapToEntityFromMap(ret, versionsEntity, primaryKey, versionsReader, revision);
idMapper.mapToEntityFromMap(ret, originalId);
return ret;
Modified: trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
===================================================================
--- trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -46,7 +46,7 @@
private void generateCollectionChangeWorkUnits(VersionsSync verSync, EntityPersister entityPersister,
String entityName, Object[] newState, Object[] oldState) {
// Checking if this is enabled in configuration ...
- if (!verCfg.isGenerateRevisionsForCollections()) {
+ if (!verCfg.getGlobalCfg().isGenerateRevisionsForCollections()) {
return;
}
@@ -57,14 +57,14 @@
for (int i=0; i<propertyNames.length; i++) {
String propertyName = propertyNames[i];
- RelationDescription relDesc = verCfg.getRelationDescription(entityName, propertyName);
+ RelationDescription relDesc = verCfg.getEntCfg().getRelationDescription(entityName, propertyName);
if (relDesc != null && relDesc.bidirectional && relDesc.relationType == RelationDescription.RelationType.TO_ONE) {
// Checking for changes
Object oldValue = oldState == null ? null : oldState[i];
Object newValue = newState == null ? null : newState[i];
if (!Tools.objectsEqual(oldValue, newValue)) {
- IdMapper idMapper = verCfg.getIdMapper(relDesc.toEntityName);
+ IdMapper idMapper = verCfg.getEntCfg().getIdMapper(relDesc.toEntityName);
// We have to generate changes both in the old collection (size decreses) and new collection
// (size increases).
@@ -85,7 +85,7 @@
public void onPostInsert(PostInsertEvent event) {
String entityName = event.getPersister().getEntityName();
- if (verCfg.isVersioned(entityName)) {
+ if (verCfg.getEntCfg().isVersioned(entityName)) {
VersionsSync verSync = verCfg.getSyncManager().get(event.getSession());
verSync.addWorkUnit(new AddWorkUnit(event.getPersister().getEntityName(), verCfg, event.getId(),
@@ -98,7 +98,7 @@
public void onPostUpdate(PostUpdateEvent event) {
String entityName = event.getPersister().getEntityName();
- if (verCfg.isVersioned(entityName)) {
+ if (verCfg.getEntCfg().isVersioned(entityName)) {
VersionsSync verSync = verCfg.getSyncManager().get(event.getSession());
verSync.addWorkUnit(new ModWorkUnit(event.getPersister().getEntityName(), verCfg, event.getId(),
@@ -111,7 +111,7 @@
public void onPostDelete(PostDeleteEvent event) {
String entityName = event.getPersister().getEntityName();
- if (verCfg.isVersioned(entityName)) {
+ if (verCfg.getEntCfg().isVersioned(entityName)) {
VersionsSync verSync = verCfg.getSyncManager().get(event.getSession());
verSync.addWorkUnit(new DelWorkUnit(event.getPersister().getEntityName(), verCfg, event.getId()));
Modified: trunk/src/main/org/jboss/envers/query/RevisionProperty.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/RevisionProperty.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/RevisionProperty.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -116,6 +116,6 @@
}
public Projection getProjection(String entityName, VersionsReaderImplementor versionsReader) {
- return Projections.property(versionsReader.getEntitiesCfg().getRevisionPropPath());
+ return Projections.property(versionsReader.getVerCfg().getVerEntCfg().getRevisionPropPath());
}
}
Modified: trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -41,6 +41,6 @@
}
public Projection getProjection(String entityName, VersionsReaderImplementor versionsReader) {
- return Projections.property(versionsReader.getEntitiesCfg().getRevisionTypePropName());
+ return Projections.property(versionsReader.getVerCfg().getVerEntCfg().getRevisionTypePropName());
}
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -56,7 +56,7 @@
throws VersionsException {
CriteriaTools.checkPropertyNotARelation(versionsReader, entityName, propertyName);
- String versionsEntityName = versionsReader.getEntitiesCfg().getVersionsEntityName(entityName);
+ String versionsEntityName = versionsReader.getVerCfg().getVerEntCfg().getVersionsEntityName(entityName);
// This will be the aggregated criteria, containing all the specified conditions
DetachedCriteria aggregatedCriteria = DetachedCriteria.forEntityName(versionsEntityName);
Modified: trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -33,7 +33,7 @@
public static void checkPropertyNotARelation(VersionsReaderImplementor versionsReader, String entityName,
String propertyName) throws VersionsException {
- if (versionsReader.getVerCfg().getEntityConfiguration(entityName).isRelation(propertyName)) {
+ if (versionsReader.getVerCfg().getEntCfg().get(entityName).isRelation(propertyName)) {
throw new VersionsException("This criterion cannot be used on a property that is " +
"a relation to another property.");
}
@@ -42,7 +42,7 @@
public static RelationDescription getRelatedEntity(VersionsReaderImplementor versionsReader, String entityName,
String propertyName) throws VersionsException {
RelationDescription relationDesc = versionsReader.getVerCfg()
- .getEntityConfiguration(entityName).getRelationDescription(propertyName);
+ .getEntCfg().get(entityName).getRelationDescription(propertyName);
if (relationDesc == null) {
return null;
Modified: trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -37,7 +37,7 @@
public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
throws VersionsException {
- return versionsReader.getVerCfg().getIdMapper(entityName)
- .getIdEqualsCriterion(id, versionsReader.getVerCfg().getEntitiesCfg().getOriginalIdPropName(), true);
+ return versionsReader.getVerCfg().getEntCfg().getIdMapper(entityName)
+ .getIdEqualsCriterion(id, versionsReader.getVerCfg().getVerEntCfg().getOriginalIdPropName(), true);
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -39,7 +39,7 @@
public Criterion toVersionsCriterion(String entityName, VersionsReaderImplementor versionsReader)
throws VersionsException {
- return new PublicSimpleExpression(versionsReader.getEntitiesCfg().getRevisionPropPath(),
+ return new PublicSimpleExpression(versionsReader.getVerCfg().getVerEntCfg().getRevisionPropPath(),
value, op, false);
}
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -62,7 +62,7 @@
entityInstantiator = new EntityInstantiator(versionsReader);
entityName = cls.getName();
- versionsEntityName = versionsReader.getEntitiesCfg().getVersionsEntityName(entityName);
+ versionsEntityName = versionsReader.getVerCfg().getVerEntCfg().getVersionsEntityName(entityName);
versionsCriteria = versionsReader.getSession().createCriteria(versionsEntityName, "e");
}
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -24,6 +24,7 @@
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.query.criteria.VersionsCriterion;
import org.jboss.envers.RevisionType;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import org.hibernate.criterion.*;
import java.util.List;
@@ -53,19 +54,21 @@
DetachedCriteria maxRevCriteria = DetachedCriteria.forEntityName(versionsEntityName, "e2");
- String revisionPropertyPath = versionsReader.getEntitiesCfg().getRevisionPropPath();
- String originalIdPropertyName = versionsReader.getEntitiesCfg().getOriginalIdPropName();
+ VersionsEntitiesConfiguration verEntCfg = versionsReader.getVerCfg().getVerEntCfg();
+ String revisionPropertyPath = verEntCfg.getRevisionPropPath();
+ String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
+
// SELECT max(e2.revision)
maxRevCriteria.setProjection(Property.forName(revisionPropertyPath).max());
// e2.revision <= :revision
maxRevCriteria.add(Restrictions.le(revisionPropertyPath, revision));
// e2.id = e.id
- maxRevCriteria.add(versionsReader.getVerCfg().getIdMapper(entityName).getIdsEqualCriterion(
+ maxRevCriteria.add(versionsReader.getVerCfg().getEntCfg().getIdMapper(entityName).getIdsEqualCriterion(
"e." + originalIdPropertyName, "e2." + originalIdPropertyName));
// e.revision_type != DEL AND
- versionsCriteria.add(Property.forName(versionsReader.getEntitiesCfg().getRevisionTypePropName()).ne(RevisionType.DEL));
+ versionsCriteria.add(Property.forName(verEntCfg.getRevisionTypePropName()).ne(RevisionType.DEL));
// e.revision = (SELECT max(...) ...)
versionsCriteria.add(Property.forName(revisionPropertyPath).eq(maxRevCriteria));
// all specified conditions, transformed
Modified: trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -25,6 +25,7 @@
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.query.criteria.VersionsCriterion;
import org.jboss.envers.RevisionType;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Property;
@@ -49,6 +50,8 @@
@SuppressWarnings({"unchecked"})
public List list() throws VersionsException {
+ VersionsEntitiesConfiguration verEntCfg = versionsReader.getVerCfg().getVerEntCfg();
+
/*
The query that should be executed in the versions table:
SELECT e (unless another projection is specified) FROM ent_ver e WHERE
@@ -56,11 +59,11 @@
(all specified conditions, transformed, on the "e" entity)
ORDER BY e.revision ASC (unless another order is specified)
*/
- String revisionPropertyPath = versionsReader.getEntitiesCfg().getRevisionPropPath();
+ String revisionPropertyPath = verEntCfg.getRevisionPropPath();
if (!selectDeletedEntities) {
// e.revision_type != DEL AND
- versionsCriteria.add(Property.forName(versionsReader.getEntitiesCfg().getRevisionTypePropName()).ne(RevisionType.DEL));
+ versionsCriteria.add(Property.forName(verEntCfg.getRevisionTypePropName()).ne(RevisionType.DEL));
}
// all specified conditions, transformed
@@ -77,9 +80,9 @@
return queryResult;
} else {
List entities = new ArrayList();
- String originalId = versionsReader.getEntitiesCfg().getOriginalIdPropName();
- String revisionPropertyName = versionsReader.getEntitiesCfg().getRevisionPropName();
- String revisionTypePropertyName = versionsReader.getEntitiesCfg().getRevisionTypePropName();
+ String originalId = verEntCfg.getOriginalIdPropName();
+ String revisionPropertyName = verEntCfg.getRevisionPropName();
+ String revisionTypePropertyName = verEntCfg.getRevisionTypePropName();
for (Map versionsEntity : queryResult) {
Number revision = (Number) ((Map) versionsEntity.get(originalId)).get(revisionPropertyName);
Modified: trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -35,7 +35,7 @@
}
public Order getOrder(String entityName, VersionsReaderImplementor versionsReader) {
- String revisionPropPath = versionsReader.getEntitiesCfg().getRevisionPropPath();
+ String revisionPropPath = versionsReader.getVerCfg().getVerEntCfg().getRevisionPropPath();
if (asc) {
return Order.asc(revisionPropPath);
Modified: trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -43,7 +43,7 @@
}
public Projection getProjection(String entityName, VersionsReaderImplementor versionsReader) {
- String revisionPropPath = versionsReader.getEntitiesCfg().getRevisionPropPath();
+ String revisionPropPath = versionsReader.getVerCfg().getVerEntCfg().getRevisionPropPath();
switch (type) {
case MAX: return Projections.max(revisionPropPath);
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -27,6 +27,7 @@
import org.hibernate.engine.SessionImplementor;
import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.RevisionInfoConfiguration;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.exception.NotVersionedException;
import org.jboss.envers.exception.RevisionDoesNotExistException;
@@ -45,17 +46,18 @@
*/
public class VersionsReaderImpl implements VersionsReaderImplementor {
private VersionsConfiguration verCfg;
- private VersionsEntitiesConfiguration entitiesCfg;
private SessionImplementor sessionImplementor;
private Session session;
+ private final RevisionInfoConfiguration revInfoCfg;
+
public VersionsReaderImpl(VersionsConfiguration verCfg, Session session,
SessionImplementor sessionImplementor) {
this.verCfg = verCfg;
this.sessionImplementor = sessionImplementor;
this.session = session;
- entitiesCfg = verCfg.getEntitiesCfg();
+ revInfoCfg = verCfg.getRevInfoCfg();
}
private void checkSession() {
@@ -76,10 +78,6 @@
return verCfg;
}
- public VersionsEntitiesConfiguration getEntitiesCfg() {
- return entitiesCfg;
- }
-
@SuppressWarnings({"unchecked"})
public <T> T find(Class<T> cls, Object primaryKey, Number revision) throws
IllegalArgumentException, NotVersionedException, IllegalStateException {
@@ -91,7 +89,7 @@
String entityName = cls.getName();
- if (!verCfg.isVersioned(entityName)) {
+ if (!verCfg.getEntCfg().isVersioned(entityName)) {
throw new NotVersionedException(entityName + " is not versioned!");
}
@@ -150,7 +148,7 @@
String entityName = cls.getName();
- if (!verCfg.isVersioned(entityName)) {
+ if (!verCfg.getEntCfg().isVersioned(entityName)) {
throw new NotVersionedException(entityName + " is not versioned!");
}
@@ -167,9 +165,9 @@
checkSession();
StringBuilder queryStr = new StringBuilder();
- queryStr.append("select rev.").append(entitiesCfg.getRevisionsInfoTimestampName())
- .append(" from ").append(entitiesCfg.getRevisionsInfoEntityName())
- .append(" rev where ").append(entitiesCfg.getRevisionsInfoIdName()).append(" = :_revision_number");
+ queryStr.append("select rev.").append(revInfoCfg.getRevisionInfoTimestampName())
+ .append(" from ").append(revInfoCfg.getRevisionInfoEntityName())
+ .append(" rev where ").append(revInfoCfg.getRevisionInfoIdName()).append(" = :_revision_number");
Query query = session.createQuery(queryStr.toString()).setParameter("_revision_number", revision);
@@ -190,9 +188,9 @@
checkSession();
StringBuilder queryStr = new StringBuilder();
- queryStr.append("select max(rev.").append(entitiesCfg.getRevisionsInfoIdName())
- .append(") from ").append(entitiesCfg.getRevisionsInfoEntityName())
- .append(" rev where ").append(entitiesCfg.getRevisionsInfoTimestampName()).append(" <= :_revision_date");
+ queryStr.append("select max(rev.").append(revInfoCfg.getRevisionInfoIdName())
+ .append(") from ").append(revInfoCfg.getRevisionInfoEntityName())
+ .append(" rev where ").append(revInfoCfg.getRevisionInfoTimestampName()).append(" <= :_revision_date");
Query query = session.createQuery(queryStr.toString()).setParameter("_revision_date", date.getTime());
@@ -217,9 +215,9 @@
StringBuilder queryStr = new StringBuilder();
queryStr.append("select rev from ")
- .append(entitiesCfg.getRevisionsInfoEntityName())
+ .append(revInfoCfg.getRevisionInfoEntityName())
.append(" rev where ")
- .append(entitiesCfg.getRevisionsInfoIdName())
+ .append(revInfoCfg.getRevisionInfoIdName())
.append(" = :_revision_number");
Query query = session.createQuery(queryStr.toString()).setParameter("_revision_number", revision);
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImplementor.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -25,7 +25,6 @@
import org.hibernate.Session;
import org.jboss.envers.VersionsReader;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import java.util.Collection;
@@ -45,6 +44,4 @@
Class<? extends Collection> collectionClass);
VersionsConfiguration getVerCfg();
-
- VersionsEntitiesConfiguration getEntitiesCfg();
}
Added: trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/revisioninfo/CustomRevisionInfoGenerator.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -0,0 +1,72 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.revisioninfo;
+
+import org.jboss.envers.RevisionListener;
+import org.jboss.envers.tools.reflection.ReflectionTools;
+import org.hibernate.MappingException;
+import org.hibernate.property.Setter;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class CustomRevisionInfoGenerator implements RevisionInfoGenerator {
+ private RevisionListener listener;
+ private Setter revisionTimestampSetter;
+ private Class<?> entityClass;
+
+ public CustomRevisionInfoGenerator(Class<?> entityClass,
+ Class<? extends RevisionListener> listenerClass,
+ String revisionInfoTimestampName) {
+ this.entityClass = entityClass;
+
+ revisionTimestampSetter = ReflectionTools.getSetter(entityClass, revisionInfoTimestampName);
+
+ if (!listenerClass.equals(RevisionListener.class)) {
+ // This is not the default value.
+ try {
+ listener = listenerClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new MappingException(e);
+ } catch (IllegalAccessException e) {
+ throw new MappingException(e);
+ }
+ }
+ }
+
+ public Object newRevision() {
+ Object entity;
+ try {
+ entity = entityClass.newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ revisionTimestampSetter.set(entity, System.currentTimeMillis(), null);
+
+ if (listener != null) {
+ listener.newRevision(entity);
+ }
+
+ return entity;
+ }
+}
Added: trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -0,0 +1,43 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.revisioninfo;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class DefaultRevisionInfoGenerator implements RevisionInfoGenerator {
+ private String revisionInfoTimestampName;
+
+ public DefaultRevisionInfoGenerator(String revisionInfoTimestampName) {
+ this.revisionInfoTimestampName = revisionInfoTimestampName;
+ }
+
+ public Object newRevision() {
+ Map<String, Object> revisionInfo = new HashMap<String, Object>();
+ revisionInfo.put(revisionInfoTimestampName, System.currentTimeMillis());
+
+ return revisionInfo;
+ }
+}
Added: trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoGenerator.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -0,0 +1,29 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.revisioninfo;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public interface RevisionInfoGenerator {
+ public Object newRevision();
+}
Added: trunk/src/main/org/jboss/envers/revisioninfo/RevisionNumberGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/RevisionNumberGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/revisioninfo/RevisionNumberGenerator.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -0,0 +1,20 @@
+package org.jboss.envers.revisioninfo;
+
+import org.hibernate.Session;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class RevisionNumberGenerator {
+ private final String revisionInfoEntityName;
+ private final RevisionInfoGenerator revisionInfoGenerator;
+
+ public RevisionNumberGenerator(String revisionInfoEntityName, RevisionInfoGenerator revisionInfoGenerator) {
+ this.revisionInfoEntityName = revisionInfoEntityName;
+ this.revisionInfoGenerator = revisionInfoGenerator;
+ }
+
+ public Number generate(Session session) {
+ return (Number) session.save(revisionInfoEntityName, revisionInfoGenerator.newRevision());
+ }
+}
Modified: trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -26,6 +26,7 @@
import org.hibernate.FlushMode;
import org.jboss.envers.synchronization.work.VersionsWorkUnit;
import org.jboss.envers.tools.Pair;
+import org.jboss.envers.revisioninfo.RevisionNumberGenerator;
import javax.transaction.Synchronization;
import java.util.*;
@@ -34,29 +35,28 @@
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsSync implements Synchronization {
- private VersionsSyncManager manager;
- private Session session;
+ private final RevisionNumberGenerator revisionNumberGenerator;
+ private final VersionsSyncManager manager;
+ private final Session session;
+
+ private final Transaction transaction;
+ private final LinkedList<VersionsWorkUnit> workUnits;
+ private final Queue<VersionsWorkUnit> undoQueue;
+ private final Map<Pair<String, Object>, VersionsWorkUnit> usedIds;
+
private Number revision;
- private Transaction transaction;
- private LinkedList<VersionsWorkUnit> workUnits;
- private Queue<VersionsWorkUnit> undoQueue;
- private Map<Pair<String, Object>, VersionsWorkUnit> usedIds;
- public VersionsSync(VersionsSyncManager manager, Session session) {
+ public VersionsSync(VersionsSyncManager manager, Session session, RevisionNumberGenerator revisionNumberGenerator) {
this.manager = manager;
this.session = session;
+ this.revisionNumberGenerator = revisionNumberGenerator;
transaction = session.getTransaction();
workUnits = new LinkedList<VersionsWorkUnit>();
undoQueue = new LinkedList<VersionsWorkUnit>();
usedIds = new HashMap<Pair<String, Object>, VersionsWorkUnit>();
}
-
- private void generateRevision(Session session) {
- revision = (Number) session.save(manager.getEntitiesCfg().getRevisionsInfoEntityName(),
- manager.getEntitiesCfg().getRevisionInfoGenerator().newRevision());
- }
-
+
private void removeWorkUnit(VersionsWorkUnit vwu) {
workUnits.remove(vwu);
if (vwu.isPerformed()) {
@@ -98,7 +98,7 @@
private void executeInSession(Session session) {
if (revision == null) {
- generateRevision(session);
+ revision = revisionNumberGenerator.generate(session);
}
VersionsWorkUnit vwu;
@@ -121,6 +121,7 @@
if (FlushMode.isManualFlushMode(session.getFlushMode())) {
Session temporarySession = null;
try {
+ //noinspection deprecation
temporarySession = session.getSessionFactory().openSession(session.connection());
executeInSession(temporarySession);
Modified: trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/synchronization/VersionsSyncManager.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -22,7 +22,7 @@
package org.jboss.envers.synchronization;
import org.jboss.envers.tools.ConcurrentReferenceHashMap;
-import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.revisioninfo.RevisionNumberGenerator;
import org.hibernate.Session;
import org.hibernate.Transaction;
@@ -32,19 +32,15 @@
* @author Adam Warski (adam at warski dot org)
*/
public class VersionsSyncManager {
- private VersionsEntitiesConfiguration verEntCfg;
- private Map<Transaction, VersionsSync> versionsSyncs;
+ private final Map<Transaction, VersionsSync> versionsSyncs;
+ private final RevisionNumberGenerator revisionNumberGenerator;
- public VersionsSyncManager(VersionsEntitiesConfiguration verEntCfg) {
- this.verEntCfg = verEntCfg;
-
+ public VersionsSyncManager(RevisionNumberGenerator revisionNumberGenerator) {
versionsSyncs = new ConcurrentReferenceHashMap<Transaction, VersionsSync>(10,
ConcurrentReferenceHashMap.ReferenceType.WEAK,
ConcurrentReferenceHashMap.ReferenceType.STRONG);
- }
- public VersionsEntitiesConfiguration getEntitiesCfg() {
- return verEntCfg;
+ this.revisionNumberGenerator = revisionNumberGenerator;
}
public VersionsSync get(Session session) {
@@ -52,7 +48,7 @@
VersionsSync verSync = versionsSyncs.get(transaction);
if (verSync == null) {
- verSync = new VersionsSync(this, session);
+ verSync = new VersionsSync(this, session, revisionNumberGenerator);
versionsSyncs.put(transaction, verSync);
transaction.registerSynchronization(verSync);
Modified: trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/synchronization/work/AbstractVersionsWorkUnit.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -47,12 +47,12 @@
}
protected void fillDataWithId(Map<String, Object> data, Number revision, RevisionType revisionType) {
- VersionsEntitiesConfiguration entitiesCfg = verCfg.getEntitiesCfg();
+ VersionsEntitiesConfiguration entitiesCfg = verCfg.getVerEntCfg();
Map<String, Object> originalId = new HashMap<String, Object>();
originalId.put(entitiesCfg.getRevisionPropName(), revision);
- verCfg.getIdMapper(getEntityName()).mapToMapFromId(originalId, id);
+ verCfg.getEntCfg().getIdMapper(getEntityName()).mapToMapFromId(originalId, id);
data.put(entitiesCfg.getRevisionTypePropName(), revisionType);
data.put(entitiesCfg.getOriginalIdPropName(), originalId);
}
@@ -75,7 +75,7 @@
public void undo(Session session) {
if (isPerformed()) {
- session.delete(verCfg.getEntitiesCfg().getVersionsEntityName(getEntityName()), performedData);
+ session.delete(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()), performedData);
session.flush();
}
}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/synchronization/work/AddWorkUnit.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -53,9 +53,9 @@
Map<String, Object> data = new HashMap<String, Object>();
fillDataWithId(data, revision, RevisionType.ADD);
- verCfg.getPropertyMapper(getEntityName()).map(data, propertyNames, state, null);
+ verCfg.getEntCfg().getPropertyMapper(getEntityName()).map(data, propertyNames, state, null);
- session.save(verCfg.getEntitiesCfg().getVersionsEntityName(getEntityName()), data);
+ session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()), data);
setPerformed(data);
}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/synchronization/work/CollectionChangeWorkUnit.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -49,9 +49,9 @@
Map<String, Object> data = new HashMap<String, Object>();
fillDataWithId(data, revision, RevisionType.MOD);
- verCfg.getPropertyMapper(getEntityName()).mapToMapFromEntity(data, entity, null);
+ verCfg.getEntCfg().getPropertyMapper(getEntityName()).mapToMapFromEntity(data, entity, null);
- session.save(verCfg.getEntitiesCfg().getVersionsEntityName(getEntityName()), data);
+ session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()), data);
setPerformed(data);
}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/synchronization/work/DelWorkUnit.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -45,7 +45,7 @@
Map<String, Object> data = new HashMap<String, Object>();
fillDataWithId(data, revision, RevisionType.DEL);
- session.save(verCfg.getEntitiesCfg().getVersionsEntityName(getEntityName()), data);
+ session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()), data);
setPerformed(data);
}
Modified: trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java 2008-08-14 11:12:23 UTC (rev 103)
+++ trunk/src/main/org/jboss/envers/synchronization/work/ModWorkUnit.java 2008-08-14 15:39:48 UTC (rev 104)
@@ -42,7 +42,7 @@
super(entityName, verCfg, id);
data = new HashMap<String, Object>();
- changes = verCfg.getPropertyMapper(getEntityName()).map(data, entityPersister.getPropertyNames(),
+ changes = verCfg.getEntCfg().getPropertyMapper(getEntityName()).map(data, entityPersister.getPropertyNames(),
newState, oldState);
}
@@ -53,7 +53,7 @@
public void perform(Session session, Number revision) {
fillDataWithId(data, revision, RevisionType.MOD);
- session.save(verCfg.getEntitiesCfg().getVersionsEntityName(getEntityName()), data);
+ session.save(verCfg.getVerEntCfg().getVersionsEntityName(getEntityName()), data);
setPerformed(data);
}
16 years, 4 months
JBoss Envers SVN: r103 - in trunk/src/main/org/jboss/envers: configuration and 3 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-14 07:12:23 -0400 (Thu, 14 Aug 2008)
New Revision: 103
Added:
trunk/src/main/org/jboss/envers/configuration/metadata/
trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
trunk/src/main/org/jboss/envers/configuration/metadata/InheritanceType.java
trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java
trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/data/
Removed:
trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
trunk/src/main/org/jboss/envers/configuration/metadata/InheritanceType.java
trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java
trunk/src/main/org/jboss/envers/configuration/metadata/RevisionType.java
trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/data/
trunk/src/main/org/jboss/envers/metadata/
trunk/src/main/org/jboss/envers/tools/Triple.java
Modified:
trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/data/IdMappingData.java
trunk/src/main/org/jboss/envers/configuration/metadata/data/PersistentClassVersioningData.java
trunk/src/main/org/jboss/envers/configuration/metadata/data/PropertyStoreInfo.java
Log:
ENVERS-37: moving metadata to configuration
Modified: trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java 2008-08-14 10:19:45 UTC (rev 102)
+++ trunk/src/main/org/jboss/envers/configuration/EntityConfiguration.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -21,7 +21,7 @@
*/
package org.jboss.envers.configuration;
-import org.jboss.envers.metadata.data.IdMappingData;
+import org.jboss.envers.configuration.metadata.data.IdMappingData;
import org.jboss.envers.mapper.ExtendedPropertyMapper;
import org.jboss.envers.mapper.id.IdMapper;
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-14 10:19:45 UTC (rev 102)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -24,10 +24,10 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.MappingException;
-import org.jboss.envers.metadata.VersionsMetadataGenerator;
-import org.jboss.envers.metadata.RevisionsInfoMetadataGenerator;
-import org.jboss.envers.metadata.AnnotationsMetadataReader;
-import org.jboss.envers.metadata.data.PersistentClassVersioningData;
+import org.jboss.envers.configuration.metadata.VersionsMetadataGenerator;
+import org.jboss.envers.configuration.metadata.RevisionsInfoMetadataGenerator;
+import org.jboss.envers.configuration.metadata.AnnotationsMetadataReader;
+import org.jboss.envers.configuration.metadata.data.PersistentClassVersioningData;
import org.jboss.envers.synchronization.VersionsSyncManager;
import org.jboss.envers.mapper.ExtendedPropertyMapper;
import org.jboss.envers.mapper.id.IdMapper;
Copied: trunk/src/main/org/jboss/envers/configuration/metadata (from rev 95, trunk/src/main/org/jboss/envers/metadata)
Deleted: trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -1,105 +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.metadata;
-
-import org.jboss.envers.reflection.YClass;
-import org.jboss.envers.reflection.YProperty;
-import org.jboss.envers.reflection.YReflectionManager;
-import org.jboss.envers.metadata.data.PersistentClassVersioningData;
-import org.jboss.envers.Versioned;
-import org.jboss.envers.VersionsTable;
-import org.jboss.envers.SecondaryVersionsTable;
-import org.jboss.envers.SecondaryVersionsTables;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.MappingException;
-
-/**
- * A helper class to read versioning meta-data from annotations on persistent classes.
- * @author Adam Warski (adam at warski dot org)
- */
-public class AnnotationsMetadataReader {
- private void addPropertiesFromClass(YClass clazz, PersistentClassVersioningData versioningData) {
- YClass superclazz = clazz.getSuperclass();
- if (!"java.lang.Object".equals(superclazz.getName())) {
- addPropertiesFromClass(superclazz, versioningData);
- }
-
- for (YProperty property : clazz.getDeclaredProperties("field")) {
- Versioned ver = property.getAnnotation(Versioned.class);
- if (ver != null) {
- versioningData.propertyStoreInfo.propertyStores.put(property.getName(), ver.modStore());
- }
- }
-
- for (YProperty property : clazz.getDeclaredProperties("property")) {
- Versioned ver = property.getAnnotation(Versioned.class);
- if (ver != null) {
- versioningData.propertyStoreInfo.propertyStores.put(property.getName(), ver.modStore());
- }
- }
- }
-
- public PersistentClassVersioningData getVersioningData(PersistentClass pc, YReflectionManager reflectionManager) {
- if (pc.getClassName() == null) {
- return null;
- }
-
- PersistentClassVersioningData versioningData = new PersistentClassVersioningData();
-
- try {
- YClass clazz = reflectionManager.classForName(pc.getClassName(), this.getClass());
- Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
-
- if (defaultVersioned != null) {
- versioningData.propertyStoreInfo.defaultStore = defaultVersioned.modStore();
- }
-
- addPropertiesFromClass(clazz, versioningData);
-
- VersionsTable versionsTable = clazz.getAnnotation(VersionsTable.class);
- if (versionsTable != null) {
- versioningData.versionsTableName = versionsTable.value();
- versioningData.schema = versionsTable.schema();
- versioningData.catalog = versionsTable.catalog();
- }
-
- // Getting information on secondary tables
- SecondaryVersionsTable secondaryVersionsTable1 = clazz.getAnnotation(SecondaryVersionsTable.class);
- if (secondaryVersionsTable1 != null) {
- versioningData.secondaryTableDictionary.put(secondaryVersionsTable1.secondaryTableName(),
- secondaryVersionsTable1.secondaryVersionsTableName());
- }
-
- SecondaryVersionsTables secondaryVersionsTables = clazz.getAnnotation(SecondaryVersionsTables.class);
- if (secondaryVersionsTables != null) {
- for (SecondaryVersionsTable secondaryVersionsTable2 : secondaryVersionsTables.value()) {
- versioningData.secondaryTableDictionary.put(secondaryVersionsTable2.secondaryTableName(),
- secondaryVersionsTable2.secondaryVersionsTableName());
- }
- }
- } catch (ClassNotFoundException e) {
- throw new MappingException(e);
- }
-
- return versioningData;
- }
-}
Copied: trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java (from rev 102, trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -0,0 +1,105 @@
+/*
+ * 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.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.Versioned;
+import org.jboss.envers.VersionsTable;
+import org.jboss.envers.SecondaryVersionsTable;
+import org.jboss.envers.SecondaryVersionsTables;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.MappingException;
+
+/**
+ * A helper class to read versioning meta-data from annotations on persistent classes.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class AnnotationsMetadataReader {
+ private void addPropertiesFromClass(YClass clazz, PersistentClassVersioningData versioningData) {
+ YClass superclazz = clazz.getSuperclass();
+ if (!"java.lang.Object".equals(superclazz.getName())) {
+ addPropertiesFromClass(superclazz, versioningData);
+ }
+
+ for (YProperty property : clazz.getDeclaredProperties("field")) {
+ Versioned ver = property.getAnnotation(Versioned.class);
+ if (ver != null) {
+ versioningData.propertyStoreInfo.propertyStores.put(property.getName(), ver.modStore());
+ }
+ }
+
+ for (YProperty property : clazz.getDeclaredProperties("property")) {
+ Versioned ver = property.getAnnotation(Versioned.class);
+ if (ver != null) {
+ versioningData.propertyStoreInfo.propertyStores.put(property.getName(), ver.modStore());
+ }
+ }
+ }
+
+ public PersistentClassVersioningData getVersioningData(PersistentClass pc, YReflectionManager reflectionManager) {
+ if (pc.getClassName() == null) {
+ return null;
+ }
+
+ PersistentClassVersioningData versioningData = new PersistentClassVersioningData();
+
+ try {
+ YClass clazz = reflectionManager.classForName(pc.getClassName(), this.getClass());
+ Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
+
+ if (defaultVersioned != null) {
+ versioningData.propertyStoreInfo.defaultStore = defaultVersioned.modStore();
+ }
+
+ addPropertiesFromClass(clazz, versioningData);
+
+ VersionsTable versionsTable = clazz.getAnnotation(VersionsTable.class);
+ if (versionsTable != null) {
+ versioningData.versionsTableName = versionsTable.value();
+ versioningData.schema = versionsTable.schema();
+ versioningData.catalog = versionsTable.catalog();
+ }
+
+ // Getting information on secondary tables
+ SecondaryVersionsTable secondaryVersionsTable1 = clazz.getAnnotation(SecondaryVersionsTable.class);
+ if (secondaryVersionsTable1 != null) {
+ versioningData.secondaryTableDictionary.put(secondaryVersionsTable1.secondaryTableName(),
+ secondaryVersionsTable1.secondaryVersionsTableName());
+ }
+
+ SecondaryVersionsTables secondaryVersionsTables = clazz.getAnnotation(SecondaryVersionsTables.class);
+ if (secondaryVersionsTables != null) {
+ for (SecondaryVersionsTable secondaryVersionsTable2 : secondaryVersionsTables.value()) {
+ versioningData.secondaryTableDictionary.put(secondaryVersionsTable2.secondaryTableName(),
+ secondaryVersionsTable2.secondaryVersionsTableName());
+ }
+ }
+ } catch (ClassNotFoundException e) {
+ throw new MappingException(e);
+ }
+
+ return versioningData;
+ }
+}
Deleted: trunk/src/main/org/jboss/envers/configuration/metadata/InheritanceType.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/InheritanceType.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/InheritanceType.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -1,60 +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.metadata;
-
-import org.hibernate.mapping.*;
-import org.hibernate.MappingException;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public enum InheritanceType {
- NONE,
- JOINED,
- SINGLE,
- TABLE_PER_CLASS;
-
- /**
- * @param pc The class for which to get the inheritance type.
- * @return The inheritance type of this class. NONE, if this class does not inherit from
- * another persisten class.
- */
- public static InheritanceType get(PersistentClass pc) {
- PersistentClass superclass = pc.getSuperclass();
- if (superclass == null) {
- return InheritanceType.NONE;
- }
-
- // We assume that every subclass is of the same type.
- Subclass subclass = (Subclass) superclass.getSubclassIterator().next();
-
- if (subclass instanceof SingleTableSubclass) {
- return InheritanceType.SINGLE;
- } else if (subclass instanceof JoinedSubclass) {
- return InheritanceType.JOINED;
- } else if (subclass instanceof UnionSubclass) {
- return InheritanceType.TABLE_PER_CLASS;
- }
-
- throw new MappingException("Unknown subclass class: " + subclass.getClass());
- }
-}
Copied: trunk/src/main/org/jboss/envers/configuration/metadata/InheritanceType.java (from rev 102, trunk/src/main/org/jboss/envers/metadata/InheritanceType.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/InheritanceType.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/InheritanceType.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -0,0 +1,60 @@
+/*
+ * 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.hibernate.mapping.*;
+import org.hibernate.MappingException;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public enum InheritanceType {
+ NONE,
+ JOINED,
+ SINGLE,
+ TABLE_PER_CLASS;
+
+ /**
+ * @param pc The class for which to get the inheritance type.
+ * @return The inheritance type of this class. NONE, if this class does not inherit from
+ * another persisten class.
+ */
+ public static InheritanceType get(PersistentClass pc) {
+ PersistentClass superclass = pc.getSuperclass();
+ if (superclass == null) {
+ return InheritanceType.NONE;
+ }
+
+ // We assume that every subclass is of the same type.
+ Subclass subclass = (Subclass) superclass.getSubclassIterator().next();
+
+ if (subclass instanceof SingleTableSubclass) {
+ return InheritanceType.SINGLE;
+ } else if (subclass instanceof JoinedSubclass) {
+ return InheritanceType.JOINED;
+ } else if (subclass instanceof UnionSubclass) {
+ return InheritanceType.TABLE_PER_CLASS;
+ }
+
+ throw new MappingException("Unknown subclass class: " + subclass.getClass());
+ }
+}
Deleted: trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/MetadataTools.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -1,125 +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.metadata;
-
-import org.dom4j.Element;
-import org.dom4j.Document;
-import org.jboss.envers.tools.StringTools;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class MetadataTools {
- public static Element addNativelyGeneratedId(Element parent, String name, String type) {
- Element id_mapping = parent.addElement("id");
- id_mapping.addAttribute("name", name).addAttribute("type", type);
-
- Element generator_mapping = id_mapping.addElement("generator");
- generator_mapping.addAttribute("class", "native");
-
- return id_mapping;
- }
-
- public static Element addProperty(Element parent, String name, String type, boolean key) {
- Element prop_mapping;
- if (key) {
- prop_mapping = parent.addElement("key-property");
- } else {
- prop_mapping = parent.addElement("property");
- }
-
- prop_mapping.addAttribute("name", name).addAttribute("type", type);
-
- return prop_mapping;
- }
-
- public static Element addColumn(Element parent, String name, Integer length) {
- Element column_mapping = parent.addElement("column");
-
- column_mapping.addAttribute("name", name);
- if (length != null) {
- column_mapping.addAttribute("length", length.toString());
- }
-
- return column_mapping;
- }
-
- private static Element createEntityCommon(Document document, String type, String entityName,
- String tableName, String schema, String catalog,
- String discriminatorValue) {
- Element hibernate_mapping = document.addElement("hibernate-mapping");
-
- Element class_mapping = hibernate_mapping.addElement(type);
- class_mapping.addAttribute("entity-name", entityName);
-
- if (discriminatorValue != null) {
- class_mapping.addAttribute("discriminator-value", discriminatorValue);
- }
-
- if (!StringTools.isEmpty(tableName)) {
- class_mapping.addAttribute("table", tableName);
- }
-
- if (!StringTools.isEmpty(schema)) {
- class_mapping.addAttribute("schema", schema);
- }
-
- if (!StringTools.isEmpty(catalog)) {
- class_mapping.addAttribute("catalog", catalog);
- }
-
- return class_mapping;
- }
-
- public static Element createEntity(Document document, String entityName, String tableName,
- String schema, String catalog, String discriminatorValue) {
- return createEntityCommon(document, "class", entityName, tableName, schema, catalog, discriminatorValue);
- }
-
- public static Element createSubclassEntity(Document document, String entityName, String tableName,
- String schema, String catalog, String extendsEntityName,
- String discriminatorValue) {
- Element class_mapping = createEntityCommon(document, "subclass", entityName, tableName, schema, catalog,
- discriminatorValue);
-
- class_mapping.addAttribute("extends", extendsEntityName);
-
- return class_mapping;
- }
-
- public static Element createJoin(Element parent, String tableName,
- String schema, String catalog) {
- Element join_mapping = parent.addElement("join");
-
- join_mapping.addAttribute("table", tableName);
-
- if (!StringTools.isEmpty(schema)) {
- join_mapping.addAttribute("schema", schema);
- }
-
- if (!StringTools.isEmpty(catalog)) {
- join_mapping.addAttribute("catalog", catalog);
- }
-
- return join_mapping;
- }
-}
Copied: trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java (from rev 102, trunk/src/main/org/jboss/envers/metadata/MetadataTools.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -0,0 +1,125 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.configuration.metadata;
+
+import org.dom4j.Element;
+import org.dom4j.Document;
+import org.jboss.envers.tools.StringTools;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class MetadataTools {
+ public static Element addNativelyGeneratedId(Element parent, String name, String type) {
+ Element id_mapping = parent.addElement("id");
+ id_mapping.addAttribute("name", name).addAttribute("type", type);
+
+ Element generator_mapping = id_mapping.addElement("generator");
+ generator_mapping.addAttribute("class", "native");
+
+ return id_mapping;
+ }
+
+ public static Element addProperty(Element parent, String name, String type, boolean key) {
+ Element prop_mapping;
+ if (key) {
+ prop_mapping = parent.addElement("key-property");
+ } else {
+ prop_mapping = parent.addElement("property");
+ }
+
+ prop_mapping.addAttribute("name", name).addAttribute("type", type);
+
+ return prop_mapping;
+ }
+
+ public static Element addColumn(Element parent, String name, Integer length) {
+ Element column_mapping = parent.addElement("column");
+
+ column_mapping.addAttribute("name", name);
+ if (length != null) {
+ column_mapping.addAttribute("length", length.toString());
+ }
+
+ return column_mapping;
+ }
+
+ private static Element createEntityCommon(Document document, String type, String entityName,
+ String tableName, String schema, String catalog,
+ String discriminatorValue) {
+ Element hibernate_mapping = document.addElement("hibernate-mapping");
+
+ Element class_mapping = hibernate_mapping.addElement(type);
+ class_mapping.addAttribute("entity-name", entityName);
+
+ if (discriminatorValue != null) {
+ class_mapping.addAttribute("discriminator-value", discriminatorValue);
+ }
+
+ if (!StringTools.isEmpty(tableName)) {
+ class_mapping.addAttribute("table", tableName);
+ }
+
+ if (!StringTools.isEmpty(schema)) {
+ class_mapping.addAttribute("schema", schema);
+ }
+
+ if (!StringTools.isEmpty(catalog)) {
+ class_mapping.addAttribute("catalog", catalog);
+ }
+
+ return class_mapping;
+ }
+
+ public static Element createEntity(Document document, String entityName, String tableName,
+ String schema, String catalog, String discriminatorValue) {
+ return createEntityCommon(document, "class", entityName, tableName, schema, catalog, discriminatorValue);
+ }
+
+ public static Element createSubclassEntity(Document document, String entityName, String tableName,
+ String schema, String catalog, String extendsEntityName,
+ String discriminatorValue) {
+ Element class_mapping = createEntityCommon(document, "subclass", entityName, tableName, schema, catalog,
+ discriminatorValue);
+
+ class_mapping.addAttribute("extends", extendsEntityName);
+
+ return class_mapping;
+ }
+
+ public static Element createJoin(Element parent, String tableName,
+ String schema, String catalog) {
+ Element join_mapping = parent.addElement("join");
+
+ join_mapping.addAttribute("table", tableName);
+
+ if (!StringTools.isEmpty(schema)) {
+ join_mapping.addAttribute("schema", schema);
+ }
+
+ if (!StringTools.isEmpty(catalog)) {
+ join_mapping.addAttribute("catalog", catalog);
+ }
+
+ return join_mapping;
+ }
+}
Deleted: trunk/src/main/org/jboss/envers/configuration/metadata/RevisionType.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/RevisionType.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/RevisionType.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -1,33 +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.metadata;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class RevisionType {
- private RevisionType() { }
-
- public final static Byte ADD = 0;
- public final static Byte MOD = 1;
- public final static Byte DEL = 2;
-}
Deleted: trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/RevisionsInfoMetadataGenerator.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -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.metadata;
-
-import org.dom4j.Document;
-import org.dom4j.DocumentHelper;
-import org.dom4j.Element;
-import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class RevisionsInfoMetadataGenerator {
- private VersionsEntitiesConfiguration verEntCfg;
-
- public RevisionsInfoMetadataGenerator(VersionsEntitiesConfiguration verEntCfg) {
- this.verEntCfg = verEntCfg;
- }
-
- public Document generate() {
- Document document = DocumentHelper.createDocument();
-
- Element class_mapping = MetadataTools.createEntity(document, verEntCfg.getRevisionsInfoEntityName(),
- null, null, null, null);
-
- MetadataTools.addNativelyGeneratedId(class_mapping, verEntCfg.getRevisionsInfoIdName(),
- verEntCfg.getRevisionPropType());
-
- MetadataTools.addProperty(class_mapping, verEntCfg.getRevisionsInfoTimestampName(),
- verEntCfg.getRevisionsInfoTimestampType(), false);
-
- return document;
- }
-}
Copied: trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java (from rev 102, trunk/src/main/org/jboss/envers/metadata/RevisionsInfoMetadataGenerator.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/RevisionsInfoMetadataGenerator.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -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.configuration.metadata;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class RevisionsInfoMetadataGenerator {
+ private VersionsEntitiesConfiguration verEntCfg;
+
+ public RevisionsInfoMetadataGenerator(VersionsEntitiesConfiguration verEntCfg) {
+ this.verEntCfg = verEntCfg;
+ }
+
+ public Document generate() {
+ Document document = DocumentHelper.createDocument();
+
+ Element class_mapping = MetadataTools.createEntity(document, verEntCfg.getRevisionsInfoEntityName(),
+ null, null, null, null);
+
+ MetadataTools.addNativelyGeneratedId(class_mapping, verEntCfg.getRevisionsInfoIdName(),
+ verEntCfg.getRevisionPropType());
+
+ MetadataTools.addProperty(class_mapping, verEntCfg.getRevisionsInfoTimestampName(),
+ verEntCfg.getRevisionsInfoTimestampType(), false);
+
+ return document;
+ }
+}
Deleted: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -1,622 +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.metadata;
-
-import org.hibernate.mapping.*;
-import org.hibernate.type.*;
-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.configuration.VersionsEntitiesConfiguration;
-import org.jboss.envers.configuration.EntityConfiguration;
-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.tools.StringTools;
-import org.jboss.envers.tools.Tools;
-import org.jboss.envers.tools.HibernateVersion;
-import org.jboss.envers.ModificationStore;
-import org.jboss.envers.log.YLog;
-import org.jboss.envers.log.YLogManager;
-import org.jboss.envers.metadata.data.IdMappingData;
-import org.jboss.envers.metadata.data.PersistentClassVersioningData;
-import org.jboss.envers.metadata.data.PropertyStoreInfo;
-import org.jboss.envers.exception.VersionsException;
-
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Collections;
-import java.util.HashMap;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class VersionsMetadataGenerator {
- private final static Map<String, ModificationStore> EMPTY_STORE = Collections.emptyMap();
-
- private VersionsConfiguration verCfg;
- private VersionsEntitiesConfiguration verEntCfg;
- private Map<String, EntityConfiguration> entitiesConfigurations;
-
- // Map entity name -> (join descriptor -> element describing the "versioned" join)
- private Map<String, Map<Join, Element>> entitiesJoins;
-
- private YLog log = YLogManager.getLogManager().getLog(VersionsMetadataGenerator.class);
-
- public VersionsMetadataGenerator(VersionsConfiguration verCfg, VersionsEntitiesConfiguration verEntCfg) {
- this.verCfg = verCfg;
- this.verEntCfg = verEntCfg;
-
- entitiesConfigurations = new HashMap<String, EntityConfiguration>();
- entitiesJoins = new HashMap<String, Map<Join, Element>>();
- }
-
- private void addComponentClassName(Element any_mapping, Component comp) {
- if (StringHelper.isNotEmpty(comp.getComponentClassName())) {
- any_mapping.addAttribute("class", comp.getComponentClassName());
- }
- }
-
- private void addColumns(Element any_mapping, Iterator<Column> columns) {
- while (columns.hasNext()) {
- Column column = columns.next();
- MetadataTools.addColumn(any_mapping, column.getName(), column.getLength());
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private void addSimpleProperty(Element parent, Property property, SimpleMapperBuilder mapper,
- ModificationStore store, boolean key) {
- Element prop_mapping = MetadataTools.addProperty(parent, property.getName(),
- property.getType().getName(), key);
- addColumns(prop_mapping, (Iterator<Column>) property.getColumnIterator());
-
- // A null mapper means that we only want to add xml mappings (while building the id mapping)
- if (mapper != null) {
- mapper.add(property.getName(), store);
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private void addEnumProperty(Element parent, Property property, SimpleMapperBuilder mapper,
- ModificationStore store) {
- Element prop_mapping = parent.addElement("property");
- prop_mapping.addAttribute("name", property.getName());
-
- CustomType propertyType = (CustomType) property.getType();
-
- Element type_mapping = prop_mapping.addElement("type");
- type_mapping.addAttribute("name", propertyType.getName());
-
- Element type_param1 = type_mapping.addElement("param");
- type_param1.addAttribute("name", "enumClass");
- type_param1.setText(propertyType.getReturnedClass().getName());
-
- Element type_param2 = type_mapping.addElement("param");
- type_param2.addAttribute("name", "type");
- type_param2.setText(Integer.toString(propertyType.sqlTypes(null)[0]));
-
- addColumns(prop_mapping, (Iterator<Column>) property.getColumnIterator());
-
- mapper.add(property.getName(), store);
- }
-
- @SuppressWarnings({"unchecked"})
- private void addComponent(Element parent, Property property, CompositeMapperBuilder mapper, ModificationStore store,
- String entityName, boolean firstPass) {
- Element component_mapping = null;
- Component prop_component = (Component) property.getValue();
-
- if (!firstPass) {
- // The required element already exists.
- Iterator<Element> iter = parent.elementIterator("component");
- while (iter.hasNext()) {
- Element child = iter.next();
- if (child.attribute("name").getText().equals(property.getName())) {
- component_mapping = child;
- break;
- }
- }
-
- if (component_mapping == null) {
- throw new VersionsException("Element for component not found during second pass!");
- }
- } else {
- component_mapping = parent.addElement("component");
- component_mapping.addAttribute("name", property.getName());
-
- addComponentClassName(component_mapping, prop_component);
- }
-
- addProperties(component_mapping, (Iterator<Property>) prop_component.getPropertyIterator(),
- mapper.addComposite(property.getName()), new PropertyStoreInfo(store, EMPTY_STORE), entityName,
- firstPass);
- }
-
- @SuppressWarnings({"unchecked"})
- private void changeNamesInColumnElement(Element element, Iterator<Column> columnIterator) {
- Iterator<Element> properties = element.elementIterator();
- while (properties.hasNext()) {
- Element property = properties.next();
-
- if ("column".equals(property.getName())) {
- Attribute nameAttr = property.attribute("name");
- if (nameAttr != null) {
- nameAttr.setText(columnIterator.next().getName());
- }
- }
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private void prefixNamesInPropertyElement(Element element, String prefix, Iterator<Column> columnIterator) {
- Iterator<Element> properties = element.elementIterator();
- while (properties.hasNext()) {
- Element property = properties.next();
-
- if ("property".equals(property.getName())) {
- Attribute nameAttr = property.attribute("name");
- if (nameAttr != null) {
- nameAttr.setText(prefix + nameAttr.getText());
- }
-
- changeNamesInColumnElement(property, columnIterator);
- }
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private void addToOne(Element parent, Property property, CompositeMapperBuilder mapper, String entityName) {
- String referencedEntityName = ((ToOne) property.getValue()).getReferencedEntityName();
-
- EntityConfiguration configuration = entitiesConfigurations.get(referencedEntityName);
- if (configuration == null) {
- throw new MappingException("A versioned relation to a non-versioned entity " + referencedEntityName + "!");
- }
-
- IdMappingData idMapping = configuration.getIdMappingData();
-
- String propertyName = property.getName();
- String lastPropertyPrefix = propertyName + "_";
-
- // Generating the id mapper for the relation
- IdMapper relMapper = idMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
-
- // Storing information about this relation
- entitiesConfigurations.get(entityName).addToOneRelation(propertyName, referencedEntityName, relMapper);
-
- // Adding an element to the mapping corresponding to the references entity id's
- Element properties = (Element) idMapping.getXmlRelationMapping().clone();
- properties.addAttribute("name", propertyName);
-
- prefixNamesInPropertyElement(properties, lastPropertyPrefix, property.getValue().getColumnIterator());
- parent.add(properties);
-
- // Adding mapper for the id
- mapper.addComposite(propertyName, new ToOneIdMapper(relMapper, propertyName, referencedEntityName));
- }
-
- @SuppressWarnings({"unchecked"})
- private void addOneToOne(Property property, CompositeMapperBuilder mapper, String entityName) {
- OneToOne propertyValue = (OneToOne) property.getValue();
-
- String owningReferencePropertyName = propertyValue.getReferencedPropertyName(); // mappedBy
-
- EntityConfiguration configuration = entitiesConfigurations.get(entityName);
- if (configuration == null) {
- throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
- }
-
- IdMappingData ownedIdMapping = configuration.getIdMappingData();
-
- if (ownedIdMapping == null) {
- throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
- }
-
- String propertyName = property.getName();
- String lastPropertyPrefix = owningReferencePropertyName + "_";
- String referencedEntityName = propertyValue.getReferencedEntityName();
-
- // Generating the id mapper for the relation
- IdMapper ownedIdMapper = ownedIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
-
- // Storing information about this relation
- entitiesConfigurations.get(entityName).addOneToOneRelation(propertyName, owningReferencePropertyName,
- referencedEntityName, ownedIdMapper);
-
- // Adding mapper for the id
- mapper.addComposite(propertyName, new OneToOneIdMapper(owningReferencePropertyName,
- referencedEntityName, propertyName));
- }
-
- @SuppressWarnings({"unchecked"})
- private String getMappedBy(Collection collectionValue) {
- Iterator<Property> assocClassProps =
- ((OneToMany) collectionValue.getElement()).getAssociatedClass().getPropertyIterator();
-
- while (assocClassProps.hasNext()) {
- Property property = assocClassProps.next();
-
- if (Tools.iteratorsContentEqual(property.getValue().getColumnIterator(),
- collectionValue.getKey().getColumnIterator())) {
- return property.getName();
- }
- }
-
- return null;
- }
-
- @SuppressWarnings({"unchecked"})
- private void addOneToMany(Property property, CompositeMapperBuilder mapper, String entityName) {
- Collection propertyValue = (Collection) property.getValue();
-
- String owningReferencePropertyName = getMappedBy(propertyValue);
- if (owningReferencePropertyName == null) {
- throw new MappingException("Unable to read the mapped by attribute for " + property.getName());
- }
-
- EntityConfiguration configuration = entitiesConfigurations.get(entityName);
- if (configuration == null) {
- throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
- }
-
- IdMappingData referencingIdMapping = configuration.getIdMappingData();
-
- String owningEntityName = ((OneToMany) propertyValue.getElement()).getReferencedEntityName();
- String propertyName = property.getName();
- String lastPropertyPrefix = owningReferencePropertyName + "_";
-
- // Generating the id mapper for the relation
- IdMapper ownedIdMapper = referencingIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
-
- // Storing information about this relation
- entitiesConfigurations.get(entityName).addOneToManyRelation(propertyName, owningReferencePropertyName,
- owningEntityName, ownedIdMapper);
-
- // Adding mapper for the id
- mapper.addComposite(propertyName, new OneToManyIdMapper(owningReferencePropertyName, owningEntityName,
- propertyName));
- }
-
- private ModificationStore getStoreForProperty(Property property, PropertyStoreInfo propertyStoreInfo) {
- /*
- * Checks if a property is versioned, which is when:
- * - the whole entity is versioned, then the default store is not null
- * - there is a store defined for this entity, which is when this property is annotated
- */
-
- ModificationStore store = propertyStoreInfo.propertyStores.get(property.getName());
-
- if (store == null) {
- return propertyStoreInfo.defaultStore;
- }
-
- return store;
- }
-
- @SuppressWarnings({"unchecked"})
- private void addIdProperties(Element parent, Iterator<Property> properties, SimpleMapperBuilder mapper, boolean key) {
- while (properties.hasNext()) {
- Property property = properties.next();
- Type propertyType = property.getType();
- if (!"_identifierMapper".equals(property.getName())) {
- if (propertyType instanceof ImmutableType) {
- addSimpleProperty(parent, property, mapper, ModificationStore.FULL, key);
- } else {
- throw new MappingException("Type not supported: " + propertyType.getClass().getName());
- }
- }
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private void addProperties(Element parent, Iterator<Property> properties, CompositeMapperBuilder currentMapper,
- PropertyStoreInfo propertyStoreInfo, String entityName, boolean firstPass) {
- while (properties.hasNext()) {
- Property property = properties.next();
- Type propertyType = property.getType();
- if (!"_identifierMapper".equals(property.getName())) {
- ModificationStore store = getStoreForProperty(property, propertyStoreInfo);
-
- if (store != null) {
- if (propertyType instanceof ComponentType) {
- // only first pass
- if (firstPass) {
- addComponent(parent, property, currentMapper, store, entityName, firstPass);
- }
- } else if (propertyType instanceof ImmutableType || propertyType instanceof MutableType) {
- // only first pass
- if (firstPass) {
- addSimpleProperty(parent, property, currentMapper, store, false);
- }
- } else if (propertyType instanceof CustomType &&
- "org.hibernate.type.EnumType".equals(propertyType.getName())) {
- // only first pass
- if (firstPass) {
- addEnumProperty(parent, property, currentMapper, store);
- }
- } else if (propertyType instanceof ManyToOneType) {
- // only second pass
- if (!firstPass) {
- addToOne(parent, property, currentMapper, entityName);
- }
- } else if (propertyType instanceof OneToOneType) {
- // only second pass
- if (!firstPass) {
- addOneToOne(property, currentMapper, entityName);
- }
- } else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(
- propertyType.getClass().getName())) {
- // only first pass
- if (firstPass) {
- addSimpleProperty(parent, property, currentMapper, store, false);
- }
- } else if (propertyType instanceof CustomType &&
- ("org.hibernate.type.PrimitiveCharacterArrayClobType".equals(propertyType.getName()) ||
- "org.hibernate.type.StringClobType".equals(propertyType.getName()))) {
- // only first pass
- if (firstPass) {
- addSimpleProperty(parent, property, currentMapper, store, false);
- }
- } else if ((propertyType instanceof BagType || propertyType instanceof SetType) &&
- ((((Collection) property.getValue()).getElement() instanceof OneToMany))) {
- // only second pass
- if (!firstPass) {
- addOneToMany(property, currentMapper, entityName);
- }
- } else {
- String message = "Type not supported for versioning: " + propertyType.getClass().getName() +
- ", on entity " + entityName + ", property '" + property.getName() + "'.";
- if (verCfg.isWarnOnUnsupportedTypes()) {
- log.warn(message);
- } else {
- throw new MappingException(message);
- }
- }
- }
- }
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private void createJoins(PersistentClass pc, Element parent, PersistentClassVersioningData versioningData) {
- Iterator<Join> joins = pc.getJoinIterator();
-
- Map<Join, Element> joinElements = new HashMap<Join, Element>();
- entitiesJoins.put(pc.getEntityName(), joinElements);
-
- while (joins.hasNext()) {
- Join join = joins.next();
-
- // Determining the table name. If there is no entry in the dictionary, just constructing the table name
- // as if it was an entity (by appending/prepending configured strings).
- String originalTableName = join.getTable().getName();
- String versionedTableName = versioningData.secondaryTableDictionary.get(originalTableName);
- if (versionedTableName == null) {
- versionedTableName = verEntCfg.getVersionsEntityName(originalTableName);
- }
-
- String schema = versioningData.schema;
- if (StringTools.isEmpty(schema)) {
- schema = join.getTable().getSchema();
- }
-
- String catalog = versioningData.catalog;
- if (StringTools.isEmpty(catalog)) {
- catalog = join.getTable().getCatalog();
- }
-
- Element joinElement = MetadataTools.createJoin(parent, versionedTableName, schema, catalog);
- joinElements.put(join, joinElement);
-
- Element joinKey = joinElement.addElement("key");
- addColumns(joinKey, join.getKey().getColumnIterator());
- MetadataTools.addColumn(joinKey, verEntCfg.getRevisionPropName(), null);
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private void addJoins(PersistentClass pc, CompositeMapperBuilder currentMapper, PropertyStoreInfo propertyStoreInfo,
- String entityName, boolean firstPass) {
- Iterator<Join> joins = pc.getJoinIterator();
-
- while (joins.hasNext()) {
- Join join = joins.next();
- Element joinElement = entitiesJoins.get(entityName).get(join);
-
- addProperties(joinElement, join.getPropertyIterator(), currentMapper, propertyStoreInfo, entityName,
- firstPass);
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private IdMappingData addId(PersistentClass pc) {
- // Mapping which will be used for relations
- Element rel_id_mapping = new DefaultElement("properties");
- // Mapping which will be used for the primary key of the versions table
- Element orig_id_mapping = new DefaultElement("composite-id");
-
- Property id_prop = pc.getIdentifierProperty();
- Component id_mapper = pc.getIdentifierMapper();
-
- SimpleIdMapperBuilder mapper;
- if (id_mapper != null) {
- mapper = new MultipleIdMapper(((Component) pc.getIdentifier()).getComponentClassName());
- addIdProperties(rel_id_mapping, (Iterator<Property>) id_mapper.getPropertyIterator(), mapper, false);
-
- // null mapper - the mapping where already added the first time, now we only want to generate the xml
- addIdProperties(orig_id_mapping, (Iterator<Property>) id_mapper.getPropertyIterator(), null, true);
- } else if (id_prop.isComposite()) {
- Component id_component = (Component) id_prop.getValue();
-
- mapper = new EmbeddedIdMapper(id_prop.getName(), id_component.getComponentClassName());
- addIdProperties(rel_id_mapping, (Iterator<Property>) id_component.getPropertyIterator(), mapper, false);
-
- // null mapper - the mapping where already added the first time, now we only want to generate the xml
- addIdProperties(orig_id_mapping, (Iterator<Property>) id_component.getPropertyIterator(), null, true);
- } else {
- mapper = new SingleIdMapper();
-
- addSimpleProperty(rel_id_mapping, id_prop, mapper, ModificationStore.FULL, false);
-
- // null mapper - the mapping where already added the first time, now we only want to generate the xml
- addSimpleProperty(orig_id_mapping, id_prop, null, ModificationStore.FULL, true);
- }
-
- 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);
-
- return new IdMappingData(mapper, orig_id_mapping, rel_id_mapping);
- }
-
- private void addPersisterHack(Element class_mapping) {
- String persisterClassName;
- if (HibernateVersion.get().startsWith("3.3")) {
- persisterClassName = "org.jboss.envers.entity.VersionsInheritanceEntityPersisterFor33";
- } else {
- persisterClassName = "org.jboss.envers.entity.VersionsInheritanceEntityPersisterFor32";
- }
-
- class_mapping.addAttribute("persister", persisterClassName);
- }
-
- @SuppressWarnings({"unchecked"})
- public Document generateFirstPass(PersistentClass pc, PersistentClassVersioningData versioningData) {
- Document document = DocumentHelper.createDocument();
-
- String schema = versioningData.schema;
- if (StringTools.isEmpty(schema)) {
- schema = pc.getTable().getSchema();
- }
-
- String catalog = versioningData.catalog;
- if (StringTools.isEmpty(catalog)) {
- catalog = pc.getTable().getCatalog();
- }
-
- String entityName = pc.getEntityName();
- String versionsEntityName = verEntCfg.getVersionsEntityName(entityName);
- String versionsTableName = verEntCfg.getVersionsTableName(entityName, pc.getTable().getName());
-
- // Generating a mapping for the id
- IdMappingData idMapper = addId(pc);
-
- Element class_mapping;
- ExtendedPropertyMapper propertyMapper;
-
- InheritanceType inheritanceType = InheritanceType.get(pc);
- String parentEntityName = null;
-
- switch (inheritanceType) {
- case NONE:
- class_mapping = MetadataTools.createEntity(document, versionsEntityName, versionsTableName,
- schema, catalog, pc.getDiscriminatorValue());
- propertyMapper = new MultiPropertyMapper();
-
- // Checking if there is a discriminator column
- if (pc.getDiscriminator() != null) {
- Element discriminator_element = class_mapping.addElement("discriminator");
- addColumns(discriminator_element, pc.getDiscriminator().getColumnIterator());
- discriminator_element.addAttribute("type", pc.getDiscriminator().getType().getName());
-
- // If so, there is some inheritance scheme -> using the persister hack.
- addPersisterHack(class_mapping);
- }
-
- // Adding the id mapping
- class_mapping.add((Element) idMapper.getXmlMapping().clone());
-
- // Adding the "revision type" property
- MetadataTools.addProperty(class_mapping, verEntCfg.getRevisionTypePropName(),
- verEntCfg.getRevisionTypePropType(), false);
-
- break;
- case SINGLE:
- String extendsEntityName = verEntCfg.getVersionsEntityName(pc.getSuperclass().getEntityName());
- class_mapping = MetadataTools.createSubclassEntity(document, versionsEntityName, versionsTableName,
- schema, catalog, extendsEntityName, pc.getDiscriminatorValue());
-
- addPersisterHack(class_mapping);
-
- // The id and revision type is already mapped in the parent
-
- // Getting the property mapper of the parent - when mapping properties, they need to be included
- parentEntityName = pc.getSuperclass().getEntityName();
- ExtendedPropertyMapper parentPropertyMapper = entitiesConfigurations.get(parentEntityName).getPropertyMapper();
- propertyMapper = new SubclassPropertyMapper(new MultiPropertyMapper(), parentPropertyMapper);
-
- break;
- case JOINED:
- throw new MappingException("Joined inheritance strategy not supported for versioning!");
- case TABLE_PER_CLASS:
- throw new MappingException("Table-per-class inheritance strategy not supported for versioning!");
- default:
- throw new AssertionError("Impossible enum value.");
- }
-
- // Mapping unjoined properties
- addProperties(class_mapping, (Iterator<Property>) pc.getUnjoinedPropertyIterator(), propertyMapper,
- versioningData.propertyStoreInfo, pc.getEntityName(), true);
-
- // Creating and mapping joins (first pass)
- createJoins(pc, class_mapping, versioningData);
- addJoins(pc, propertyMapper, versioningData.propertyStoreInfo, pc.getEntityName(), true);
-
- // Storing the generated configuration
- 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) {
- String entityName = pc.getEntityName();
-
- CompositeMapperBuilder propertyMapper = entitiesConfigurations.get(entityName).getPropertyMapper();
-
- // Mapping unjoined properties
- addProperties(document.getRootElement().element("class"), (Iterator<Property>) pc.getUnjoinedPropertyIterator(),
- propertyMapper, versioningData.propertyStoreInfo, entityName, false);
-
- // Mapping joins (second pass)
- addJoins(pc, propertyMapper, versioningData.propertyStoreInfo, entityName, false);
- }
-
- public Map<String, EntityConfiguration> getEntitiesConfigurations() {
- return entitiesConfigurations;
- }
-}
Copied: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java (from rev 102, trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -0,0 +1,662 @@
+/*
+ * 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.hibernate.mapping.*;
+import org.hibernate.type.*;
+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.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.EntityConfiguration;
+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.tools.StringTools;
+import org.jboss.envers.tools.Tools;
+import org.jboss.envers.tools.HibernateVersion;
+import org.jboss.envers.ModificationStore;
+import org.jboss.envers.tools.log.YLog;
+import org.jboss.envers.tools.log.YLogManager;
+import org.jboss.envers.configuration.metadata.data.IdMappingData;
+import org.jboss.envers.configuration.metadata.data.PersistentClassVersioningData;
+import org.jboss.envers.configuration.metadata.data.PropertyStoreInfo;
+import org.jboss.envers.exception.VersionsException;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Collections;
+import java.util.HashMap;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class VersionsMetadataGenerator {
+ private final static Map<String, ModificationStore> EMPTY_STORE = Collections.emptyMap();
+
+ private VersionsConfiguration verCfg;
+ private VersionsEntitiesConfiguration verEntCfg;
+ private Map<String, EntityConfiguration> entitiesConfigurations;
+
+ // Map entity name -> (join descriptor -> element describing the "versioned" join)
+ private Map<String, Map<Join, Element>> entitiesJoins;
+
+ private YLog log = YLogManager.getLogManager().getLog(VersionsMetadataGenerator.class);
+
+ public VersionsMetadataGenerator(VersionsConfiguration verCfg, VersionsEntitiesConfiguration verEntCfg) {
+ this.verCfg = verCfg;
+ this.verEntCfg = verEntCfg;
+
+ entitiesConfigurations = new HashMap<String, EntityConfiguration>();
+ entitiesJoins = new HashMap<String, Map<Join, Element>>();
+ }
+
+ private void addComponentClassName(Element any_mapping, Component comp) {
+ if (StringHelper.isNotEmpty(comp.getComponentClassName())) {
+ any_mapping.addAttribute("class", comp.getComponentClassName());
+ }
+ }
+
+ private void addColumns(Element any_mapping, Iterator<Column> columns) {
+ while (columns.hasNext()) {
+ Column column = columns.next();
+ MetadataTools.addColumn(any_mapping, column.getName(), column.getLength());
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void addSimpleProperty(Element parent, Property property, SimpleMapperBuilder mapper,
+ ModificationStore store, boolean key) {
+ Element prop_mapping = MetadataTools.addProperty(parent, property.getName(),
+ property.getType().getName(), key);
+ addColumns(prop_mapping, (Iterator<Column>) property.getColumnIterator());
+
+ // A null mapper means that we only want to add xml mappings (while building the id mapping)
+ if (mapper != null) {
+ mapper.add(property.getName(), store);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void addEnumProperty(Element parent, Property property, SimpleMapperBuilder mapper,
+ ModificationStore store) {
+ Element prop_mapping = parent.addElement("property");
+ prop_mapping.addAttribute("name", property.getName());
+
+ CustomType propertyType = (CustomType) property.getType();
+
+ Element type_mapping = prop_mapping.addElement("type");
+ type_mapping.addAttribute("name", propertyType.getName());
+
+ Element type_param1 = type_mapping.addElement("param");
+ type_param1.addAttribute("name", "enumClass");
+ type_param1.setText(propertyType.getReturnedClass().getName());
+
+ Element type_param2 = type_mapping.addElement("param");
+ type_param2.addAttribute("name", "type");
+ type_param2.setText(Integer.toString(propertyType.sqlTypes(null)[0]));
+
+ addColumns(prop_mapping, (Iterator<Column>) property.getColumnIterator());
+
+ mapper.add(property.getName(), store);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void addComponent(Element parent, Property property, CompositeMapperBuilder mapper, ModificationStore store,
+ String entityName, boolean firstPass) {
+ Element component_mapping = null;
+ Component prop_component = (Component) property.getValue();
+
+ if (!firstPass) {
+ // The required element already exists.
+ Iterator<Element> iter = parent.elementIterator("component");
+ while (iter.hasNext()) {
+ Element child = iter.next();
+ if (child.attribute("name").getText().equals(property.getName())) {
+ component_mapping = child;
+ break;
+ }
+ }
+
+ if (component_mapping == null) {
+ throw new VersionsException("Element for component not found during second pass!");
+ }
+ } else {
+ component_mapping = parent.addElement("component");
+ component_mapping.addAttribute("name", property.getName());
+
+ addComponentClassName(component_mapping, prop_component);
+ }
+
+ addProperties(component_mapping, (Iterator<Property>) prop_component.getPropertyIterator(),
+ mapper.addComposite(property.getName()), new PropertyStoreInfo(store, EMPTY_STORE), entityName,
+ firstPass);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void changeNamesInColumnElement(Element element, Iterator<Column> columnIterator) {
+ Iterator<Element> properties = element.elementIterator();
+ while (properties.hasNext()) {
+ Element property = properties.next();
+
+ if ("column".equals(property.getName())) {
+ Attribute nameAttr = property.attribute("name");
+ if (nameAttr != null) {
+ nameAttr.setText(columnIterator.next().getName());
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void prefixNamesInPropertyElement(Element element, String prefix, Iterator<Column> columnIterator) {
+ Iterator<Element> properties = element.elementIterator();
+ while (properties.hasNext()) {
+ Element property = properties.next();
+
+ if ("property".equals(property.getName())) {
+ Attribute nameAttr = property.attribute("name");
+ if (nameAttr != null) {
+ nameAttr.setText(prefix + nameAttr.getText());
+ }
+
+ changeNamesInColumnElement(property, columnIterator);
+ }
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void addToOne(Element parent, Property property, CompositeMapperBuilder mapper, String entityName) {
+ String referencedEntityName = ((ToOne) property.getValue()).getReferencedEntityName();
+
+ EntityConfiguration configuration = entitiesConfigurations.get(referencedEntityName);
+ if (configuration == null) {
+ throw new MappingException("A versioned relation to a non-versioned entity " + referencedEntityName + "!");
+ }
+
+ IdMappingData idMapping = configuration.getIdMappingData();
+
+ String propertyName = property.getName();
+ String lastPropertyPrefix = propertyName + "_";
+
+ // Generating the id mapper for the relation
+ IdMapper relMapper = idMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
+
+ // Storing information about this relation
+ entitiesConfigurations.get(entityName).addToOneRelation(propertyName, referencedEntityName, relMapper);
+
+ // Adding an element to the mapping corresponding to the references entity id's
+ Element properties = (Element) idMapping.getXmlRelationMapping().clone();
+ properties.addAttribute("name", propertyName);
+
+ prefixNamesInPropertyElement(properties, lastPropertyPrefix, property.getValue().getColumnIterator());
+ parent.add(properties);
+
+ // Adding mapper for the id
+ mapper.addComposite(propertyName, new ToOneIdMapper(relMapper, propertyName, referencedEntityName));
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void addOneToOneBidirectional(Property property, CompositeMapperBuilder mapper, String entityName) {
+ OneToOne propertyValue = (OneToOne) property.getValue();
+
+ String owningReferencePropertyName = propertyValue.getReferencedPropertyName(); // mappedBy
+
+ EntityConfiguration configuration = entitiesConfigurations.get(entityName);
+ if (configuration == null) {
+ throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
+ }
+
+ IdMappingData ownedIdMapping = configuration.getIdMappingData();
+
+ if (ownedIdMapping == null) {
+ throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
+ }
+
+ String propertyName = property.getName();
+ String lastPropertyPrefix = owningReferencePropertyName + "_";
+ String referencedEntityName = propertyValue.getReferencedEntityName();
+
+ // Generating the id mapper for the relation
+ IdMapper ownedIdMapper = ownedIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
+
+ // Storing information about this relation
+ entitiesConfigurations.get(entityName).addOneToOneRelation(propertyName, owningReferencePropertyName,
+ referencedEntityName, ownedIdMapper);
+
+ // Adding mapper for the id
+ mapper.addComposite(propertyName, new OneToOneIdMapper(owningReferencePropertyName,
+ referencedEntityName, propertyName));
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private String getMappedBy(Collection collectionValue) {
+ Iterator<Property> assocClassProps =
+ ((OneToMany) collectionValue.getElement()).getAssociatedClass().getPropertyIterator();
+
+ while (assocClassProps.hasNext()) {
+ Property property = assocClassProps.next();
+
+ if (Tools.iteratorsContentEqual(property.getValue().getColumnIterator(),
+ collectionValue.getKey().getColumnIterator())) {
+ return property.getName();
+ }
+ }
+
+ return null;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void addOneToManyBidirectional(Property property, CompositeMapperBuilder mapper, String entityName) {
+ Collection propertyValue = (Collection) property.getValue();
+
+ String owningReferencePropertyName = getMappedBy(propertyValue);
+ if (owningReferencePropertyName == null) {
+ throw new MappingException("Unable to read the mapped by attribute for " + property.getName());
+ }
+
+ EntityConfiguration configuration = entitiesConfigurations.get(entityName);
+ if (configuration == null) {
+ throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
+ }
+
+ IdMappingData referencingIdMapping = configuration.getIdMappingData();
+
+ String owningEntityName = ((OneToMany) propertyValue.getElement()).getReferencedEntityName();
+ String propertyName = property.getName();
+ String lastPropertyPrefix = owningReferencePropertyName + "_";
+
+ // Generating the id mapper for the relation
+ IdMapper ownedIdMapper = referencingIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
+
+ // Storing information about this relation
+ entitiesConfigurations.get(entityName).addOneToManyRelation(propertyName, owningReferencePropertyName,
+ owningEntityName, ownedIdMapper);
+
+ // Adding mapper for the id
+ mapper.addComposite(propertyName, new OneToManyIdMapper(owningReferencePropertyName, owningEntityName,
+ propertyName));
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void addOneToManyUnidirectional(Property property, CompositeMapperBuilder mapper, String entityName) {
+ Collection propertyValue = (Collection) property.getValue();
+ ManyToOne mto = (ManyToOne) propertyValue.getElement();
+
+ String referencedEntityName = mto.getReferencedEntityName();
+
+ EntityConfiguration configuration = entitiesConfigurations.get(entityName);
+ if (configuration == null) {
+ throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
+ }
+
+ EntityConfiguration referencedConfiguration = entitiesConfigurations.get(referencedEntityName);
+ if (referencedConfiguration == null) {
+ throw new MappingException("A versioned relation to a non-versioned entity " + referencedEntityName + "!");
+ }
+
+ IdMappingData referencingIdMapping = configuration.getIdMappingData();
+ IdMappingData referencedIdMapping = referencedConfiguration.getIdMappingData();
+
+ // Name of the entity that will be used to store the relation between the two entities.
+ String middleEntityName = entityName + "_" + referencedEntityName;
+
+ MetadataTools.createEntity(null, middleEntityName, mto.getTable().getName(), mto.getTable().getSchema(),
+ mto.getTable().getCatalog(), null);
+
+ // TODO: ???
+ }
+
+ private ModificationStore getStoreForProperty(Property property, PropertyStoreInfo propertyStoreInfo) {
+ /*
+ * Checks if a property is versioned, which is when:
+ * - the whole entity is versioned, then the default store is not null
+ * - there is a store defined for this entity, which is when this property is annotated
+ */
+
+ ModificationStore store = propertyStoreInfo.propertyStores.get(property.getName());
+
+ if (store == null) {
+ return propertyStoreInfo.defaultStore;
+ }
+
+ return store;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void addIdProperties(Element parent, Iterator<Property> properties, SimpleMapperBuilder mapper, boolean key) {
+ while (properties.hasNext()) {
+ Property property = properties.next();
+ Type propertyType = property.getType();
+ if (!"_identifierMapper".equals(property.getName())) {
+ if (propertyType instanceof ImmutableType) {
+ addSimpleProperty(parent, property, mapper, ModificationStore.FULL, key);
+ } else {
+ throw new MappingException("Type not supported: " + propertyType.getClass().getName());
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void addProperties(Element parent, Iterator<Property> properties, CompositeMapperBuilder currentMapper,
+ PropertyStoreInfo propertyStoreInfo, String entityName, boolean firstPass) {
+ while (properties.hasNext()) {
+ Property property = properties.next();
+ Type propertyType = property.getType();
+ if (!"_identifierMapper".equals(property.getName())) {
+ ModificationStore store = getStoreForProperty(property, propertyStoreInfo);
+
+ if (store != null) {
+ if (propertyType instanceof ComponentType) {
+ // only first pass
+ if (firstPass) {
+ addComponent(parent, property, currentMapper, store, entityName, firstPass);
+ }
+ } else if (propertyType instanceof ImmutableType || propertyType instanceof MutableType) {
+ // only first pass
+ if (firstPass) {
+ addSimpleProperty(parent, property, currentMapper, store, false);
+ }
+ } else if (propertyType instanceof CustomType &&
+ "org.hibernate.type.EnumType".equals(propertyType.getName())) {
+ // only first pass
+ if (firstPass) {
+ addEnumProperty(parent, property, currentMapper, store);
+ }
+ } else if (propertyType instanceof ManyToOneType) {
+ // only second pass
+ if (!firstPass) {
+ addToOne(parent, property, currentMapper, entityName);
+ }
+ } else if (propertyType instanceof OneToOneType) {
+ // only second pass
+ if (!firstPass) {
+ addOneToOneBidirectional(property, currentMapper, entityName);
+ }
+ } else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(
+ propertyType.getClass().getName())) {
+ // only first pass
+ if (firstPass) {
+ addSimpleProperty(parent, property, currentMapper, store, false);
+ }
+ } else if (propertyType instanceof CustomType &&
+ ("org.hibernate.type.PrimitiveCharacterArrayClobType".equals(propertyType.getName()) ||
+ "org.hibernate.type.StringClobType".equals(propertyType.getName()))) {
+ // only first pass
+ if (firstPass) {
+ addSimpleProperty(parent, property, currentMapper, store, false);
+ }
+ } else if ((propertyType instanceof BagType || propertyType instanceof SetType) &&
+ ((((Collection) property.getValue()).getElement() instanceof OneToMany))) {
+ // only second pass
+ if (!firstPass) {
+ addOneToManyBidirectional(property, currentMapper, entityName);
+ }
+ } else if ((propertyType instanceof BagType || propertyType instanceof SetType) &&
+ ((((Collection) property.getValue()).getElement() instanceof ManyToOne))) {
+ // only second pass
+ if (!firstPass) {
+ addOneToManyUnidirectional(property, currentMapper, entityName);
+ }
+ } else {
+ String message = "Type not supported for versioning: " + propertyType.getClass().getName() +
+ ", on entity " + entityName + ", property '" + property.getName() + "'.";
+ if (verCfg.isWarnOnUnsupportedTypes()) {
+ log.warn(message);
+ } else {
+ throw new MappingException(message);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void createJoins(PersistentClass pc, Element parent, PersistentClassVersioningData versioningData) {
+ Iterator<Join> joins = pc.getJoinIterator();
+
+ Map<Join, Element> joinElements = new HashMap<Join, Element>();
+ entitiesJoins.put(pc.getEntityName(), joinElements);
+
+ while (joins.hasNext()) {
+ Join join = joins.next();
+
+ // Determining the table name. If there is no entry in the dictionary, just constructing the table name
+ // as if it was an entity (by appending/prepending configured strings).
+ String originalTableName = join.getTable().getName();
+ String versionedTableName = versioningData.secondaryTableDictionary.get(originalTableName);
+ if (versionedTableName == null) {
+ versionedTableName = verEntCfg.getVersionsEntityName(originalTableName);
+ }
+
+ String schema = versioningData.schema;
+ if (StringTools.isEmpty(schema)) {
+ schema = join.getTable().getSchema();
+ }
+
+ String catalog = versioningData.catalog;
+ if (StringTools.isEmpty(catalog)) {
+ catalog = join.getTable().getCatalog();
+ }
+
+ Element joinElement = MetadataTools.createJoin(parent, versionedTableName, schema, catalog);
+ joinElements.put(join, joinElement);
+
+ Element joinKey = joinElement.addElement("key");
+ addColumns(joinKey, join.getKey().getColumnIterator());
+ MetadataTools.addColumn(joinKey, verEntCfg.getRevisionPropName(), null);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void addJoins(PersistentClass pc, CompositeMapperBuilder currentMapper, PropertyStoreInfo propertyStoreInfo,
+ String entityName, boolean firstPass) {
+ Iterator<Join> joins = pc.getJoinIterator();
+
+ while (joins.hasNext()) {
+ Join join = joins.next();
+ Element joinElement = entitiesJoins.get(entityName).get(join);
+
+ addProperties(joinElement, join.getPropertyIterator(), currentMapper, propertyStoreInfo, entityName,
+ firstPass);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private IdMappingData addId(PersistentClass pc) {
+ // Xml mapping which will be used for relations
+ Element rel_id_mapping = new DefaultElement("properties");
+ // Xml mapping which will be used for the primary key of the versions table
+ Element orig_id_mapping = new DefaultElement("composite-id");
+
+ Property id_prop = pc.getIdentifierProperty();
+ Component id_mapper = pc.getIdentifierMapper();
+
+ SimpleIdMapperBuilder mapper;
+ if (id_mapper != null) {
+ mapper = new MultipleIdMapper(((Component) pc.getIdentifier()).getComponentClassName());
+ addIdProperties(rel_id_mapping, (Iterator<Property>) id_mapper.getPropertyIterator(), mapper, false);
+
+ // null mapper - the mapping where already added the first time, now we only want to generate the xml
+ addIdProperties(orig_id_mapping, (Iterator<Property>) id_mapper.getPropertyIterator(), null, true);
+ } else if (id_prop.isComposite()) {
+ Component id_component = (Component) id_prop.getValue();
+
+ mapper = new EmbeddedIdMapper(id_prop.getName(), id_component.getComponentClassName());
+ addIdProperties(rel_id_mapping, (Iterator<Property>) id_component.getPropertyIterator(), mapper, false);
+
+ // null mapper - the mapping where already added the first time, now we only want to generate the xml
+ addIdProperties(orig_id_mapping, (Iterator<Property>) id_component.getPropertyIterator(), null, true);
+ } else {
+ mapper = new SingleIdMapper();
+
+ addSimpleProperty(rel_id_mapping, id_prop, mapper, ModificationStore.FULL, false);
+
+ // null mapper - the mapping where already added the first time, now we only want to generate the xml
+ addSimpleProperty(orig_id_mapping, id_prop, null, ModificationStore.FULL, true);
+ }
+
+ 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);
+
+ return new IdMappingData(mapper, orig_id_mapping, rel_id_mapping);
+ }
+
+ private void addPersisterHack(Element class_mapping) {
+ String persisterClassName;
+ if (HibernateVersion.get().startsWith("3.3")) {
+ persisterClassName = "org.jboss.envers.entity.VersionsInheritanceEntityPersisterFor33";
+ } else {
+ persisterClassName = "org.jboss.envers.entity.VersionsInheritanceEntityPersisterFor32";
+ }
+
+ class_mapping.addAttribute("persister", persisterClassName);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public Document generateFirstPass(PersistentClass pc, PersistentClassVersioningData versioningData) {
+ Document document = DocumentHelper.createDocument();
+
+ String schema = versioningData.schema;
+ if (StringTools.isEmpty(schema)) {
+ schema = pc.getTable().getSchema();
+ }
+
+ String catalog = versioningData.catalog;
+ if (StringTools.isEmpty(catalog)) {
+ catalog = pc.getTable().getCatalog();
+ }
+
+ String entityName = pc.getEntityName();
+ String versionsEntityName = verEntCfg.getVersionsEntityName(entityName);
+ String versionsTableName = verEntCfg.getVersionsTableName(entityName, pc.getTable().getName());
+
+ // Generating a mapping for the id
+ IdMappingData idMapper = addId(pc);
+
+ Element class_mapping;
+ ExtendedPropertyMapper propertyMapper;
+
+ InheritanceType inheritanceType = InheritanceType.get(pc);
+ String parentEntityName = null;
+
+ switch (inheritanceType) {
+ case NONE:
+ class_mapping = MetadataTools.createEntity(document, versionsEntityName, versionsTableName,
+ schema, catalog, pc.getDiscriminatorValue());
+ propertyMapper = new MultiPropertyMapper();
+
+ // Checking if there is a discriminator column
+ if (pc.getDiscriminator() != null) {
+ Element discriminator_element = class_mapping.addElement("discriminator");
+ addColumns(discriminator_element, pc.getDiscriminator().getColumnIterator());
+ discriminator_element.addAttribute("type", pc.getDiscriminator().getType().getName());
+
+ // If so, there is some inheritance scheme -> using the persister hack.
+ addPersisterHack(class_mapping);
+ }
+
+ // Adding the id mapping
+ 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.entity.RevisionTypeType");
+
+ break;
+ case SINGLE:
+ String extendsEntityName = verEntCfg.getVersionsEntityName(pc.getSuperclass().getEntityName());
+ class_mapping = MetadataTools.createSubclassEntity(document, versionsEntityName, versionsTableName,
+ schema, catalog, extendsEntityName, pc.getDiscriminatorValue());
+
+ addPersisterHack(class_mapping);
+
+ // The id and revision type is already mapped in the parent
+
+ // Getting the property mapper of the parent - when mapping properties, they need to be included
+ parentEntityName = pc.getSuperclass().getEntityName();
+ ExtendedPropertyMapper parentPropertyMapper = entitiesConfigurations.get(parentEntityName).getPropertyMapper();
+ propertyMapper = new SubclassPropertyMapper(new MultiPropertyMapper(), parentPropertyMapper);
+
+ break;
+ case JOINED:
+ throw new MappingException("Joined inheritance strategy not supported for versioning!");
+ case TABLE_PER_CLASS:
+ throw new MappingException("Table-per-class inheritance strategy not supported for versioning!");
+ default:
+ throw new AssertionError("Impossible enum value.");
+ }
+
+ // Mapping unjoined properties
+ addProperties(class_mapping, (Iterator<Property>) pc.getUnjoinedPropertyIterator(), propertyMapper,
+ versioningData.propertyStoreInfo, pc.getEntityName(), true);
+
+ // Creating and mapping joins (first pass)
+ createJoins(pc, class_mapping, versioningData);
+ addJoins(pc, propertyMapper, versioningData.propertyStoreInfo, pc.getEntityName(), true);
+
+ // Storing the generated configuration
+ 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) {
+ String entityName = pc.getEntityName();
+
+ CompositeMapperBuilder propertyMapper = entitiesConfigurations.get(entityName).getPropertyMapper();
+
+ // Mapping unjoined properties
+ Element parent = document.getRootElement().element("class");
+ if (parent == null) {
+ parent = document.getRootElement().element("subclass");
+ }
+
+ addProperties(parent, (Iterator<Property>) pc.getUnjoinedPropertyIterator(),
+ propertyMapper, versioningData.propertyStoreInfo, entityName, false);
+
+ // Mapping joins (second pass)
+ addJoins(pc, propertyMapper, versioningData.propertyStoreInfo, entityName, false);
+ }
+
+ public Map<String, EntityConfiguration> getEntitiesConfigurations() {
+ return entitiesConfigurations;
+ }
+}
Copied: trunk/src/main/org/jboss/envers/configuration/metadata/data (from rev 102, trunk/src/main/org/jboss/envers/metadata/data)
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/data/IdMappingData.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/data/IdMappingData.java 2008-08-14 10:19:45 UTC (rev 102)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/data/IdMappingData.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.metadata.data;
+package org.jboss.envers.configuration.metadata.data;
import org.jboss.envers.mapper.id.IdMapper;
import org.dom4j.Element;
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/data/PersistentClassVersioningData.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/data/PersistentClassVersioningData.java 2008-08-14 10:19:45 UTC (rev 102)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/data/PersistentClassVersioningData.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.metadata.data;
+package org.jboss.envers.configuration.metadata.data;
import org.jboss.envers.ModificationStore;
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/data/PropertyStoreInfo.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/data/PropertyStoreInfo.java 2008-08-14 10:19:45 UTC (rev 102)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/data/PropertyStoreInfo.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.metadata.data;
+package org.jboss.envers.configuration.metadata.data;
import org.jboss.envers.ModificationStore;
Deleted: trunk/src/main/org/jboss/envers/tools/Triple.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/Triple.java 2008-08-14 10:19:45 UTC (rev 102)
+++ trunk/src/main/org/jboss/envers/tools/Triple.java 2008-08-14 11:12:23 UTC (rev 103)
@@ -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.tools;
-
-/**
- * A triple of objects.
- * @param <T1>
- * @param <T2>
- * @param <T3>
- * @author Adam Warski (adamw(a)aster.pl)
- */
-public class Triple<T1, T2, T3> {
- private T1 obj1;
- private T2 obj2;
- private T3 obj3;
-
- public Triple(T1 obj1, T2 obj2, T3 obj3) {
- this.obj1 = obj1;
- this.obj2 = obj2;
- this.obj3 = obj3;
- }
-
- public T1 getFirst() {
- return obj1;
- }
-
- public T2 getSecond() {
- return obj2;
- }
-
- public T3 getThird() {
- return obj3;
- }
-
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof Triple)) return false;
-
- Triple triple = (Triple) o;
-
- if (obj1 != null ? !obj1.equals(triple.obj1) : triple.obj1 != null) return false;
- if (obj2 != null ? !obj2.equals(triple.obj2) : triple.obj2 != null) return false;
- if (obj3 != null ? !obj3.equals(triple.obj3) : triple.obj3 != null) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result;
- result = (obj1 != null ? obj1.hashCode() : 0);
- result = 31 * result + (obj2 != null ? obj2.hashCode() : 0);
- result = 31 * result + (obj3 != null ? obj3.hashCode() : 0);
- return result;
- }
-
- public static <T1, T2, T3> Triple<T1, T2, T3> make(T1 obj1, T2 obj2, T3 obj3) {
- return new Triple<T1, T2, T3>(obj1, obj2, obj3);
- }
-}
\ No newline at end of file
16 years, 4 months
JBoss Envers SVN: r102 - in trunk/src/main/org/jboss/envers: entity and 4 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-14 06:19:45 -0400 (Thu, 14 Aug 2008)
New Revision: 102
Modified:
trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
trunk/src/main/org/jboss/envers/mapper/MapPropertyMapper.java
trunk/src/main/org/jboss/envers/mapper/MultiPropertyMapper.java
trunk/src/main/org/jboss/envers/mapper/SinglePropertyMapper.java
trunk/src/main/org/jboss/envers/mapper/id/EmbeddedIdMapper.java
trunk/src/main/org/jboss/envers/mapper/id/SingleIdMapper.java
trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java
trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.java
trunk/src/main/org/jboss/envers/mapper/id/relation/ToOneIdMapper.java
trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java
trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java
Log:
ENVERS-37: moving reflection and log facades to tools
Modified: trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java 2008-08-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/configuration/CustomRevisionInfoGenerator.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -22,7 +22,7 @@
package org.jboss.envers.configuration;
import org.jboss.envers.RevisionListener;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.hibernate.MappingException;
import org.hibernate.property.Setter;
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -32,7 +32,7 @@
import org.jboss.envers.mapper.ExtendedPropertyMapper;
import org.jboss.envers.mapper.id.IdMapper;
import org.jboss.envers.tools.graph.GraphTopologicalSort;
-import org.jboss.envers.reflection.YReflectionManager;
+import org.jboss.envers.tools.reflection.YReflectionManager;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.XMLWriter;
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-08-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -27,9 +27,9 @@
import org.jboss.envers.RevisionEntity;
import org.jboss.envers.RevisionNumber;
import org.jboss.envers.RevisionTimestamp;
-import org.jboss.envers.reflection.YReflectionManager;
-import org.jboss.envers.reflection.YClass;
-import org.jboss.envers.reflection.YProperty;
+import org.jboss.envers.tools.reflection.YReflectionManager;
+import org.jboss.envers.tools.reflection.YClass;
+import org.jboss.envers.tools.reflection.YProperty;
import org.jboss.envers.tools.MutableBoolean;
import java.util.*;
Modified: trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -25,7 +25,7 @@
import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.mapper.id.IdMapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import java.util.Map;
import java.util.List;
Modified: trunk/src/main/org/jboss/envers/mapper/MapPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/MapPropertyMapper.java 2008-08-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/MapPropertyMapper.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -22,7 +22,7 @@
package org.jboss.envers.mapper;
import org.jboss.envers.ModificationStore;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
import org.hibernate.property.Getter;
Modified: trunk/src/main/org/jboss/envers/mapper/MultiPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/MultiPropertyMapper.java 2008-08-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/MultiPropertyMapper.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -24,7 +24,7 @@
import org.hibernate.property.Getter;
import org.hibernate.MappingException;
import org.jboss.envers.ModificationStore;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
import java.util.Map;
Modified: trunk/src/main/org/jboss/envers/mapper/SinglePropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/SinglePropertyMapper.java 2008-08-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/SinglePropertyMapper.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -22,7 +22,7 @@
package org.jboss.envers.mapper;
import org.jboss.envers.ModificationStore;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.tools.Tools;
import org.jboss.envers.exception.VersionsException;
Modified: trunk/src/main/org/jboss/envers/mapper/id/EmbeddedIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/EmbeddedIdMapper.java 2008-08-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/id/EmbeddedIdMapper.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -25,7 +25,7 @@
import org.hibernate.property.Setter;
import org.hibernate.util.ReflectHelper;
import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import java.util.Map;
import java.util.Set;
Modified: trunk/src/main/org/jboss/envers/mapper/id/SingleIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/SingleIdMapper.java 2008-08-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/id/SingleIdMapper.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -22,7 +22,7 @@
package org.jboss.envers.mapper.id;
import org.jboss.envers.ModificationStore;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.exception.VersionsException;
import org.hibernate.property.Setter;
import org.hibernate.property.Getter;
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-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/id/relation/OneToManyIdMapper.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -27,7 +27,7 @@
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.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.hibernate.property.Setter;
import org.hibernate.property.Getter;
Modified: trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.java 2008-08-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/id/relation/OneToOneIdMapper.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -23,7 +23,7 @@
import org.jboss.envers.mapper.PropertyMapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.reflection.ReflectionTools;
+import org.jboss.envers.tools.reflection.ReflectionTools;
import org.hibernate.property.Setter;
import java.util.Map;
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-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/mapper/id/relation/ToOneIdMapper.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -24,7 +24,7 @@
import org.jboss.envers.mapper.PropertyMapper;
import org.jboss.envers.mapper.id.IdMapper;
import org.jboss.envers.tools.Tools;
-import org.jboss.envers.reflection.ReflectionTools;
+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;
Modified: trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java 2008-08-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/metadata/AnnotationsMetadataReader.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -21,9 +21,9 @@
*/
package org.jboss.envers.metadata;
-import org.jboss.envers.reflection.YClass;
-import org.jboss.envers.reflection.YProperty;
-import org.jboss.envers.reflection.YReflectionManager;
+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.metadata.data.PersistentClassVersioningData;
import org.jboss.envers.Versioned;
import org.jboss.envers.VersionsTable;
Modified: trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java 2008-08-14 10:11:22 UTC (rev 101)
+++ trunk/src/main/org/jboss/envers/metadata/VersionsMetadataGenerator.java 2008-08-14 10:19:45 UTC (rev 102)
@@ -42,8 +42,8 @@
import org.jboss.envers.tools.Tools;
import org.jboss.envers.tools.HibernateVersion;
import org.jboss.envers.ModificationStore;
-import org.jboss.envers.log.YLog;
-import org.jboss.envers.log.YLogManager;
+import org.jboss.envers.tools.log.YLog;
+import org.jboss.envers.tools.log.YLogManager;
import org.jboss.envers.metadata.data.IdMappingData;
import org.jboss.envers.metadata.data.PersistentClassVersioningData;
import org.jboss.envers.metadata.data.PropertyStoreInfo;
@@ -223,7 +223,7 @@
}
@SuppressWarnings({"unchecked"})
- private void addOneToOne(Property property, CompositeMapperBuilder mapper, String entityName) {
+ private void addOneToOneBidirectional(Property property, CompositeMapperBuilder mapper, String entityName) {
OneToOne propertyValue = (OneToOne) property.getValue();
String owningReferencePropertyName = propertyValue.getReferencedPropertyName(); // mappedBy
@@ -273,7 +273,7 @@
}
@SuppressWarnings({"unchecked"})
- private void addOneToMany(Property property, CompositeMapperBuilder mapper, String entityName) {
+ private void addOneToManyBidirectional(Property property, CompositeMapperBuilder mapper, String entityName) {
Collection propertyValue = (Collection) property.getValue();
String owningReferencePropertyName = getMappedBy(propertyValue);
@@ -304,6 +304,35 @@
propertyName));
}
+ @SuppressWarnings({"unchecked"})
+ private void addOneToManyUnidirectional(Property property, CompositeMapperBuilder mapper, String entityName) {
+ Collection propertyValue = (Collection) property.getValue();
+ ManyToOne mto = (ManyToOne) propertyValue.getElement();
+
+ String referencedEntityName = mto.getReferencedEntityName();
+
+ EntityConfiguration configuration = entitiesConfigurations.get(entityName);
+ if (configuration == null) {
+ throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
+ }
+
+ EntityConfiguration referencedConfiguration = entitiesConfigurations.get(referencedEntityName);
+ if (referencedConfiguration == null) {
+ throw new MappingException("A versioned relation to a non-versioned entity " + referencedEntityName + "!");
+ }
+
+ IdMappingData referencingIdMapping = configuration.getIdMappingData();
+ IdMappingData referencedIdMapping = referencedConfiguration.getIdMappingData();
+
+ // Name of the entity that will be used to store the relation between the two entities.
+ String middleEntityName = entityName + "_" + referencedEntityName;
+
+ MetadataTools.createEntity(null, middleEntityName, mto.getTable().getName(), mto.getTable().getSchema(),
+ mto.getTable().getCatalog(), null);
+
+ // TODO: ???
+ }
+
private ModificationStore getStoreForProperty(Property property, PropertyStoreInfo propertyStoreInfo) {
/*
* Checks if a property is versioned, which is when:
@@ -369,7 +398,7 @@
} else if (propertyType instanceof OneToOneType) {
// only second pass
if (!firstPass) {
- addOneToOne(property, currentMapper, entityName);
+ addOneToOneBidirectional(property, currentMapper, entityName);
}
} else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(
propertyType.getClass().getName())) {
@@ -388,8 +417,14 @@
((((Collection) property.getValue()).getElement() instanceof OneToMany))) {
// only second pass
if (!firstPass) {
- addOneToMany(property, currentMapper, entityName);
+ addOneToManyBidirectional(property, currentMapper, entityName);
}
+ } else if ((propertyType instanceof BagType || propertyType instanceof SetType) &&
+ ((((Collection) property.getValue()).getElement() instanceof ManyToOne))) {
+ // only second pass
+ if (!firstPass) {
+ addOneToManyUnidirectional(property, currentMapper, entityName);
+ }
} else {
String message = "Type not supported for versioning: " + propertyType.getClass().getName() +
", on entity " + entityName + ", property '" + property.getName() + "'.";
@@ -457,9 +492,9 @@
@SuppressWarnings({"unchecked"})
private IdMappingData addId(PersistentClass pc) {
- // Mapping which will be used for relations
+ // Xml mapping which will be used for relations
Element rel_id_mapping = new DefaultElement("properties");
- // Mapping which will be used for the primary key of the versions table
+ // Xml mapping which will be used for the primary key of the versions table
Element orig_id_mapping = new DefaultElement("composite-id");
Property id_prop = pc.getIdentifierProperty();
@@ -491,7 +526,6 @@
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);
16 years, 4 months
JBoss Envers SVN: r101 - in trunk/src/main/org/jboss/envers: tools and 2 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-14 06:11:22 -0400 (Thu, 14 Aug 2008)
New Revision: 101
Added:
trunk/src/main/org/jboss/envers/tools/log/
trunk/src/main/org/jboss/envers/tools/reflection/
Removed:
trunk/src/main/org/jboss/envers/log/
trunk/src/main/org/jboss/envers/reflection/
Modified:
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/ReflectionTools.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 reflection and log facades to tools
Copied: trunk/src/main/org/jboss/envers/tools/log (from rev 95, trunk/src/main/org/jboss/envers/log)
Modified: trunk/src/main/org/jboss/envers/tools/log/YLog.java
===================================================================
--- trunk/src/main/org/jboss/envers/log/YLog.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/tools/log/YLog.java 2008-08-14 10:11:22 UTC (rev 101)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.log;
+package org.jboss.envers.tools.log;
import org.jboss.envers.exception.VersionsException;
Modified: trunk/src/main/org/jboss/envers/tools/log/YLogManager.java
===================================================================
--- trunk/src/main/org/jboss/envers/log/YLogManager.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/tools/log/YLogManager.java 2008-08-14 10:11:22 UTC (rev 101)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.log;
+package org.jboss.envers.tools.log;
import org.jboss.envers.exception.VersionsException;
Copied: trunk/src/main/org/jboss/envers/tools/reflection (from rev 95, trunk/src/main/org/jboss/envers/reflection)
Modified: trunk/src/main/org/jboss/envers/tools/reflection/ReflectionTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/reflection/ReflectionTools.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/tools/reflection/ReflectionTools.java 2008-08-14 10:11:22 UTC (rev 101)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.reflection;
+package org.jboss.envers.tools.reflection;
import org.hibernate.property.PropertyAccessor;
import org.hibernate.property.BasicPropertyAccessor;
Modified: trunk/src/main/org/jboss/envers/tools/reflection/YClass.java
===================================================================
--- trunk/src/main/org/jboss/envers/reflection/YClass.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/tools/reflection/YClass.java 2008-08-14 10:11:22 UTC (rev 101)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.reflection;
+package org.jboss.envers.tools.reflection;
import org.jboss.envers.exception.VersionsException;
Modified: trunk/src/main/org/jboss/envers/tools/reflection/YMethodsAndClasses.java
===================================================================
--- trunk/src/main/org/jboss/envers/reflection/YMethodsAndClasses.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/tools/reflection/YMethodsAndClasses.java 2008-08-14 10:11:22 UTC (rev 101)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.reflection;
+package org.jboss.envers.tools.reflection;
import org.jboss.envers.exception.VersionsException;
Modified: trunk/src/main/org/jboss/envers/tools/reflection/YProperty.java
===================================================================
--- trunk/src/main/org/jboss/envers/reflection/YProperty.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/tools/reflection/YProperty.java 2008-08-14 10:11:22 UTC (rev 101)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.reflection;
+package org.jboss.envers.tools.reflection;
import org.jboss.envers.exception.VersionsException;
Modified: trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java
===================================================================
--- trunk/src/main/org/jboss/envers/reflection/YReflectionManager.java 2008-07-16 09:40:37 UTC (rev 95)
+++ trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java 2008-08-14 10:11:22 UTC (rev 101)
@@ -19,7 +19,7 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.reflection;
+package org.jboss.envers.tools.reflection;
import org.hibernate.cfg.Configuration;
import org.jboss.envers.exception.VersionsException;
16 years, 4 months
JBoss Envers SVN: r100 - in trunk/src: main/org/jboss/envers/query and 4 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-14 06:02:22 -0400 (Thu, 14 Aug 2008)
New Revision: 100
Modified:
trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java
trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
trunk/src/test/org/jboss/envers/test/integration/query/MaximalizePropertyQuery.java
trunk/src/test/org/jboss/envers/test/integration/query/RevisionConstraintQuery.java
trunk/src/test/org/jboss/envers/test/integration/query/SimpleQuery.java
trunk/src/test/org/jboss/envers/test/working/WorkingEntity2.java
trunk/src/test/org/jboss/envers/test/working/WorkingMain.java
Log:
ENVERS-36: an additonal parametr for the revisions of entity query, stating if deleted entities should be selected, and tests
Modified: trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-14 09:36:38 UTC (rev 99)
+++ trunk/src/main/org/jboss/envers/entity/EntityInstantiator.java 2008-08-14 10:02:22 UTC (rev 100)
@@ -21,7 +21,6 @@
*/
package org.jboss.envers.entity;
-import org.jboss.envers.RevisionType;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.mapper.id.IdMapper;
@@ -56,11 +55,6 @@
if (versionsEntity == null) {
return null;
}
-
- if (RevisionType.DEL.equals(versionsEntity.get(verCfg.getEntitiesCfg().getRevisionTypePropName()))) {
- // This means that at the given revision the entity didn't yet exist.
- return null;
- }
// The $type$ property holds the name of the (versions) entity
String type = verCfg.getEntityNameForVersionsEntityName((String) versionsEntity.get("$type$"));
Modified: trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-08-14 09:36:38 UTC (rev 99)
+++ trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-08-14 10:02:22 UTC (rev 100)
@@ -59,12 +59,14 @@
* @param c Class of the entities for which to query.
* @param selectEntitiesOnly If true, instead of a list of three-element arrays, a list of entites will be
* returned as a result of executing this query.
+ * @param selectDeletedEntities If true, also revisions where entities where deleted will be returned. The
+ * entities will have revision type "delete", and contain no data (all fields null), except for the id field.
* @return A query for revisions at which instances of the given entity were modified, to which
* conditions can be added (for example - a specific id of an entity of class <code>c</code>), and which
* can then be executed. The results of the query will be sorted in ascending order by the revision number,
* unless an order or projection is added.
*/
- public VersionsQuery forRevisionsOfEntity(Class<?> c, boolean selectEntitiesOnly) {
- return new RevisionsOfEntityQuery(versionsReaderImplementor, c, selectEntitiesOnly);
+ public VersionsQuery forRevisionsOfEntity(Class<?> c, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
+ return new RevisionsOfEntityQuery(versionsReaderImplementor, c, selectEntitiesOnly,selectDeletedEntities);
}
}
Modified: trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-14 09:36:38 UTC (rev 99)
+++ trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-14 10:02:22 UTC (rev 100)
@@ -26,6 +26,7 @@
import org.jboss.envers.query.criteria.VersionsCriterion;
import org.jboss.envers.RevisionType;
import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Property;
import java.util.List;
import java.util.ArrayList;
@@ -35,12 +36,15 @@
* @author Adam Warski (adam at warski dot org)
*/
public class RevisionsOfEntityQuery extends AbstractVersionsQuery {
- private boolean selectEntitiesOnly;
+ private final boolean selectEntitiesOnly;
+ private final boolean selectDeletedEntities;
- public RevisionsOfEntityQuery(VersionsReaderImplementor versionsReader, Class<?> cls, boolean selectEntitiesOnly) {
+ public RevisionsOfEntityQuery(VersionsReaderImplementor versionsReader, Class<?> cls, boolean selectEntitiesOnly,
+ boolean selectDeletedEntities) {
super(versionsReader, cls);
this.selectEntitiesOnly = selectEntitiesOnly;
+ this.selectDeletedEntities = selectDeletedEntities;
}
@SuppressWarnings({"unchecked"})
@@ -48,11 +52,17 @@
/*
The query that should be executed in the versions table:
SELECT e (unless another projection is specified) FROM ent_ver e WHERE
+ e.revision_type != DEL AND (if selectDeletedEntities == false)
(all specified conditions, transformed, on the "e" entity)
ORDER BY e.revision ASC (unless another order is specified)
*/
String revisionPropertyPath = versionsReader.getEntitiesCfg().getRevisionPropPath();
+ if (!selectDeletedEntities) {
+ // e.revision_type != DEL AND
+ versionsCriteria.add(Property.forName(versionsReader.getEntitiesCfg().getRevisionTypePropName()).ne(RevisionType.DEL));
+ }
+
// all specified conditions, transformed
for (VersionsCriterion criterion : criterions) {
versionsCriteria.add(criterion.toVersionsCriterion(entityName, versionsReader));
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-14 09:36:38 UTC (rev 99)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-14 10:02:22 UTC (rev 100)
@@ -154,7 +154,7 @@
throw new NotVersionedException(entityName + " is not versioned!");
}
- return createQuery().forRevisionsOfEntity(cls, false)
+ return createQuery().forRevisionsOfEntity(cls, false, true)
.setProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.idEq(primaryKey))
.getResultList();
Modified: trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java 2008-08-14 09:36:38 UTC (rev 99)
+++ trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java 2008-08-14 10:02:22 UTC (rev 100)
@@ -66,4 +66,18 @@
assert (Integer) getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2)
.setProjection(Projections.count("originalId.id")).getResultList().get(0) == 1;
}
+
+ @Test
+ public void testRevisionsOfEntityWithoutDelete() {
+ List result = getVersionsReader().createQuery()
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, false)
+ .add(VersionsRestrictions.idEq(id2))
+ .getResultList();
+
+ assert result.size() == 1;
+
+ assert ((Object []) result.get(0))[0].equals(new StrIntTestEntity("b", 11, id2));
+ assert ((Object []) result.get(0))[1].equals(1);
+ assert ((Object []) result.get(0))[2].equals(RevisionType.ADD);
+ }
}
Modified: trunk/src/test/org/jboss/envers/test/integration/query/MaximalizePropertyQuery.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/MaximalizePropertyQuery.java 2008-08-14 09:36:38 UTC (rev 99)
+++ trunk/src/test/org/jboss/envers/test/integration/query/MaximalizePropertyQuery.java 2008-08-14 10:02:22 UTC (rev 100)
@@ -78,7 +78,7 @@
@Test
public void testMaximizeWithIdEq() {
List revs_id1 = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.maximizeProperty("number")
.add(VersionsRestrictions.idEq(id2)))
@@ -90,7 +90,7 @@
@Test
public void testMinimizeWithPropertyEq() {
List result = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.minimizeProperty("number")
.add(VersionsRestrictions.eq("str1", "a")))
Modified: trunk/src/test/org/jboss/envers/test/integration/query/RevisionConstraintQuery.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/RevisionConstraintQuery.java 2008-08-14 09:36:38 UTC (rev 99)
+++ trunk/src/test/org/jboss/envers/test/integration/query/RevisionConstraintQuery.java 2008-08-14 10:02:22 UTC (rev 100)
@@ -78,7 +78,7 @@
@Test
public void testRevisionsLtQuery() {
List result = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(VersionsProjections.distinct(RevisionProperty.revisionNumber()))
.add(RevisionProperty.lt(3))
.getResultList();
@@ -89,7 +89,7 @@
@Test
public void testRevisionsGeQuery() {
List result = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(VersionsProjections.distinct(RevisionProperty.revisionNumber()))
.add(RevisionProperty.ge(2))
.getResultList();
@@ -100,7 +100,7 @@
@Test
public void testRevisionsLeWithPropertyQuery() {
List result = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(RevisionProperty.revisionNumber())
.add(RevisionProperty.le(3))
.add(VersionsRestrictions.eq("str1", "a"))
@@ -112,7 +112,7 @@
@Test
public void testRevisionsGtWithPropertyQuery() {
List result = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(RevisionProperty.revisionNumber())
.add(RevisionProperty.gt(1))
.add(VersionsRestrictions.lt("number", 10))
@@ -124,7 +124,7 @@
@Test
public void testRevisionProjectionQuery() {
Object[] result = (Object[]) getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(
VersionsProjections.projectionList()
.add(RevisionProperty.max())
@@ -141,7 +141,7 @@
@Test
public void testRevisionOrderQuery() {
List result = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.idEq(id1))
.addOrder(RevisionProperty.desc())
@@ -154,7 +154,7 @@
public void testRevisionCountQuery() {
// The query shouldn't be ordered as always, otherwise - we get an exception.
Object result = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(RevisionProperty.count())
.add(VersionsRestrictions.idEq(id1))
.getSingleResult();
Modified: trunk/src/test/org/jboss/envers/test/integration/query/SimpleQuery.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/SimpleQuery.java 2008-08-14 09:36:38 UTC (rev 99)
+++ trunk/src/test/org/jboss/envers/test/integration/query/SimpleQuery.java 2008-08-14 10:02:22 UTC (rev 100)
@@ -141,21 +141,21 @@
@Test
public void testRevisionsPropertyEqQuery() {
List revs_id1 = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.le("str1", "a"))
.add(VersionsRestrictions.idEq(id1))
.getResultList();
List revs_id2 = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.le("str1", "a"))
.add(VersionsRestrictions.idEq(id2))
.getResultList();
List revs_id3 = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.le("str1", "a"))
.add(VersionsRestrictions.idEq(id3))
@@ -169,10 +169,12 @@
@Test
public void testSelectEntitiesQuery() {
List result = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, true)
+ .forRevisionsOfEntity(StrIntTestEntity.class, true, false)
.add(VersionsRestrictions.idEq(id1))
.getResultList();
+ assert result.size() == 2;
+
assert result.get(0).equals(new StrIntTestEntity("a", 10, id1));
assert result.get(1).equals(new StrIntTestEntity("c", 10, id1));
}
@@ -180,13 +182,15 @@
@Test
public void testSelectEntitiesAndRevisionsQuery() {
List result = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.add(VersionsRestrictions.idEq(id1))
.getResultList();
+ assert result.size() == 3;
+
assert ((Object []) result.get(0))[0].equals(new StrIntTestEntity("a", 10, id1));
assert ((Object []) result.get(1))[0].equals(new StrIntTestEntity("c", 10, id1));
- assert ((Object []) result.get(2))[0] == null;
+ assert ((Object []) result.get(2))[0].equals(new StrIntTestEntity(null, null, id1));
assert ((Object []) result.get(0))[1].equals(1);
assert ((Object []) result.get(1))[1].equals(2);
@@ -200,11 +204,13 @@
@Test
public void testSelectRevisionTypeQuery() {
List result = getVersionsReader().createQuery()
- .forRevisionsOfEntity(StrIntTestEntity.class, false)
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
.setProjection(RevisionTypeProperty.revisionType())
.add(VersionsRestrictions.idEq(id1))
.getResultList();
+ assert result.size() == 3;
+
assert result.get(0).equals(RevisionType.ADD);
assert result.get(1).equals(RevisionType.MOD);
assert result.get(2).equals(RevisionType.DEL);
Modified: trunk/src/test/org/jboss/envers/test/working/WorkingEntity2.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/working/WorkingEntity2.java 2008-08-14 09:36:38 UTC (rev 99)
+++ trunk/src/test/org/jboss/envers/test/working/WorkingEntity2.java 2008-08-14 10:02:22 UTC (rev 100)
@@ -5,6 +5,7 @@
import javax.persistence.*;
import java.util.Set;
+import java.util.List;
/**
* @author Adam Warski (adam at warski dot org)
@@ -21,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-14 09:36:38 UTC (rev 99)
+++ trunk/src/test/org/jboss/envers/test/working/WorkingMain.java 2008-08-14 10:02:22 UTC (rev 100)
@@ -7,6 +7,7 @@
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
+import org.hibernate.criterion.Projections;
import org.jboss.envers.VersionsReader;
import org.jboss.envers.VersionsReaderFactory;
import org.jboss.envers.test.entities.ids.EmbId;
@@ -16,6 +17,8 @@
import org.jboss.envers.test.integration.inheritance.single.relation.ParentIngEntity;
import org.jboss.envers.test.integration.inheritance.single.relation.ChildIngEntity;
import org.jboss.envers.query.criteria.VersionsCriterion;
+import org.jboss.envers.query.VersionsRestrictions;
+import org.jboss.envers.query.VersionsProjections;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -57,9 +60,43 @@
// 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);
- entityManager.getTransaction().commit();
+ WorkingEntity1 we1_2 = new WorkingEntity1("b2", "c2");
+ we1_2.setWe2(we2);
+ entityManager.persist(we1_2);
+
+ entityManager.getTransaction().commit();
+
+ // Rev 2
+ entityManager.getTransaction().begin();
+
+ we1 = entityManager.find(WorkingEntity1.class, we1.getId1());
+ entityManager.remove(we1);
+
+ entityManager.getTransaction().commit();
+
+ // Rev 3
+ entityManager.getTransaction().begin();
+
+ VersionsReader vr = VersionsReaderFactory.get(entityManager);
+
+ 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());
+
+ 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());
+
+ entityManager.getTransaction().commit();
}
}
16 years, 4 months
JBoss Envers SVN: r99 - trunk/src/test/org/jboss/envers/test/integration/query.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-14 05:36:38 -0400 (Thu, 14 Aug 2008)
New Revision: 99
Added:
trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
Log:
ENVERS-35: test
Added: trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java 2008-08-14 09:36:38 UTC (rev 99)
@@ -0,0 +1,69 @@
+package org.jboss.envers.test.integration.query;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.StrIntTestEntity;
+import org.jboss.envers.test.tools.TestTools;
+import org.jboss.envers.query.VersionsRestrictions;
+import org.jboss.envers.query.RevisionProperty;
+import org.jboss.envers.query.RevisionTypeProperty;
+import org.jboss.envers.RevisionType;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.criterion.Projections;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.List;
+import java.util.HashSet;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class DeletedEntities extends AbstractEntityTest {
+ private Integer id1;
+ private Integer id2;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(StrIntTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ // Revision 1
+ EntityManager em = getEntityManager();
+ em.getTransaction().begin();
+
+ StrIntTestEntity site1 = new StrIntTestEntity("a", 10);
+ StrIntTestEntity site2 = new StrIntTestEntity("b", 11);
+
+ em.persist(site1);
+ em.persist(site2);
+
+ id1 = site1.getId();
+ id2 = site2.getId();
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ site2 = em.find(StrIntTestEntity.class, id2);
+ em.remove(site2);
+
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testProjectionsInEntitiesAtRevision() {
+ assert getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 1)
+ .getResultList().size() == 2;
+ assert getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2)
+ .getResultList().size() == 1;
+
+ assert (Integer) getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 1)
+ .setProjection(Projections.count("originalId.id")).getResultList().get(0) == 2;
+ assert (Integer) getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2)
+ .setProjection(Projections.count("originalId.id")).getResultList().get(0) == 1;
+ }
+}
16 years, 4 months
JBoss Envers SVN: r98 - trunk/src/main/org/jboss/envers/query/impl.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-08-14 05:12:11 -0400 (Thu, 14 Aug 2008)
New Revision: 98
Modified:
trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
Log:
ENVERS-35: only non-deleted entities are selected
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-07-29 08:44:59 UTC (rev 97)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-14 09:12:11 UTC (rev 98)
@@ -23,6 +23,7 @@
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.query.criteria.VersionsCriterion;
+import org.jboss.envers.RevisionType;
import org.hibernate.criterion.*;
import java.util.List;
@@ -45,6 +46,7 @@
The query that should be executed in the versions table:
SELECT e FROM ent_ver e WHERE
(all specified conditions, transformed, on the "e" entity) AND
+ e.revision_type != DEL AND
e.revision = (SELECT max(e2.revision) FROM ent_ver e2 WHERE
e2.revision <= :revision AND e2.originalId.id = e.originalId.id)
*/
@@ -62,6 +64,8 @@
maxRevCriteria.add(versionsReader.getVerCfg().getIdMapper(entityName).getIdsEqualCriterion(
"e." + originalIdPropertyName, "e2." + originalIdPropertyName));
+ // e.revision_type != DEL AND
+ versionsCriteria.add(Property.forName(versionsReader.getEntitiesCfg().getRevisionTypePropName()).ne(RevisionType.DEL));
// e.revision = (SELECT max(...) ...)
versionsCriteria.add(Property.forName(revisionPropertyPath).eq(maxRevCriteria));
// all specified conditions, transformed
16 years, 4 months