JBoss Envers SVN: r172 - tags.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-26 11:33:14 -0400 (Fri, 26 Sep 2008)
New Revision: 172
Added:
tags/1.1.0-beta2/
Log:
Taggin the 1.0.0.beta2 release
Copied: tags/1.1.0-beta2 (from rev 171, trunk)
16 years, 3 months
JBoss Envers SVN: r171 - trunk/src/main/org/jboss/envers/synchronization.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-25 03:16:20 -0400 (Thu, 25 Sep 2008)
New Revision: 171
Modified:
trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java
Log:
Fix (by adepue) for a bug reported in the forums: http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4178431
Modified: trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java
===================================================================
--- trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java 2008-09-24 16:03:11 UTC (rev 170)
+++ trunk/src/main/org/jboss/envers/synchronization/VersionsSync.java 2008-09-25 07:16:20 UTC (rev 171)
@@ -126,7 +126,8 @@
return;
}
- if (FlushMode.isManualFlushMode(session.getFlushMode())) {
+ // see: http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4178431
+ if (FlushMode.isManualFlushMode(session.getFlushMode()) || session.isClosed()) {
Session temporarySession = null;
try {
temporarySession = session.getFactory().openTemporarySession();
16 years, 3 months
JBoss Envers SVN: r170 - in trunk: src/main/org/jboss/envers/configuration and 11 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-24 12:03:11 -0400 (Wed, 24 Sep 2008)
New Revision: 170
Modified:
trunk/envers.iml
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/QueryGeneratorBuilder.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/EntityConfiguration.java
trunk/src/main/org/jboss/envers/entities/mapper/id/EmbeddedIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/id/MultipleIdMapper.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/CommonCollectionMapperData.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/ListCollectionMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/MapCollectionMapper.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/MiddleComponentMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleDummyComponentMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyPropertyComponentMapper.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/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/ListCollectionInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/RelationQueryGenerator.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
trunk/src/main/org/jboss/envers/exception/NotVersionedException.java
trunk/src/main/org/jboss/envers/exception/RevisionDoesNotExistException.java
trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedTestUserType.java
trunk/src/test/org/jboss/envers/test/integration/collection/StringMap.java
Log:
Code cleanup and missing license headers
Modified: trunk/envers.iml
===================================================================
--- trunk/envers.iml 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/envers.iml 2008-09-24 16:03:11 UTC (rev 170)
@@ -10,6 +10,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/main-3.2" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build" />
+ <excludeFolder url="file://$MODULE_DIR$/clover" />
</content>
<orderEntry type="jdk" jdkName="1.5" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
Modified: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -87,10 +87,10 @@
}
// Second pass
- for (PersistentClass pc : pcDatas.keySet()) {
- EntityXmlMappingData xmlMappingData = xmlMappings.get(pc);
+ for (Map.Entry<PersistentClass, PersistentClassVersioningData> pcDatasEntry : pcDatas.entrySet()) {
+ EntityXmlMappingData xmlMappingData = xmlMappings.get(pcDatasEntry.getKey());
- versionsMetaGen.generateSecondPass(pc, pcDatas.get(pc), xmlMappingData);
+ versionsMetaGen.generateSecondPass(pcDatasEntry.getKey(), pcDatasEntry.getValue(), xmlMappingData);
try {
cfg.addDocument(writer.write(xmlMappingData.getMainXmlMapping()));
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.Element;
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.hibernate.mapping.*;
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.Element;
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.jboss.envers.entities.mapper.relation.MiddleIdData;
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.Element;
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -321,7 +321,7 @@
addJoins(pc, propertyMapper, versioningData, pc.getEntityName(), xmlMappingData, true);
// Storing the generated configuration
- EntityConfiguration entityCfg = new EntityConfiguration(entityName, versionsEntityName, idMapper,
+ EntityConfiguration entityCfg = new EntityConfiguration(versionsEntityName, idMapper,
propertyMapper, parentEntityName);
entitiesConfigurations.put(pc.getEntityName(), entityCfg);
}
Modified: trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -31,7 +31,6 @@
* @author Adam Warski (adam at warski dot org)
*/
public class EntityConfiguration {
- private String entityName;
private String versionsEntityName;
private IdMappingData idMappingData;
private ExtendedPropertyMapper propertyMapper;
@@ -39,9 +38,8 @@
private Map<String, RelationDescription> relations;
private String parentEntityName;
- public EntityConfiguration(String entityName, String versionsEntityName, IdMappingData idMappingData,
+ public EntityConfiguration(String versionsEntityName, IdMappingData idMappingData,
ExtendedPropertyMapper propertyMapper, String parentEntityName) {
- this.entityName = entityName;
this.versionsEntityName = versionsEntityName;
this.idMappingData = idMappingData;
this.propertyMapper = propertyMapper;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/EmbeddedIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/EmbeddedIdMapper.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/EmbeddedIdMapper.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -101,8 +101,8 @@
List<QueryParameterData> ret = new ArrayList<QueryParameterData>();
- for (String propertyName : data.keySet()) {
- ret.add(new QueryParameterData(propertyName, data.get(propertyName)));
+ for (Map.Entry<String, Object> propertyData : data.entrySet()) {
+ ret.add(new QueryParameterData(propertyData.getKey(), propertyData.getValue()));
}
return ret;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/MultipleIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/MultipleIdMapper.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/MultipleIdMapper.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -84,8 +84,8 @@
List<QueryParameterData> ret = new ArrayList<QueryParameterData>();
- for (String propertyName : data.keySet()) {
- ret.add(new QueryParameterData(propertyName, data.get(propertyName)));
+ for (Map.Entry<String, Object> propertyData : data.entrySet()) {
+ ret.add(new QueryParameterData(propertyData.getKey(), propertyData.getValue()));
}
return ret;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractCollectionMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractCollectionMapper.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/AbstractCollectionMapper.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.PersistentCollectionChangeData;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/BasicCollectionMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/BasicCollectionMapper.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/BasicCollectionMapper.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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/CommonCollectionMapperData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/CommonCollectionMapperData.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/CommonCollectionMapperData.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.configuration.VersionsEntitiesConfiguration;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/ListCollectionMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/ListCollectionMapper.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/ListCollectionMapper.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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/MapCollectionMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/MapCollectionMapper.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/MapCollectionMapper.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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/MiddleComponentData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleComponentData.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleComponentData.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.relation.component.MiddleComponentMapper;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleIdData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleIdData.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleIdData.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.IdMapper;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleComponentMapper.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleComponentMapper.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.component;
import org.jboss.envers.entities.EntityInstantiator;
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-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleDummyComponentMapper.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.component;
import org.jboss.envers.entities.EntityInstantiator;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.component;
import org.jboss.envers.entities.EntityInstantiator;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyPropertyComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyPropertyComponentMapper.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyPropertyComponentMapper.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.component;
import org.jboss.envers.entities.EntityInstantiator;
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-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleRelatedComponentMapper.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.component;
import org.jboss.envers.entities.EntityInstantiator;
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-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.component;
import org.jboss.envers.entities.EntityInstantiator;
Modified: 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 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.initializor;
import org.jboss.envers.entities.mapper.relation.query.RelationQueryGenerator;
Modified: 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 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.initializor;
import org.jboss.envers.entities.mapper.relation.query.RelationQueryGenerator;
Modified: 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 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.initializor;
import org.jboss.envers.entities.mapper.relation.query.RelationQueryGenerator;
Modified: 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 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.initializor;
import org.jboss.envers.entities.mapper.relation.query.RelationQueryGenerator;
Modified: 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 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.initializor;
import org.jboss.envers.entities.mapper.relation.query.RelationQueryGenerator;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.query;
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.query;
import org.jboss.envers.entities.mapper.id.QueryParameterData;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.query;
import org.jboss.envers.tools.query.QueryBuilder;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/RelationQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/RelationQueryGenerator.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/RelationQueryGenerator.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.query;
import org.hibernate.Query;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.query;
import org.jboss.envers.entities.mapper.id.QueryParameterData;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -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.query;
import org.jboss.envers.entities.mapper.id.QueryParameterData;
Modified: trunk/src/main/org/jboss/envers/exception/NotVersionedException.java
===================================================================
--- trunk/src/main/org/jboss/envers/exception/NotVersionedException.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/exception/NotVersionedException.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -22,19 +22,17 @@
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 {
- public NotVersionedException(String message) {
+ private final String entityName;
+
+ public NotVersionedException(String entityName, String message) {
super(message);
+ this.entityName = entityName;
}
- public NotVersionedException(String message, Throwable cause) {
- super(message, cause);
+ public String getEntityName() {
+ return entityName;
}
-
- public NotVersionedException(Throwable cause) {
- super(cause);
- }
}
Modified: trunk/src/main/org/jboss/envers/exception/RevisionDoesNotExistException.java
===================================================================
--- trunk/src/main/org/jboss/envers/exception/RevisionDoesNotExistException.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/exception/RevisionDoesNotExistException.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -24,27 +24,27 @@
import java.util.Date;
/**
- * TODO: add the revision number.
* @author Adam Warski (adam at warski dot org)
*/
public class RevisionDoesNotExistException extends VersionsException {
- public RevisionDoesNotExistException(String message) {
- super(message);
- }
+ private Number revision;
+ private Date date;
- public RevisionDoesNotExistException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public RevisionDoesNotExistException(Throwable cause) {
- super(cause);
- }
-
public RevisionDoesNotExistException(Number revision) {
super("Revision " + revision + " does not exist.");
+ this.revision = revision;
}
public RevisionDoesNotExistException(Date date) {
super("There is no revision before or at " + date + ".");
+ this.date = date;
}
+
+ public Number getRevision() {
+ return revision;
+ }
+
+ public Date getDate() {
+ return date;
+ }
}
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -80,7 +80,7 @@
String entityName = cls.getName();
if (!verCfg.getEntCfg().isVersioned(entityName)) {
- throw new NotVersionedException(entityName + " is not versioned!");
+ throw new NotVersionedException(entityName, entityName + " is not versioned!");
}
try {
@@ -104,7 +104,7 @@
String entityName = cls.getName();
if (!verCfg.getEntCfg().isVersioned(entityName)) {
- throw new NotVersionedException(entityName + " is not versioned!");
+ throw new NotVersionedException(entityName, entityName + " is not versioned!");
}
return createQuery().forRevisionsOfEntity(cls, false, true)
Modified: trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedTestUserType.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedTestUserType.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedTestUserType.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -4,13 +4,13 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Types;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.Hibernate;
import org.hibernate.usertype.ParameterizedType;
import org.hibernate.usertype.UserType;
-import org.hsqldb.Types;
/**
* @author Adam Warski (adam at warski dot org)
Modified: trunk/src/test/org/jboss/envers/test/integration/collection/StringMap.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/collection/StringMap.java 2008-09-24 13:45:08 UTC (rev 169)
+++ trunk/src/test/org/jboss/envers/test/integration/collection/StringMap.java 2008-09-24 16:03:11 UTC (rev 170)
@@ -93,9 +93,6 @@
assert rev1.getStrings().equals(Collections.EMPTY_MAP);
assert rev2.getStrings().equals(TestTools.makeMap("1", "a", "2", "b"));
- System.out.println(rev2.getStrings());
- System.out.println(rev3.getStrings());
- System.out.println(rev4.getStrings());
assert rev3.getStrings().equals(TestTools.makeMap("2", "b"));
assert rev4.getStrings().equals(TestTools.makeMap("2", "b"));
}
16 years, 3 months
JBoss Envers SVN: r169 - trunk/resources/test.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-24 09:45:08 -0400 (Wed, 24 Sep 2008)
New Revision: 169
Modified:
trunk/resources/test/testng.xml
Log:
ENVERS-25: adding the new test to testng.xml
Modified: trunk/resources/test/testng.xml
===================================================================
--- trunk/resources/test/testng.xml 2008-09-24 12:06:48 UTC (rev 168)
+++ trunk/resources/test/testng.xml 2008-09-24 13:45:08 UTC (rev 169)
@@ -15,6 +15,7 @@
<package name="org.jboss.envers.test.integration.inheritance.single.childrelation" />
<package name="org.jboss.envers.test.integration.inheritance.single.relation" />
<package name="org.jboss.envers.test.integration.manytomany" />
+ <package name="org.jboss.envers.test.integration.manytomany.ternary" />
<package name="org.jboss.envers.test.integration.manytomany.unidirectional" />
<package name="org.jboss.envers.test.integration.naming" />
<package name="org.jboss.envers.test.integration.naming.ids" />
16 years, 3 months
JBoss Envers SVN: r168 - in trunk/src: main/org/jboss/envers/entities/mapper/relation/query and 2 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-24 08:06:48 -0400 (Wed, 24 Sep 2008)
New Revision: 168
Added:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java
trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/
trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMap.java
trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMapEntity.java
Removed:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.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
Log:
ENVERS-25: @MapKeyManyToMany support in ternary associations
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-09-24 11:17:25 UTC (rev 167)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-09-24 12:06:48 UTC (rev 168)
@@ -4,8 +4,8 @@
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
import org.jboss.envers.entities.mapper.relation.query.RelationQueryGenerator;
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.entities.mapper.relation.query.TwoEntityQueryGenerator;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import java.util.List;
@@ -42,10 +42,9 @@
} else if (idDatas.size() == 1) {
return new TwoEntityQueryGenerator(verEntCfg, versionsMiddleEntityName, referencingIdData,
idDatas.get(0), componentDatas);
- } else if (idDatas.size() == 1) {
- // TODO: add componentDatas
+ } else if (idDatas.size() == 2) {
return new ThreeEntityQueryGenerator(verEntCfg, versionsMiddleEntityName, referencingIdData,
- idDatas.get(0), idDatas.get(1));
+ idDatas.get(0), idDatas.get(1), componentDatas);
} else {
throw new IllegalStateException("Illegal number of related entities.");
}
Deleted: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java 2008-09-24 11:17:25 UTC (rev 167)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java 2008-09-24 12:06:48 UTC (rev 168)
@@ -1,14 +0,0 @@
-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/QueryGeneratorTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2008-09-24 12:06:48 UTC (rev 168)
@@ -0,0 +1,51 @@
+package org.jboss.envers.entities.mapper.relation.query;
+
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
+import org.jboss.envers.entities.mapper.relation.MiddleIdData;
+import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class QueryGeneratorTools {
+ public static void addEntityAtRevision(QueryBuilder qb, Parameters rootParameters, MiddleIdData idData,
+ String revisionPropertyPath, String originalIdPropertyName,
+ String alias1, String alias2) {
+ // SELECT max(e.revision) FROM versionsReferencedEntity e2
+ QueryBuilder maxERevQb = qb.newSubQueryBuilder(idData.getVersionsEntityName(), alias2);
+ maxERevQb.addProjection("max", revisionPropertyPath, false);
+ // WHERE
+ Parameters maxERevQbParameters = maxERevQb.getRootParameters();
+ // e2.revision <= :revision
+ maxERevQbParameters.addWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
+ // e2.id_ref_ed = e.id_ref_ed
+ idData.getOriginalMapper().addIdsEqualToQuery(maxERevQbParameters,
+ alias1 + "." + originalIdPropertyName, alias2 +"." + originalIdPropertyName);
+
+ // e.revision = (SELECT max(...) ...)
+ rootParameters.addWhere("e." + revisionPropertyPath, false, "=", maxERevQb);
+ }
+
+ public static void addAssociationAtRevision(QueryBuilder qb, Parameters rootParameters,
+ MiddleIdData referencingIdData, String versionsMiddleEntityName,
+ String eeOriginalIdPropertyPath, String revisionPropertyPath,
+ String originalIdPropertyName, MiddleComponentData... componentDatas) {
+ // SELECT max(ee2.revision) FROM middleEntity ee2
+ QueryBuilder maxEeRevQb = qb.newSubQueryBuilder(versionsMiddleEntityName, "ee2");
+ maxEeRevQb.addProjection("max", revisionPropertyPath, false);
+ // WHERE
+ Parameters maxEeRevQbParameters = maxEeRevQb.getRootParameters();
+ // ee2.revision <= :revision
+ maxEeRevQbParameters.addWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
+ // ee2.originalId.* = ee.originalId.*
+ String ee2OriginalIdPropertyPath = "ee2." + originalIdPropertyName;
+ referencingIdData.getPrefixedMapper().addIdsEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
+ for (MiddleComponentData componentData : componentDatas) {
+ componentData.getComponentMapper().addMiddleEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
+ }
+
+ // ee.revision = (SELECT max(...) ...)
+ rootParameters.addWhere(revisionPropertyPath, "=", maxEeRevQb);
+ }
+}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-09-24 11:17:25 UTC (rev 167)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-09-24 12:06:48 UTC (rev 168)
@@ -1,11 +1,19 @@
package org.jboss.envers.entities.mapper.relation.query;
-import org.hibernate.Query;
-import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.entities.mapper.id.QueryParameterData;
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
+import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.RevisionType;
+import org.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
+import org.hibernate.Query;
+import java.util.Collections;
+
/**
+ * Selects data from a relation middle-table and a two related versions entity.
* @author Adam Warski (adam at warski dot org)
*/
public final class ThreeEntityQueryGenerator implements RelationQueryGenerator {
@@ -15,15 +23,88 @@
public ThreeEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg,
String versionsMiddleEntityName,
MiddleIdData referencingIdData,
- MiddleIdData referencedIdData1,
- MiddleIdData referencedIdData2) {
+ MiddleIdData referencedIdData,
+ MiddleIdData indexIdData,
+ MiddleComponentData... componentDatas) {
this.referencingIdData = referencingIdData;
- // TODO
- queryString = "";
+ /*
+ * The query that we need to create:
+ * SELECT new list(ee, e, f) FROM versionsReferencedEntity e, versionsIndexEntity f, middleEntity ee
+ * WHERE
+ * (entities referenced by the middle table; id_ref_ed = id of the referenced entity)
+ * ee.id_ref_ed = e.id_ref_ed AND
+ * (entities referenced by the middle table; id_ref_ind = id of the index entity)
+ * ee.id_ref_ind = f.id_ref_ind AND
+ * (only entities referenced by the association; id_ref_ing = id of the referencing entity)
+ * ee.id_ref_ing = :id_ref_ing AND
+ * (selecting e entities at revision :revision)
+ * e.revision = (SELECT max(e2.revision) FROM versionsReferencedEntity e2
+ * WHERE e2.revision <= :revision AND e2.id_ref_ed = e.id_ref_ed) AND
+ * (selecting f entities at revision :revision)
+ * f.revision = (SELECT max(f2.revision) FROM versionsIndexEntity f2
+ * WHERE f2.revision <= :revision AND f2.id_ref_ed = f.id_ref_ed) AND
+ * (the association at revision :revision)
+ * ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2
+ * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*) AND
+ * (only non-deleted entities and associations)
+ * ee.revision_type != DEL AND
+ * e.revision_type != DEL AND
+ * f.revision_type != DEL
+ */
+ String revisionPropertyPath = verEntCfg.getRevisionPropPath();
+ String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
+
+ String eeOriginalIdPropertyPath = "ee." + originalIdPropertyName;
+
+ // SELECT new list(ee) FROM middleEntity ee
+ QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee");
+ qb.addFrom(referencedIdData.getVersionsEntityName(), "e");
+ qb.addFrom(indexIdData.getVersionsEntityName(), "f");
+ qb.addProjection("new list", "ee, e, f", false, false);
+ // WHERE
+ Parameters rootParameters = qb.getRootParameters();
+ // ee.id_ref_ed = e.id_ref_ed
+ referencedIdData.getPrefixedMapper().addIdsEqualToQuery(rootParameters, eeOriginalIdPropertyPath,
+ referencedIdData.getOriginalMapper(), "e." + originalIdPropertyName);
+ // ee.id_ref_ind = f.id_ref_ind
+ indexIdData.getPrefixedMapper().addIdsEqualToQuery(rootParameters, eeOriginalIdPropertyPath,
+ indexIdData.getOriginalMapper(), "f." + originalIdPropertyName);
+ // ee.originalId.id_ref_ing = :id_ref_ing
+ referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true);
+
+ // e.revision = (SELECT max(...) ...)
+ QueryGeneratorTools.addEntityAtRevision(qb, rootParameters, referencedIdData, revisionPropertyPath,
+ originalIdPropertyName, "e", "e2");
+
+ // f.revision = (SELECT max(...) ...)
+ QueryGeneratorTools.addEntityAtRevision(qb, rootParameters, indexIdData, revisionPropertyPath,
+ originalIdPropertyName, "f", "f2");
+
+ // ee.revision = (SELECT max(...) ...)
+ QueryGeneratorTools.addAssociationAtRevision(qb, rootParameters, referencingIdData, versionsMiddleEntityName,
+ eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName, componentDatas);
+
+ // ee.revision_type != DEL
+ rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(), "!=", "delrevisiontype");
+ // e.revision_type != DEL
+ rootParameters.addWhereWithNamedParam("e." + verEntCfg.getRevisionTypePropName(), false, "!=", "delrevisiontype");
+ // f.revision_type != DEL
+ rootParameters.addWhereWithNamedParam("f." + verEntCfg.getRevisionTypePropName(), false, "!=", "delrevisiontype");
+
+ StringBuilder sb = new StringBuilder();
+ qb.build(sb, Collections.<String, Object>emptyMap());
+ queryString = sb.toString();
}
public Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey, Number revision) {
- throw new RuntimeException();
+ 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/entities/mapper/relation/query/TwoEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-09-24 11:17:25 UTC (rev 167)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-09-24 12:06:48 UTC (rev 168)
@@ -62,35 +62,13 @@
// ee.originalId.id_ref_ing = :id_ref_ing
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true);
- // SELECT max(e.revision) FROM versionsReferencedEntity e2
- QueryBuilder maxERevQb = qb.newSubQueryBuilder(referencedIdData.getVersionsEntityName(), "e2");
- maxERevQb.addProjection("max", revisionPropertyPath, false);
- // WHERE
- Parameters maxERevQbParameters = maxERevQb.getRootParameters();
- // e2.revision <= :revision
- maxERevQbParameters.addWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
- // e2.id_ref_ed = e.id_ref_ed
- referencedIdData.getOriginalMapper().addIdsEqualToQuery(maxERevQbParameters, "e." + originalIdPropertyName, "e2." + originalIdPropertyName);
-
// e.revision = (SELECT max(...) ...)
- rootParameters.addWhere("e." + revisionPropertyPath, false, "=", maxERevQb);
+ QueryGeneratorTools.addEntityAtRevision(qb, rootParameters, referencedIdData, revisionPropertyPath,
+ originalIdPropertyName, "e", "e2");
- // SELECT max(ee2.revision) FROM middleEntity ee2
- QueryBuilder maxEeRevQb = qb.newSubQueryBuilder(versionsMiddleEntityName, "ee2");
- maxEeRevQb.addProjection("max", revisionPropertyPath, false);
- // WHERE
- Parameters maxEeRevQbParameters = maxEeRevQb.getRootParameters();
- // ee2.revision <= :revision
- maxEeRevQbParameters.addWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
- // ee2.originalId.* = ee.originalId.*
- String ee2OriginalIdPropertyPath = "ee2." + originalIdPropertyName;
- referencingIdData.getPrefixedMapper().addIdsEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
- for (MiddleComponentData componentData : componentDatas) {
- componentData.getComponentMapper().addMiddleEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
- }
-
// ee.revision = (SELECT max(...) ...)
- rootParameters.addWhere(revisionPropertyPath, "=", maxEeRevQb);
+ QueryGeneratorTools.addAssociationAtRevision(qb, rootParameters, referencingIdData, versionsMiddleEntityName,
+ eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName, componentDatas);
// ee.revision_type != DEL
rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(), "!=", "delrevisiontype");
Copied: trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMap.java (from rev 156, trunk/src/test/org/jboss/envers/test/integration/manytomany/BasicMap.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMap.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMap.java 2008-09-24 12:06:48 UTC (rev 168)
@@ -0,0 +1,176 @@
+package org.jboss.envers.test.integration.manytomany.ternary;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.StrTestEntity;
+import org.jboss.envers.test.entities.IntTestEntity;
+import org.jboss.envers.test.tools.TestTools;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.hibernate.ejb.Ejb3Configuration;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class TernaryMap extends AbstractEntityTest {
+ private Integer str1_id;
+ private Integer str2_id;
+
+ private Integer int1_id;
+ private Integer int2_id;
+
+ private Integer map1_id;
+ private Integer map2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(TernaryMapEntity.class);
+ cfg.addAnnotatedClass(StrTestEntity.class);
+ cfg.addAnnotatedClass(IntTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ StrTestEntity str1 = new StrTestEntity("a");
+ StrTestEntity str2 = new StrTestEntity("b");
+
+ IntTestEntity int1 = new IntTestEntity(1);
+ IntTestEntity int2 = new IntTestEntity(2);
+
+ TernaryMapEntity map1 = new TernaryMapEntity();
+ TernaryMapEntity map2 = new TernaryMapEntity();
+
+ // Revision 1 (map1: initialy one mapping int1 -> str1, map2: empty)
+ em.getTransaction().begin();
+
+ em.persist(str1);
+ em.persist(str2);
+ em.persist(int1);
+ em.persist(int2);
+
+ map1.getMap().put(int1, str1);
+
+ em.persist(map1);
+ em.persist(map2);
+
+ em.getTransaction().commit();
+
+ // Revision 2 (map1: replacing the mapping, map2: adding two mappings)
+
+ em.getTransaction().begin();
+
+ map1 = em.find(TernaryMapEntity.class, map1.getId());
+ map2 = em.find(TernaryMapEntity.class, map2.getId());
+
+ str1 = em.find(StrTestEntity.class, str1.getId());
+ str2 = em.find(StrTestEntity.class, str2.getId());
+
+ int1 = em.find(IntTestEntity.class, int1.getId());
+ int2 = em.find(IntTestEntity.class, int2.getId());
+
+ map1.getMap().put(int1, str2);
+
+ map2.getMap().put(int1, str1);
+ map2.getMap().put(int2, str1);
+
+ em.getTransaction().commit();
+
+ // Revision 3 (map1: removing a non-existing mapping, adding an existing mapping - no changes, map2: removing a mapping)
+ em.getTransaction().begin();
+
+ map1 = em.find(TernaryMapEntity.class, map1.getId());
+ map2 = em.find(TernaryMapEntity.class, map2.getId());
+
+ str2 = em.find(StrTestEntity.class, str2.getId());
+
+ int1 = em.find(IntTestEntity.class, int1.getId());
+ int2 = em.find(IntTestEntity.class, int2.getId());
+
+ map1.getMap().remove(int2);
+ map1.getMap().put(int1, str2);
+
+ map2.getMap().remove(int1);
+
+ em.getTransaction().commit();
+
+ // Revision 4 (map1: adding a mapping, map2: adding a mapping)
+ em.getTransaction().begin();
+
+ map1 = em.find(TernaryMapEntity.class, map1.getId());
+ map2 = em.find(TernaryMapEntity.class, map2.getId());
+
+ str2 = em.find(StrTestEntity.class, str2.getId());
+
+ int1 = em.find(IntTestEntity.class, int1.getId());
+ int2 = em.find(IntTestEntity.class, int2.getId());
+
+ map1.getMap().put(int2, str2);
+
+ map2.getMap().put(int1, str2);
+
+ em.getTransaction().commit();
+ //
+
+ map1_id = map1.getId();
+ map2_id = map2.getId();
+
+ str1_id = str1.getId();
+ str2_id = str2.getId();
+
+ int1_id = int1.getId();
+ int2_id = int2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 4).equals(getVersionsReader().getRevisions(TernaryMapEntity.class, map1_id));
+ assert Arrays.asList(1, 2, 3, 4).equals(getVersionsReader().getRevisions(TernaryMapEntity.class, map2_id));
+
+ assert Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str1_id));
+ assert Arrays.asList(1).equals(getVersionsReader().getRevisions(StrTestEntity.class, str2_id));
+
+ assert Arrays.asList(1).equals(getVersionsReader().getRevisions(IntTestEntity.class, int1_id));
+ assert Arrays.asList(1).equals(getVersionsReader().getRevisions(IntTestEntity.class, int2_id));
+ }
+
+ @Test
+ public void testHistoryOfMap1() {
+ StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
+ StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
+
+ IntTestEntity int1 = getEntityManager().find(IntTestEntity.class, int1_id);
+ IntTestEntity int2 = getEntityManager().find(IntTestEntity.class, int2_id);
+
+ TernaryMapEntity rev1 = getVersionsReader().find(TernaryMapEntity.class, map1_id, 1);
+ TernaryMapEntity rev2 = getVersionsReader().find(TernaryMapEntity.class, map1_id, 2);
+ TernaryMapEntity rev3 = getVersionsReader().find(TernaryMapEntity.class, map1_id, 3);
+ TernaryMapEntity rev4 = getVersionsReader().find(TernaryMapEntity.class, map1_id, 4);
+
+ assert rev1.getMap().equals(TestTools.makeMap(int1, str1));
+ assert rev2.getMap().equals(TestTools.makeMap(int1, str2));
+ assert rev3.getMap().equals(TestTools.makeMap(int1, str2));
+ assert rev4.getMap().equals(TestTools.makeMap(int1, str2, int2, str2));
+ }
+
+ @Test
+ public void testHistoryOfMap2() {
+ StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
+ StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
+
+ IntTestEntity int1 = getEntityManager().find(IntTestEntity.class, int1_id);
+ IntTestEntity int2 = getEntityManager().find(IntTestEntity.class, int2_id);
+
+ TernaryMapEntity rev1 = getVersionsReader().find(TernaryMapEntity.class, map2_id, 1);
+ TernaryMapEntity rev2 = getVersionsReader().find(TernaryMapEntity.class, map2_id, 2);
+ TernaryMapEntity rev3 = getVersionsReader().find(TernaryMapEntity.class, map2_id, 3);
+ TernaryMapEntity rev4 = getVersionsReader().find(TernaryMapEntity.class, map2_id, 4);
+
+ assert rev1.getMap().equals(TestTools.makeMap());
+ assert rev2.getMap().equals(TestTools.makeMap(int1, str1, int2, str1));
+ assert rev3.getMap().equals(TestTools.makeMap(int2, str1));
+ assert rev4.getMap().equals(TestTools.makeMap(int1, str2, int2, str1));
+ }
+}
\ No newline at end of file
Copied: trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMapEntity.java (from rev 148, trunk/src/test/org/jboss/envers/test/entities/StrIntTestEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMapEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMapEntity.java 2008-09-24 12:06:48 UTC (rev 168)
@@ -0,0 +1,67 @@
+package org.jboss.envers.test.integration.manytomany.ternary;
+
+import org.jboss.envers.Versioned;
+import org.jboss.envers.test.entities.IntTestEntity;
+import org.jboss.envers.test.entities.StrTestEntity;
+import org.hibernate.annotations.MapKeyManyToMany;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.ManyToMany;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class TernaryMapEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Versioned
+ @ManyToMany
+ @MapKeyManyToMany
+ private Map<IntTestEntity, StrTestEntity> map;
+
+ public TernaryMapEntity() {
+ map = new HashMap<IntTestEntity, StrTestEntity>();
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Map<IntTestEntity, StrTestEntity> getMap() {
+ return map;
+ }
+
+ public void setMap(Map<IntTestEntity, StrTestEntity> map) {
+ this.map = map;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof TernaryMapEntity)) return false;
+
+ TernaryMapEntity that = (TernaryMapEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return (id != null ? id.hashCode() : 0);
+ }
+
+ public String toString() {
+ return "TME(id = " + id + ", map = " + map + ")";
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/integration/manytomany/ternary/TernaryMapEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
16 years, 3 months
JBoss Envers SVN: r167 - in trunk/src: main/org/jboss/envers/entities/mapper/relation and 5 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-24 07:17:25 -0400 (Wed, 24 Sep 2008)
New Revision: 167
Added:
trunk/src/main/org/jboss/envers/entities/mapper/relation/ListCollectionMapper.java
trunk/src/test/org/jboss/envers/test/entities/collection/StringListEntity.java
trunk/src/test/org/jboss/envers/test/integration/collection/StringList.java
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java
trunk/src/main/org/jboss/envers/tools/Tools.java
trunk/src/test/org/jboss/envers/test/tools/TestTools.java
Log:
ENVERS-42: support for (indexed) lists
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-24 10:42:17 UTC (rev 166)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-24 11:17:25 UTC (rev 167)
@@ -377,6 +377,10 @@
} else if (type instanceof BagType) {
currentMapper.addComposite(propertyName, new BasicCollectionMapper<List>(commonCollectionMapperData,
ArrayList.class, ListProxy.class, elementComponentData));
+ } else if (type instanceof ListType) {
+ // Indexed collection, so <code>indexComponentData</code> is not null.
+ currentMapper.addComposite(propertyName, new ListCollectionMapper(commonCollectionMapperData,
+ elementComponentData, indexComponentData));
} else {
mainGenerator.throwUnsupportedTypeException(type, referencingEntityName, propertyName);
}
Copied: trunk/src/main/org/jboss/envers/entities/mapper/relation/ListCollectionMapper.java (from rev 156, trunk/src/main/org/jboss/envers/entities/mapper/relation/MapCollectionMapper.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/ListCollectionMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/ListCollectionMapper.java 2008-09-24 11:17:25 UTC (rev 167)
@@ -0,0 +1,67 @@
+package org.jboss.envers.entities.mapper.relation;
+
+import org.jboss.envers.entities.mapper.PropertyMapper;
+import org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor;
+import org.jboss.envers.entities.mapper.relation.lazy.initializor.ListCollectionInitializor;
+import org.jboss.envers.entities.mapper.relation.lazy.proxy.ListProxy;
+import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.reader.VersionsReaderImplementor;
+import org.jboss.envers.tools.Tools;
+import org.jboss.envers.tools.Pair;
+import org.hibernate.collection.PersistentCollection;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.io.Serializable;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class ListCollectionMapper extends AbstractCollectionMapper<List> implements PropertyMapper {
+ private final MiddleComponentData elementComponentData;
+ private final MiddleComponentData indexComponentData;
+
+ public ListCollectionMapper(CommonCollectionMapperData commonCollectionMapperData,
+ MiddleComponentData elementComponentData, MiddleComponentData indexComponentData) {
+ super(commonCollectionMapperData, List.class, ListProxy.class);
+ this.elementComponentData = elementComponentData;
+ this.indexComponentData = indexComponentData;
+ }
+
+ protected Initializor<List> getInitializor(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader,
+ Object primaryKey, Number revision) {
+ return new ListCollectionInitializor(verCfg, versionsReader, commonCollectionMapperData.getQueryGenerator(),
+ primaryKey, revision, elementComponentData, indexComponentData);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected Collection getNewCollectionContent(PersistentCollection newCollection) {
+ if (newCollection == null) {
+ return null;
+ } else {
+ return Tools.listToIndexElementPairList((List<Object>) newCollection);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected Collection getOldCollectionContent(Serializable oldCollection) {
+ if (oldCollection == null) {
+ return null;
+ } else {
+ return Tools.listToIndexElementPairList((List<Object>) oldCollection);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected void mapToMapFromObject(Map<String, Object> data, Object changed) {
+ Pair<Integer, Object> indexValuePair = (Pair<Integer, Object>) changed;
+ elementComponentData.getComponentMapper().mapToMapFromObject(data, indexValuePair.getSecond());
+ indexComponentData.getComponentMapper().mapToMapFromObject(data, indexValuePair.getFirst());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected Object getElement(Object changedObject) {
+ return ((Pair<Integer, Object>) changedObject).getFirst();
+ }
+}
\ No newline at end of file
Modified: 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 2008-09-24 10:42:17 UTC (rev 166)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java 2008-09-24 11:17:25 UTC (rev 167)
@@ -27,8 +27,13 @@
this.indexComponentData = indexComponentData;
}
+ @SuppressWarnings({"unchecked"})
protected List initializeCollection(int size) {
- return new ArrayList();
+ // Creating a list of the given capacity with all elements null initially. This ensures that we can then
+ // fill the elements safely using the <code>List.set</code> method.
+ List list = new ArrayList(size);
+ for (int i=0; i<size; i++) { list.add(null); }
+ return list;
}
@SuppressWarnings({"unchecked"})
Modified: trunk/src/main/org/jboss/envers/tools/Tools.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/Tools.java 2008-09-24 10:42:17 UTC (rev 166)
+++ trunk/src/main/org/jboss/envers/tools/Tools.java 2008-09-24 11:17:25 UTC (rev 167)
@@ -59,4 +59,19 @@
return true;
}
+
+ /**
+ * Transforms a list of arbitrary elements to a list of index-element pairs.
+ * @param list List to transform.
+ * @return A list of pairs: ((0, element_at_index_0), (1, element_at_index_1), ...)
+ */
+ public static <T> List<Pair<Integer, T>> listToIndexElementPairList(List<T> list) {
+ List<Pair<Integer, T>> ret = new ArrayList<Pair<Integer, T>>();
+ Iterator<T> listIter = list.iterator();
+ for (int i=0; i<list.size(); i++) {
+ ret.add(Pair.make(i, listIter.next()));
+ }
+
+ return ret;
+ }
}
Copied: trunk/src/test/org/jboss/envers/test/entities/collection/StringListEntity.java (from rev 153, trunk/src/test/org/jboss/envers/test/entities/collection/StringSetEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/collection/StringListEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/collection/StringListEntity.java 2008-09-24 11:17:25 UTC (rev 167)
@@ -0,0 +1,65 @@
+package org.jboss.envers.test.entities.collection;
+
+import org.jboss.envers.Versioned;
+import org.hibernate.annotations.CollectionOfElements;
+import org.hibernate.annotations.IndexColumn;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class StringListEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Versioned
+ @CollectionOfElements
+ @IndexColumn(name = "list_index")
+ private List<String> strings;
+
+ public StringListEntity() {
+ strings = new ArrayList<String>();
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public List<String> getStrings() {
+ return strings;
+ }
+
+ public void setStrings(List<String> strings) {
+ this.strings = strings;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof StringListEntity)) return false;
+
+ StringListEntity that = (StringListEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return (id != null ? id.hashCode() : 0);
+ }
+
+ public String toString() {
+ return "SLE(id = " + id + ", strings = " + strings + ")";
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/entities/collection/StringListEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/src/test/org/jboss/envers/test/integration/collection/StringList.java (from rev 154, trunk/src/test/org/jboss/envers/test/integration/collection/StringSet.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/collection/StringList.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/collection/StringList.java 2008-09-24 11:17:25 UTC (rev 167)
@@ -0,0 +1,101 @@
+package org.jboss.envers.test.integration.collection;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.tools.TestTools;
+import org.jboss.envers.test.entities.collection.StringListEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.hibernate.ejb.Ejb3Configuration;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.Collections;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class StringList extends AbstractEntityTest {
+ private Integer sle1_id;
+ private Integer sle2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(StringListEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ StringListEntity sle1 = new StringListEntity();
+ StringListEntity sle2 = new StringListEntity();
+
+ // Revision 1 (sle1: initialy empty, sle2: initialy 2 elements)
+ em.getTransaction().begin();
+
+ sle2.getStrings().add("sle2_string1");
+ sle2.getStrings().add("sle2_string2");
+
+ em.persist(sle1);
+ em.persist(sle2);
+
+ em.getTransaction().commit();
+
+ // Revision 2 (sle1: adding 2 elements, sle2: adding an existing element)
+ em.getTransaction().begin();
+
+ sle1 = em.find(StringListEntity.class, sle1.getId());
+ sle2 = em.find(StringListEntity.class, sle2.getId());
+
+ sle1.getStrings().add("sle1_string1");
+ sle1.getStrings().add("sle1_string2");
+
+ sle2.getStrings().add("sle2_string1");
+
+ em.getTransaction().commit();
+
+ // Revision 3 (sle1: replacing an element at index 0, sle2: removing an element at index 0)
+ em.getTransaction().begin();
+
+ sle1 = em.find(StringListEntity.class, sle1.getId());
+ sle2 = em.find(StringListEntity.class, sle2.getId());
+
+ sle1.getStrings().set(0, "sle1_string3");
+
+ sle2.getStrings().remove(0);
+
+ em.getTransaction().commit();
+
+ //
+
+ sle1_id = sle1.getId();
+ sle2_id = sle2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 3).equals(getVersionsReader().getRevisions(StringListEntity.class, sle1_id));
+ assert Arrays.asList(1, 2, 3).equals(getVersionsReader().getRevisions(StringListEntity.class, sle2_id));
+ }
+
+ @Test
+ public void testHistoryOfSle1() {
+ StringListEntity rev1 = getVersionsReader().find(StringListEntity.class, sle1_id, 1);
+ StringListEntity rev2 = getVersionsReader().find(StringListEntity.class, sle1_id, 2);
+ StringListEntity rev3 = getVersionsReader().find(StringListEntity.class, sle1_id, 3);
+
+ assert rev1.getStrings().equals(Collections.EMPTY_LIST);
+ assert rev2.getStrings().equals(TestTools.makeList("sle1_string1", "sle1_string2"));
+ assert rev3.getStrings().equals(TestTools.makeList("sle1_string3", "sle1_string2"));
+ }
+
+ @Test
+ public void testHistoryOfSse2() {
+ StringListEntity rev1 = getVersionsReader().find(StringListEntity.class, sle2_id, 1);
+ StringListEntity rev2 = getVersionsReader().find(StringListEntity.class, sle2_id, 2);
+ StringListEntity rev3 = getVersionsReader().find(StringListEntity.class, sle2_id, 3);
+
+ assert rev1.getStrings().equals(TestTools.makeList("sle2_string1", "sle2_string2"));
+ assert rev2.getStrings().equals(TestTools.makeList("sle2_string1", "sle2_string2", "sle2_string1"));
+ assert rev3.getStrings().equals(TestTools.makeList("sle2_string2", "sle2_string1"));
+ }
+}
\ No newline at end of file
Modified: trunk/src/test/org/jboss/envers/test/tools/TestTools.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/tools/TestTools.java 2008-09-24 10:42:17 UTC (rev 166)
+++ trunk/src/test/org/jboss/envers/test/tools/TestTools.java 2008-09-24 11:17:25 UTC (rev 167)
@@ -16,6 +16,10 @@
return ret;
}
+ public static <T> List<T> makeList(T... objects) {
+ return Arrays.asList(objects);
+ }
+
public static Map<Object, Object> makeMap(Object... objects) {
Map<Object, Object> ret = new HashMap<Object, Object>();
// The number of objects must be divisable by 2.
16 years, 3 months
JBoss Envers SVN: r166 - in trunk/src: main/org/jboss/envers/entities/mapper/relation and 7 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-24 06:42:17 -0400 (Wed, 24 Sep 2008)
New Revision: 166
Added:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/RelationQueryGenerator.java
trunk/src/test/org/jboss/envers/test/integration/onetomany/BidirectionalMapKey.java
trunk/src/test/org/jboss/envers/test/integration/onetomany/RefEdMapKeyEntity.java
trunk/src/test/org/jboss/envers/test/integration/onetomany/RefIngMapKeyEntity.java
Removed:
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyAttachedMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyComponentMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyAttachedInitializor.java
trunk/src/test/org/jboss/envers/test/integration/components/Component1.java
trunk/src/test/org/jboss/envers/test/integration/components/Component2.java
trunk/src/test/org/jboss/envers/test/integration/components/ComponentTestEntity.java
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/CommonCollectionMapperData.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleIdData.java
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/ListCollectionInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.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
trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKey.java
trunk/src/test/org/jboss/envers/test/integration/onetomany/BasicCollection.java
Log:
ENVERS-25: adding @MapKey support for one-to-many attached relations. Using the new collection generator for generating the mapping of one-to-many attached relations.
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -7,9 +7,9 @@
import org.jboss.envers.entities.mapper.CompositeMapperBuilder;
import org.jboss.envers.entities.mapper.relation.*;
import org.jboss.envers.entities.mapper.relation.lazy.proxy.*;
-import org.jboss.envers.entities.mapper.relation.query.MiddleTableQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.query.RelationQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.query.OneVersionsEntityQueryGenerator;
import org.jboss.envers.entities.mapper.relation.component.*;
-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;
@@ -92,33 +92,59 @@
void addCollection() {
Type type = propertyValue.getType();
- if ((type instanceof BagType || type instanceof SetType) &&
+ if ((type instanceof BagType || type instanceof SetType || type instanceof MapType) &&
(propertyValue.getElement() instanceof OneToMany) && (propertyValue.isInverse())) {
// A one-to-many relation mapped using @ManyToOne and @OneToMany(mappedBy="...")
addOneToManyAttached();
} else {
- // All other kinds of relations require a middle (join) table).
+ // All other kinds of relations require a middle (join) table.
addWithMiddleTable();
}
}
@SuppressWarnings({"unchecked"})
private void addOneToManyAttached() {
- String owningReferencePropertyName = getMappedBy(propertyValue);
+ String mappedBy = getMappedBy(propertyValue);
+ EntityConfiguration referencedEntityConfiguration = mainGenerator.getEntitiesConfigurations()
+ .get(referencedEntityName);
+
+ IdMappingData referencedIdMapping = referencedEntityConfiguration.getIdMappingData();
IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();
- String lastPropertyPrefix = owningReferencePropertyName + "_";
- // Generating the id mapper for the relation
- IdMapper ownedIdMapper = referencingIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);
+ // Generating the id mappers data for the referencing side of the relation.
+ MiddleIdData referencingIdData = new MiddleIdData(mainGenerator.getVerEntCfg(), referencingIdMapping,
+ mappedBy + "_", referencingEntityName);
- // Storing information about this relation
- referencingEntityConfiguration.addToManyNotOwningRelation(propertyName, owningReferencePropertyName,
- referencedEntityName, ownedIdMapper);
+ // And for the referenced side. The prefixed mapper won't be used (as this collection isn't persisted
+ // in a join table, so the prefix value is arbitrary).
+ MiddleIdData referencedIdData = new MiddleIdData(mainGenerator.getVerEntCfg(), referencedIdMapping,
+ null, referencedEntityName);
- // Adding mapper for the id
- currentMapper.addComposite(propertyName, new OneToManyAttachedMapper(referencedEntityName, propertyName,
- owningReferencePropertyName));
+ // Generating the element mapping.
+ MiddleComponentData elementComponentData = new MiddleComponentData(
+ new MiddleRelatedComponentMapper(referencedIdData), 0);
+
+ // Generating the index mapping, if an index exists. It can only exists in case a javax.persistence.MapKey
+ // annotation is present on the entity. So the middleEntityXml will be not be used. The queryGeneratorBuilder
+ // will only be checked for nullnes.
+ MiddleComponentData indexComponentData = addIndex(null, null);
+
+ // Generating the query generator - it should read directly from the related entity.
+ RelationQueryGenerator queryGenerator = new OneVersionsEntityQueryGenerator(mainGenerator.getVerEntCfg(),
+ referencingIdData, referencedEntityName, referencedIdMapping.getIdMapper());
+
+ // Creating common mapper data.
+ CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(
+ mainGenerator.getVerEntCfg(), referencedEntityName, propertyName,
+ referencingIdData, queryGenerator);
+
+ // Checking the type of the collection and adding an appropriate mapper.
+ addMapper(commonCollectionMapperData, elementComponentData, indexComponentData);
+
+ // Storing information about this relation.
+ referencingEntityConfiguration.addToManyNotOwningRelation(propertyName, mappedBy,
+ referencedEntityName, referencingIdData.getPrefixedMapper());
}
/**
@@ -201,11 +227,8 @@
}
// Storing the id data of the referencing entity: original mapper, prefixed mapper and entity name.
- MiddleIdData referencingIdData = new MiddleIdData(
- referencingIdMapping.getIdMapper(),
- referencingIdMapping.getIdMapper().prefixMappedProperties(referencingPrefixRelated),
- referencingEntityName,
- mainGenerator.getVerEntCfg().getVersionsEntityName(referencingEntityName));
+ MiddleIdData referencingIdData = new MiddleIdData(mainGenerator.getVerEntCfg(), referencingIdMapping,
+ referencingPrefixRelated, referencingEntityName);
// 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
@@ -236,7 +259,7 @@
// Generating the property mapper.
// ******
// Building the query generator.
- MiddleTableQueryGenerator queryGenerator = queryGeneratorBuilder.build(elementComponentData, indexComponentData);
+ RelationQueryGenerator queryGenerator = queryGeneratorBuilder.build(elementComponentData, indexComponentData);
// Creating common data
CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(
@@ -261,21 +284,20 @@
} else {
IdMappingData referencedIdMapping = mainGenerator.getEntitiesConfigurations()
.get(referencedEntityName).getIdMappingData();
+ int currentIndex = queryGeneratorBuilder == null ? 0 : queryGeneratorBuilder.getCurrentIndex();
if ("".equals(mapKey)) {
// The key of the map is the id of the entity.
return new MiddleComponentData(new MiddleMapKeyIdComponentMapper(mainGenerator.getVerEntCfg(),
- referencedIdMapping.getIdMapper()), queryGeneratorBuilder.getCurrentIndex());
+ referencedIdMapping.getIdMapper()), currentIndex);
} else {
// The key of the map is a property of the entity.
- return new MiddleComponentData(new MiddleMapKeyPropertyComponentMapper(mapKey),
- queryGeneratorBuilder.getCurrentIndex());
+ return new MiddleComponentData(new MiddleMapKeyPropertyComponentMapper(mapKey), currentIndex);
}
}
// TODO: @MapKeyManyToMany
} else {
// No index - creating a dummy mapper.
- return new MiddleComponentData(new MiddleDummyComponentMapper(),
- queryGeneratorBuilder.getCurrentIndex());
+ return new MiddleComponentData(new MiddleDummyComponentMapper(), 0);
}
}
@@ -313,12 +335,8 @@
}
// Storing the id data of the referenced entity: original mapper, prefixed mapper and entity name.
- IdMapper referencedPrefixedIdMapper = referencedIdMapping.getIdMapper().prefixMappedProperties(prefixRelated);
- MiddleIdData referencedIdData = new MiddleIdData(
- referencedIdMapping.getIdMapper(),
- referencedPrefixedIdMapper,
- referencedEntityName,
- mainGenerator.getVerEntCfg().getVersionsEntityName(referencedEntityName));
+ MiddleIdData referencedIdData = new MiddleIdData(mainGenerator.getVerEntCfg(), referencedIdMapping,
+ prefixRelated, referencedEntityName);
// And adding it to the generator builder.
queryGeneratorBuilder.addRelation(referencedIdData);
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -2,7 +2,7 @@
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
-import org.jboss.envers.entities.mapper.relation.query.MiddleTableQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.query.RelationQueryGenerator;
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;
@@ -35,7 +35,7 @@
idDatas.add(idData);
}
- MiddleTableQueryGenerator build(MiddleComponentData... componentDatas) {
+ RelationQueryGenerator build(MiddleComponentData... componentDatas) {
if (idDatas.size() == 0) {
return new OneEntityQueryGenerator(verEntCfg, versionsMiddleEntityName, referencingIdData,
componentDatas);
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/CommonCollectionMapperData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/CommonCollectionMapperData.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/CommonCollectionMapperData.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,7 +1,7 @@
package org.jboss.envers.entities.mapper.relation;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
-import org.jboss.envers.entities.mapper.relation.query.MiddleTableQueryGenerator;
+import org.jboss.envers.entities.mapper.relation.query.RelationQueryGenerator;
/**
* Data that is used by all collection mappers, regardless of the type.
@@ -12,11 +12,11 @@
private final String versionsMiddleEntityName;
private final String collectionReferencingPropertyName;
private final MiddleIdData referencingIdData;
- private final MiddleTableQueryGenerator queryGenerator;
+ private final RelationQueryGenerator queryGenerator;
public CommonCollectionMapperData(VersionsEntitiesConfiguration verEntCfg, String versionsMiddleEntityName,
String collectionReferencingPropertyName, MiddleIdData referencingIdData,
- MiddleTableQueryGenerator queryGenerator) {
+ RelationQueryGenerator queryGenerator) {
this.verEntCfg = verEntCfg;
this.versionsMiddleEntityName = versionsMiddleEntityName;
this.collectionReferencingPropertyName = collectionReferencingPropertyName;
@@ -40,7 +40,7 @@
return referencingIdData;
}
- public MiddleTableQueryGenerator getQueryGenerator() {
+ public RelationQueryGenerator getQueryGenerator() {
return queryGenerator;
}
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleIdData.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleIdData.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/MiddleIdData.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,6 +1,8 @@
package org.jboss.envers.entities.mapper.relation;
import org.jboss.envers.entities.mapper.id.IdMapper;
+import org.jboss.envers.entities.IdMappingData;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
/**
* A class holding information about ids, which form a virtual "relation" from a middle-table. Middle-tables are used
@@ -25,11 +27,12 @@
*/
private final String versionsEntityName;
- public MiddleIdData(IdMapper originalMapper, IdMapper prefixedMapper, String entityName, String versionsEntityName) {
- this.originalMapper = originalMapper;
- this.prefixedMapper = prefixedMapper;
+ public MiddleIdData(VersionsEntitiesConfiguration verEntCfg, IdMappingData mappingData, String prefix,
+ String entityName) {
+ this.originalMapper = mappingData.getIdMapper();
+ this.prefixedMapper = mappingData.getIdMapper().prefixMappedProperties(prefix);
this.entityName = entityName;
- this.versionsEntityName = versionsEntityName;
+ this.versionsEntityName = verEntCfg.getVersionsEntityName(entityName);
}
public IdMapper getOriginalMapper() {
Deleted: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyAttachedMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyAttachedMapper.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToManyAttachedMapper.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,101 +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;
-
-import org.jboss.envers.entities.mapper.PropertyMapper;
-import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
-import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.entities.mapper.relation.lazy.OneToManyAttachedInitializor;
-import org.jboss.envers.entities.mapper.relation.lazy.proxy.ListProxy;
-import org.jboss.envers.entities.mapper.relation.lazy.proxy.SetProxy;
-import org.jboss.envers.entities.mapper.relation.lazy.proxy.MapProxy;
-import org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor;
-import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.tools.reflection.ReflectionTools;
-import org.jboss.envers.exception.VersionsException;
-import org.hibernate.collection.PersistentCollection;
-import org.hibernate.property.Getter;
-import org.hibernate.property.Setter;
-
-import java.util.*;
-import java.io.Serializable;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class OneToManyAttachedMapper implements PropertyMapper {
- private final String owningEntityName;
- private final String propertyName;
- private final String owningReferencePropertyName;
-
- public OneToManyAttachedMapper(String owningEntityName, String propertyName, String owningReferencePropertyName) {
- this.owningEntityName = owningEntityName;
- this.propertyName = propertyName;
- this.owningReferencePropertyName = owningReferencePropertyName;
- }
-
- @SuppressWarnings({"unchecked"})
- public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey,
- VersionsReaderImplementor versionsReader, Number revision) {
- if (obj == null) {
- return;
- }
-
- Class<?> entityClass = ReflectionTools.loadClass(owningEntityName);
-
- Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyName);
- Class collectionClass = getter.getReturnType();
-
- // todo: investigate generics
- // todo: add support for @MapKey, sorted collections
- Object value;
- if (List.class.isAssignableFrom(collectionClass)) {
- value = new ListProxy(getInitializator(versionsReader, entityClass, primaryKey, revision, ArrayList.class));
- } else if (Set.class.isAssignableFrom(collectionClass) || Collection.class.isAssignableFrom(collectionClass)) {
- value = new SetProxy(getInitializator(versionsReader, entityClass, primaryKey, revision, HashSet.class));
- } else if (Map.class.isAssignableFrom(collectionClass)) {
- value = new MapProxy(getInitializator(versionsReader, entityClass, primaryKey, revision, HashMap.class));
- } else {
- throw new VersionsException("Unsupported versioned collection type: " + collectionClass.getName());
- }
-
- Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyName);
- setter.set(obj, value, null);
- }
-
- public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj) {
- return false;
- }
-
- protected <T> Initializor<T> getInitializator(VersionsReaderImplementor versionsReader,
- Class<?> entityClass, Object primaryKey,
- Number revision,
- Class<T> collectionClass) {
- return new OneToManyAttachedInitializor<T>(versionsReader, entityClass, owningReferencePropertyName, primaryKey,
- revision, collectionClass);
- }
-
- public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName, PersistentCollection newColl,
- Serializable oldColl, Serializable id) {
- return null;
- }
-}
\ No newline at end of file
Deleted: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyComponentMapper.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyComponentMapper.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,34 +0,0 @@
-package org.jboss.envers.entities.mapper.relation.component;
-
-import org.jboss.envers.entities.EntityInstantiator;
-import org.jboss.envers.entities.mapper.relation.MiddleIdData;
-import org.jboss.envers.tools.query.Parameters;
-
-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.
- }
-
- public void addMiddleEqualToQuery(Parameters parameters, String prefix1, String prefix2) {
- // Doing nothing.
- }
-}
\ No newline at end of file
Deleted: 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-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/OneToManyAttachedInitializor.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,75 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.entities.mapper.relation.lazy;
-
-import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.entities.mapper.relation.lazy.initializor.Initializor;
-import org.jboss.envers.query.VersionsRestrictions;
-import org.jboss.envers.exception.VersionsException;
-
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class OneToManyAttachedInitializor<T> implements Initializor<T> {
- private VersionsReaderImplementor versionsReader;
- private Class<?> entityClass;
- private String owningReferencePropertyName;
- private Object primaryKey;
- private Number revision;
- private Class<T> collectionClass;
-
- public OneToManyAttachedInitializor(VersionsReaderImplementor versionsReader, Class<?> entityClass,
- String owningReferencePropertyName, Object primaryKey, Number revision,
- Class<T> collectionClass) {
- this.versionsReader = versionsReader;
- this.entityClass = entityClass;
- this.owningReferencePropertyName = owningReferencePropertyName;
- this.primaryKey = primaryKey;
- this.revision = revision;
- this.collectionClass = collectionClass;
- }
-
- @SuppressWarnings({"unchecked"})
- public T initialize() {
- List queryResult = versionsReader.createQuery().forEntitiesAtRevision(entityClass, revision)
- .add(VersionsRestrictions.relatedIdEq(owningReferencePropertyName, primaryKey)).getResultList();
-
- if (collectionClass.isAssignableFrom(queryResult.getClass())) {
- return (T) queryResult;
- } else {
- Collection result;
- try {
- // TODO
- result = (Collection) collectionClass.newInstance();
- } catch (Exception e) {
- throw new VersionsException(e);
- }
-
- result.addAll(queryResult);
-
- return (T) result;
- }
- }
-}
Modified: 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 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/AbstractCollectionInitializor.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,6 +1,6 @@
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.query.RelationQueryGenerator;
import org.jboss.envers.entities.EntityInstantiator;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.configuration.VersionsConfiguration;
@@ -13,7 +13,7 @@
*/
public abstract class AbstractCollectionInitializor<T> implements Initializor<T> {
private final VersionsReaderImplementor versionsReader;
- private final MiddleTableQueryGenerator queryGenerator;
+ private final RelationQueryGenerator queryGenerator;
private final Object primaryKey;
protected final Number revision;
@@ -21,7 +21,7 @@
public AbstractCollectionInitializor(VersionsConfiguration verCfg,
VersionsReaderImplementor versionsReader,
- MiddleTableQueryGenerator queryGenerator,
+ RelationQueryGenerator queryGenerator,
Object primaryKey, Number revision) {
this.versionsReader = versionsReader;
this.queryGenerator = queryGenerator;
Modified: 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 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,6 +1,6 @@
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.query.RelationQueryGenerator;
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.configuration.VersionsConfiguration;
@@ -17,7 +17,7 @@
public ArrayCollectionInitializor(VersionsConfiguration verCfg,
VersionsReaderImplementor versionsReader,
- MiddleTableQueryGenerator queryGenerator,
+ RelationQueryGenerator queryGenerator,
Object primaryKey, Number revision,
MiddleComponentData elementComponentData,
MiddleComponentData indexComponentData) {
Modified: 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 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,6 +1,6 @@
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.query.RelationQueryGenerator;
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
@@ -18,7 +18,7 @@
public BasicCollectionInitializor(VersionsConfiguration verCfg,
VersionsReaderImplementor versionsReader,
- MiddleTableQueryGenerator queryGenerator,
+ RelationQueryGenerator queryGenerator,
Object primaryKey, Number revision,
Class<? extends T> collectionClass,
MiddleComponentData elementComponentData) {
Modified: 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 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,6 +1,6 @@
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.query.RelationQueryGenerator;
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.configuration.VersionsConfiguration;
@@ -17,7 +17,7 @@
public ListCollectionInitializor(VersionsConfiguration verCfg,
VersionsReaderImplementor versionsReader,
- MiddleTableQueryGenerator queryGenerator,
+ RelationQueryGenerator queryGenerator,
Object primaryKey, Number revision,
MiddleComponentData elementComponentData,
MiddleComponentData indexComponentData) {
Modified: 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 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,6 +1,6 @@
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.query.RelationQueryGenerator;
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.exception.VersionsException;
@@ -19,7 +19,7 @@
public MapCollectionInitializor(VersionsConfiguration verCfg,
VersionsReaderImplementor versionsReader,
- MiddleTableQueryGenerator queryGenerator,
+ RelationQueryGenerator queryGenerator,
Object primaryKey, Number revision,
Class<? extends T> collectionClass,
MiddleComponentData elementComponentData,
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -13,9 +13,10 @@
import java.util.Collections;
/**
+ * Selects data from a relation middle-table only.
* @author Adam Warski (adam at warski dot org)
*/
-public final class OneEntityQueryGenerator implements MiddleTableQueryGenerator {
+public final class OneEntityQueryGenerator implements RelationQueryGenerator {
private final String queryString;
private final MiddleIdData referencingIdData;
Copied: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java (from rev 155, trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -0,0 +1,84 @@
+package org.jboss.envers.entities.mapper.relation.query;
+
+import org.jboss.envers.entities.mapper.id.QueryParameterData;
+import org.jboss.envers.entities.mapper.id.IdMapper;
+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.jboss.envers.tools.query.QueryBuilder;
+import org.jboss.envers.tools.query.Parameters;
+import org.hibernate.Query;
+
+import java.util.Collections;
+
+/**
+ * Selects data from a versions entity.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class OneVersionsEntityQueryGenerator implements RelationQueryGenerator {
+ private final String queryString;
+ private final MiddleIdData referencingIdData;
+
+ public OneVersionsEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData,
+ String referencedEntityName, IdMapper referencedIdMapper) {
+ this.referencingIdData = referencingIdData;
+
+ /*
+ * The query that we need to create:
+ * SELECT new list(e) FROM versionsReferencedEntity e
+ * WHERE
+ * (only entities referenced by the association; id_ref_ing = id of the referencing entity)
+ * e.id_ref_ing = :id_ref_ing AND
+ * (selecting e entities at revision :revision)
+ * e.revision = (SELECT max(e2.revision) FROM versionsReferencedEntity e2
+ * WHERE e2.revision <= :revision AND e2.id = e.id) AND
+ * (only non-deleted entities)
+ * e.revision_type != DEL
+ */
+ String revisionPropertyPath = verEntCfg.getRevisionPropPath();
+ String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
+
+ String versionsReferencedEntityName = verEntCfg.getVersionsEntityName(referencedEntityName);
+
+ // SELECT new list(e) FROM versionsEntity e
+ QueryBuilder qb = new QueryBuilder(versionsReferencedEntityName, "e");
+ qb.addProjection("new list", "e", false, false);
+ // WHERE
+ Parameters rootParameters = qb.getRootParameters();
+ // e.id_ref_ed = :id_ref_ed
+ referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, null, true);
+
+ // SELECT max(e.revision) FROM versionsReferencedEntity e2
+ QueryBuilder maxERevQb = qb.newSubQueryBuilder(versionsReferencedEntityName, "e2");
+ maxERevQb.addProjection("max", revisionPropertyPath, false);
+ // WHERE
+ Parameters maxERevQbParameters = maxERevQb.getRootParameters();
+ // e2.revision <= :revision
+ maxERevQbParameters.addWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
+ // e2.id = e.id
+ referencedIdMapper.addIdsEqualToQuery(maxERevQbParameters,
+ "e." + originalIdPropertyName, "e2." + originalIdPropertyName);
+
+ // e.revision = (SELECT max(...) ...)
+ rootParameters.addWhere(revisionPropertyPath, false, "=", maxERevQb);
+
+ // e.revision_type != DEL
+ rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(), false, "!=", "delrevisiontype");
+
+ StringBuilder sb = new StringBuilder();
+ qb.build(sb, Collections.<String, Object>emptyMap());
+ queryString = sb.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;
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/RelationQueryGenerator.java (from rev 151, trunk/src/main/org/jboss/envers/entities/mapper/relation/query/MiddleTableQueryGenerator.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/RelationQueryGenerator.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/RelationQueryGenerator.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -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 relation table (a table used
+ * for mapping relations). The query can select, apart from selecting the content of the relation table, also data of
+ * other "related" entities.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public interface RelationQueryGenerator {
+ Query getQuery(VersionsReaderImplementor versionsReader, Object primaryKey, Number revision);
+}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -8,7 +8,7 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public final class ThreeEntityQueryGenerator implements MiddleTableQueryGenerator {
+public final class ThreeEntityQueryGenerator implements RelationQueryGenerator {
private final String queryString;
private final MiddleIdData referencingIdData;
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -13,9 +13,10 @@
import java.util.Collections;
/**
+ * Selects data from a relation middle-table and a related versions entity.
* @author Adam Warski (adam at warski dot org)
*/
-public final class TwoEntityQueryGenerator implements MiddleTableQueryGenerator {
+public final class TwoEntityQueryGenerator implements RelationQueryGenerator {
private final String queryString;
private final MiddleIdData referencingIdData;
Modified: trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKey.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKey.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKey.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -76,7 +76,6 @@
IdMapKeyEntity rev1 = getVersionsReader().find(IdMapKeyEntity.class, imke_id, 1);
IdMapKeyEntity rev2 = getVersionsReader().find(IdMapKeyEntity.class, imke_id, 2);
- System.out.println(rev1.getIdmap());
assert rev1.getIdmap().equals(TestTools.makeMap(ste1.getId(), ste1));
assert rev2.getIdmap().equals(TestTools.makeMap(ste1.getId(), ste1, ste2.getId(), ste2));
}
Deleted: trunk/src/test/org/jboss/envers/test/integration/components/Component1.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/components/Component1.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/test/org/jboss/envers/test/integration/components/Component1.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,53 +0,0 @@
-package org.jboss.envers.test.integration.components;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class Component1 {
- private String str1;
-
- private String str2;
-
- public Component1(String str1, String str2) {
- this.str1 = str1;
- this.str2 = str2;
- }
-
- public Component1() {
- }
-
- public String getStr2() {
- return str2;
- }
-
- public void setStr2(String str2) {
- this.str2 = str2;
- }
-
- public String getStr1() {
- return str1;
- }
-
- public void setStr1(String str1) {
- this.str1 = str1;
- }
-
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof Component1)) return false;
-
- Component1 that = (Component1) o;
-
- if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false;
- if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result;
- result = (str1 != null ? str1.hashCode() : 0);
- result = 31 * result + (str2 != null ? str2.hashCode() : 0);
- return result;
- }
-}
Deleted: trunk/src/test/org/jboss/envers/test/integration/components/Component2.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/components/Component2.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/test/org/jboss/envers/test/integration/components/Component2.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,53 +0,0 @@
-package org.jboss.envers.test.integration.components;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class Component2 {
- private String str5;
-
- private String str6;
-
- public Component2(String str5, String str6) {
- this.str5 = str5;
- this.str6 = str6;
- }
-
- public Component2() {
- }
-
- public String getStr5() {
- return str5;
- }
-
- public void setStr5(String str5) {
- this.str5 = str5;
- }
-
- public String getStr6() {
- return str6;
- }
-
- public void setStr6(String str6) {
- this.str6 = str6;
- }
-
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof Component2)) return false;
-
- Component2 that = (Component2) o;
-
- if (str5 != null ? !str5.equals(that.str5) : that.str5 != null) return false;
- if (str6 != null ? !str6.equals(that.str6) : that.str6 != null) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result;
- result = (str5 != null ? str5.hashCode() : 0);
- result = 31 * result + (str6 != null ? str6.hashCode() : 0);
- return result;
- }
-}
Deleted: trunk/src/test/org/jboss/envers/test/integration/components/ComponentTestEntity.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/components/ComponentTestEntity.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/test/org/jboss/envers/test/integration/components/ComponentTestEntity.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -1,85 +0,0 @@
-package org.jboss.envers.test.integration.components;
-
-import org.jboss.envers.Versioned;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Embedded;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-@Entity
-public class ComponentTestEntity {
- @Id
- @GeneratedValue
- private Integer id;
-
- @Embedded
- @Versioned
- private Component1 comp1;
-
- @Embedded
- private Component2 comp2;
-
- public ComponentTestEntity() {
- }
-
- public ComponentTestEntity(Integer id, Component1 comp1, Component2 comp2) {
- this.id = id;
- this.comp1 = comp1;
- this.comp2 = comp2;
- }
-
- public ComponentTestEntity(Component1 comp1, Component2 comp2) {
- this.comp1 = comp1;
- this.comp2 = comp2;
- }
-
- public Integer getId() {
- return id;
- }
-
- public void setId(Integer id) {
- this.id = id;
- }
-
- public Component1 getComp1() {
- return comp1;
- }
-
- public void setComp1(Component1 comp1) {
- this.comp1 = comp1;
- }
-
- public Component2 getComp2() {
- return comp2;
- }
-
- public void setComp2(Component2 comp2) {
- this.comp2 = comp2;
- }
-
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof ComponentTestEntity)) return false;
-
- ComponentTestEntity that = (ComponentTestEntity) o;
-
- if (comp1 != null ? !comp1.equals(that.comp1) : that.comp1 != null) return false;
- if (comp2 != null ? !comp2.equals(that.comp2) : that.comp2 != null) return false;
- if (id != null ? !id.equals(that.id) : that.id != null) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result;
- result = (id != null ? id.hashCode() : 0);
- result = 31 * result + (comp1 != null ? comp1.hashCode() : 0);
- result = 31 * result + (comp2 != null ? comp2.hashCode() : 0);
- return result;
- }
-}
-
Modified: trunk/src/test/org/jboss/envers/test/integration/onetomany/BasicCollection.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/onetomany/BasicCollection.java 2008-09-23 17:05:36 UTC (rev 165)
+++ trunk/src/test/org/jboss/envers/test/integration/onetomany/BasicCollection.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -103,9 +103,14 @@
CollectionRefEdEntity rev2 = getVersionsReader().find(CollectionRefEdEntity.class, ed1_id, 2);
CollectionRefEdEntity rev3 = getVersionsReader().find(CollectionRefEdEntity.class, ed1_id, 3);
- assert rev1.getReffering().equals(makeSet(ing1, ing2));
- assert rev2.getReffering().equals(makeSet(ing2));
- assert rev3.getReffering().equals(Collections.EMPTY_SET);
+ assert rev1.getReffering().containsAll(makeSet(ing1, ing2));
+ assert rev1.getReffering().size() == 2;
+
+ assert rev2.getReffering().containsAll(makeSet(ing2));
+ assert rev2.getReffering().size() == 1;
+
+ assert rev3.getReffering().containsAll(Collections.EMPTY_SET);
+ assert rev3.getReffering().size() == 0;
}
@Test
@@ -117,9 +122,15 @@
CollectionRefEdEntity rev2 = getVersionsReader().find(CollectionRefEdEntity.class, ed2_id, 2);
CollectionRefEdEntity rev3 = getVersionsReader().find(CollectionRefEdEntity.class, ed2_id, 3);
- assert rev1.getReffering().equals(Collections.EMPTY_SET);
- assert rev2.getReffering().equals(makeSet(ing1));
- assert rev3.getReffering().equals(makeSet(ing1, ing2));
+ assert rev1.getReffering().containsAll(Collections.EMPTY_SET);
+ assert rev1.getReffering().size() == 0;
+
+ assert rev2.getReffering().containsAll(makeSet(ing1));
+ assert rev2.getReffering().size() == 1;
+
+ assert rev3.getReffering().containsAll(makeSet(ing1, ing2));
+ assert rev3.getReffering().size() == 2;
+
}
@Test
Copied: trunk/src/test/org/jboss/envers/test/integration/onetomany/BidirectionalMapKey.java (from rev 165, trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/ComponentMapKey.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/onetomany/BidirectionalMapKey.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/onetomany/BidirectionalMapKey.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -0,0 +1,86 @@
+package org.jboss.envers.test.integration.onetomany;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.tools.TestTools;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.hibernate.ejb.Ejb3Configuration;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class BidirectionalMapKey extends AbstractEntityTest {
+ private Integer ed_id;
+
+ private Integer ing1_id;
+ private Integer ing2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(RefIngMapKeyEntity.class);
+ cfg.addAnnotatedClass(RefEdMapKeyEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ // Revision 1 (intialy 1 relation: ing1 -> ed)
+ em.getTransaction().begin();
+
+ RefEdMapKeyEntity ed = new RefEdMapKeyEntity();
+
+ em.persist(ed);
+
+ RefIngMapKeyEntity ing1 = new RefIngMapKeyEntity();
+ ing1.setData("a");
+ ing1.setReference(ed);
+
+ RefIngMapKeyEntity ing2 = new RefIngMapKeyEntity();
+ ing2.setData("b");
+
+ em.persist(ing1);
+ em.persist(ing2);
+
+ em.getTransaction().commit();
+
+ // Revision 2 (adding second relation: ing2 -> ed)
+ em.getTransaction().begin();
+
+ ed = em.find(RefEdMapKeyEntity.class, ed.getId());
+ ing2 = em.find(RefIngMapKeyEntity.class, ing2.getId());
+
+ ing2.setReference(ed);
+
+ em.getTransaction().commit();
+
+ //
+
+ ed_id = ed.getId();
+
+ ing1_id = ing1.getId();
+ ing2_id = ing2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getVersionsReader().getRevisions(RefEdMapKeyEntity.class, ed_id));
+
+ assert Arrays.asList(1).equals(getVersionsReader().getRevisions(RefIngMapKeyEntity.class, ing1_id));
+ assert Arrays.asList(1, 2).equals(getVersionsReader().getRevisions(RefIngMapKeyEntity.class, ing2_id));
+ }
+
+ @Test
+ public void testHistoryOfEd() {
+ RefIngMapKeyEntity ing1 = getEntityManager().find(RefIngMapKeyEntity.class, ing1_id);
+ RefIngMapKeyEntity ing2 = getEntityManager().find(RefIngMapKeyEntity.class, ing2_id);
+
+ RefEdMapKeyEntity rev1 = getVersionsReader().find(RefEdMapKeyEntity.class, ed_id, 1);
+ RefEdMapKeyEntity rev2 = getVersionsReader().find(RefEdMapKeyEntity.class, ed_id, 2);
+
+ assert rev1.getIdmap().equals(TestTools.makeMap("a", ing1));
+ assert rev2.getIdmap().equals(TestTools.makeMap("a", ing1, "b", ing2));
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/integration/onetomany/BidirectionalMapKey.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/src/test/org/jboss/envers/test/integration/onetomany/RefEdMapKeyEntity.java (from rev 165, trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/ComponentMapKeyEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/onetomany/RefEdMapKeyEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/onetomany/RefEdMapKeyEntity.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -0,0 +1,61 @@
+package org.jboss.envers.test.integration.onetomany;
+
+import org.jboss.envers.Versioned;
+
+import javax.persistence.*;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class RefEdMapKeyEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Versioned
+ @OneToMany(mappedBy="reference")
+ @MapKey(name = "data")
+ private Map<String, RefIngMapKeyEntity> idmap;
+
+ public RefEdMapKeyEntity() {
+ idmap = new HashMap<String, RefIngMapKeyEntity>();
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Map<String, RefIngMapKeyEntity> getIdmap() {
+ return idmap;
+ }
+
+ public void setIdmap(Map<String, RefIngMapKeyEntity> idmap) {
+ this.idmap = idmap;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof RefEdMapKeyEntity)) return false;
+
+ RefEdMapKeyEntity that = (RefEdMapKeyEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return (id != null ? id.hashCode() : 0);
+ }
+
+ public String toString() {
+ return "RedMKE(id = " + id + ", idmap = " + idmap + ")";
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/integration/onetomany/RefEdMapKeyEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/src/test/org/jboss/envers/test/integration/onetomany/RefIngMapKeyEntity.java (from rev 165, trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/ComponentMapKeyEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/onetomany/RefIngMapKeyEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/onetomany/RefIngMapKeyEntity.java 2008-09-24 10:42:17 UTC (rev 166)
@@ -0,0 +1,65 @@
+package org.jboss.envers.test.integration.onetomany;
+
+import org.jboss.envers.Versioned;
+
+import javax.persistence.*;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class RefIngMapKeyEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Versioned
+ @ManyToOne
+ private RefEdMapKeyEntity reference;
+
+ @Versioned
+ private String data;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public RefEdMapKeyEntity getReference() {
+ return reference;
+ }
+
+ public void setReference(RefEdMapKeyEntity reference) {
+ this.reference = reference;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof RefIngMapKeyEntity)) return false;
+
+ RefIngMapKeyEntity that = (RefIngMapKeyEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return (id != null ? id.hashCode() : 0);
+ }
+
+ public String toString() {
+ return "RingMKE(id = " + id + ", data = " + data + ", reference = " + reference + ")";
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/integration/onetomany/RefIngMapKeyEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
16 years, 3 months
JBoss Envers SVN: r165 - in trunk: src/main/org/jboss/envers/configuration/metadata and 7 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-23 13:05:36 -0400 (Tue, 23 Sep 2008)
New Revision: 165
Added:
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyPropertyComponentMapper.java
trunk/src/test/org/jboss/envers/test/entities/components/
trunk/src/test/org/jboss/envers/test/entities/components/Component1.java
trunk/src/test/org/jboss/envers/test/entities/components/Component2.java
trunk/src/test/org/jboss/envers/test/entities/components/ComponentTestEntity.java
trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/
trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/ComponentMapKey.java
trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/ComponentMapKeyEntity.java
trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKey.java
trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKeyEntity.java
Modified:
trunk/resources/test/testng.xml
trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/PersistentClassVersioningData.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
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/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/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/ListCollectionInitializor.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.java
trunk/src/test/org/jboss/envers/test/integration/components/Components.java
Log:
ENVERS-25: support for @MapKey
Modified: trunk/resources/test/testng.xml
===================================================================
--- trunk/resources/test/testng.xml 2008-09-22 21:20:21 UTC (rev 164)
+++ trunk/resources/test/testng.xml 2008-09-23 17:05:36 UTC (rev 165)
@@ -4,7 +4,8 @@
<test name="All">
<packages>
<package name="org.jboss.envers.test.integration.basic" />
- <package name="org.jboss.envers.test.integration.collection" />
+ <package name="org.jboss.envers.test.integration.collection" />
+ <package name="org.jboss.envers.test.integration.collection.mapkey" />
<package name="org.jboss.envers.test.integration.components" />
<package name="org.jboss.envers.test.integration.customtype" />
<package name="org.jboss.envers.test.integration.data" />
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-09-22 21:20:21 UTC (rev 164)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/AnnotationsMetadataReader.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -22,6 +22,7 @@
package org.jboss.envers.configuration.metadata;
import javax.persistence.Version;
+import javax.persistence.MapKey;
import org.jboss.envers.configuration.GlobalConfiguration;
import org.jboss.envers.tools.reflection.YClass;
@@ -65,6 +66,13 @@
}
}
+ private void addPropertyMapKey(YProperty property) {
+ MapKey mapKey = property.getAnnotation(MapKey.class);
+ if (mapKey != null) {
+ versioningData.mapKeys.put(property.getName(), mapKey.name());
+ }
+ }
+
private void addPropertyUnversioned(YProperty property) {
// check if a property is declared as unversioned to exclude it
// useful if a class is versioned but some properties should be excluded
@@ -95,6 +103,7 @@
addPropertyVersioned(property);
addPropertyUnversioned(property);
addPropertyJoinTables(property);
+ addPropertyMapKey(property);
}
}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-22 21:20:21 UTC (rev 164)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -8,9 +8,7 @@
import org.jboss.envers.entities.mapper.relation.*;
import org.jboss.envers.entities.mapper.relation.lazy.proxy.*;
import org.jboss.envers.entities.mapper.relation.query.MiddleTableQueryGenerator;
-import org.jboss.envers.entities.mapper.relation.component.MiddleRelatedComponentMapper;
-import org.jboss.envers.entities.mapper.relation.component.MiddleSimpleComponentMapper;
-import org.jboss.envers.entities.mapper.relation.component.MiddleDummyComponentMapper;
+import org.jboss.envers.entities.mapper.relation.component.*;
import org.jboss.envers.entities.mapper.id.IdMapper;
import org.jboss.envers.entities.EntityConfiguration;
import org.jboss.envers.entities.IdMappingData;
@@ -39,6 +37,7 @@
private final String referencingEntityName;
private final EntityXmlMappingData xmlMappingData;
private final VersionsJoinTable joinTable;
+ private final String mapKey;
private final EntityConfiguration referencingEntityConfiguration;
/**
@@ -56,11 +55,13 @@
* @param xmlMappingData In case this collection requires a middle table, additional mapping documents will
* be created using this object.
* @param joinTable User data for the middle (join) table. <code>null</code> if the user didn't specify it.
+ * @param mapKey The value of the name() property of the MapKey annotation on this property. Null, if this
+ * property isn't annotated with this annotation.
*/
public CollectionMetadataGenerator(VersionsMetadataGenerator mainGenerator, String propertyName,
Collection propertyValue, CompositeMapperBuilder currentMapper,
String referencingEntityName, EntityXmlMappingData xmlMappingData,
- VersionsJoinTable joinTable) {
+ VersionsJoinTable joinTable, String mapKey) {
this.mainGenerator = mainGenerator;
this.propertyName = propertyName;
this.propertyValue = propertyValue;
@@ -68,6 +69,7 @@
this.referencingEntityName = referencingEntityName;
this.xmlMappingData = xmlMappingData;
this.joinTable = joinTable == null ? getDefaultVersionsJoinTable() : joinTable;
+ this.mapKey = mapKey;
referencingEntityConfiguration = mainGenerator.getEntitiesConfigurations().get(referencingEntityName);
if (referencingEntityConfiguration == null) {
@@ -226,19 +228,9 @@
queryGeneratorBuilder, referencedPrefix, joinTable.inverseJoinColumns());
// ******
- // Optionally, generating the index mapping.
+ // Generating the index mapping, if an index exists.
// ******
- MiddleComponentData indexComponentData;
- if (propertyValue instanceof IndexedCollection) {
- IndexedCollection indexedValue = (IndexedCollection) propertyValue;
- indexComponentData = addValueToMiddleTable(indexedValue.getIndex(), middleEntityXml,
- queryGeneratorBuilder, "mapkey", null);
- // TODO: @MapKey support, @MapKeyManyToMany
- } else {
- // No index - creating a dummy mapper.
- indexComponentData = new MiddleComponentData(new MiddleDummyComponentMapper(),
- queryGeneratorBuilder.getCurrentIndex());
- }
+ MiddleComponentData indexComponentData = addIndex(middleEntityXml, queryGeneratorBuilder);
// ******
// Generating the property mapper.
@@ -259,6 +251,34 @@
storeMiddleEntityRelationInformation(mappedBy);
}
+ private MiddleComponentData addIndex(Element middleEntityXml, QueryGeneratorBuilder queryGeneratorBuilder) {
+ if (propertyValue instanceof IndexedCollection) {
+ IndexedCollection indexedValue = (IndexedCollection) propertyValue;
+ if (mapKey == null) {
+ // This entity doesn't specify a javax.persistence.MapKey. Mapping it to the middle entity.
+ return addValueToMiddleTable(indexedValue.getIndex(), middleEntityXml,
+ queryGeneratorBuilder, "mapkey", null);
+ } else {
+ IdMappingData referencedIdMapping = mainGenerator.getEntitiesConfigurations()
+ .get(referencedEntityName).getIdMappingData();
+ if ("".equals(mapKey)) {
+ // The key of the map is the id of the entity.
+ return new MiddleComponentData(new MiddleMapKeyIdComponentMapper(mainGenerator.getVerEntCfg(),
+ referencedIdMapping.getIdMapper()), queryGeneratorBuilder.getCurrentIndex());
+ } else {
+ // The key of the map is a property of the entity.
+ return new MiddleComponentData(new MiddleMapKeyPropertyComponentMapper(mapKey),
+ queryGeneratorBuilder.getCurrentIndex());
+ }
+ }
+ // TODO: @MapKeyManyToMany
+ } else {
+ // No index - creating a dummy mapper.
+ return new MiddleComponentData(new MiddleDummyComponentMapper(),
+ queryGeneratorBuilder.getCurrentIndex());
+ }
+ }
+
/**
*
* @param value Value, which should be mapped to the middle-table, either as a relation to another entity,
@@ -279,8 +299,8 @@
String prefixRelated = prefix + "_";
String referencedEntityName = getReferencedEntityName(value);
- IdMappingData referencedIdMapping = mainGenerator.getEntitiesConfigurations().get(
- referencedEntityName).getIdMappingData();
+ IdMappingData referencedIdMapping = mainGenerator.getEntitiesConfigurations()
+ .get(referencedEntityName).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>xmlMapping</code> is not null).
@@ -305,8 +325,8 @@
return new MiddleComponentData(new MiddleRelatedComponentMapper(referencedIdData),
queryGeneratorBuilder.getCurrentIndex());
} else {
- boolean mapped = mainGenerator.getBasicMetadataGenerator().addBasic(xmlMapping, prefix, value, null,
- ModificationStore.FULL, referencingEntityName, true);
+ boolean mapped = mainGenerator.getBasicMetadataGenerator().addBasicNoComponent(xmlMapping, prefix, value, null,
+ ModificationStore.FULL, true);
if (mapped) {
// Simple values are always stored in the first item of the array returned by the query generator.
@@ -314,7 +334,7 @@
} else {
mainGenerator.throwUnsupportedTypeException(type, referencingEntityName, propertyName);
// Impossible to get here.
- throw new AssertionError();
+ throw new AssertionError();
}
}
}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/PersistentClassVersioningData.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/PersistentClassVersioningData.java 2008-09-22 21:20:21 UTC (rev 164)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/PersistentClassVersioningData.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -40,6 +40,7 @@
secondaryTableDictionary = new HashMap<String, String>();
unversionedProperties = new ArrayList<String>();
versionsJoinTables = new HashMap<String, VersionsJoinTable>();
+ mapKeys = new HashMap<String, String>();
}
public PropertyStoreInfo propertyStoreInfo;
@@ -50,6 +51,11 @@
* A map from property names to custom join tables definitions.
*/
public Map<String, VersionsJoinTable> versionsJoinTables;
+ /**
+ * A map from property names to the value of the related property names in a map key annotation. An empty string,
+ * if the property name is not specified in the mapkey annotation.
+ */
+ public Map<String, String> mapKeys;
public boolean isVersioned() {
if (propertyStoreInfo.propertyStores.size() > 0) { return true; }
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-09-22 21:20:21 UTC (rev 164)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -119,7 +119,7 @@
@SuppressWarnings({"unchecked"})
void addValue(Element parent, String name, Value value, CompositeMapperBuilder currentMapper,
ModificationStore store, String entityName, EntityXmlMappingData xmlMappingData,
- VersionsJoinTable joinTable, boolean firstPass) {
+ VersionsJoinTable joinTable, String mapKey, boolean firstPass) {
Type type = value.getType();
// only first pass
@@ -144,7 +144,7 @@
// only second pass
if (!firstPass) {
CollectionMetadataGenerator collectionMetadataGenerator = new CollectionMetadataGenerator(this,
- name, (Collection) value, currentMapper, entityName, xmlMappingData, joinTable);
+ name, (Collection) value, currentMapper, entityName, xmlMappingData, joinTable, mapKey);
collectionMetadataGenerator.addCollection();
}
} else {
@@ -168,7 +168,8 @@
if (store != null) {
addValue(parent, property.getName(), property.getValue(), currentMapper, store, entityName,
- xmlMappingData, versioningData.versionsJoinTables.get(property.getName()), firstPass);
+ xmlMappingData, versioningData.versionsJoinTables.get(property.getName()),
+ versioningData.mapKeys.get(property.getName()), firstPass);
}
}
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleComponentMapper.java 2008-09-22 21:20:21 UTC (rev 164)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleComponentMapper.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -10,14 +10,16 @@
*/
public interface MiddleComponentMapper {
/**
- * Maps from full object data, contained in the given map, to an object.
+ * Maps from full object data, contained in the given map (or object representation of the map, if
+ * available), to an object.
* @param entityInstantiator An entity instatiator bound with an open versions reader.
* @param data Full object data.
+ * @param dataObject An optional object representation of the 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);
+ Object dataObject, Number revision);
/**
* Maps from an object to the object's map representation (for an entity - only its id).
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-22 21:20:21 UTC (rev 164)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleDummyComponentMapper.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -9,7 +9,8 @@
* @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) {
+ public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map<String, Object> data,
+ Object dataObject, Number revision) {
return null;
}
Copied: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java (from rev 154, trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyComponentMapper.java)
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyIdComponentMapper.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -0,0 +1,37 @@
+package org.jboss.envers.entities.mapper.relation.component;
+
+import org.jboss.envers.entities.EntityInstantiator;
+import org.jboss.envers.entities.mapper.id.IdMapper;
+import org.jboss.envers.tools.query.Parameters;
+import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+
+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 MiddleMapKeyIdComponentMapper implements MiddleComponentMapper {
+ private final VersionsEntitiesConfiguration verEntCfg;
+ private final IdMapper relatedIdMapper;
+
+ public MiddleMapKeyIdComponentMapper(VersionsEntitiesConfiguration verEntCfg, IdMapper relatedIdMapper) {
+ this.verEntCfg = verEntCfg;
+ this.relatedIdMapper = relatedIdMapper;
+ }
+
+ public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map<String, Object> data,
+ Object dataObject, Number revision) {
+ return relatedIdMapper.mapToIdFromMap((Map) data.get(verEntCfg.getOriginalIdPropName()));
+ }
+
+ public void mapToMapFromObject(Map<String, Object> data, Object obj) {
+ // Doing nothing.
+ }
+
+ public void addMiddleEqualToQuery(Parameters parameters, String prefix1, String prefix2) {
+ // Doing nothing.
+ }
+}
\ No newline at end of file
Added: trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyPropertyComponentMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyPropertyComponentMapper.java (rev 0)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleMapKeyPropertyComponentMapper.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -0,0 +1,35 @@
+package org.jboss.envers.entities.mapper.relation.component;
+
+import org.jboss.envers.entities.EntityInstantiator;
+import org.jboss.envers.tools.query.Parameters;
+import org.jboss.envers.tools.reflection.ReflectionTools;
+
+import java.util.Map;
+
+/**
+ * A component mapper for the @MapKey mapping with the name parameter specified: the value of the map's key
+ * is a property 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 MiddleMapKeyPropertyComponentMapper implements MiddleComponentMapper {
+ private final String propertyName;
+
+ public MiddleMapKeyPropertyComponentMapper(String propertyName) {
+ this.propertyName = propertyName;
+ }
+
+ public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map<String, Object> data,
+ Object dataObject, Number revision) {
+ // dataObject is not null, as this mapper can only be used in an index.
+ return ReflectionTools.getGetter(dataObject.getClass(), propertyName).get(dataObject);
+ }
+
+ public void mapToMapFromObject(Map<String, Object> data, Object obj) {
+ // Doing nothing.
+ }
+
+ public void addMiddleEqualToQuery(Parameters parameters, String prefix1, String prefix2) {
+ // Doing nothing.
+ }
+}
\ No newline at end of file
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-22 21:20:21 UTC (rev 164)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleRelatedComponentMapper.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -17,7 +17,7 @@
}
public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map<String, Object> data,
- Number revision) {
+ Object dataObject, Number revision) {
return entityInstantiator.createInstanceFromVersionsEntity(relatedIdData.getEntityName(), data, revision);
}
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-22 21:20:21 UTC (rev 164)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/component/MiddleSimpleComponentMapper.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -19,7 +19,8 @@
}
@SuppressWarnings({"unchecked"})
- public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map<String, Object> data, Number revision) {
+ public Object mapToObjectFromFullMap(EntityInstantiator entityInstantiator, Map<String, Object> data,
+ Object dataObject, Number revision) {
return ((Map<String, Object>) data.get(verEntCfg.getOriginalIdPropName())).get(propertyName);
}
Modified: 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 2008-09-22 21:20:21 UTC (rev 164)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ArrayCollectionInitializor.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -35,11 +35,11 @@
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);
+ (Map<String, Object>) elementData, null, revision);
Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
- (Map<String, Object>) indexData, revision);
+ (Map<String, Object>) indexData, element, revision);
int index = ((Number) indexObj).intValue();
collection[index] = element;
Modified: 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 2008-09-22 21:20:21 UTC (rev 164)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -42,7 +42,7 @@
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);
+ (Map<String, Object>) elementData, null, revision);
collection.add(element);
}
}
Modified: 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 2008-09-22 21:20:21 UTC (rev 164)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/ListCollectionInitializor.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -35,11 +35,11 @@
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);
+ (Map<String, Object>) elementData, null, revision);
Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
- (Map<String, Object>) indexData, revision);
+ (Map<String, Object>) indexData, element, revision);
int index = ((Number) indexObj).intValue();
collection.set(index, element);
Modified: 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 2008-09-22 21:20:21 UTC (rev 164)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/lazy/initializor/MapCollectionInitializor.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -45,11 +45,11 @@
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);
+ (Map<String, Object>) elementData, null, revision);
Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
Object index = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
- (Map<String, Object>) indexData, revision);
+ (Map<String, Object>) indexData, element, revision);
collection.put(index, element);
}
Copied: trunk/src/test/org/jboss/envers/test/entities/components/Component1.java (from rev 148, trunk/src/test/org/jboss/envers/test/integration/components/Component1.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/components/Component1.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/components/Component1.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -0,0 +1,57 @@
+package org.jboss.envers.test.entities.components;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class Component1 {
+ private String str1;
+
+ private String str2;
+
+ public Component1(String str1, String str2) {
+ this.str1 = str1;
+ this.str2 = str2;
+ }
+
+ public Component1() {
+ }
+
+ public String getStr2() {
+ return str2;
+ }
+
+ public void setStr2(String str2) {
+ this.str2 = str2;
+ }
+
+ public String getStr1() {
+ return str1;
+ }
+
+ public void setStr1(String str1) {
+ this.str1 = str1;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Component1)) return false;
+
+ Component1 that = (Component1) o;
+
+ if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false;
+ if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (str1 != null ? str1.hashCode() : 0);
+ result = 31 * result + (str2 != null ? str2.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "Comp1(str1 = " + str1 + ", " + str2 + ")";
+ }
+}
Copied: trunk/src/test/org/jboss/envers/test/entities/components/Component2.java (from rev 148, trunk/src/test/org/jboss/envers/test/integration/components/Component2.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/components/Component2.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/components/Component2.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -0,0 +1,57 @@
+package org.jboss.envers.test.entities.components;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class Component2 {
+ private String str5;
+
+ private String str6;
+
+ public Component2(String str5, String str6) {
+ this.str5 = str5;
+ this.str6 = str6;
+ }
+
+ public Component2() {
+ }
+
+ public String getStr5() {
+ return str5;
+ }
+
+ public void setStr5(String str5) {
+ this.str5 = str5;
+ }
+
+ public String getStr6() {
+ return str6;
+ }
+
+ public void setStr6(String str6) {
+ this.str6 = str6;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Component2)) return false;
+
+ Component2 that = (Component2) o;
+
+ if (str5 != null ? !str5.equals(that.str5) : that.str5 != null) return false;
+ if (str6 != null ? !str6.equals(that.str6) : that.str6 != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (str5 != null ? str5.hashCode() : 0);
+ result = 31 * result + (str6 != null ? str6.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "Comp2(str1 = " + str5 + ", " + str6 + ")";
+ }
+}
Copied: trunk/src/test/org/jboss/envers/test/entities/components/ComponentTestEntity.java (from rev 148, trunk/src/test/org/jboss/envers/test/integration/components/ComponentTestEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/components/ComponentTestEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/components/ComponentTestEntity.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -0,0 +1,89 @@
+package org.jboss.envers.test.entities.components;
+
+import org.jboss.envers.Versioned;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Embedded;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class ComponentTestEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Embedded
+ @Versioned
+ private Component1 comp1;
+
+ @Embedded
+ private Component2 comp2;
+
+ public ComponentTestEntity() {
+ }
+
+ public ComponentTestEntity(Integer id, Component1 comp1, Component2 comp2) {
+ this.id = id;
+ this.comp1 = comp1;
+ this.comp2 = comp2;
+ }
+
+ public ComponentTestEntity(Component1 comp1, Component2 comp2) {
+ this.comp1 = comp1;
+ this.comp2 = comp2;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Component1 getComp1() {
+ return comp1;
+ }
+
+ public void setComp1(Component1 comp1) {
+ this.comp1 = comp1;
+ }
+
+ public Component2 getComp2() {
+ return comp2;
+ }
+
+ public void setComp2(Component2 comp2) {
+ this.comp2 = comp2;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ComponentTestEntity)) return false;
+
+ ComponentTestEntity that = (ComponentTestEntity) o;
+
+ if (comp1 != null ? !comp1.equals(that.comp1) : that.comp1 != null) return false;
+ if (comp2 != null ? !comp2.equals(that.comp2) : that.comp2 != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (comp1 != null ? comp1.hashCode() : 0);
+ result = 31 * result + (comp2 != null ? comp2.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "CTE(id = " + id + ", comp1 = " + comp1 + ", comp2 = " + comp2 + ")";
+ }
+}
+
Added: trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/ComponentMapKey.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/ComponentMapKey.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/ComponentMapKey.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -0,0 +1,88 @@
+package org.jboss.envers.test.integration.collection.mapkey;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.tools.TestTools;
+import org.jboss.envers.test.entities.components.ComponentTestEntity;
+import org.jboss.envers.test.entities.components.Component1;
+import org.jboss.envers.test.entities.components.Component2;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.hibernate.ejb.Ejb3Configuration;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ComponentMapKey extends AbstractEntityTest {
+ private Integer cmke_id;
+
+ private Integer cte1_id;
+ private Integer cte2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ComponentMapKeyEntity.class);
+ cfg.addAnnotatedClass(ComponentTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ ComponentMapKeyEntity imke = new ComponentMapKeyEntity();
+
+ // Revision 1 (intialy 1 mapping)
+ em.getTransaction().begin();
+
+ ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("x1", "y2"), new Component2("a1", "b2"));
+ ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("x1", "y2"), new Component2("a1", "b2"));
+
+ em.persist(cte1);
+ em.persist(cte2);
+
+ imke.getIdmap().put(cte1.getComp1(), cte1);
+
+ em.persist(imke);
+
+ em.getTransaction().commit();
+
+ // Revision 2 (sse1: adding 1 mapping)
+ em.getTransaction().begin();
+
+ cte2 = em.find(ComponentTestEntity.class, cte2.getId());
+ imke = em.find(ComponentMapKeyEntity.class, imke.getId());
+
+ imke.getIdmap().put(cte2.getComp1(), cte2);
+
+ em.getTransaction().commit();
+
+ //
+
+ cmke_id = imke.getId();
+
+ cte1_id = cte1.getId();
+ cte2_id = cte2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getVersionsReader().getRevisions(ComponentMapKeyEntity.class, cmke_id));
+ }
+
+ @Test
+ public void testHistoryOfImke() {
+ ComponentTestEntity cte1 = getEntityManager().find(ComponentTestEntity.class, cte1_id);
+ ComponentTestEntity cte2 = getEntityManager().find(ComponentTestEntity.class, cte2_id);
+
+ // These fields are unversioned.
+ cte1.setComp2(null);
+ cte2.setComp2(null);
+
+ ComponentMapKeyEntity rev1 = getVersionsReader().find(ComponentMapKeyEntity.class, cmke_id, 1);
+ ComponentMapKeyEntity rev2 = getVersionsReader().find(ComponentMapKeyEntity.class, cmke_id, 2);
+
+ assert rev1.getIdmap().equals(TestTools.makeMap(cte1.getComp1(), cte1));
+ assert rev2.getIdmap().equals(TestTools.makeMap(cte1.getComp1(), cte1, cte2.getComp1(), cte2));
+ }
+}
\ No newline at end of file
Added: trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/ComponentMapKeyEntity.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/ComponentMapKeyEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/ComponentMapKeyEntity.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -0,0 +1,63 @@
+package org.jboss.envers.test.integration.collection.mapkey;
+
+import org.jboss.envers.Versioned;
+import org.jboss.envers.test.entities.components.Component1;
+import org.jboss.envers.test.entities.components.ComponentTestEntity;
+
+import javax.persistence.*;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class ComponentMapKeyEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Versioned
+ @ManyToMany
+ @MapKey(name = "comp1")
+ private Map<Component1, ComponentTestEntity> idmap;
+
+ public ComponentMapKeyEntity() {
+ idmap = new HashMap<Component1, ComponentTestEntity>();
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Map<Component1, ComponentTestEntity> getIdmap() {
+ return idmap;
+ }
+
+ public void setIdmap(Map<Component1, ComponentTestEntity> idmap) {
+ this.idmap = idmap;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ComponentMapKeyEntity)) return false;
+
+ ComponentMapKeyEntity that = (ComponentMapKeyEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return (id != null ? id.hashCode() : 0);
+ }
+
+ public String toString() {
+ return "CMKE(id = " + id + ", idmap = " + idmap + ")";
+ }
+}
\ No newline at end of file
Copied: trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKey.java (from rev 154, trunk/src/test/org/jboss/envers/test/integration/collection/StringSet.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKey.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKey.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -0,0 +1,83 @@
+package org.jboss.envers.test.integration.collection.mapkey;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.tools.TestTools;
+import org.jboss.envers.test.entities.StrTestEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.hibernate.ejb.Ejb3Configuration;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class IdMapKey extends AbstractEntityTest {
+ private Integer imke_id;
+
+ private Integer ste1_id;
+ private Integer ste2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(IdMapKeyEntity.class);
+ cfg.addAnnotatedClass(StrTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ IdMapKeyEntity imke = new IdMapKeyEntity();
+
+ // Revision 1 (intialy 1 mapping)
+ em.getTransaction().begin();
+
+ StrTestEntity ste1 = new StrTestEntity("x");
+ StrTestEntity ste2 = new StrTestEntity("y");
+
+ em.persist(ste1);
+ em.persist(ste2);
+
+ imke.getIdmap().put(ste1.getId(), ste1);
+
+ em.persist(imke);
+
+ em.getTransaction().commit();
+
+ // Revision 2 (sse1: adding 1 mapping)
+ em.getTransaction().begin();
+
+ ste2 = em.find(StrTestEntity.class, ste2.getId());
+ imke = em.find(IdMapKeyEntity.class, imke.getId());
+
+ imke.getIdmap().put(ste2.getId(), ste2);
+
+ em.getTransaction().commit();
+
+ //
+
+ imke_id = imke.getId();
+
+ ste1_id = ste1.getId();
+ ste2_id = ste2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getVersionsReader().getRevisions(IdMapKeyEntity.class, imke_id));
+ }
+
+ @Test
+ public void testHistoryOfImke() {
+ StrTestEntity ste1 = getEntityManager().find(StrTestEntity.class, ste1_id);
+ StrTestEntity ste2 = getEntityManager().find(StrTestEntity.class, ste2_id);
+
+ IdMapKeyEntity rev1 = getVersionsReader().find(IdMapKeyEntity.class, imke_id, 1);
+ IdMapKeyEntity rev2 = getVersionsReader().find(IdMapKeyEntity.class, imke_id, 2);
+
+ System.out.println(rev1.getIdmap());
+ assert rev1.getIdmap().equals(TestTools.makeMap(ste1.getId(), ste1));
+ assert rev2.getIdmap().equals(TestTools.makeMap(ste1.getId(), ste1, ste2.getId(), ste2));
+ }
+}
\ No newline at end of file
Copied: trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKeyEntity.java (from rev 148, trunk/src/test/org/jboss/envers/test/entities/StrIntTestEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKeyEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKeyEntity.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -0,0 +1,62 @@
+package org.jboss.envers.test.integration.collection.mapkey;
+
+import org.jboss.envers.Versioned;
+import org.jboss.envers.test.entities.StrTestEntity;
+
+import javax.persistence.*;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class IdMapKeyEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Versioned
+ @ManyToMany
+ @MapKey
+ private Map<Integer, StrTestEntity> idmap;
+
+ public IdMapKeyEntity() {
+ idmap = new HashMap<Integer, StrTestEntity>();
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Map<Integer, StrTestEntity> getIdmap() {
+ return idmap;
+ }
+
+ public void setIdmap(Map<Integer, StrTestEntity> idmap) {
+ this.idmap = idmap;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof IdMapKeyEntity)) return false;
+
+ IdMapKeyEntity that = (IdMapKeyEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return (id != null ? id.hashCode() : 0);
+ }
+
+ public String toString() {
+ return "IMKE(id = " + id + ", idmap = " + idmap + ")";
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/integration/collection/mapkey/IdMapKeyEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/src/test/org/jboss/envers/test/integration/components/Components.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/components/Components.java 2008-09-22 21:20:21 UTC (rev 164)
+++ trunk/src/test/org/jboss/envers/test/integration/components/Components.java 2008-09-23 17:05:36 UTC (rev 165)
@@ -1,6 +1,9 @@
package org.jboss.envers.test.integration.components;
import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.components.Component1;
+import org.jboss.envers.test.entities.components.Component2;
+import org.jboss.envers.test.entities.components.ComponentTestEntity;
import org.hibernate.ejb.Ejb3Configuration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
16 years, 3 months
JBoss Envers SVN: r164 - in trunk: src/main/org/jboss/envers/configuration and 5 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-22 17:20:21 -0400 (Mon, 22 Sep 2008)
New Revision: 164
Removed:
trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneNotOwningIdMapper.java
Modified:
trunk/envers.iml
trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java
trunk/src/main/org/jboss/envers/tools/ArraysTools.java
trunk/src/main/org/jboss/envers/tools/MutableBoolean.java
trunk/src/main/org/jboss/envers/tools/MutableInteger.java
trunk/src/main/org/jboss/envers/tools/Pair.java
trunk/src/main/org/jboss/envers/tools/Triple.java
Log:
Removing dead code
Modified: trunk/envers.iml
===================================================================
--- trunk/envers.iml 2008-09-22 20:30:29 UTC (rev 163)
+++ trunk/envers.iml 2008-09-22 21:20:21 UTC (rev 164)
@@ -51,6 +51,7 @@
</orderEntry>
<orderEntry type="library" name="hibernate-common" level="project" />
<orderEntry type="library" name="hibernate-3.2.6" level="project" />
+ <orderEntry type="library" name="Clover IDEA Plugin" level="application" />
<orderEntryProperties />
</component>
</module>
Modified: trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-09-22 20:30:29 UTC (rev 163)
+++ trunk/src/main/org/jboss/envers/configuration/EntitiesConfigurator.java 2008-09-22 21:20:21 UTC (rev 164)
@@ -95,12 +95,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/VersionsEntitiesConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-09-22 20:30:29 UTC (rev 163)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-09-22 21:20:21 UTC (rev 164)
@@ -97,15 +97,6 @@
return versionsTablePrefix + entityName + versionsTableSuffix;
}
- public boolean isVersionsEntityName(String entityName) {
- if (entityName == null) {
- return false;
- }
-
- return entityName.endsWith(versionsTableSuffix) &&
- entityName.startsWith(versionsTablePrefix);
- }
-
public String getVersionsTableName(String entityName, String tableName) {
String customHistoryTableName = customVersionsTablesNames.get(entityName);
if (customHistoryTableName == null) {
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-22 20:30:29 UTC (rev 163)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-09-22 21:20:21 UTC (rev 164)
@@ -190,7 +190,7 @@
mappedBy = getMappedBy(propertyValue.getCollectionTable(), mainGenerator.getCfg().getClassMapping(referencedEntityName));
referencingPrefixRelated = mappedBy + "_";
- referencedPrefix = referencedEntityName == null ? "element" : StringTools.getLastComponent(referencedEntityName);
+ referencedPrefix = StringTools.getLastComponent(referencedEntityName);
} else {
mappedBy = null;
Modified: trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-09-22 20:30:29 UTC (rev 163)
+++ trunk/src/main/org/jboss/envers/entities/EntityConfiguration.java 2008-09-22 21:20:21 UTC (rev 164)
@@ -97,10 +97,6 @@
return propertyMapper;
}
- public String getEntityName() {
- return entityName;
- }
-
// For use by EntitiesConfigurations
String getParentEntityName() {
Modified: trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java 2008-09-22 20:30:29 UTC (rev 163)
+++ trunk/src/main/org/jboss/envers/entities/mapper/SinglePropertyMapper.java 2008-09-22 21:20:21 UTC (rev 164)
@@ -41,10 +41,6 @@
public class SinglePropertyMapper implements PropertyMapper, SimpleMapperBuilder {
private String propertyName;
- public SinglePropertyMapper(String propertyName, ModificationStore modStore) {
- this.propertyName = propertyName;
- }
-
public SinglePropertyMapper() { }
public void add(String propertyName, ModificationStore modStore) {
Deleted: trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneNotOwningIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneNotOwningIdMapper.java 2008-09-22 20:30:29 UTC (rev 163)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/OneToOneNotOwningIdMapper.java 2008-09-22 21:20:21 UTC (rev 164)
@@ -1,87 +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;
-
-import org.jboss.envers.entities.mapper.PropertyMapper;
-import org.jboss.envers.entities.mapper.PersistentCollectionChangeData;
-import org.jboss.envers.reader.VersionsReaderImplementor;
-import org.jboss.envers.tools.reflection.ReflectionTools;
-import org.jboss.envers.query.VersionsRestrictions;
-import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.configuration.VersionsConfiguration;
-import org.hibernate.property.Setter;
-import org.hibernate.NonUniqueResultException;
-import org.hibernate.collection.PersistentCollection;
-
-import javax.persistence.NoResultException;
-import java.util.Map;
-import java.util.List;
-import java.io.Serializable;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class OneToOneNotOwningIdMapper implements PropertyMapper {
- private String owningReferencePropertyName;
- private String owningEntityName;
- private String propertyName;
-
- public OneToOneNotOwningIdMapper(String owningReferencePropertyName, String owningEntityName, String propertyName) {
- this.owningReferencePropertyName = owningReferencePropertyName;
- this.owningEntityName = owningEntityName;
- this.propertyName = propertyName;
- }
-
- public boolean mapToMapFromEntity(Map<String, Object> data, Object newObj, Object oldObj) {
- return false;
- }
-
- public void mapToEntityFromMap(VersionsConfiguration verCfg, Object obj, Map data, Object primaryKey, VersionsReaderImplementor versionsReader, Number revision) {
- if (obj == null) {
- return;
- }
-
- Class<?> entityClass = ReflectionTools.loadClass(owningEntityName);
-
- Object value;
-
- try {
- value = versionsReader.createQuery().forEntitiesAtRevision(entityClass, revision)
- .add(VersionsRestrictions.relatedIdEq(owningReferencePropertyName, primaryKey)).getSingleResult();
- } catch (NoResultException e) {
- value = null;
- } catch (NonUniqueResultException e) {
- throw new VersionsException("Many versions results for one-to-one relationship: (" + owningEntityName +
- ", " + owningReferencePropertyName + ")");
- }
-
- Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyName);
- setter.set(obj, value, null);
- }
-
- public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
- PersistentCollection newColl,
- Serializable oldColl,
- Serializable id) {
- return null;
- }
-}
Modified: trunk/src/main/org/jboss/envers/tools/ArraysTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/ArraysTools.java 2008-09-22 20:30:29 UTC (rev 163)
+++ trunk/src/main/org/jboss/envers/tools/ArraysTools.java 2008-09-22 21:20:21 UTC (rev 164)
@@ -34,16 +34,4 @@
return false;
}
-
- public static <T> int indexInArray(T[] array, T object) {
- if (array != null) {
- for (int i=0; i<array.length; i++) {
- if (Tools.objectsEqual(array[i], object)) {
- return i;
- }
- }
- }
-
- return -1;
- }
}
Modified: trunk/src/main/org/jboss/envers/tools/MutableBoolean.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/MutableBoolean.java 2008-09-22 20:30:29 UTC (rev 163)
+++ trunk/src/main/org/jboss/envers/tools/MutableBoolean.java 2008-09-22 21:20:21 UTC (rev 164)
@@ -45,8 +45,4 @@
public void unset() {
value = false;
}
-
- public void setTo(boolean value) {
- this.value = value;
- }
}
Modified: trunk/src/main/org/jboss/envers/tools/MutableInteger.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/MutableInteger.java 2008-09-22 20:30:29 UTC (rev 163)
+++ trunk/src/main/org/jboss/envers/tools/MutableInteger.java 2008-09-22 21:20:21 UTC (rev 164)
@@ -30,18 +30,6 @@
public MutableInteger() {
}
- public MutableInteger(int value) {
- this.value = value;
- }
-
- public int get() {
- return value;
- }
-
- public void set(int value) {
- this.value = value;
- }
-
public int getAndIncrease() {
return value++;
}
Modified: trunk/src/main/org/jboss/envers/tools/Pair.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/Pair.java 2008-09-22 20:30:29 UTC (rev 163)
+++ trunk/src/main/org/jboss/envers/tools/Pair.java 2008-09-22 21:20:21 UTC (rev 164)
@@ -31,9 +31,6 @@
private T1 obj1;
private T2 obj2;
- public Pair() {
- }
-
public Pair(T1 obj1, T2 obj2) {
this.obj1 = obj1;
this.obj2 = obj2;
@@ -47,14 +44,6 @@
return obj2;
}
- public void setFirst(T1 obj1) {
- this.obj1 = obj1;
- }
-
- public void setSecond(T2 obj2) {
- this.obj2 = obj2;
- }
-
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Pair)) return false;
Modified: trunk/src/main/org/jboss/envers/tools/Triple.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/Triple.java 2008-09-22 20:30:29 UTC (rev 163)
+++ trunk/src/main/org/jboss/envers/tools/Triple.java 2008-09-22 21:20:21 UTC (rev 164)
@@ -33,9 +33,6 @@
private T2 obj2;
private T3 obj3;
- public Triple() {
- }
-
public Triple(T1 obj1, T2 obj2, T3 obj3) {
this.obj1 = obj1;
this.obj2 = obj2;
@@ -54,18 +51,6 @@
return obj3;
}
- public void setFirst(T1 obj1) {
- this.obj1 = obj1;
- }
-
- public void setSecond(T2 obj2) {
- this.obj2 = obj2;
- }
-
- public void setThird(T3 obj3) {
- this.obj3 = obj3;
- }
-
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Triple)) return false;
16 years, 3 months
JBoss Envers SVN: r163 - in trunk: src/main/org/jboss/envers/configuration/metadata and 4 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-22 16:30:29 -0400 (Mon, 22 Sep 2008)
New Revision: 163
Added:
trunk/src/test/org/jboss/envers/test/entities/customtype/
trunk/src/test/org/jboss/envers/test/entities/customtype/Component.java
trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeCustomTypeEntity.java
trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeTestUserType.java
trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedCustomTypeEntity.java
trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedTestUserType.java
trunk/src/test/org/jboss/envers/test/integration/customtype/
trunk/src/test/org/jboss/envers/test/integration/customtype/CompositeCustom.java
trunk/src/test/org/jboss/envers/test/integration/customtype/ParametrizedCustom.java
Modified:
trunk/resources/test/testng.xml
trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java
Log:
ENVERS-49: custom user type support
Modified: trunk/resources/test/testng.xml
===================================================================
--- trunk/resources/test/testng.xml 2008-09-22 18:07:02 UTC (rev 162)
+++ trunk/resources/test/testng.xml 2008-09-22 20:30:29 UTC (rev 163)
@@ -6,6 +6,7 @@
<package name="org.jboss.envers.test.integration.basic" />
<package name="org.jboss.envers.test.integration.collection" />
<package name="org.jboss.envers.test.integration.components" />
+ <package name="org.jboss.envers.test.integration.customtype" />
<package name="org.jboss.envers.test.integration.data" />
<package name="org.jboss.envers.test.integration.flush" />
<package name="org.jboss.envers.test.integration.ids" />
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java 2008-09-22 18:07:02 UTC (rev 162)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java 2008-09-22 20:30:29 UTC (rev 163)
@@ -1,10 +1,7 @@
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.mapping.*;
import org.hibernate.type.*;
import org.hibernate.util.StringHelper;
import org.jboss.envers.entities.mapper.SimpleMapperBuilder;
@@ -12,6 +9,7 @@
import org.jboss.envers.ModificationStore;
import java.util.Iterator;
+import java.util.Properties;
/**
* Generates metadata for basic properties: immutable types (including enums) and components
@@ -19,40 +17,25 @@
*/
public final class BasicMetadataGenerator {
boolean addBasic(Element parent, String name, Value value, CompositeMapperBuilder mapper,
- ModificationStore store, String entityName, boolean key) {
+ ModificationStore store, String entityName, boolean key) {
Type type = value.getType();
if (type instanceof ComponentType) {
addComponent(parent, name, value, mapper, entityName, key);
- } else if (type instanceof ImmutableType || type instanceof MutableType) {
- addSimpleValue(parent, name, value, mapper, store, key);
- } else if (type instanceof CustomType && "org.hibernate.type.EnumType".equals(type.getName())) {
- addEnumValue(parent, name, value, mapper, store, key);
- } else if (type instanceof CustomType &&
- ("org.hibernate.type.PrimitiveCharacterArrayClobType".equals(type.getName()) ||
- "org.hibernate.type.StringClobType".equals(type.getName()))) {
- addSimpleValue(parent, name, value, mapper, store, key);
- } else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName())) {
- addSimpleValue(parent, name, value, mapper, store, key);
+ return true;
} else {
- return false;
+ return addBasicNoComponent(parent, name, value, mapper, store, key);
}
-
- return true;
}
boolean addBasicNoComponent(Element parent, String name, Value value, SimpleMapperBuilder mapper,
- ModificationStore store, boolean key) {
+ ModificationStore store, boolean key) {
Type type = value.getType();
if (type instanceof ImmutableType || type instanceof MutableType) {
addSimpleValue(parent, name, value, mapper, store, key);
- } else if (type instanceof CustomType && "org.hibernate.type.EnumType".equals(type.getName())) {
- addEnumValue(parent, name, value, mapper, store, key);
- } else if (type instanceof CustomType &&
- ("org.hibernate.type.PrimitiveCharacterArrayClobType".equals(type.getName()) ||
- "org.hibernate.type.StringClobType".equals(type.getName()))) {
- addSimpleValue(parent, name, value, mapper, store, key);
+ } else if (type instanceof CustomType || type instanceof CompositeCustomType) {
+ addCustomValue(parent, name, value, mapper, store, key);
} else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName())) {
addSimpleValue(parent, name, value, mapper, store, key);
} else {
@@ -64,7 +47,7 @@
@SuppressWarnings({"unchecked"})
private void addSimpleValue(Element parent, String name, Value value, SimpleMapperBuilder mapper,
- ModificationStore store, boolean key) {
+ ModificationStore store, boolean key) {
if (parent != null) {
Element prop_mapping = MetadataTools.addProperty(parent, name,
value.getType().getName(), key);
@@ -78,25 +61,28 @@
}
@SuppressWarnings({"unchecked"})
- private void addEnumValue(Element parent, String name, Value value, SimpleMapperBuilder mapper,
- ModificationStore store, boolean key) {
+ private void addCustomValue(Element parent, String name, Value value, SimpleMapperBuilder mapper,
+ ModificationStore store, boolean key) {
if (parent != null) {
Element prop_mapping = MetadataTools.addProperty(parent, name,
null, key);
- CustomType propertyType = (CustomType) value.getType();
+ //CustomType propertyType = (CustomType) value.getType();
Element type_mapping = prop_mapping.addElement("type");
- type_mapping.addAttribute("name", propertyType.getName());
+ type_mapping.addAttribute("name", value.getType().getName());
- Element type_param1 = type_mapping.addElement("param");
- type_param1.addAttribute("name", "enumClass");
- type_param1.setText(propertyType.getReturnedClass().getName());
+ if (value instanceof SimpleValue) {
+ Properties typeParameters = ((SimpleValue) value).getTypeParameters();
+ if (typeParameters != null) {
+ for (java.util.Map.Entry paramKeyValue : typeParameters.entrySet()) {
+ Element type_param = type_mapping.addElement("param");
+ type_param.addAttribute("name", (String) paramKeyValue.getKey());
+ type_param.setText((String) paramKeyValue.getValue());
+ }
+ }
+ }
- 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());
}
@@ -113,7 +99,7 @@
@SuppressWarnings({"unchecked"})
private void addComponent(Element parent, String name, Value value, CompositeMapperBuilder mapper,
- String entityName, boolean key) {
+ String entityName, boolean key) {
Element component_mapping = null;
Component prop_component = (Component) value;
Added: trunk/src/test/org/jboss/envers/test/entities/customtype/Component.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/customtype/Component.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/customtype/Component.java 2008-09-22 20:30:29 UTC (rev 163)
@@ -0,0 +1,54 @@
+package org.jboss.envers.test.entities.customtype;
+
+import java.io.Serializable;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class Component implements Serializable {
+ private String prop1;
+ private int prop2;
+
+ public Component(String prop1, int prop2) {
+ this.prop1 = prop1;
+ this.prop2 = prop2;
+ }
+
+ public Component() {
+ }
+
+ public String getProp1() {
+ return prop1;
+ }
+
+ public void setProp1(String prop1) {
+ this.prop1 = prop1;
+ }
+
+ public int getProp2() {
+ return prop2;
+ }
+
+ public void setProp2(int prop2) {
+ this.prop2 = prop2;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Component)) return false;
+
+ Component that = (Component) o;
+
+ if (prop2 != that.prop2) return false;
+ if (prop1 != null ? !prop1.equals(that.prop1) : that.prop1 != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (prop1 != null ? prop1.hashCode() : 0);
+ result = 31 * result + prop2;
+ return result;
+ }
+}
Added: trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeCustomTypeEntity.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeCustomTypeEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeCustomTypeEntity.java 2008-09-22 20:30:29 UTC (rev 163)
@@ -0,0 +1,74 @@
+package org.jboss.envers.test.entities.customtype;
+
+import org.jboss.envers.Versioned;
+import org.hibernate.annotations.TypeDef;
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.Columns;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Column;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@TypeDef(name = "comp", typeClass = CompositeTestUserType.class)
+public class CompositeCustomTypeEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Versioned
+ @Type(type = "comp")
+ @Columns(columns = { @Column(name = "str"), @Column(name = "num") })
+ private Component component;
+
+ public CompositeCustomTypeEntity() {
+ }
+
+ public CompositeCustomTypeEntity(Integer id, Component component) {
+ this.id = id;
+ this.component = component;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Component getComponent() {
+ return component;
+ }
+
+ public void setComponent(Component component) {
+ this.component = component;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof CompositeCustomTypeEntity)) return false;
+
+ CompositeCustomTypeEntity that = (CompositeCustomTypeEntity) o;
+
+ if (component != null ? !component.equals(that.component) : that.component != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (component != null ? component.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "CCTE(id = " + id + ", component = " + component + ")";
+ }
+}
Added: trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeTestUserType.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeTestUserType.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeTestUserType.java 2008-09-22 20:30:29 UTC (rev 163)
@@ -0,0 +1,117 @@
+package org.jboss.envers.test.entities.customtype;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Hibernate;
+import org.hibernate.usertype.CompositeUserType;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.type.Type;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.PreparedStatement;
+import java.io.Serializable;
+
+/**
+ * @author Andrew DePue
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class CompositeTestUserType implements CompositeUserType {
+ public String[] getPropertyNames() {
+ return new String[] { "prop1", "prop2" };
+ }
+
+ public Type[] getPropertyTypes() {
+ return new Type[] { Hibernate.STRING, Hibernate.INTEGER };
+ }
+
+ public Object getPropertyValue(final Object component, final int property) throws HibernateException {
+ Component comp = (Component) component;
+ if (property == 0) {
+ return comp.getProp1();
+ } else {
+ return comp.getProp2();
+ }
+ }
+
+ public void setPropertyValue(final Object component, final int property, final Object value) throws HibernateException {
+ Component comp = (Component) component;
+ if (property == 0) {
+ comp.setProp1((String) value);
+ } else {
+ comp.setProp2((Integer) value);
+ }
+ }
+
+ public Class returnedClass() {
+ return Component.class;
+ }
+
+ public boolean equals(final Object x, final Object y) throws HibernateException {
+ //noinspection ObjectEquality
+ if (x == y) {
+ return true;
+ }
+
+ if (x == null || y == null) {
+ return false;
+ }
+
+ return x.equals(y);
+ }
+
+ public int hashCode(final Object x) throws HibernateException {
+ return x.hashCode();
+ }
+
+ public Object nullSafeGet(final ResultSet rs, final String[] names,
+ final SessionImplementor session,
+ final Object owner) throws HibernateException, SQLException {
+ if (rs.wasNull()) {
+ return null;
+ }
+ final String prop1 = rs.getString(names[0]);
+ if (prop1 == null) {
+ return null;
+ }
+ final int prop2 = rs.getInt(names[1]);
+
+ return new Component(prop1, prop2);
+ }
+
+ public void nullSafeSet(final PreparedStatement st, final Object value,
+ final int index, final SessionImplementor session)
+ throws HibernateException, SQLException
+ {
+ if (value == null) {
+ st.setNull(index, Hibernate.STRING.sqlType());
+ st.setNull(index + 1, Hibernate.INTEGER.sqlType());
+ } else {
+ final Component comp = (Component) value;
+ st.setString(index, comp.getProp1());
+ st.setInt(index + 1, comp.getProp2());
+ }
+ }
+
+ public Object deepCopy(final Object value) throws HibernateException {
+ Component comp = (Component) value;
+ return new Component(comp.getProp1(), comp.getProp2());
+ }
+
+ public boolean isMutable() {
+ return true;
+ }
+
+ public Serializable disassemble(final Object value, final SessionImplementor session) throws HibernateException {
+ return (Serializable) value;
+ }
+
+ public Object assemble(final Serializable cached, final SessionImplementor session,
+ final Object owner) throws HibernateException {
+ return cached;
+ }
+
+ public Object replace(Object original, Object target,
+ SessionImplementor session, Object owner) throws HibernateException {
+ return original;
+ }
+}
\ No newline at end of file
Added: trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedCustomTypeEntity.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedCustomTypeEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedCustomTypeEntity.java 2008-09-22 20:30:29 UTC (rev 163)
@@ -0,0 +1,73 @@
+package org.jboss.envers.test.entities.customtype;
+
+import org.jboss.envers.Versioned;
+import org.hibernate.annotations.TypeDef;
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.Parameter;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@TypeDef(name = "param", typeClass = ParametrizedTestUserType.class,
+ parameters = { @Parameter(name="param1", value = "x"), @Parameter(name="param2", value = "y") })
+public class ParametrizedCustomTypeEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Versioned
+ @Type(type = "param")
+ private String str;
+
+ public ParametrizedCustomTypeEntity() {
+ }
+
+ public ParametrizedCustomTypeEntity(Integer id, String str) {
+ this.id = id;
+ this.str = str;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getStr() {
+ return str;
+ }
+
+ public void setStr(String str) {
+ this.str = str;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ParametrizedCustomTypeEntity)) return false;
+
+ ParametrizedCustomTypeEntity that = (ParametrizedCustomTypeEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+ if (str != null ? !str.equals(that.str) : that.str != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (str != null ? str.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "PCTE(id = " + id + ", str = " + str + ")";
+ }
+}
\ No newline at end of file
Added: trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedTestUserType.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedTestUserType.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedTestUserType.java 2008-09-22 20:30:29 UTC (rev 163)
@@ -0,0 +1,92 @@
+package org.jboss.envers.test.entities.customtype;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Hibernate;
+import org.hibernate.usertype.ParameterizedType;
+import org.hibernate.usertype.UserType;
+import org.hsqldb.Types;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ParametrizedTestUserType implements UserType, ParameterizedType {
+ private static final int[] TYPES = new int[] { Types.VARCHAR };
+
+ private String param1;
+ private String param2;
+
+ public void setParameterValues(Properties parameters) {
+ param1 = parameters.getProperty("param1");
+ param2 = parameters.getProperty("param2");
+ }
+
+ public Class returnedClass() {
+ return String.class;
+ }
+
+ public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
+ return Hibernate.STRING.nullSafeGet(rs, names[0]);
+ }
+
+ public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
+ if (value != null) {
+ String v = (String) value;
+ if (!v.startsWith(param1)) {
+ v = param1 + v;
+ }
+ if (!v.endsWith(param2)) {
+ v = v + param2;
+ }
+ Hibernate.STRING.nullSafeSet(st, v, index);
+ } else {
+ Hibernate.STRING.nullSafeSet(st, value, index);
+ }
+ }
+
+ public int[] sqlTypes() {
+ return TYPES;
+ }
+
+ public Object assemble(Serializable cached, Object owner) throws HibernateException {
+ return cached;
+ }
+
+ public Object deepCopy(Object value) throws HibernateException {
+ return value;
+ }
+
+ public Serializable disassemble(Object value) throws HibernateException {
+ return (Serializable) value;
+ }
+
+ public boolean equals(Object x, Object y) throws HibernateException {
+ //noinspection ObjectEquality
+ if (x == y) {
+ return true;
+ }
+
+ if (x == null || y == null) {
+ return false;
+ }
+
+ return x.equals(y);
+ }
+
+ public int hashCode(Object x) throws HibernateException {
+ return x.hashCode();
+ }
+
+ public boolean isMutable() {
+ return false;
+ }
+
+ public Object replace(Object original, Object target, Object owner) throws HibernateException {
+ return original;
+ }
+}
Copied: trunk/src/test/org/jboss/envers/test/integration/customtype/CompositeCustom.java (from rev 154, trunk/src/test/org/jboss/envers/test/integration/collection/StringSet.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/customtype/CompositeCustom.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/customtype/CompositeCustom.java 2008-09-22 20:30:29 UTC (rev 163)
@@ -0,0 +1,76 @@
+package org.jboss.envers.test.integration.customtype;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.customtype.CompositeCustomTypeEntity;
+import org.jboss.envers.test.entities.customtype.Component;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.hibernate.ejb.Ejb3Configuration;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class CompositeCustom extends AbstractEntityTest {
+ private Integer ccte_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(CompositeCustomTypeEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ CompositeCustomTypeEntity ccte = new CompositeCustomTypeEntity();
+
+ // Revision 1 (persisting 1 entity)
+ em.getTransaction().begin();
+
+ ccte.setComponent(new Component("a", 1));
+
+ em.persist(ccte);
+
+ em.getTransaction().commit();
+
+ // Revision 2 (changing the component)
+ em.getTransaction().begin();
+
+ ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId());
+
+ ccte.getComponent().setProp1("b");
+
+ em.getTransaction().commit();
+
+ // Revision 3 (replacing the component)
+ em.getTransaction().begin();
+
+ ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId());
+
+ ccte.setComponent(new Component("c", 3));
+
+ em.getTransaction().commit();
+
+ //
+
+ ccte_id = ccte.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 3).equals(getVersionsReader().getRevisions(CompositeCustomTypeEntity.class, ccte_id));
+ }
+
+ @Test
+ public void testHistoryOfCcte() {
+ CompositeCustomTypeEntity rev1 = getVersionsReader().find(CompositeCustomTypeEntity.class, ccte_id, 1);
+ CompositeCustomTypeEntity rev2 = getVersionsReader().find(CompositeCustomTypeEntity.class, ccte_id, 2);
+ CompositeCustomTypeEntity rev3 = getVersionsReader().find(CompositeCustomTypeEntity.class, ccte_id, 3);
+
+ assert rev1.getComponent().equals(new Component("a", 1));
+ assert rev2.getComponent().equals(new Component("b", 1));
+ assert rev3.getComponent().equals(new Component("c", 3));
+ }
+}
\ No newline at end of file
Added: trunk/src/test/org/jboss/envers/test/integration/customtype/ParametrizedCustom.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/customtype/ParametrizedCustom.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/customtype/ParametrizedCustom.java 2008-09-22 20:30:29 UTC (rev 163)
@@ -0,0 +1,64 @@
+package org.jboss.envers.test.integration.customtype;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.customtype.ParametrizedCustomTypeEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.hibernate.ejb.Ejb3Configuration;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ParametrizedCustom extends AbstractEntityTest {
+ private Integer pcte_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ParametrizedCustomTypeEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ ParametrizedCustomTypeEntity pcte = new ParametrizedCustomTypeEntity();
+
+ // Revision 1 (persisting 1 entity)
+ em.getTransaction().begin();
+
+ pcte.setStr("U");
+
+ em.persist(pcte);
+
+ em.getTransaction().commit();
+
+ // Revision 2 (changing the value)
+ em.getTransaction().begin();
+
+ pcte = em.find(ParametrizedCustomTypeEntity.class, pcte.getId());
+
+ pcte.setStr("V");
+
+ em.getTransaction().commit();
+
+ //
+
+ pcte_id = pcte.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getVersionsReader().getRevisions(ParametrizedCustomTypeEntity.class, pcte_id));
+ }
+
+ @Test
+ public void testHistoryOfCcte() {
+ ParametrizedCustomTypeEntity rev1 = getVersionsReader().find(ParametrizedCustomTypeEntity.class, pcte_id, 1);
+ ParametrizedCustomTypeEntity rev2 = getVersionsReader().find(ParametrizedCustomTypeEntity.class, pcte_id, 2);
+
+ assert "xUy".equals(rev1.getStr());
+ assert "xVy".equals(rev2.getStr());
+ }
+}
\ No newline at end of file
16 years, 3 months