Hibernate SVN: r15567 - in search/trunk: src/java/org/hibernate/search and 9 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2008-11-16 10:06:50 -0500 (Sun, 16 Nov 2008)
New Revision: 15567
Modified:
search/trunk/readme.txt
search/trunk/src/java/org/hibernate/search/FullTextQuery.java
search/trunk/src/java/org/hibernate/search/annotations/FullTextFilterDef.java
search/trunk/src/java/org/hibernate/search/backend/Workspace.java
search/trunk/src/java/org/hibernate/search/backend/configuration/MaskedProperty.java
search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java
search/trunk/src/java/org/hibernate/search/cfg/SearchConfigurationFromHibernateCore.java
search/trunk/src/java/org/hibernate/search/engine/FilterDef.java
search/trunk/src/java/org/hibernate/search/impl/SearchFactoryImpl.java
search/trunk/src/java/org/hibernate/search/reader/NotSharedReaderProvider.java
search/trunk/src/java/org/hibernate/search/util/HibernateSearchResourceLoader.java
search/trunk/src/java/org/hibernate/search/util/WeakIdentityHashMap.java
Log:
Removal of old TODO, @SuppressWarnings which didn't apply anymore, unused imports and variables.
Fix some typos in comments and javadoc.
Modified: search/trunk/readme.txt
===================================================================
--- search/trunk/readme.txt 2008-11-15 15:23:25 UTC (rev 15566)
+++ search/trunk/readme.txt 2008-11-16 15:06:50 UTC (rev 15567)
@@ -15,7 +15,7 @@
Hibernate Search is using Apache Lucene(tm) under the cover.
-Hibernate Requires Hibernate Core 3.3 and above.
+Hibernate Search Requires Hibernate Core 3.3 and above.
This version runs well with Hibernate Annotations 3.4.x and Hibernate EntityManager 3.4.x
Modified: search/trunk/src/java/org/hibernate/search/FullTextQuery.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/FullTextQuery.java 2008-11-15 15:23:25 UTC (rev 15566)
+++ search/trunk/src/java/org/hibernate/search/FullTextQuery.java 2008-11-16 15:06:50 UTC (rev 15567)
@@ -9,7 +9,7 @@
import org.hibernate.transform.ResultTransformer;
/**
- * The base interface for lucene powered searches.
+ * The base interface for Lucene powered searches.
*
* @author Hardy Ferentschik
* @author Emmanuel Bernard
Modified: search/trunk/src/java/org/hibernate/search/annotations/FullTextFilterDef.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/annotations/FullTextFilterDef.java 2008-11-15 15:23:25 UTC (rev 15566)
+++ search/trunk/src/java/org/hibernate/search/annotations/FullTextFilterDef.java 2008-11-16 15:06:50 UTC (rev 15567)
@@ -31,7 +31,6 @@
* If the filter accept parameters, an @Key method must be present as well
*
*/
- @SuppressWarnings("unchecked")
Class<?> impl();
/**
Modified: search/trunk/src/java/org/hibernate/search/backend/Workspace.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/Workspace.java 2008-11-15 15:23:25 UTC (rev 15566)
+++ search/trunk/src/java/org/hibernate/search/backend/Workspace.java 2008-11-16 15:06:50 UTC (rev 15567)
@@ -36,7 +36,6 @@
* @author Hardy Ferentschik
* @author Sanne Grinovero
*/
-//TODO introduce the notion of read only IndexReader? We cannot enforce it because Lucene uses abstract classes, not interfaces.
//TODO renaming to "DirectoryWorkspace" would be nice.
public class Workspace {
Modified: search/trunk/src/java/org/hibernate/search/backend/configuration/MaskedProperty.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/configuration/MaskedProperty.java 2008-11-15 15:23:25 UTC (rev 15566)
+++ search/trunk/src/java/org/hibernate/search/backend/configuration/MaskedProperty.java 2008-11-16 15:06:50 UTC (rev 15567)
@@ -3,8 +3,6 @@
import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
@@ -159,12 +157,12 @@
}
}
}
- if (fallBack != null) {
+ if ( fallBack != null ) {
Enumeration<?> fallBackNames = fallBack.propertyNames();
while ( fallBackNames.hasMoreElements() ) {
Object key = fallBackNames.nextElement();
if ( String.class.isInstance( key ) ) {
- maskedProperties.add( (String) key );
+ maskedProperties.add( key );
}
}
}
Modified: search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java 2008-11-15 15:23:25 UTC (rev 15566)
+++ search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java 2008-11-16 15:06:50 UTC (rev 15567)
@@ -133,7 +133,7 @@
+ impl );
}
if ( cb.params().length > 0 && ParameterizedBridge.class.isAssignableFrom( impl ) ) {
- Map params = new HashMap( cb.params().length );
+ Map<String, String> params = new HashMap<String, String>( cb.params().length );
for ( Parameter param : cb.params() ) {
params.put( param.name(), param.value() );
}
@@ -175,7 +175,7 @@
bridge = builtInBridges.get( returnType.getName() );
if ( bridge == null && returnType.isEnum() ) {
bridge = new TwoWayString2FieldBridgeAdaptor(
- new EnumBridge( (Class<? extends Enum>) reflectionManager.toClass( returnType ) )
+ new EnumBridge( reflectionManager.toClass( returnType ) )
);
}
}
@@ -209,7 +209,7 @@
);
}
if ( bridgeAnn.params().length > 0 && ParameterizedBridge.class.isAssignableFrom( impl ) ) {
- Map params = new HashMap( bridgeAnn.params().length );
+ Map<String, String> params = new HashMap<String, String>( bridgeAnn.params().length );
for ( Parameter param : bridgeAnn.params() ) {
params.put( param.name(), param.value() );
}
Modified: search/trunk/src/java/org/hibernate/search/cfg/SearchConfigurationFromHibernateCore.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/cfg/SearchConfigurationFromHibernateCore.java 2008-11-15 15:23:25 UTC (rev 15566)
+++ search/trunk/src/java/org/hibernate/search/cfg/SearchConfigurationFromHibernateCore.java 2008-11-16 15:06:50 UTC (rev 15567)
@@ -59,7 +59,6 @@
private static class ClassIterator implements Iterator<Class<?>> {
private Iterator hibernatePersistentClassIterator;
private Class<?> future;
- private Class<?> current;
private ClassIterator(Iterator hibernatePersistentClassIterator) {
this.hibernatePersistentClassIterator = hibernatePersistentClassIterator;
Modified: search/trunk/src/java/org/hibernate/search/engine/FilterDef.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/FilterDef.java 2008-11-15 15:23:25 UTC (rev 15566)
+++ search/trunk/src/java/org/hibernate/search/engine/FilterDef.java 2008-11-16 15:06:50 UTC (rev 15567)
@@ -16,7 +16,6 @@
* @author Emmanuel Bernard
*/
//TODO serialization
-@SuppressWarnings("unchecked")
public class FilterDef {
private Method factoryMethod;
private Method keyMethod;
Modified: search/trunk/src/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/impl/SearchFactoryImpl.java 2008-11-15 15:23:25 UTC (rev 15566)
+++ search/trunk/src/java/org/hibernate/search/impl/SearchFactoryImpl.java 2008-11-16 15:06:50 UTC (rev 15567)
@@ -12,7 +12,6 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
@@ -57,8 +56,6 @@
* @author Emmanuel Bernard
*/
public class SearchFactoryImpl implements SearchFactoryImplementor {
- private static final ThreadLocal<WeakHashMap<SearchConfiguration, SearchFactoryImpl>> contexts =
- new ThreadLocal<WeakHashMap<SearchConfiguration, SearchFactoryImpl>>();
static {
Version.touch();
Modified: search/trunk/src/java/org/hibernate/search/reader/NotSharedReaderProvider.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/reader/NotSharedReaderProvider.java 2008-11-15 15:23:25 UTC (rev 15566)
+++ search/trunk/src/java/org/hibernate/search/reader/NotSharedReaderProvider.java 2008-11-16 15:06:50 UTC (rev 15567)
@@ -18,7 +18,7 @@
*/
public class NotSharedReaderProvider implements ReaderProvider {
@SuppressWarnings( { "ThrowableInstanceNeverThrown" } )
- public IndexReader openReader(DirectoryProvider[] directoryProviders) {
+ public IndexReader openReader(DirectoryProvider... directoryProviders) {
final int length = directoryProviders.length;
IndexReader[] readers = new IndexReader[length];
try {
Modified: search/trunk/src/java/org/hibernate/search/util/HibernateSearchResourceLoader.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/util/HibernateSearchResourceLoader.java 2008-11-15 15:23:25 UTC (rev 15566)
+++ search/trunk/src/java/org/hibernate/search/util/HibernateSearchResourceLoader.java 2008-11-16 15:06:50 UTC (rev 15567)
@@ -4,7 +4,6 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
-import java.io.Reader;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
Modified: search/trunk/src/java/org/hibernate/search/util/WeakIdentityHashMap.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/util/WeakIdentityHashMap.java 2008-11-15 15:23:25 UTC (rev 15566)
+++ search/trunk/src/java/org/hibernate/search/util/WeakIdentityHashMap.java 2008-11-16 15:06:50 UTC (rev 15567)
@@ -166,7 +166,7 @@
*/
public WeakIdentityHashMap() {
this.loadFactor = DEFAULT_LOAD_FACTOR;
- threshold = (int) ( DEFAULT_INITIAL_CAPACITY );
+ threshold = DEFAULT_INITIAL_CAPACITY;
table = new Entry[DEFAULT_INITIAL_CAPACITY];
}
15 years, 5 months
Hibernate SVN: r15566 - in core/trunk/envers/src: main/java/org/hibernate/envers/configuration/metadata and 8 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2008-11-15 10:23:25 -0500 (Sat, 15 Nov 2008)
New Revision: 15566
Added:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditTableData.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildAuditing.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentAuditing.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/NotOwnedBidirectional.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildAuditing.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentAuditing.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildIngEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildReferencing.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ParentNotIngEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ReferencedEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Address.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Contact.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/NotOwnedBidirectional.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/PersonalContact.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ChildIngEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ParentIngEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/PolymorphicCollection.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ReferencedEntity.java
Removed:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildVersioning.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentVersioning.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/InheritedBidirectional.java
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/EntityXmlMappingData.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/MetadataTools.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Address.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Contact.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/PersonalContact.java
core/trunk/envers/src/test/resources/testng.xml
Log:
HHH-3564: support for table-per-class inheritance strategy with tests
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2008-11-14 15:16:23 UTC (rev 15565)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -32,6 +32,7 @@
import org.hibernate.envers.*;
import org.hibernate.envers.entities.PropertyData;
import org.hibernate.envers.configuration.metadata.MetadataTools;
+import org.hibernate.envers.configuration.metadata.AuditTableData;
import org.hibernate.envers.revisioninfo.DefaultRevisionInfoGenerator;
import org.hibernate.envers.revisioninfo.RevisionInfoGenerator;
import org.hibernate.envers.revisioninfo.RevisionInfoNumberReader;
@@ -68,7 +69,7 @@
private Document generateDefaultRevisionInfoXmlMapping() {
Document document = DocumentHelper.createDocument();
- Element class_mapping = MetadataTools.createEntity(document, null, null, null, null, null);
+ Element class_mapping = MetadataTools.createEntity(document, new AuditTableData(null, null, null, null), null);
class_mapping.addAttribute("name", revisionInfoEntityName);
class_mapping.addAttribute("table", "REVINFO");
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2008-11-14 15:16:23 UTC (rev 15565)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -37,6 +37,7 @@
import org.hibernate.envers.entities.mapper.MultiPropertyMapper;
import org.hibernate.envers.entities.mapper.SubclassPropertyMapper;
import org.hibernate.envers.tools.StringTools;
+import org.hibernate.envers.tools.Triple;
import org.hibernate.MappingException;
import org.hibernate.cfg.Configuration;
@@ -210,6 +211,47 @@
}
@SuppressWarnings({"unchecked"})
+ private Triple<Element, ExtendedPropertyMapper, String> generateMappingData(
+ PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData,
+ IdMappingData idMapper) {
+ Element class_mapping = MetadataTools.createEntity(xmlMappingData.getMainXmlMapping(), auditTableData,
+ pc.getDiscriminatorValue());
+ ExtendedPropertyMapper propertyMapper = new MultiPropertyMapper();
+
+ // Checking if there is a discriminator column
+ if (pc.getDiscriminator() != null) {
+ Element discriminator_element = class_mapping.addElement("discriminator");
+ MetadataTools.addColumns(discriminator_element, pc.getDiscriminator().getColumnIterator());
+ discriminator_element.addAttribute("type", pc.getDiscriminator().getType().getName());
+ }
+
+ // Adding the id mapping
+ class_mapping.add((Element) idMapper.getXmlMapping().clone());
+
+ // Adding the "revision type" property
+ addRevisionType(class_mapping);
+
+ return Triple.make(class_mapping, propertyMapper, null);
+ }
+
+ private Triple<Element, ExtendedPropertyMapper, String> generateInheritanceMappingData(
+ PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData,
+ String inheritanceMappingType) {
+ String extendsEntityName = verEntCfg.getAuditEntityName(pc.getSuperclass().getEntityName());
+ Element class_mapping = MetadataTools.createSubclassEntity(xmlMappingData.getMainXmlMapping(),
+ inheritanceMappingType, auditTableData, extendsEntityName, pc.getDiscriminatorValue());
+
+ // The id and revision type is already mapped in the parent
+
+ // Getting the property mapper of the parent - when mapping properties, they need to be included
+ String parentEntityName = pc.getSuperclass().getEntityName();
+ ExtendedPropertyMapper parentPropertyMapper = entitiesConfigurations.get(parentEntityName).getPropertyMapper();
+ ExtendedPropertyMapper propertyMapper = new SubclassPropertyMapper(new MultiPropertyMapper(), parentPropertyMapper);
+
+ return Triple.make(class_mapping, propertyMapper, parentEntityName);
+ }
+
+ @SuppressWarnings({"unchecked"})
public void generateFirstPass(PersistentClass pc, PersistentClassAuditingData auditingData,
EntityXmlMappingData xmlMappingData) {
String schema = auditingData.getAuditTable().schema();
@@ -226,56 +268,47 @@
String auditEntityName = verEntCfg.getAuditEntityName(entityName);
String auditTableName = verEntCfg.getAuditTableName(entityName, pc.getTable().getName());
+ AuditTableData auditTableData = new AuditTableData(auditEntityName, auditTableName, schema, catalog);
+
// Generating a mapping for the id
IdMappingData idMapper = idMetadataGenerator.addId(pc);
- Element class_mapping;
- ExtendedPropertyMapper propertyMapper;
-
InheritanceType inheritanceType = InheritanceType.get(pc);
- String parentEntityName = null;
+ // These properties will be read from the mapping data
+ final Element class_mapping;
+ final ExtendedPropertyMapper propertyMapper;
+ final String parentEntityName;
+
+ final Triple<Element, ExtendedPropertyMapper, String> mappingData;
+
+ // Reading the mapping data depending on inheritance type (if any)
switch (inheritanceType) {
case NONE:
- class_mapping = MetadataTools.createEntity(xmlMappingData.getMainXmlMapping(), auditEntityName, auditTableName,
- schema, catalog, pc.getDiscriminatorValue());
- propertyMapper = new MultiPropertyMapper();
+ mappingData = generateMappingData(pc, xmlMappingData, auditTableData, idMapper);
+ break;
- // Checking if there is a discriminator column
- if (pc.getDiscriminator() != null) {
- Element discriminator_element = class_mapping.addElement("discriminator");
- MetadataTools.addColumns(discriminator_element, pc.getDiscriminator().getColumnIterator());
- discriminator_element.addAttribute("type", pc.getDiscriminator().getType().getName());
- }
-
- // Adding the id mapping
- class_mapping.add((Element) idMapper.getXmlMapping().clone());
-
- // Adding the "revision type" property
- addRevisionType(class_mapping);
-
+ case SINGLE:
+ mappingData = generateInheritanceMappingData(pc, xmlMappingData, auditTableData, "subclass");
break;
- case SINGLE:
- String extendsEntityName = verEntCfg.getAuditEntityName(pc.getSuperclass().getEntityName());
- class_mapping = MetadataTools.createSubclassEntity(xmlMappingData.getMainXmlMapping(), auditEntityName,
- auditTableName, schema, catalog, extendsEntityName, pc.getDiscriminatorValue());
- // The id and revision type is already mapped in the parent
-
- // Getting the property mapper of the parent - when mapping properties, they need to be included
- parentEntityName = pc.getSuperclass().getEntityName();
- ExtendedPropertyMapper parentPropertyMapper = entitiesConfigurations.get(parentEntityName).getPropertyMapper();
- propertyMapper = new SubclassPropertyMapper(new MultiPropertyMapper(), parentPropertyMapper);
-
- break;
case JOINED:
throw new MappingException("Joined inheritance strategy not supported for auditing!");
+
case TABLE_PER_CLASS:
- throw new MappingException("Table-per-class inheritance strategy not supported for auditing!");
+ mappingData = generateInheritanceMappingData(pc, xmlMappingData, auditTableData, "union-subclass");
+ break;
+
default:
throw new AssertionError("Impossible enum value.");
}
+ class_mapping = mappingData.getFirst();
+ propertyMapper = mappingData.getSecond();
+ parentEntityName = mappingData.getThird();
+
+ xmlMappingData.setClassMapping(class_mapping);
+
// Mapping unjoined properties
addProperties(class_mapping, (Iterator<Property>) pc.getUnjoinedPropertyIterator(), propertyMapper,
auditingData, pc.getEntityName(), xmlMappingData,
@@ -299,10 +332,7 @@
CompositeMapperBuilder propertyMapper = entitiesConfigurations.get(entityName).getPropertyMapper();
// Mapping unjoined properties
- Element parent = xmlMappingData.getMainXmlMapping().getRootElement().element("class");
- if (parent == null) {
- parent = xmlMappingData.getMainXmlMapping().getRootElement().element("subclass");
- }
+ Element parent = xmlMappingData.getClassMapping();
addProperties(parent, (Iterator<Property>) pc.getUnjoinedPropertyIterator(),
propertyMapper, auditingData, entityName, xmlMappingData, false);
Added: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditTableData.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditTableData.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditTableData.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,60 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.configuration.metadata;
+
+/**
+ * Holds information necessary to create an audit table: its name, schema and catalog, as well as the audit
+ * entity name.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class AuditTableData {
+ private final String auditEntityName;
+ private final String auditTableName;
+ private final String schema;
+ private final String catalog;
+
+ public AuditTableData(String auditEntityName, String auditTableName, String schema, String catalog) {
+ this.auditEntityName = auditEntityName;
+ this.auditTableName = auditTableName;
+ this.schema = schema;
+ this.catalog = catalog;
+ }
+
+ public String getAuditEntityName() {
+ return auditEntityName;
+ }
+
+ public String getAuditTableName() {
+ return auditTableName;
+ }
+
+ public String getSchema() {
+ return schema;
+ }
+
+ public String getCatalog() {
+ return catalog;
+ }
+}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-11-14 15:16:23 UTC (rev 15565)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -468,7 +468,7 @@
propertyValue.getCollectionTable().getCatalog() : persistentPropertyAuditingData.getJoinTable().catalog();
Element middleEntityXml = MetadataTools.createEntity(xmlMappingData.newAdditionalMapping(),
- auditMiddleEntityName, auditMiddleTableName, schema, catalog, null);
+ new AuditTableData(auditMiddleEntityName, auditMiddleTableName, schema, catalog), null);
Element middleEntityXmlId = middleEntityXml.addElement("composite-id");
middleEntityXmlId.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/EntityXmlMappingData.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/EntityXmlMappingData.java 2008-11-14 15:16:23 UTC (rev 15565)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/EntityXmlMappingData.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -28,6 +28,7 @@
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
/**
* @author Adam Warski (adam at warski dot org)
@@ -35,6 +36,11 @@
public class EntityXmlMappingData {
private Document mainXmlMapping;
private List<Document> additionalXmlMappings;
+ /**
+ * The xml element that maps the class. The root can be one of the folowing elements:
+ * class, subclass, union-subclass, joined-subclass
+ */
+ private Element classMapping;
public EntityXmlMappingData() {
mainXmlMapping = DocumentHelper.createDocument();
@@ -55,4 +61,12 @@
return additionalMapping;
}
+
+ public Element getClassMapping() {
+ return classMapping;
+ }
+
+ public void setClassMapping(Element classMapping) {
+ this.classMapping = classMapping;
+ }
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/MetadataTools.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/MetadataTools.java 2008-11-14 15:16:23 UTC (rev 15565)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/MetadataTools.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -79,47 +79,43 @@
return column_mapping;
}
- private static Element createEntityCommon(Document document, String type, String entityName,
- String tableName, String schema, String catalog,
+ private static Element createEntityCommon(Document document, String type, AuditTableData auditTableData,
String discriminatorValue) {
Element hibernate_mapping = document.addElement("hibernate-mapping");
hibernate_mapping.addAttribute("auto-import", "false");
Element class_mapping = hibernate_mapping.addElement(type);
- if (entityName != null) {
- class_mapping.addAttribute("entity-name", entityName);
+ if (auditTableData.getAuditEntityName() != null) {
+ class_mapping.addAttribute("entity-name", auditTableData.getAuditEntityName());
}
if (discriminatorValue != null) {
class_mapping.addAttribute("discriminator-value", discriminatorValue);
}
- if (!StringTools.isEmpty(tableName)) {
- class_mapping.addAttribute("table", tableName);
+ if (!StringTools.isEmpty(auditTableData.getAuditTableName())) {
+ class_mapping.addAttribute("table", auditTableData.getAuditTableName());
}
- if (!StringTools.isEmpty(schema)) {
- class_mapping.addAttribute("schema", schema);
+ if (!StringTools.isEmpty(auditTableData.getSchema())) {
+ class_mapping.addAttribute("schema", auditTableData.getSchema());
}
- if (!StringTools.isEmpty(catalog)) {
- class_mapping.addAttribute("catalog", catalog);
+ if (!StringTools.isEmpty(auditTableData.getCatalog())) {
+ class_mapping.addAttribute("catalog", auditTableData.getCatalog());
}
return class_mapping;
}
- public static Element createEntity(Document document, String entityName, String tableName,
- String schema, String catalog, String discriminatorValue) {
- return createEntityCommon(document, "class", entityName, tableName, schema, catalog, discriminatorValue);
+ public static Element createEntity(Document document, AuditTableData auditTableData, String discriminatorValue) {
+ return createEntityCommon(document, "class", auditTableData, discriminatorValue);
}
- public static Element createSubclassEntity(Document document, String entityName, String tableName,
- String schema, String catalog, String extendsEntityName,
- String discriminatorValue) {
- Element class_mapping = createEntityCommon(document, "subclass", entityName, tableName, schema, catalog,
- discriminatorValue);
+ public static Element createSubclassEntity(Document document, String subclassType, AuditTableData auditTableData,
+ String extendsEntityName, String discriminatorValue) {
+ Element class_mapping = createEntityCommon(document, subclassType, auditTableData, discriminatorValue);
class_mapping.addAttribute("extends", extendsEntityName);
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildAuditing.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildVersioning.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildAuditing.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildAuditing.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,92 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.envers.test.integration.inheritance.single;
+
+import java.util.Arrays;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ChildAuditing extends AbstractEntityTest {
+ private Integer id1;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ChildEntity.class);
+ cfg.addAnnotatedClass(ParentEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ // Rev 1
+ em.getTransaction().begin();
+ ChildEntity ce = new ChildEntity("x", 1l);
+ em.persist(ce);
+ id1 = ce.getId();
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+ ce = em.find(ChildEntity.class, id1);
+ ce.setData("y");
+ ce.setNumber(2l);
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ChildEntity.class, id1));
+ }
+
+ @Test
+ public void testHistoryOfChildId1() {
+ ChildEntity ver1 = new ChildEntity(id1, "x", 1l);
+ ChildEntity ver2 = new ChildEntity(id1, "y", 2l);
+
+ assert getAuditReader().find(ChildEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(ChildEntity.class, id1, 2).equals(ver2);
+
+ assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2);
+ }
+
+ @Test
+ public void testPolymorphicQuery() {
+ ChildEntity childVer1 = new ChildEntity(id1, "x", 1l);
+
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1).getSingleResult()
+ .equals(childVer1);
+
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult()
+ .equals(childVer1);
+ }
+}
Deleted: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildVersioning.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildVersioning.java 2008-11-14 15:16:23 UTC (rev 15565)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildVersioning.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -1,92 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * 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, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY 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
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.envers.test.integration.inheritance.single;
-
-import java.util.Arrays;
-import javax.persistence.EntityManager;
-
-import org.hibernate.envers.test.AbstractEntityTest;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import org.hibernate.ejb.Ejb3Configuration;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class ChildVersioning extends AbstractEntityTest {
- private Integer id1;
-
- public void configure(Ejb3Configuration cfg) {
- cfg.addAnnotatedClass(ChildEntity.class);
- cfg.addAnnotatedClass(ParentEntity.class);
- }
-
- @BeforeClass(dependsOnMethods = "init")
- public void initData() {
- EntityManager em = getEntityManager();
-
- // Rev 1
- em.getTransaction().begin();
- ChildEntity ce = new ChildEntity("x", 1l);
- em.persist(ce);
- id1 = ce.getId();
- em.getTransaction().commit();
-
- // Rev 2
- em.getTransaction().begin();
- ce = em.find(ChildEntity.class, id1);
- ce.setData("y");
- ce.setNumber(2l);
- em.getTransaction().commit();
- }
-
- @Test
- public void testRevisionsCounts() {
- assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ChildEntity.class, id1));
- }
-
- @Test
- public void testHistoryOfChildId1() {
- ChildEntity ver1 = new ChildEntity(id1, "x", 1l);
- ChildEntity ver2 = new ChildEntity(id1, "y", 2l);
-
- assert getAuditReader().find(ChildEntity.class, id1, 1).equals(ver1);
- assert getAuditReader().find(ChildEntity.class, id1, 2).equals(ver2);
-
- assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1);
- assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2);
- }
-
- @Test
- public void testPolymorphicQuery() {
- ChildEntity childVer1 = new ChildEntity(id1, "x", 1l);
-
- assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1).getSingleResult()
- .equals(childVer1);
-
- assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult()
- .equals(childVer1);
- }
-}
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentAuditing.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentVersioning.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentAuditing.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentAuditing.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,93 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.envers.test.integration.inheritance.single;
+
+import java.util.Arrays;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ParentAuditing extends AbstractEntityTest {
+ private Integer id1;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ChildEntity.class);
+ cfg.addAnnotatedClass(ParentEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ // Rev 1
+ em.getTransaction().begin();
+ ParentEntity pe = new ParentEntity("x");
+ em.persist(pe);
+ id1 = pe.getId();
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+ pe = em.find(ParentEntity.class, id1);
+ pe.setData("y");
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ParentEntity.class, id1));
+ }
+
+ @Test
+ public void testHistoryOfChildId1() {
+ assert getAuditReader().find(ChildEntity.class, id1, 1) == null;
+ assert getAuditReader().find(ChildEntity.class, id1, 2) == null;
+ }
+
+ @Test
+ public void testHistoryOfParentId1() {
+ ParentEntity ver1 = new ParentEntity(id1, "x");
+ ParentEntity ver2 = new ParentEntity(id1, "y");
+
+ assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2);
+ }
+
+ @Test
+ public void testPolymorphicQuery() {
+ ParentEntity parentVer1 = new ParentEntity(id1, "x");
+
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult()
+ .equals(parentVer1);
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1)
+ .getResultList().size() == 0;
+ }
+}
\ No newline at end of file
Deleted: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentVersioning.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentVersioning.java 2008-11-14 15:16:23 UTC (rev 15565)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentVersioning.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -1,93 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * 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, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY 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
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.envers.test.integration.inheritance.single;
-
-import java.util.Arrays;
-import javax.persistence.EntityManager;
-
-import org.hibernate.envers.test.AbstractEntityTest;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import org.hibernate.ejb.Ejb3Configuration;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class ParentVersioning extends AbstractEntityTest {
- private Integer id1;
-
- public void configure(Ejb3Configuration cfg) {
- cfg.addAnnotatedClass(ChildEntity.class);
- cfg.addAnnotatedClass(ParentEntity.class);
- }
-
- @BeforeClass(dependsOnMethods = "init")
- public void initData() {
- EntityManager em = getEntityManager();
-
- // Rev 1
- em.getTransaction().begin();
- ParentEntity pe = new ParentEntity("x");
- em.persist(pe);
- id1 = pe.getId();
- em.getTransaction().commit();
-
- // Rev 2
- em.getTransaction().begin();
- pe = em.find(ParentEntity.class, id1);
- pe.setData("y");
- em.getTransaction().commit();
- }
-
- @Test
- public void testRevisionsCounts() {
- assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ParentEntity.class, id1));
- }
-
- @Test
- public void testHistoryOfChildId1() {
- assert getAuditReader().find(ChildEntity.class, id1, 1) == null;
- assert getAuditReader().find(ChildEntity.class, id1, 2) == null;
- }
-
- @Test
- public void testHistoryOfParentId1() {
- ParentEntity ver1 = new ParentEntity(id1, "x");
- ParentEntity ver2 = new ParentEntity(id1, "y");
-
- assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1);
- assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2);
- }
-
- @Test
- public void testPolymorphicQuery() {
- ParentEntity parentVer1 = new ParentEntity(id1, "x");
-
- assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult()
- .equals(parentVer1);
- assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1)
- .getResultList().size() == 0;
- }
-}
\ No newline at end of file
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation (from rev 15565, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation)
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Address.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/Address.java 2008-11-14 15:16:23 UTC (rev 15565)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Address.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -1,4 +1,4 @@
-package org.hibernate.envers.test.integration.inheritance.single.inheritedrelation;
+package org.hibernate.envers.test.integration.inheritance.single.notownedrelation;
import org.hibernate.envers.Audited;
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Contact.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/Contact.java 2008-11-14 15:16:23 UTC (rev 15565)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/Contact.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -1,4 +1,4 @@
-package org.hibernate.envers.test.integration.inheritance.single.inheritedrelation;
+package org.hibernate.envers.test.integration.inheritance.single.notownedrelation;
import java.io.Serializable;
import java.util.Set;
Deleted: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/InheritedBidirectional.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/InheritedBidirectional.java 2008-11-14 15:16:23 UTC (rev 15565)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/InheritedBidirectional.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -1,120 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * 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, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY 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
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-
-package org.hibernate.envers.test.integration.inheritance.single.inheritedrelation;
-
-import java.util.Arrays;
-import javax.persistence.EntityManager;
-
-import org.hibernate.envers.test.AbstractEntityTest;
-import org.hibernate.envers.test.tools.TestTools;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import org.hibernate.ejb.Ejb3Configuration;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class InheritedBidirectional extends AbstractEntityTest {
- private Long pc_id;
- private Long a1_id;
- private Long a2_id;
-
- public void configure(Ejb3Configuration cfg) {
- cfg.addAnnotatedClass(Address.class);
- cfg.addAnnotatedClass(Contact.class);
- cfg.addAnnotatedClass(PersonalContact.class);
- }
-
- @BeforeClass(dependsOnMethods = "init")
- public void initData() {
- EntityManager em = getEntityManager();
-
- // Rev 1
- em.getTransaction().begin();
-
- PersonalContact pc = new PersonalContact();
- pc.setEmail("e");
- pc.setFirstname("f");
-
- Address a1 = new Address();
- a1.setAddress1("a1");
- a1.setContact(pc);
-
- em.persist(pc);
- em.persist(a1);
-
- em.getTransaction().commit();
-
- // Rev 2
- em.getTransaction().begin();
-
- pc = em.find(PersonalContact.class, pc.getId());
-
- Address a2 = new Address();
- a2.setAddress1("a2");
- a2.setContact(pc);
-
- em.persist(a2);
-
- em.getTransaction().commit();
-
- //
-
- pc_id = pc.getId();
- a1_id = a1.getId();
- a2_id = a2.getId();
- }
-
- @Test
- public void testRevisionsCounts() {
- assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(Contact.class, pc_id));
- assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(PersonalContact.class, pc_id));
-
- assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id));
- assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id));
-
- assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id));
- assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id));
- }
-
- @Test
- public void testHistoryOfContact() {
- assert getAuditReader().find(Contact.class, pc_id, 1).getAddresses().equals(
- TestTools.makeSet(new Address(a1_id, "a1")));
-
- assert getAuditReader().find(Contact.class, pc_id, 2).getAddresses().equals(
- TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2")));
- }
-
- @Test
- public void testHistoryOfPersonalContact() {
- assert getAuditReader().find(PersonalContact.class, pc_id, 1).getAddresses().equals(
- TestTools.makeSet(new Address(a1_id, "a1")));
-
- assert getAuditReader().find(PersonalContact.class, pc_id, 2).getAddresses().equals(
- TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2")));
- }
-}
\ No newline at end of file
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/NotOwnedBidirectional.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/NotOwnedBidirectional.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/NotOwnedBidirectional.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,120 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.single.notownedrelation;
+
+import java.util.Arrays;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.tools.TestTools;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class NotOwnedBidirectional extends AbstractEntityTest {
+ private Long pc_id;
+ private Long a1_id;
+ private Long a2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(Address.class);
+ cfg.addAnnotatedClass(Contact.class);
+ cfg.addAnnotatedClass(PersonalContact.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ // Rev 1
+ em.getTransaction().begin();
+
+ PersonalContact pc = new PersonalContact();
+ pc.setEmail("e");
+ pc.setFirstname("f");
+
+ Address a1 = new Address();
+ a1.setAddress1("a1");
+ a1.setContact(pc);
+
+ em.persist(pc);
+ em.persist(a1);
+
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+
+ pc = em.find(PersonalContact.class, pc.getId());
+
+ Address a2 = new Address();
+ a2.setAddress1("a2");
+ a2.setContact(pc);
+
+ em.persist(a2);
+
+ em.getTransaction().commit();
+
+ //
+
+ pc_id = pc.getId();
+ a1_id = a1.getId();
+ a2_id = a2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(Contact.class, pc_id));
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(PersonalContact.class, pc_id));
+
+ assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id));
+ assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id));
+
+ assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id));
+ assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id));
+ }
+
+ @Test
+ public void testHistoryOfContact() {
+ assert getAuditReader().find(Contact.class, pc_id, 1).getAddresses().equals(
+ TestTools.makeSet(new Address(a1_id, "a1")));
+
+ assert getAuditReader().find(Contact.class, pc_id, 2).getAddresses().equals(
+ TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2")));
+ }
+
+ @Test
+ public void testHistoryOfPersonalContact() {
+ assert getAuditReader().find(PersonalContact.class, pc_id, 1).getAddresses().equals(
+ TestTools.makeSet(new Address(a1_id, "a1")));
+
+ assert getAuditReader().find(PersonalContact.class, pc_id, 2).getAddresses().equals(
+ TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2")));
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/NotOwnedBidirectional.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/PersonalContact.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/PersonalContact.java 2008-11-14 15:16:23 UTC (rev 15565)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/notownedrelation/PersonalContact.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -1,4 +1,4 @@
-package org.hibernate.envers.test.integration.inheritance.single.inheritedrelation;
+package org.hibernate.envers.test.integration.inheritance.single.notownedrelation;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildAuditing.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildAuditing.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildAuditing.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,94 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass;
+
+import java.util.Arrays;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ChildAuditing extends AbstractEntityTest {
+ private Integer id1;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ChildEntity.class);
+ cfg.addAnnotatedClass(ParentEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ id1 = 1;
+
+ // Rev 1
+ em.getTransaction().begin();
+ ChildEntity ce = new ChildEntity(id1, "x", 1l);
+ em.persist(ce);
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+ ce = em.find(ChildEntity.class, id1);
+ ce.setData("y");
+ ce.setNumber(2l);
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ChildEntity.class, id1));
+ }
+
+ @Test
+ public void testHistoryOfChildId1() {
+ ChildEntity ver1 = new ChildEntity(id1, "x", 1l);
+ ChildEntity ver2 = new ChildEntity(id1, "y", 2l);
+
+ assert getAuditReader().find(ChildEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(ChildEntity.class, id1, 2).equals(ver2);
+
+ assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2);
+ }
+
+ @Test
+ public void testPolymorphicQuery() {
+ ChildEntity childVer1 = new ChildEntity(id1, "x", 1l);
+
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1).getSingleResult()
+ .equals(childVer1);
+
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult()
+ .equals(childVer1);
+ }
+}
\ No newline at end of file
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,78 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Audited
+public class ChildEntity extends ParentEntity {
+ @Basic
+ private Long number;
+
+ public ChildEntity() {
+ }
+
+ public ChildEntity(Integer id, String data, Long number) {
+ super(id, data);
+ this.number = number;
+ }
+
+ public Long getNumber() {
+ return number;
+ }
+
+ public void setNumber(Long number) {
+ this.number = number;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ChildEntity)) return false;
+ if (!super.equals(o)) return false;
+
+ ChildEntity childEntity = (ChildEntity) o;
+
+ if (number != null ? !number.equals(childEntity.number) : childEntity.number != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = super.hashCode();
+ result = 31 * result + (number != null ? number.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "ChildEntity(id = " + getId() + ", data = " + getData() + ", number = " + number + ")";
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentAuditing.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentAuditing.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentAuditing.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,95 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass;
+
+import java.util.Arrays;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ParentAuditing extends AbstractEntityTest {
+ private Integer id1;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ChildEntity.class);
+ cfg.addAnnotatedClass(ParentEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ id1 = 1;
+
+ // Rev 1
+ em.getTransaction().begin();
+ ParentEntity pe = new ParentEntity(id1, "x");
+ em.persist(pe);
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+ pe = em.find(ParentEntity.class, id1);
+ pe.setData("y");
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ParentEntity.class, id1));
+ }
+
+ @Test
+ public void testHistoryOfChildId1() {
+ assert getAuditReader().find(ChildEntity.class, id1, 1) == null;
+ assert getAuditReader().find(ChildEntity.class, id1, 2) == null;
+ }
+
+ @Test
+ public void testHistoryOfParentId1() {
+ ParentEntity ver1 = new ParentEntity(id1, "x");
+ ParentEntity ver2 = new ParentEntity(id1, "y");
+
+ assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2);
+ }
+
+ @Test
+ public void testPolymorphicQuery() {
+ ParentEntity parentVer1 = new ParentEntity(id1, "x");
+
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult()
+ .equals(parentVer1);
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1)
+ .getResultList().size() == 0;
+ }
+}
\ No newline at end of file
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentEntity.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ParentEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentEntity.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,95 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Audited
+public class ParentEntity {
+ @Id
+ private Integer id;
+
+ @Basic
+ private String data;
+
+ public ParentEntity() {
+ }
+
+ public ParentEntity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ParentEntity)) return false;
+
+ ParentEntity that = (ParentEntity) o;
+
+ if (data != null ? !data.equals(that.data) : that.data != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "ParentEntity(id = " + getId() + ", data = " + getData() + ")";
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ParentEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildIngEntity.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ChildIngEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildIngEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildIngEntity.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,90 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass.childrelation;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.ManyToOne;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Audited
+public class ChildIngEntity extends ParentNotIngEntity {
+ @Basic
+ private Long number;
+
+ @ManyToOne
+ private ReferencedEntity referenced;
+
+ public ChildIngEntity() {
+ }
+
+ public ChildIngEntity(Integer id, String data, Long number) {
+ super(id, data);
+ this.number = number;
+ }
+
+ public Long getNumber() {
+ return number;
+ }
+
+ public void setNumber(Long number) {
+ this.number = number;
+ }
+
+ public ReferencedEntity getReferenced() {
+ return referenced;
+ }
+
+ public void setReferenced(ReferencedEntity referenced) {
+ this.referenced = referenced;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ChildIngEntity)) return false;
+ if (!super.equals(o)) return false;
+
+ ChildIngEntity childEntity = (ChildIngEntity) o;
+
+ if (number != null ? !number.equals(childEntity.number) : childEntity.number != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = super.hashCode();
+ result = 31 * result + (number != null ? number.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", number = " + number + ")";
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildIngEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildReferencing.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ChildReferencing.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildReferencing.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildReferencing.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,124 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass.childrelation;
+
+import java.util.Arrays;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.tools.TestTools;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ChildReferencing extends AbstractEntityTest {
+ private Integer re_id1;
+ private Integer re_id2;
+ private Integer c_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ChildIngEntity.class);
+ cfg.addAnnotatedClass(ParentNotIngEntity.class);
+ cfg.addAnnotatedClass(ReferencedEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ re_id1 = 1;
+ re_id2 = 10;
+ c_id = 100;
+
+ // Rev 1
+ em.getTransaction().begin();
+
+ ReferencedEntity re1 = new ReferencedEntity(re_id1);
+ em.persist(re1);
+
+ ReferencedEntity re2 = new ReferencedEntity(re_id2);
+ em.persist(re2);
+
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+
+ re1 = em.find(ReferencedEntity.class, re_id1);
+
+ ChildIngEntity cie = new ChildIngEntity(c_id, "y", 1l);
+ cie.setReferenced(re1);
+ em.persist(cie);
+ c_id = cie.getId();
+
+ em.getTransaction().commit();
+
+ // Rev 3
+ em.getTransaction().begin();
+
+ re2 = em.find(ReferencedEntity.class, re_id2);
+ cie = em.find(ChildIngEntity.class, c_id);
+
+ cie.setReferenced(re2);
+
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ReferencedEntity.class, re_id1));
+ assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(ReferencedEntity.class, re_id2));
+ assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(ChildIngEntity.class, c_id));
+ }
+
+ @Test
+ public void testHistoryOfReferencedCollection1() {
+ assert getAuditReader().find(ReferencedEntity.class, re_id1, 1).getReferencing().size() == 0;
+ assert getAuditReader().find(ReferencedEntity.class, re_id1, 2).getReferencing().equals(
+ TestTools.makeSet(new ChildIngEntity(c_id, "y", 1l)));
+ assert getAuditReader().find(ReferencedEntity.class, re_id1, 3).getReferencing().size() == 0;
+ }
+
+ @Test
+ public void testHistoryOfReferencedCollection2() {
+ assert getAuditReader().find(ReferencedEntity.class, re_id2, 1).getReferencing().size() == 0;
+ assert getAuditReader().find(ReferencedEntity.class, re_id2, 2).getReferencing().size() == 0;
+ assert getAuditReader().find(ReferencedEntity.class, re_id2, 3).getReferencing().equals(
+ TestTools.makeSet(new ChildIngEntity(c_id, "y", 1l)));
+ }
+
+ @Test
+ public void testChildHistory() {
+ assert getAuditReader().find(ChildIngEntity.class, c_id, 1) == null;
+ assert getAuditReader().find(ChildIngEntity.class, c_id, 2).getReferenced().equals(
+ new ReferencedEntity(re_id1));
+ assert getAuditReader().find(ChildIngEntity.class, c_id, 3).getReferenced().equals(
+ new ReferencedEntity(re_id2));
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ChildReferencing.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ParentNotIngEntity.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ParentNotIngEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ParentNotIngEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ParentNotIngEntity.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,94 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass.childrelation;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Audited
+public class ParentNotIngEntity {
+ @Id
+ private Integer id;
+
+ @Basic
+ private String data;
+
+ public ParentNotIngEntity() {
+ }
+
+ public ParentNotIngEntity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ParentNotIngEntity)) return false;
+
+ ParentNotIngEntity that = (ParentNotIngEntity) o;
+
+ if (data != null ? !data.equals(that.data) : that.data != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "ParentNotIngEntity(id = " + getId() + ", data = " + getData() + ")";
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ParentNotIngEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ReferencedEntity.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/childrelation/ReferencedEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ReferencedEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ReferencedEntity.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,87 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass.childrelation;
+
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Audited
+public class ReferencedEntity {
+ @Id
+ private Integer id;
+
+ @OneToMany(mappedBy = "referenced")
+ private Set<ChildIngEntity> referencing;
+
+ public ReferencedEntity(Integer id) {
+ this.id = id;
+ }
+
+ public ReferencedEntity() {
+ }
+
+ public Set<ChildIngEntity> getReferencing() {
+ return referencing;
+ }
+
+ public void setReferencing(Set<ChildIngEntity> referencing) {
+ this.referencing = referencing;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ReferencedEntity)) return false;
+
+ ReferencedEntity that = (ReferencedEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return id;
+ }
+
+ public String toString() {
+ return "ReferencedEntity(id = " + getId() + ")";
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/childrelation/ReferencedEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Address.java (from rev 15565, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/Address.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Address.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Address.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,100 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass.notownedrelation;
+
+import org.hibernate.envers.Audited;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+@Entity
+@Audited
+public class Address implements Serializable {
+ @Id
+ private Long id;
+
+ private String address1;
+
+ @ManyToOne
+ private Contact contact;
+
+ public Address() {
+ }
+
+ public Address(Long id, String address1) {
+ this.id = id;
+ this.address1 = address1;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getAddress1() {
+ return address1;
+ }
+
+ public void setAddress1(String address1) {
+ this.address1 = address1;
+ }
+
+ public Contact getContact() {
+ return contact;
+ }
+
+ public void setContact(Contact contact) {
+ this.contact = contact;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Address)) return false;
+
+ Address address = (Address) o;
+
+ if (address1 != null ? !address1.equals(address.address1) : address.address1 != null) return false;
+ if (id != null ? !id.equals(address.id) : address.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (address1 != null ? address1.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "Address(id = " + getId() + ", address1 = " + getAddress1() + ")";
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Address.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Contact.java (from rev 15565, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/Contact.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Contact.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Contact.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,77 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass.notownedrelation;
+
+import java.io.Serializable;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.OneToMany;
+
+import org.hibernate.envers.Audited;
+
+@Entity
+(a)Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
+@Audited
+public class Contact implements Serializable {
+ @Id
+ private Long id;
+
+ private String email;
+
+ @OneToMany(mappedBy="contact")
+ private Set<Address> addresses;
+
+ public Contact() {
+ }
+
+ public Contact(Long id, String email) {
+ this.id = id;
+ this.email = email;
+ }
+
+ public Long getId() {
+ return id;
+ }
+ public void setId(Long id) {
+ this.id = id;
+ }
+ public String getEmail() {
+ return email;
+ }
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public Set<Address> getAddresses() {
+ return addresses;
+ }
+ public void setAddresses(Set<Address> addresses) {
+ this.addresses = addresses;
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/Contact.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/NotOwnedBidirectional.java (from rev 15565, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/InheritedBidirectional.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/NotOwnedBidirectional.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/NotOwnedBidirectional.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,115 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass.notownedrelation;
+
+import java.util.Arrays;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.tools.TestTools;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class NotOwnedBidirectional extends AbstractEntityTest {
+ private Long pc_id;
+ private Long a1_id;
+ private Long a2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(Address.class);
+ cfg.addAnnotatedClass(Contact.class);
+ cfg.addAnnotatedClass(PersonalContact.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ pc_id = 1l;
+ a1_id = 10l;
+ a2_id = 100l;
+
+ // Rev 1
+ em.getTransaction().begin();
+
+ PersonalContact pc = new PersonalContact(pc_id, "e", "f");
+
+ Address a1 = new Address(a1_id, "a1");
+ a1.setContact(pc);
+
+ em.persist(pc);
+ em.persist(a1);
+
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+
+ pc = em.find(PersonalContact.class, pc_id);
+
+ Address a2 = new Address(a2_id, "a2");
+ a2.setContact(pc);
+
+ em.persist(a2);
+
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(Contact.class, pc_id));
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(PersonalContact.class, pc_id));
+
+ assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id));
+ assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id));
+
+ assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id));
+ assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id));
+ }
+
+ @Test
+ public void testHistoryOfContact() {
+ assert getAuditReader().find(Contact.class, pc_id, 1).getAddresses().equals(
+ TestTools.makeSet(new Address(a1_id, "a1")));
+
+ assert getAuditReader().find(Contact.class, pc_id, 2).getAddresses().equals(
+ TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2")));
+ }
+
+ @Test
+ public void testHistoryOfPersonalContact() {
+ System.out.println(getAuditReader().find(PersonalContact.class, pc_id, 1).getAddresses());
+ assert getAuditReader().find(PersonalContact.class, pc_id, 1).getAddresses().equals(
+ TestTools.makeSet(new Address(a1_id, "a1")));
+
+ assert getAuditReader().find(PersonalContact.class, pc_id, 2).getAddresses().equals(
+ TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2")));
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/NotOwnedBidirectional.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/PersonalContact.java (from rev 15565, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/PersonalContact.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/PersonalContact.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/PersonalContact.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,51 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass.notownedrelation;
+
+import javax.persistence.Entity;
+
+import org.hibernate.envers.Audited;
+
+@Entity
+@Audited
+public class PersonalContact extends Contact {
+ private String firstname;
+
+ public PersonalContact() {
+ }
+
+ public PersonalContact(Long id, String email, String firstname) {
+ super(id, email);
+ this.firstname = firstname;
+ }
+
+ public String getFirstname() {
+ return firstname;
+ }
+
+ public void setFirstname(String firstname) {
+ this.firstname = firstname;
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/notownedrelation/PersonalContact.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ChildIngEntity.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ChildIngEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ChildIngEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ChildIngEntity.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,78 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass.relation;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Audited
+public class ChildIngEntity extends ParentIngEntity {
+ @Basic
+ private Long number;
+
+ public ChildIngEntity() {
+ }
+
+ public ChildIngEntity(Integer id, String data, Long number) {
+ super(id, data);
+ this.number = number;
+ }
+
+ public Long getNumber() {
+ return number;
+ }
+
+ public void setNumber(Long number) {
+ this.number = number;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ChildIngEntity)) return false;
+ if (!super.equals(o)) return false;
+
+ ChildIngEntity childEntity = (ChildIngEntity) o;
+
+ if (number != null ? !number.equals(childEntity.number) : childEntity.number != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = super.hashCode();
+ result = 31 * result + (number != null ? number.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "ChildIngEntity(id = " + getId() + ", data = " + getData() + ", number = " + number + ")";
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ChildIngEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ParentIngEntity.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ParentIngEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ParentIngEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ParentIngEntity.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,106 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass.relation;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.ManyToOne;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Audited
+public class ParentIngEntity {
+ @Id
+ private Integer id;
+
+ @Basic
+ private String data;
+
+ @ManyToOne
+ private ReferencedEntity referenced;
+
+ public ParentIngEntity() {
+ }
+
+ public ParentIngEntity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public ReferencedEntity getReferenced() {
+ return referenced;
+ }
+
+ public void setReferenced(ReferencedEntity referenced) {
+ this.referenced = referenced;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ParentIngEntity)) return false;
+
+ ParentIngEntity that = (ParentIngEntity) o;
+
+ if (data != null ? !data.equals(that.data) : that.data != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "ParentIngEntity(id = " + getId() + ", data = " + getData() + ")";
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ParentIngEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/PolymorphicCollection.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/PolymorphicCollection.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/PolymorphicCollection.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/PolymorphicCollection.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,107 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass.relation;
+
+import java.util.Arrays;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.tools.TestTools;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class PolymorphicCollection extends AbstractEntityTest {
+ private Integer ed_id1;
+ private Integer c_id;
+ private Integer p_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ChildIngEntity.class);
+ cfg.addAnnotatedClass(ParentIngEntity.class);
+ cfg.addAnnotatedClass(ReferencedEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ ed_id1 = 1;
+ p_id = 10;
+ c_id = 100;
+
+ // Rev 1
+ em.getTransaction().begin();
+
+ ReferencedEntity re = new ReferencedEntity(ed_id1);
+ em.persist(re);
+
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+
+ re = em.find(ReferencedEntity.class, ed_id1);
+
+ ParentIngEntity pie = new ParentIngEntity(p_id,"x");
+ pie.setReferenced(re);
+ em.persist(pie);
+ p_id = pie.getId();
+
+ em.getTransaction().commit();
+
+ // Rev 3
+ em.getTransaction().begin();
+
+ re = em.find(ReferencedEntity.class, ed_id1);
+
+ ChildIngEntity cie = new ChildIngEntity(c_id, "y", 1l);
+ cie.setReferenced(re);
+ em.persist(cie);
+ c_id = cie.getId();
+
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ReferencedEntity.class, ed_id1));
+ assert Arrays.asList(2).equals(getAuditReader().getRevisions(ParentIngEntity.class, p_id));
+ assert Arrays.asList(3).equals(getAuditReader().getRevisions(ChildIngEntity.class, c_id));
+ }
+
+ @Test
+ public void testHistoryOfReferencedCollection() {
+ assert getAuditReader().find(ReferencedEntity.class, ed_id1, 1).getReferencing().size() == 0;
+ assert getAuditReader().find(ReferencedEntity.class, ed_id1, 2).getReferencing().equals(
+ TestTools.makeSet(new ParentIngEntity(p_id, "x")));
+ assert getAuditReader().find(ReferencedEntity.class, ed_id1, 3).getReferencing().equals(
+ TestTools.makeSet(new ParentIngEntity(p_id, "x"), new ChildIngEntity(c_id, "y", 1l)));
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/PolymorphicCollection.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ReferencedEntity.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/ReferencedEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ReferencedEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ReferencedEntity.java 2008-11-15 15:23:25 UTC (rev 15566)
@@ -0,0 +1,87 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.tableperclass.relation;
+
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Audited
+public class ReferencedEntity {
+ @Id
+ private Integer id;
+
+ @OneToMany(mappedBy = "referenced")
+ private Set<ParentIngEntity> referencing;
+
+ public ReferencedEntity() {
+ }
+
+ public ReferencedEntity(Integer id) {
+ this.id = id;
+ }
+
+ public Set<ParentIngEntity> getReferencing() {
+ return referencing;
+ }
+
+ public void setReferencing(Set<ParentIngEntity> referencing) {
+ this.referencing = referencing;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ReferencedEntity)) return false;
+
+ ReferencedEntity that = (ReferencedEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return id;
+ }
+
+ public String toString() {
+ return "ReferencedEntity(id = " + getId() + ")";
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/relation/ReferencedEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: core/trunk/envers/src/test/resources/testng.xml
===================================================================
--- core/trunk/envers/src/test/resources/testng.xml 2008-11-14 15:16:23 UTC (rev 15565)
+++ core/trunk/envers/src/test/resources/testng.xml 2008-11-15 15:23:25 UTC (rev 15566)
@@ -15,8 +15,12 @@
<package name="org.hibernate.envers.test.integration.ids" />
<package name="org.hibernate.envers.test.integration.inheritance.single" />
<package name="org.hibernate.envers.test.integration.inheritance.single.childrelation" />
- <package name="org.hibernate.envers.test.integration.inheritance.single.inheritedrelation" />
+ <package name="org.hibernate.envers.test.integration.inheritance.single.notownedrelation" />
<package name="org.hibernate.envers.test.integration.inheritance.single.relation" />
+ <package name="org.hibernate.envers.test.integration.inheritance.tableperclass" />
+ <package name="org.hibernate.envers.test.integration.inheritance.tableperclass.childrelation" />
+ <package name="org.hibernate.envers.test.integration.inheritance.tableperclass.notownedrelation" />
+ <package name="org.hibernate.envers.test.integration.inheritance.tableperclass.relation" />
<package name="org.hibernate.envers.test.integration.manytomany" />
<package name="org.hibernate.envers.test.integration.manytomany.ternary" />
<package name="org.hibernate.envers.test.integration.manytomany.unidirectional" />
15 years, 5 months
Hibernate SVN: r15565 - in core/trunk/envers/src: test/java/org/hibernate/envers/test/integration/inheritance/single and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2008-11-14 10:16:23 -0500 (Fri, 14 Nov 2008)
New Revision: 15565
Added:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/Address.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/Contact.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/InheritedBidirectional.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/PersonalContact.java
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java
core/trunk/envers/src/test/resources/testng.xml
Log:
HHH-3602: bug fix with test (generating a CollectionChangeWorkUnit for the proper entity in case a relation is owned by a superclass, when inheritance is used)
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2008-11-14 11:10:15 UTC (rev 15564)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2008-11-14 15:16:23 UTC (rev 15565)
@@ -41,6 +41,7 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.CollectionEntry;
+import org.hibernate.engine.SessionImplementor;
import org.hibernate.event.AbstractCollectionEvent;
import org.hibernate.event.Initializable;
import org.hibernate.event.PostCollectionRecreateEvent;
@@ -66,7 +67,8 @@
private AuditConfiguration verCfg;
private void generateBidirectionalCollectionChangeWorkUnits(AuditSync verSync, EntityPersister entityPersister,
- String entityName, Object[] newState, Object[] oldState) {
+ String entityName, Object[] newState, Object[] oldState,
+ SessionImplementor session) {
// Checking if this is enabled in configuration ...
if (!verCfg.getGlobalCfg().isGenerateRevisionsForCollections()) {
return;
@@ -86,18 +88,26 @@
Object newValue = newState == null ? null : newState[i];
if (!Tools.objectsEqual(oldValue, newValue)) {
- IdMapper idMapper = verCfg.getEntCfg().get(relDesc.getToEntityName()).getIdMapper();
-
// We have to generate changes both in the old collection (size decreses) and new collection
// (size increases).
if (newValue != null) {
+ // relDesc.getToEntityName() doesn't always return the entity name of the value - in case
+ // of subclasses, this will be root class, no the actual class. So it can't be used here.
+ String toEntityName = session.guessEntityName(newValue);
+
+ IdMapper idMapper = verCfg.getEntCfg().get(toEntityName).getIdMapper();
+
Serializable id = (Serializable) idMapper.mapToIdFromEntity(newValue);
- verSync.addWorkUnit(new CollectionChangeWorkUnit(relDesc.getToEntityName(), verCfg, id, newValue));
+ verSync.addWorkUnit(new CollectionChangeWorkUnit(toEntityName, verCfg, id, newValue));
}
if (oldValue != null) {
+ String toEntityName = session.guessEntityName(oldValue);
+
+ IdMapper idMapper = verCfg.getEntCfg().get(toEntityName).getIdMapper();
+
Serializable id = (Serializable) idMapper.mapToIdFromEntity(oldValue);
- verSync.addWorkUnit(new CollectionChangeWorkUnit(relDesc.getToEntityName(), verCfg, id, oldValue));
+ verSync.addWorkUnit(new CollectionChangeWorkUnit(toEntityName, verCfg, id, oldValue));
}
}
}
@@ -113,7 +123,8 @@
verSync.addWorkUnit(new AddWorkUnit(event.getPersister().getEntityName(), verCfg, event.getId(),
event.getPersister(), event.getState()));
- generateBidirectionalCollectionChangeWorkUnits(verSync, event.getPersister(), entityName, event.getState(), null);
+ generateBidirectionalCollectionChangeWorkUnits(verSync, event.getPersister(), entityName, event.getState(),
+ null, event.getSession());
}
}
@@ -126,7 +137,8 @@
verSync.addWorkUnit(new ModWorkUnit(event.getPersister().getEntityName(), verCfg, event.getId(),
event.getPersister(), event.getState(), event.getOldState()));
- generateBidirectionalCollectionChangeWorkUnits(verSync, event.getPersister(), entityName, event.getState(), event.getOldState());
+ generateBidirectionalCollectionChangeWorkUnits(verSync, event.getPersister(), entityName, event.getState(),
+ event.getOldState(), event.getSession());
}
}
@@ -138,7 +150,8 @@
verSync.addWorkUnit(new DelWorkUnit(event.getPersister().getEntityName(), verCfg, event.getId()));
- generateBidirectionalCollectionChangeWorkUnits(verSync, event.getPersister(), entityName, null, event.getDeletedState());
+ generateBidirectionalCollectionChangeWorkUnits(verSync, event.getPersister(), entityName, null,
+ event.getDeletedState(), event.getSession());
}
}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/Address.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/Address.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/Address.java 2008-11-14 15:16:23 UTC (rev 15565)
@@ -0,0 +1,73 @@
+package org.hibernate.envers.test.integration.inheritance.single.inheritedrelation;
+
+import org.hibernate.envers.Audited;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+@Entity
+@Audited
+public class Address implements Serializable {
+ @Id @GeneratedValue
+ private Long id;
+
+ private String address1;
+
+ @ManyToOne
+ private Contact contact;
+
+ public Address() {
+ }
+
+ public Address(Long id, String address1) {
+ this.id = id;
+ this.address1 = address1;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getAddress1() {
+ return address1;
+ }
+
+ public void setAddress1(String address1) {
+ this.address1 = address1;
+ }
+
+ public Contact getContact() {
+ return contact;
+ }
+
+ public void setContact(Contact contact) {
+ this.contact = contact;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Address)) return false;
+
+ Address address = (Address) o;
+
+ if (address1 != null ? !address1.equals(address.address1) : address.address1 != null) return false;
+ if (id != null ? !id.equals(address.id) : address.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (address1 != null ? address1.hashCode() : 0);
+ return result;
+ }
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/Contact.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/Contact.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/Contact.java 2008-11-14 15:16:23 UTC (rev 15565)
@@ -0,0 +1,53 @@
+package org.hibernate.envers.test.integration.inheritance.single.inheritedrelation;
+
+import java.io.Serializable;
+import java.util.Set;
+
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.OneToMany;
+
+import org.hibernate.envers.Audited;
+
+@Entity
+(a)Inheritance(strategy=InheritanceType.SINGLE_TABLE)
+@DiscriminatorValue("Contact")
+@DiscriminatorColumn(name="contactType",discriminatorType=javax.persistence.DiscriminatorType.STRING)
+@Audited
+public class Contact implements Serializable {
+ @Id @GeneratedValue
+ private Long id;
+
+ private String email;
+
+ @OneToMany(mappedBy="contact")
+ private Set<Address> addresses;
+
+ public Contact() {
+ }
+
+ public Long getId() {
+ return id;
+ }
+ public void setId(Long id) {
+ this.id = id;
+ }
+ public String getEmail() {
+ return email;
+ }
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public Set<Address> getAddresses() {
+ return addresses;
+ }
+ public void setAddresses(Set<Address> addresses) {
+ this.addresses = addresses;
+ }
+}
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/InheritedBidirectional.java (from rev 15550, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/relation/PolymorphicCollection.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/InheritedBidirectional.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/InheritedBidirectional.java 2008-11-14 15:16:23 UTC (rev 15565)
@@ -0,0 +1,120 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.single.inheritedrelation;
+
+import java.util.Arrays;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.tools.TestTools;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class InheritedBidirectional extends AbstractEntityTest {
+ private Long pc_id;
+ private Long a1_id;
+ private Long a2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(Address.class);
+ cfg.addAnnotatedClass(Contact.class);
+ cfg.addAnnotatedClass(PersonalContact.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ // Rev 1
+ em.getTransaction().begin();
+
+ PersonalContact pc = new PersonalContact();
+ pc.setEmail("e");
+ pc.setFirstname("f");
+
+ Address a1 = new Address();
+ a1.setAddress1("a1");
+ a1.setContact(pc);
+
+ em.persist(pc);
+ em.persist(a1);
+
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+
+ pc = em.find(PersonalContact.class, pc.getId());
+
+ Address a2 = new Address();
+ a2.setAddress1("a2");
+ a2.setContact(pc);
+
+ em.persist(a2);
+
+ em.getTransaction().commit();
+
+ //
+
+ pc_id = pc.getId();
+ a1_id = a1.getId();
+ a2_id = a2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(Contact.class, pc_id));
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(PersonalContact.class, pc_id));
+
+ assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id));
+ assert Arrays.asList(1).equals(getAuditReader().getRevisions(Address.class, a1_id));
+
+ assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id));
+ assert Arrays.asList(2).equals(getAuditReader().getRevisions(Address.class, a2_id));
+ }
+
+ @Test
+ public void testHistoryOfContact() {
+ assert getAuditReader().find(Contact.class, pc_id, 1).getAddresses().equals(
+ TestTools.makeSet(new Address(a1_id, "a1")));
+
+ assert getAuditReader().find(Contact.class, pc_id, 2).getAddresses().equals(
+ TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2")));
+ }
+
+ @Test
+ public void testHistoryOfPersonalContact() {
+ assert getAuditReader().find(PersonalContact.class, pc_id, 1).getAddresses().equals(
+ TestTools.makeSet(new Address(a1_id, "a1")));
+
+ assert getAuditReader().find(PersonalContact.class, pc_id, 2).getAddresses().equals(
+ TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2")));
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/InheritedBidirectional.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/PersonalContact.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/PersonalContact.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/inheritedrelation/PersonalContact.java 2008-11-14 15:16:23 UTC (rev 15565)
@@ -0,0 +1,21 @@
+package org.hibernate.envers.test.integration.inheritance.single.inheritedrelation;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
+import org.hibernate.envers.Audited;
+
+@Entity
+@DiscriminatorValue("PersonalContact")
+@Audited
+public class PersonalContact extends Contact {
+ private String firstname;
+
+ public String getFirstname() {
+ return firstname;
+ }
+
+ public void setFirstname(String firstname) {
+ this.firstname = firstname;
+ }
+}
Modified: core/trunk/envers/src/test/resources/testng.xml
===================================================================
--- core/trunk/envers/src/test/resources/testng.xml 2008-11-14 11:10:15 UTC (rev 15564)
+++ core/trunk/envers/src/test/resources/testng.xml 2008-11-14 15:16:23 UTC (rev 15565)
@@ -15,6 +15,7 @@
<package name="org.hibernate.envers.test.integration.ids" />
<package name="org.hibernate.envers.test.integration.inheritance.single" />
<package name="org.hibernate.envers.test.integration.inheritance.single.childrelation" />
+ <package name="org.hibernate.envers.test.integration.inheritance.single.inheritedrelation" />
<package name="org.hibernate.envers.test.integration.inheritance.single.relation" />
<package name="org.hibernate.envers.test.integration.manytomany" />
<package name="org.hibernate.envers.test.integration.manytomany.ternary" />
15 years, 5 months
Hibernate SVN: r15564 - in search/trunk: doc/quickstart and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-11-14 06:10:15 -0500 (Fri, 14 Nov 2008)
New Revision: 15564
Modified:
search/trunk/build.xml
search/trunk/changelog.txt
search/trunk/doc/quickstart/pom.xml
search/trunk/doc/quickstart/src/main/resources/archetype-resources/pom.xml
search/trunk/pom.xml
search/trunk/readme.txt
search/trunk/src/java/org/hibernate/search/Version.java
Log:
changed version string for CR1 release
Modified: search/trunk/build.xml
===================================================================
--- search/trunk/build.xml 2008-11-13 16:02:44 UTC (rev 15563)
+++ search/trunk/build.xml 2008-11-14 11:10:15 UTC (rev 15564)
@@ -18,7 +18,7 @@
<!-- Name of project and version, used to create filenames -->
<property name="Name" value="Hibernate Search"/>
<property name="name" value="hibernate-search"/>
- <property name="version" value="3.1.0.Beta2"/>
+ <property name="version" value="3.1.0.CR1"/>
<property name="javadoc.packagenames" value="org.hibernate.search.*"/>
<property name="copy.test" value="true"/>
<property name="javac.source" value="1.5"/>
Modified: search/trunk/changelog.txt
===================================================================
--- search/trunk/changelog.txt 2008-11-13 16:02:44 UTC (rev 15563)
+++ search/trunk/changelog.txt 2008-11-14 11:10:15 UTC (rev 15564)
@@ -1,6 +1,9 @@
Hibernate Search Changelog
==========================
+3.1.0.CR1 (17-10-2008)
+------------------------
+
3.1.0.Beta2 (27-10-2008)
------------------------
Modified: search/trunk/doc/quickstart/pom.xml
===================================================================
--- search/trunk/doc/quickstart/pom.xml 2008-11-13 16:02:44 UTC (rev 15563)
+++ search/trunk/doc/quickstart/pom.xml 2008-11-14 11:10:15 UTC (rev 15564)
@@ -3,5 +3,5 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-quickstart</artifactId>
<packaging>jar</packaging>
- <version>3.1.0.Beta2</version>
+ <version>3.1.0.CR1</version>
</project>
Modified: search/trunk/doc/quickstart/src/main/resources/archetype-resources/pom.xml
===================================================================
--- search/trunk/doc/quickstart/src/main/resources/archetype-resources/pom.xml 2008-11-13 16:02:44 UTC (rev 15563)
+++ search/trunk/doc/quickstart/src/main/resources/archetype-resources/pom.xml 2008-11-14 11:10:15 UTC (rev 15564)
@@ -11,7 +11,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
- <version>3.1.0.Beta2</version>
+ <version>3.1.0.CR1</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
Modified: search/trunk/pom.xml
===================================================================
--- search/trunk/pom.xml 2008-11-13 16:02:44 UTC (rev 15563)
+++ search/trunk/pom.xml 2008-11-14 11:10:15 UTC (rev 15564)
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
- <version>3.1.0.Beta2</version>
+ <version>3.1.0.CR1</version>
<description>Hibernate Search</description>
<dependencies>
<dependency>
@@ -69,8 +69,18 @@
<version>2.4.0</version>
<optional>true</optional>
</dependency>
-
-
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-analyzers</artifactId>
+ <version>2.4.0</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.3</version>
+ <optional>true</optional>
+ </dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
Modified: search/trunk/readme.txt
===================================================================
--- search/trunk/readme.txt 2008-11-13 16:02:44 UTC (rev 15563)
+++ search/trunk/readme.txt 2008-11-14 11:10:15 UTC (rev 15564)
@@ -1,6 +1,6 @@
Hibernate Search
==================================================
-Version: 3.1.0.Beta2, 27.10.2008
+Version: 3.1.0.CR1, 17.11.2008
Description
-----------
Modified: search/trunk/src/java/org/hibernate/search/Version.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/Version.java 2008-11-13 16:02:44 UTC (rev 15563)
+++ search/trunk/src/java/org/hibernate/search/Version.java 2008-11-14 11:10:15 UTC (rev 15564)
@@ -12,7 +12,7 @@
* @author Emmanuel Bernard
*/
public class Version {
- public static final String VERSION = "3.1.0.Beta2";
+ public static final String VERSION = "3.1.0.CR1";
private static final Logger log = LoggerFactory.make();
15 years, 5 months
Hibernate SVN: r15563 - in search/trunk/src: java/org/hibernate/search/query and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-11-13 11:02:44 -0500 (Thu, 13 Nov 2008)
New Revision: 15563
Modified:
search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
search/trunk/src/java/org/hibernate/search/engine/DocumentExtractor.java
search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java
search/trunk/src/java/org/hibernate/search/query/QueryHits.java
search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java
Log:
HSEARCH-213
Applied patch and extented it to catch the TwoWayFieldBridge case. In order to to that I added a flag in DocumentBuilder. Unfortunately, I have 'drag' the flag along via FullTextQueryImpl into DocumentEctractor.
Modified: search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2008-11-13 15:40:37 UTC (rev 15562)
+++ search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2008-11-13 16:02:44 UTC (rev 15563)
@@ -2,9 +2,9 @@
package org.hibernate.search.engine;
import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.Method;
-import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -53,6 +53,7 @@
import org.hibernate.search.bridge.LuceneOptions;
import org.hibernate.search.bridge.TwoWayFieldBridge;
import org.hibernate.search.bridge.TwoWayString2FieldBridgeAdaptor;
+import org.hibernate.search.bridge.TwoWayStringBridge;
import org.hibernate.search.impl.InitContext;
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.store.IndexShardingStrategy;
@@ -61,7 +62,7 @@
import org.hibernate.search.util.ScopedAnalyzer;
/**
- * Set up and provide a manager for indexes classes
+ * Set up and provide a manager for indexed classes.
*
* @author Gavin King
* @author Emmanuel Bernard
@@ -82,6 +83,14 @@
* Flag indicating whether <code>@DocumentId</code> was explicitly specified.
*/
private boolean explicitDocumentId = false;
+
+ /**
+ * Flag indicating whether {@link org.apache.lucene.search.Searcher#doc(int, org.apache.lucene.document.FieldSelector)}
+ * can be used in order to retrieve documents. This is only safe to do if we know that
+ * all involved bridges are implementing <code>TwoWayStringBridge</code>. See HSEARCH-213.
+ */
+ private boolean allowFieldSelectionInProjection = false;
+
private XMember idGetter;
private Float idBoost;
public static final String CLASS_FIELDNAME = "_hibernate_class";
@@ -114,6 +123,25 @@
init( clazz, context, reflectionManager );
}
+ /**
+ * Constructor used on a non @Indexed entity.
+ */
+ public DocumentBuilder(XClass clazz, InitContext context, ReflectionManager reflectionManager) {
+ this.entityState = EntityState.CONTAINED_IN_ONLY;
+ this.beanClass = clazz;
+ this.directoryProviders = null;
+ this.shardingStrategy = null;
+
+
+ this.reflectionManager = reflectionManager;
+ this.similarity = context.getDefaultSimilarity();
+
+ init( clazz, context, reflectionManager );
+ if ( rootPropertiesMetadata.containedInGetters.size() == 0 ) {
+ this.entityState = EntityState.NON_INDEXABLE;
+ }
+ }
+
private void init(XClass clazz, InitContext context, ReflectionManager reflectionManager) {
if ( clazz == null ) throw new AssertionFailure( "Unable to build a DocumentBuilder with a null class" );
rootPropertiesMetadata.boost = getBoost( clazz );
@@ -131,34 +159,42 @@
idBridge = BridgeFactory.extractTwoWayType( provided.bridge() );
idKeywordName = provided.name();
}
+
//if composite id, use of (a, b) in ((1,2)TwoWayString2FieldBridgeAdaptor, (3,4)) fails on most database
//a TwoWayString2FieldBridgeAdaptor is never a composite id
safeFromTupleId = entityState != EntityState.INDEXED || TwoWayString2FieldBridgeAdaptor.class.isAssignableFrom( idBridge.getClass() );
+ checkAllowFieldSelection();
+ if ( log.isDebugEnabled() ) {
+ log.debug( "Field selection in projections is set to {} for entity {}.", allowFieldSelectionInProjection, clazz.getName() );
+ }
}
/**
- * Constructor used on a non @Indexed entity.
+ * Checks whether all involved bridges are two way string bridges. If so we can optimize document retrieval
+ * by using <code>FieldSelector</code>. See HSEARCH-213.
*/
- public DocumentBuilder(XClass clazz, InitContext context, ReflectionManager reflectionManager) {
- this.entityState = EntityState.CONTAINED_IN_ONLY;
- this.beanClass = clazz;
- this.directoryProviders = null;
- this.shardingStrategy = null;
-
-
- this.reflectionManager = reflectionManager;
- this.similarity = context.getDefaultSimilarity();
-
- init( clazz, context, reflectionManager );
- if ( rootPropertiesMetadata.containedInGetters.size() == 0 ) {
- this.entityState = EntityState.NON_INDEXABLE;
+ private void checkAllowFieldSelection() {
+ allowFieldSelectionInProjection = true;
+ if ( ! (idBridge instanceof TwoWayStringBridge || idBridge instanceof TwoWayString2FieldBridgeAdaptor) ) {
+ allowFieldSelectionInProjection = false;
+ return;
}
+ for ( FieldBridge bridge : rootPropertiesMetadata.fieldBridges) {
+ if ( !( bridge instanceof TwoWayStringBridge || bridge instanceof TwoWayString2FieldBridgeAdaptor ) ) {
+ allowFieldSelectionInProjection = false;
+ return;
+ }
+ }
}
public boolean isRoot() {
return isRoot;
}
+ public boolean allowFieldSelectionInProjection() {
+ return allowFieldSelectionInProjection;
+ }
+
private ProvidedId findProvidedId(XClass clazz, ReflectionManager reflectionManager) {
ProvidedId id = null;
XClass currentClass = clazz;
Modified: search/trunk/src/java/org/hibernate/search/engine/DocumentExtractor.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/DocumentExtractor.java 2008-11-13 15:40:37 UTC (rev 15562)
+++ search/trunk/src/java/org/hibernate/search/engine/DocumentExtractor.java 2008-11-13 16:02:44 UTC (rev 15563)
@@ -3,13 +3,21 @@
import java.io.IOException;
import java.io.Serializable;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
import org.apache.lucene.document.Document;
+import org.apache.lucene.document.FieldSelectorResult;
+import org.apache.lucene.document.MapFieldSelector;
+import org.apache.lucene.document.FieldSelector;
import org.hibernate.search.ProjectionConstants;
import org.hibernate.search.query.QueryHits;
/**
+ * Helper class to extract <code>EntityInfo</code>s out of the <code>QueryHits</code>.
+ *
* @author Emmanuel Bernard
* @author John Griffin
* @author Hardy Ferentschik
@@ -18,13 +26,44 @@
private final SearchFactoryImplementor searchFactoryImplementor;
private final String[] projection;
private final QueryHits queryHits;
+ private FieldSelector fieldSelector;
+ private boolean allowFieldSelection;
- public DocumentExtractor(QueryHits queryHits, SearchFactoryImplementor searchFactoryImplementor, String... projection) {
+ public DocumentExtractor(QueryHits queryHits, SearchFactoryImplementor searchFactoryImplementor, String[] projection, Set<String> idFieldNames, boolean allowFieldSelection) {
this.searchFactoryImplementor = searchFactoryImplementor;
this.projection = projection;
this.queryHits = queryHits;
+ this.allowFieldSelection = allowFieldSelection;
+ initFieldSelection( projection, idFieldNames );
}
+ private void initFieldSelection(String[] projection, Set<String> idFieldNames) {
+ // if we need to project DOCUMENT do not use fieldSelector as the user might want anything
+ int projectionSize = projection != null && projection.length != 0 ? projection.length : 0;
+ if ( projectionSize != 0 ) {
+ for ( String property : projection ) {
+ if ( ProjectionConstants.DOCUMENT.equals( property ) ) {
+ allowFieldSelection = false;
+ return;
+ }
+ }
+ }
+
+
+ // set up the field selector. CLASS_FIELDNAME and id fields are needed on top of any projected fields
+ Map<String, FieldSelectorResult> fields = new HashMap<String, FieldSelectorResult>( 1 + idFieldNames.size() + projectionSize );
+ fields.put( DocumentBuilder.CLASS_FIELDNAME, FieldSelectorResult.LOAD );
+ for ( String idFieldName : idFieldNames ) {
+ fields.put( idFieldName, FieldSelectorResult.LOAD );
+ }
+ if ( projectionSize != 0 ) {
+ for ( String projectedField : projection ) {
+ fields.put( projectedField, FieldSelectorResult.LOAD );
+ }
+ }
+ this.fieldSelector = new MapFieldSelector( fields );
+ }
+
private EntityInfo extract(Document document) {
Class clazz = DocumentBuilder.getDocumentClass( document );
Serializable id = DocumentBuilder.getDocumentId( searchFactoryImplementor, clazz, document );
@@ -36,7 +75,13 @@
}
public EntityInfo extract(int index) throws IOException {
- Document doc = queryHits.doc( index );
+ Document doc;
+ if ( allowFieldSelection ) {
+ doc = queryHits.doc( index, fieldSelector );
+ }
+ else {
+ doc = queryHits.doc( index );
+ }
//TODO if we are only looking for score (unlikely), avoid accessing doc (lazy load)
EntityInfo entityInfo = extract( doc );
Object[] eip = entityInfo.projection;
Modified: search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2008-11-13 15:40:37 UTC (rev 15562)
+++ search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2008-11-13 16:02:44 UTC (rev 15563)
@@ -63,7 +63,7 @@
import org.hibernate.transform.ResultTransformer;
/**
- * Implementation of {@link org.hibernate.search.FullTextQuery}
+ * Implementation of {@link org.hibernate.search.FullTextQuery}.
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
@@ -83,13 +83,20 @@
private Filter filter;
private Criteria criteria;
private String[] indexProjection;
+ private Set<String> idFieldNames;
+ private boolean allowFieldSelectionInProjection = true;
private ResultTransformer resultTransformer;
private SearchFactoryImplementor searchFactoryImplementor;
private Map<String, FullTextFilterImpl> filterDefinitions;
private int fetchSize = 1;
/**
- * classes must be immutable
+ * Constructs a <code>FullTextQueryImpl</code> instance.
+ *
+ * @param query The Lucene query
+ * @param classes Array of classes (must be immutable) used to filter the results to the given class types.
+ * @param session Access to the Hibernate session.
+ * @param parameterMetadata Additional query metadata.
*/
public FullTextQueryImpl(org.apache.lucene.search.Query query, Class[] classes, SessionImplementor session,
ParameterMetadata parameterMetadata) {
@@ -139,7 +146,9 @@
int size = max - first + 1 < 0 ? 0 : max - first + 1;
List<EntityInfo> infos = new ArrayList<EntityInfo>( size );
- DocumentExtractor extractor = new DocumentExtractor( queryHits, searchFactoryImplementor, indexProjection );
+ DocumentExtractor extractor = new DocumentExtractor(
+ queryHits, searchFactoryImplementor, indexProjection, idFieldNames, allowFieldSelectionInProjection
+ );
for ( int index = first; index <= max; index++ ) {
//TODO use indexSearcher.getIndexReader().document( hits.id(index), FieldSelector(indexProjection) );
infos.add( extractor.extract( index ) );
@@ -208,7 +217,7 @@
public ScrollableResults scroll() throws HibernateException {
//keep the searcher open until the resultset is closed
- SearchFactoryImplementor searchFactory = ContextHelper.getSearchFactoryBySFI( session );
+ SearchFactoryImplementor searchFactory = getSearchFactoryImplementor();
//find the directories
IndexSearcher searcher = buildSearcher( searchFactory );
@@ -217,7 +226,9 @@
QueryHits queryHits = getQueryHits( searcher );
int first = first();
int max = max( first, queryHits.totalHits );
- DocumentExtractor extractor = new DocumentExtractor( queryHits, searchFactory, indexProjection );
+ DocumentExtractor extractor = new DocumentExtractor(
+ queryHits, searchFactory, indexProjection, idFieldNames,allowFieldSelectionInProjection
+ );
Loader loader = getLoader( ( Session ) this.session, searchFactory );
return new ScrollableResultsImpl(
searcher, first, max, fetchSize, extractor, loader, searchFactory
@@ -241,7 +252,7 @@
}
public List list() throws HibernateException {
- SearchFactoryImplementor searchFactoryImplementor = ContextHelper.getSearchFactoryBySFI( session );
+ SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
//find the directories
IndexSearcher searcher = buildSearcher( searchFactoryImplementor );
if ( searcher == null ) {
@@ -255,7 +266,9 @@
int size = max - first + 1 < 0 ? 0 : max - first + 1;
List<EntityInfo> infos = new ArrayList<EntityInfo>( size );
- DocumentExtractor extractor = new DocumentExtractor( queryHits, searchFactoryImplementor, indexProjection );
+ DocumentExtractor extractor = new DocumentExtractor(
+ queryHits, searchFactoryImplementor, indexProjection, idFieldNames, allowFieldSelectionInProjection
+ );
for ( int index = first; index <= max; index++ ) {
infos.add( extractor.extract( index ) );
}
@@ -383,7 +396,7 @@
}
private Filter createFilter(FilterDef def, Object instance) {
- Filter filter = null;
+ Filter filter;
if ( def.getFactoryMethod() != null ) {
try {
filter = ( Filter ) def.getFactoryMethod().invoke( instance );
@@ -558,12 +571,16 @@
/**
- * can return null
+ * Build the index searcher for this fulltext query.
+ *
+ * @param searchFactoryImplementor the search factory.
+ * @return the <code>IndexSearcher</code> for this query (can be <code>null</code>.
* TODO change classesAndSubclasses by side effect, which is a mismatch with the Searcher return, fix that.
*/
private IndexSearcher buildSearcher(SearchFactoryImplementor searchFactoryImplementor) {
Map<Class<?>, DocumentBuilder<?>> builders = searchFactoryImplementor.getDocumentBuilders();
List<DirectoryProvider> directories = new ArrayList<DirectoryProvider>();
+ Set<String> idFieldNames = new HashSet<String>();
Similarity searcherSimilarity = null;
//TODO check if caching this work for the last n list of classes makes a perf boost
@@ -572,15 +589,19 @@
// but we have to make sure there is at least one
if ( builders.isEmpty() ) {
throw new HibernateException(
- "There are no mapped entities (don't forget to add @Indexed to at least one class)."
+ "There are no mapped entities. Don't forget to add @Indexed to at least one class."
);
}
for ( DocumentBuilder builder : builders.values() ) {
searcherSimilarity = checkSimilarity( searcherSimilarity, builder );
+ if ( builder.getIdKeywordName() != null ) {
+ idFieldNames.add( builder.getIdKeywordName() );
+ allowFieldSelectionInProjection = allowFieldSelectionInProjection && builder.allowFieldSelectionInProjection();
+ }
final DirectoryProvider[] directoryProviders = builder.getDirectoryProviderSelectionStrategy()
.getDirectoryProvidersForAllShards();
- populateDirectories( directories, directoryProviders, searchFactoryImplementor );
+ populateDirectories( directories, directoryProviders );
}
classesAndSubclasses = null;
}
@@ -600,14 +621,18 @@
if ( builder == null ) {
throw new HibernateException( "Not a mapped entity (don't forget to add @Indexed): " + clazz );
}
-
+ if ( builder.getIdKeywordName() != null ) {
+ idFieldNames.add( builder.getIdKeywordName() );
+ allowFieldSelectionInProjection = allowFieldSelectionInProjection && builder.allowFieldSelectionInProjection();
+ }
final DirectoryProvider[] directoryProviders = builder.getDirectoryProviderSelectionStrategy()
.getDirectoryProvidersForAllShards();
searcherSimilarity = checkSimilarity( searcherSimilarity, builder );
- populateDirectories( directories, directoryProviders, searchFactoryImplementor );
+ populateDirectories( directories, directoryProviders );
}
- classesAndSubclasses = involvedClasses;
+ this.classesAndSubclasses = involvedClasses;
}
+ this.idFieldNames = idFieldNames;
//compute optimization needClassFilterClause
//if at least one DP contains one class that is not part of the targeted classesAndSubclasses we can't optimize
@@ -643,8 +668,7 @@
return is;
}
- private void populateDirectories(List<DirectoryProvider> directories, DirectoryProvider[] directoryProviders,
- SearchFactoryImplementor searchFactoryImplementor) {
+ private void populateDirectories(List<DirectoryProvider> directories, DirectoryProvider[] directoryProviders) {
for ( DirectoryProvider provider : directoryProviders ) {
if ( !directories.contains( provider ) ) {
directories.add( provider );
@@ -677,7 +701,7 @@
public int getResultSize() {
if ( resultSize == null ) {
//get result size without object initialization
- SearchFactoryImplementor searchFactoryImplementor = ContextHelper.getSearchFactoryBySFI( session );
+ SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
IndexSearcher searcher = buildSearcher( searchFactoryImplementor );
if ( searcher == null ) {
resultSize = 0;
Modified: search/trunk/src/java/org/hibernate/search/query/QueryHits.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/query/QueryHits.java 2008-11-13 15:40:37 UTC (rev 15562)
+++ search/trunk/src/java/org/hibernate/search/query/QueryHits.java 2008-11-13 16:02:44 UTC (rev 15563)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -20,6 +20,7 @@
import java.io.IOException;
import org.apache.lucene.document.Document;
+import org.apache.lucene.document.FieldSelector;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.ScoreDoc;
@@ -59,6 +60,10 @@
return searcher.doc( docId( index ) );
}
+ public Document doc(int index, FieldSelector selector) throws IOException {
+ return searcher.doc( docId( index ), selector );
+ }
+
public ScoreDoc scoreDoc(int index) throws IOException {
if ( index >= totalHits ) {
throw new SearchException("Not a valid ScoreDoc index: " + index);
Modified: search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java 2008-11-13 15:40:37 UTC (rev 15562)
+++ search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java 2008-11-13 16:02:44 UTC (rev 15563)
@@ -12,6 +12,7 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
+
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.Transaction;
@@ -39,7 +40,15 @@
Query query = parser.parse( "dept:ITech" );
org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
// Is the 'FullTextQuery.ID' value correct here? Do we want the Lucene internal document number?
- hibQuery.setProjection( "id", "lastname", "dept", FullTextQuery.THIS, FullTextQuery.SCORE, FullTextQuery.DOCUMENT, FullTextQuery.ID );
+ hibQuery.setProjection(
+ "id",
+ "lastname",
+ "dept",
+ FullTextQuery.THIS,
+ FullTextQuery.SCORE,
+ FullTextQuery.DOCUMENT,
+ FullTextQuery.ID
+ );
ScrollableResults projections = hibQuery.scroll();
@@ -78,7 +87,9 @@
assertNull( projection );
//cleanup
- for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
+ for ( Object element : s.createQuery( "from " + Employee.class.getName() ).list() ) {
+ s.delete( element );
+ }
tx.commit();
s.close();
}
@@ -97,7 +108,8 @@
hibQuery.setProjection( "id", "lastname", "dept", FullTextQuery.THIS, FullTextQuery.SCORE, FullTextQuery.ID );
hibQuery.setResultTransformer( new ProjectionToDelimStringResultTransformer() );
- List<String> result = (List<String>) hibQuery.list();
+ @SuppressWarnings( "unchecked" )
+ List<String> result = hibQuery.list();
assertTrue( "incorrect transformation", result.get( 0 ).startsWith( "1000, Griffin, ITech" ) );
assertTrue( "incorrect transformation", result.get( 1 ).startsWith( "1002, Jimenez, ITech" ) );
@@ -120,19 +132,29 @@
Query query = parser.parse( "dept:ITech" );
org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
- hibQuery.setProjection( "id", "lastname", "dept", FullTextQuery.THIS, FullTextQuery.SCORE, FullTextQuery.DOCUMENT, FullTextQuery.ID );
+ hibQuery.setProjection(
+ "id",
+ "lastname",
+ "dept",
+ FullTextQuery.THIS,
+ FullTextQuery.SCORE,
+ FullTextQuery.DOCUMENT,
+ FullTextQuery.ID
+ );
hibQuery.setResultTransformer( new ProjectionToMapResultTransformer() );
List transforms = hibQuery.list();
- Map map = (Map) transforms.get( 1 );
+ Map map = ( Map ) transforms.get( 1 );
assertEquals( "incorrect transformation", "ITech", map.get( "dept" ) );
assertEquals( "incorrect transformation", 1002, map.get( "id" ) );
assertTrue( "incorrect transformation", map.get( FullTextQuery.DOCUMENT ) instanceof Document );
- assertEquals( "incorrect transformation", "1002", ( (Document) map.get( FullTextQuery.DOCUMENT ) ).get( "id" ) );
+ assertEquals(
+ "incorrect transformation", "1002", ( ( Document ) map.get( FullTextQuery.DOCUMENT ) ).get( "id" )
+ );
//cleanup
- for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) {
+ for ( Object element : s.createQuery( "from " + Employee.class.getName() ).list() ) {
s.delete( element );
}
tx.commit();
@@ -143,10 +165,10 @@
assertEquals( "id incorrect", 1000, projection[0] );
assertEquals( "lastname incorrect", "Griffin", projection[1] );
assertEquals( "dept incorrect", "ITech", projection[2] );
- assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, (Serializable) projection[0] ) );
+ assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
assertEquals( "SCORE incorrect", 1.0F, projection[4] );
assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
- assertEquals( "DOCUMENT size incorrect", 4, ( (Document) projection[5] ).getFields().size() );
+ assertEquals( "DOCUMENT size incorrect", 4, ( ( Document ) projection[5] ).getFields().size() );
assertEquals( "legacy ID incorrect", 1000, projection[6] );
}
@@ -154,10 +176,10 @@
assertEquals( "id incorrect", 1004, projection[0] );
assertEquals( "lastname incorrect", "Whetbrook", projection[1] );
assertEquals( "dept incorrect", "ITech", projection[2] );
- assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, (Serializable) projection[0] ) );
+ assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
assertEquals( "SCORE incorrect", 1.0F, projection[4] );
assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
- assertEquals( "DOCUMENT size incorrect", 4, ( (Document) projection[5] ).getFields().size() );
+ assertEquals( "DOCUMENT size incorrect", 4, ( ( Document ) projection[5] ).getFields().size() );
assertEquals( "legacy ID incorrect", 1004, projection[6] );
}
@@ -165,10 +187,10 @@
assertEquals( "id incorrect", 1003, projection[0] );
assertEquals( "lastname incorrect", "Stejskal", projection[1] );
assertEquals( "dept incorrect", "ITech", projection[2] );
- assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, (Serializable) projection[0] ) );
+ assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
assertEquals( "SCORE incorrect", 1.0F, projection[4] );
assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
- assertEquals( "DOCUMENT size incorrect", 4, ( (Document) projection[5] ).getFields().size() );
+ assertEquals( "DOCUMENT size incorrect", 4, ( ( Document ) projection[5] ).getFields().size() );
assertEquals( "legacy ID incorrect", 1003, projection[6] );
}
@@ -183,25 +205,29 @@
Query query = parser.parse( "dept:ITech" );
org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
- hibQuery.setProjection( "id", "lastname", "dept", FullTextQuery.THIS, FullTextQuery.SCORE,
- FullTextQuery.DOCUMENT, FullTextQuery.ID );
+ hibQuery.setProjection(
+ "id", "lastname", "dept", FullTextQuery.THIS, FullTextQuery.SCORE,
+ FullTextQuery.DOCUMENT, FullTextQuery.ID
+ );
int counter = 0;
- for (Iterator iter = hibQuery.iterate(); iter.hasNext();) {
- Object[] projection = (Object[]) iter.next();
+ for ( Iterator iter = hibQuery.iterate(); iter.hasNext(); ) {
+ Object[] projection = ( Object[] ) iter.next();
assertNotNull( projection );
counter++;
assertEquals( "dept incorrect", "ITech", projection[2] );
- assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, (Serializable) projection[0] ) );
+ assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
assertEquals( "SCORE incorrect", 1.0F, projection[4] );
assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
- assertEquals( "DOCUMENT size incorrect", 4, ( (Document) projection[5] ).getFields().size() );
+ assertEquals( "DOCUMENT size incorrect", 4, ( ( Document ) projection[5] ).getFields().size() );
}
assertEquals( "incorrect number of results returned", 4, counter );
//cleanup
- for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
+ for ( Object element : s.createQuery( "from " + Employee.class.getName() ).list() ) {
+ s.delete( element );
+ }
tx.commit();
s.close();
}
@@ -217,38 +243,42 @@
Query query = parser.parse( "dept:Accounting" );
org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
- hibQuery.setProjection( "id", "lastname", "dept", FullTextQuery.THIS, FullTextQuery.SCORE,
- FullTextQuery.DOCUMENT, FullTextQuery.ID, FullTextQuery.DOCUMENT_ID );
+ hibQuery.setProjection(
+ "id", "lastname", "dept", FullTextQuery.THIS, FullTextQuery.SCORE,
+ FullTextQuery.DOCUMENT, FullTextQuery.ID, FullTextQuery.DOCUMENT_ID
+ );
List result = hibQuery.list();
assertNotNull( result );
- Object[] projection = (Object[]) result.get( 0 );
+ Object[] projection = ( Object[] ) result.get( 0 );
assertNotNull( projection );
assertEquals( "id incorrect", 1001, projection[0] );
assertEquals( "last name incorrect", "Jackson", projection[1] );
assertEquals( "dept incorrect", "Accounting", projection[2] );
- assertEquals( "THIS incorrect", "Jackson", ( (Employee) projection[3] ).getLastname() );
- assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, (Serializable) projection[0] ) );
+ assertEquals( "THIS incorrect", "Jackson", ( ( Employee ) projection[3] ).getLastname() );
+ assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
assertEquals( "SCORE incorrect", 1.9162908F, projection[4] );
assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
- assertEquals( "DOCUMENT size incorrect", 5, ( (Document) projection[5] ).getFields().size() );
+ assertEquals( "DOCUMENT size incorrect", 5, ( ( Document ) projection[5] ).getFields().size() );
assertEquals( "ID incorrect", 1001, projection[6] );
assertNotNull( "Lucene internal doc id", projection[7] );
// Change the projection order and null one
- hibQuery.setProjection( FullTextQuery.DOCUMENT, FullTextQuery.THIS, FullTextQuery.SCORE, null, FullTextQuery.ID,
- "id", "lastname", "dept", "hireDate", FullTextQuery.DOCUMENT_ID );
+ hibQuery.setProjection(
+ FullTextQuery.DOCUMENT, FullTextQuery.THIS, FullTextQuery.SCORE, null, FullTextQuery.ID,
+ "id", "lastname", "dept", "hireDate", FullTextQuery.DOCUMENT_ID
+ );
result = hibQuery.list();
assertNotNull( result );
- projection = (Object[]) result.get( 0 );
+ projection = ( Object[] ) result.get( 0 );
assertNotNull( projection );
assertTrue( "DOCUMENT incorrect", projection[0] instanceof Document );
- assertEquals( "DOCUMENT size incorrect", 5, ( (Document) projection[0] ).getFields().size() );
- assertEquals( "THIS incorrect", projection[1], s.get( Employee.class, (Serializable) projection[4] ) );
+ assertEquals( "DOCUMENT size incorrect", 5, ( ( Document ) projection[0] ).getFields().size() );
+ assertEquals( "THIS incorrect", projection[1], s.get( Employee.class, ( Serializable ) projection[4] ) );
assertEquals( "SCORE incorrect", 1.9162908F, projection[2] );
assertNull( "BOOST not removed", projection[3] );
assertEquals( "ID incorrect", 1001, projection[4] );
@@ -259,11 +289,59 @@
assertNotNull( "Lucene internal doc id", projection[9] );
//cleanup
- for (Object element : s.createQuery( "from " + Employee.class.getName() ).list()) s.delete( element );
+ for ( Object element : s.createQuery( "from " + Employee.class.getName() ).list() ) {
+ s.delete( element );
+ }
tx.commit();
s.close();
}
+ public void testNonLoadedFieldOptmization() throws Exception {
+ FullTextSession s = Search.getFullTextSession( openSession() );
+ prepEmployeeIndex( s );
+
+ Transaction tx;
+ s.clear();
+ tx = s.beginTransaction();
+ QueryParser parser = new QueryParser( "dept", new StandardAnalyzer() );
+
+ Query query = parser.parse( "dept:Accounting" );
+ org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Employee.class );
+ hibQuery.setProjection( FullTextQuery.ID, FullTextQuery.DOCUMENT );
+
+ List result = hibQuery.list();
+ assertNotNull( result );
+
+ Object[] projection = ( Object[] ) result.get( 0 );
+ assertNotNull( projection );
+ assertEquals( "id field name not projected", 1001, projection[0] );
+ assertEquals(
+ "Document fields should not be lazy on DOCUMENT projection",
+ "Jackson", ( ( Document ) projection[1] ).getField( "lastname" ).stringValue()
+ );
+ assertEquals( "DOCUMENT size incorrect", 5, ( ( Document ) projection[1] ).getFields().size() );
+
+ // Change the projection order and null one
+ hibQuery.setProjection( FullTextQuery.THIS, FullTextQuery.SCORE, null, "lastname" );
+
+ result = hibQuery.list();
+ assertNotNull( result );
+
+ projection = ( Object[] ) result.get( 0 );
+ assertNotNull( projection );
+
+ assertTrue( "THIS incorrect", projection[0] instanceof Employee );
+ assertEquals( "SCORE incorrect", 1.9162908F, projection[1] );
+ assertEquals( "last name incorrect", "Jackson", projection[3] );
+
+ //cleanup
+ for ( Object element : s.createQuery( "from " + Employee.class.getName() ).list() ) {
+ s.delete( element );
+ }
+ tx.commit();
+ s.close();
+ }
+
private void prepEmployeeIndex(FullTextSession s) {
Transaction tx = s.beginTransaction();
Employee e1 = new Employee( 1000, "Griffin", "ITech" );
@@ -284,7 +362,11 @@
public void testProjection() throws Exception {
FullTextSession s = Search.getFullTextSession( openSession() );
Transaction tx = s.beginTransaction();
- Book book = new Book( 1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah" );
+ Book book = new Book(
+ 1,
+ "La chute de la petite reine a travers les yeux de Festina",
+ "La chute de la petite reine a travers les yeux de Festina, blahblah"
+ );
s.save( book );
Book book2 = new Book( 2, "Sous les fleurs il n'y a rien", null );
s.save( book2 );
@@ -304,7 +386,7 @@
List result = hibQuery.list();
assertNotNull( result );
assertEquals( "Query with no explicit criteria", 1, result.size() );
- Object[] projection = (Object[]) result.get( 0 );
+ Object[] projection = ( Object[] ) result.get( 0 );
assertEquals( "id", 1, projection[0] );
assertEquals( "summary", "La chute de la petite reine a travers les yeux de Festina", projection[1] );
assertEquals( "mainAuthor.name (embedded objects)", "Emmanuel", projection[2] );
@@ -313,10 +395,10 @@
hibQuery.setProjection( "id", "body", "mainAuthor.name" );
try {
- result = hibQuery.list();
+ hibQuery.list();
fail( "Projecting an unstored field should raise an exception" );
}
- catch (SearchException e) {
+ catch ( SearchException e ) {
//success
}
@@ -340,12 +422,16 @@
hibQuery.setProjection( "id", "summary", "mainAuthor.name" );
result = hibQuery.list();
assertEquals( 1, result.size() );
- projection = (Object[]) result.get( 0 );
+ projection = ( Object[] ) result.get( 0 );
assertEquals( "mainAuthor.name", null, projection[2] );
//cleanup
- for (Object element : s.createQuery( "from " + Book.class.getName() ).list()) s.delete( element );
- for (Object element : s.createQuery( "from " + Author.class.getName() ).list()) s.delete( element );
+ for ( Object element : s.createQuery( "from " + Book.class.getName() ).list() ) {
+ s.delete( element );
+ }
+ for ( Object element : s.createQuery( "from " + Author.class.getName() ).list() ) {
+ s.delete( element );
+ }
tx.commit();
s.close();
}
15 years, 5 months
Hibernate SVN: r15562 - search/trunk/src/test/org/hibernate/search/test/id.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-11-13 10:40:37 -0500 (Thu, 13 Nov 2008)
New Revision: 15562
Modified:
search/trunk/src/test/org/hibernate/search/test/id/PersonPKBridge.java
Log:
code formatting
Modified: search/trunk/src/test/org/hibernate/search/test/id/PersonPKBridge.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/id/PersonPKBridge.java 2008-11-13 15:39:23 UTC (rev 15561)
+++ search/trunk/src/test/org/hibernate/search/test/id/PersonPKBridge.java 2008-11-13 15:40:37 UTC (rev 15562)
@@ -3,6 +3,7 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
+
import org.hibernate.search.bridge.LuceneOptions;
import org.hibernate.search.bridge.TwoWayFieldBridge;
@@ -21,26 +22,44 @@
}
public String objectToString(Object object) {
- PersonPK id = (PersonPK) object;
+ PersonPK id = ( PersonPK ) object;
StringBuilder sb = new StringBuilder();
sb.append( id.getFirstName() ).append( " " ).append( id.getLastName() );
return sb.toString();
}
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
- PersonPK id = (PersonPK) value;
+ PersonPK id = ( PersonPK ) value;
//store each property in a unique field
- Field field = new Field( name + ".firstName", id.getFirstName(), luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
+ Field field = new Field(
+ name + ".firstName",
+ id.getFirstName(),
+ luceneOptions.getStore(),
+ luceneOptions.getIndex(),
+ luceneOptions.getTermVector()
+ );
field.setBoost( luceneOptions.getBoost() );
document.add( field );
-
- field = new Field( name + ".lastName", id.getLastName(), luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
+
+ field = new Field(
+ name + ".lastName",
+ id.getLastName(),
+ luceneOptions.getStore(),
+ luceneOptions.getIndex(),
+ luceneOptions.getTermVector()
+ );
field.setBoost( luceneOptions.getBoost() );
document.add( field );
//store the unique string representation in the named field
- field = new Field( name, objectToString( id ), luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
+ field = new Field(
+ name,
+ objectToString( id ),
+ luceneOptions.getStore(),
+ luceneOptions.getIndex(),
+ luceneOptions.getTermVector()
+ );
field.setBoost( luceneOptions.getBoost() );
document.add( field );
}
15 years, 5 months
Hibernate SVN: r15561 - search/trunk/src/java/org/hibernate/search/util.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-11-13 10:39:23 -0500 (Thu, 13 Nov 2008)
New Revision: 15561
Modified:
search/trunk/src/java/org/hibernate/search/util/ContextHelper.java
Log:
Javadoc changes.
Modified: search/trunk/src/java/org/hibernate/search/util/ContextHelper.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/util/ContextHelper.java 2008-11-13 15:38:44 UTC (rev 15560)
+++ search/trunk/src/java/org/hibernate/search/util/ContextHelper.java 2008-11-13 15:39:23 UTC (rev 15561)
@@ -10,7 +10,7 @@
/**
* @author Emmanuel Bernard
- * @deprecated Use fullTextSession.getSearchFactory() instead
+ * @deprecated Use {@link org.hibernate.search.FullTextSession#getSearchFactory()} instead.
*/
public abstract class ContextHelper {
15 years, 5 months
Hibernate SVN: r15560 - in search/trunk/src/java/org/hibernate/search/bridge: builtin and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-11-13 10:38:44 -0500 (Thu, 13 Nov 2008)
New Revision: 15560
Modified:
search/trunk/src/java/org/hibernate/search/bridge/StringBridge.java
search/trunk/src/java/org/hibernate/search/bridge/TwoWayFieldBridge.java
search/trunk/src/java/org/hibernate/search/bridge/TwoWayStringBridge.java
search/trunk/src/java/org/hibernate/search/bridge/builtin/UrlBridge.java
Log:
Javadoc changes.
Modified: search/trunk/src/java/org/hibernate/search/bridge/StringBridge.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/StringBridge.java 2008-11-13 10:56:39 UTC (rev 15559)
+++ search/trunk/src/java/org/hibernate/search/bridge/StringBridge.java 2008-11-13 15:38:44 UTC (rev 15560)
@@ -14,8 +14,7 @@
public interface StringBridge {
/**
- * convert the object representation to a String
- * The return String must not be null, it can be empty though
+ * {@inheritDoc}
*/
String objectToString(Object object);
}
Modified: search/trunk/src/java/org/hibernate/search/bridge/TwoWayFieldBridge.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/TwoWayFieldBridge.java 2008-11-13 10:56:39 UTC (rev 15559)
+++ search/trunk/src/java/org/hibernate/search/bridge/TwoWayFieldBridge.java 2008-11-13 15:38:44 UTC (rev 15560)
@@ -4,28 +4,29 @@
import org.apache.lucene.document.Document;
/**
- * A FieldBrige able to convert the index representation back into an object without losing information
+ * A <code>FieldBridge</code> able to convert the index representation back into an object without losing information.
+ * Any bridge expected to process a document id should implement this interface.
*
- * Any bridge expected to process a document id should implement this interface
- * EXPERIMENTAL Consider this interface as private
- *
* @author Emmanuel Bernard
*/
-//FIXME rework the interface inheritance there are some common concepts with StringBridge
+// FIXME rework the interface inheritance there are some common concepts with StringBridge
public interface TwoWayFieldBridge extends FieldBridge {
/**
- * build the element object from the Document
+ * Build the element object from the <code>Document</code>
*
- * The return value is the Entity id
+ * @param name field name
+ * @param document document
*
- * @param name field name
- * @param document document
+ * @return The return value is the entity property value.
*/
Object get(String name, Document document);
/**
- * convert the object representation to a String
- * The return String must not be null, it can be empty though
+ * Convert the object representation to a string.
+ *
+ * @param object The object to index.
+ * @return string (index) representationT of the specified object. Must not be <code>null</code>, but
+ * can be empty.
*/
String objectToString(Object object);
}
Modified: search/trunk/src/java/org/hibernate/search/bridge/TwoWayStringBridge.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/TwoWayStringBridge.java 2008-11-13 10:56:39 UTC (rev 15559)
+++ search/trunk/src/java/org/hibernate/search/bridge/TwoWayStringBridge.java 2008-11-13 15:38:44 UTC (rev 15560)
@@ -14,8 +14,9 @@
* @author Emmanuel Bernard
*/
public interface TwoWayStringBridge extends StringBridge {
+
/**
- * Convert the string representation to an object
+ * {@inheritDoc}
*/
Object stringToObject(String stringValue);
}
Modified: search/trunk/src/java/org/hibernate/search/bridge/builtin/UrlBridge.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/builtin/UrlBridge.java 2008-11-13 10:56:39 UTC (rev 15559)
+++ search/trunk/src/java/org/hibernate/search/bridge/builtin/UrlBridge.java 2008-11-13 15:38:44 UTC (rev 15560)
@@ -9,7 +9,7 @@
import org.hibernate.annotations.common.util.StringHelper;
/**
- * Bridge for <code>URL</code>
+ * Bridge for <code>URL</code>s.
*
* @author Emmanuel Bernard
*/
@@ -20,10 +20,10 @@
}
else {
try {
- return new URL(stringValue);
+ return new URL( stringValue );
}
- catch (MalformedURLException e) {
- throw new SearchException("Unable to build URL: " + stringValue, e);
+ catch ( MalformedURLException e ) {
+ throw new SearchException( "Unable to build URL: " + stringValue, e );
}
}
}
15 years, 5 months
Hibernate SVN: r15559 - in search/trunk/doc/reference/en: modules and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-11-13 05:56:39 -0500 (Thu, 13 Nov 2008)
New Revision: 15559
Modified:
search/trunk/doc/reference/en/master.xml
search/trunk/doc/reference/en/modules/getting-started.xml
search/trunk/doc/reference/en/modules/mapping.xml
Log:
started a full review of the online docs - more to come ;-)
Modified: search/trunk/doc/reference/en/master.xml
===================================================================
--- search/trunk/doc/reference/en/master.xml 2008-11-12 22:24:55 UTC (rev 15558)
+++ search/trunk/doc/reference/en/master.xml 2008-11-13 10:56:39 UTC (rev 15559)
@@ -23,12 +23,12 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
- <!ENTITY versionNumber "3.1.0.CR1">
- <!ENTITY copyrightYear "2004">
- <!ENTITY copyrightHolder "Red Hat Middleware, LLC.">
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+<!ENTITY versionNumber "3.1.0.CR1">
+<!ENTITY copyrightYear "2004">
+<!ENTITY copyrightHolder "Red Hat Middleware, LLC.">
]>
-
<book lang="en">
<bookinfo>
<title>Hibernate Search</title>
@@ -51,30 +51,42 @@
<preface id="preface" revision="2">
<title>Preface</title>
- <para>Full text search engines like <productname>Apache
- Lucene</productname> are very powerful technologies to add efficient free
- text search capabilities to applications. However, they suffer several mismatches when
- dealing with object domain models. Amongst other things indexes have to be kept up to date and
- mismatches between index structure and domain model as well as query mismatches
- have to be avoided.
- </para>
- <para>
- Hibernate Search indexes your domain model with the help of a few annotations,
- takes care of database/index synchronization and brings back
- regular managed objects from free text queries. To achieve this Hibernate Search
- is combining the power of <ulink url="http://www.hibernate.org">Hibernate</ulink> and
- <ulink url="http://lucene.apache.org">Apache Lucene</ulink>.
- </para>
+ <para>Full text search engines like Apache Lucene are very powerful
+ technologies to add efficient free text search capabilities to
+ applications. However, they suffer several mismatches when dealing with
+ object domain models. Amongst other things indexes have to be kept up to
+ date and mismatches between index structure and domain model as well as
+ query mismatches have to be avoided.</para>
+ <para>Hibernate Search indexes your domain model with the help of a few
+ annotations, takes care of database/index synchronization and brings back
+ regular managed objects from free text queries. To achieve this Hibernate
+ Search is combining the power of <ulink
+ url="http://www.hibernate.org">Hibernate</ulink> and <ulink
+ url="http://lucene.apache.org">Apache Lucene</ulink>.</para>
</preface>
- <xi:include href="modules/getting-started.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/architecture.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/configuration.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/mapping.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/query.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/batchindex.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/optimize.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/lucene-native.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="modules/getting-started.xml"
+ xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="modules/architecture.xml"
+ xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="modules/configuration.xml"
+ xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="modules/mapping.xml"
+ xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="modules/query.xml"
+ xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="modules/batchindex.xml"
+ xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="modules/optimize.xml"
+ xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="modules/lucene-native.xml"
+ xmlns:xi="http://www.w3.org/2001/XInclude" />
</book>
Modified: search/trunk/doc/reference/en/modules/getting-started.xml
===================================================================
--- search/trunk/doc/reference/en/modules/getting-started.xml 2008-11-12 22:24:55 UTC (rev 15558)
+++ search/trunk/doc/reference/en/modules/getting-started.xml 2008-11-13 10:56:39 UTC (rev 15559)
@@ -48,8 +48,7 @@
<entry>A JDK or JRE version <emphasis>5</emphasis> or greater. You
can download a Java Runtime for Windows/Linux/Solaris <ulink
- url="http://java.sun.com/javase/downloads/"> here
- </ulink>.</entry>
+ url="http://java.sun.com/javase/downloads/">here</ulink>.</entry>
</row>
<row>
@@ -57,7 +56,7 @@
<entry><literal>hibernate-search.jar</literal> and all the
dependencies from the <literal>lib</literal> directory of the
- Hibernate Search distribution, especially lucene :)</entry>
+ Hibernate Search distribution, especially lucene.</entry>
</row>
<row>
@@ -120,7 +119,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
- <version>3.1.0.Beta2</version>
+ <version>3.1.0.CR1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
@@ -151,18 +150,18 @@
<para>Not all dependencies are required. Only the
<emphasis>hibernate-search</emphasis> dependeny is mandatory. This
- dependeny, together with its required transitive dependencies, contains
- everything needed to use Hibernate Search.
+ dependency, together with its required transitive dependencies, contain
+ all required classes needed to use Hibernate Search.
<emphasis>hibernate-annotations</emphasis> is only needed if you want to
use annotations to configure your domain model as we do in this tutorial.
- However, even if you choose not to use Hibernate Annotations you will
- still have to use the Hibernate Search specific annotations to configure
- your Lucene index. Currently there is no XML configuration option
- available for Hibernate Search.
+ However, even if you choose not to use Hibernate Annotations you still
+ have to use the Hibernate Search specific annotations, which are bundled
+ with the hibernate-search jar file, to configure your Lucene index.
+ Currently there is no XML configuration available for Hibernate Search.
<emphasis>hibernate-entitymanager</emphasis> is required if you want to
use Hibernate Search in conjunction with JPA. Finally, the Solr
- dependencies are only needed if you want to utilize Solr's analyzer
- framework. More about this later.</para>
+ dependencies are needed if you want to utilize Solr's analyzer framework.
+ More about this later.</para>
</section>
<section>
@@ -175,8 +174,8 @@
<literal>hibernate.cfg.xml</literal>. If you are using Hibernate via JPA
you can also add the properties to <literal>persistence.xml</literal>. The
good news is that for standard use most properties offer a sensible
- default. Within <filename>persistence.xml</filename> this could look like
- this:</para>
+ default. An example <filename>persistence.xml</filename> configuration
+ could look like this:</para>
<para><programlisting>
...
@@ -188,8 +187,8 @@
</programlisting>First you have to tell Hibernate Search which
<classname>DirectoryProvider</classname> to use. This can be achieved by
setting the <literal>hibernate.search.default.directory_provider</literal>
- property. Apache Lucene has a notion of <literal>Directory</literal> to
- store the index files. Hibernate Search handles the initialization and
+ property. Apache Lucene has the notion of a <literal>Directory</literal>
+ to store the index files. Hibernate Search handles the initialization and
configuration of a Lucene <literal>Directory</literal> instance via a
<literal>DirectoryProvider</literal>. In this tutorial we will use a
subclass of <literal>DirectoryProvider</literal> called
@@ -202,8 +201,8 @@
for all indexes via
<literal>hibernate.search.default.indexBase</literal>.</para>
- <para>Lets further assume that your application contains the Hibernate
- managed classes <classname>example.Book</classname> and
+ <para>Lets assume that your application contains the Hibernate managed
+ classes <classname>example.Book</classname> and
<classname>example.Author</classname> and you want to add free text search
capabilities to your application in order to search the books contained in
your database.</para>
@@ -262,8 +261,10 @@
<classname>Book</classname> as indexable. By design Hibernate Search needs
to store an untokenized id in the index to ensure index unicity for a
given entity. <literal>@DocumentId</literal> marks the property to use for
- this purpose and is in most cases the same as the database primary
- key.</para>
+ this purpose and is in most cases the same as the database primary key. In
+ fact since the latest release of Hibernate Search
+ <literal>@DocumentId</literal> is optional in the case where an
+ <classname>@Id</classname> annotation exists.</para>
<para>Next you have to mark the fields you want to make searchable. Let's
start with <literal>title</literal> and <literal>subtitle</literal> and
@@ -275,16 +276,15 @@
talk more about analyzers a little later on. The second parameter we
specify within <literal>@Field</literal>,<literal>
store=Store.NO</literal>, ensures that the actual data will not be stored
- in the index. This is the default settings and probably a good choice
+ in the index. This is the default setting and probably a good choice
unless you want to avoid database roundtrips and retrieve the indexed data
via projections (<xref linkend="projections" />). Without projections,
Hibernate Search will per default execute the Lucene query in order to
find the database identifiers of the entities matching the query critera
and use these identifiers to retrieve managed objects from the database.
- Is it not better then to always use projections? The answer is no, since
- projections only returns object arrays and not managed entities. The
- decision for or against projection has to be made on a case to case
- basis.</para>
+ The decision for or against projection has to be made on a case to case
+ basis. The default behaviour is recommended since it returns managed
+ objects whereas projections only returns object arrays. </para>
<para>After this short look under the hood let's go back to annotating the
<classname>Book</classname> class. Another annotation we have not yet
@@ -404,8 +404,9 @@
<para>After executing the above code, you should be able to see a Lucene
index under <literal>/var/lucene/indexes/example.Book</literal>. Go ahead
- an inspect this index. It will help you to understand how Hibernate Search
- works.</para>
+ an inspect this index with <ulink
+ url="http://www.getopt.org/luke/">Luke</ulink>. It will help you to
+ understand how Hibernate Search works.</para>
</section>
<section>
@@ -422,10 +423,10 @@
Transaction tx = fullTextSession.beginTransaction();
-MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{"title", "subtitle", "authors.name", "publicationDate"},
- new StandardAnalyzer());
+String[] fields = new String[]{"title", "subtitle", "authors.name", "publicationDate"};
+MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
Query query = parser.parse( "Java rocks!" );
-org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery( query, Book.class );
+org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, Book.class);
List result = hibQuery.list();
tx.commit();
@@ -439,10 +440,10 @@
FullTextEntityManager fullTextEntityManager =
org.hibernate.hibernate.search.jpa.Search.getFullTextEntityManager(em);
-MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{"title", "subtitle", "authors.name", "publicationDate"},
- new StandardAnalyzer());
+String[] fields = new String[]{"title", "subtitle", "authors.name", "publicationDate"};
+MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
Query query = parser.parse( "Java rocks!" );
-org.hibernate.Query hibQuery = fullTextEntityManager.createFullTextQuery( query, Book.class );
+org.hibernate.Query hibQuery = fullTextEntityManager.createFullTextQuery(query, Book.class);
List result = hibQuery.list();
</programlisting>
</section>
@@ -450,14 +451,14 @@
<section>
<title>Analyzer</title>
- <para>Assume that one of your indexed book entities has the title
- "Refactoring: Improving the Design of Existing Code" and you want to get
- hits for all of the following queries: "refactor", "refactors",
- "refactored" and "refactoring". In Lucene this can be achieved by choosing
- an analyzer class which applies word stemming during the indexing
- <emphasis role="bold">and</emphasis> search process. Hibernate Search
- offers several ways to configure the analyzer to use (see <xref
- linkend="analyzer" />):</para>
+ <para>Let's make things a little more interesting now. Assume that one of
+ your indexed book entities has the title "Refactoring: Improving the
+ Design of Existing Code" and you want to get hits for all of the following
+ queries: "refactor", "refactors", "refactored" and "refactoring". In
+ Lucene this can be achieved by choosing an analyzer class which applies
+ word stemming during the indexing <emphasis role="bold">and</emphasis>
+ search process. Hibernate Search offers several ways to configure the
+ analyzer to use (see <xref linkend="analyzer" />):</para>
<itemizedlist>
<listitem>
@@ -488,7 +489,7 @@
Wiki.</ulink> Note that depending on the chosen factory class additional
libraries on top of the Solr dependencies might be required. For example,
the <classname>PhoneticFilterFactory</classname> depends on <ulink
- url="http://commons.apache.org/codec">commons-codec</ulink>. </para>
+ url="http://commons.apache.org/codec">commons-codec</ulink>.</para>
<para>In the example below a
<classname>StandardTokenizerFactory</classname> is used followed by two
@@ -561,7 +562,7 @@
<para><programlisting>mvn archetype:create \
-DarchetypeGroupId=org.hibernate \
-DarchetypeArtifactId=hibernate-search-quickstart \
- -DarchetypeVersion=3.1.0.Beta2 \
+ -DarchetypeVersion=3.1.0.CR1 \
-DgroupId=my.company -DartifactId=quickstart</programlisting>Using the
maven project you can execute the examples, inspect the file system based
index and search and retrieve a list of managed objects. Just run
Modified: search/trunk/doc/reference/en/modules/mapping.xml
===================================================================
--- search/trunk/doc/reference/en/modules/mapping.xml 2008-11-12 22:24:55 UTC (rev 15558)
+++ search/trunk/doc/reference/en/modules/mapping.xml 2008-11-13 10:56:39 UTC (rev 15559)
@@ -183,8 +183,10 @@
<para>Finally, the id property of an entity is a special property used
by Hibernate Search to ensure index unicity of a given entity. By
design, an id has to be stored and must not be tokenized. To mark a
- property as index id, use the <literal>@DocumentId</literal>
- annotation.</para>
+ property as index id, use the <literal>@DocumentId</literal> annotation.
+ If you are using Hibernate Annotations and you have specified @Id you
+ can omit @DocumentId. The chosen entity id will also be used as document
+ id.</para>
<programlisting>@Entity
@Indexed(index="indexes/essays")
@@ -206,13 +208,7 @@
<para>These annotations define an index with three fields:
<literal>id</literal> , <literal>Abstract</literal> and
<literal>text</literal> . Note that by default the field name is
- decapitalized, following the JavaBean specification.</para>
-
- <note>
- <para>You <emphasis>must</emphasis> specify
- <literal>@DocumentId</literal> on the identifier property of your
- entity class.</para>
- </note>
+ decapitalized, following the JavaBean specification</para>
</section>
<section>
@@ -1208,7 +1204,7 @@
private String network;
private String branchHead;
private String branch;
- private Integer maxEmployees;
+ private Integer maxEmployees
...
}
@@ -1275,21 +1271,13 @@
sure however, to <emphasis>not</emphasis> use this annotation with
@DocumentId as your system will break.</para>
- <programlisting>
-
- @ProvidedId (bridge = org.my.own.package.MyCustomBridge)
- @Indexed
- public class MyClass{
-
- @Field
- String MyString;
-
- ...
-
- }
-
-
- </programlisting>
+ <programlisting>@ProvidedId (bridge = org.my.own.package.MyCustomBridge)
+@Indexed
+public class MyClass{
+ @Field
+ String MyString;
+ ...
+}</programlisting>
</section>
</section>
</chapter>
15 years, 5 months
Hibernate SVN: r15558 - search/tags.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2008-11-12 17:24:55 -0500 (Wed, 12 Nov 2008)
New Revision: 15558
Added:
search/tags/v3_0_1_GA_CP01/
Log:
JBPAPP-1389 : create hibernate search tag v3_0_1_GA_CP01 for EAP 4.3.0.GA_CP03_FP01
Copied: search/tags/v3_0_1_GA_CP01 (from rev 15557, search/branches/Branch_3_0_1_GA_CP)
15 years, 5 months