Author: adamw
Date: 2008-08-22 12:24:06 -0400 (Fri, 22 Aug 2008)
New Revision: 124
Added:
trunk/src/main/org/jboss/envers/entities/mapper/relation/DetachedRelationQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyAttachedMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneNotOwningIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyAttachedInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyDetachedInitializor.java
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/ListRefCollEntity.java
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/ids/
trunk/src/test/org/jboss/envers/test/integration/naming/DetachedNamingTestEntity.java
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedList.java
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSet.java
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSetWithEmbId.java
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSetWithMulId.java
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DataChangesNotOwnedSet.java
Removed:
trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSet.java
trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/
Modified:
trunk/resources/test/testng.xml
trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
trunk/src/test/org/jboss/envers/test/entities/manytomany/SetOwnedEntity.java
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/SetRefCollEntity.java
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/ids/SetRefCollEntityEmbId.java
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/ids/SetRefCollEntityMulId.java
trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java
trunk/src/test/org/jboss/envers/test/working/WorkingEntity1.java
trunk/src/test/org/jboss/envers/test/working/WorkingMain.java
Log:
ENVERS-24: renaming
Modified: trunk/resources/test/testng.xml
===================================================================
--- trunk/resources/test/testng.xml 2008-08-22 15:22:20 UTC (rev 123)
+++ trunk/resources/test/testng.xml 2008-08-22 16:24:06 UTC (rev 124)
@@ -11,10 +11,12 @@
<package
name="org.jboss.envers.test.integration.inheritance.single" />
<package
name="org.jboss.envers.test.integration.inheritance.single.childrelation" />
<package
name="org.jboss.envers.test.integration.inheritance.single.relation" />
+ <package name="org.jboss.envers.test.integration.manytomany"
/>
+ <package
name="org.jboss.envers.test.integration.manytomany.unidirectional" />
<package name="org.jboss.envers.test.integration.naming" />
<package name="org.jboss.envers.test.integration.naming.ids"
/>
<package name="org.jboss.envers.test.integration.onetomany"
/>
- <package
name="org.jboss.envers.test.integration.onetomany.unidirectional" />
+ <package
name="org.jboss.envers.test.integration.onetomany.detached" />
<package
name="org.jboss.envers.test.integration.onetoone.bidirectional" />
<package
name="org.jboss.envers.test.integration.onetoone.bidirectional.ids" />
<package
name="org.jboss.envers.test.integration.onetoone.unidirectional" />
Modified: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-08-22
15:22:20 UTC (rev 123)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -75,7 +75,7 @@
for (Document additionalMapping : mappingData.getAdditionalMappings()) {
cfg.addDocument(writer.write(additionalMapping));
- writeDocument(additionalMapping);
+ //writeDocument(additionalMapping);
}
} catch (DocumentException e) {
throw new MappingException(e);
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-22
15:22:20 UTC (rev 123)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -36,9 +36,9 @@
import org.jboss.envers.entities.mapper.*;
import org.jboss.envers.entities.mapper.id.*;
import org.jboss.envers.entities.mapper.relation.ToOneIdMapper;
-import org.jboss.envers.entities.mapper.relation.OneToOneIdMapper;
-import org.jboss.envers.entities.mapper.relation.OneToManyBidirectionalMapper;
-import org.jboss.envers.entities.mapper.relation.OneToManyUnidirectionalMapper;
+import org.jboss.envers.entities.mapper.relation.OneToOneNotOwningIdMapper;
+import org.jboss.envers.entities.mapper.relation.OneToManyAttachedMapper;
+import org.jboss.envers.entities.mapper.relation.OneToManyDetachedMapper;
import org.jboss.envers.tools.StringTools;
import org.jboss.envers.tools.Tools;
import org.jboss.envers.tools.HibernateVersion;
@@ -240,7 +240,7 @@
}
@SuppressWarnings({"unchecked"})
- private void addOneToOneBidirectional(Property property, CompositeMapperBuilder
mapper, String entityName) {
+ private void addOneToOneNotOwning(Property property, CompositeMapperBuilder mapper,
String entityName) {
OneToOne propertyValue = (OneToOne) property.getValue();
String owningReferencePropertyName = propertyValue.getReferencedPropertyName();
// mappedBy
@@ -264,11 +264,11 @@
IdMapper ownedIdMapper =
ownedIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
// Storing information about this relation
- entitiesConfigurations.get(entityName).addOneToOneRelation(propertyName,
owningReferencePropertyName,
+ entitiesConfigurations.get(entityName).addOneToOneNotOwningRelation(propertyName,
owningReferencePropertyName,
referencedEntityName, ownedIdMapper);
// Adding mapper for the id
- mapper.addComposite(propertyName, new
OneToOneIdMapper(owningReferencePropertyName,
+ mapper.addComposite(propertyName, new
OneToOneNotOwningIdMapper(owningReferencePropertyName,
referencedEntityName, propertyName));
}
@@ -290,7 +290,7 @@
}
@SuppressWarnings({"unchecked"})
- private void addOneToManyBidirectional(Property property, CompositeMapperBuilder
mapper, String entityName) {
+ private void addOneToManyAttached(Property property, CompositeMapperBuilder mapper,
String entityName) {
Collection propertyValue = (Collection) property.getValue();
String owningReferencePropertyName = getMappedBy(propertyValue);
@@ -313,16 +313,16 @@
IdMapper ownedIdMapper =
referencingIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
// Storing information about this relation
- entitiesConfigurations.get(entityName).addOneToManyRelation(propertyName,
owningReferencePropertyName,
+ entitiesConfigurations.get(entityName).addOneToManyAttachedRelation(propertyName,
owningReferencePropertyName,
owningEntityName, ownedIdMapper);
// Adding mapper for the id
- mapper.addComposite(propertyName, new
OneToManyBidirectionalMapper(owningReferencePropertyName, owningEntityName,
+ mapper.addComposite(propertyName, new
OneToManyAttachedMapper(owningReferencePropertyName, owningEntityName,
propertyName));
}
@SuppressWarnings({"unchecked"})
- private void addOneToManyUnidirectional(Property property, CompositeMapperBuilder
mapper, String entityName,
+ private void addOneToManyDetached(Property property, CompositeMapperBuilder mapper,
String entityName,
EntityMappingData mappingData) {
Collection propertyValue = (Collection) property.getValue();
ManyToOne mto = (ManyToOne) propertyValue.getElement();
@@ -375,8 +375,12 @@
addRevisionNumber(middleEntityId);
addRevisionType(middleEntity);
+ // TODO storing information about this relation
+
//entitiesConfigurations.get(entityName).addOneToManyAttachedRelation(propertyName,
owningReferencePropertyName,
+ // owningEntityName, ownedIdMapper);
+
// Adding the property mapper
- mapper.addComposite(property.getName(), new
OneToManyUnidirectionalMapper(verEntCfg, entityName,
+ mapper.addComposite(property.getName(), new OneToManyDetachedMapper(verEntCfg,
entityName,
referencedEntityName, property.getName(),
verEntCfg.getVersionsEntityName(referencedEntityName),
versionsMiddleEntityName,
referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
referencedIdMapping.getIdMapper().prefixMappedProperties(referencedPrefix),
@@ -385,6 +389,11 @@
// TODO: ???
}
+ private void addManyToManyNotOwning(Property property, CompositeMapperBuilder mapper,
String entityName,
+ EntityMappingData mappingData) {
+ System.out.println("XXX");
+ }
+
private ModificationStore getStoreForProperty(Property property, PropertyStoreInfo
propertyStoreInfo,
List<String>
unversionedProperties) {
/*
@@ -458,7 +467,7 @@
} else if (propertyType instanceof OneToOneType) {
// only second pass
if (!firstPass) {
- addOneToOneBidirectional(property, currentMapper,
entityName);
+ addOneToOneNotOwning(property, currentMapper, entityName);
}
} else if
("org.hibernate.type.PrimitiveByteArrayBlobType".equals(
propertyType.getClass().getName())) {
@@ -477,14 +486,22 @@
((((Collection) property.getValue()).getElement() instanceof
OneToMany))) {
// only second pass
if (!firstPass) {
- addOneToManyBidirectional(property, currentMapper,
entityName);
+ addOneToManyAttached(property, currentMapper, entityName);
}
} else if ((propertyType instanceof BagType || propertyType
instanceof SetType) &&
- ((((Collection) property.getValue()).getElement() instanceof
ManyToOne))) {
+ ((((Collection) property.getValue()).getElement() instanceof
ManyToOne)) &&
+ !((Collection) property.getValue()).isInverse()) {
// only second pass
if (!firstPass) {
- addOneToManyUnidirectional(property, currentMapper,
entityName, mappingData);
+ addOneToManyDetached(property, currentMapper, entityName,
mappingData);
}
+ } else if ((propertyType instanceof BagType || propertyType
instanceof SetType) &&
+ ((((Collection) property.getValue()).getElement() instanceof
ManyToOne)) &&
+ ((Collection) property.getValue()).isInverse()) {
+ // only second pass
+ if (!firstPass) {
+ addManyToManyNotOwning(property, currentMapper, entityName,
mappingData);
+ }
} else {
String message = "Type not supported for versioning: "
+ propertyType.getClass().getName() +
", on entity " + entityName + ", property
'" + property.getName() + "'.";
Modified: trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-08-22 15:22:20
UTC (rev 123)
+++ trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-08-22 16:24:06
UTC (rev 124)
@@ -55,13 +55,13 @@
toEntityName, null, idMapper));
}
- public void addOneToOneRelation(String fromPropertyName, String mappedByPropertyName,
String toEntityName,
+ public void addOneToOneNotOwningRelation(String fromPropertyName, String
mappedByPropertyName, String toEntityName,
IdMapper idMapper) {
relations.put(fromPropertyName, new RelationDescription(fromPropertyName,
RelationType.ONE_TO_ONE,
toEntityName, mappedByPropertyName, idMapper));
}
- public void addOneToManyRelation(String fromPropertyName, String
mappedByPropertyName, String toEntityName,
+ public void addOneToManyAttachedRelation(String fromPropertyName, String
mappedByPropertyName, String toEntityName,
IdMapper idMapper) {
relations.put(fromPropertyName, new RelationDescription(fromPropertyName,
RelationType.ONE_TO_MANY,
toEntityName, mappedByPropertyName, idMapper));
Copied:
trunk/src/main/org/jboss/envers/entities/mapper/relation/DetachedRelationQueryGenerator.java
(from rev 117,
trunk/src/main/org/jboss/envers/entities/mapper/relation/UnidirectionalRelationQueryGenerator.java)
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/DetachedRelationQueryGenerator.java
(rev 0)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/DetachedRelationQueryGenerator.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,93 @@
+package org.jboss.envers.entities.mapper.relation;
+
+import org.jboss.envers.entities.mapper.id.QueryParameterData;
+import org.jboss.envers.entities.mapper.id.IdMapper;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.RevisionType;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.hibernate.Query;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class DetachedRelationQueryGenerator {
+ private final String queryString;
+ private final IdMapper referencingMiddleIdMapper;
+
+ public DetachedRelationQueryGenerator(VersionsEntitiesConfiguration verEntCfg,
+ String versionsReferencedEntityName, String
versionsMiddleEntityName,
+ IdMapper referencingMiddleIdMapper, IdMapper
referencedMiddleIdMapper,
+ IdMapper referencedIdMapper) {
+ this.referencingMiddleIdMapper = referencingMiddleIdMapper;
+
+ /*
+ * The query that we need to create:
+ * SELECT e FROM versionsReferencedEntity e, middleEntity ee
+ * WHERE
+ * (selecting e entities at revision :revision)
+ * e.revision = (SELECT max(e2.revision) FROM referencedEntity e2
+ * WHERE e2.revision <= :revision AND e2.id1 = e.id1) AND
+ * (only entities referenced by the association)
+ * ee.id1 = e.id1 AND
+ * ee.id2 = :id2 AND
+ * (the association at revision :revision)
+ * ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2
+ * WHERE ee2.revision <= :revision AND ee2.id2 = :id2 AND ee2.id1 =
ee.id1) AND
+ * (only non-deleted entities and associations)
+ * ee.revision_type != DEL AND
+ * e.revision_type != DEL
+ */
+ String revisionPropertyPath = verEntCfg.getRevisionPropPath();
+ String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
+
+ StringBuilder querySB = new StringBuilder();
+ querySB
+ .append("SELECT e FROM
").append(versionsReferencedEntityName).append(" e")
+ .append(", ").append(versionsMiddleEntityName).append(" ee
")
+ .append("WHERE ")
+ // e.revision = (SELECT max(e2.revision) ...
+ .append("e.").append(revisionPropertyPath).append(" =
(SELECT max(e2.").append(revisionPropertyPath)
+ .append(") FROM
").append(versionsReferencedEntityName).append(" e2 ")
+ // e2.revision <= :revision
+ .append("WHERE e2.").append(revisionPropertyPath).append("
<= :revision AND ")
+ // e2.id1 = e.id1)
+ .append(referencedIdMapper.getIdsEqualQuery("e." +
originalIdPropertyName, "e2." + originalIdPropertyName))
+ .append(") AND ")
+ // ee.id1 = e.id1
+ .append(referencedMiddleIdMapper.getIdsEqualQuery("ee." +
originalIdPropertyName,
+ referencedIdMapper, "e." + originalIdPropertyName))
+ .append(" AND ")
+ // ee.id2 = :id2
+ .append(referencingMiddleIdMapper.getIdEqualsQuery("ee." +
originalIdPropertyName, true))
+ .append(" AND ")
+ // ee.revision = (SELECT max(ee2.revision) ...
+ .append("ee.").append(revisionPropertyPath).append(" =
(SELECT max(ee2.").append(revisionPropertyPath)
+ .append(") FROM
").append(versionsMiddleEntityName).append(" ee2 ")
+ // ee2.revision <= :revision
+ .append("WHERE
ee2.").append(revisionPropertyPath).append(" <= :revision AND ")
+ // ee2.id2 = :id2)
+ .append(referencingMiddleIdMapper.getIdEqualsQuery("ee2." +
originalIdPropertyName, true))
+ .append(" AND ")
+ // ee2.id1 = ee.id1)
+ .append(referencedMiddleIdMapper.getIdsEqualQuery("ee." +
originalIdPropertyName, "ee2." + originalIdPropertyName))
+ .append(") AND ")
+ // e.revision_type != DEL AND
+
.append("e.").append(verEntCfg.getRevisionTypePropName()).append(" !=
").append(":delrevisiontype")
+ .append(" AND ")
+ // ee.revision_type != DEL
+
.append("ee.").append(verEntCfg.getRevisionTypePropName()).append(" !=
").append(":delrevisiontype");
+
+ queryString = querySB.toString();
+ }
+
+ public Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey,
Number revision) {
+ Query query = versionsReader.getSession().createQuery(queryString);
+ query.setParameter("revision", revision);
+ query.setParameter("delrevisiontype", RevisionType.DEL);
+ for (QueryParameterData paramData:
referencingMiddleIdMapper.mapToQueryParametersFromId(primaryKey)) {
+ paramData.setParameterValue(query);
+ }
+
+ return query;
+ }
+}
Copied:
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyAttachedMapper.java
(from rev 117,
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyBidirectionalMapper.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyAttachedMapper.java
(rev 0)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyAttachedMapper.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,64 @@
+/*
+ * Envers.
http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.entities.mapper.relation;
+
+import org.jboss.envers.entities.mapper.PropertyMapper;
+import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.entities.mapper.relation.lazy.OneToManyAttachedInitializor;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
+import org.jboss.envers.configuration.VersionsConfiguration;
+import org.hibernate.collection.PersistentCollection;
+
+import java.util.*;
+import java.io.Serializable;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class OneToManyAttachedMapper extends AbstractOneToManyMapper implements
PropertyMapper {
+ private final String owningReferencePropertyName;
+
+ public OneToManyAttachedMapper(String owningReferencePropertyName, String
owningEntityName, String propertyName) {
+ super(owningEntityName, propertyName);
+
+ this.owningReferencePropertyName = owningReferencePropertyName;
+ }
+
+ public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj,
Object oldObj) {
+ return false;
+ }
+
+ protected <T extends Collection> Initializor<T>
getInitializator(VersionsConfiguration verCfg,
+
VersionsReaderImplementor versionsReader,
+ Class<?>
entityClass, Object primaryKey,
+ Number revision,
+ Class<T>
collectionClass) {
+ return new OneToManyAttachedInitializor<T>(versionsReader, entityClass,
owningReferencePropertyName, primaryKey,
+ revision, collectionClass);
+ }
+
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String
referencingPropertyName, PersistentCollection newColl,
+ Serializable
oldColl, Serializable id) {
+ return null;
+ }
+}
\ No newline at end of file
Copied:
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java
(from rev 117,
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyUnidirectionalMapper.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java
(rev 0)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,121 @@
+package org.jboss.envers.entities.mapper.relation;
+
+import org.jboss.envers.entities.mapper.PropertyMapper;
+import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
+import org.jboss.envers.entities.mapper.relation.lazy.OneToManyDetachedInitializor;
+import org.jboss.envers.entities.mapper.id.IdMapper;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.RevisionType;
+import org.hibernate.collection.PersistentCollection;
+
+import java.util.*;
+import java.io.Serializable;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class OneToManyDetachedMapper extends AbstractOneToManyMapper implements
PropertyMapper {
+ private final VersionsEntitiesConfiguration verEntCfg;
+ /**
+ * Name of the entity that declares the relation.
+ */
+ private final String referencedEntityName;
+ /**
+ * Name of the property in <code>referencedEntityName</code> that holds
the value of the relation.
+ */
+ private final String collectionReferencingPropertyName;
+ /**
+ * Generated middle entity, which stores the bindings of the relation.
+ */
+ private final String versionsMiddleEntityName;
+ private final IdMapper referencingMiddleIdMapper;
+ private final IdMapper referencedMiddleIdMapper;
+
+ private final DetachedRelationQueryGenerator queryGenerator;
+
+ public OneToManyDetachedMapper(VersionsEntitiesConfiguration verEntCfg, String
referencingEntityName,
+ String referencedEntityName, String
collectionReferencingPropertyName,
+ String versionsReferencedEntityName, String
versionsMiddleEntityName,
+ IdMapper referencingMiddleIdMapper, IdMapper
referencedMiddleIdMapper,
+ IdMapper referencedIdMapper) {
+ super(referencingEntityName, collectionReferencingPropertyName);
+
+ this.verEntCfg = verEntCfg;
+ this.referencedEntityName = referencedEntityName;
+ this.collectionReferencingPropertyName = collectionReferencingPropertyName;
+ this.versionsMiddleEntityName = versionsMiddleEntityName;
+ this.referencingMiddleIdMapper = referencingMiddleIdMapper;
+ this.referencedMiddleIdMapper = referencedMiddleIdMapper;
+
+ queryGenerator = new DetachedRelationQueryGenerator(verEntCfg,
versionsReferencedEntityName,
+ versionsMiddleEntityName, referencingMiddleIdMapper,
referencedMiddleIdMapper, referencedIdMapper);
+ }
+
+ private Collection getOldCollection(Serializable oldColl) {
+ if (oldColl instanceof Map) {
+ return ((Map) oldColl).keySet();
+ } else {
+ return (Collection) oldColl;
+ }
+ }
+
+ private void addCollectionChanges(List<PersistentCollectionChangeData>
collectionChanges, Set<Object> changed,
+ RevisionType revisionType, Serializable id) {
+ for (Object changedEntity : changed) {
+ Map<String, Object> entityData = new HashMap<String, Object>();
+ Map<String, Object> originalId = new HashMap<String, Object>();
+ entityData.put(verEntCfg.getOriginalIdPropName(), originalId);
+
+ collectionChanges.add(new
PersistentCollectionChangeData(versionsMiddleEntityName, entityData));
+ referencingMiddleIdMapper.mapToMapFromId(originalId, id);
+ referencedMiddleIdMapper.mapToMapFromEntity(originalId, changedEntity);
+
+ entityData.put(verEntCfg.getRevisionTypePropName(), revisionType);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String
referencingPropertyName,
+ PersistentCollection
newColl,
+ Serializable
oldColl, Serializable id) {
+ if (!collectionReferencingPropertyName.equals(referencingPropertyName)) {
+ return null;
+ }
+
+ List<PersistentCollectionChangeData> collectionChanges = new
ArrayList<PersistentCollectionChangeData>();
+
+ Collection newCollection = (Collection) newColl;
+ Collection oldCollection = getOldCollection(oldColl);
+
+ Set<Object> added = new HashSet<Object>();
+ if (newColl != null) { added.addAll(newCollection); }
+ if (oldColl != null) { added.removeAll(oldCollection); }
+
+ addCollectionChanges(collectionChanges, added, RevisionType.ADD, id);
+
+ Set<Object> deleted = new HashSet<Object>();
+ if (oldColl != null) { deleted.addAll(oldCollection); }
+ if (newColl != null) { deleted.removeAll(newCollection); }
+
+ addCollectionChanges(collectionChanges, deleted, RevisionType.DEL, id);
+
+ return collectionChanges;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj,
Object oldObj) {
+ // Changes are mapped in the "mapCollectionChanges" method.
+ return false;
+ }
+
+ protected <T extends Collection> Initializor<T>
getInitializator(VersionsConfiguration verCfg,
+
VersionsReaderImplementor versionsReader,
+ Class<?>
entityClass, Object primaryKey,
+ Number revision,
Class<T> collectionClass) {
+ return new OneToManyDetachedInitializor<T>(verCfg, referencedEntityName,
queryGenerator,
+ versionsReader, primaryKey, revision, collectionClass);
+ }
+}
Copied:
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneNotOwningIdMapper.java
(from rev 116,
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneIdMapper.java)
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneNotOwningIdMapper.java
(rev 0)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneNotOwningIdMapper.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,87 @@
+/*
+ * Envers.
http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.entities.mapper.relation;
+
+import org.jboss.envers.entities.mapper.PropertyMapper;
+import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.tools.reflection.ReflectionTools;
+import org.jboss.envers.query.VersionsRestrictions;
+import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
+import org.hibernate.property.Setter;
+import org.hibernate.NonUniqueResultException;
+import org.hibernate.collection.PersistentCollection;
+
+import javax.persistence.NoResultException;
+import java.util.Map;
+import java.util.List;
+import java.io.Serializable;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class OneToOneNotOwningIdMapper implements PropertyMapper {
+ private String owningReferencePropertyName;
+ private String owningEntityName;
+ private String propertyName;
+
+ public OneToOneNotOwningIdMapper(String owningReferencePropertyName, String
owningEntityName, String propertyName) {
+ this.owningReferencePropertyName = owningReferencePropertyName;
+ this.owningEntityName = owningEntityName;
+ this.propertyName = propertyName;
+ }
+
+ public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj,
Object oldObj) {
+ return false;
+ }
+
+ public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data,
Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
+ if (obj == null) {
+ return;
+ }
+
+ Class<?> entityClass = ReflectionTools.loadClass(owningEntityName);
+
+ 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);
+ }
+
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String
referencingPropertyName,
+
PersistentCollection newColl,
+
Serializable oldColl,
+
Serializable id) {
+ return null;
+ }
+}
Copied:
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyAttachedInitializor.java
(from rev 117,
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyBidirectionalInitializor.java)
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyAttachedInitializor.java
(rev 0)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyAttachedInitializor.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,74 @@
+/*
+ * Envers.
http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.entities.mapper.relation.lazy;
+
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
+import org.jboss.envers.query.VersionsRestrictions;
+import org.jboss.envers.exception.VersionsException;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class OneToManyAttachedInitializor<T extends Collection> implements
Initializor<T> {
+ private VersionsReaderImplementor versionsReader;
+ private Class<?> entityClass;
+ private String owningReferencePropertyName;
+ private Object primaryKey;
+ private Number revision;
+ private Class<T> collectionClass;
+
+ public OneToManyAttachedInitializor(VersionsReaderImplementor versionsReader,
Class<?> entityClass,
+ String owningReferencePropertyName, Object primaryKey,
Number revision,
+ Class<T> collectionClass) {
+ this.versionsReader = versionsReader;
+ this.entityClass = entityClass;
+ this.owningReferencePropertyName = owningReferencePropertyName;
+ this.primaryKey = primaryKey;
+ this.revision = revision;
+ this.collectionClass = collectionClass;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public T initialize() {
+ List queryResult =
versionsReader.createQuery().forEntitiesAtRevision(entityClass, revision)
+ .add(VersionsRestrictions.relatedIdEq(owningReferencePropertyName,
primaryKey)).getResultList();
+
+ if (collectionClass.isAssignableFrom(queryResult.getClass())) {
+ return (T) queryResult;
+ } else {
+ Collection result;
+ try {
+ result = collectionClass.newInstance();
+ } catch (Exception e) {
+ throw new VersionsException(e);
+ }
+
+ result.addAll(queryResult);
+
+ return (T) result;
+ }
+ }
+}
Copied:
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyDetachedInitializor.java
(from rev 117,
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyUnidirectionalInitializor.java)
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyDetachedInitializor.java
(rev 0)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyDetachedInitializor.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,55 @@
+package org.jboss.envers.entities.mapper.relation.lazy;
+
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
+import org.jboss.envers.entities.mapper.relation.DetachedRelationQueryGenerator;
+import org.jboss.envers.entities.EntityInstantiator;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class OneToManyDetachedInitializor<T extends Collection> implements
Initializor<T> {
+ private final VersionsConfiguration verCfg;
+ private final String entityName;
+ private final DetachedRelationQueryGenerator queryGenerator;
+ private final VersionsReaderImplementor versionsReader;
+ private final Object primaryKey;
+ private final Number revision;
+ private final Class<T> collectionClass;
+
+ public OneToManyDetachedInitializor(VersionsConfiguration verCfg, String entityName,
+ DetachedRelationQueryGenerator
queryGenerator,
+ VersionsReaderImplementor versionsReader,
Object primaryKey,
+ Number revision, Class<T>
collectionClass) {
+ this.verCfg = verCfg;
+ this.entityName = entityName;
+ this.queryGenerator = queryGenerator;
+ this.versionsReader = versionsReader;
+ this.primaryKey = primaryKey;
+ this.revision = revision;
+ this.collectionClass = collectionClass;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public T initialize() {
+ EntityInstantiator entityInstantiator = new EntityInstantiator(verCfg,
versionsReader);
+
+ List queryResult = queryGenerator.getQuery(versionsReader, primaryKey,
revision).list();
+
+ T result;
+ try {
+ result = collectionClass.newInstance();
+ } catch (Exception e) {
+ throw new VersionsException(e);
+ }
+
+ entityInstantiator.addInstancesFromVersionsEntities(entityName, result,
queryResult, revision);
+
+ return result;
+ }
+}
Modified: trunk/src/test/org/jboss/envers/test/entities/manytomany/SetOwnedEntity.java
===================================================================
---
trunk/src/test/org/jboss/envers/test/entities/manytomany/SetOwnedEntity.java 2008-08-22
15:22:20 UTC (rev 123)
+++
trunk/src/test/org/jboss/envers/test/entities/manytomany/SetOwnedEntity.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -20,7 +20,7 @@
private String data;
@Versioned
- @ManyToMany(mappedBy="referencing")
+ @ManyToMany(mappedBy="references")
private Set<SetOwningEntity> referencing;
public SetOwnedEntity() {
Copied: trunk/src/test/org/jboss/envers/test/entities/onetomany/detached (from rev 117,
trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional)
Copied:
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/ListRefCollEntity.java
(from rev 118,
trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ListRefCollEntity.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/ListRefCollEntity.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/ListRefCollEntity.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,85 @@
+package org.jboss.envers.test.entities.onetomany.detached;
+
+import org.jboss.envers.Versioned;
+import org.jboss.envers.test.entities.StrTestEntity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import java.util.List;
+
+/**
+ * Set collection of references entity
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class ListRefCollEntity {
+ @Id
+ private Integer id;
+
+ @Versioned
+ private String data;
+
+ @Versioned
+ @OneToMany
+ private List<StrTestEntity> collection;
+
+ public ListRefCollEntity() {
+ }
+
+ public ListRefCollEntity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public ListRefCollEntity(String data) {
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public List<StrTestEntity> getCollection() {
+ return collection;
+ }
+
+ public void setCollection(List<StrTestEntity> collection) {
+ this.collection = collection;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ListRefCollEntity)) return false;
+
+ ListRefCollEntity that = (ListRefCollEntity) o;
+
+ if (data != null ? !data.equals(that.data) : that.data != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "SetRefEdEntity(id = " + id + ", data = " + data +
")";
+ }
+}
\ No newline at end of file
Modified:
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/SetRefCollEntity.java
===================================================================
---
trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/SetRefCollEntity.java 2008-08-21
11:18:53 UTC (rev 117)
+++
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/SetRefCollEntity.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -1,4 +1,4 @@
-package org.jboss.envers.test.entities.onetomany.unidirectional;
+package org.jboss.envers.test.entities.onetomany.detached;
import org.jboss.envers.Versioned;
import org.jboss.envers.test.entities.StrTestEntity;
Copied: trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/ids (from rev
119, trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids)
Modified:
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/ids/SetRefCollEntityEmbId.java
===================================================================
---
trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids/SetRefCollEntityEmbId.java 2008-08-21
13:56:27 UTC (rev 119)
+++
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/ids/SetRefCollEntityEmbId.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -1,4 +1,4 @@
-package org.jboss.envers.test.entities.onetomany.unidirectional.ids;
+package org.jboss.envers.test.entities.onetomany.detached.ids;
import org.jboss.envers.Versioned;
import org.jboss.envers.test.entities.ids.EmbId;
Modified:
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/ids/SetRefCollEntityMulId.java
===================================================================
---
trunk/src/test/org/jboss/envers/test/entities/onetomany/unidirectional/ids/SetRefCollEntityMulId.java 2008-08-21
13:56:27 UTC (rev 119)
+++
trunk/src/test/org/jboss/envers/test/entities/onetomany/detached/ids/SetRefCollEntityMulId.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -1,4 +1,4 @@
-package org.jboss.envers.test.entities.onetomany.unidirectional.ids;
+package org.jboss.envers.test.entities.onetomany.detached.ids;
import org.jboss.envers.Versioned;
import org.jboss.envers.test.entities.ids.MulIdTestEntity;
Copied:
trunk/src/test/org/jboss/envers/test/integration/naming/DetachedNamingTestEntity.java
(from rev 120,
trunk/src/test/org/jboss/envers/test/integration/naming/UnidirectionalNamingTestEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/naming/DetachedNamingTestEntity.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/naming/DetachedNamingTestEntity.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,85 @@
+package org.jboss.envers.test.integration.naming;
+
+import org.jboss.envers.Versioned;
+import org.jboss.envers.test.entities.StrTestEntity;
+
+import javax.persistence.*;
+import java.util.Set;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class DetachedNamingTestEntity {
+ @Id
+ private Integer id;
+
+ @Versioned
+ private String data;
+
+ @Versioned
+ @OneToMany
+ @JoinTable(name = "UNI_NAMING_TEST",
+ joinColumns = @JoinColumn(name = "ID_1"),
+ inverseJoinColumns = @JoinColumn(name = "ID_2"))
+ private Set<StrTestEntity> collection;
+
+ public DetachedNamingTestEntity() {
+ }
+
+ public DetachedNamingTestEntity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public DetachedNamingTestEntity(String data) {
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public Set<StrTestEntity> getCollection() {
+ return collection;
+ }
+
+ public void setCollection(Set<StrTestEntity> collection) {
+ this.collection = collection;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof DetachedNamingTestEntity)) return false;
+
+ DetachedNamingTestEntity that = (DetachedNamingTestEntity) o;
+
+ if (data != null ? !data.equals(that.data) : that.data != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "DetachedNamingTestEntity(id = " + id + ", data = " +
data + ")";
+ }
+}
Modified:
trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java 2008-08-22
15:22:20 UTC (rev 123)
+++
trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -21,13 +21,13 @@
private Integer str1_id;
public void configure(Ejb3Configuration cfg) {
- cfg.addAnnotatedClass(UnidirectionalNamingTestEntity.class);
+ cfg.addAnnotatedClass(DetachedNamingTestEntity.class);
cfg.addAnnotatedClass(StrTestEntity.class);
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
- UnidirectionalNamingTestEntity uni1 = new UnidirectionalNamingTestEntity(1,
"data1");
+ DetachedNamingTestEntity uni1 = new DetachedNamingTestEntity(1,
"data1");
StrTestEntity str1 = new StrTestEntity("str1");
// Revision 1
@@ -43,7 +43,7 @@
// Revision 2
em.getTransaction().begin();
- uni1 = em.find(UnidirectionalNamingTestEntity.class, uni1.getId());
+ uni1 = em.find(DetachedNamingTestEntity.class, uni1.getId());
str1 = em.find(StrTestEntity.class, str1.getId());
uni1.getCollection().add(str1);
@@ -57,7 +57,7 @@
@Test
public void testRevisionsCounts() {
- assert Arrays.asList(1,
2).equals(getVersionsReader().getRevisions(UnidirectionalNamingTestEntity.class,
uni1_id));
+ assert Arrays.asList(1,
2).equals(getVersionsReader().getRevisions(DetachedNamingTestEntity.class, uni1_id));
assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str1_id));
}
@@ -65,8 +65,8 @@
public void testHistoryOfUniId1() {
StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
- UnidirectionalNamingTestEntity rev1 =
getVersionsReader().find(UnidirectionalNamingTestEntity.class, uni1_id, 1);
- UnidirectionalNamingTestEntity rev2 =
getVersionsReader().find(UnidirectionalNamingTestEntity.class, uni1_id, 2);
+ DetachedNamingTestEntity rev1 =
getVersionsReader().find(DetachedNamingTestEntity.class, uni1_id, 1);
+ DetachedNamingTestEntity rev2 =
getVersionsReader().find(DetachedNamingTestEntity.class, uni1_id, 2);
assert rev1.getCollection().equals(TestTools.makeSet());
assert rev2.getCollection().equals(TestTools.makeSet(str1));
@@ -78,7 +78,7 @@
@Test
public void testTableName() {
assert "UNI_NAMING_TEST_versions".equals(
-
getCfg().getClassMapping("UnidirectionalNamingTestEntity_org.jboss.envers.test.entities.StrTestEntity_versions")
+
getCfg().getClassMapping("DetachedNamingTestEntity_org.jboss.envers.test.entities.StrTestEntity_versions")
.getTable().getName());
}
@@ -86,7 +86,7 @@
@Test
public void testJoinColumnName() {
Iterator<Column> columns =
-
getCfg().getClassMapping("UnidirectionalNamingTestEntity_org.jboss.envers.test.entities.StrTestEntity_versions")
+
getCfg().getClassMapping("DetachedNamingTestEntity_org.jboss.envers.test.entities.StrTestEntity_versions")
.getTable().getColumnIterator();
boolean id1Found = false;
Copied: trunk/src/test/org/jboss/envers/test/integration/onetomany/detached (from rev 117,
trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional)
Copied:
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedList.java
(from rev 118,
trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedList.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedList.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedList.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,115 @@
+package org.jboss.envers.test.integration.onetomany.detached;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.onetomany.detached.ListRefCollEntity;
+import org.jboss.envers.test.entities.StrTestEntity;
+import org.jboss.envers.test.tools.TestTools;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.ArrayList;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BasicNotOwnedList extends AbstractEntityTest {
+ private Integer str1_id;
+ private Integer str2_id;
+
+ private Integer coll1_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(StrTestEntity.class);
+ cfg.addAnnotatedClass(ListRefCollEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ StrTestEntity str1 = new StrTestEntity("str1");
+ StrTestEntity str2 = new StrTestEntity("str2");
+
+ ListRefCollEntity coll1 = new ListRefCollEntity(3, "coll1");
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ em.persist(str1);
+ em.persist(str2);
+
+ coll1.setCollection(new ArrayList<StrTestEntity>());
+ coll1.getCollection().add(str1);
+ em.persist(coll1);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ str2 = em.find(StrTestEntity.class, str2.getId());
+ coll1 = em.find(ListRefCollEntity.class, coll1.getId());
+
+ coll1.getCollection().add(str2);
+
+ em.getTransaction().commit();
+
+ // Revision 3
+ em.getTransaction().begin();
+
+ str1 = em.find(StrTestEntity.class, str1.getId());
+ coll1 = em.find(ListRefCollEntity.class, coll1.getId());
+
+ coll1.getCollection().remove(str1);
+
+ em.getTransaction().commit();
+
+ // Revision 4
+ em.getTransaction().begin();
+
+ coll1 = em.find(ListRefCollEntity.class, coll1.getId());
+
+ coll1.getCollection().clear();
+
+ em.getTransaction().commit();
+
+ //
+
+ str1_id = str1.getId();
+ str2_id = str2.getId();
+
+ coll1_id = coll1.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 3,
4).equals(getVersionsReader().getRevisions(ListRefCollEntity.class, coll1_id));
+
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str1_id));
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str2_id));
+ }
+
+ @Test
+ public void testHistoryOfColl1() {
+ StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
+ StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
+
+ ListRefCollEntity rev1 = getVersionsReader().find(ListRefCollEntity.class,
coll1_id, 1);
+ ListRefCollEntity rev2 = getVersionsReader().find(ListRefCollEntity.class,
coll1_id, 2);
+ ListRefCollEntity rev3 = getVersionsReader().find(ListRefCollEntity.class,
coll1_id, 3);
+ ListRefCollEntity rev4 = getVersionsReader().find(ListRefCollEntity.class,
coll1_id, 4);
+
+ assert TestTools.checkList(rev1.getCollection(), str1);
+ assert TestTools.checkList(rev2.getCollection(), str1, str2);
+ assert TestTools.checkList(rev3.getCollection(), str2);
+ assert TestTools.checkList(rev4.getCollection());
+
+ assert "coll1".equals(rev1.getData());
+ assert "coll1".equals(rev2.getData());
+ assert "coll1".equals(rev3.getData());
+ assert "coll1".equals(rev4.getData());
+ }
+}
\ No newline at end of file
Deleted:
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSet.java
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSet.java 2008-08-21
11:18:53 UTC (rev 117)
+++
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSet.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -1,123 +0,0 @@
-package org.jboss.envers.test.integration.onetomany.unidirectional;
-
-import org.jboss.envers.test.integration.AbstractEntityTest;
-import org.jboss.envers.test.entities.onetomany.unidirectional.SetRefCollEntity;
-import org.jboss.envers.test.entities.StrTestEntity;
-import org.hibernate.ejb.Ejb3Configuration;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import javax.persistence.EntityManager;
-import java.util.Arrays;
-import java.util.Set;
-import java.util.HashSet;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class BasicNotOwnedSet extends AbstractEntityTest {
- private Integer str1_id;
- private Integer str2_id;
-
- private Integer coll1_id;
-
- public void configure(Ejb3Configuration cfg) {
- cfg.addAnnotatedClass(StrTestEntity.class);
- cfg.addAnnotatedClass(SetRefCollEntity.class);
- }
-
- @BeforeClass(dependsOnMethods = "init")
- public void initData() {
- EntityManager em = getEntityManager();
-
- StrTestEntity str1 = new StrTestEntity("str1");
- StrTestEntity str2 = new StrTestEntity("str2");
-
- SetRefCollEntity coll1 = new SetRefCollEntity(3, "coll1");
-
- // Revision 1
- em.getTransaction().begin();
-
- em.persist(str1);
- em.persist(str2);
-
- coll1.setCollection(new HashSet<StrTestEntity>());
- coll1.getCollection().add(str1);
- em.persist(coll1);
-
- em.getTransaction().commit();
-
- // Revision 2
- em.getTransaction().begin();
-
- str2 = em.find(StrTestEntity.class, str2.getId());
- coll1 = em.find(SetRefCollEntity.class, coll1.getId());
-
- coll1.getCollection().add(str2);
-
- em.getTransaction().commit();
-
- // Revision 3
- em.getTransaction().begin();
-
- str1 = em.find(StrTestEntity.class, str1.getId());
- coll1 = em.find(SetRefCollEntity.class, coll1.getId());
-
- coll1.getCollection().remove(str1);
-
- em.getTransaction().commit();
-
- // Revision 4
- em.getTransaction().begin();
-
- coll1 = em.find(SetRefCollEntity.class, coll1.getId());
-
- coll1.getCollection().clear();
-
- em.getTransaction().commit();
-
- //
-
- str1_id = str1.getId();
- str2_id = str2.getId();
-
- coll1_id = coll1.getId();
- }
-
- @Test
- public void testRevisionsCounts() {
- assert Arrays.asList(1, 2, 3,
4).equals(getVersionsReader().getRevisions(SetRefCollEntity.class, coll1_id));
-
- assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str1_id));
- assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str2_id));
- }
-
- @SuppressWarnings({"ManualArrayToCollectionCopy"})
- private <T> Set<T> makeSet(T... objects) {
- Set<T> ret = new HashSet<T>();
- for (T obj : objects) { ret.add(obj); }
- return ret;
- }
-
- @Test
- public void testHistoryOfColl1() {
- StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
- StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
-
- SetRefCollEntity rev1 = getVersionsReader().find(SetRefCollEntity.class,
coll1_id, 1);
- SetRefCollEntity rev2 = getVersionsReader().find(SetRefCollEntity.class,
coll1_id, 2);
- SetRefCollEntity rev3 = getVersionsReader().find(SetRefCollEntity.class,
coll1_id, 3);
- SetRefCollEntity rev4 = getVersionsReader().find(SetRefCollEntity.class,
coll1_id, 4);
-
- assert rev1.getCollection().equals(makeSet(str1));
- assert rev2.getCollection().equals(makeSet(str1, str2));
- assert rev3.getCollection().equals(makeSet(str2));
- assert rev4.getCollection().equals(makeSet());
-
- assert "coll1".equals(rev1.getData());
- assert "coll1".equals(rev2.getData());
- assert "coll1".equals(rev3.getData());
- assert "coll1".equals(rev4.getData());
-
- }
-}
Copied:
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSet.java
(from rev 118,
trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSet.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSet.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSet.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,115 @@
+package org.jboss.envers.test.integration.onetomany.detached;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.onetomany.detached.SetRefCollEntity;
+import org.jboss.envers.test.entities.StrTestEntity;
+import org.jboss.envers.test.tools.TestTools;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BasicNotOwnedSet extends AbstractEntityTest {
+ private Integer str1_id;
+ private Integer str2_id;
+
+ private Integer coll1_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(StrTestEntity.class);
+ cfg.addAnnotatedClass(SetRefCollEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ StrTestEntity str1 = new StrTestEntity("str1");
+ StrTestEntity str2 = new StrTestEntity("str2");
+
+ SetRefCollEntity coll1 = new SetRefCollEntity(3, "coll1");
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ em.persist(str1);
+ em.persist(str2);
+
+ coll1.setCollection(new HashSet<StrTestEntity>());
+ coll1.getCollection().add(str1);
+ em.persist(coll1);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ str2 = em.find(StrTestEntity.class, str2.getId());
+ coll1 = em.find(SetRefCollEntity.class, coll1.getId());
+
+ coll1.getCollection().add(str2);
+
+ em.getTransaction().commit();
+
+ // Revision 3
+ em.getTransaction().begin();
+
+ str1 = em.find(StrTestEntity.class, str1.getId());
+ coll1 = em.find(SetRefCollEntity.class, coll1.getId());
+
+ coll1.getCollection().remove(str1);
+
+ em.getTransaction().commit();
+
+ // Revision 4
+ em.getTransaction().begin();
+
+ coll1 = em.find(SetRefCollEntity.class, coll1.getId());
+
+ coll1.getCollection().clear();
+
+ em.getTransaction().commit();
+
+ //
+
+ str1_id = str1.getId();
+ str2_id = str2.getId();
+
+ coll1_id = coll1.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 3,
4).equals(getVersionsReader().getRevisions(SetRefCollEntity.class, coll1_id));
+
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str1_id));
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str2_id));
+ }
+
+ @Test
+ public void testHistoryOfColl1() {
+ StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
+ StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
+
+ SetRefCollEntity rev1 = getVersionsReader().find(SetRefCollEntity.class,
coll1_id, 1);
+ SetRefCollEntity rev2 = getVersionsReader().find(SetRefCollEntity.class,
coll1_id, 2);
+ SetRefCollEntity rev3 = getVersionsReader().find(SetRefCollEntity.class,
coll1_id, 3);
+ SetRefCollEntity rev4 = getVersionsReader().find(SetRefCollEntity.class,
coll1_id, 4);
+
+ assert rev1.getCollection().equals(TestTools.makeSet(str1));
+ assert rev2.getCollection().equals(TestTools.makeSet(str1, str2));
+ assert rev3.getCollection().equals(TestTools.makeSet(str2));
+ assert rev4.getCollection().equals(TestTools.makeSet());
+
+ assert "coll1".equals(rev1.getData());
+ assert "coll1".equals(rev2.getData());
+ assert "coll1".equals(rev3.getData());
+ assert "coll1".equals(rev4.getData());
+ }
+}
Copied:
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSetWithEmbId.java
(from rev 119,
trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSetWithEmbId.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSetWithEmbId.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSetWithEmbId.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,114 @@
+package org.jboss.envers.test.integration.onetomany.detached;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.onetomany.detached.ids.SetRefCollEntityEmbId;
+import org.jboss.envers.test.entities.ids.EmbIdTestEntity;
+import org.jboss.envers.test.entities.ids.EmbId;
+import org.jboss.envers.test.tools.TestTools;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BasicNotOwnedSetWithEmbId extends AbstractEntityTest {
+ private EmbId str1_id;
+ private EmbId str2_id;
+
+ private EmbId coll1_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(EmbIdTestEntity.class);
+ cfg.addAnnotatedClass(SetRefCollEntityEmbId.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ str1_id = new EmbId(1, 2);
+ str2_id = new EmbId(3, 4);
+
+ coll1_id = new EmbId(5, 6);
+
+ EmbIdTestEntity str1 = new EmbIdTestEntity(str1_id, "str1");
+ EmbIdTestEntity str2 = new EmbIdTestEntity(str2_id, "str2");
+
+ SetRefCollEntityEmbId coll1 = new SetRefCollEntityEmbId(coll1_id,
"coll1");
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ em.persist(str1);
+ em.persist(str2);
+
+ coll1.setCollection(new HashSet<EmbIdTestEntity>());
+ coll1.getCollection().add(str1);
+ em.persist(coll1);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ str2 = em.find(EmbIdTestEntity.class, str2.getId());
+ coll1 = em.find(SetRefCollEntityEmbId.class, coll1.getId());
+
+ coll1.getCollection().add(str2);
+
+ em.getTransaction().commit();
+
+ // Revision 3
+ em.getTransaction().begin();
+
+ str1 = em.find(EmbIdTestEntity.class, str1.getId());
+ coll1 = em.find(SetRefCollEntityEmbId.class, coll1.getId());
+
+ coll1.getCollection().remove(str1);
+
+ em.getTransaction().commit();
+
+ // Revision 4
+ em.getTransaction().begin();
+
+ coll1 = em.find(SetRefCollEntityEmbId.class, coll1.getId());
+
+ coll1.getCollection().clear();
+
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 3,
4).equals(getVersionsReader().getRevisions(SetRefCollEntityEmbId.class, coll1_id));
+
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(EmbIdTestEntity.class,
str1_id));
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(EmbIdTestEntity.class,
str2_id));
+ }
+
+ @Test
+ public void testHistoryOfColl1() {
+ EmbIdTestEntity str1 = getEntityManager().find(EmbIdTestEntity.class, str1_id);
+ EmbIdTestEntity str2 = getEntityManager().find(EmbIdTestEntity.class, str2_id);
+
+ SetRefCollEntityEmbId rev1 =
getVersionsReader().find(SetRefCollEntityEmbId.class, coll1_id, 1);
+ SetRefCollEntityEmbId rev2 =
getVersionsReader().find(SetRefCollEntityEmbId.class, coll1_id, 2);
+ SetRefCollEntityEmbId rev3 =
getVersionsReader().find(SetRefCollEntityEmbId.class, coll1_id, 3);
+ SetRefCollEntityEmbId rev4 =
getVersionsReader().find(SetRefCollEntityEmbId.class, coll1_id, 4);
+
+ assert rev1.getCollection().equals(TestTools.makeSet(str1));
+ assert rev2.getCollection().equals(TestTools.makeSet(str1, str2));
+ assert rev3.getCollection().equals(TestTools.makeSet(str2));
+ assert rev4.getCollection().equals(TestTools.makeSet());
+
+ assert "coll1".equals(rev1.getData());
+ assert "coll1".equals(rev2.getData());
+ assert "coll1".equals(rev3.getData());
+ assert "coll1".equals(rev4.getData());
+ }
+}
\ No newline at end of file
Copied:
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSetWithMulId.java
(from rev 119,
trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/BasicNotOwnedSetWithMulId.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSetWithMulId.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/BasicNotOwnedSetWithMulId.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,114 @@
+package org.jboss.envers.test.integration.onetomany.detached;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.onetomany.detached.ids.SetRefCollEntityMulId;
+import org.jboss.envers.test.entities.ids.MulIdTestEntity;
+import org.jboss.envers.test.entities.ids.MulId;
+import org.jboss.envers.test.tools.TestTools;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BasicNotOwnedSetWithMulId extends AbstractEntityTest {
+ private MulId str1_id;
+ private MulId str2_id;
+
+ private MulId coll1_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(MulIdTestEntity.class);
+ cfg.addAnnotatedClass(SetRefCollEntityMulId.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ str1_id = new MulId(1, 2);
+ str2_id = new MulId(3, 4);
+
+ coll1_id = new MulId(5, 6);
+
+ MulIdTestEntity str1 = new MulIdTestEntity(str1_id.getId1(), str1_id.getId2(),
"str1");
+ MulIdTestEntity str2 = new MulIdTestEntity(str2_id.getId1(), str2_id.getId2(),
"str2");
+
+ SetRefCollEntityMulId coll1 = new SetRefCollEntityMulId(coll1_id.getId1(),
coll1_id.getId2(), "coll1");
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ em.persist(str1);
+ em.persist(str2);
+
+ coll1.setCollection(new HashSet<MulIdTestEntity>());
+ coll1.getCollection().add(str1);
+ em.persist(coll1);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ str2 = em.find(MulIdTestEntity.class, str2_id);
+ coll1 = em.find(SetRefCollEntityMulId.class, coll1_id);
+
+ coll1.getCollection().add(str2);
+
+ em.getTransaction().commit();
+
+ // Revision 3
+ em.getTransaction().begin();
+
+ str1 = em.find(MulIdTestEntity.class, str1_id);
+ coll1 = em.find(SetRefCollEntityMulId.class, coll1_id);
+
+ coll1.getCollection().remove(str1);
+
+ em.getTransaction().commit();
+
+ // Revision 4
+ em.getTransaction().begin();
+
+ coll1 = em.find(SetRefCollEntityMulId.class, coll1_id);
+
+ coll1.getCollection().clear();
+
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 3,
4).equals(getVersionsReader().getRevisions(SetRefCollEntityMulId.class, coll1_id));
+
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(MulIdTestEntity.class,
str1_id));
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(MulIdTestEntity.class,
str2_id));
+ }
+
+ @Test
+ public void testHistoryOfColl1() {
+ MulIdTestEntity str1 = getEntityManager().find(MulIdTestEntity.class, str1_id);
+ MulIdTestEntity str2 = getEntityManager().find(MulIdTestEntity.class, str2_id);
+
+ SetRefCollEntityMulId rev1 =
getVersionsReader().find(SetRefCollEntityMulId.class, coll1_id, 1);
+ SetRefCollEntityMulId rev2 =
getVersionsReader().find(SetRefCollEntityMulId.class, coll1_id, 2);
+ SetRefCollEntityMulId rev3 =
getVersionsReader().find(SetRefCollEntityMulId.class, coll1_id, 3);
+ SetRefCollEntityMulId rev4 =
getVersionsReader().find(SetRefCollEntityMulId.class, coll1_id, 4);
+
+ assert rev1.getCollection().equals(TestTools.makeSet(str1));
+ assert rev2.getCollection().equals(TestTools.makeSet(str1, str2));
+ assert rev3.getCollection().equals(TestTools.makeSet(str2));
+ assert rev4.getCollection().equals(TestTools.makeSet());
+
+ assert "coll1".equals(rev1.getData());
+ assert "coll1".equals(rev2.getData());
+ assert "coll1".equals(rev3.getData());
+ assert "coll1".equals(rev4.getData());
+ }
+}
\ No newline at end of file
Copied:
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DataChangesNotOwnedSet.java
(from rev 118,
trunk/src/test/org/jboss/envers/test/integration/onetomany/unidirectional/DataChangesNotOwnedSet.java)
===================================================================
---
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DataChangesNotOwnedSet.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/onetomany/detached/DataChangesNotOwnedSet.java 2008-08-22
16:24:06 UTC (rev 124)
@@ -0,0 +1,84 @@
+package org.jboss.envers.test.integration.onetomany.detached;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.onetomany.detached.SetRefCollEntity;
+import org.jboss.envers.test.entities.StrTestEntity;
+import org.jboss.envers.test.tools.TestTools;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class DataChangesNotOwnedSet extends AbstractEntityTest {
+ private Integer str1_id;
+
+ private Integer coll1_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(StrTestEntity.class);
+ cfg.addAnnotatedClass(SetRefCollEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ StrTestEntity str1 = new StrTestEntity("str1");
+
+ SetRefCollEntity coll1 = new SetRefCollEntity(3, "coll1");
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ em.persist(str1);
+
+ coll1.setCollection(new HashSet<StrTestEntity>());
+ em.persist(coll1);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ str1 = em.find(StrTestEntity.class, str1.getId());
+ coll1 = em.find(SetRefCollEntity.class, coll1.getId());
+
+ coll1.getCollection().add(str1);
+ coll1.setData("coll2");
+
+ em.getTransaction().commit();
+
+ //
+
+ str1_id = str1.getId();
+
+ coll1_id = coll1.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1,
2).equals(getVersionsReader().getRevisions(SetRefCollEntity.class, coll1_id));
+
+ assert
Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str1_id));
+ }
+
+ @Test
+ public void testHistoryOfColl1() {
+ StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
+
+ SetRefCollEntity rev1 = getVersionsReader().find(SetRefCollEntity.class,
coll1_id, 1);
+ SetRefCollEntity rev2 = getVersionsReader().find(SetRefCollEntity.class,
coll1_id, 2);
+
+ assert rev1.getCollection().equals(TestTools.makeSet());
+ assert rev2.getCollection().equals(TestTools.makeSet(str1));
+
+ assert "coll1".equals(rev1.getData());
+ assert "coll2".equals(rev2.getData());
+ }
+}
\ No newline at end of file
Modified: trunk/src/test/org/jboss/envers/test/working/WorkingEntity1.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/working/WorkingEntity1.java 2008-08-22 15:22:20
UTC (rev 123)
+++ trunk/src/test/org/jboss/envers/test/working/WorkingEntity1.java 2008-08-22 16:24:06
UTC (rev 124)
@@ -5,6 +5,7 @@
import org.jboss.envers.SecondaryVersionsTables;
import javax.persistence.*;
+import java.util.Set;
/**
* @author Adam Warski (adam at warski dot org)
@@ -32,6 +33,10 @@
@Transient
private WorkingEntity2 we2;
+ @ManyToMany(mappedBy="we1s")
+ @Versioned
+ private Set<WorkingEntity2> we2s;
+
public WorkingEntity1() {
}
@@ -81,6 +86,14 @@
this.we2 = we2;
}
+ public Set<WorkingEntity2> getWe2s() {
+ return we2s;
+ }
+
+ public void setWe2s(Set<WorkingEntity2> we2s) {
+ this.we2s = we2s;
+ }
+
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof WorkingEntity1)) return false;
Modified: trunk/src/test/org/jboss/envers/test/working/WorkingMain.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/working/WorkingMain.java 2008-08-22 15:22:20 UTC
(rev 123)
+++ trunk/src/test/org/jboss/envers/test/working/WorkingMain.java 2008-08-22 16:24:06 UTC
(rev 124)
@@ -77,51 +77,10 @@
entityManager.getTransaction().commit();
- // Rev 2
+ //
entityManager.getTransaction().begin();
- we1 = entityManager.find(WorkingEntity1.class, we1.getId1());
- we2 = entityManager.find(WorkingEntity2.class, we2.getId2());
- we2.getWe1s().add(we1);
-
- entityManager.getTransaction().commit();
-
- // Rev 3
- entityManager.getTransaction().begin();
-
- we1_2 = entityManager.find(WorkingEntity1.class, we1_2.getId1());
- we2 = entityManager.find(WorkingEntity2.class, we2.getId2());
- we2.getWe1s().add(we1_2);
-
- entityManager.getTransaction().commit();
-
- // Rev 4
- entityManager.getTransaction().begin();
-
- we1_2 = entityManager.find(WorkingEntity1.class, we1_2.getId1());
- we2 = entityManager.find(WorkingEntity2.class, we2.getId2());
- we2.getWe1s().remove(we1_2);
-
- entityManager.getTransaction().commit();
-
- // Rev 5
- entityManager.getTransaction().begin();
-
- we2 = entityManager.find(WorkingEntity2.class, we2.getId2());
- we2.setWe1s(null);
-
- entityManager.getTransaction().commit();
-
- // Rev 6
- entityManager.getTransaction().begin();
-
VersionsReader vr = VersionsReaderFactory.get(entityManager);
- System.out.println("1 " + vr.find(WorkingEntity2.class, we2.getId2(),
1).getWe1s());
- System.out.println("2 " + vr.find(WorkingEntity2.class, we2.getId2(),
2).getWe1s());
- System.out.println("3 " + vr.find(WorkingEntity2.class, we2.getId2(),
3).getWe1s());
- System.out.println("4 " + vr.find(WorkingEntity2.class, we2.getId2(),
4).getWe1s());
- System.out.println("5 " + vr.find(WorkingEntity2.class, we2.getId2(),
5).getWe1s());
- System.out.println("6 " + vr.find(WorkingEntity2.class, we2.getId2(),
6).getWe1s());
entityManager.getTransaction().commit();
}