JBoss Envers SVN: r152 - in trunk/src: main/org/jboss/envers/entities and 3 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-21 08:21:25 -0400 (Sun, 21 Sep 2008)
New Revision: 152
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java
trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
trunk/src/main/org/jboss/envers/entities/RelationType.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleDummyComponentMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleRelatedComponentMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java
trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java
Log:
ENVERS-42, ENVERS-44: many-to-many relations support working again
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-19 14:51:22 UTC (rev 151)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-21 12:21:25 UTC (rev 152)
@@ -28,7 +28,7 @@
* Generates metadata for collection-valued properties.
* @author Adam Warski (adam at warski dot org)
*/
-public final class CollectionMetadataGenerator {
+public final class CollectionMetadataGenerator {
private final VersionsMetadataGenerator mainGenerator;
CollectionMetadataGenerator(VersionsMetadataGenerator versionsMetadataGenerator) {
@@ -102,7 +102,7 @@
IdMapper ownedIdMapper = referencingIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
// Storing information about this relation
- mainGenerator.getEntitiesConfigurations().get(entityName).addOneToManyAttachedRelation(name, owningReferencePropertyName,
+ mainGenerator.getEntitiesConfigurations().get(entityName).addToManyNotOwningRelation(name, owningReferencePropertyName,
owningEntityName, ownedIdMapper);
// Adding mapper for the id
@@ -119,6 +119,15 @@
}
@SuppressWarnings({"unchecked"})
+ private void addRelatedToXmlMapping(Element xmlMapping, String prefix, Value relatedValue, IdMappingData relatedIdMapping) {
+ Element properties = (Element) relatedIdMapping.getXmlRelationMapping().clone();
+ MetadataTools.prefixNamesInPropertyElement(properties, prefix, relatedValue.getColumnIterator(), true);
+ for (Element idProperty : (java.util.List<Element>) properties.elements()) {
+ xmlMapping.add((Element) idProperty.clone());
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
private void addWithMiddleTable(String name, Collection value, CompositeMapperBuilder currentMapper,
String entityName, EntityXmlMappingData xmlMappingData) {
// Generating the name of the middle table, its schema and catalog
@@ -135,16 +144,13 @@
// If the relation is inverse, will be later checked by comparing middleEntityXml with null.
Element middleEntityXml;
Element middleEntityXmlId;
- Iterator<Column> middleEntityOriginalColumns;
if (!value.isInverse()) {
middleEntityXml = MetadataTools.createEntity(xmlMappingData.newAdditionalMapping(),
versionsMiddleEntityName, versionsMiddleTableName, schema, catalog, null);
middleEntityXmlId = middleEntityXml.addElement("composite-id");
- middleEntityOriginalColumns = value.getCollectionTable().getColumnIterator();
} else {
middleEntityXml = null;
middleEntityXmlId = null;
- middleEntityOriginalColumns = null;
}
// ******
@@ -200,11 +206,8 @@
if (middleEntityXml != null) {
middleEntityXmlId.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
- Element properties = (Element) referencingIdMapping.getXmlRelationMapping().clone();
- MetadataTools.prefixNamesInPropertyElement(properties, referencingPrefix, middleEntityOriginalColumns, true);
- for (Element idProperty : (java.util.List<Element>) properties.elements()) {
- middleEntityXmlId.add((Element) idProperty.clone());
- }
+ // Adding related-entity (in this case: the referencing's entity id) id mapping to the xml.
+ addRelatedToXmlMapping(middleEntityXmlId, referencingPrefix, value.getKey(), referencingIdMapping);
// Adding the revision number as a foreign key to the revision info entity to the composite id of the
// middle table.
@@ -218,7 +221,7 @@
// Generating the element mapping.
// ******
MiddleComponentData elementComponentData = addValueToMiddleTable(value.getElement(), middleEntityXmlId,
- middleEntityOriginalColumns, queryGeneratorBuilder, referencedPrefix);
+ queryGeneratorBuilder, referencedPrefix);
// ******
// Optionally, generating the index mapping.
@@ -254,6 +257,17 @@
} else {
throw new RuntimeException();
}
+
+ // ******
+ // Storing information about this relation.
+ // ******
+ if (value.isInverse()) {
+ mainGenerator.getEntitiesConfigurations().get(entityName).addToManyMiddleNotOwningRelation(name, mappedBy,
+ referencedEntityName);
+ } else {
+ mainGenerator.getEntitiesConfigurations().get(entityName).addToManyMiddleRelation(name,
+ referencedEntityName);
+ }
}
/**
@@ -261,15 +275,12 @@
* @param value Value, which should be mapped to the middle-table, either as a relation to another entity,
* or as a simple value.
* @param middleEntityXml If not <code>null</code>, xml mapping for this value is added to this element.
- * @param middleEntityOriginalColumns If <code>middleEntityXml</code> is not null, this iterator is used
- * to read column names for the generated xml mapping.
* @param queryGeneratorBuilder In case <code>value</code> is a relation to another entity, information about it
* should be added to the given.
* @param prefix Prefix for proeprty names of related entities identifiers.
* @return Data for mapping this component.
*/
private MiddleComponentData addValueToMiddleTable(Value value, Element middleEntityXml,
- Iterator<Column> middleEntityOriginalColumns,
QueryGeneratorBuilder queryGeneratorBuilder,
String prefix) {
Type type = value.getType();
@@ -279,6 +290,12 @@
IdMappingData referencedIdMapping = mainGenerator.getEntitiesConfigurations().get(
toOneValue.getReferencedEntityName()).getIdMappingData();
+ // Adding related-entity (in this case: the referenced entities id) id mapping to the xml only if the
+ // relation isn't inverse (so when <code>middleEntityXml</code> is not null).
+ if (middleEntityXml != null) {
+ addRelatedToXmlMapping(middleEntityXml, prefix, value, referencedIdMapping);
+ }
+
// Storing the id data of the referenced entity: original mapper, prefixed mapper and entity name.
IdMapper referencedPrefixedIdMapper = referencedIdMapping.getIdMapper().prefixMappedProperties(prefix);
MiddleIdData referencedIdData = new MiddleIdData(
@@ -302,114 +319,4 @@
throw new RuntimeException();
}
}
-
- private String getMiddleEntityName(String entityName, String referencedEntityName, ManyToOne mto) {
- return entityName + "_" + referencedEntityName + "_" + mto.getTable().getName();
- }
-
- @SuppressWarnings({"unchecked"})
- private void addOneToManyDetached(String name, Collection value, CompositeMapperBuilder mapper, String entityName,
- EntityXmlMappingData xmlMappingData) {
- ManyToOne mto = (ManyToOne) value.getElement();
-
- String referencedEntityName = mto.getReferencedEntityName();
-
- EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(entityName);
- if (configuration == null) {
- throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
- }
-
- EntityConfiguration referencedConfiguration = mainGenerator.getEntitiesConfigurations().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();
-
- String referencingPrefix = StringTools.getLastComponent(entityName) + "_";
- String referencedPrefix = name + "_";
-
- // Name of the entity that will be used to store the relation between the two entities.
- String middleEntityName = getMiddleEntityName(entityName, referencedEntityName, mto);
- String versionsMiddleEntityName = mainGenerator.getVerEntCfg().getVersionsEntityName(middleEntityName);
- String versionsMiddleTableName = mainGenerator.getVerEntCfg().getVersionsTableName(middleEntityName, mto.getTable().getName());
-
- Element middleEntity = MetadataTools.createEntity(xmlMappingData.newAdditionalMapping(), versionsMiddleEntityName,
- versionsMiddleTableName, mto.getTable().getSchema(), mto.getTable().getCatalog(), null);
-
- Element middleEntityId = middleEntity.addElement("composite-id");
- middleEntityId.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
-
- Iterator columnIterator = mto.getTable().getColumnIterator();
-
- // Adding elements to the mapping corresponding to the referencing entity id's
- Element properties = (Element) referencingIdMapping.getXmlRelationMapping().clone();
- MetadataTools.prefixNamesInPropertyElement(properties, referencingPrefix, columnIterator, true);
- for (Element idProperty : (java.util.List<Element>) properties.elements()) {
- middleEntityId.add((Element) idProperty.clone());
- }
-
- // Adding elements to the mapping corresponding to the referenced entity id's
- properties = (Element) referencedIdMapping.getXmlRelationMapping().clone();
- MetadataTools.prefixNamesInPropertyElement(properties, referencedPrefix, columnIterator, true);
- for (Element idProperty : (java.util.List<Element>) properties.elements()) {
- middleEntityId.add((Element) idProperty.clone());
- }
-
- mainGenerator.addRevisionInfoRelation(middleEntityId);
- mainGenerator.addRevisionType(middleEntity);
-
- mainGenerator.getEntitiesConfigurations().get(entityName).addOneToManyDetachedRelation(name, referencedEntityName);
-
- // Adding the property mapper
- mapper.addComposite(name, new OneToManyDetachedMapper(mainGenerator.getVerEntCfg(), entityName,
- referencedEntityName, name, mainGenerator.getVerEntCfg().getVersionsEntityName(referencedEntityName),
- versionsMiddleEntityName, referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
- referencedIdMapping.getIdMapper().prefixMappedProperties(referencedPrefix),
- mainGenerator.getEntitiesConfigurations().get(referencedEntityName).getIdMapper()));
- }
-
- private void addManyToManyNotOwning(String name, Collection value, CompositeMapperBuilder mapper, String entityName) {
- ManyToOne mto = (ManyToOne) value.getElement();
-
- String referencedEntityName = mto.getReferencedEntityName();
-
- EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(entityName);
- if (configuration == null) {
- throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
- }
-
- EntityConfiguration referencedConfiguration = mainGenerator.getEntitiesConfigurations().get(referencedEntityName);
- if (referencedConfiguration == null) {
- throw new MappingException("A versioned relation to a non-versioned entity " + referencedEntityName + "!");
- }
-
- String mappedBy = getMappedBy(value.getCollectionTable(), mainGenerator.getCfg().getClassMapping(referencedEntityName));
- if (mappedBy == null) {
- throw new MappingException("Unable to read the mapped by attribute for " + name);
- }
-
- IdMappingData referencingIdMapping = configuration.getIdMappingData();
- IdMappingData referencedIdMapping = referencedConfiguration.getIdMappingData();
-
- String referencingPrefix = mappedBy + "_";
- String referencedPrefix = StringTools.getLastComponent(referencedEntityName) + "_";
-
- // Name of the entity that will be used to store the relation between the two entities.
- // The order is inverse, as the referenced and referencing entity names are swapped with respect to the
- // name of the entity that was created on the owning side in <code>addOneToManyDetached</code>.
- String middleEntityName = getMiddleEntityName(referencedEntityName, entityName, mto);
- String versionsMiddleEntityName = mainGenerator.getVerEntCfg().getVersionsEntityName(middleEntityName);
-
- mainGenerator.getEntitiesConfigurations().get(entityName).addManyToManyNotOwningRelation(name, mappedBy,
- referencedEntityName);
-
- // Adding the property mapper
- mapper.addComposite(name, new ManyToManyNotOwningMapper(mainGenerator.getVerEntCfg(), entityName,
- referencedEntityName, name, mainGenerator.getVerEntCfg().getVersionsEntityName(referencedEntityName),
- versionsMiddleEntityName, referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
- referencedIdMapping.getIdMapper().prefixMappedProperties(referencedPrefix),
- mainGenerator.getEntitiesConfigurations().get(referencedEntityName).getIdMapper()));
- }
}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2008-09-19 14:51:22 UTC (rev 151)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2008-09-21 12:21:25 UTC (rev 152)
@@ -77,7 +77,7 @@
IdMapper ownedIdMapper = ownedIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
// Storing information about this relation
- mainGenerator.getEntitiesConfigurations().get(entityName).addOneToOneNotOwningRelation(name, owningReferencePropertyName,
+ mainGenerator.getEntitiesConfigurations().get(entityName).addToOneNotOwningRelation(name, owningReferencePropertyName,
referencedEntityName, ownedIdMapper);
// Adding mapper for the id
Modified: trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java 2008-09-19 14:51:22 UTC (rev 151)
+++ trunk/src/main/org/jboss/envers/entities/EntitiesConfigurations.java 2008-09-21 12:21:25 UTC (rev 152)
@@ -59,7 +59,7 @@
// 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.getRelationType() == RelationType.TO_ONE ||
- relDesc.getRelationType() == RelationType.ONE_TO_MANY_DETACHED) {
+ relDesc.getRelationType() == RelationType.TO_MANY_MIDDLE) {
for (RelationDescription other : entitiesConfigurations.get(relDesc.getToEntityName()).getRelationsIterator()) {
if (relDesc.getFromPropertyName().equals(other.getMappedByPropertyName()) &&
(entityName.equals(other.getToEntityName()))) {
Modified: trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-09-19 14:51:22 UTC (rev 151)
+++ trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-09-21 12:21:25 UTC (rev 152)
@@ -55,26 +55,25 @@
toEntityName, null, idMapper));
}
- public void addOneToOneNotOwningRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName,
+ public void addToOneNotOwningRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName,
IdMapper idMapper) {
- relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.ONE_TO_ONE,
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.TO_ONE_NOT_OWNING,
toEntityName, mappedByPropertyName, idMapper));
}
- public void addOneToManyAttachedRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName,
+ public void addToManyNotOwningRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName,
IdMapper idMapper) {
- relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.ONE_TO_MANY,
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.TO_MANY_NOT_OWNING,
toEntityName, mappedByPropertyName, idMapper));
}
- public void addOneToManyDetachedRelation(String fromPropertyName, String toEntityName) {
- relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.ONE_TO_MANY_DETACHED,
+ public void addToManyMiddleRelation(String fromPropertyName, String toEntityName) {
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.TO_MANY_MIDDLE,
toEntityName, null, null));
}
- public void addManyToManyNotOwningRelation(String fromPropertyName, String mappedByPropertyName,
- String toEntityName) {
- relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.MANY_TO_MANY_NOT_OWNING,
+ public void addToManyMiddleNotOwningRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName) {
+ relations.put(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.TO_MANY_MIDDLE_NOT_OWNING,
toEntityName, mappedByPropertyName, null));
}
Modified: trunk/src/main/org/jboss/envers/entities/RelationType.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/RelationType.java 2008-09-19 14:51:22 UTC (rev 151)
+++ trunk/src/main/org/jboss/envers/entities/RelationType.java 2008-09-21 12:21:25 UTC (rev 152)
@@ -24,12 +24,31 @@
package org.jboss.envers.entities;
/**
+ * Type of a relation between two entities.
* @author Adam Warski (adam at warski dot org)
*/
public enum RelationType {
+ /**
+ * A single-reference-valued relation. The entity owns the relation.
+ */
TO_ONE,
- ONE_TO_ONE,
- ONE_TO_MANY,
- ONE_TO_MANY_DETACHED,
- MANY_TO_MANY_NOT_OWNING
+ /**
+ * A single-reference-valued relation. The entity doesn't own the relation. It is directly mapped in the related
+ * entity.
+ */
+ TO_ONE_NOT_OWNING,
+ /**
+ * A collection-of-references-valued relation. The entity doesn't own the relation. It is directly mapped in the
+ * related entity.
+ */
+ TO_MANY_NOT_OWNING,
+ /**
+ * A collection-of-references-valued relation. The entity owns the relation. It is mapped using a middle table.
+ */
+ TO_MANY_MIDDLE,
+ /**
+ * A collection-of-references-valued relation. The entity doesn't own the relation. It is mapped using a middle
+ * table.
+ */
+ TO_MANY_MIDDLE_NOT_OWNING
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleDummyComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleDummyComponentMapper.java 2008-09-19 14:51:22 UTC (rev 151)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleDummyComponentMapper.java 2008-09-21 12:21:25 UTC (rev 152)
@@ -1,12 +1,12 @@
package org.jboss.envers.entities.mapper.relation.component;
import org.jboss.envers.entities.EntityInstantiator;
-import org.jboss.envers.entities.mapper.relation.component.MiddleComponentMapper;
import java.util.Map;
/**
* @author Adam Warski (adam at warski dot org)
+ * @deprecated
*/
public final class MiddleDummyComponentMapper implements MiddleComponentMapper {
public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map<String, Object> data, Number revision) {
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleRelatedComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleRelatedComponentMapper.java 2008-09-19 14:51:22 UTC (rev 151)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleRelatedComponentMapper.java 2008-09-21 12:21:25 UTC (rev 152)
@@ -1,7 +1,6 @@
package org.jboss.envers.entities.mapper.relation.component;
import org.jboss.envers.entities.EntityInstantiator;
-import org.jboss.envers.entities.mapper.relation.component.MiddleComponentMapper;
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
import java.util.Map;
@@ -22,6 +21,6 @@
}
public void mapToMapFromObject(Map<String, Object> data, Object obj) {
- relatedIdData.getOriginalMapper().mapToMapFromEntity(data, obj);
+ relatedIdData.getPrefixedMapper().mapToMapFromEntity(data, obj);
}
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java 2008-09-19 14:51:22 UTC (rev 151)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java 2008-09-21 12:21:25 UTC (rev 152)
@@ -1,7 +1,6 @@
package org.jboss.envers.entities.mapper.relation.component;
import org.jboss.envers.entities.EntityInstantiator;
-import org.jboss.envers.entities.mapper.relation.component.MiddleComponentMapper;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import java.util.Map;
Modified: trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
===================================================================
--- trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-09-19 14:51:22 UTC (rev 151)
+++ trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-09-21 12:21:25 UTC (rev 152)
@@ -52,7 +52,7 @@
return;
}
- // Checks every property of the entity, if it is an "owned" relation to another entity.
+ // Checks every property of the entity, if it is an "owned" to-one relation to another entity.
// If the value of that property changed, and the relation is bi-directional, a new revision
// for the related entity is generated.
String[] propertyNames = entityPersister.getPropertyNames();
@@ -134,7 +134,7 @@
RelationDescription relDesc = verCfg.getEntCfg().getRelationDescription(event.getAffectedOwnerEntityName(),
workUnit.getReferencingPropertyName());
- // TODO: remove the null check (relation info should be added in the metadata generator)
+ // relDesc can be null if this is a collection of simple values (not a relation).
if (relDesc != null && relDesc.isBidirectional()) {
String relatedEntityName = relDesc.getToEntityName();
IdMapper relatedIdMapper = verCfg.getEntCfg().get(relatedEntityName).getIdMapper();
Modified: trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java 2008-09-19 14:51:22 UTC (rev 151)
+++ trunk/src/test/org/jboss/envers/test/integration/naming/OneToManyUnidirectionalNaming.java 2008-09-21 12:21:25 UTC (rev 152)
@@ -76,7 +76,7 @@
}
private final static String MIDDLE_VERSIONS_ENTITY_NAME =
- "org.jboss.envers.test.integration.naming.DetachedNamingTestEntity_org.jboss.envers.test.entities.StrTestEntity_UNI_NAMING_TEST_versions";
+ "UNI_NAMING_TEST_versions";
@Test
public void testTableName() {
assert "UNI_NAMING_TEST_versions".equals(
@@ -93,11 +93,12 @@
boolean id2Found = false;
while (columns.hasNext()) {
- if ("ID_1".equals(columns.next().getName())) {
+ Column column = columns.next();
+ if ("ID_1".equals(column.getName())) {
id1Found = true;
}
- if ("ID_2".equals(columns.next().getName())) {
+ if ("ID_2".equals(column.getName())) {
id2Found = true;
}
}
16 years, 1 month
JBoss Envers SVN: r151 - in trunk/src/main/org/jboss/envers: configuration and 11 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-19 10:51:22 -0400 (Fri, 19 Sep 2008)
New Revision: 151
Added:
trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractCollectionMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/BasicCollectionMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleComponentData.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleIdData.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleComponentMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleDummyComponentMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyComponentMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleRelatedComponentMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/Initializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SortedMapProxy.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
Removed:
trunk/src/main/org/jboss/envers/configuration/metadata/EntityMappingData.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/DetachedRelationQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/Initializor.java
Modified:
trunk/src/main/org/jboss/envers/VersionsReader.java
trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/ManyToManyNotOwningMapper.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/lazy/DetachedRelationInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyAttachedInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/ListProxy.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/MapProxy.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SetProxy.java
trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
trunk/src/main/org/jboss/envers/exception/NotVersionedException.java
trunk/src/main/org/jboss/envers/exception/RevisionDoesNotExistException.java
trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java
Log:
ENVERS-42, ENVERS-44: initial support of redesigned collection handling, ENVERS-50: merging patch
Modified: trunk/src/main/org/jboss/envers/VersionsReader.java
===================================================================
--- trunk/src/main/org/jboss/envers/VersionsReader.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/VersionsReader.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -40,7 +40,7 @@
* @return The found entity instance at the given revision (its properties may be partially filled
* if not all properties are versioned) or null, if an entity with that id didn't exist at that
* revision.
- * @throws IllegalArgumentException If cls, primaryKey is null or revision is less or equal to 0.
+ * @throws IllegalArgumentException If cls or primaryKey is null or revision is less or equal to 0.
* @throws NotVersionedException When entities of the given class are not versioned.
* @throws IllegalStateException If the associated entity manager is closed.
*/
@@ -48,18 +48,13 @@
IllegalArgumentException, NotVersionedException, IllegalStateException;
/**
- * Get revisions, at which an entity was modified.
- * <b>Warning!</b> Only revisions, at which properties that the entity "owns" changed will be returned.
- * Properties not owned by an entity are:
- * <ul>
- * <li>@OneToOne(mappedBy="...")</li>
- * <li>@OneToMany</li>
- * </ul>
+ * Get a list of revision numbers, at which an entity was modified.
* @param cls Class of the entity.
* @param primaryKey Primary key of the entity.
- * @return A list of revision numbers, at which the entity was modified, sorted in ascending order.
+ * @return A list of revision numbers, at which the entity was modified, sorted in ascending order (so older
+ * revisions come first).
* @throws NotVersionedException When entities of the given class are not versioned.
- * @throws IllegalArgumentException If cls, primaryKey is null.
+ * @throws IllegalArgumentException If cls or primaryKey is null.
* @throws IllegalStateException If the associated entity manager is closed.
*/
List<Number> getRevisions(Class<?> cls, Object primaryKey)
@@ -78,8 +73,8 @@
/**
* Gets the revision number, that corresponds to the given date. More precisely, returns
- * the number of the highest revision, which was created before the given date. So:
- * <code>getRevisionDate(getRevisionNumberForDate(date)) < date</code> and
+ * the number of the highest revision, which was created on or before the given date. So:
+ * <code>getRevisionDate(getRevisionNumberForDate(date)) <= date</code> and
* <code>getRevisionDate(getRevisionNumberForDate(date)+1) > date</code>.
* @param date Date for which to get the revision.
* @return Revision number corresponding to the given date.
Modified: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -94,12 +94,12 @@
try {
cfg.addDocument(writer.write(xmlMappingData.getMainXmlMapping()));
// TODO
- //writeDocument(xmlMappingData.getMainXmlMapping());
+ writeDocument(xmlMappingData.getMainXmlMapping());
for (Document additionalMapping : xmlMappingData.getAdditionalXmlMappings()) {
cfg.addDocument(writer.write(additionalMapping));
// TODO
- //writeDocument(additionalMapping);
+ writeDocument(additionalMapping);
}
} catch (DocumentException e) {
throw new MappingException(e);
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -18,7 +18,7 @@
* Generates metadata for basic properties: immutable types (including enums) and components
* @author Adam Warski (adam at warski dot org)
*/
-public class BasicMetadataGenerator {
+public final class BasicMetadataGenerator {
private final VersionsMetadataGenerator mainGenerator;
BasicMetadataGenerator(VersionsMetadataGenerator versionsMetadataGenerator) {
@@ -28,9 +28,11 @@
@SuppressWarnings({"unchecked"})
void addSimpleValue(Element parent, String name, Value value, SimpleMapperBuilder mapper,
ModificationStore store, boolean key) {
- Element prop_mapping = MetadataTools.addProperty(parent, name,
- value.getType().getName(), key);
- MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
+ if (parent != null) {
+ Element prop_mapping = MetadataTools.addProperty(parent, name,
+ value.getType().getName(), key);
+ MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
+ }
// A null mapper means that we only want to add xml mappings (while building the id mapping)
if (mapper != null) {
@@ -41,23 +43,25 @@
@SuppressWarnings({"unchecked"})
void addEnumValue(Element parent, String name, Value value, SimpleMapperBuilder mapper,
ModificationStore store) {
- Element prop_mapping = parent.addElement("property");
- prop_mapping.addAttribute("name", name);
+ if (parent != null) {
+ Element prop_mapping = parent.addElement("property");
+ prop_mapping.addAttribute("name", name);
- CustomType propertyType = (CustomType) value.getType();
+ CustomType propertyType = (CustomType) value.getType();
- Element type_mapping = prop_mapping.addElement("type");
- type_mapping.addAttribute("name", propertyType.getName());
+ 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_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]));
+ Element type_param2 = type_mapping.addElement("param");
+ type_param2.addAttribute("name", "type");
+ type_param2.setText(Integer.toString(propertyType.sqlTypes(null)[0]));
- MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
+ MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
+ }
mapper.add(name, store);
}
@@ -75,25 +79,27 @@
Element component_mapping = null;
Component prop_component = (Component) value;
- 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(name)) {
- component_mapping = child;
- break;
+ if (parent != null) {
+ 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(name)) {
+ component_mapping = child;
+ break;
+ }
}
- }
- if (component_mapping == null) {
- throw new VersionsException("Element for component not found during second pass!");
+ 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", name);
+
+ addComponentClassName(component_mapping, prop_component);
}
- } else {
- component_mapping = parent.addElement("component");
- component_mapping.addAttribute("name", name);
-
- addComponentClassName(component_mapping, prop_component);
}
CompositeMapperBuilder componentMapper = mapper.addComposite(name);
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -3,28 +3,50 @@
import org.hibernate.mapping.*;
import org.hibernate.mapping.Collection;
import org.hibernate.MappingException;
+import org.hibernate.type.*;
import org.jboss.envers.entities.mapper.CompositeMapperBuilder;
import org.jboss.envers.entities.mapper.relation.*;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.SetProxy;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.ListProxy;
+import org.jboss.envers.entities.mapper.relation.query.MiddleTableQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.component.MiddleDummyComponentMapper;
+import org.jboss.envers.entities.mapper.relation.component.MiddleRelatedComponentMapper;
+import org.jboss.envers.entities.mapper.relation.component.MiddleSimpleComponentMapper;
import org.jboss.envers.entities.mapper.id.IdMapper;
import org.jboss.envers.entities.EntityConfiguration;
import org.jboss.envers.entities.IdMappingData;
import org.jboss.envers.tools.Tools;
import org.jboss.envers.tools.StringTools;
+import org.jboss.envers.ModificationStore;
import org.dom4j.Element;
import java.util.*;
+import java.util.Set;
+import java.util.List;
/**
* Generates metadata for collection-valued properties.
* @author Adam Warski (adam at warski dot org)
*/
-public class CollectionMetadataGenerator {
+public final class CollectionMetadataGenerator {
private final VersionsMetadataGenerator mainGenerator;
CollectionMetadataGenerator(VersionsMetadataGenerator versionsMetadataGenerator) {
mainGenerator = versionsMetadataGenerator;
}
+ void addCollection(String name, Collection value, CompositeMapperBuilder currentMapper,
+ String entityName, EntityXmlMappingData xmlMappingData) {
+ Type type = value.getType();
+
+ if ((type instanceof BagType || type instanceof SetType) &&
+ (value.getElement() instanceof OneToMany)) {
+ addOneToManyAttached(name, value, currentMapper, entityName);
+ } else {
+ addWithMiddleTable(name, value, currentMapper, entityName, xmlMappingData);
+ }
+ }
+
@SuppressWarnings({"unchecked"})
private String getMappedBy(Collection collectionValue) {
Iterator<Property> assocClassProps =
@@ -43,22 +65,37 @@
}
@SuppressWarnings({"unchecked"})
- void addOneToManyAttached(String name, Value value, CompositeMapperBuilder mapper, String entityName) {
- Collection propertyValue = (Collection) value;
+ private String getMappedBy(Table collectionTable, PersistentClass referencedClass) {
+ Iterator<Property> properties = referencedClass.getPropertyIterator();
+ while (properties.hasNext()) {
+ Property property = properties.next();
+ if (property.getValue() instanceof Collection) {
+ // The equality is intentional. We want to find a collection property with the same collection table.
+ //noinspection ObjectEquality
+ if (((Collection) property.getValue()).getCollectionTable() == collectionTable) {
+ return property.getName();
+ }
+ }
+ }
- String owningReferencePropertyName = getMappedBy(propertyValue);
+ return null;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void addOneToManyAttached(String name, Collection value, CompositeMapperBuilder mapper, String entityName) {
+ String owningReferencePropertyName = getMappedBy(value);
if (owningReferencePropertyName == null) {
- throw new MappingException("Unable to read the mapped by attribute for " + name);
+ throw new MappingException("Unable to read the mapped by attribute for " + name + " in " + entityName + "!");
}
EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(entityName);
if (configuration == null) {
- throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
+ throw new MappingException("Unable to read versioning configuration for " + entityName + "!");
}
IdMappingData referencingIdMapping = configuration.getIdMappingData();
- String owningEntityName = ((OneToMany) propertyValue.getElement()).getReferencedEntityName();
+ String owningEntityName = ((OneToMany) value.getElement()).getReferencedEntityName();
String lastPropertyPrefix = owningReferencePropertyName + "_";
// Generating the id mapper for the relation
@@ -73,15 +110,207 @@
name));
}
+ private String getReferencedEntityName(Collection value) {
+ if (value.getElement() instanceof ToOne) {
+ return ((ToOne) value.getElement()).getReferencedEntityName();
+ } else {
+ return null;
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void addWithMiddleTable(String name, Collection value, CompositeMapperBuilder currentMapper,
+ String entityName, EntityXmlMappingData xmlMappingData) {
+ // Generating the name of the middle table, its schema and catalog
+ // TODO: add support for @VersionsJoinTable
+ String middleTableName = value.getCollectionTable().getName();
+ String middleEntityName = middleTableName;
+ String versionsMiddleTableName = mainGenerator.getVerEntCfg().getVersionsTableName(null, middleTableName);
+ String versionsMiddleEntityName = mainGenerator.getVerEntCfg().getVersionsEntityName(middleEntityName);
+
+ String schema = value.getCollectionTable().getSchema();
+ String catalog = value.getCollectionTable().getCatalog();
+
+ // Generating the XML mapping for the middle entity, only if the relation isn't inverse.
+ // If the relation is inverse, will be later checked by comparing middleEntityXml with null.
+ Element middleEntityXml;
+ Element middleEntityXmlId;
+ Iterator<Column> middleEntityOriginalColumns;
+ if (!value.isInverse()) {
+ middleEntityXml = MetadataTools.createEntity(xmlMappingData.newAdditionalMapping(),
+ versionsMiddleEntityName, versionsMiddleTableName, schema, catalog, null);
+ middleEntityXmlId = middleEntityXml.addElement("composite-id");
+ middleEntityOriginalColumns = value.getCollectionTable().getColumnIterator();
+ } else {
+ middleEntityXml = null;
+ middleEntityXmlId = null;
+ middleEntityOriginalColumns = null;
+ }
+
+ // ******
+ // Generating the mapping for the referencing entity (it must be an entity).
+ // ******
+ EntityConfiguration referencingConfiguration = mainGenerator.getEntitiesConfigurations().get(entityName);
+ if (referencingConfiguration == null) {
+ throw new MappingException("Unable to read versioning configuration for " + entityName + "!");
+ }
+
+ // Getting the id-mapping data of the referencing entity (the entity that "owns" this collection).
+ IdMappingData referencingIdMapping = referencingConfiguration.getIdMappingData();
+
+ // Null if this collection doesn't reference an entity.
+ String referencedEntityName = getReferencedEntityName(value);
+ // Only valid for an inverse relation; null otherwise.
+ String mappedBy;
+
+ String referencingPrefix;
+ // Only valid if referencedEntityName isn't null.
+ String referencedPrefix;
+
+ if (value.isInverse()) {
+ // If the relation is inverse, then referencedEntityName is not null.
+ mappedBy = getMappedBy(value.getCollectionTable(), mainGenerator.getCfg().getClassMapping(referencedEntityName));
+ if (mappedBy == null) {
+ throw new MappingException("Unable to read the mapped by attribute for " + name);
+ }
+
+ referencingPrefix = mappedBy + "_";
+ referencedPrefix = StringTools.getLastComponent(referencedEntityName) + "_";
+ } else {
+ mappedBy = null;
+
+ referencingPrefix = StringTools.getLastComponent(entityName) + "_";
+ referencedPrefix = name + "_";
+ }
+
+ // Storing the id data of the referencing entity: original mapper, prefixed mapper and entity name.
+ MiddleIdData referencingIdData = new MiddleIdData(
+ referencingIdMapping.getIdMapper(),
+ referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
+ entityName,
+ mainGenerator.getVerEntCfg().getVersionsEntityName(entityName));
+
+ // Creating a query generator builder, to which additional id data will be added, in case this collection
+ // references some entities (either from the element or index). At the end, this will be used to build
+ // a query generator to read the raw data collection from the middle table.
+ QueryGeneratorBuilder queryGeneratorBuilder = new QueryGeneratorBuilder(mainGenerator.getVerEntCfg(),
+ referencingIdData, versionsMiddleEntityName);
+
+ // Adding the XML mapping for the referencing entity, if the relation isn't inverse.
+ if (middleEntityXml != null) {
+ middleEntityXmlId.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
+
+ Element properties = (Element) referencingIdMapping.getXmlRelationMapping().clone();
+ MetadataTools.prefixNamesInPropertyElement(properties, referencingPrefix, middleEntityOriginalColumns, true);
+ for (Element idProperty : (java.util.List<Element>) properties.elements()) {
+ middleEntityXmlId.add((Element) idProperty.clone());
+ }
+
+ // Adding the revision number as a foreign key to the revision info entity to the composite id of the
+ // middle table.
+ mainGenerator.addRevisionInfoRelation(middleEntityXmlId);
+
+ // Adding the revision type property to the entity xml.
+ mainGenerator.addRevisionType(middleEntityXml);
+ }
+
+ // ******
+ // Generating the element mapping.
+ // ******
+ MiddleComponentData elementComponentData = addValueToMiddleTable(value.getElement(), middleEntityXmlId,
+ middleEntityOriginalColumns, queryGeneratorBuilder, referencedPrefix);
+
+ // ******
+ // Optionally, generating the index mapping.
+ // ******
+ MiddleComponentData indexComponentData;
+ if (value instanceof IndexedCollection) {
+ IndexedCollection indexedValue = (IndexedCollection) value;
+ indexComponentData = null;
+ // TODO
+ } else {
+ // No index - creating a dummy mapper.
+ indexComponentData = new MiddleComponentData(new MiddleDummyComponentMapper(),
+ queryGeneratorBuilder.getCurrentIndex());
+ }
+
+ // ******
+ // Generating the property mapper.
+ // ******
+
+ // Building the query generator.
+ MiddleTableQueryGenerator queryGenerator = queryGeneratorBuilder.build();
+
+ // Checking the type of the collection and adding an appropriate mapper.
+ Type type = value.getType();
+ if (type instanceof SetType) {
+ currentMapper.addComposite(name, new BasicCollectionMapper<Set>(mainGenerator.getVerEntCfg(),
+ versionsMiddleEntityName, referencingIdData, HashSet.class, SetProxy.class, queryGenerator,
+ name, elementComponentData));
+ } else if (type instanceof BagType) {
+ currentMapper.addComposite(name, new BasicCollectionMapper<List>(mainGenerator.getVerEntCfg(),
+ versionsMiddleEntityName, referencingIdData, ArrayList.class, ListProxy.class, queryGenerator,
+ name, elementComponentData));
+ } else {
+ throw new RuntimeException();
+ }
+ }
+
+ /**
+ *
+ * @param value Value, which should be mapped to the middle-table, either as a relation to another entity,
+ * or as a simple value.
+ * @param middleEntityXml If not <code>null</code>, xml mapping for this value is added to this element.
+ * @param middleEntityOriginalColumns If <code>middleEntityXml</code> is not null, this iterator is used
+ * to read column names for the generated xml mapping.
+ * @param queryGeneratorBuilder In case <code>value</code> is a relation to another entity, information about it
+ * should be added to the given.
+ * @param prefix Prefix for proeprty names of related entities identifiers.
+ * @return Data for mapping this component.
+ */
+ private MiddleComponentData addValueToMiddleTable(Value value, Element middleEntityXml,
+ Iterator<Column> middleEntityOriginalColumns,
+ QueryGeneratorBuilder queryGeneratorBuilder,
+ String prefix) {
+ Type type = value.getType();
+ if (type instanceof ManyToOneType) {
+ ToOne toOneValue = (ToOne) value;
+ String referencedEntityName = toOneValue.getReferencedEntityName();
+ IdMappingData referencedIdMapping = mainGenerator.getEntitiesConfigurations().get(
+ toOneValue.getReferencedEntityName()).getIdMappingData();
+
+ // Storing the id data of the referenced entity: original mapper, prefixed mapper and entity name.
+ IdMapper referencedPrefixedIdMapper = referencedIdMapping.getIdMapper().prefixMappedProperties(prefix);
+ MiddleIdData referencedIdData = new MiddleIdData(
+ referencedIdMapping.getIdMapper(),
+ referencedPrefixedIdMapper,
+ referencedEntityName,
+ mainGenerator.getVerEntCfg().getVersionsEntityName(referencedEntityName));
+ // And adding it to the generator builder.
+ queryGeneratorBuilder.addRelation(referencedIdData);
+
+ return new MiddleComponentData(new MiddleRelatedComponentMapper(referencedIdData),
+ queryGeneratorBuilder.getCurrentIndex());
+ } else if (type instanceof ImmutableType || type instanceof MutableType) {
+ // TODO: add support for enums, components, custom types
+ mainGenerator.getBasicMetadataGenerator().addSimpleValue(middleEntityXml, "element", value, null, ModificationStore.FULL, true);
+
+ return new MiddleComponentData(new MiddleSimpleComponentMapper(mainGenerator.getVerEntCfg(), "element"),
+ queryGeneratorBuilder.getCurrentIndex());
+ } else {
+ // TODO: throw an exception
+ throw new RuntimeException();
+ }
+ }
+
private String getMiddleEntityName(String entityName, String referencedEntityName, ManyToOne mto) {
return entityName + "_" + referencedEntityName + "_" + mto.getTable().getName();
}
@SuppressWarnings({"unchecked"})
- void addOneToManyDetached(String name, Value value, CompositeMapperBuilder mapper, String entityName,
+ private void addOneToManyDetached(String name, Collection value, CompositeMapperBuilder mapper, String entityName,
EntityXmlMappingData xmlMappingData) {
- Collection propertyValue = (Collection) value;
- ManyToOne mto = (ManyToOne) propertyValue.getElement();
+ ManyToOne mto = (ManyToOne) value.getElement();
String referencedEntityName = mto.getReferencedEntityName();
@@ -141,27 +370,9 @@
mainGenerator.getEntitiesConfigurations().get(referencedEntityName).getIdMapper()));
}
- @SuppressWarnings({"unchecked"})
- private String getMappedBy(Table collectionTable, PersistentClass referencedClass) {
- Iterator<Property> properties = referencedClass.getPropertyIterator();
- while (properties.hasNext()) {
- Property property = properties.next();
- if (property.getValue() instanceof Collection) {
- // The equality is intentional. We want to find a collection property with the same collection table.
- //noinspection ObjectEquality
- if (((Collection) property.getValue()).getCollectionTable() == collectionTable) {
- return property.getName();
- }
- }
- }
+ private void addManyToManyNotOwning(String name, Collection value, CompositeMapperBuilder mapper, String entityName) {
+ ManyToOne mto = (ManyToOne) value.getElement();
- return null;
- }
-
- void addManyToManyNotOwning(String name, Value value, CompositeMapperBuilder mapper, String entityName) {
- Collection propertyValue = (Collection) value;
- ManyToOne mto = (ManyToOne) propertyValue.getElement();
-
String referencedEntityName = mto.getReferencedEntityName();
EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(entityName);
@@ -174,7 +385,7 @@
throw new MappingException("A versioned relation to a non-versioned entity " + referencedEntityName + "!");
}
- String mappedBy = getMappedBy(propertyValue.getCollectionTable(), mainGenerator.getCfg().getClassMapping(referencedEntityName));
+ String mappedBy = getMappedBy(value.getCollectionTable(), mainGenerator.getCfg().getClassMapping(referencedEntityName));
if (mappedBy == null) {
throw new MappingException("Unable to read the mapped by attribute for " + name);
}
Deleted: trunk/src/main/org/jboss/envers/configuration/metadata/EntityMappingData.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/EntityMappingData.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/EntityMappingData.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- *
- * See the copyright.txt in the distribution for a full listing of individual
- * contributors. 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 java.util.List;
-import java.util.ArrayList;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class EntityMappingData {
- private Document mainMapping;
- private List<Document> additionalMappings;
-
- public EntityMappingData() {
- mainMapping = DocumentHelper.createDocument();
- additionalMappings = new ArrayList<Document>();
- }
-
- public Document getMainMapping() {
- return mainMapping;
- }
-
- public List<Document> getAdditionalMappings() {
- return additionalMappings;
- }
-
- public Document newAdditionalMapping() {
- Document additionalMapping = DocumentHelper.createDocument();
- additionalMappings.add(additionalMapping);
-
- return additionalMapping;
- }
-}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -22,7 +22,7 @@
* Generates metadata for primary identifiers (ids) of versions entities.
* @author Adam Warski (adam at warski dot org)
*/
-public class IdMetadataGenerator {
+public final class IdMetadataGenerator {
private final VersionsMetadataGenerator mainGenerator;
IdMetadataGenerator(VersionsMetadataGenerator versionsMetadataGenerator) {
Added: trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,58 @@
+package org.jboss.envers.configuration.metadata;
+
+import org.jboss.envers.entities.mapper.relation.MiddleIdData;
+import org.jboss.envers.entities.mapper.relation.query.MiddleTableQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.query.OneEntityQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.query.TwoEntityQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.query.ThreeEntityQueryGenerator;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Builds query generators, for reading collection middle tables, along with any related entities.
+ * The related entities information can be added gradually, and when complete, the query generator can be built.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class QueryGeneratorBuilder {
+ private final VersionsEntitiesConfiguration verEntCfg;
+ private final MiddleIdData referencingIdData;
+ private final String versionsMiddleEntityName;
+ private final List<MiddleIdData> idDatas;
+
+ QueryGeneratorBuilder(VersionsEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData,
+ String versionsMiddleEntityName) {
+ this.verEntCfg = verEntCfg;
+ this.referencingIdData = referencingIdData;
+ this.versionsMiddleEntityName = versionsMiddleEntityName;
+
+ idDatas = new ArrayList<MiddleIdData>();
+ }
+
+ void addRelation(MiddleIdData idData) {
+ idDatas.add(idData);
+ }
+
+ MiddleTableQueryGenerator build() {
+ if (idDatas.size() == 0) {
+ return new OneEntityQueryGenerator(verEntCfg, versionsMiddleEntityName, referencingIdData);
+ } else if (idDatas.size() == 1) {
+ return new TwoEntityQueryGenerator(verEntCfg, versionsMiddleEntityName, referencingIdData,
+ idDatas.get(0));
+ } else if (idDatas.size() == 1) {
+ return new ThreeEntityQueryGenerator(verEntCfg, versionsMiddleEntityName, referencingIdData,
+ idDatas.get(0), idDatas.get(1));
+ } else {
+ throw new IllegalStateException("Illegal number of related entities.");
+ }
+ }
+
+ /**
+ * @return Current index of data in the array, which will be the element of a list, returned when executing a query
+ * generated by the built query generator.
+ */
+ int getCurrentIndex() {
+ return idDatas.size();
+ }
+}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -16,7 +16,7 @@
* Generates metadata for to-one relations (reference-valued properties).
* @author Adam Warski (adam at warski dot org)
*/
-public class ToOneRelationMetadataGenerator {
+public final class ToOneRelationMetadataGenerator {
private final VersionsMetadataGenerator mainGenerator;
ToOneRelationMetadataGenerator(VersionsMetadataGenerator versionsMetadataGenerator) {
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -46,7 +46,7 @@
* @author Adam Warski (adam at warski dot org)
* @author Sebastian Komander
*/
-public class VersionsMetadataGenerator {
+public final class VersionsMetadataGenerator {
private final Configuration cfg;
private final GlobalConfiguration globalCfg;
private final VersionsEntitiesConfiguration verEntCfg;
@@ -57,10 +57,10 @@
private final CollectionMetadataGenerator collectionMetadataGenerator;
private final ToOneRelationMetadataGenerator toOneRelationMetadataGenerator;
- private Map<String, EntityConfiguration> entitiesConfigurations;
+ private final Map<String, EntityConfiguration> entitiesConfigurations;
// Map entity name -> (join descriptor -> element describing the "versioned" join)
- private Map<String, Map<Join, Element>> entitiesJoins;
+ private final Map<String, Map<Join, Element>> entitiesJoins;
private YLog log = YLogManager.getLogManager().getLog(VersionsMetadataGenerator.class);
@@ -119,8 +119,8 @@
@SuppressWarnings({"unchecked"})
void addValue(Element parent, String name, Value value, CompositeMapperBuilder currentMapper,
- ModificationStore store, String entityName, EntityXmlMappingData xmlMappingData,
- boolean firstPass) {
+ ModificationStore store, String entityName, EntityXmlMappingData xmlMappingData,
+ boolean firstPass) {
Type type = value.getType();
if (type instanceof ComponentType) {
@@ -139,48 +139,34 @@
if (firstPass) {
basicMetadataGenerator.addEnumValue(parent, name, value, currentMapper, store);
}
- } else if (type instanceof ManyToOneType) {
- // only second pass
- if (!firstPass) {
- toOneRelationMetadataGenerator.addToOne(parent, name, value, currentMapper, entityName);
- }
- } else if (type instanceof OneToOneType) {
- // only second pass
- if (!firstPass) {
- toOneRelationMetadataGenerator.addOneToOneNotOwning(name, value, currentMapper, entityName);
- }
- } else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(
- type.getClass().getName())) {
+ } else if (type instanceof CustomType &&
+ ("org.hibernate.type.PrimitiveCharacterArrayClobType".equals(type.getName()) ||
+ "org.hibernate.type.StringClobType".equals(type.getName()))) {
// only first pass
if (firstPass) {
basicMetadataGenerator.addSimpleValue(parent, name, value, currentMapper, store, false);
}
- } else if (type instanceof CustomType &&
- ("org.hibernate.type.PrimitiveCharacterArrayClobType".equals(type.getName()) ||
- "org.hibernate.type.StringClobType".equals(type.getName()))) {
+ } else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(
+ type.getClass().getName())) {
// only first pass
if (firstPass) {
basicMetadataGenerator.addSimpleValue(parent, name, value, currentMapper, store, false);
}
- } else if ((type instanceof BagType || type instanceof SetType) &&
- ((((Collection) value).getElement() instanceof OneToMany))) {
+ } else if (type instanceof ManyToOneType) {
// only second pass
if (!firstPass) {
- collectionMetadataGenerator.addOneToManyAttached(name, value, currentMapper, entityName);
+ toOneRelationMetadataGenerator.addToOne(parent, name, value, currentMapper, entityName);
}
- } else if ((type instanceof BagType || type instanceof SetType) &&
- ((((Collection) value).getElement() instanceof ManyToOne)) &&
- !((Collection) value).isInverse()) {
+ } else if (type instanceof OneToOneType) {
// only second pass
if (!firstPass) {
- collectionMetadataGenerator.addOneToManyDetached(name, value, currentMapper, entityName, xmlMappingData);
+ toOneRelationMetadataGenerator.addOneToOneNotOwning(name, value, currentMapper, entityName);
}
- } else if ((type instanceof BagType || type instanceof SetType) &&
- ((((Collection) value).getElement() instanceof ManyToOne)) &&
- ((Collection) value).isInverse()) {
+ } else if (type instanceof CollectionType) {
// only second pass
if (!firstPass) {
- collectionMetadataGenerator.addManyToManyNotOwning(name, value, currentMapper, entityName);
+ collectionMetadataGenerator.addCollection(name, (Collection) value, currentMapper, entityName,
+ xmlMappingData);
}
} else {
String message = "Type not supported for versioning: " + type.getClass().getName() +
@@ -395,26 +381,10 @@
return basicMetadataGenerator;
}
- IdMetadataGenerator getIdMetadataGenerator() {
- return idMetadataGenerator;
- }
-
- CollectionMetadataGenerator getCollectionMetadataGenerator() {
- return collectionMetadataGenerator;
- }
-
- ToOneRelationMetadataGenerator getToOneRelationMetadataGenerator() {
- return toOneRelationMetadataGenerator;
- }
-
Configuration getCfg() {
return cfg;
}
- GlobalConfiguration getGlobalCfg() {
- return globalCfg;
- }
-
VersionsEntitiesConfiguration getVerEntCfg() {
return verEntCfg;
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -40,7 +40,7 @@
* @param oldObj Old state of the entity.
* @return True if there are any differences between the states represented by newObj and oldObj.
*/
- public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj);
+ boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj);
/**
* Maps properties from the given map to the given object.
@@ -51,8 +51,8 @@
* @param versionsReader VersionsReader for reading relations
* @param revision Revision at which the object is read, for reading relations
*/
- public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey,
- VersionsReaderImplementor versionsReader, Number revision);
+ void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey,
+ VersionsReaderImplementor versionsReader, Number revision);
/**
* Maps collection changes
@@ -62,7 +62,7 @@
* @param id Id of the object owning the collection.
* @return List of changes that need to be performed on the persistent store.
*/
- public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
- PersistentCollection newColl,
- Serializable oldColl, Serializable id);
+ List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
+ PersistentCollection newColl,
+ Serializable oldColl, Serializable id);
}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractCollectionMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractCollectionMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractCollectionMapper.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,90 @@
+package org.jboss.envers.entities.mapper.relation;
+
+import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
+import org.jboss.envers.entities.mapper.PropertyMapper;
+import org.jboss.envers.RevisionType;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.hibernate.collection.PersistentCollection;
+
+import java.util.*;
+import java.io.Serializable;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public abstract class AbstractCollectionMapper implements PropertyMapper {
+ private final VersionsEntitiesConfiguration verEntCfg;
+ private final String versionsMiddleEntityName;
+ private final String collectionReferencingPropertyName;
+ private final MiddleIdData referencingIdData;
+
+ protected AbstractCollectionMapper(VersionsEntitiesConfiguration verEntCfg, String versionsMiddleEntityName,
+ String collectionReferencingPropertyName, MiddleIdData referencingIdData) {
+ this.verEntCfg = verEntCfg;
+ this.versionsMiddleEntityName = versionsMiddleEntityName;
+ this.collectionReferencingPropertyName = collectionReferencingPropertyName;
+ this.referencingIdData = referencingIdData;
+ }
+
+ protected abstract Collection getNewCollectionContent(PersistentCollection newCollection);
+ protected abstract Collection getOldCollectionContent(Serializable oldCollection);
+
+ /**
+ * Maps the changed collection element to the given map.
+ * @param data Where to map the data.
+ * @param changed The changed collection element to map.
+ */
+ protected abstract void mapToMapFromObject(Map<String, Object> data, Object changed);
+
+ private void addCollectionChanges(List<PersistentCollectionChangeData> collectionChanges, Set<Object> changed,
+ RevisionType revisionType, Serializable id) {
+ for (Object changedObj : 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, changedObj));
+ // Mapping the collection owner's id.
+ referencingIdData.getPrefixedMapper().mapToMapFromId(originalId, id);
+
+ // Mapping collection element and index (if present).
+ mapToMapFromObject(originalId, changedObj);
+
+ 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>();
+
+ // Comparing new and old collection content.
+ Collection newCollection = getNewCollectionContent(newColl);
+ Collection oldCollection = getOldCollectionContent(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;
+ }
+
+ public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj) {
+ // Changes are mapped in the "mapCollectionChanges" method.
+ return false;
+ }
+}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -27,7 +27,7 @@
import org.jboss.envers.tools.reflection.ReflectionTools;
import org.jboss.envers.entities.mapper.relation.lazy.proxy.ListProxy;
import org.jboss.envers.entities.mapper.relation.lazy.proxy.SetProxy;
-import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
+import org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor;
import org.jboss.envers.entities.mapper.relation.lazy.proxy.MapProxy;
import org.jboss.envers.entities.mapper.PropertyMapper;
import org.jboss.envers.exception.VersionsException;
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/BasicCollectionMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/BasicCollectionMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/BasicCollectionMapper.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,86 @@
+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.query.MiddleTableQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor;
+import org.jboss.envers.entities.mapper.relation.lazy.initializor.BasicCollectionInitializor;
+import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.tools.reflection.ReflectionTools;
+import org.jboss.envers.exception.VersionsException;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.property.Setter;
+
+import java.util.Map;
+import java.util.List;
+import java.util.Collection;
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class BasicCollectionMapper<T extends Collection> extends AbstractCollectionMapper implements PropertyMapper {
+ private final Class<? extends T> collectionClass;
+ private final MiddleTableQueryGenerator queryGenerator;
+ private final String propertyName;
+ private final MiddleComponentData elementComponentData;
+
+ private final Constructor<? extends T> proxyConstructor;
+
+ public BasicCollectionMapper(VersionsEntitiesConfiguration verEntCfg, String versionsMiddleEntityName,
+ MiddleIdData referencingIdData,
+ Class<? extends T> collectionClass, Class<? extends T> proxyClass,
+ MiddleTableQueryGenerator queryGenerator,
+ String propertyName, MiddleComponentData elementComponentData) {
+ super(verEntCfg, versionsMiddleEntityName, propertyName, referencingIdData);
+ this.collectionClass = collectionClass;
+ this.queryGenerator = queryGenerator;
+ this.propertyName = propertyName;
+ this.elementComponentData = elementComponentData;
+
+ try {
+ proxyConstructor = proxyClass.getConstructor(Initializor.class);
+ } catch (NoSuchMethodException e) {
+ throw new VersionsException(e);
+ }
+ }
+
+ public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey,
+ VersionsReaderImplementor versionsReader, Number revision) {
+ // Creating the initializator and passing to the proxy, which will use it to initialize the collection
+ // when and if it is accessed.
+ Initializor<? extends Collection> collectionInitializor = new BasicCollectionInitializor<T>(verCfg,
+ versionsReader, queryGenerator, primaryKey, revision, collectionClass, elementComponentData);
+
+ Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyName);
+ try {
+ setter.set(obj, proxyConstructor.newInstance(collectionInitializor), null);
+ } catch (InstantiationException e) {
+ throw new VersionsException(e);
+ } catch (IllegalAccessException e) {
+ throw new VersionsException(e);
+ } catch (InvocationTargetException e) {
+ throw new VersionsException(e);
+ }
+ }
+
+ protected Collection getNewCollectionContent(PersistentCollection newCollection) {
+ return (Collection) newCollection;
+ }
+
+ protected Collection getOldCollectionContent(Serializable oldCollection) {
+ if (oldCollection instanceof Map) {
+ return ((Map) oldCollection).keySet();
+ } else {
+ return (Collection) oldCollection;
+ }
+ }
+
+ protected void mapToMapFromObject(Map<String, Object> data, Object changed) {
+ elementComponentData.getComponentMapper().mapToMapFromObject(data, changed);
+ }
+}
Deleted: trunk/src/main/org/jboss/envers/entities/mapper/relation/DetachedRelationQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/DetachedRelationQueryGenerator.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/DetachedRelationQueryGenerator.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -1,116 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- *
- * See the copyright.txt in the distribution for a full listing of individual
- * contributors. 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.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;
- }
-}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/ManyToManyNotOwningMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/ManyToManyNotOwningMapper.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/ManyToManyNotOwningMapper.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -25,8 +25,8 @@
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.DetachedRelationInitializor;
+import org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor;
import org.jboss.envers.entities.mapper.id.IdMapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
@@ -45,7 +45,7 @@
*/
private final String referencedEntityName;
- private final DetachedRelationQueryGenerator queryGenerator;
+ // private final DetachedRelationQueryGenerator queryGenerator;
public ManyToManyNotOwningMapper(VersionsEntitiesConfiguration verEntCfg, String referencingEntityName,
String referencedEntityName, String collectionReferencingPropertyName,
@@ -56,8 +56,8 @@
this.referencedEntityName = referencedEntityName;
- queryGenerator = new DetachedRelationQueryGenerator(verEntCfg, versionsReferencedEntityName,
- versionsMiddleEntityName, referencingMiddleIdMapper, referencedMiddleIdMapper, referencedIdMapper);
+ // queryGenerator = new DetachedRelationQueryGenerator(verEntCfg, versionsReferencedEntityName,
+ // versionsMiddleEntityName, referencingMiddleIdMapper, referencedMiddleIdMapper, referencedIdMapper);
}
public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
@@ -72,11 +72,11 @@
return false;
}
- protected <T extends Collection> Initializor<T> getInitializator(VersionsConfiguration verCfg,
+ protected <T> Initializor<T> getInitializator(VersionsConfiguration verCfg,
VersionsReaderImplementor versionsReader,
Class<?> entityClass, Object primaryKey,
Number revision, Class<T> collectionClass) {
- return new DetachedRelationInitializor<T>(verCfg, referencedEntityName, queryGenerator,
- versionsReader, primaryKey, revision, collectionClass);
+ return null; //new DetachedRelationInitializor<T>(verCfg, referencedEntityName, queryGenerator,
+ // versionsReader, primaryKey, revision, collectionClass);
}
}
\ No newline at end of file
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleComponentData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleComponentData.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleComponentData.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,28 @@
+package org.jboss.envers.entities.mapper.relation;
+
+import org.jboss.envers.entities.mapper.relation.component.MiddleComponentMapper;
+
+/**
+ * A data holder for a middle relation component (which is either the collection element or index):
+ * - component mapper used to map the component to and from versions entities
+ * - an index, which specifies in which element of the array returned by the query for reading the collection the data
+ * of the component is
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class MiddleComponentData {
+ private final MiddleComponentMapper componentMapper;
+ private final int componentIndex;
+
+ public MiddleComponentData(MiddleComponentMapper componentMapper, int componentIndex) {
+ this.componentMapper = componentMapper;
+ this.componentIndex = componentIndex;
+ }
+
+ public MiddleComponentMapper getComponentMapper() {
+ return componentMapper;
+ }
+
+ public int getComponentIndex() {
+ return componentIndex;
+ }
+}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleIdData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleIdData.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleIdData.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,38 @@
+package org.jboss.envers.entities.mapper.relation;
+
+import org.jboss.envers.entities.mapper.id.IdMapper;
+
+/**
+ * A class holding information about ids, which form a virtual "relation" from a middle-table. Middle-tables are used
+ * when mapping collections.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class MiddleIdData {
+ private final IdMapper originalMapper;
+ private final IdMapper prefixedMapper;
+ private final String entityName;
+ private final String versionsEntityName;
+
+ public MiddleIdData(IdMapper originalMapper, IdMapper prefixedMapper, String entityName, String versionsEntityName) {
+ this.originalMapper = originalMapper;
+ this.prefixedMapper = prefixedMapper;
+ this.entityName = entityName;
+ this.versionsEntityName = versionsEntityName;
+ }
+
+ public IdMapper getOriginalMapper() {
+ return originalMapper;
+ }
+
+ public IdMapper getPrefixedMapper() {
+ return prefixedMapper;
+ }
+
+ public String getEntityName() {
+ return entityName;
+ }
+
+ public String getVersionsEntityName() {
+ return versionsEntityName;
+ }
+}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyAttachedMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyAttachedMapper.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyAttachedMapper.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -25,7 +25,7 @@
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.entities.mapper.relation.lazy.initializor.Initializor;
import org.jboss.envers.configuration.VersionsConfiguration;
import org.hibernate.collection.PersistentCollection;
@@ -48,7 +48,7 @@
return false;
}
- protected <T extends Collection> Initializor<T> getInitializator(VersionsConfiguration verCfg,
+ protected <T> Initializor<T> getInitializator(VersionsConfiguration verCfg,
VersionsReaderImplementor versionsReader,
Class<?> entityClass, Object primaryKey,
Number revision,
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -25,8 +25,8 @@
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.DetachedRelationInitializor;
+import org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor;
import org.jboss.envers.entities.mapper.id.IdMapper;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
@@ -57,7 +57,7 @@
private final IdMapper referencingMiddleIdMapper;
private final IdMapper referencedMiddleIdMapper;
- private final DetachedRelationQueryGenerator queryGenerator;
+ //private final DetachedRelationQueryGenerator queryGenerator;
public OneToManyDetachedMapper(VersionsEntitiesConfiguration verEntCfg, String referencingEntityName,
String referencedEntityName, String collectionReferencingPropertyName,
@@ -73,8 +73,8 @@
this.referencingMiddleIdMapper = referencingMiddleIdMapper;
this.referencedMiddleIdMapper = referencedMiddleIdMapper;
- queryGenerator = new DetachedRelationQueryGenerator(verEntCfg, versionsReferencedEntityName,
- versionsMiddleEntityName, referencingMiddleIdMapper, referencedMiddleIdMapper, referencedIdMapper);
+ //queryGenerator = new DetachedRelationQueryGenerator(verEntCfg, versionsReferencedEntityName,
+ // versionsMiddleEntityName, referencingMiddleIdMapper, referencedMiddleIdMapper, referencedIdMapper);
}
private Collection getOldCollection(Serializable oldColl) {
@@ -138,7 +138,7 @@
VersionsReaderImplementor versionsReader,
Class<?> entityClass, Object primaryKey,
Number revision, Class<T> collectionClass) {
- return new DetachedRelationInitializor<T>(verCfg, referencedEntityName, queryGenerator,
- versionsReader, primaryKey, revision, collectionClass);
+ return null;// new DetachedRelationInitializor<T>(verCfg, referencedEntityName, queryGenerator,
+ //versionsReader, primaryKey, revision, collectionClass);
}
}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleComponentMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleComponentMapper.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,27 @@
+package org.jboss.envers.entities.mapper.relation.component;
+
+import org.jboss.envers.entities.EntityInstantiator;
+
+import java.util.Map;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public interface MiddleComponentMapper {
+ /**
+ * Maps from full object data, contained in the given map, to an object.
+ * @param entityInstantiator An entity instatiator bound with an open versions reader.
+ * @param data Full object data.
+ * @param revision Revision at which the data is read.
+ * @return An object with data corresponding to the one found in the given map.
+ */
+ Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map<String, Object> data,
+ Number revision);
+
+ /**
+ * Maps from an object to the object's representation (for an entity - only its id).
+ * @param data Map to which data should be added.
+ * @param obj Object to map from.
+ */
+ void mapToMapFromObject(Map<String, Object> data, Object obj);
+}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleDummyComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleDummyComponentMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleDummyComponentMapper.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,18 @@
+package org.jboss.envers.entities.mapper.relation.component;
+
+import org.jboss.envers.entities.EntityInstantiator;
+import org.jboss.envers.entities.mapper.relation.component.MiddleComponentMapper;
+
+import java.util.Map;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class MiddleDummyComponentMapper implements MiddleComponentMapper {
+ public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map<String, Object> data, Number revision) {
+ return null;
+ }
+
+ public void mapToMapFromObject(Map<String, Object> data, Object obj) {
+ }
+}
\ No newline at end of file
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyComponentMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyComponentMapper.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,29 @@
+package org.jboss.envers.entities.mapper.relation.component;
+
+import org.jboss.envers.entities.EntityInstantiator;
+import org.jboss.envers.entities.mapper.relation.MiddleIdData;
+
+import java.util.Map;
+
+/**
+ * A component mapper for the @MapKey mapping: the value of the map's key is the id of the entity. This
+ * doesn't have an effect on the data stored in the versions tables, so <code>mapToMapFromObject</code> is
+ * empty.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class MiddleMapKeyComponentMapper implements MiddleComponentMapper {
+ private final MiddleIdData relatedIdData;
+
+ public MiddleMapKeyComponentMapper(MiddleIdData relatedIdData) {
+ this.relatedIdData = relatedIdData;
+ }
+
+ public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map<String, Object> data,
+ Number revision) {
+ return relatedIdData.getOriginalMapper().mapToIdFromMap(data);
+ }
+
+ public void mapToMapFromObject(Map<String, Object> data, Object obj) {
+ // Doing nothing.
+ }
+}
\ No newline at end of file
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleRelatedComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleRelatedComponentMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleRelatedComponentMapper.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,27 @@
+package org.jboss.envers.entities.mapper.relation.component;
+
+import org.jboss.envers.entities.EntityInstantiator;
+import org.jboss.envers.entities.mapper.relation.component.MiddleComponentMapper;
+import org.jboss.envers.entities.mapper.relation.MiddleIdData;
+
+import java.util.Map;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class MiddleRelatedComponentMapper implements MiddleComponentMapper {
+ private final MiddleIdData relatedIdData;
+
+ public MiddleRelatedComponentMapper(MiddleIdData relatedIdData) {
+ this.relatedIdData = relatedIdData;
+ }
+
+ public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map<String, Object> data,
+ Number revision) {
+ return entityInstantiator.createInstanceFromVersionsEntity(relatedIdData.getEntityName(), data, revision);
+ }
+
+ public void mapToMapFromObject(Map<String, Object> data, Object obj) {
+ relatedIdData.getOriginalMapper().mapToMapFromEntity(data, obj);
+ }
+}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,29 @@
+package org.jboss.envers.entities.mapper.relation.component;
+
+import org.jboss.envers.entities.EntityInstantiator;
+import org.jboss.envers.entities.mapper.relation.component.MiddleComponentMapper;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+
+import java.util.Map;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class MiddleSimpleComponentMapper implements MiddleComponentMapper {
+ private final String propertyName;
+ private final VersionsEntitiesConfiguration verEntCfg;
+
+ public MiddleSimpleComponentMapper(VersionsEntitiesConfiguration verEntCfg, String propertyName) {
+ this.propertyName = propertyName;
+ this.verEntCfg = verEntCfg;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map<String, Object> data, Number revision) {
+ return ((Map<String, Object>) data.get(verEntCfg.getOriginalIdPropName())).get(propertyName);
+ }
+
+ public void mapToMapFromObject(Map<String, Object> data, Object obj) {
+ data.put(propertyName, obj);
+ }
+}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/DetachedRelationInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/DetachedRelationInitializor.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/DetachedRelationInitializor.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -23,8 +23,7 @@
*/
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.mapper.relation.lazy.initializor.Initializor;
import org.jboss.envers.entities.EntityInstantiator;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
@@ -39,19 +38,19 @@
public class DetachedRelationInitializor<T> implements Initializor<T> {
private final VersionsConfiguration verCfg;
private final String entityName;
- private final DetachedRelationQueryGenerator queryGenerator;
+ //private final DetachedRelationQueryGenerator queryGenerator;
private final VersionsReaderImplementor versionsReader;
private final Object primaryKey;
private final Number revision;
private final Class<T> collectionClass;
public DetachedRelationInitializor(VersionsConfiguration verCfg, String entityName,
- DetachedRelationQueryGenerator queryGenerator,
+ //DetachedRelationQueryGenerator queryGenerator,
VersionsReaderImplementor versionsReader, Object primaryKey,
Number revision, Class<T> collectionClass) {
this.verCfg = verCfg;
this.entityName = entityName;
- this.queryGenerator = queryGenerator;
+ //this.queryGenerator = queryGenerator;
this.versionsReader = versionsReader;
this.primaryKey = primaryKey;
this.revision = revision;
@@ -62,7 +61,7 @@
public T initialize() {
EntityInstantiator entityInstantiator = new EntityInstantiator(verCfg, versionsReader);
- List queryResult = queryGenerator.getQuery(versionsReader, primaryKey, revision).list();
+ List queryResult = null;//queryGenerator.getQuery(versionsReader, primaryKey, revision).list();
T result;
try {
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyAttachedInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyAttachedInitializor.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyAttachedInitializor.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -22,7 +22,7 @@
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.entities.mapper.relation.lazy.initializor.Initializor;
import org.jboss.envers.query.VersionsRestrictions;
import org.jboss.envers.exception.VersionsException;
@@ -32,7 +32,7 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class OneToManyAttachedInitializor<T extends Collection> implements Initializor<T> {
+public class OneToManyAttachedInitializor<T> implements Initializor<T> {
private VersionsReaderImplementor versionsReader;
private Class<?> entityClass;
private String owningReferencePropertyName;
@@ -61,7 +61,8 @@
} else {
Collection result;
try {
- result = collectionClass.newInstance();
+ // TODO
+ result = (Collection) collectionClass.newInstance();
} catch (Exception e) {
throw new VersionsException(e);
}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,49 @@
+package org.jboss.envers.entities.mapper.relation.lazy.initializor;
+
+import org.jboss.envers.entities.mapper.relation.query.MiddleTableQueryGenerator;
+import org.jboss.envers.entities.EntityInstantiator;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
+
+import java.util.List;
+
+/**
+ * Initializes a persistent collection.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public abstract class AbstractCollectionInitializor<T> implements Initializor<T> {
+ private final VersionsReaderImplementor versionsReader;
+ private final MiddleTableQueryGenerator queryGenerator;
+ private final Object primaryKey;
+
+ protected final Number revision;
+ protected final EntityInstantiator entityInstantiator;
+
+ public AbstractCollectionInitializor(VersionsConfiguration verCfg,
+ VersionsReaderImplementor versionsReader,
+ MiddleTableQueryGenerator queryGenerator,
+ Object primaryKey, Number revision) {
+ this.versionsReader = versionsReader;
+ this.queryGenerator = queryGenerator;
+ this.primaryKey = primaryKey;
+ this.revision = revision;
+
+ entityInstantiator = new EntityInstantiator(verCfg, versionsReader);
+ }
+
+ protected abstract T initializeCollection(int size);
+
+ protected abstract void addToCollection(T collection, Object collectionRow);
+
+ public T initialize() {
+ List<?> collectionContent = queryGenerator.getQuery(versionsReader, primaryKey, revision).list();
+
+ T collection = initializeCollection(collectionContent.size());
+
+ for (Object collectionRow : collectionContent) {
+ addToCollection(collection, collectionRow);
+ }
+
+ return collection;
+ }
+}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,47 @@
+package org.jboss.envers.entities.mapper.relation.lazy.initializor;
+
+import org.jboss.envers.entities.mapper.relation.query.MiddleTableQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
+
+import java.util.*;
+
+/**
+ * Initializes a map.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ArrayCollectionInitializor extends AbstractCollectionInitializor<Object[]> {
+ private final MiddleComponentData elementComponentData;
+ private final MiddleComponentData indexComponentData;
+
+ public ArrayCollectionInitializor(VersionsConfiguration verCfg,
+ VersionsReaderImplementor versionsReader,
+ MiddleTableQueryGenerator queryGenerator,
+ Object primaryKey, Number revision,
+ MiddleComponentData elementComponentData,
+ MiddleComponentData indexComponentData) {
+ super(verCfg, versionsReader, queryGenerator, primaryKey, revision);
+
+ this.elementComponentData = elementComponentData;
+ this.indexComponentData = indexComponentData;
+ }
+
+ protected Object[] initializeCollection(int size) {
+ return new Object[size];
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected void addToCollection(Object[] collection, Object collectionRow) {
+ Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
+ Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
+ (Map<String, Object>) elementData, revision);
+
+ Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
+ Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
+ (Map<String, Object>) indexData, revision);
+ int index = ((Number) indexObj).intValue();
+
+ collection[index] = element;
+ }
+}
\ No newline at end of file
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,48 @@
+package org.jboss.envers.entities.mapper.relation.lazy.initializor;
+
+import org.jboss.envers.entities.mapper.relation.query.MiddleTableQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
+
+import java.util.*;
+
+/**
+ * Initializes a non-indexed java collection (set or list, eventually sorted).
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BasicCollectionInitializor<T extends Collection> extends AbstractCollectionInitializor<T> {
+ private final Class<? extends T> collectionClass;
+ private final MiddleComponentData elementComponentData;
+
+ public BasicCollectionInitializor(VersionsConfiguration verCfg,
+ VersionsReaderImplementor versionsReader,
+ MiddleTableQueryGenerator queryGenerator,
+ Object primaryKey, Number revision,
+ Class<? extends T> collectionClass,
+ MiddleComponentData elementComponentData) {
+ super(verCfg, versionsReader, queryGenerator, primaryKey, revision);
+
+ this.collectionClass = collectionClass;
+ this.elementComponentData = elementComponentData;
+ }
+
+ protected T initializeCollection(int size) {
+ try {
+ return collectionClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new VersionsException(e);
+ } catch (IllegalAccessException e) {
+ throw new VersionsException(e);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected void addToCollection(T collection, Object collectionRow) {
+ Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
+ Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
+ (Map<String, Object>) elementData, revision);
+ collection.add(element);
+ }
+}
Copied: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/Initializor.java (from rev 149, trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/Initializor.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/Initializor.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/Initializor.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -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.entities.mapper.relation.lazy.initializor;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public interface Initializor<T> {
+ T initialize();
+}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,47 @@
+package org.jboss.envers.entities.mapper.relation.lazy.initializor;
+
+import org.jboss.envers.entities.mapper.relation.query.MiddleTableQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.configuration.VersionsConfiguration;
+
+import java.util.*;
+
+/**
+ * Initializes a map.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ListCollectionInitializor extends AbstractCollectionInitializor<List> {
+ private final MiddleComponentData elementComponentData;
+ private final MiddleComponentData indexComponentData;
+
+ public ListCollectionInitializor(VersionsConfiguration verCfg,
+ VersionsReaderImplementor versionsReader,
+ MiddleTableQueryGenerator queryGenerator,
+ Object primaryKey, Number revision,
+ MiddleComponentData elementComponentData,
+ MiddleComponentData indexComponentData) {
+ super(verCfg, versionsReader, queryGenerator, primaryKey, revision);
+
+ this.elementComponentData = elementComponentData;
+ this.indexComponentData = indexComponentData;
+ }
+
+ protected List initializeCollection(int size) {
+ return new ArrayList();
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected void addToCollection(List collection, Object collectionRow) {
+ Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
+ Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
+ (Map<String, Object>) elementData, revision);
+
+ Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
+ Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
+ (Map<String, Object>) indexData, revision);
+ int index = ((Number) indexObj).intValue();
+
+ collection.set(index, element);
+ }
+}
\ No newline at end of file
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,56 @@
+package org.jboss.envers.entities.mapper.relation.lazy.initializor;
+
+import org.jboss.envers.entities.mapper.relation.query.MiddleTableQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.exception.VersionsException;
+import org.jboss.envers.configuration.VersionsConfiguration;
+
+import java.util.*;
+
+/**
+ * Initializes a map.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class MapCollectionInitializor<T extends Map<Object, Object>> extends AbstractCollectionInitializor<T> {
+ private final Class<T> collectionClass;
+ private final MiddleComponentData elementComponentData;
+ private final MiddleComponentData indexComponentData;
+
+ public MapCollectionInitializor(VersionsConfiguration verCfg,
+ VersionsReaderImplementor versionsReader,
+ MiddleTableQueryGenerator queryGenerator,
+ Object primaryKey, Number revision,
+ Class<T> collectionClass,
+ MiddleComponentData elementComponentData,
+ MiddleComponentData indexComponentData) {
+ super(verCfg, versionsReader, queryGenerator, primaryKey, revision);
+
+ this.collectionClass = collectionClass;
+ this.elementComponentData = elementComponentData;
+ this.indexComponentData = indexComponentData;
+ }
+
+ protected T initializeCollection(int size) {
+ try {
+ return collectionClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new VersionsException(e);
+ } catch (IllegalAccessException e) {
+ throw new VersionsException(e);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected void addToCollection(T collection, Object collectionRow) {
+ Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
+ Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
+ (Map<String, Object>) elementData, revision);
+
+ Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
+ Object index = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
+ (Map<String, Object>) indexData, revision);
+
+ collection.put(index, element);
+ }
+}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -21,6 +21,8 @@
*/
package org.jboss.envers.entities.mapper.relation.lazy.proxy;
+import org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor;
+
import java.util.Collection;
import java.util.Iterator;
@@ -28,7 +30,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public abstract class CollectionProxy<U, T extends Collection<U>> implements Collection<U> {
- private Initializor<T> initializor;
+ private org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor<T> initializor;
protected T delegate;
public CollectionProxy(Initializor<T> initializor) {
Deleted: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/Initializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/Initializor.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/Initializor.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -1,31 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.entities.mapper.relation.lazy.proxy;
-
-import java.util.Collection;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public interface Initializor<T> {
- T initialize();
-}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/ListProxy.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/ListProxy.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/ListProxy.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -29,7 +29,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public class ListProxy<U> extends CollectionProxy<U, List<U>> implements List<U> {
- public ListProxy(Initializor<List<U>> initializor) {
+ public ListProxy(org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor<List<U>> initializor) {
super(initializor);
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/MapProxy.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/MapProxy.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/MapProxy.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -23,6 +23,8 @@
*/
package org.jboss.envers.entities.mapper.relation.lazy.proxy;
+import org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor;
+
import java.util.Map;
import java.util.Set;
import java.util.Collection;
@@ -34,7 +36,7 @@
private Initializor<Map<K, V>> initializor;
protected Map<K, V> delegate;
- public MapProxy(Initializor<Map<K, V>> initializor) {
+ public MapProxy(org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor<Map<K, V>> initializor) {
this.initializor = initializor;
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SetProxy.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SetProxy.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SetProxy.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -27,7 +27,7 @@
* @author Adam Warski (adam at warski dot org)
*/
public class SetProxy<U> extends CollectionProxy<U, Set<U>> implements Set<U> {
- public SetProxy(Initializor<Set<U>> initializor) {
+ public SetProxy(org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor<Set<U>> initializor) {
super(initializor);
}
}
Copied: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SortedMapProxy.java (from rev 149, trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/MapProxy.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SortedMapProxy.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SortedMapProxy.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.proxy;
+
+import org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor;
+
+import java.util.*;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class SortedMapProxy<K, V> implements SortedMap<K, V> {
+ private Initializor<SortedMap<K, V>> initializor;
+ protected SortedMap<K, V> delegate;
+
+ public SortedMapProxy(org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor<SortedMap<K, V>> initializor) {
+ this.initializor = initializor;
+ }
+
+ private void checkInit() {
+ if (delegate == null) {
+ delegate = initializor.initialize();
+ }
+ }
+
+ public int size() {
+ checkInit();
+ return delegate.size();
+ }
+
+ public boolean isEmpty() {
+ checkInit();
+ return delegate.isEmpty();
+ }
+
+ public boolean containsKey(Object o) {
+ checkInit();
+ return delegate.containsKey(o);
+ }
+
+ public boolean containsValue(Object o) {
+ checkInit();
+ return delegate.containsValue(o);
+ }
+
+ public V get(Object o) {
+ checkInit();
+ return delegate.get(o);
+ }
+
+ public V put(K k, V v) {
+ checkInit();
+ return delegate.put(k, v);
+ }
+
+ public V remove(Object o) {
+ checkInit();
+ return delegate.remove(o);
+ }
+
+ public void putAll(Map<? extends K, ? extends V> map) {
+ checkInit();
+ delegate.putAll(map);
+ }
+
+ public void clear() {
+ checkInit();
+ delegate.clear();
+ }
+
+ public Set<K> keySet() {
+ checkInit();
+ return delegate.keySet();
+ }
+
+ public Collection<V> values() {
+ checkInit();
+ return delegate.values();
+ }
+
+ public Set<Entry<K, V>> entrySet() {
+ checkInit();
+ return delegate.entrySet();
+ }
+
+ public Comparator<? super K> comparator() {
+ checkInit();
+ return delegate.comparator();
+ }
+
+ public SortedMap<K, V> subMap(K k, K k1) {
+ checkInit();
+ return delegate.subMap(k, k1);
+ }
+
+ public SortedMap<K, V> headMap(K k) {
+ checkInit();
+ return delegate.headMap(k);
+ }
+
+ public SortedMap<K, V> tailMap(K k) {
+ checkInit();
+ return delegate.tailMap(k);
+ }
+
+ public K firstKey() {
+ checkInit();
+ return delegate.firstKey();
+ }
+
+ public K lastKey() {
+ checkInit();
+ return delegate.lastKey();
+ }
+
+ @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"})
+ public boolean equals(Object o) {
+ checkInit();
+ return delegate.equals(o);
+ }
+
+ public int hashCode() {
+ checkInit();
+ return delegate.hashCode();
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SortedMapProxy.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java (from rev 148, trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SetProxy.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.proxy;
+
+import java.util.SortedSet;
+import java.util.Comparator;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class SortedSetProxy<U> extends CollectionProxy<U, SortedSet<U>> implements SortedSet<U> {
+ public SortedSetProxy(org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor<SortedSet<U>> initializor) {
+ super(initializor);
+ }
+
+ public Comparator<? super U> comparator() {
+ checkInit();
+ return delegate.comparator();
+ }
+
+ public SortedSet<U> subSet(U u, U u1) {
+ checkInit();
+ return delegate.subSet(u, u1);
+ }
+
+ public SortedSet<U> headSet(U u) {
+ checkInit();
+ return delegate.headSet(u);
+ }
+
+ public SortedSet<U> tailSet(U u) {
+ checkInit();
+ return delegate.tailSet(u);
+ }
+
+ public U first() {
+ checkInit();
+ return delegate.first();
+ }
+
+ public U last() {
+ checkInit();
+ return delegate.last();
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,14 @@
+package org.jboss.envers.entities.mapper.relation.query;
+
+import org.hibernate.Query;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+
+/**
+ * Implementations of this interface provide a method to generate queries on a middle-table (a table used
+ * for mapping relations). The query can select, apart from selecting the middle table, select also other "related"
+ * entities.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public interface MiddleTableQueryGenerator {
+ Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey, Number revision);
+}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,67 @@
+package org.jboss.envers.entities.mapper.relation.query;
+
+import org.jboss.envers.entities.mapper.relation.MiddleIdData;
+import org.jboss.envers.entities.mapper.id.QueryParameterData;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.RevisionType;
+import org.hibernate.Query;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class OneEntityQueryGenerator implements MiddleTableQueryGenerator {
+ private final String queryString;
+ private final MiddleIdData referencingIdData;
+
+ public OneEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg,
+ String versionsMiddleEntityName,
+ MiddleIdData referencingIdData) {
+ this.referencingIdData = referencingIdData;
+
+ /*
+ * The query that we need to create:
+ * SELECT new list(ee) FROM middleEntity ee WHERE
+ * (only entities referenced by the association)
+ * 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
+ * (only non-deleted entities and associations)
+ * ee.revision_type != DEL
+ */
+ String revisionPropertyPath = verEntCfg.getRevisionPropPath();
+ String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
+
+ StringBuilder querySB = new StringBuilder();
+ querySB
+ .append("SELECT new list(ee) FROM ").append(versionsMiddleEntityName).append(" ee ")
+ .append("WHERE ")
+ // ee.id2 = :id2
+ .append(referencingIdData.getPrefixedMapper().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(referencingIdData.getPrefixedMapper().getIdEqualsQuery("ee2." + originalIdPropertyName, true))
+ .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: referencingIdData.getPrefixedMapper().mapToQueryParametersFromId(primaryKey)) {
+ paramData.setParameterValue(query);
+ }
+
+ return query;
+ }
+}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,29 @@
+package org.jboss.envers.entities.mapper.relation.query;
+
+import org.hibernate.Query;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.entities.mapper.relation.MiddleIdData;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class ThreeEntityQueryGenerator implements MiddleTableQueryGenerator {
+ private final String queryString;
+ private final MiddleIdData referencingIdData;
+
+ public ThreeEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg,
+ String versionsMiddleEntityName,
+ MiddleIdData referencingIdData,
+ MiddleIdData referencedIdData1,
+ MiddleIdData referencedIdData2) {
+ this.referencingIdData = referencingIdData;
+
+ // TODO
+ queryString = "";
+ }
+
+ public Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey, Number revision) {
+ throw new RuntimeException();
+ }
+}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -0,0 +1,93 @@
+package org.jboss.envers.entities.mapper.relation.query;
+
+import org.jboss.envers.entities.mapper.id.QueryParameterData;
+import org.jboss.envers.entities.mapper.relation.MiddleIdData;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.RevisionType;
+import org.hibernate.Query;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class TwoEntityQueryGenerator implements MiddleTableQueryGenerator {
+ private final String queryString;
+ private final MiddleIdData referencingIdData;
+
+ public TwoEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg,
+ String versionsMiddleEntityName,
+ MiddleIdData referencingIdData,
+ MiddleIdData referencedIdData) {
+ this.referencingIdData = referencingIdData;
+
+ /*
+ * The query that we need to create:
+ * SELECT new list(ee, e) FROM versionsReferencedEntity e, middleEntity ee
+ * WHERE
+ * (selecting e entities at revision :revision)
+ * e.revision = (SELECT max(e2.revision) FROM versionsReferencedEntity 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 new list(ee, e) FROM ").append(referencedIdData.getVersionsEntityName()).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(referencedIdData.getVersionsEntityName()).append(" e2 ")
+ // e2.revision <= :revision
+ .append("WHERE e2.").append(revisionPropertyPath).append(" <= :revision AND ")
+ // e2.id1 = e.id1)
+ .append(referencedIdData.getOriginalMapper().getIdsEqualQuery("e." + originalIdPropertyName, "e2." + originalIdPropertyName))
+ .append(") AND ")
+ // ee.id1 = e.id1
+ .append(referencedIdData.getPrefixedMapper().getIdsEqualQuery("ee." + originalIdPropertyName,
+ referencedIdData.getOriginalMapper(), "e." + originalIdPropertyName))
+ .append(" AND ")
+ // ee.id2 = :id2
+ .append(referencingIdData.getPrefixedMapper().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(referencingIdData.getPrefixedMapper().getIdEqualsQuery("ee2." + originalIdPropertyName, true))
+ .append(" AND ")
+ // ee2.id1 = ee.id1)
+ .append(referencedIdData.getPrefixedMapper().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: referencingIdData.getPrefixedMapper().mapToQueryParametersFromId(primaryKey)) {
+ paramData.setParameterValue(query);
+ }
+
+ return query;
+ }
+}
Modified: trunk/src/main/org/jboss/envers/event/VersionsEventListener.java
===================================================================
--- trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/event/VersionsEventListener.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -134,7 +134,8 @@
RelationDescription relDesc = verCfg.getEntCfg().getRelationDescription(event.getAffectedOwnerEntityName(),
workUnit.getReferencingPropertyName());
- if (relDesc.isBidirectional()) {
+ // TODO: remove the null check (relation info should be added in the metadata generator)
+ if (relDesc != null && relDesc.isBidirectional()) {
String relatedEntityName = relDesc.getToEntityName();
IdMapper relatedIdMapper = verCfg.getEntCfg().get(relatedEntityName).getIdMapper();
Modified: trunk/src/main/org/jboss/envers/exception/NotVersionedException.java
===================================================================
--- trunk/src/main/org/jboss/envers/exception/NotVersionedException.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/exception/NotVersionedException.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -22,6 +22,7 @@
package org.jboss.envers.exception;
/**
+ * TODO: add a field describing what isn't versioned.
* @author Adam Warski (adam at warski dot org)
*/
public class NotVersionedException extends VersionsException {
Modified: trunk/src/main/org/jboss/envers/exception/RevisionDoesNotExistException.java
===================================================================
--- trunk/src/main/org/jboss/envers/exception/RevisionDoesNotExistException.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/exception/RevisionDoesNotExistException.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -24,6 +24,7 @@
import java.util.Date;
/**
+ * TODO: add the revision number.
* @author Adam Warski (adam at warski dot org)
*/
public class RevisionDoesNotExistException extends VersionsException {
Modified: trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-09-17 15:38:55 UTC (rev 150)
+++ trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-09-19 14:51:22 UTC (rev 151)
@@ -67,7 +67,7 @@
* @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
+ * @param selectDeletedEntities If true, also revisions where entities were deleted will be returned. The additional
* 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
16 years, 1 month
JBoss Envers SVN: r149 - in trunk/src/main/org/jboss/envers: configuration/metadata and 6 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-15 11:32:02 -0400 (Mon, 15 Sep 2008)
New Revision: 149
Added:
trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/EntityXmlMappingData.java
trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/MapProxy.java
Removed:
trunk/src/main/org/jboss/envers/entities/mapper/CompositePropertyMapperBuilder.java
Modified:
trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java
trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/DetachedRelationInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/Initializor.java
trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java
trunk/src/main/org/jboss/envers/tools/reflection/ReflectionTools.java
Log:
ENVERS-41: breaking down VersionsMetadaGenerator to smaller classes
Modified: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -25,7 +25,7 @@
import org.jboss.envers.configuration.metadata.VersionsMetadataGenerator;
import org.jboss.envers.configuration.metadata.PersistentClassVersioningData;
import org.jboss.envers.configuration.metadata.AnnotationsMetadataReader;
-import org.jboss.envers.configuration.metadata.EntityMappingData;
+import org.jboss.envers.configuration.metadata.EntityXmlMappingData;
import org.jboss.envers.tools.graph.GraphTopologicalSort;
import org.jboss.envers.tools.reflection.YReflectionManager;
import org.dom4j.io.DOMWriter;
@@ -62,7 +62,7 @@
Map<PersistentClass, PersistentClassVersioningData> pcDatas =
new HashMap<PersistentClass, PersistentClassVersioningData>();
- Map<PersistentClass, EntityMappingData> xmlMappings = new HashMap<PersistentClass, EntityMappingData>();
+ Map<PersistentClass, EntityXmlMappingData> xmlMappings = new HashMap<PersistentClass, EntityXmlMappingData>();
// First pass
AnnotationsMetadataReader annotationsMetadataReader = new AnnotationsMetadataReader();
@@ -79,25 +79,24 @@
verEntCfg.addCustomVersionsTableName(pc.getEntityName(), versioningData.versionsTableName);
}
- EntityMappingData mappingData = new EntityMappingData();
- versionsMetaGen.generateFirstPass(pc, versioningData, mappingData);
- xmlMappings.put(pc, mappingData);
+ EntityXmlMappingData xmlMappingData = new EntityXmlMappingData();
+ versionsMetaGen.generateFirstPass(pc, versioningData, xmlMappingData);
+ xmlMappings.put(pc, xmlMappingData);
}
}
// Second pass
for (PersistentClass pc : pcDatas.keySet()) {
- EntityMappingData mappingData = xmlMappings.get(pc);
+ EntityXmlMappingData xmlMappingData = xmlMappings.get(pc);
- versionsMetaGen.generateSecondPass(pc, pcDatas.get(pc), mappingData);
+ versionsMetaGen.generateSecondPass(pc, pcDatas.get(pc), xmlMappingData);
-
try {
- cfg.addDocument(writer.write(mappingData.getMainMapping()));
+ cfg.addDocument(writer.write(xmlMappingData.getMainXmlMapping()));
// TODO
- //writeDocument(mappingData.getMainMapping());
+ //writeDocument(xmlMappingData.getMainXmlMapping());
- for (Document additionalMapping : mappingData.getAdditionalMappings()) {
+ for (Document additionalMapping : xmlMappingData.getAdditionalXmlMappings()) {
cfg.addDocument(writer.write(additionalMapping));
// TODO
//writeDocument(additionalMapping);
Modified: trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -64,5 +64,4 @@
public boolean isUnversionedOptimisticLockingField() {
return unversionedOptimisticLockingField;
}
-
}
Modified: trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -203,7 +203,7 @@
}
return new RevisionInfoConfigurationResult(
- revisionInfoGenerator, revisionPropType, revisionInfoXmlMapping,
+ revisionInfoGenerator, revisionInfoXmlMapping,
new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdName, revisionInfoTimestampName),
generateRevisionInfoRelationMapping(),
new RevisionInfoNumberReader(revisionInfoClass, revisionInfoIdName), revisionInfoEntityName);
@@ -212,19 +212,17 @@
class RevisionInfoConfigurationResult {
private final RevisionInfoGenerator revisionInfoGenerator;
- private final String revisionPropType;
private final Document revisionInfoXmlMapping;
private final RevisionInfoQueryCreator revisionInfoQueryCreator;
private final Element revisionInfoRelationMapping;
private final RevisionInfoNumberReader revisionInfoNumberReader;
private final String revisionInfoEntityName;
- RevisionInfoConfigurationResult(RevisionInfoGenerator revisionInfoGenerator, String revisionPropType,
+ RevisionInfoConfigurationResult(RevisionInfoGenerator revisionInfoGenerator,
Document revisionInfoXmlMapping, RevisionInfoQueryCreator revisionInfoQueryCreator,
Element revisionInfoRelationMapping,
RevisionInfoNumberReader revisionInfoNumberReader, String revisionInfoEntityName) {
this.revisionInfoGenerator = revisionInfoGenerator;
- this.revisionPropType = revisionPropType;
this.revisionInfoXmlMapping = revisionInfoXmlMapping;
this.revisionInfoQueryCreator = revisionInfoQueryCreator;
this.revisionInfoRelationMapping = revisionInfoRelationMapping;
@@ -236,10 +234,6 @@
return revisionInfoGenerator;
}
- public String getRevisionPropType() {
- return revisionPropType;
- }
-
public Document getRevisionInfoXmlMapping() {
return revisionInfoXmlMapping;
}
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -72,8 +72,7 @@
YReflectionManager reflectionManager = YReflectionManager.get(cfg);
RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration();
RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg, reflectionManager);
- verEntCfg = new VersionsEntitiesConfiguration(properties, revInfoCfgResult.getRevisionPropType(),
- revInfoCfgResult.getRevisionInfoEntityName());
+ verEntCfg = new VersionsEntitiesConfiguration(properties, revInfoCfgResult.getRevisionInfoEntityName());
globalCfg = new GlobalConfiguration(properties);
versionsSyncManager = new VersionsSyncManager(revInfoCfgResult.getRevisionInfoGenerator());
revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -34,11 +34,8 @@
private final String originalIdPropName;
private final String revisionPropName;
- private final String revisionPropType;
private final String revisionPropPath;
- private final String revisionEntityPath;
-
private final String revisionTypePropName;
private final String revisionTypePropType;
@@ -46,7 +43,7 @@
private final Map<String, String> customVersionsTablesNames;
- public VersionsEntitiesConfiguration(Properties properties, String revisionPropType, String revisionInfoEntityName) {
+ public VersionsEntitiesConfiguration(Properties properties, String revisionInfoEntityName) {
this.revisionInfoEntityName = revisionInfoEntityName;
versionsTablePrefix = properties.getProperty("org.jboss.envers.versionsTablePrefix", "");
@@ -55,15 +52,13 @@
originalIdPropName = "originalId";
revisionPropName = properties.getProperty("org.jboss.envers.revisionFieldName", "_revision");
- this.revisionPropType = revisionPropType;
revisionTypePropName = properties.getProperty("org.jboss.envers.revisionTypeFieldName", "_revision_type");
revisionTypePropType = "byte";
customVersionsTablesNames = new HashMap<String, String>();
- revisionEntityPath = originalIdPropName + "." + revisionPropName;
- revisionPropPath = revisionEntityPath + ".id";
+ revisionPropPath = originalIdPropName + "." + revisionPropName + ".id";
}
public String getOriginalIdPropName() {
@@ -78,10 +73,6 @@
return revisionPropPath;
}
- public String getRevisionPropType() {
- return revisionPropType;
- }
-
public String getRevisionTypePropName() {
return revisionTypePropName;
}
@@ -90,10 +81,6 @@
return revisionTypePropType;
}
- public String getRevisionEntityPath() {
- return revisionEntityPath;
- }
-
public String getRevisionInfoEntityName() {
return revisionInfoEntityName;
}
Added: trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -0,0 +1,108 @@
+package org.jboss.envers.configuration.metadata;
+
+import org.dom4j.Element;
+import org.hibernate.mapping.Value;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.Property;
+import org.hibernate.type.CustomType;
+import org.hibernate.util.StringHelper;
+import org.jboss.envers.entities.mapper.SimpleMapperBuilder;
+import org.jboss.envers.entities.mapper.CompositeMapperBuilder;
+import org.jboss.envers.ModificationStore;
+import org.jboss.envers.exception.VersionsException;
+
+import java.util.Iterator;
+
+/**
+ * Generates metadata for basic properties: immutable types (including enums) and components
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BasicMetadataGenerator {
+ private final VersionsMetadataGenerator mainGenerator;
+
+ BasicMetadataGenerator(VersionsMetadataGenerator versionsMetadataGenerator) {
+ mainGenerator = versionsMetadataGenerator;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ void addSimpleValue(Element parent, String name, Value value, SimpleMapperBuilder mapper,
+ ModificationStore store, boolean key) {
+ Element prop_mapping = MetadataTools.addProperty(parent, name,
+ value.getType().getName(), key);
+ MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
+
+ // A null mapper means that we only want to add xml mappings (while building the id mapping)
+ if (mapper != null) {
+ mapper.add(name, store);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ void addEnumValue(Element parent, String name, Value value, SimpleMapperBuilder mapper,
+ ModificationStore store) {
+ Element prop_mapping = parent.addElement("property");
+ prop_mapping.addAttribute("name", name);
+
+ CustomType propertyType = (CustomType) value.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]));
+
+ MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
+
+ mapper.add(name, store);
+ }
+
+ private void addComponentClassName(Element any_mapping, Component comp) {
+ if (StringHelper.isNotEmpty(comp.getComponentClassName())) {
+ any_mapping.addAttribute("class", comp.getComponentClassName());
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ void addComponent(Element parent, String name, Value value, CompositeMapperBuilder mapper,
+ String entityName, EntityXmlMappingData xmlMappingData,
+ boolean firstPass) {
+ Element component_mapping = null;
+ Component prop_component = (Component) value;
+
+ 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(name)) {
+ 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", name);
+
+ addComponentClassName(component_mapping, prop_component);
+ }
+
+ CompositeMapperBuilder componentMapper = mapper.addComposite(name);
+
+ Iterator<Property> properties = (Iterator<Property>) prop_component.getPropertyIterator();
+ while (properties.hasNext()) {
+ Property property = properties.next();
+ mainGenerator.addValue(component_mapping, property.getName(), property.getValue(),
+ componentMapper, ModificationStore.FULL, entityName, xmlMappingData, firstPass);
+ }
+ }
+}
Added: trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -0,0 +1,204 @@
+package org.jboss.envers.configuration.metadata;
+
+import org.hibernate.mapping.*;
+import org.hibernate.mapping.Collection;
+import org.hibernate.MappingException;
+import org.jboss.envers.entities.mapper.CompositeMapperBuilder;
+import org.jboss.envers.entities.mapper.relation.*;
+import org.jboss.envers.entities.mapper.id.IdMapper;
+import org.jboss.envers.entities.EntityConfiguration;
+import org.jboss.envers.entities.IdMappingData;
+import org.jboss.envers.tools.Tools;
+import org.jboss.envers.tools.StringTools;
+import org.dom4j.Element;
+
+import java.util.*;
+
+/**
+ * Generates metadata for collection-valued properties.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class CollectionMetadataGenerator {
+ private final VersionsMetadataGenerator mainGenerator;
+
+ CollectionMetadataGenerator(VersionsMetadataGenerator versionsMetadataGenerator) {
+ mainGenerator = versionsMetadataGenerator;
+ }
+
+ @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"})
+ void addOneToManyAttached(String name, Value value, CompositeMapperBuilder mapper, String entityName) {
+ Collection propertyValue = (Collection) value;
+
+ String owningReferencePropertyName = getMappedBy(propertyValue);
+ if (owningReferencePropertyName == null) {
+ throw new MappingException("Unable to read the mapped by attribute for " + name);
+ }
+
+ EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().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 lastPropertyPrefix = owningReferencePropertyName + "_";
+
+ // Generating the id mapper for the relation
+ IdMapper ownedIdMapper = referencingIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
+
+ // Storing information about this relation
+ mainGenerator.getEntitiesConfigurations().get(entityName).addOneToManyAttachedRelation(name, owningReferencePropertyName,
+ owningEntityName, ownedIdMapper);
+
+ // Adding mapper for the id
+ mapper.addComposite(name, new OneToManyAttachedMapper(owningReferencePropertyName, owningEntityName,
+ name));
+ }
+
+ private String getMiddleEntityName(String entityName, String referencedEntityName, ManyToOne mto) {
+ return entityName + "_" + referencedEntityName + "_" + mto.getTable().getName();
+ }
+
+ @SuppressWarnings({"unchecked"})
+ void addOneToManyDetached(String name, Value value, CompositeMapperBuilder mapper, String entityName,
+ EntityXmlMappingData xmlMappingData) {
+ Collection propertyValue = (Collection) value;
+ ManyToOne mto = (ManyToOne) propertyValue.getElement();
+
+ String referencedEntityName = mto.getReferencedEntityName();
+
+ EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(entityName);
+ if (configuration == null) {
+ throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
+ }
+
+ EntityConfiguration referencedConfiguration = mainGenerator.getEntitiesConfigurations().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();
+
+ String referencingPrefix = StringTools.getLastComponent(entityName) + "_";
+ String referencedPrefix = name + "_";
+
+ // Name of the entity that will be used to store the relation between the two entities.
+ String middleEntityName = getMiddleEntityName(entityName, referencedEntityName, mto);
+ String versionsMiddleEntityName = mainGenerator.getVerEntCfg().getVersionsEntityName(middleEntityName);
+ String versionsMiddleTableName = mainGenerator.getVerEntCfg().getVersionsTableName(middleEntityName, mto.getTable().getName());
+
+ Element middleEntity = MetadataTools.createEntity(xmlMappingData.newAdditionalMapping(), versionsMiddleEntityName,
+ versionsMiddleTableName, mto.getTable().getSchema(), mto.getTable().getCatalog(), null);
+
+ Element middleEntityId = middleEntity.addElement("composite-id");
+ middleEntityId.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
+
+ Iterator columnIterator = mto.getTable().getColumnIterator();
+
+ // Adding elements to the mapping corresponding to the referencing entity id's
+ Element properties = (Element) referencingIdMapping.getXmlRelationMapping().clone();
+ MetadataTools.prefixNamesInPropertyElement(properties, referencingPrefix, columnIterator, true);
+ for (Element idProperty : (java.util.List<Element>) properties.elements()) {
+ middleEntityId.add((Element) idProperty.clone());
+ }
+
+ // Adding elements to the mapping corresponding to the referenced entity id's
+ properties = (Element) referencedIdMapping.getXmlRelationMapping().clone();
+ MetadataTools.prefixNamesInPropertyElement(properties, referencedPrefix, columnIterator, true);
+ for (Element idProperty : (java.util.List<Element>) properties.elements()) {
+ middleEntityId.add((Element) idProperty.clone());
+ }
+
+ mainGenerator.addRevisionInfoRelation(middleEntityId);
+ mainGenerator.addRevisionType(middleEntity);
+
+ mainGenerator.getEntitiesConfigurations().get(entityName).addOneToManyDetachedRelation(name, referencedEntityName);
+
+ // Adding the property mapper
+ mapper.addComposite(name, new OneToManyDetachedMapper(mainGenerator.getVerEntCfg(), entityName,
+ referencedEntityName, name, mainGenerator.getVerEntCfg().getVersionsEntityName(referencedEntityName),
+ versionsMiddleEntityName, referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
+ referencedIdMapping.getIdMapper().prefixMappedProperties(referencedPrefix),
+ mainGenerator.getEntitiesConfigurations().get(referencedEntityName).getIdMapper()));
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private String getMappedBy(Table collectionTable, PersistentClass referencedClass) {
+ Iterator<Property> properties = referencedClass.getPropertyIterator();
+ while (properties.hasNext()) {
+ Property property = properties.next();
+ if (property.getValue() instanceof Collection) {
+ // The equality is intentional. We want to find a collection property with the same collection table.
+ //noinspection ObjectEquality
+ if (((Collection) property.getValue()).getCollectionTable() == collectionTable) {
+ return property.getName();
+ }
+ }
+ }
+
+ return null;
+ }
+
+ void addManyToManyNotOwning(String name, Value value, CompositeMapperBuilder mapper, String entityName) {
+ Collection propertyValue = (Collection) value;
+ ManyToOne mto = (ManyToOne) propertyValue.getElement();
+
+ String referencedEntityName = mto.getReferencedEntityName();
+
+ EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(entityName);
+ if (configuration == null) {
+ throw new MappingException("A versioned relation to a non-versioned entity " + entityName + "!");
+ }
+
+ EntityConfiguration referencedConfiguration = mainGenerator.getEntitiesConfigurations().get(referencedEntityName);
+ if (referencedConfiguration == null) {
+ throw new MappingException("A versioned relation to a non-versioned entity " + referencedEntityName + "!");
+ }
+
+ String mappedBy = getMappedBy(propertyValue.getCollectionTable(), mainGenerator.getCfg().getClassMapping(referencedEntityName));
+ if (mappedBy == null) {
+ throw new MappingException("Unable to read the mapped by attribute for " + name);
+ }
+
+ IdMappingData referencingIdMapping = configuration.getIdMappingData();
+ IdMappingData referencedIdMapping = referencedConfiguration.getIdMappingData();
+
+ String referencingPrefix = mappedBy + "_";
+ String referencedPrefix = StringTools.getLastComponent(referencedEntityName) + "_";
+
+ // Name of the entity that will be used to store the relation between the two entities.
+ // The order is inverse, as the referenced and referencing entity names are swapped with respect to the
+ // name of the entity that was created on the owning side in <code>addOneToManyDetached</code>.
+ String middleEntityName = getMiddleEntityName(referencedEntityName, entityName, mto);
+ String versionsMiddleEntityName = mainGenerator.getVerEntCfg().getVersionsEntityName(middleEntityName);
+
+ mainGenerator.getEntitiesConfigurations().get(entityName).addManyToManyNotOwningRelation(name, mappedBy,
+ referencedEntityName);
+
+ // Adding the property mapper
+ mapper.addComposite(name, new ManyToManyNotOwningMapper(mainGenerator.getVerEntCfg(), entityName,
+ referencedEntityName, name, mainGenerator.getVerEntCfg().getVersionsEntityName(referencedEntityName),
+ versionsMiddleEntityName, referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
+ referencedIdMapping.getIdMapper().prefixMappedProperties(referencedPrefix),
+ mainGenerator.getEntitiesConfigurations().get(referencedEntityName).getIdMapper()));
+ }
+}
Copied: trunk/src/main/org/jboss/envers/configuration/metadata/EntityXmlMappingData.java (from rev 148, trunk/src/main/org/jboss/envers/configuration/metadata/EntityMappingData.java)
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/EntityXmlMappingData.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/EntityXmlMappingData.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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 java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class EntityXmlMappingData {
+ private Document mainXmlMapping;
+ private List<Document> additionalXmlMappings;
+
+ public EntityXmlMappingData() {
+ mainXmlMapping = DocumentHelper.createDocument();
+ additionalXmlMappings = new ArrayList<Document>();
+ }
+
+ public Document getMainXmlMapping() {
+ return mainXmlMapping;
+ }
+
+ public List<Document> getAdditionalXmlMappings() {
+ return additionalXmlMappings;
+ }
+
+ public Document newAdditionalMapping() {
+ Document additionalMapping = DocumentHelper.createDocument();
+ additionalXmlMappings.add(additionalMapping);
+
+ return additionalMapping;
+ }
+}
Added: trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -0,0 +1,91 @@
+package org.jboss.envers.configuration.metadata;
+
+import org.dom4j.Element;
+import org.dom4j.tree.DefaultElement;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Component;
+import org.hibernate.type.Type;
+import org.hibernate.type.ImmutableType;
+import org.hibernate.MappingException;
+import org.jboss.envers.entities.mapper.SimpleMapperBuilder;
+import org.jboss.envers.entities.mapper.id.SimpleIdMapperBuilder;
+import org.jboss.envers.entities.mapper.id.MultipleIdMapper;
+import org.jboss.envers.entities.mapper.id.EmbeddedIdMapper;
+import org.jboss.envers.entities.mapper.id.SingleIdMapper;
+import org.jboss.envers.entities.IdMappingData;
+import org.jboss.envers.ModificationStore;
+
+import java.util.Iterator;
+
+/**
+ * Generates metadata for primary identifiers (ids) of versions entities.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class IdMetadataGenerator {
+ private final VersionsMetadataGenerator mainGenerator;
+
+ IdMetadataGenerator(VersionsMetadataGenerator versionsMetadataGenerator) {
+ mainGenerator = versionsMetadataGenerator;
+ }
+
+ @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) {
+ mainGenerator.getBasicMetadataGenerator().addSimpleValue(parent, property.getName(),
+ property.getValue(), mapper, ModificationStore.FULL, key);
+ } else {
+ throw new MappingException("Type not supported: " + propertyType.getClass().getName());
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ 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();
+
+ mainGenerator.getBasicMetadataGenerator().addSimpleValue(rel_id_mapping, id_prop.getName(),
+ id_prop.getValue(), mapper, ModificationStore.FULL, false);
+
+ // null mapper - the mapping where already added the first time, now we only want to generate the xml
+ mainGenerator.getBasicMetadataGenerator().addSimpleValue(orig_id_mapping, id_prop.getName(),
+ id_prop.getValue(), null, ModificationStore.FULL, true);
+ }
+
+ orig_id_mapping.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
+
+ // Adding a relation to the revision entity (effectively: the "revision number" property)
+ mainGenerator.addRevisionInfoRelation(orig_id_mapping);
+
+ return new IdMappingData(mapper, orig_id_mapping, rel_id_mapping);
+ }
+}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -23,8 +23,12 @@
import org.dom4j.Element;
import org.dom4j.Document;
+import org.dom4j.Attribute;
import org.jboss.envers.tools.StringTools;
+import org.hibernate.mapping.Column;
+import java.util.Iterator;
+
/**
* @author Adam Warski (adam at warski dot org)
*/
@@ -126,4 +130,48 @@
return join_mapping;
}
+
+ public static void addColumns(Element any_mapping, Iterator<Column> columns) {
+ while (columns.hasNext()) {
+ Column column = columns.next();
+ addColumn(any_mapping, column.getName(), column.getLength());
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private static 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"})
+ public static void prefixNamesInPropertyElement(Element element, String prefix, Iterator<Column> columnIterator,
+ boolean changeToKey) {
+ 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);
+
+ if (changeToKey) {
+ property.setName("key-property");
+ }
+ }
+ }
+ }
}
Added: trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -0,0 +1,87 @@
+package org.jboss.envers.configuration.metadata;
+
+import org.dom4j.Element;
+import org.hibernate.mapping.Value;
+import org.hibernate.mapping.ToOne;
+import org.hibernate.mapping.OneToOne;
+import org.hibernate.MappingException;
+import org.jboss.envers.entities.mapper.CompositeMapperBuilder;
+import org.jboss.envers.entities.mapper.relation.ToOneIdMapper;
+import org.jboss.envers.entities.mapper.relation.OneToOneNotOwningIdMapper;
+import org.jboss.envers.entities.mapper.id.IdMapper;
+import org.jboss.envers.entities.EntityConfiguration;
+import org.jboss.envers.entities.IdMappingData;
+
+/**
+ * Generates metadata for to-one relations (reference-valued properties).
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ToOneRelationMetadataGenerator {
+ private final VersionsMetadataGenerator mainGenerator;
+
+ ToOneRelationMetadataGenerator(VersionsMetadataGenerator versionsMetadataGenerator) {
+ mainGenerator = versionsMetadataGenerator;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ void addToOne(Element parent, String name, Value value, CompositeMapperBuilder mapper, String entityName) {
+ String referencedEntityName = ((ToOne) value).getReferencedEntityName();
+
+ EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(referencedEntityName);
+ if (configuration == null) {
+ throw new MappingException("A versioned relation to a non-versioned entity " + referencedEntityName + "!");
+ }
+
+ IdMappingData idMapping = configuration.getIdMappingData();
+
+ String lastPropertyPrefix = name + "_";
+
+ // Generating the id mapper for the relation
+ IdMapper relMapper = idMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
+
+ // Storing information about this relation
+ mainGenerator.getEntitiesConfigurations().get(entityName).addToOneRelation(name, referencedEntityName, relMapper);
+
+ // Adding an element to the mapping corresponding to the references entity id's
+ Element properties = (Element) idMapping.getXmlRelationMapping().clone();
+ properties.addAttribute("name", name);
+
+ MetadataTools.prefixNamesInPropertyElement(properties, lastPropertyPrefix, value.getColumnIterator(), false);
+ parent.add(properties);
+
+ // Adding mapper for the id
+ mapper.addComposite(name, new ToOneIdMapper(relMapper, name, referencedEntityName));
+ }
+
+ @SuppressWarnings({"unchecked"})
+ void addOneToOneNotOwning(String name, Value value, CompositeMapperBuilder mapper, String entityName) {
+ OneToOne propertyValue = (OneToOne) value;
+
+ String owningReferencePropertyName = propertyValue.getReferencedPropertyName(); // mappedBy
+
+ EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().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 lastPropertyPrefix = owningReferencePropertyName + "_";
+ String referencedEntityName = propertyValue.getReferencedEntityName();
+
+ // Generating the id mapper for the relation
+ IdMapper ownedIdMapper = ownedIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
+
+ // Storing information about this relation
+ mainGenerator.getEntitiesConfigurations().get(entityName).addOneToOneNotOwningRelation(name, owningReferencePropertyName,
+ referencedEntityName, ownedIdMapper);
+
+ // Adding mapper for the id
+ mapper.addComposite(name, new OneToOneNotOwningIdMapper(owningReferencePropertyName,
+ referencedEntityName, name));
+ }
+}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -22,28 +22,21 @@
package org.jboss.envers.configuration.metadata;
import org.hibernate.type.*;
-import org.hibernate.util.StringHelper;
import org.hibernate.MappingException;
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.*;
import org.hibernate.mapping.Collection;
import org.dom4j.Element;
-import org.dom4j.Attribute;
-import org.dom4j.tree.DefaultElement;
import org.jboss.envers.entities.EntityConfiguration;
import org.jboss.envers.entities.IdMappingData;
import org.jboss.envers.configuration.GlobalConfiguration;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import org.jboss.envers.entities.mapper.*;
-import org.jboss.envers.entities.mapper.id.*;
-import org.jboss.envers.entities.mapper.relation.*;
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.exception.VersionsException;
import java.util.*;
import java.util.List;
@@ -54,13 +47,16 @@
* @author Sebastian Komander
*/
public class VersionsMetadataGenerator {
- private final static Map<String, ModificationStore> EMPTY_STORE = Collections.emptyMap();
-
private final Configuration cfg;
private final GlobalConfiguration globalCfg;
private final VersionsEntitiesConfiguration verEntCfg;
private final Element revisionInfoRelationMapping;
+ private final BasicMetadataGenerator basicMetadataGenerator;
+ private final IdMetadataGenerator idMetadataGenerator;
+ private final CollectionMetadataGenerator collectionMetadataGenerator;
+ private final ToOneRelationMetadataGenerator toOneRelationMetadataGenerator;
+
private Map<String, EntityConfiguration> entitiesConfigurations;
// Map entity name -> (join descriptor -> element describing the "versioned" join)
@@ -76,24 +72,16 @@
this.verEntCfg = verEntCfg;
this.revisionInfoRelationMapping = revisionInfoRelationMapping;
+ this.basicMetadataGenerator = new BasicMetadataGenerator(this);
+ this.idMetadataGenerator = new IdMetadataGenerator(this);
+ this.collectionMetadataGenerator = new CollectionMetadataGenerator(this);
+ this.toOneRelationMetadataGenerator = new ToOneRelationMetadataGenerator(this);
+
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());
- }
- }
-
- private void addRevisionInfoRelation(Element any_mapping) {
+ void addRevisionInfoRelation(Element any_mapping) {
Element rev_mapping = (Element) revisionInfoRelationMapping.clone();
rev_mapping.addAttribute("name", verEntCfg.getRevisionPropName());
MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionPropName(), null);
@@ -101,361 +89,12 @@
any_mapping.add(rev_mapping);
}
- private void addRevisionType(Element any_mapping) {
+ void addRevisionType(Element any_mapping) {
Element revTypeProperty = MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionTypePropName(),
verEntCfg.getRevisionTypePropType(), false);
revTypeProperty.addAttribute("type", "org.jboss.envers.entities.RevisionTypeType");
}
- @SuppressWarnings({"unchecked"})
- private void addSimpleProperty(Element parent, Property property, SimpleMapperBuilder mapper,
- ModificationStore store, boolean key) {
- 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, EntityMappingData mappingData, List<String> unversionedProperties,
- 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,
- mappingData, unversionedProperties, 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,
- boolean changeToKey) {
- 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);
-
- if (changeToKey) {
- property.setName("key-property");
- }
- }
- }
- }
-
- @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(), false);
- parent.add(properties);
-
- // Adding mapper for the id
- mapper.addComposite(propertyName, new ToOneIdMapper(relMapper, propertyName, referencedEntityName));
- }
-
- @SuppressWarnings({"unchecked"})
- private void addOneToOneNotOwning(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).addOneToOneNotOwningRelation(propertyName, owningReferencePropertyName,
- referencedEntityName, ownedIdMapper);
-
- // Adding mapper for the id
- mapper.addComposite(propertyName, new OneToOneNotOwningIdMapper(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 addOneToManyAttached(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).addOneToManyAttachedRelation(propertyName, owningReferencePropertyName,
- owningEntityName, ownedIdMapper);
-
- // Adding mapper for the id
- mapper.addComposite(propertyName, new OneToManyAttachedMapper(owningReferencePropertyName, owningEntityName,
- propertyName));
- }
-
- private String getMiddleEntityName(String entityName, String referencedEntityName, ManyToOne mto) {
- return entityName + "_" + referencedEntityName + "_" + mto.getTable().getName();
- }
-
- @SuppressWarnings({"unchecked"})
- private void addOneToManyDetached(Property property, CompositeMapperBuilder mapper, String entityName,
- EntityMappingData mappingData) {
- 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();
-
- String referencingPrefix = StringTools.getLastComponent(entityName) + "_";
- String referencedPrefix = property.getName() + "_";
-
- // Name of the entity that will be used to store the relation between the two entities.
- String middleEntityName = getMiddleEntityName(entityName, referencedEntityName, mto);
- String versionsMiddleEntityName = verEntCfg.getVersionsEntityName(middleEntityName);
- String versionsMiddleTableName = verEntCfg.getVersionsTableName(middleEntityName, mto.getTable().getName());
-
- Element middleEntity = MetadataTools.createEntity(mappingData.newAdditionalMapping(), versionsMiddleEntityName,
- versionsMiddleTableName, mto.getTable().getSchema(), mto.getTable().getCatalog(), null);
-
- Element middleEntityId = middleEntity.addElement("composite-id");
- middleEntityId.addAttribute("name", verEntCfg.getOriginalIdPropName());
-
- Iterator columnIterator = mto.getTable().getColumnIterator();
-
- // Adding elements to the mapping corresponding to the referencing entity id's
- Element properties = (Element) referencingIdMapping.getXmlRelationMapping().clone();
- prefixNamesInPropertyElement(properties, referencingPrefix, columnIterator, true);
- for (Element idProperty : (List<Element>) properties.elements()) {
- middleEntityId.add((Element) idProperty.clone());
- }
-
- // Adding elements to the mapping corresponding to the referenced entity id's
- properties = (Element) referencedIdMapping.getXmlRelationMapping().clone();
- prefixNamesInPropertyElement(properties, referencedPrefix, columnIterator, true);
- for (Element idProperty : (List<Element>) properties.elements()) {
- middleEntityId.add((Element) idProperty.clone());
- }
-
- addRevisionInfoRelation(middleEntityId);
- addRevisionType(middleEntity);
-
- entitiesConfigurations.get(entityName).addOneToManyDetachedRelation(property.getName(), referencedEntityName);
-
- // Adding the property mapper
- mapper.addComposite(property.getName(), new OneToManyDetachedMapper(verEntCfg, entityName,
- referencedEntityName, property.getName(), verEntCfg.getVersionsEntityName(referencedEntityName),
- versionsMiddleEntityName, referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
- referencedIdMapping.getIdMapper().prefixMappedProperties(referencedPrefix),
- entitiesConfigurations.get(referencedEntityName).getIdMapper()));
- }
-
- @SuppressWarnings({"unchecked"})
- private String getMappedBy(Table collectionTable, PersistentClass referencedClass) {
- Iterator<Property> properties = referencedClass.getPropertyIterator();
- while (properties.hasNext()) {
- Property property = properties.next();
- if (property.getValue() instanceof Collection) {
- // The equality is intentional. We want to find a collection property with the same collection table.
- //noinspection ObjectEquality
- if (((Collection) property.getValue()).getCollectionTable() == collectionTable) {
- return property.getName();
- }
- }
- }
-
- return null;
- }
-
- private void addManyToManyNotOwning(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 + "!");
- }
-
- String mappedBy = getMappedBy(propertyValue.getCollectionTable(), cfg.getClassMapping(referencedEntityName));
- if (mappedBy == null) {
- throw new MappingException("Unable to read the mapped by attribute for " + property.getName());
- }
-
- IdMappingData referencingIdMapping = configuration.getIdMappingData();
- IdMappingData referencedIdMapping = referencedConfiguration.getIdMappingData();
-
- String referencingPrefix = mappedBy + "_";
- String referencedPrefix = StringTools.getLastComponent(referencedEntityName) + "_";
-
- // Name of the entity that will be used to store the relation between the two entities.
- // The order is inverse, as the referenced and referencing entity names are swapped with respect to the
- // name of the entity that was created on the owning side in <code>addOneToManyDetached</code>.
- String middleEntityName = getMiddleEntityName(referencedEntityName, entityName, mto);
- String versionsMiddleEntityName = verEntCfg.getVersionsEntityName(middleEntityName);
-
- entitiesConfigurations.get(entityName).addManyToManyNotOwningRelation(property.getName(), mappedBy,
- referencedEntityName);
-
- // Adding the property mapper
- mapper.addComposite(property.getName(), new ManyToManyNotOwningMapper(verEntCfg, entityName,
- referencedEntityName, property.getName(), verEntCfg.getVersionsEntityName(referencedEntityName),
- versionsMiddleEntityName, referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefix),
- referencedIdMapping.getIdMapper().prefixMappedProperties(referencedPrefix),
- entitiesConfigurations.get(referencedEntityName).getIdMapper()));
- }
-
private ModificationStore getStoreForProperty(Property property, PropertyStoreInfo propertyStoreInfo,
List<String> unversionedProperties) {
/*
@@ -479,100 +118,93 @@
}
@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());
- }
+ void addValue(Element parent, String name, Value value, CompositeMapperBuilder currentMapper,
+ ModificationStore store, String entityName, EntityXmlMappingData xmlMappingData,
+ boolean firstPass) {
+ Type type = value.getType();
+
+ if (type instanceof ComponentType) {
+ // only first pass
+ if (firstPass) {
+ basicMetadataGenerator.addComponent(parent, name, value, currentMapper, entityName, xmlMappingData, firstPass);
}
+ } else if (type instanceof ImmutableType || type instanceof MutableType) {
+ // only first pass
+ if (firstPass) {
+ basicMetadataGenerator.addSimpleValue(parent, name, value, currentMapper, store, false);
+ }
+ } else if (type instanceof CustomType &&
+ "org.hibernate.type.EnumType".equals(type.getName())) {
+ // only first pass
+ if (firstPass) {
+ basicMetadataGenerator.addEnumValue(parent, name, value, currentMapper, store);
+ }
+ } else if (type instanceof ManyToOneType) {
+ // only second pass
+ if (!firstPass) {
+ toOneRelationMetadataGenerator.addToOne(parent, name, value, currentMapper, entityName);
+ }
+ } else if (type instanceof OneToOneType) {
+ // only second pass
+ if (!firstPass) {
+ toOneRelationMetadataGenerator.addOneToOneNotOwning(name, value, currentMapper, entityName);
+ }
+ } else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(
+ type.getClass().getName())) {
+ // only first pass
+ if (firstPass) {
+ basicMetadataGenerator.addSimpleValue(parent, name, value, currentMapper, store, false);
+ }
+ } else if (type instanceof CustomType &&
+ ("org.hibernate.type.PrimitiveCharacterArrayClobType".equals(type.getName()) ||
+ "org.hibernate.type.StringClobType".equals(type.getName()))) {
+ // only first pass
+ if (firstPass) {
+ basicMetadataGenerator.addSimpleValue(parent, name, value, currentMapper, store, false);
+ }
+ } else if ((type instanceof BagType || type instanceof SetType) &&
+ ((((Collection) value).getElement() instanceof OneToMany))) {
+ // only second pass
+ if (!firstPass) {
+ collectionMetadataGenerator.addOneToManyAttached(name, value, currentMapper, entityName);
+ }
+ } else if ((type instanceof BagType || type instanceof SetType) &&
+ ((((Collection) value).getElement() instanceof ManyToOne)) &&
+ !((Collection) value).isInverse()) {
+ // only second pass
+ if (!firstPass) {
+ collectionMetadataGenerator.addOneToManyDetached(name, value, currentMapper, entityName, xmlMappingData);
+ }
+ } else if ((type instanceof BagType || type instanceof SetType) &&
+ ((((Collection) value).getElement() instanceof ManyToOne)) &&
+ ((Collection) value).isInverse()) {
+ // only second pass
+ if (!firstPass) {
+ collectionMetadataGenerator.addManyToManyNotOwning(name, value, currentMapper, entityName);
+ }
+ } else {
+ String message = "Type not supported for versioning: " + type.getClass().getName() +
+ ", on entity " + entityName + ", property '" + name + "'.";
+ if (globalCfg.isWarnOnUnsupportedTypes()) {
+ log.warn(message);
+ } else {
+ throw new MappingException(message);
+ }
}
}
@SuppressWarnings({"unchecked"})
private void addProperties(Element parent, Iterator<Property> properties, CompositeMapperBuilder currentMapper,
- PropertyStoreInfo propertyStoreInfo, String entityName, EntityMappingData mappingData,
+ PropertyStoreInfo propertyStoreInfo, String entityName, EntityXmlMappingData xmlMappingData,
List<String> unversionedProperties, boolean firstPass) {
while (properties.hasNext()) {
Property property = properties.next();
- Type propertyType = property.getType();
if (!"_identifierMapper".equals(property.getName())) {
ModificationStore store = getStoreForProperty(property, propertyStoreInfo, unversionedProperties);
- if (store != null) {
- if (propertyType instanceof ComponentType) {
- // only first pass
- if (firstPass) {
- addComponent(parent, property, currentMapper, store, entityName, mappingData,
- unversionedProperties, 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) {
- addOneToOneNotOwning(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) {
- addOneToManyAttached(property, currentMapper, entityName);
- }
- } else if ((propertyType instanceof BagType || propertyType instanceof SetType) &&
- ((((Collection) property.getValue()).getElement() instanceof ManyToOne)) &&
- !((Collection) property.getValue()).isInverse()) {
- // only second pass
- if (!firstPass) {
- 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);
- }
- } else {
- String message = "Type not supported for versioning: " + propertyType.getClass().getName() +
- ", on entity " + entityName + ", property '" + property.getName() + "'.";
- if (globalCfg.isWarnOnUnsupportedTypes()) {
- log.warn(message);
- } else {
- throw new MappingException(message);
- }
- }
+ if (store != null) {
+ addValue(parent, property.getName(), property.getValue(), currentMapper, store, entityName,
+ xmlMappingData, firstPass);
}
}
}
@@ -610,14 +242,14 @@
joinElements.put(join, joinElement);
Element joinKey = joinElement.addElement("key");
- addColumns(joinKey, join.getKey().getColumnIterator());
+ MetadataTools.addColumns(joinKey, join.getKey().getColumnIterator());
MetadataTools.addColumn(joinKey, verEntCfg.getRevisionPropName(), null);
}
}
@SuppressWarnings({"unchecked"})
private void addJoins(PersistentClass pc, CompositeMapperBuilder currentMapper, PropertyStoreInfo propertyStoreInfo,
- String entityName, EntityMappingData mappingData, List<String> unversionedProperties,
+ String entityName, EntityXmlMappingData xmlMappingData, List<String> unversionedProperties,
boolean firstPass) {
Iterator<Join> joins = pc.getJoinIterator();
@@ -626,52 +258,12 @@
Element joinElement = entitiesJoins.get(entityName).get(join);
addProperties(joinElement, join.getPropertyIterator(), currentMapper, propertyStoreInfo, entityName,
- mappingData, unversionedProperties, firstPass);
+ xmlMappingData, unversionedProperties, 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 a relation to the revision entity (effectively: the "revision number" property)
- addRevisionInfoRelation(orig_id_mapping);
-
- return new IdMappingData(mapper, orig_id_mapping, rel_id_mapping);
- }
-
private void addPersisterHack(Element class_mapping) {
String persisterClassName;
if (HibernateVersion.get().startsWith("3.3")) {
@@ -685,7 +277,7 @@
@SuppressWarnings({"unchecked"})
public void generateFirstPass(PersistentClass pc, PersistentClassVersioningData versioningData,
- EntityMappingData mappingData) {
+ EntityXmlMappingData xmlMappingData) {
String schema = versioningData.schema;
if (StringTools.isEmpty(schema)) {
schema = pc.getTable().getSchema();
@@ -701,7 +293,7 @@
String versionsTableName = verEntCfg.getVersionsTableName(entityName, pc.getTable().getName());
// Generating a mapping for the id
- IdMappingData idMapper = addId(pc);
+ IdMappingData idMapper = idMetadataGenerator.addId(pc);
Element class_mapping;
ExtendedPropertyMapper propertyMapper;
@@ -711,14 +303,14 @@
switch (inheritanceType) {
case NONE:
- class_mapping = MetadataTools.createEntity(mappingData.getMainMapping(), versionsEntityName, versionsTableName,
+ class_mapping = MetadataTools.createEntity(xmlMappingData.getMainXmlMapping(), 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());
+ MetadataTools.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.
@@ -734,7 +326,7 @@
break;
case SINGLE:
String extendsEntityName = verEntCfg.getVersionsEntityName(pc.getSuperclass().getEntityName());
- class_mapping = MetadataTools.createSubclassEntity(mappingData.getMainMapping(), versionsEntityName,
+ class_mapping = MetadataTools.createSubclassEntity(xmlMappingData.getMainXmlMapping(), versionsEntityName,
versionsTableName, schema, catalog, extendsEntityName, pc.getDiscriminatorValue());
addPersisterHack(class_mapping);
@@ -757,12 +349,12 @@
// Mapping unjoined properties
addProperties(class_mapping, (Iterator<Property>) pc.getUnjoinedPropertyIterator(), propertyMapper,
- versioningData.propertyStoreInfo, pc.getEntityName(), mappingData, versioningData.unversionedProperties,
+ versioningData.propertyStoreInfo, pc.getEntityName(), xmlMappingData, versioningData.unversionedProperties,
true);
// Creating and mapping joins (first pass)
createJoins(pc, class_mapping, versioningData);
- addJoins(pc, propertyMapper, versioningData.propertyStoreInfo, pc.getEntityName(), mappingData,
+ addJoins(pc, propertyMapper, versioningData.propertyStoreInfo, pc.getEntityName(), xmlMappingData,
versioningData.unversionedProperties, true);
// Storing the generated configuration
@@ -773,27 +365,57 @@
@SuppressWarnings({"unchecked"})
public void generateSecondPass(PersistentClass pc, PersistentClassVersioningData versioningData,
- EntityMappingData mappingData) {
+ EntityXmlMappingData xmlMappingData) {
String entityName = pc.getEntityName();
CompositeMapperBuilder propertyMapper = entitiesConfigurations.get(entityName).getPropertyMapper();
// Mapping unjoined properties
- Element parent = mappingData.getMainMapping().getRootElement().element("class");
+ Element parent = xmlMappingData.getMainXmlMapping().getRootElement().element("class");
if (parent == null) {
- parent = mappingData.getMainMapping().getRootElement().element("subclass");
+ parent = xmlMappingData.getMainXmlMapping().getRootElement().element("subclass");
}
addProperties(parent, (Iterator<Property>) pc.getUnjoinedPropertyIterator(),
- propertyMapper, versioningData.propertyStoreInfo, entityName, mappingData,
+ propertyMapper, versioningData.propertyStoreInfo, entityName, xmlMappingData,
versioningData.unversionedProperties, false);
// Mapping joins (second pass)
- addJoins(pc, propertyMapper, versioningData.propertyStoreInfo, entityName, mappingData,
+ addJoins(pc, propertyMapper, versioningData.propertyStoreInfo, entityName, xmlMappingData,
versioningData.unversionedProperties, false);
}
public Map<String, EntityConfiguration> getEntitiesConfigurations() {
return entitiesConfigurations;
}
+
+ // Getters for generators and configuration
+
+ BasicMetadataGenerator getBasicMetadataGenerator() {
+ return basicMetadataGenerator;
+ }
+
+ IdMetadataGenerator getIdMetadataGenerator() {
+ return idMetadataGenerator;
+ }
+
+ CollectionMetadataGenerator getCollectionMetadataGenerator() {
+ return collectionMetadataGenerator;
+ }
+
+ ToOneRelationMetadataGenerator getToOneRelationMetadataGenerator() {
+ return toOneRelationMetadataGenerator;
+ }
+
+ Configuration getCfg() {
+ return cfg;
+ }
+
+ GlobalConfiguration getGlobalCfg() {
+ return globalCfg;
+ }
+
+ VersionsEntitiesConfiguration getVerEntCfg() {
+ return verEntCfg;
+ }
}
Deleted: trunk/src/main/org/jboss/envers/entities/mapper/CompositePropertyMapperBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/CompositePropertyMapperBuilder.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/entities/mapper/CompositePropertyMapperBuilder.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -1,28 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.entities.mapper;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public interface CompositePropertyMapperBuilder extends PropertyMapper, CompositeMapperBuilder {
-}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/entities/mapper/MapPropertyMapper.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -39,7 +39,7 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class MapPropertyMapper implements CompositePropertyMapperBuilder {
+public class MapPropertyMapper implements PropertyMapper, CompositeMapperBuilder {
private String propertyName;
private ExtendedPropertyMapper delegate;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/entities/mapper/MultiPropertyMapper.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -55,7 +55,7 @@
throw new MappingException("Mapping for " + propertyName + " already added!");
}
- CompositePropertyMapperBuilder mapperBuilder = new MapPropertyMapper(propertyName);
+ MapPropertyMapper mapperBuilder = new MapPropertyMapper(propertyName);
properties.put(propertyName, mapperBuilder);
return mapperBuilder;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -26,6 +26,8 @@
import java.util.Map;
/**
+ * Data describing the change of a single object in a persisten collection (when the object was added, removed or
+ * modified in the collection).
* @author Adam Warski (adam at warski dot org)
*/
public class PersistentCollectionChangeData {
@@ -39,6 +41,10 @@
this.obj = obj;
}
+ /**
+ *
+ * @return Name of the (middle) entity that holds the collection data.
+ */
public String getEntityName() {
return entityName;
}
@@ -47,6 +53,10 @@
return data;
}
+ /**
+ *
+ * @return The affected object, which was changed (added, removed, modified) in the collection.
+ */
public Object getObj() {
return obj;
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/entities/mapper/PropertyMapper.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -36,9 +36,8 @@
/**
* Maps properties to the given map, basing on differences between properties of new and old objects.
* @param data Data to map to.
- * @param newObj If the modification store for a property is DIFF, diff-s are created from differences between
- * newObj and oldObj.
- * @param oldObj Data to map from.
+ * @param newObj New state of the entity.
+ * @param oldObj Old state of the entity.
* @return True if there are any differences between the states represented by newObj and oldObj.
*/
public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj);
@@ -50,7 +49,7 @@
* @param data Data to map from.
* @param primaryKey Primary key of the object to which we map (for relations)
* @param versionsReader VersionsReader for reading relations
- * @param revision Revision at which the obejct is read, for reading relations
+ * @param revision Revision at which the object is read, for reading relations
*/
public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey,
VersionsReaderImplementor versionsReader, Number revision);
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -28,6 +28,7 @@
import org.jboss.envers.entities.mapper.relation.lazy.proxy.ListProxy;
import org.jboss.envers.entities.mapper.relation.lazy.proxy.SetProxy;
import org.jboss.envers.entities.mapper.relation.lazy.proxy.Initializor;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.MapProxy;
import org.jboss.envers.entities.mapper.PropertyMapper;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
@@ -48,10 +49,10 @@
this.propertyName = propertyName;
}
- protected abstract <T extends Collection> Initializor<T> getInitializator(VersionsConfiguration verCfg,
- VersionsReaderImplementor versionsReader,
- Class<?> entityClass, Object primaryKey,
- Number revision, Class<T> collectionClass);
+ protected abstract <T> Initializor<T> getInitializator(VersionsConfiguration verCfg,
+ VersionsReaderImplementor versionsReader,
+ Class<?> entityClass, Object primaryKey,
+ Number revision, Class<T> collectionClass);
@SuppressWarnings({"unchecked"})
public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey,
@@ -71,6 +72,8 @@
value = new ListProxy(getInitializator(verCfg, versionsReader, entityClass, primaryKey, revision, ArrayList.class));
} else if (Set.class.isAssignableFrom(collectionClass) || Collection.class.isAssignableFrom(collectionClass)) {
value = new SetProxy(getInitializator(verCfg, versionsReader, entityClass, primaryKey, revision, HashSet.class));
+ } else if (Map.class.isAssignableFrom(collectionClass)) {
+ value = new MapProxy(getInitializator(verCfg, versionsReader, entityClass, primaryKey, revision, HashMap.class));
} else {
throw new VersionsException("Unsupported versioned collection type: " + collectionClass.getName());
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -134,7 +134,7 @@
return false;
}
- protected <T extends Collection> Initializor<T> getInitializator(VersionsConfiguration verCfg,
+ protected <T> Initializor<T> getInitializator(VersionsConfiguration verCfg,
VersionsReaderImplementor versionsReader,
Class<?> entityClass, Object primaryKey,
Number revision, Class<T> collectionClass) {
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/DetachedRelationInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/DetachedRelationInitializor.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/DetachedRelationInitializor.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -36,7 +36,7 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class DetachedRelationInitializor<T extends Collection> implements Initializor<T> {
+public class DetachedRelationInitializor<T> implements Initializor<T> {
private final VersionsConfiguration verCfg;
private final String entityName;
private final DetachedRelationQueryGenerator queryGenerator;
@@ -71,7 +71,8 @@
throw new VersionsException(e);
}
- entityInstantiator.addInstancesFromVersionsEntities(entityName, result, queryResult, revision);
+ // TODO
+ entityInstantiator.addInstancesFromVersionsEntities(entityName, (Collection) result, queryResult, revision);
return result;
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/Initializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/Initializor.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/Initializor.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -26,6 +26,6 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public interface Initializor<T extends Collection> {
+public interface Initializor<T> {
T initialize();
}
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/MapProxy.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/MapProxy.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/proxy/MapProxy.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.proxy;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.Collection;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class MapProxy<K, V> implements Map<K, V> {
+ private Initializor<Map<K, V>> initializor;
+ protected Map<K, V> delegate;
+
+ public MapProxy(Initializor<Map<K, V>> initializor) {
+ this.initializor = initializor;
+ }
+
+ private void checkInit() {
+ if (delegate == null) {
+ delegate = initializor.initialize();
+ }
+ }
+
+ public int size() {
+ checkInit();
+ return delegate.size();
+ }
+
+ public boolean isEmpty() {
+ checkInit();
+ return delegate.isEmpty();
+ }
+
+ public boolean containsKey(Object o) {
+ checkInit();
+ return delegate.containsKey(o);
+ }
+
+ public boolean containsValue(Object o) {
+ checkInit();
+ return delegate.containsValue(o);
+ }
+
+ public V get(Object o) {
+ checkInit();
+ return delegate.get(o);
+ }
+
+ public V put(K k, V v) {
+ checkInit();
+ return delegate.put(k, v);
+ }
+
+ public V remove(Object o) {
+ checkInit();
+ return delegate.remove(o);
+ }
+
+ public void putAll(Map<? extends K, ? extends V> map) {
+ checkInit();
+ delegate.putAll(map);
+ }
+
+ public void clear() {
+ checkInit();
+ delegate.clear();
+ }
+
+ public Set<K> keySet() {
+ checkInit();
+ return delegate.keySet();
+ }
+
+ public Collection<V> values() {
+ checkInit();
+ return delegate.values();
+ }
+
+ public Set<Entry<K, V>> entrySet() {
+ checkInit();
+ return delegate.entrySet();
+ }
+
+ @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"})
+ public boolean equals(Object o) {
+ checkInit();
+ return delegate.equals(o);
+ }
+
+ public int hashCode() {
+ checkInit();
+ return delegate.hashCode();
+ }
+}
Modified: trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/query/criteria/CriteriaTools.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -42,7 +42,7 @@
public static RelationDescription getRelatedEntity(VersionsConfiguration verCfg, String entityName,
String propertyName) throws VersionsException {
- RelationDescription relationDesc = verCfg.getEntCfg().get(entityName).getRelationDescription(propertyName);
+ RelationDescription relationDesc = verCfg.getEntCfg().getRelationDescription(entityName, propertyName);
if (relationDesc == null) {
return null;
Modified: trunk/src/main/org/jboss/envers/tools/reflection/ReflectionTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/reflection/ReflectionTools.java 2008-09-03 09:54:06 UTC (rev 148)
+++ trunk/src/main/org/jboss/envers/tools/reflection/ReflectionTools.java 2008-09-15 15:32:02 UTC (rev 149)
@@ -62,7 +62,7 @@
Getter value = getterCache.get(key);
if (value == null) {
value = ReflectHelper.getGetter(cls, propertyName);
- // It's ok if two getter are generated concurrently
+ // It's ok if two getters are generated concurrently
getterCache.put(key, value);
}
16 years, 1 month
JBoss Envers SVN: r148 - trunk/src/main/org/jboss/envers/query.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-03 05:54:06 -0400 (Wed, 03 Sep 2008)
New Revision: 148
Modified:
trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java
Log:
Javadoc fix
Modified: trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-09-03 09:48:55 UTC (rev 147)
+++ trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-09-03 09:54:06 UTC (rev 148)
@@ -62,6 +62,7 @@
* <li>revision entity, corresponding to the revision at which the entity was modified. If no custom
* revision entity is used, this will be an instance of {@link org.jboss.envers.DefaultRevisionEntity}</li>
* <li>type of the revision (an enum instance of class {@link org.jboss.envers.RevisionType})</li>.
+ * </ol>
* Additional conditions that the results must satisfy may be specified.
* @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
16 years, 2 months
JBoss Envers SVN: r147 - in demos/seam: lib and 1 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-03 05:48:55 -0400 (Wed, 03 Sep 2008)
New Revision: 147
Added:
demos/seam/lib/envers-1.1.0.beta1.jar
demos/seam/lib/hibernate3.jar
demos/seam/lib/lucene-core-2.3.0.jar
Removed:
demos/seam/lib/envers-1.0.0.ga.jar
demos/seam/lib/hibernate.jar
demos/seam/lib/lucene-core.jar
Modified:
demos/seam/build.xml
demos/seam/lib/hibernate-annotations.jar
demos/seam/lib/hibernate-entitymanager.jar
demos/seam/lib/hibernate-search.jar
demos/seam/src/action/org/jboss/envers/demo/seam/persons/PersonsAddresses.java
demos/seam/src/action/org/jboss/envers/demo/seam/persons/Register.java
Log:
Updated demo
Modified: demos/seam/build.xml
===================================================================
--- demos/seam/build.xml 2008-09-03 08:41:02 UTC (rev 146)
+++ demos/seam/build.xml 2008-09-03 09:48:55 UTC (rev 147)
@@ -153,8 +153,8 @@
<include name="lib/richfaces-api*.jar" />
<include name="lib/jsf-facelets*.jar"/>
<include name="lib/envers*.jar"/>
- <!--<include name="lib/hibernate*.jar"/>
- <include name="lib/lucene*.jar"/>-->
+ <include name="lib/hibernate*.jar"/>
+ <include name="lib/lucene*.jar"/>
</fileset>
</copy>
<copy todir="${ear.dir}/META-INF">
Deleted: demos/seam/lib/envers-1.0.0.ga.jar
===================================================================
(Binary files differ)
Added: demos/seam/lib/envers-1.1.0.beta1.jar
===================================================================
(Binary files differ)
Property changes on: demos/seam/lib/envers-1.1.0.beta1.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: demos/seam/lib/hibernate-annotations.jar
===================================================================
(Binary files differ)
Modified: demos/seam/lib/hibernate-entitymanager.jar
===================================================================
(Binary files differ)
Modified: demos/seam/lib/hibernate-search.jar
===================================================================
(Binary files differ)
Deleted: demos/seam/lib/hibernate.jar
===================================================================
(Binary files differ)
Added: demos/seam/lib/hibernate3.jar
===================================================================
(Binary files differ)
Property changes on: demos/seam/lib/hibernate3.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: demos/seam/lib/lucene-core-2.3.0.jar
===================================================================
(Binary files differ)
Property changes on: demos/seam/lib/lucene-core-2.3.0.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: demos/seam/lib/lucene-core.jar
===================================================================
(Binary files differ)
Modified: demos/seam/src/action/org/jboss/envers/demo/seam/persons/PersonsAddresses.java
===================================================================
--- demos/seam/src/action/org/jboss/envers/demo/seam/persons/PersonsAddresses.java 2008-09-03 08:41:02 UTC (rev 146)
+++ demos/seam/src/action/org/jboss/envers/demo/seam/persons/PersonsAddresses.java 2008-09-03 09:48:55 UTC (rev 147)
@@ -4,7 +4,6 @@
import org.jboss.seam.annotations.Name;
import org.jboss.envers.VersionsReader;
import org.jboss.envers.query.VersionsRestrictions;
-import org.hibernate.criterion.Order;
import javax.persistence.NoResultException;
import java.util.List;
@@ -37,9 +36,9 @@
public List<Registration> getRegistrations() {
if (registrations == null) {
registrations = versionsReader.createQuery()
- .forRevisionsOfEntity(Registration.class, true)
+ .forRevisionsOfEntity(Registration.class, true, false)
.add(VersionsRestrictions.relatedIdEq("person", person.getId()))
- .addOrder(Order.asc("registrationDate"))
+ .addOrder("registrationDate", true)
.getResultList();
}
@@ -49,7 +48,7 @@
public void check() {
try {
regOnCheckDate = (Registration) versionsReader.createQuery()
- .forRevisionsOfEntity(Registration.class, true)
+ .forRevisionsOfEntity(Registration.class, true, false)
.add(VersionsRestrictions.maximizeProperty("actualDate")
.add(VersionsRestrictions.relatedIdEq("person", person.getId()))
.add(VersionsRestrictions.le("registrationDate", addressCheckDate))
@@ -61,7 +60,7 @@
try {
regNow = (Registration) versionsReader.createQuery()
- .forRevisionsOfEntity(Registration.class, true)
+ .forRevisionsOfEntity(Registration.class, true, false)
.add(VersionsRestrictions.maximizeProperty("actualDate")
.add(VersionsRestrictions.relatedIdEq("person", person.getId()))
.add(VersionsRestrictions.le("actualDate", addressCheckDate)))
Modified: demos/seam/src/action/org/jboss/envers/demo/seam/persons/Register.java
===================================================================
--- demos/seam/src/action/org/jboss/envers/demo/seam/persons/Register.java 2008-09-03 08:41:02 UTC (rev 146)
+++ demos/seam/src/action/org/jboss/envers/demo/seam/persons/Register.java 2008-09-03 09:48:55 UTC (rev 147)
@@ -59,9 +59,9 @@
public boolean register() {
// Checking if there is no registration with the same registration date already
- int registrationsWithSameRegDate = (Integer) versionsReader.createQuery()
- .forRevisionsOfEntity(Registration.class, false)
- .setProjection(RevisionProperty.count())
+ long registrationsWithSameRegDate = (Long) versionsReader.createQuery()
+ .forRevisionsOfEntity(Registration.class, false, false)
+ .addProjection(RevisionProperty.count())
.add(VersionsRestrictions.relatedIdEq("person", person.getId()))
.add(VersionsRestrictions.eq("registrationDate", registrationDate))
.getSingleResult();
@@ -73,9 +73,9 @@
}
// Checking if there is no registration with the same actual date already
- int registrationsWithSameActDate = (Integer) versionsReader.createQuery()
- .forRevisionsOfEntity(Registration.class, false)
- .setProjection(RevisionProperty.count())
+ long registrationsWithSameActDate = (Long) versionsReader.createQuery()
+ .forRevisionsOfEntity(Registration.class, false, false)
+ .addProjection(RevisionProperty.count())
.add(VersionsRestrictions.relatedIdEq("person", person.getId()))
.add(VersionsRestrictions.eq("actualDate", actualDate))
.getSingleResult();
16 years, 2 months
JBoss Envers SVN: r146 - tags.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-03 04:41:02 -0400 (Wed, 03 Sep 2008)
New Revision: 146
Added:
tags/1.1.0-beta1/
Log:
Tagging the 1.1.0.beta1 release
Copied: tags/1.1.0-beta1 (from rev 145, trunk)
16 years, 2 months
JBoss Envers SVN: r145 - in trunk/src: test/org/jboss/envers/test/integration/reventity and 1 other directory.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-03 04:13:16 -0400 (Wed, 03 Sep 2008)
New Revision: 145
Removed:
trunk/src/main/org/jboss/envers/query/impl/Parameters.java
trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java
trunk/src/test/org/jboss/envers/test/integration/reventity/CustomRevEntity.java
Log:
Cleanup
Deleted: trunk/src/main/org/jboss/envers/query/impl/Parameters.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/Parameters.java 2008-09-03 08:12:08 UTC (rev 144)
+++ trunk/src/main/org/jboss/envers/query/impl/Parameters.java 2008-09-03 08:13:16 UTC (rev 145)
@@ -1,227 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- *
- * See the copyright.txt in the distribution for a full listing of individual
- * contributors. 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.query.impl;
-
-import org.jboss.envers.tools.MutableInteger;
-import org.jboss.envers.tools.MutableBoolean;
-
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * Parameters of a query, built using {@link org.jboss.envers.query.impl.QueryBuilder}.
- * @author Adam Warski (adam at warski dot org)
- */
-public class Parameters {
- public final static String AND = "and";
- public final static String OR = "or";
-
- /**
- * Main alias of the entity.
- */
- private final String alias;
- /**
- * Connective between these parameters - "and" or "or".
- */
- private final String connective;
- /**
- * For use by the parameter generator. Must be the same in all "child" (and parent) parameters.
- */
- private final MutableInteger queryParamCounter;
-
- /**
- * A list of sub-parameters (parameters with a different connective).
- */
- private final List<Parameters> subParameters;
- /**
- * A list of negated parameters.
- */
- private final List<Parameters> negatedParameters;
- /**
- * A list of complete where-expressions.
- */
- private final List<String> expressions;
- /**
- * Values of parameters used in expressions.
- */
- private final Map<String, Object> localQueryParamValues;
-
- Parameters(String alias, String connective, MutableInteger queryParamCounter) {
- this.alias = alias;
- this.connective = connective;
- this.queryParamCounter = queryParamCounter;
-
- subParameters = new ArrayList<Parameters>();
- negatedParameters = new ArrayList<Parameters>();
- expressions = new ArrayList<String>();
- localQueryParamValues = new HashMap<String, Object>();
- }
-
- private String generateQueryParam() {
- return "_p" + queryParamCounter.getAndIncrease();
- }
-
- /**
- * Adds sub-parameters with a new connective. That is, the parameters will be grouped in parentheses in the
- * generated query, e.g.: ... and (exp1 or exp2) and ..., assuming the old connective is "and", and the
- * new connective is "or".
- * @param newConnective New connective of the parameters.
- * @return Sub-parameters with the given connective.
- */
- public Parameters addSubParameters(String newConnective) {
- if (connective.equals(newConnective)) {
- return this;
- } else {
- Parameters newParams = new Parameters(alias, newConnective, queryParamCounter);
- subParameters.add(newParams);
- return newParams;
- }
- }
-
- /**
- * Adds negated parameters, by default with the "and" connective. These paremeters will be grouped in parentheses
- * in the generated query and negated, e.g. ... not (exp1 and exp2) ...
- * @return Negated sub paremters.
- */
- public Parameters addNegatedParameters() {
- Parameters newParams = new Parameters(alias, AND, queryParamCounter);
- negatedParameters.add(newParams);
- return newParams;
- }
-
- public void addWhere(String left, String op, String right) {
- addWhere(left, true, op, right, true);
- }
-
- public void addWhere(String left, boolean addAliasLeft, String op, String right, boolean addAliasRight) {
- StringBuilder expression = new StringBuilder();
-
- if (addAliasLeft) { expression.append(alias).append("."); }
- expression.append(left);
-
- expression.append(" ").append(op).append(" ");
-
- if (addAliasRight) { expression.append(alias).append("."); }
- expression.append(right);
-
- expressions.add(expression.toString());
- }
-
- public void addWhereWithParam(String left, String op, Object paramValue) {
- addWhereWithParam(left, true, op, paramValue);
- }
-
- public void addWhereWithParam(String left, boolean addAlias, String op, Object paramValue) {
- StringBuilder expression = new StringBuilder();
-
- if (addAlias) { expression.append(alias).append("."); }
- expression.append(left);
-
- expression.append(" ").append(op).append(" ");
-
- String paramName = generateQueryParam();
- localQueryParamValues.put(paramName, paramValue);
- expression.append(":").append(paramName);
-
- expressions.add(expression.toString());
- }
-
- public void addWhereWithParams(String left, String opStart, Object[] paramValues, String opEnd) {
- StringBuilder expression = new StringBuilder();
-
- expression.append(alias).append(".").append(left).append(" ").append(opStart);
-
- for (int i=0; i<paramValues.length; i++) {
- Object paramValue = paramValues[i];
- String paramName = generateQueryParam();
- localQueryParamValues.put(paramName, paramValue);
- expression.append(":").append(paramName);
-
- if (i != paramValues.length-1) {
- expression.append(", ");
- }
- }
-
- expression.append(opEnd);
-
- expressions.add(expression.toString());
- }
-
- public void addWhere(String left, String op, QueryBuilder right) {
- StringBuilder expression = new StringBuilder();
-
- expression.append(alias).append(".").append(left);
-
- expression.append(" ").append(op).append(" ");
-
- expression.append("(");
- right.build(expression, localQueryParamValues);
- expression.append(")");
-
- expressions.add(expression.toString());
- }
-
- private void append(StringBuilder sb, String toAppend, MutableBoolean isFirst) {
- if (!isFirst.isSet()) {
- sb.append(" ").append(connective).append(" ");
- }
-
- sb.append(toAppend);
-
- isFirst.unset();
- }
-
- boolean isEmpty() {
- return expressions.size() == 0 && subParameters.size() == 0 && negatedParameters.size() == 0;
- }
-
- void build(StringBuilder sb, Map<String, Object> queryParamValues) {
- MutableBoolean isFirst = new MutableBoolean(true);
-
- for (String expression : expressions) {
- append(sb, expression, isFirst);
- }
-
- for (Parameters sub : subParameters) {
- if (!subParameters.isEmpty()) {
- append(sb, "(", isFirst);
- sub.build(sb, queryParamValues);
- sb.append(")");
- }
- }
-
- for (Parameters negated : negatedParameters) {
- if (!negatedParameters.isEmpty()) {
- append(sb, "not (", isFirst);
- negated.build(sb, queryParamValues);
- sb.append(")");
- }
- }
-
- queryParamValues.putAll(localQueryParamValues);
- }
-}
-
Deleted: trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java 2008-09-03 08:12:08 UTC (rev 144)
+++ trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java 2008-09-03 08:13:16 UTC (rev 145)
@@ -1,196 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- *
- * See the copyright.txt in the distribution for a full listing of individual
- * contributors. 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.query.impl;
-
-import org.jboss.envers.tools.MutableInteger;
-import org.jboss.envers.tools.Pair;
-import org.jboss.envers.tools.StringTools;
-
-import java.util.Map;
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * A class for incrementaly building a HQL query.
- * @author Adam Warski (adam at warski dot org)
- */
-public class QueryBuilder {
- private final String entityName;
- private final String alias;
-
- /**
- * For use by alias generator (in case an alias is not provided by the user).
- */
- private final MutableInteger aliasCounter;
- /**
- * For use by parameter generator, in {@link org.jboss.envers.query.impl.Parameters}. This counter must be
- * the same in all parameters and sub-queries of this query.
- */
- private final MutableInteger paramCounter;
- /**
- * Main "where" parameters for this query.
- */
- private final Parameters rootParameters;
-
- /**
- * A list of pairs (from entity name, alias name).
- */
- private final List<Pair<String, String>> froms;
- /**
- * A list of pairs (property name, order ascending?).
- */
- private final List<Pair<String, Boolean>> orders;
- /**
- * A list of complete projection definitions: either a sole property name, or a function(property name).
- */
- private final List<String> projections;
-
- /**
- *
- * @param entityName Main entity which should be selected.
- * @param alias Alias of the entity
- */
- public QueryBuilder(String entityName, String alias) {
- this(entityName, alias, new MutableInteger(), new MutableInteger());
- }
-
- private QueryBuilder(String entityName, String alias, MutableInteger aliasCounter, MutableInteger paramCounter) {
- this.entityName = entityName;
- this.alias = alias;
- this.aliasCounter = aliasCounter;
- this.paramCounter = paramCounter;
-
- rootParameters = new Parameters(alias, "and", paramCounter);
-
- froms = new ArrayList<Pair<String, String>>();
- orders = new ArrayList<Pair<String, Boolean>>();
- projections = new ArrayList<String>();
-
- addFrom(entityName, alias);
- }
-
- /**
- * Add an entity from which to select.
- * @param entityName Name of the entity from which to select.
- * @param alias Alias of the entity. Should be different than all other aliases.
- */
- public void addFrom(String entityName, String alias) {
- froms.add(Pair.make(entityName, alias));
- }
-
- private String generateAlias() {
- return "_e" + aliasCounter.getAndIncrease();
- }
-
- /**
- * @return A sub-query builder for the same entity (with an auto-generated alias). The sub-query can
- * be later used as a value of a parameter.
- */
- public QueryBuilder newSubQueryBuilder() {
- return newSubQueryBuilder(entityName, generateAlias());
- }
-
- /**
- * @param entityName Entity name, which will be the main entity for the sub-query.
- * @param alias Alias of the entity, which can later be used in parameters.
- * @return A sub-query builder for the given entity, with the given alias. The sub-query can
- * be later used as a value of a parameter.
- */
- public QueryBuilder newSubQueryBuilder(String entityName, String alias) {
- return new QueryBuilder(entityName, alias, aliasCounter, paramCounter);
- }
-
- public Parameters getRootParameters() {
- return rootParameters;
- }
-
- public void addOrder(String propertyName, boolean ascending) {
- orders.add(Pair.make(propertyName, ascending));
- }
-
- public void addProjection(String function, String propertyName, boolean distinct) {
- if (function == null) {
- projections.add((distinct ? "distinct " : "") + alias + "." + propertyName);
- } else {
- projections.add(function + "(" + (distinct ? "distinct " : "") + alias + "." + propertyName + ")");
- }
- }
-
- /**
- * Builds the given query, appending results to the given string buffer, and adding all query parameter values
- * that are used to the map provided.
- * @param sb String builder to which the query will be appended.
- * @param queryParamValues Values of parameters used in the query.
- */
- public void build(StringBuilder sb, Map<String, Object> queryParamValues) {
- sb.append("select ");
- if (projections.size() > 0) {
- // all projections separated with commas
- StringTools.append(sb, projections.iterator(), ", ");
- } else {
- // all aliases separated with commas
- StringTools.append(sb, getAliasList().iterator(), ", ");
- }
- sb.append(" from ");
- // all from entities with aliases, separated with commas
- StringTools.append(sb, getFromList().iterator(), ", ");
- // where part - rootParameters
- if (!rootParameters.isEmpty()) {
- sb.append(" where ");
- rootParameters.build(sb, queryParamValues);
- }
- // orders
- if (orders.size() > 0) {
- sb.append(" order by ");
- StringTools.append(sb, getOrderList().iterator(), ", ");
- }
- }
-
- private List<String> getAliasList() {
- List<String> aliasList = new ArrayList<String>();
- for (Pair<String, String> from : froms) {
- aliasList.add(from.getSecond());
- }
-
- return aliasList;
- }
-
- private List<String> getFromList() {
- List<String> fromList = new ArrayList<String>();
- for (Pair<String, String> from : froms) {
- fromList.add(from.getFirst() + " " + from.getSecond());
- }
-
- return fromList;
- }
-
- private List<String> getOrderList() {
- List<String> orderList = new ArrayList<String>();
- for (Pair<String, Boolean> order : orders) {
- orderList.add(alias + "." + order.getFirst() + " " + (order.getSecond() ? "asc" : "desc"));
- }
-
- return orderList;
- }
-}
Deleted: trunk/src/test/org/jboss/envers/test/integration/reventity/CustomRevEntity.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/reventity/CustomRevEntity.java 2008-09-03 08:12:08 UTC (rev 144)
+++ trunk/src/test/org/jboss/envers/test/integration/reventity/CustomRevEntity.java 2008-09-03 08:13:16 UTC (rev 145)
@@ -1,59 +0,0 @@
-package org.jboss.envers.test.integration.reventity;
-
-import org.jboss.envers.RevisionNumber;
-import org.jboss.envers.RevisionTimestamp;
-import org.jboss.envers.RevisionEntity;
-
-import javax.persistence.Id;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Entity;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-@Entity
-@RevisionEntity
-public class CustomRevEntity {
- @Id
- @GeneratedValue
- @RevisionNumber
- private int customId;
-
- @RevisionTimestamp
- private long customTimestamp;
-
- public int getCustomId() {
- return customId;
- }
-
- public void setCustomId(int customId) {
- this.customId = customId;
- }
-
- public long getCustomTimestamp() {
- return customTimestamp;
- }
-
- public void setCustomTimestamp(long customTimestamp) {
- this.customTimestamp = customTimestamp;
- }
-
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof CustomRevEntity)) return false;
-
- CustomRevEntity that = (CustomRevEntity) o;
-
- if (customId != that.customId) return false;
- if (customTimestamp != that.customTimestamp) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result;
- result = customId;
- result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32));
- return result;
- }
-}
16 years, 2 months
JBoss Envers SVN: r144 - in trunk/src/main/org/jboss/envers: query/criteria and 3 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-03 04:12:08 -0400 (Wed, 03 Sep 2008)
New Revision: 144
Added:
trunk/src/main/org/jboss/envers/tools/query/
trunk/src/main/org/jboss/envers/tools/query/Parameters.java
trunk/src/main/org/jboss/envers/tools/query/QueryBuilder.java
Modified:
trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java
trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/BetweenVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/InVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/LogicalVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/NotVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/PropertyVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java
trunk/src/main/org/jboss/envers/query/criteria/VersionsCriterion.java
trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java
trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
Log:
ENVERS-47: moving query builder to tools
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -21,7 +21,7 @@
*/
package org.jboss.envers.entities.mapper.id;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.Parameters;
import java.util.Iterator;
import java.util.List;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -21,7 +21,7 @@
*/
package org.jboss.envers.entities.mapper.id;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.Parameters;
import java.util.Map;
import java.util.List;
Modified: trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
import java.util.List;
import java.util.ArrayList;
Modified: trunk/src/main/org/jboss/envers/query/criteria/BetweenVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/BetweenVersionsExpression.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/BetweenVersionsExpression.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/query/criteria/InVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/InVersionsExpression.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/InVersionsExpression.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/query/criteria/LogicalVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/LogicalVersionsExpression.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/LogicalVersionsExpression.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -23,8 +23,8 @@
import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/query/criteria/NotVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NotVersionsExpression.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/NotVersionsExpression.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -23,8 +23,8 @@
import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/query/criteria/PropertyVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/PropertyVersionsExpression.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/PropertyVersionsExpression.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -24,8 +24,8 @@
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -24,8 +24,8 @@
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
import java.util.ArrayList;
import java.util.List;
Modified: trunk/src/main/org/jboss/envers/query/criteria/VersionsCriterion.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/VersionsCriterion.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/VersionsCriterion.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -22,8 +22,8 @@
package org.jboss.envers.query.criteria;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.query.impl.QueryBuilder;
-import org.jboss.envers.query.impl.Parameters;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
import java.util.List;
import java.util.ArrayList;
Modified: trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -31,6 +31,7 @@
import org.jboss.envers.configuration.VersionsConfiguration;
import org.jboss.envers.tools.Pair;
import org.jboss.envers.tools.Triple;
+import org.jboss.envers.tools.query.QueryBuilder;
import org.hibernate.*;
import javax.persistence.NonUniqueResultException;
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-09-03 08:10:24 UTC (rev 143)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -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.tools.query.QueryBuilder;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import org.jboss.envers.configuration.VersionsConfiguration;
Copied: trunk/src/main/org/jboss/envers/tools/query/Parameters.java (from rev 143, trunk/src/main/org/jboss/envers/query/impl/Parameters.java)
===================================================================
--- trunk/src/main/org/jboss/envers/tools/query/Parameters.java (rev 0)
+++ trunk/src/main/org/jboss/envers/tools/query/Parameters.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -0,0 +1,227 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.query;
+
+import org.jboss.envers.tools.MutableInteger;
+import org.jboss.envers.tools.MutableBoolean;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Parameters of a query, built using {@link QueryBuilder}.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class Parameters {
+ public final static String AND = "and";
+ public final static String OR = "or";
+
+ /**
+ * Main alias of the entity.
+ */
+ private final String alias;
+ /**
+ * Connective between these parameters - "and" or "or".
+ */
+ private final String connective;
+ /**
+ * For use by the parameter generator. Must be the same in all "child" (and parent) parameters.
+ */
+ private final MutableInteger queryParamCounter;
+
+ /**
+ * A list of sub-parameters (parameters with a different connective).
+ */
+ private final List<Parameters> subParameters;
+ /**
+ * A list of negated parameters.
+ */
+ private final List<Parameters> negatedParameters;
+ /**
+ * A list of complete where-expressions.
+ */
+ private final List<String> expressions;
+ /**
+ * Values of parameters used in expressions.
+ */
+ private final Map<String, Object> localQueryParamValues;
+
+ Parameters(String alias, String connective, MutableInteger queryParamCounter) {
+ this.alias = alias;
+ this.connective = connective;
+ this.queryParamCounter = queryParamCounter;
+
+ subParameters = new ArrayList<Parameters>();
+ negatedParameters = new ArrayList<Parameters>();
+ expressions = new ArrayList<String>();
+ localQueryParamValues = new HashMap<String, Object>();
+ }
+
+ private String generateQueryParam() {
+ return "_p" + queryParamCounter.getAndIncrease();
+ }
+
+ /**
+ * Adds sub-parameters with a new connective. That is, the parameters will be grouped in parentheses in the
+ * generated query, e.g.: ... and (exp1 or exp2) and ..., assuming the old connective is "and", and the
+ * new connective is "or".
+ * @param newConnective New connective of the parameters.
+ * @return Sub-parameters with the given connective.
+ */
+ public Parameters addSubParameters(String newConnective) {
+ if (connective.equals(newConnective)) {
+ return this;
+ } else {
+ Parameters newParams = new Parameters(alias, newConnective, queryParamCounter);
+ subParameters.add(newParams);
+ return newParams;
+ }
+ }
+
+ /**
+ * Adds negated parameters, by default with the "and" connective. These paremeters will be grouped in parentheses
+ * in the generated query and negated, e.g. ... not (exp1 and exp2) ...
+ * @return Negated sub paremters.
+ */
+ public Parameters addNegatedParameters() {
+ Parameters newParams = new Parameters(alias, AND, queryParamCounter);
+ negatedParameters.add(newParams);
+ return newParams;
+ }
+
+ public void addWhere(String left, String op, String right) {
+ addWhere(left, true, op, right, true);
+ }
+
+ public void addWhere(String left, boolean addAliasLeft, String op, String right, boolean addAliasRight) {
+ StringBuilder expression = new StringBuilder();
+
+ if (addAliasLeft) { expression.append(alias).append("."); }
+ expression.append(left);
+
+ expression.append(" ").append(op).append(" ");
+
+ if (addAliasRight) { expression.append(alias).append("."); }
+ expression.append(right);
+
+ expressions.add(expression.toString());
+ }
+
+ public void addWhereWithParam(String left, String op, Object paramValue) {
+ addWhereWithParam(left, true, op, paramValue);
+ }
+
+ public void addWhereWithParam(String left, boolean addAlias, String op, Object paramValue) {
+ StringBuilder expression = new StringBuilder();
+
+ if (addAlias) { expression.append(alias).append("."); }
+ expression.append(left);
+
+ expression.append(" ").append(op).append(" ");
+
+ String paramName = generateQueryParam();
+ localQueryParamValues.put(paramName, paramValue);
+ expression.append(":").append(paramName);
+
+ expressions.add(expression.toString());
+ }
+
+ public void addWhereWithParams(String left, String opStart, Object[] paramValues, String opEnd) {
+ StringBuilder expression = new StringBuilder();
+
+ expression.append(alias).append(".").append(left).append(" ").append(opStart);
+
+ for (int i=0; i<paramValues.length; i++) {
+ Object paramValue = paramValues[i];
+ String paramName = generateQueryParam();
+ localQueryParamValues.put(paramName, paramValue);
+ expression.append(":").append(paramName);
+
+ if (i != paramValues.length-1) {
+ expression.append(", ");
+ }
+ }
+
+ expression.append(opEnd);
+
+ expressions.add(expression.toString());
+ }
+
+ public void addWhere(String left, String op, QueryBuilder right) {
+ StringBuilder expression = new StringBuilder();
+
+ expression.append(alias).append(".").append(left);
+
+ expression.append(" ").append(op).append(" ");
+
+ expression.append("(");
+ right.build(expression, localQueryParamValues);
+ expression.append(")");
+
+ expressions.add(expression.toString());
+ }
+
+ private void append(StringBuilder sb, String toAppend, MutableBoolean isFirst) {
+ if (!isFirst.isSet()) {
+ sb.append(" ").append(connective).append(" ");
+ }
+
+ sb.append(toAppend);
+
+ isFirst.unset();
+ }
+
+ boolean isEmpty() {
+ return expressions.size() == 0 && subParameters.size() == 0 && negatedParameters.size() == 0;
+ }
+
+ void build(StringBuilder sb, Map<String, Object> queryParamValues) {
+ MutableBoolean isFirst = new MutableBoolean(true);
+
+ for (String expression : expressions) {
+ append(sb, expression, isFirst);
+ }
+
+ for (Parameters sub : subParameters) {
+ if (!subParameters.isEmpty()) {
+ append(sb, "(", isFirst);
+ sub.build(sb, queryParamValues);
+ sb.append(")");
+ }
+ }
+
+ for (Parameters negated : negatedParameters) {
+ if (!negatedParameters.isEmpty()) {
+ append(sb, "not (", isFirst);
+ negated.build(sb, queryParamValues);
+ sb.append(")");
+ }
+ }
+
+ queryParamValues.putAll(localQueryParamValues);
+ }
+}
+
Copied: trunk/src/main/org/jboss/envers/tools/query/QueryBuilder.java (from rev 143, trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java)
===================================================================
--- trunk/src/main/org/jboss/envers/tools/query/QueryBuilder.java (rev 0)
+++ trunk/src/main/org/jboss/envers/tools/query/QueryBuilder.java 2008-09-03 08:12:08 UTC (rev 144)
@@ -0,0 +1,196 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.query;
+
+import org.jboss.envers.tools.MutableInteger;
+import org.jboss.envers.tools.Pair;
+import org.jboss.envers.tools.StringTools;
+
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * A class for incrementaly building a HQL query.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class QueryBuilder {
+ private final String entityName;
+ private final String alias;
+
+ /**
+ * For use by alias generator (in case an alias is not provided by the user).
+ */
+ private final MutableInteger aliasCounter;
+ /**
+ * For use by parameter generator, in {@link Parameters}. This counter must be
+ * the same in all parameters and sub-queries of this query.
+ */
+ private final MutableInteger paramCounter;
+ /**
+ * Main "where" parameters for this query.
+ */
+ private final Parameters rootParameters;
+
+ /**
+ * A list of pairs (from entity name, alias name).
+ */
+ private final List<Pair<String, String>> froms;
+ /**
+ * A list of pairs (property name, order ascending?).
+ */
+ private final List<Pair<String, Boolean>> orders;
+ /**
+ * A list of complete projection definitions: either a sole property name, or a function(property name).
+ */
+ private final List<String> projections;
+
+ /**
+ *
+ * @param entityName Main entity which should be selected.
+ * @param alias Alias of the entity
+ */
+ public QueryBuilder(String entityName, String alias) {
+ this(entityName, alias, new MutableInteger(), new MutableInteger());
+ }
+
+ private QueryBuilder(String entityName, String alias, MutableInteger aliasCounter, MutableInteger paramCounter) {
+ this.entityName = entityName;
+ this.alias = alias;
+ this.aliasCounter = aliasCounter;
+ this.paramCounter = paramCounter;
+
+ rootParameters = new Parameters(alias, "and", paramCounter);
+
+ froms = new ArrayList<Pair<String, String>>();
+ orders = new ArrayList<Pair<String, Boolean>>();
+ projections = new ArrayList<String>();
+
+ addFrom(entityName, alias);
+ }
+
+ /**
+ * Add an entity from which to select.
+ * @param entityName Name of the entity from which to select.
+ * @param alias Alias of the entity. Should be different than all other aliases.
+ */
+ public void addFrom(String entityName, String alias) {
+ froms.add(Pair.make(entityName, alias));
+ }
+
+ private String generateAlias() {
+ return "_e" + aliasCounter.getAndIncrease();
+ }
+
+ /**
+ * @return A sub-query builder for the same entity (with an auto-generated alias). The sub-query can
+ * be later used as a value of a parameter.
+ */
+ public QueryBuilder newSubQueryBuilder() {
+ return newSubQueryBuilder(entityName, generateAlias());
+ }
+
+ /**
+ * @param entityName Entity name, which will be the main entity for the sub-query.
+ * @param alias Alias of the entity, which can later be used in parameters.
+ * @return A sub-query builder for the given entity, with the given alias. The sub-query can
+ * be later used as a value of a parameter.
+ */
+ public QueryBuilder newSubQueryBuilder(String entityName, String alias) {
+ return new QueryBuilder(entityName, alias, aliasCounter, paramCounter);
+ }
+
+ public Parameters getRootParameters() {
+ return rootParameters;
+ }
+
+ public void addOrder(String propertyName, boolean ascending) {
+ orders.add(Pair.make(propertyName, ascending));
+ }
+
+ public void addProjection(String function, String propertyName, boolean distinct) {
+ if (function == null) {
+ projections.add((distinct ? "distinct " : "") + alias + "." + propertyName);
+ } else {
+ projections.add(function + "(" + (distinct ? "distinct " : "") + alias + "." + propertyName + ")");
+ }
+ }
+
+ /**
+ * Builds the given query, appending results to the given string buffer, and adding all query parameter values
+ * that are used to the map provided.
+ * @param sb String builder to which the query will be appended.
+ * @param queryParamValues Values of parameters used in the query.
+ */
+ public void build(StringBuilder sb, Map<String, Object> queryParamValues) {
+ sb.append("select ");
+ if (projections.size() > 0) {
+ // all projections separated with commas
+ StringTools.append(sb, projections.iterator(), ", ");
+ } else {
+ // all aliases separated with commas
+ StringTools.append(sb, getAliasList().iterator(), ", ");
+ }
+ sb.append(" from ");
+ // all from entities with aliases, separated with commas
+ StringTools.append(sb, getFromList().iterator(), ", ");
+ // where part - rootParameters
+ if (!rootParameters.isEmpty()) {
+ sb.append(" where ");
+ rootParameters.build(sb, queryParamValues);
+ }
+ // orders
+ if (orders.size() > 0) {
+ sb.append(" order by ");
+ StringTools.append(sb, getOrderList().iterator(), ", ");
+ }
+ }
+
+ private List<String> getAliasList() {
+ List<String> aliasList = new ArrayList<String>();
+ for (Pair<String, String> from : froms) {
+ aliasList.add(from.getSecond());
+ }
+
+ return aliasList;
+ }
+
+ private List<String> getFromList() {
+ List<String> fromList = new ArrayList<String>();
+ for (Pair<String, String> from : froms) {
+ fromList.add(from.getFirst() + " " + from.getSecond());
+ }
+
+ return fromList;
+ }
+
+ private List<String> getOrderList() {
+ List<String> orderList = new ArrayList<String>();
+ for (Pair<String, Boolean> order : orders) {
+ orderList.add(alias + "." + order.getFirst() + " " + (order.getSecond() ? "asc" : "desc"));
+ }
+
+ return orderList;
+ }
+}
16 years, 2 months
JBoss Envers SVN: r143 - in trunk: resources/main/META-INF and 10 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-03 04:10:24 -0400 (Wed, 03 Sep 2008)
New Revision: 143
Added:
trunk/resources/main/META-INF/copyright.txt
Modified:
trunk/
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/metadata/EntityMappingData.java
trunk/src/main/org/jboss/envers/entities/RelationType.java
trunk/src/main/org/jboss/envers/entities/RevisionTypeType.java
trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/DetachedRelationQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/ManyToManyNotOwningMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/DetachedRelationInitializor.java
trunk/src/main/org/jboss/envers/query/impl/Parameters.java
trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java
trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoQueryCreator.java
trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java
Log:
Adding missing license headers
Property changes on: trunk
___________________________________________________________________
Name: svn:ignore
- build.properties
target
build
dist
doc
+ header.txt
build.properties
target
build
dist
doc
Added: trunk/resources/main/META-INF/copyright.txt
===================================================================
--- trunk/resources/main/META-INF/copyright.txt (rev 0)
+++ trunk/resources/main/META-INF/copyright.txt 2008-09-03 08:10:24 UTC (rev 143)
@@ -0,0 +1 @@
+(c) 2008, Adam Warski, JBoss Inc.
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.Properties;
@@ -12,7 +35,7 @@
// Should a warning, instead of an error and an exception, be logged, when an unsupported type is versioned
private final boolean warnOnUnsupportedTypes;
-
+
// Should the optimistic locking property of an entity be considered unversioned
private final boolean unversionedOptimisticLockingField;
@@ -24,9 +47,9 @@
String warnOnUnsupportedTypesStr = properties.getProperty("org.jboss.envers.warnOnUnsupportedTypes",
"false");
warnOnUnsupportedTypes = Boolean.parseBoolean(warnOnUnsupportedTypesStr);
-
+
String ignoreOptimisticLockingPropertyStr = properties.getProperty("org.jboss.envers.unversionedOptimisticLockingField",
- "false");
+ "false");
unversionedOptimisticLockingField = Boolean.parseBoolean(ignoreOptimisticLockingPropertyStr);
}
@@ -37,9 +60,9 @@
public boolean isWarnOnUnsupportedTypes() {
return warnOnUnsupportedTypes;
}
-
+
public boolean isUnversionedOptimisticLockingField() {
return unversionedOptimisticLockingField;
}
-
+
}
Modified: trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.tools.reflection.YClass;
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/EntityMappingData.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/EntityMappingData.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/EntityMappingData.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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;
Modified: trunk/src/main/org/jboss/envers/entities/RelationType.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/RelationType.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/entities/RelationType.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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;
/**
Modified: trunk/src/main/org/jboss/envers/entities/RevisionTypeType.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/RevisionTypeType.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/entities/RevisionTypeType.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. This copyrighted material is made available to anyone wishing
+ * to use, modify, copy, or redistribute it subject to the terms and
+ * conditions of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
package org.jboss.envers.entities;
import org.hibernate.usertype.UserType;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/entities/mapper/PersistentCollectionChangeData.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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;
import java.util.Map;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractOneToManyMapper.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.reader.VersionsReaderImplementor;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/DetachedRelationQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/DetachedRelationQueryGenerator.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/DetachedRelationQueryGenerator.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.id.QueryParameterData;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/ManyToManyNotOwningMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/ManyToManyNotOwningMapper.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/ManyToManyNotOwningMapper.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyDetachedMapper.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/DetachedRelationInitializor.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/DetachedRelationInitializor.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/DetachedRelationInitializor.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.entities.mapper.relation.lazy.proxy.Initializor;
Modified: trunk/src/main/org/jboss/envers/query/impl/Parameters.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/Parameters.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/query/impl/Parameters.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.query.impl;
import org.jboss.envers.tools.MutableInteger;
Modified: trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.query.impl;
import org.jboss.envers.tools.MutableInteger;
Modified: trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoQueryCreator.java
===================================================================
--- trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoQueryCreator.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/revisioninfo/RevisionInfoQueryCreator.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. 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.hibernate.Session;
Modified: trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/main/org/jboss/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ *
+ * See the copyright.txt in the distribution for a full listing of individual
+ * contributors. This copyrighted material is made available to anyone wishing
+ * to use, modify, copy, or redistribute it subject to the terms and
+ * conditions of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
package org.jboss.envers.synchronization.work;
import org.hibernate.Session;
Modified: trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java 2008-09-03 07:50:01 UTC (rev 142)
+++ trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java 2008-09-03 08:10:24 UTC (rev 143)
@@ -4,14 +4,12 @@
import org.jboss.envers.test.entities.StrIntTestEntity;
import org.jboss.envers.test.entities.reventity.CustomRevEntity;
import org.jboss.envers.query.VersionsRestrictions;
-import org.jboss.envers.query.RevisionProperty;
import org.hibernate.ejb.Ejb3Configuration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import javax.persistence.EntityManager;
import java.util.List;
-import java.util.Arrays;
/**
* @author Adam Warski (adam at warski dot org)
16 years, 2 months
JBoss Envers SVN: r142 - in trunk/src/test/org/jboss/envers/test: entities/reventity and 2 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-03 03:50:01 -0400 (Wed, 03 Sep 2008)
New Revision: 142
Added:
trunk/src/test/org/jboss/envers/test/entities/reventity/
trunk/src/test/org/jboss/envers/test/entities/reventity/CustomRevEntity.java
trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java
Modified:
trunk/src/test/org/jboss/envers/test/integration/reventity/Custom.java
Log:
ENVERS-47: custom revision entity + rev-of-entities query test
Copied: trunk/src/test/org/jboss/envers/test/entities/reventity/CustomRevEntity.java (from rev 138, trunk/src/test/org/jboss/envers/test/integration/reventity/CustomRevEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/reventity/CustomRevEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/reventity/CustomRevEntity.java 2008-09-03 07:50:01 UTC (rev 142)
@@ -0,0 +1,59 @@
+package org.jboss.envers.test.entities.reventity;
+
+import org.jboss.envers.RevisionNumber;
+import org.jboss.envers.RevisionTimestamp;
+import org.jboss.envers.RevisionEntity;
+
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Entity;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@RevisionEntity
+public class CustomRevEntity {
+ @Id
+ @GeneratedValue
+ @RevisionNumber
+ private int customId;
+
+ @RevisionTimestamp
+ private long customTimestamp;
+
+ public int getCustomId() {
+ return customId;
+ }
+
+ public void setCustomId(int customId) {
+ this.customId = customId;
+ }
+
+ public long getCustomTimestamp() {
+ return customTimestamp;
+ }
+
+ public void setCustomTimestamp(long customTimestamp) {
+ this.customTimestamp = customTimestamp;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof CustomRevEntity)) return false;
+
+ CustomRevEntity that = (CustomRevEntity) o;
+
+ if (customId != that.customId) return false;
+ if (customTimestamp != that.customTimestamp) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = customId;
+ result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32));
+ return result;
+ }
+}
Copied: trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java (from rev 138, trunk/src/test/org/jboss/envers/test/integration/query/RevisionConstraintQuery.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java 2008-09-03 07:50:01 UTC (rev 142)
@@ -0,0 +1,83 @@
+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.entities.reventity.CustomRevEntity;
+import org.jboss.envers.query.VersionsRestrictions;
+import org.jboss.envers.query.RevisionProperty;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.List;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@SuppressWarnings({"unchecked"})
+public class CustomRevEntityQuery extends AbstractEntityTest {
+ private Integer id1;
+ private Integer id2;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(CustomRevEntity.class);
+ 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", 15);
+
+ em.persist(site1);
+ em.persist(site2);
+
+ id1 = site1.getId();
+ id2 = site2.getId();
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ site1 = em.find(StrIntTestEntity.class, id1);
+
+ site1.setStr1("c");
+
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsOfId1Query() {
+ List<Object[]> result = getVersionsReader().createQuery()
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
+ .add(VersionsRestrictions.idEq(id1))
+ .getResultList();
+
+ assert result.get(0)[0].equals(new StrIntTestEntity("a", 10, id1));
+ assert result.get(0)[1] instanceof CustomRevEntity;
+ assert ((CustomRevEntity) result.get(0)[1]).getCustomId() == 1;
+
+ assert result.get(1)[0].equals(new StrIntTestEntity("c", 10, id1));
+ assert result.get(1)[1] instanceof CustomRevEntity;
+ assert ((CustomRevEntity) result.get(1)[1]).getCustomId() == 2;
+ }
+
+ @Test
+ public void testRevisionsOfId2Query() {
+ List<Object[]> result = getVersionsReader().createQuery()
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
+ .add(VersionsRestrictions.idEq(id2))
+ .getResultList();
+
+ assert result.get(0)[0].equals(new StrIntTestEntity("b", 15, id2));
+ assert result.get(0)[1] instanceof CustomRevEntity;
+ assert ((CustomRevEntity) result.get(0)[1]).getCustomId() == 1;
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/integration/query/CustomRevEntityQuery.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/src/test/org/jboss/envers/test/integration/reventity/Custom.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/reventity/Custom.java 2008-09-03 07:29:48 UTC (rev 141)
+++ trunk/src/test/org/jboss/envers/test/integration/reventity/Custom.java 2008-09-03 07:50:01 UTC (rev 142)
@@ -2,6 +2,7 @@
import org.jboss.envers.test.integration.AbstractEntityTest;
import org.jboss.envers.test.entities.StrTestEntity;
+import org.jboss.envers.test.entities.reventity.CustomRevEntity;
import org.jboss.envers.exception.RevisionDoesNotExistException;
import org.jboss.envers.VersionsReader;
import org.hibernate.ejb.Ejb3Configuration;
16 years, 2 months