Hibernate SVN: r15102 - core/trunk/testing/src/main/java/org/hibernate/junit.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2008-08-18 14:57:39 -0400 (Mon, 18 Aug 2008)
New Revision: 15102
Modified:
core/trunk/testing/src/main/java/org/hibernate/junit/UnitTestCase.java
Log:
fixed validation of failure expected results
Modified: core/trunk/testing/src/main/java/org/hibernate/junit/UnitTestCase.java
===================================================================
--- core/trunk/testing/src/main/java/org/hibernate/junit/UnitTestCase.java 2008-08-18 18:19:09 UTC (rev 15101)
+++ core/trunk/testing/src/main/java/org/hibernate/junit/UnitTestCase.java 2008-08-18 18:57:39 UTC (rev 15102)
@@ -62,9 +62,12 @@
log.info( "Starting test [" + fullTestName() + "]" );
super.runBare();
if ( doValidate ) {
- fail( "Test marked as FailureExpected, but did not fail!" );
+ throw new FailureExpectedTestPassedException( "Test marked as FailureExpected, but did not fail!" );
}
}
+ catch ( FailureExpectedTestPassedException t ) {
+ throw t;
+ }
catch( Throwable t ) {
if ( doValidate ) {
skipExpectedFailure( t );
@@ -78,6 +81,12 @@
}
}
+ private static class FailureExpectedTestPassedException extends Exception {
+ public FailureExpectedTestPassedException(String message) {
+ super( message );
+ }
+ }
+
protected void skipExpectedFailure(Throwable error) {
reportSkip( "ignoring *FailuredExpected methods", "Failed with: " + error.toString() );
}
16 years, 3 months
Hibernate SVN: r15101 - core/branches/Branch_3_2/src/org/hibernate/impl.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2008-08-18 14:19:09 -0400 (Mon, 18 Aug 2008)
New Revision: 15101
Modified:
core/branches/Branch_3_2/src/org/hibernate/impl/SessionFactoryImpl.java
Log:
HHH-2694 moved connectionProvider.close() after schemaExport.drop()
Modified: core/branches/Branch_3_2/src/org/hibernate/impl/SessionFactoryImpl.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/impl/SessionFactoryImpl.java 2008-08-18 17:59:24 UTC (rev 15100)
+++ core/branches/Branch_3_2/src/org/hibernate/impl/SessionFactoryImpl.java 2008-08-18 18:19:09 UTC (rev 15101)
@@ -799,6 +799,10 @@
settings.getCacheProvider().stop();
+ if ( settings.isAutoDropSchema() ) {
+ schemaExport.drop( false, true );
+ }
+
try {
settings.getConnectionProvider().close();
}
@@ -806,10 +810,6 @@
SessionFactoryObjectFactory.removeInstance(uuid, name, properties);
}
- if ( settings.isAutoDropSchema() ) {
- schemaExport.drop( false, true );
- }
-
}
public void evictEntity(String entityName, Serializable id) throws HibernateException {
16 years, 3 months
Hibernate SVN: r15100 - search/trunk/src/java/org/hibernate/search/engine.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-08-18 13:59:24 -0400 (Mon, 18 Aug 2008)
New Revision: 15100
Modified:
search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
Log:
fix infinite loop on moving up the class hierarchy in @ProvidedId
Modified: search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2008-08-18 17:58:21 UTC (rev 15099)
+++ search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2008-08-18 17:59:24 UTC (rev 15100)
@@ -115,7 +115,7 @@
this.analyzer.setGlobalAnalyzer( rootPropertiesMetadata.analyzer );
if ( idKeywordName == null ) {
// if no DocumentId then check if we have a ProvidedId instead
- ProvidedId provided = findProvidedId( clazz );
+ ProvidedId provided = findProvidedId( clazz, reflectionManager );
if ( provided == null ) throw new SearchException( "No document id in: " + clazz.getName() );
idBridge = BridgeFactory.extractTwoWayType(provided.bridge());
@@ -126,10 +126,10 @@
safeFromTupleId = TwoWayString2FieldBridgeAdaptor.class.isAssignableFrom( idBridge.getClass() );
}
- private ProvidedId findProvidedId(XClass clazz) {
+ private ProvidedId findProvidedId(XClass clazz, ReflectionManager reflectionManager) {
ProvidedId id = null;
XClass currentClass = clazz;
- while ( id == null && currentClass != null) {
+ while ( id == null && ( ! reflectionManager.equals( currentClass, Object.class ) ) ) {
id = currentClass.getAnnotation( ProvidedId.class );
currentClass = clazz.getSuperclass();
}
16 years, 3 months
Hibernate SVN: r15099 - annotations/tags.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-08-18 13:58:21 -0400 (Mon, 18 Aug 2008)
New Revision: 15099
Added:
annotations/tags/3.4.0.GA/
Log:
Created tag 3.4.0.GA.
Copied: annotations/tags/3.4.0.GA (from rev 15098, annotations/trunk)
16 years, 3 months
Hibernate SVN: r15098 - in annotations/trunk: doc/reference/en and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-08-18 13:54:58 -0400 (Mon, 18 Aug 2008)
New Revision: 15098
Modified:
annotations/trunk/build.xml
annotations/trunk/changelog.txt
annotations/trunk/common-build.xml
annotations/trunk/doc/reference/en/master.xml
annotations/trunk/ivy.xml
annotations/trunk/pom.xml
annotations/trunk/readme.txt
annotations/trunk/src/java/org/hibernate/cfg/annotations/Version.java
Log:
Updated all files for 3.4.0.GA release
Modified: annotations/trunk/build.xml
===================================================================
--- annotations/trunk/build.xml 2008-08-18 17:51:31 UTC (rev 15097)
+++ annotations/trunk/build.xml 2008-08-18 17:54:58 UTC (rev 15098)
@@ -17,7 +17,7 @@
<!-- Name of project and version, used to create filenames -->
<property name="Name" value="Hibernate Annotations"/>
<property name="name" value="hibernate-annotations"/>
- <property name="version" value="3.4.0.CR2"/>
+ <property name="version" value="3.4.0.GA"/>
<property name="javadoc.packagenames" value="org.hibernate.*"/>
<property name="jdbc.dir" value="jdbc"/>
<property name="copy.test" value="true"/>
Modified: annotations/trunk/changelog.txt
===================================================================
--- annotations/trunk/changelog.txt 2008-08-18 17:51:31 UTC (rev 15097)
+++ annotations/trunk/changelog.txt 2008-08-18 17:54:58 UTC (rev 15098)
@@ -1,6 +1,23 @@
Hibernate Annotations Changelog
===============================
+3.4.0.GA (18-08-2008)
+----------------------
+
+** Bug
+ * [ANN-761] - Typo in documentation
+
+
+** Improvement
+ * [ANN-765] - Update of "Preface" section in documentation
+ * [ANN-766] - Test updates due to the usage of (oracle) reserved keywords as properties
+
+
+
+** Task
+ * [ANN-767] - Refactor build to allow filtering of resources
+
+
3.4.0.CR2 (01-08-2008)
----------------------
Modified: annotations/trunk/common-build.xml
===================================================================
--- annotations/trunk/common-build.xml 2008-08-18 17:51:31 UTC (rev 15097)
+++ annotations/trunk/common-build.xml 2008-08-18 17:54:58 UTC (rev 15098)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<project name="common-build" default="dist"
xmlns:artifact="urn:maven-artifact-ant" xmlns:ivy="antlib:fr.jayasoft.ivy.ant">
<description>Common properties and targets for the HibernateExt
@@ -13,9 +13,9 @@
<property file="${common-build.basedir}/build.properties"/>
<property file="${user.home}/.ant.properties"/>
- <property name="src.dir" location="src/java"/>
- <property name="test.dir" location="src/test"/>
- <property name="test.resources.dir" location="src/test-resources"/>
+ <property name="src.dir" location="src/java"/>
+ <property name="test.dir" location="src/test"/>
+ <property name="test.resources.dir" location="src/test-resources"/>
<property name="filter.dir" location="src/filters"/>
<property name="lib.dir" location="lib"/>
<property name="build.dir" location="build"/>
@@ -45,7 +45,7 @@
<property name="javac.source" value="1.4"/>
<property name="javac.target" value="1.4"/>
- <property name="pom.file" value="pom.xml"/>
+ <property name="pom.file" value="${build.dir}/pom.xml"/>
<property name="src.jar" value="${build.dir}/src.jar"/>
<taskdef name="junit"
@@ -184,6 +184,9 @@
<tstamp>
<format property="subversion" pattern="yyyy-MM-dd hh:mm:ss"/>
</tstamp>
+ <tstamp>
+ <format property="releasedate" pattern="dd-MM-yyyy"/>
+ </tstamp>
<echo message="Build ${Name}-${version} (${subversion})"/>
<mkdir dir="${classes.dir}"/>
<mkdir dir="${testclasses.dir}"/>
@@ -192,27 +195,29 @@
<patternset refid="support.files"/>
</fileset>
</copy>
-
- <copy todir="${build.dir}">
+ <filter token="version" value="${version}"/>
+ <filter token="releasedate" value="${releasedate}"/>
+ <copy todir="${build.dir}" filtering="true">
<fileset dir=".">
<include name="readme.txt"/>
<include name="lgpl.txt"/>
+ <include name="pom.xml"/>
</fileset>
</copy>
- </target>
-
- <target name="get.deps.core" depends="init"
- description="retrieve the core dependencies">
- <ivy:resolve conf="default"/>
- <ivy:retrieve pattern="${ivy.dep.dir}/core/[artifact].[ext]"
- conf="default"/>
- </target>
-
- <target name="get.deps.test" depends="init"
- description="retrieve the test dependencies">
- <ivy:resolve conf="test"/>
- <ivy:retrieve pattern="${ivy.dep.dir}/test/[artifact].[ext]" conf="test"/>
+ </target>
+
+ <target name="get.deps.core" depends="init"
+ description="retrieve the core dependencies">
+ <ivy:resolve conf="default"/>
+ <ivy:retrieve pattern="${ivy.dep.dir}/core/[artifact].[ext]"
+ conf="default"/>
</target>
+
+ <target name="get.deps.test" depends="init"
+ description="retrieve the test dependencies">
+ <ivy:resolve conf="test"/>
+ <ivy:retrieve pattern="${ivy.dep.dir}/test/[artifact].[ext]" conf="test"/>
+ </target>
<target name="copytest" description="Copy tests to dist dir" if="copy.test">
<mkdir dir="${dist.test.dir}"/>
@@ -302,7 +307,7 @@
<include name="*.bat"/>
</fileset>
</copy>
- <copy file="readme.txt" todir="${dist.dir}"/>
+ <copy file="${build.dir}/readme.txt" todir="${dist.dir}"/>
<copy file="lgpl.txt" todir="${dist.dir}"/>
<copy file="changelog.txt" todir="${dist.dir}"/>
<copy file="build.xml" todir="${dist.dir}"/>
@@ -345,49 +350,49 @@
<mkdir dir="${testclasses.dir}"/>
<copy todir="${testclasses.dir}" filtering="true" overwrite="true">
<fileset dir="${test.resources.dir}">
- <include name="*.properties"/>
+ <include name="*.properties"/>
<include name="*.xml"/>
</fileset>
</copy>
</target>
-
- <target name="instrument" depends="compiletest"
- description="Instrument the persistent classes"> <!-- depends="jar" -->
-
- <taskdef name="instrument"
- classname="org.hibernate.tool.instrument.javassist.InstrumentTask">
- <classpath refid="junit.classpath"/>
- </taskdef>
-
- <instrument verbose="true">
- <fileset dir="${testclasses.dir}/org/hibernate/test">
- <include name="**/*.class"/>
- <exclude name="**/*Test$*.class"/>
- <exclude name="**/*Test.class"/>
- <exclude name="**/*Tests.class"/>
- </fileset>
- </instrument>
+
+ <target name="instrument" depends="compiletest"
+ description="Instrument the persistent classes"> <!-- depends="jar" -->
+
+ <taskdef name="instrument"
+ classname="org.hibernate.tool.instrument.javassist.InstrumentTask">
+ <classpath refid="junit.classpath"/>
+ </taskdef>
+
+ <instrument verbose="true">
+ <fileset dir="${testclasses.dir}/org/hibernate/test">
+ <include name="**/*.class"/>
+ <exclude name="**/*Test$*.class"/>
+ <exclude name="**/*Test.class"/>
+ <exclude name="**/*Tests.class"/>
+ </fileset>
+ </instrument>
</target>
<target name="junitinstrument" depends="compiletest,instrument"
- description="Run the instrument test suite">
- <for list="${targetdb}" param="db">
- <sequential>
- <antcall target="test-resources">
- <param name="db" value="@{db}"/>
- </antcall>
- <mkdir dir="${instrumenttest.out.dir}/@{db}"/>
- <echo>Running against db: @{db}</echo>
- <junit printsummary="yes" haltonfailure="yes" dir="${basedir}"
- maxmemory="256M" fork="yes" forkmode="perBatch">
- <classpath refid="junit.classpath"/>
- <formatter type="plain"/>
- <formatter type="xml"/>
- <batchtest todir="${instrumenttest.out.dir}/@{db}" haltonfailure="no">
- <fileset refid="junit.batchtestset"/>
- </batchtest>
- </junit>
- </sequential>
+ description="Run the instrument test suite">
+ <for list="${targetdb}" param="db">
+ <sequential>
+ <antcall target="test-resources">
+ <param name="db" value="@{db}"/>
+ </antcall>
+ <mkdir dir="${instrumenttest.out.dir}/@{db}"/>
+ <echo>Running against db: @{db}</echo>
+ <junit printsummary="yes" haltonfailure="yes" dir="${basedir}"
+ maxmemory="256M" fork="yes" forkmode="perBatch">
+ <classpath refid="junit.classpath"/>
+ <formatter type="plain"/>
+ <formatter type="xml"/>
+ <batchtest todir="${instrumenttest.out.dir}/@{db}" haltonfailure="no">
+ <fileset refid="junit.batchtestset"/>
+ </batchtest>
+ </junit>
+ </sequential>
</for>
</target>
Modified: annotations/trunk/doc/reference/en/master.xml
===================================================================
--- annotations/trunk/doc/reference/en/master.xml 2008-08-18 17:51:31 UTC (rev 15097)
+++ annotations/trunk/doc/reference/en/master.xml 2008-08-18 17:54:58 UTC (rev 15098)
@@ -12,7 +12,7 @@
<subtitle>Reference Guide</subtitle>
- <releaseinfo>3.4.0.CR2</releaseinfo>
+ <releaseinfo>3.4.0.GA</releaseinfo>
<mediaobject>
<imageobject>
Modified: annotations/trunk/ivy.xml
===================================================================
--- annotations/trunk/ivy.xml 2008-08-18 17:51:31 UTC (rev 15097)
+++ annotations/trunk/ivy.xml 2008-08-18 17:54:58 UTC (rev 15098)
@@ -14,8 +14,8 @@
<dependencies>
<!-- compile time dependencies -->
<dependency name="ejb3-persistence" rev="1.0.2.GA" conf="default->default"/>
- <dependency name="commons-annotations" rev="3.1.0.CR2" conf="default->default"/>
- <dependency org="org.hibernate" name="hibernate-core" rev="3.3.0.CR2" conf="default->default"/>
+ <dependency name="commons-annotations" rev="3.1.0.GA" conf="default->default"/>
+ <dependency org="org.hibernate" name="hibernate-core" rev="3.3.0.GA" conf="default->default"/>
<dependency org="dom4j" name="dom4j" rev="1.6.1" conf="default->default"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.4.2" conf="default->default"/>
Modified: annotations/trunk/pom.xml
===================================================================
--- annotations/trunk/pom.xml 2008-08-18 17:51:31 UTC (rev 15097)
+++ annotations/trunk/pom.xml 2008-08-18 17:54:58 UTC (rev 15098)
@@ -8,7 +8,7 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<packaging>jar</packaging>
- <version>3.4.0.CR2</version>
+ <version>@version@</version>
<name>Hibernate Annotations</name>
<description>Annotations metadata for Hibernate</description>
@@ -30,12 +30,12 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
- <version>3.1.0.CR2</version>
+ <version>3.1.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
- <version>3.3.0.CR2</version>
+ <version>3.3.0.GA</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Modified: annotations/trunk/readme.txt
===================================================================
--- annotations/trunk/readme.txt 2008-08-18 17:51:31 UTC (rev 15097)
+++ annotations/trunk/readme.txt 2008-08-18 17:54:58 UTC (rev 15098)
@@ -1,6 +1,6 @@
Hibernate Annotations
==================================================
-Version: 3.4.0.CR2, 01.08.2008
+Version: @version@, @releasedate@
THIS RELEASE OF HIBERNATE ANNOTATIONS REQUIRES HIBERNATE CORE 3.3 (and above)
Modified: annotations/trunk/src/java/org/hibernate/cfg/annotations/Version.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/annotations/Version.java 2008-08-18 17:51:31 UTC (rev 15097)
+++ annotations/trunk/src/java/org/hibernate/cfg/annotations/Version.java 2008-08-18 17:54:58 UTC (rev 15098)
@@ -8,7 +8,7 @@
* @author Emmanuel Bernard
*/
public class Version {
- public static final String VERSION = "3.4.0.CR2";
+ public static final String VERSION = "3.4.0.GA";
private static Logger log = LoggerFactory.getLogger( Version.class );
static {
16 years, 3 months
Hibernate SVN: r15097 - search/trunk/src/test/org/hibernate/search/test/id/providedId.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-08-18 13:51:31 -0400 (Mon, 18 Aug 2008)
New Revision: 15097
Modified:
search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdPersonSub.java
search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdTest.java
Log:
hierarchical test
Modified: search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdPersonSub.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdPersonSub.java 2008-08-18 17:36:38 UTC (rev 15096)
+++ search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdPersonSub.java 2008-08-18 17:51:31 UTC (rev 15097)
@@ -1,9 +1,13 @@
package org.hibernate.search.test.id.providedId;
+import javax.persistence.Entity;
+
+import org.hibernate.search.annotations.Indexed;
+
/**
* @author Navin Surtani (<a href="mailto:nsurtani@redhat.com">nsurtani(a)redhat.com</a>)
*/
-public class ProvidedIdPersonSub extends ProvidedIdPerson {
-
-
+@Indexed
+@Entity
+public class ProvidedIdPersonSub extends ProvidedIdPerson {
}
Modified: search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdTest.java 2008-08-18 17:36:38 UTC (rev 15096)
+++ search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdTest.java 2008-08-18 17:51:31 UTC (rev 15097)
@@ -2,9 +2,9 @@
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Hits;
import org.hibernate.Session;
import org.hibernate.Transaction;
@@ -20,7 +20,8 @@
protected Class[] getMappings() {
return new Class[] {
- ProvidedIdPerson.class
+ ProvidedIdPerson.class,
+ ProvidedIdPersonSub.class
};
}
@@ -34,18 +35,18 @@
person2.setName( "Mini Goat" );
person2.setBlurb( "Eats cheese" );
- ProvidedIdPersonSub person3 = new ProvidedIdPersonSub();
- person3.setName ( "Regular goat" );
- person3.setBlurb ( "Is anorexic" );
+ ProvidedIdPersonSub person3 = new ProvidedIdPersonSub();
+ person3.setName( "Regular goat" );
+ person3.setBlurb( "Is anorexic" );
- Session session = openSession();
+ Session session = openSession();
FullTextSession fullTextSession = Search.getFullTextSession( session );
Transaction transaction = session.beginTransaction();
session.persist( person1 );
session.persist( person2 );
- session.persist( person3 );
+ session.persist( person3 );
- transaction.commit();
+ transaction.commit();
session.clear();
transaction = fullTextSession.beginTransaction();
@@ -57,8 +58,9 @@
//needs it. So we use plain Lucene
//we know there is only one DP
- DirectoryProvider provider = fullTextSession.getSearchFactory().getDirectoryProviders( ProvidedIdPerson.class )[0];
- IndexSearcher searcher = new IndexSearcher( provider.getDirectory() );
+ DirectoryProvider provider = fullTextSession.getSearchFactory()
+ .getDirectoryProviders( ProvidedIdPerson.class )[0];
+ IndexSearcher searcher = new IndexSearcher( provider.getDirectory() );
Hits hits = searcher.search( luceneQuery );
searcher.close();
transaction.commit();
16 years, 3 months
Hibernate SVN: r15096 - search/trunk/src/test/org/hibernate/search/test/id/providedId.
by hibernate-commits@lists.jboss.org
Author: navssurtani
Date: 2008-08-18 13:36:38 -0400 (Mon, 18 Aug 2008)
New Revision: 15096
Added:
search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdPerson.java
search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdPersonSub.java
Removed:
search/trunk/src/test/org/hibernate/search/test/id/providedId/JBossCachePerson.java
Modified:
search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdTest.java
Log:
Changed JBossCachePerson to ProvidedIdPerson and added subclass ...
Deleted: search/trunk/src/test/org/hibernate/search/test/id/providedId/JBossCachePerson.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/id/providedId/JBossCachePerson.java 2008-08-18 15:25:50 UTC (rev 15095)
+++ search/trunk/src/test/org/hibernate/search/test/id/providedId/JBossCachePerson.java 2008-08-18 17:36:38 UTC (rev 15096)
@@ -1,63 +0,0 @@
-package org.hibernate.search.test.id.providedId;
-
-import org.hibernate.search.annotations.*;
-import org.hibernate.search.bridge.builtin.LongBridge;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.GeneratedValue;
-import java.io.Serializable;
-
-
-/**
- @author Navin Surtani (<a href="mailto:nsurtani@redhat.com">nsurtani(a)redhat.com</a>)
- */
-@Entity
-@ProvidedId(bridge = @FieldBridge(impl = LongBridge.class))
-@Indexed
-public class JBossCachePerson implements Serializable
-{
-
- @Id
- @GeneratedValue
- private long id;
-
-
- @Field (index = Index.TOKENIZED, store = Store.YES)
- private String name;
- @Field (index = Index.TOKENIZED, store = Store.YES)
- private String blurb;
- @Field (index = Index.UN_TOKENIZED, store = Store.YES)
- private int age;
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public String getBlurb()
- {
- return blurb;
- }
-
- public void setBlurb(String blurb)
- {
- this.blurb = blurb;
- }
-
- public int getAge()
- {
- return age;
- }
-
- public void setAge(int age)
- {
- this.age = age;
- }
-
-}
Copied: search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdPerson.java (from rev 15091, search/trunk/src/test/org/hibernate/search/test/id/providedId/JBossCachePerson.java)
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdPerson.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdPerson.java 2008-08-18 17:36:38 UTC (rev 15096)
@@ -0,0 +1,63 @@
+package org.hibernate.search.test.id.providedId;
+
+import org.hibernate.search.annotations.*;
+import org.hibernate.search.bridge.builtin.LongBridge;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import java.io.Serializable;
+
+
+/**
+ @author Navin Surtani (<a href="mailto:nsurtani@redhat.com">nsurtani(a)redhat.com</a>)
+ */
+@Entity
+@ProvidedId(bridge = @FieldBridge(impl = LongBridge.class))
+@Indexed
+public class ProvidedIdPerson implements Serializable
+{
+
+ @Id
+ @GeneratedValue
+ private long id;
+
+
+ @Field (index = Index.TOKENIZED, store = Store.YES)
+ private String name;
+ @Field (index = Index.TOKENIZED, store = Store.YES)
+ private String blurb;
+ @Field (index = Index.UN_TOKENIZED, store = Store.YES)
+ private int age;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getBlurb()
+ {
+ return blurb;
+ }
+
+ public void setBlurb(String blurb)
+ {
+ this.blurb = blurb;
+ }
+
+ public int getAge()
+ {
+ return age;
+ }
+
+ public void setAge(int age)
+ {
+ this.age = age;
+ }
+
+}
Added: search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdPersonSub.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdPersonSub.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdPersonSub.java 2008-08-18 17:36:38 UTC (rev 15096)
@@ -0,0 +1,9 @@
+package org.hibernate.search.test.id.providedId;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani@redhat.com">nsurtani(a)redhat.com</a>)
+ */
+public class ProvidedIdPersonSub extends ProvidedIdPerson {
+
+
+}
Modified: search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdTest.java 2008-08-18 15:25:50 UTC (rev 15095)
+++ search/trunk/src/test/org/hibernate/search/test/id/providedId/ProvidedIdTest.java 2008-08-18 17:36:38 UTC (rev 15096)
@@ -1,9 +1,6 @@
package org.hibernate.search.test.id.providedId;
-import java.util.List;
-
import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.IndexSearcher;
@@ -11,7 +8,6 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.search.FullTextQuery;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.store.DirectoryProvider;
@@ -24,28 +20,32 @@
protected Class[] getMappings() {
return new Class[] {
- JBossCachePerson.class
+ ProvidedIdPerson.class
};
}
public void testProvidedId() throws Exception {
- JBossCachePerson person1 = new JBossCachePerson();
+ ProvidedIdPerson person1 = new ProvidedIdPerson();
person1.setName( "Big Goat" );
person1.setBlurb( "Eats grass" );
- JBossCachePerson person2 = new JBossCachePerson();
+ ProvidedIdPerson person2 = new ProvidedIdPerson();
person2.setName( "Mini Goat" );
person2.setBlurb( "Eats cheese" );
+ ProvidedIdPersonSub person3 = new ProvidedIdPersonSub();
+ person3.setName ( "Regular goat" );
+ person3.setBlurb ( "Is anorexic" );
- Session session = openSession();
+ Session session = openSession();
FullTextSession fullTextSession = Search.getFullTextSession( session );
Transaction transaction = session.beginTransaction();
session.persist( person1 );
session.persist( person2 );
+ session.persist( person3 );
- transaction.commit();
+ transaction.commit();
session.clear();
transaction = fullTextSession.beginTransaction();
@@ -57,14 +57,14 @@
//needs it. So we use plain Lucene
//we know there is only one DP
- DirectoryProvider provider = fullTextSession.getSearchFactory().getDirectoryProviders( JBossCachePerson.class )[0];
+ DirectoryProvider provider = fullTextSession.getSearchFactory().getDirectoryProviders( ProvidedIdPerson.class )[0];
IndexSearcher searcher = new IndexSearcher( provider.getDirectory() );
Hits hits = searcher.search( luceneQuery );
searcher.close();
transaction.commit();
session.close();
- assertEquals( 2, hits.length() );
+ assertEquals( 3, hits.length() );
}
16 years, 3 months
Hibernate SVN: r15095 - commons-annotations/tags.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-08-18 11:25:50 -0400 (Mon, 18 Aug 2008)
New Revision: 15095
Added:
commons-annotations/tags/3.1.0.GA/
Log:
Created tag 3.1.0.GA.
Copied: commons-annotations/tags/3.1.0.GA (from rev 15094, commons-annotations/trunk)
16 years, 3 months
Hibernate SVN: r15094 - in commons-annotations/trunk: src/java/org/hibernate/annotations/common and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-08-18 11:22:12 -0400 (Mon, 18 Aug 2008)
New Revision: 15094
Modified:
commons-annotations/trunk/build.xml
commons-annotations/trunk/changelog.txt
commons-annotations/trunk/common-build.xml
commons-annotations/trunk/pom.xml
commons-annotations/trunk/readme.txt
commons-annotations/trunk/src/java/org/hibernate/annotations/common/Version.java
Log:
* Updated all files for 3.1.0.GA release
Modified: commons-annotations/trunk/build.xml
===================================================================
--- commons-annotations/trunk/build.xml 2008-08-18 15:16:52 UTC (rev 15093)
+++ commons-annotations/trunk/build.xml 2008-08-18 15:22:12 UTC (rev 15094)
@@ -9,7 +9,7 @@
<!-- Name of project and version, used to create filenames -->
<property name="Name" value="Hibernate Commons Annotations"/>
<property name="name" value="hibernate-commons-annotations"/>
- <property name="version" value="3.1.0.CR2"/>
+ <property name="version" value="3.1.0.GA"/>
<property name="javadoc.packagenames" value="org.hibernate.commons.annotations.*"/>
<property name="copy.test" value="true"/>
<property name="javac.source" value="1.5"/>
@@ -36,10 +36,7 @@
</path>
<target name="init" description="Initialize the build">
- <!-- CCed from common-build to avoid failure when hibernate core is not compiled -->
- <tstamp>
- <format property="subversion" pattern="yyyy-MM-dd hh:mm:ss"/>
- </tstamp>
+ <antcall target="common-build.init"/>
<tstamp>
<format property="now" pattern="yyyyMMddhhmmss"/>
</tstamp>
Modified: commons-annotations/trunk/changelog.txt
===================================================================
--- commons-annotations/trunk/changelog.txt 2008-08-18 15:16:52 UTC (rev 15093)
+++ commons-annotations/trunk/changelog.txt 2008-08-18 15:22:12 UTC (rev 15094)
@@ -1,6 +1,9 @@
Hibernate Annotations Changelog
===============================
+3.1.0.GA (18-08-2008)
+----------------------
+
3.1.0.CR2 (23-07-2008)
----------------------
Modified: commons-annotations/trunk/common-build.xml
===================================================================
--- commons-annotations/trunk/common-build.xml 2008-08-18 15:16:52 UTC (rev 15093)
+++ commons-annotations/trunk/common-build.xml 2008-08-18 15:22:12 UTC (rev 15094)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<project name="common-build" default="dist"
xmlns:artifact="urn:maven-artifact-ant" xmlns:ivy="antlib:fr.jayasoft.ivy.ant">
<description>Common properties and targets for the HibernateExt
@@ -13,9 +13,9 @@
<property file="${common-build.basedir}/build.properties"/>
<property file="${user.home}/.ant.properties"/>
- <property name="src.dir" location="src/java"/>
- <property name="test.dir" location="src/test"/>
- <property name="test.resources.dir" location="src/test-resources"/>
+ <property name="src.dir" location="src/java"/>
+ <property name="test.dir" location="src/test"/>
+ <property name="test.resources.dir" location="src/test-resources"/>
<property name="filter.dir" location="src/filters"/>
<property name="lib.dir" location="lib"/>
<property name="build.dir" location="build"/>
@@ -45,7 +45,7 @@
<property name="javac.source" value="1.4"/>
<property name="javac.target" value="1.4"/>
- <property name="pom.file" value="pom.xml"/>
+ <property name="pom.file" value="${build.dir}/pom.xml"/>
<property name="src.jar" value="${build.dir}/src.jar"/>
<taskdef name="junit"
@@ -184,6 +184,9 @@
<tstamp>
<format property="subversion" pattern="yyyy-MM-dd hh:mm:ss"/>
</tstamp>
+ <tstamp>
+ <format property="releasedate" pattern="dd-MM-yyyy"/>
+ </tstamp>
<echo message="Build ${Name}-${version} (${subversion})"/>
<mkdir dir="${classes.dir}"/>
<mkdir dir="${testclasses.dir}"/>
@@ -192,27 +195,30 @@
<patternset refid="support.files"/>
</fileset>
</copy>
-
- <copy todir="${build.dir}">
+ <filter token="version" value="${version}"/>
+ <filter token="releasedate" value="${releasedate}"/>
+ <echo>filtering</echo>
+ <copy todir="${build.dir}" filtering="true">
<fileset dir=".">
<include name="readme.txt"/>
<include name="lgpl.txt"/>
+ <include name="pom.xml"/>
</fileset>
</copy>
- </target>
-
- <target name="get.deps.core" depends="init"
- description="retrieve the core dependencies">
- <ivy:resolve conf="default"/>
- <ivy:retrieve pattern="${ivy.dep.dir}/core/[artifact].[ext]"
- conf="default"/>
- </target>
-
- <target name="get.deps.test" depends="init"
- description="retrieve the test dependencies">
- <ivy:resolve conf="test"/>
- <ivy:retrieve pattern="${ivy.dep.dir}/test/[artifact].[ext]" conf="test"/>
+ </target>
+
+ <target name="get.deps.core" depends="init"
+ description="retrieve the core dependencies">
+ <ivy:resolve conf="default"/>
+ <ivy:retrieve pattern="${ivy.dep.dir}/core/[artifact].[ext]"
+ conf="default"/>
</target>
+
+ <target name="get.deps.test" depends="init"
+ description="retrieve the test dependencies">
+ <ivy:resolve conf="test"/>
+ <ivy:retrieve pattern="${ivy.dep.dir}/test/[artifact].[ext]" conf="test"/>
+ </target>
<target name="copytest" description="Copy tests to dist dir" if="copy.test">
<mkdir dir="${dist.test.dir}"/>
@@ -302,7 +308,7 @@
<include name="*.bat"/>
</fileset>
</copy>
- <copy file="readme.txt" todir="${dist.dir}"/>
+ <copy file="${build.dir}/readme.txt" todir="${dist.dir}"/>
<copy file="lgpl.txt" todir="${dist.dir}"/>
<copy file="changelog.txt" todir="${dist.dir}"/>
<copy file="build.xml" todir="${dist.dir}"/>
@@ -345,49 +351,49 @@
<mkdir dir="${testclasses.dir}"/>
<copy todir="${testclasses.dir}" filtering="true" overwrite="true">
<fileset dir="${test.resources.dir}">
- <include name="*.properties"/>
+ <include name="*.properties"/>
<include name="*.xml"/>
</fileset>
</copy>
</target>
-
- <target name="instrument" depends="compiletest"
- description="Instrument the persistent classes"> <!-- depends="jar" -->
-
- <taskdef name="instrument"
- classname="org.hibernate.tool.instrument.javassist.InstrumentTask">
- <classpath refid="junit.classpath"/>
- </taskdef>
-
- <instrument verbose="true">
- <fileset dir="${testclasses.dir}/org/hibernate/test">
- <include name="**/*.class"/>
- <exclude name="**/*Test$*.class"/>
- <exclude name="**/*Test.class"/>
- <exclude name="**/*Tests.class"/>
- </fileset>
- </instrument>
+
+ <target name="instrument" depends="compiletest"
+ description="Instrument the persistent classes"> <!-- depends="jar" -->
+
+ <taskdef name="instrument"
+ classname="org.hibernate.tool.instrument.javassist.InstrumentTask">
+ <classpath refid="junit.classpath"/>
+ </taskdef>
+
+ <instrument verbose="true">
+ <fileset dir="${testclasses.dir}/org/hibernate/test">
+ <include name="**/*.class"/>
+ <exclude name="**/*Test$*.class"/>
+ <exclude name="**/*Test.class"/>
+ <exclude name="**/*Tests.class"/>
+ </fileset>
+ </instrument>
</target>
<target name="junitinstrument" depends="compiletest,instrument"
- description="Run the instrument test suite">
- <for list="${targetdb}" param="db">
- <sequential>
- <antcall target="test-resources">
- <param name="db" value="@{db}"/>
- </antcall>
- <mkdir dir="${instrumenttest.out.dir}/@{db}"/>
- <echo>Running against db: @{db}</echo>
- <junit printsummary="yes" haltonfailure="yes" dir="${basedir}"
- maxmemory="256M" fork="yes" forkmode="perBatch">
- <classpath refid="junit.classpath"/>
- <formatter type="plain"/>
- <formatter type="xml"/>
- <batchtest todir="${instrumenttest.out.dir}/@{db}" haltonfailure="no">
- <fileset refid="junit.batchtestset"/>
- </batchtest>
- </junit>
- </sequential>
+ description="Run the instrument test suite">
+ <for list="${targetdb}" param="db">
+ <sequential>
+ <antcall target="test-resources">
+ <param name="db" value="@{db}"/>
+ </antcall>
+ <mkdir dir="${instrumenttest.out.dir}/@{db}"/>
+ <echo>Running against db: @{db}</echo>
+ <junit printsummary="yes" haltonfailure="yes" dir="${basedir}"
+ maxmemory="256M" fork="yes" forkmode="perBatch">
+ <classpath refid="junit.classpath"/>
+ <formatter type="plain"/>
+ <formatter type="xml"/>
+ <batchtest todir="${instrumenttest.out.dir}/@{db}" haltonfailure="no">
+ <fileset refid="junit.batchtestset"/>
+ </batchtest>
+ </junit>
+ </sequential>
</for>
</target>
Modified: commons-annotations/trunk/pom.xml
===================================================================
--- commons-annotations/trunk/pom.xml 2008-08-18 15:16:52 UTC (rev 15093)
+++ commons-annotations/trunk/pom.xml 2008-08-18 15:22:12 UTC (rev 15094)
@@ -7,7 +7,7 @@
<artifactId>hibernate-commons-annotations</artifactId>
<packaging>jar</packaging>
<name>Hibernate Commons Annotations</name>
- <version>3.1.0.CR2</version>
+ <version>@version@</version>
<licenses>
<license>
<name>GNU LESSER GENERAL PUBLIC LICENSE</name>
Modified: commons-annotations/trunk/readme.txt
===================================================================
--- commons-annotations/trunk/readme.txt 2008-08-18 15:16:52 UTC (rev 15093)
+++ commons-annotations/trunk/readme.txt 2008-08-18 15:22:12 UTC (rev 15094)
@@ -1,6 +1,6 @@
Hibernate Commons Annotations
==================================================
-Version: 3.1.0.CR2, 23.07.2008
+Version: @version@, @releasedate@
Description
-----------
Modified: commons-annotations/trunk/src/java/org/hibernate/annotations/common/Version.java
===================================================================
--- commons-annotations/trunk/src/java/org/hibernate/annotations/common/Version.java 2008-08-18 15:16:52 UTC (rev 15093)
+++ commons-annotations/trunk/src/java/org/hibernate/annotations/common/Version.java 2008-08-18 15:22:12 UTC (rev 15094)
@@ -7,7 +7,7 @@
* @author Emmanuel Bernard
*/
public class Version {
- public static final String VERSION = "3.1.0.CR2";
+ public static final String VERSION = "3.1.0.GA";
private static Logger log = LoggerFactory.getLogger( Version.class );
static {
16 years, 3 months
Hibernate SVN: r15093 - in search/trunk/src/java/org/hibernate/search: bridge and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-08-18 11:16:52 -0400 (Mon, 18 Aug 2008)
New Revision: 15093
Modified:
search/trunk/src/java/org/hibernate/search/annotations/ProvidedId.java
search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java
search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
Log:
Enhance Navin's contrib, fix styles issues and compilation problem
Modified: search/trunk/src/java/org/hibernate/search/annotations/ProvidedId.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/annotations/ProvidedId.java 2008-08-18 12:28:57 UTC (rev 15092)
+++ search/trunk/src/java/org/hibernate/search/annotations/ProvidedId.java 2008-08-18 15:16:52 UTC (rev 15093)
@@ -26,5 +26,5 @@
String name() default "providedId";
- ClassBridge bridge() default @ClassBridge(impl = org.hibernate.search.bridge.builtin.StringBridge.class);
+ FieldBridge bridge() default @FieldBridge(impl = org.hibernate.search.bridge.builtin.StringBridge.class);
}
Modified: search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java 2008-08-18 12:28:57 UTC (rev 15092)
+++ search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java 2008-08-18 15:16:52 UTC (rev 15093)
@@ -160,39 +160,9 @@
else {
bridgeAnn = member.getAnnotation( org.hibernate.search.annotations.FieldBridge.class );
}
+ final String memberName = member.getName();
if ( bridgeAnn != null ) {
- Class impl = bridgeAnn.impl();
- if (impl == void.class)
- throw new SearchException("@FieldBridge with no implementation class defined in: " + member.getName() );
- try {
- Object instance = impl.newInstance();
- if ( FieldBridge.class.isAssignableFrom( impl ) ) {
- bridge = (FieldBridge) instance;
- }
- else if ( org.hibernate.search.bridge.TwoWayStringBridge.class.isAssignableFrom( impl ) ) {
- bridge = new TwoWayString2FieldBridgeAdaptor(
- (org.hibernate.search.bridge.TwoWayStringBridge) instance );
- }
- else if ( org.hibernate.search.bridge.StringBridge.class.isAssignableFrom( impl ) ) {
- bridge = new String2FieldBridgeAdaptor( (org.hibernate.search.bridge.StringBridge) instance );
- }
- else {
- throw new SearchException("@FieldBridge implementation implements none of the field bridge interfaces: "
- + impl + " in " + member.getName() );
- }
- if ( bridgeAnn.params().length > 0 && ParameterizedBridge.class.isAssignableFrom( impl ) ) {
- Map params = new HashMap( bridgeAnn.params().length );
- for ( Parameter param : bridgeAnn.params() ) {
- params.put( param.name(), param.value() );
- }
- ( (ParameterizedBridge) instance ).setParameterValues( params );
- }
-
- }
- catch (Exception e) {
- //TODO add classname
- throw new HibernateException( "Unable to instanciate FieldBridge for " + member.getName(), e );
- }
+ bridge = doExtractType( bridgeAnn, memberName );
}
else if ( member.isAnnotationPresent( org.hibernate.search.annotations.DateBridge.class ) ) {
Resolution resolution =
@@ -210,10 +180,49 @@
}
}
//TODO add classname
- if ( bridge == null ) throw new SearchException( "Unable to guess FieldBridge for " + member.getName() );
+ if ( bridge == null ) throw new SearchException( "Unable to guess FieldBridge for " + memberName );
return bridge;
}
+ /** assume not null bridgeAnn */
+ private static FieldBridge doExtractType(org.hibernate.search.annotations.FieldBridge bridgeAnn, String memberName) {
+ assert bridgeAnn != null : "doExtractType assume bridge instance not null";
+ FieldBridge bridge;
+ Class impl = bridgeAnn.impl();
+ if (impl == void.class)
+ throw new SearchException("@FieldBridge with no implementation class defined in: " + memberName );
+ try {
+ Object instance = impl.newInstance();
+ if ( FieldBridge.class.isAssignableFrom( impl ) ) {
+ bridge = (FieldBridge) instance;
+ }
+ else if ( TwoWayStringBridge.class.isAssignableFrom( impl ) ) {
+ bridge = new TwoWayString2FieldBridgeAdaptor(
+ ( TwoWayStringBridge) instance );
+ }
+ else if ( org.hibernate.search.bridge.StringBridge.class.isAssignableFrom( impl ) ) {
+ bridge = new String2FieldBridgeAdaptor( (org.hibernate.search.bridge.StringBridge) instance );
+ }
+ else {
+ throw new SearchException("@FieldBridge implementation implements none of the field bridge interfaces: "
+ + impl + " in " + memberName
+ );
+ }
+ if ( bridgeAnn.params().length > 0 && ParameterizedBridge.class.isAssignableFrom( impl ) ) {
+ Map params = new HashMap( bridgeAnn.params().length );
+ for ( Parameter param : bridgeAnn.params() ) {
+ params.put( param.name(), param.value() );
+ }
+ ( (ParameterizedBridge) instance ).setParameterValues( params );
+ }
+ }
+ catch (Exception e) {
+ //TODO add classname
+ throw new SearchException( "Unable to instanciate FieldBridge for " + memberName, e );
+ }
+ return bridge;
+ }
+
public static FieldBridge getDateField(Resolution resolution) {
switch (resolution) {
case YEAR:
@@ -235,15 +244,17 @@
}
}
- /**
- * Takes in a fieldBridge and will return you a TwoWayFieldBridge instance.
- *
- * @param fieldBridge
- * @return a TwoWayFieldBridge instance if the Field Bridge is an instance of a TwoWayFieldBridge.
- * @throws SearchException if the FieldBridge passed in is not an instance of a TwoWayFieldBridge.
- */
+ /**
+ * Takes in a fieldBridge and will return you a TwoWayFieldBridge instance.
+ *
+ * @param fieldBridge
+ *
+ * @return a TwoWayFieldBridge instance if the Field Bridge is an instance of a TwoWayFieldBridge.
+ *
+ * @throws SearchException if the FieldBridge passed in is not an instance of a TwoWayFieldBridge.
+ */
- public static TwoWayFieldBridge extractTwoWayType(org.hibernate.search.annotations.FieldBridge fieldBridge) {
+ public static TwoWayFieldBridge extractTwoWayType(org.hibernate.search.annotations.FieldBridge fieldBridge) {
FieldBridge fb = extractType( fieldBridge );
if ( fb instanceof TwoWayFieldBridge ) {
return ( TwoWayFieldBridge ) fb;
@@ -253,54 +264,29 @@
}
}
- /**
- * This extracts and instantiates the implementation class from a ClassBridge
- * annotation.
- *
- * @param fieldBridgeAnnotation the FieldBridge annotation
- * @return FieldBridge
- */
- public static FieldBridge extractType(org.hibernate.search.annotations.FieldBridge fieldBridgeAnnotation)
- {
- FieldBridge bridge = null;
+ /**
+ * This extracts and instantiates the implementation class from a ClassBridge
+ * annotation.
+ *
+ * @param fieldBridgeAnnotation the FieldBridge annotation
+ *
+ * @return FieldBridge
+ */
+ public static FieldBridge extractType(org.hibernate.search.annotations.FieldBridge fieldBridgeAnnotation) {
+ FieldBridge bridge = null;
- if ( fieldBridgeAnnotation != null ) {
- Class impl = fieldBridgeAnnotation.impl();
- //TODO better error information ( see guessType() )
- if (impl != null) {
- try {
- Object instance = impl.newInstance();
- if ( FieldBridge.class.isAssignableFrom( impl ) ) {
- bridge = (FieldBridge) instance;
- }
- else if ( org.hibernate.search.bridge.TwoWayStringBridge.class.isAssignableFrom( impl ) ) {
- bridge = new TwoWayString2FieldBridgeAdaptor(
- (org.hibernate.search.bridge.TwoWayStringBridge) instance );
- }
- else if ( org.hibernate.search.bridge.StringBridge.class.isAssignableFrom( impl ) ) {
- bridge = new String2FieldBridgeAdaptor( (org.hibernate.search.bridge.StringBridge) instance );
- }
- else {
- throw new SearchException("@ClassBridge implementation implements none of the field bridge interfaces: "
- + impl );
- }
- if ( fieldBridgeAnnotation.params().length > 0 && ParameterizedBridge.class.isAssignableFrom( impl ) ) {
- Map params = new HashMap( fieldBridgeAnnotation.params().length );
- for ( Parameter param : fieldBridgeAnnotation.params() ) {
- params.put( param.name(), param.value() );
- }
- ( (ParameterizedBridge) instance ).setParameterValues( params );
- }
- }
- catch (Exception e) {
- throw new HibernateException( "Unable to instantiate FieldBridge for " + org.hibernate.search.annotations.FieldBridge.class.getName(), e );
- }
- }
- }
- if ( bridge == null ) throw new SearchException( "Unable to guess FieldBridge for " + org.hibernate.search.annotations.FieldBridge.class.getName() );
+ if ( fieldBridgeAnnotation != null ) {
+ bridge = doExtractType( fieldBridgeAnnotation, null );
+ }
- return bridge;
- }
+ if ( bridge == null ) {
+ throw new SearchException(
+ "Unable to guess FieldBridge for " + org.hibernate.search.annotations.FieldBridge.class.getName()
+ );
+ }
+ return bridge;
+ }
+
}
Modified: search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2008-08-18 12:28:57 UTC (rev 15092)
+++ search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2008-08-18 15:16:52 UTC (rev 15093)
@@ -67,832 +67,818 @@
* @author Richard Hallier
* @author Hardy Ferentschik
*/
-@SuppressWarnings("unchecked")
+@SuppressWarnings( "unchecked" )
public class DocumentBuilder<T> {
- private static final Logger log = LoggerFactory.getLogger(DocumentBuilder.class);
+ private static final Logger log = LoggerFactory.getLogger( DocumentBuilder.class );
- private final PropertiesMetadata rootPropertiesMetadata = new PropertiesMetadata();
- private final XClass beanClass;
- private final DirectoryProvider[] directoryProviders;
- private final IndexShardingStrategy shardingStrategy;
- private String idKeywordName;
- private XMember idGetter;
- private Float idBoost;
- public static final String CLASS_FIELDNAME = "_hibernate_class";
- private TwoWayFieldBridge idBridge;
- private Set<Class> mappedSubclasses = new HashSet<Class>();
- private ReflectionManager reflectionManager;
- private int level = 0;
- private int maxLevel = Integer.MAX_VALUE;
- private final ScopedAnalyzer analyzer = new ScopedAnalyzer();
- private Similarity similarity;
- private boolean isRoot;
- //if composite id, use of (a, b) in ((1,2), (3,4)) fails on most database
- private boolean safeFromTupleId;
- private boolean idProvided = false;
+ private final PropertiesMetadata rootPropertiesMetadata = new PropertiesMetadata();
+ private final XClass beanClass;
+ private final DirectoryProvider[] directoryProviders;
+ private final IndexShardingStrategy shardingStrategy;
+ private String idKeywordName;
+ private XMember idGetter;
+ private Float idBoost;
+ public static final String CLASS_FIELDNAME = "_hibernate_class";
+ private TwoWayFieldBridge idBridge;
+ private Set<Class> mappedSubclasses = new HashSet<Class>();
+ private ReflectionManager reflectionManager;
+ private int level = 0;
+ private int maxLevel = Integer.MAX_VALUE;
+ private final ScopedAnalyzer analyzer = new ScopedAnalyzer();
+ private Similarity similarity;
+ private boolean isRoot;
+ //if composite id, use of (a, b) in ((1,2), (3,4)) fails on most database
+ private boolean safeFromTupleId;
+ private boolean idProvided = false;
- public boolean isRoot() {
- return isRoot;
- }
+ public boolean isRoot() {
+ return isRoot;
+ }
- public DocumentBuilder(XClass clazz, InitContext context, DirectoryProvider[] directoryProviders,
- IndexShardingStrategy shardingStrategy, ReflectionManager reflectionManager) {
- this.beanClass = clazz;
- this.directoryProviders = directoryProviders;
- this.shardingStrategy = shardingStrategy;
- //FIXME get rid of it when boost is stored?
- this.reflectionManager = reflectionManager;
- this.similarity = context.getDefaultSimilarity();
+ public DocumentBuilder(XClass clazz, InitContext context, DirectoryProvider[] directoryProviders,
+ IndexShardingStrategy shardingStrategy, ReflectionManager reflectionManager) {
+ this.beanClass = clazz;
+ this.directoryProviders = directoryProviders;
+ this.shardingStrategy = shardingStrategy;
+ //FIXME get rid of it when boost is stored?
+ this.reflectionManager = reflectionManager;
+ this.similarity = context.getDefaultSimilarity();
- if (clazz == null) throw new AssertionFailure("Unable to build a DocumentBuilder with a null class");
- rootPropertiesMetadata.boost = getBoost(clazz);
- rootPropertiesMetadata.analyzer = context.getDefaultAnalyzer();
- Set<XClass> processedClasses = new HashSet<XClass>();
- processedClasses.add(clazz);
- initializeMembers(clazz, rootPropertiesMetadata, true, "", processedClasses, context);
- //processedClasses.remove( clazz ); for the sake of completness
- this.analyzer.setGlobalAnalyzer(rootPropertiesMetadata.analyzer);
- if (idKeywordName == null) {
- // if no DocumentId then check if we have a ProvidedId instead
- ProvidedId provided = findProvidedId(clazz);
- if (provided == null) throw new SearchException("No document id in: " + clazz.getName());
+ if ( clazz == null ) throw new AssertionFailure( "Unable to build a DocumentBuilder with a null class" );
+ rootPropertiesMetadata.boost = getBoost( clazz );
+ rootPropertiesMetadata.analyzer = context.getDefaultAnalyzer();
+ Set<XClass> processedClasses = new HashSet<XClass>();
+ processedClasses.add( clazz );
+ initializeMembers( clazz, rootPropertiesMetadata, true, "", processedClasses, context );
+ //processedClasses.remove( clazz ); for the sake of completness
+ this.analyzer.setGlobalAnalyzer( rootPropertiesMetadata.analyzer );
+ if ( idKeywordName == null ) {
+ // if no DocumentId then check if we have a ProvidedId instead
+ ProvidedId provided = findProvidedId( clazz );
+ if ( provided == null ) throw new SearchException( "No document id in: " + clazz.getName() );
- 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 = TwoWayString2FieldBridgeAdaptor.class.isAssignableFrom(idBridge.getClass());
- }
+ 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 = TwoWayString2FieldBridgeAdaptor.class.isAssignableFrom( idBridge.getClass() );
+ }
- private ProvidedId findProvidedId(XClass clazz) {
- ProvidedId id = clazz.getAnnotation(ProvidedId.class);
- if (id == null) {
- if (clazz.getClass().equals(Object.class)) {
- // no superclass!
- return null;
- }
- else {
- // look at superclass
- return findProvidedId(clazz.getSuperclass());
- }
- }
- else {
- return id;
- }
- }
+ private ProvidedId findProvidedId(XClass clazz) {
+ ProvidedId id = null;
+ XClass currentClass = clazz;
+ while ( id == null && currentClass != null) {
+ id = currentClass.getAnnotation( ProvidedId.class );
+ currentClass = clazz.getSuperclass();
+ }
+ return id;
+ }
- private Analyzer getAnalyzer(XAnnotatedElement annotatedElement, InitContext context) {
- org.hibernate.search.annotations.Analyzer analyzerAnn =
- annotatedElement.getAnnotation(org.hibernate.search.annotations.Analyzer.class);
- return getAnalyzer(analyzerAnn, context);
- }
+ private Analyzer getAnalyzer(XAnnotatedElement annotatedElement, InitContext context) {
+ org.hibernate.search.annotations.Analyzer analyzerAnn =
+ annotatedElement.getAnnotation( org.hibernate.search.annotations.Analyzer.class );
+ return getAnalyzer( analyzerAnn, context );
+ }
- private Analyzer getAnalyzer(org.hibernate.search.annotations.Analyzer analyzerAnn, InitContext context) {
- Class analyzerClass = analyzerAnn == null ? void.class : analyzerAnn.impl();
- if (analyzerClass == void.class) {
- String definition = analyzerAnn == null ? "" : analyzerAnn.definition();
- if (StringHelper.isEmpty(definition)) {
- return null;
- }
- else {
+ private Analyzer getAnalyzer(org.hibernate.search.annotations.Analyzer analyzerAnn, InitContext context) {
+ Class analyzerClass = analyzerAnn == null ? void.class : analyzerAnn.impl();
+ if ( analyzerClass == void.class ) {
+ String definition = analyzerAnn == null ? "" : analyzerAnn.definition();
+ if ( StringHelper.isEmpty( definition ) ) {
+ return null;
+ }
+ else {
- return context.buildLazyAnalyzer(definition);
- }
- }
- else {
- try {
- return (Analyzer) analyzerClass.newInstance();
- }
- catch (ClassCastException e) {
- throw new SearchException(
- "Lucene analyzer does not implement " + Analyzer.class.getName() + ": " + analyzerClass.getName(), e
- );
- }
- catch (Exception e) {
- throw new SearchException("Failed to instantiate lucene analyzer with type " + analyzerClass.getName(), e);
- }
- }
- }
+ return context.buildLazyAnalyzer( definition );
+ }
+ }
+ else {
+ try {
+ return (Analyzer) analyzerClass.newInstance();
+ }
+ catch (ClassCastException e) {
+ throw new SearchException(
+ "Lucene analyzer does not implement " + Analyzer.class.getName() + ": " + analyzerClass.getName(), e
+ );
+ }
+ catch (Exception e) {
+ throw new SearchException( "Failed to instantiate lucene analyzer with type " + analyzerClass.getName(), e );
+ }
+ }
+ }
- private void initializeMembers(XClass clazz, PropertiesMetadata propertiesMetadata, boolean isRoot, String prefix,
- Set<XClass> processedClasses, InitContext context) {
- List<XClass> hierarchy = new ArrayList<XClass>();
- for (XClass currClass = clazz; currClass != null; currClass = currClass.getSuperclass()) {
- hierarchy.add(currClass);
- }
- Class similarityClass = null;
- for (int index = hierarchy.size() - 1; index >= 0; index--) {
- XClass currClass = hierarchy.get(index);
- /**
- * Override the default analyzer for the properties if the class hold one
- * That's the reason we go down the hierarchy
- */
- Analyzer analyzer = getAnalyzer(currClass, context);
+ private void initializeMembers(XClass clazz, PropertiesMetadata propertiesMetadata, boolean isRoot, String prefix,
+ Set<XClass> processedClasses, InitContext context) {
+ List<XClass> hierarchy = new ArrayList<XClass>();
+ for (XClass currClass = clazz; currClass != null; currClass = currClass.getSuperclass()) {
+ hierarchy.add( currClass );
+ }
+ Class similarityClass = null;
+ for (int index = hierarchy.size() - 1; index >= 0; index--) {
+ XClass currClass = hierarchy.get( index );
+ /**
+ * Override the default analyzer for the properties if the class hold one
+ * That's the reason we go down the hierarchy
+ */
+ Analyzer analyzer = getAnalyzer( currClass, context );
- if (analyzer != null) {
- propertiesMetadata.analyzer = analyzer;
- }
- getAnalyzerDefs(currClass, context);
- // Check for any ClassBridges annotation.
- ClassBridges classBridgesAnn = currClass.getAnnotation(ClassBridges.class);
- if (classBridgesAnn != null) {
- ClassBridge[] cbs = classBridgesAnn.value();
- for (ClassBridge cb : cbs) {
- bindClassAnnotation(prefix, propertiesMetadata, cb, context);
- }
- }
+ if ( analyzer != null ) {
+ propertiesMetadata.analyzer = analyzer;
+ }
+ getAnalyzerDefs( currClass, context );
+ // Check for any ClassBridges annotation.
+ ClassBridges classBridgesAnn = currClass.getAnnotation( ClassBridges.class );
+ if ( classBridgesAnn != null ) {
+ ClassBridge[] cbs = classBridgesAnn.value();
+ for (ClassBridge cb : cbs) {
+ bindClassAnnotation( prefix, propertiesMetadata, cb, context );
+ }
+ }
- // Check for any ClassBridge style of annotations.
- ClassBridge classBridgeAnn = currClass.getAnnotation(ClassBridge.class);
- if (classBridgeAnn != null) {
- bindClassAnnotation(prefix, propertiesMetadata, classBridgeAnn, context);
- }
+ // Check for any ClassBridge style of annotations.
+ ClassBridge classBridgeAnn = currClass.getAnnotation( ClassBridge.class );
+ if ( classBridgeAnn != null ) {
+ bindClassAnnotation( prefix, propertiesMetadata, classBridgeAnn, context );
+ }
- //Get similarity
- //TODO: similarity form @IndexedEmbedded are not taken care of. Exception??
- if (isRoot) {
- org.hibernate.search.annotations.Similarity similarityAnn = currClass.getAnnotation(org.hibernate.search.annotations.Similarity.class);
- if (similarityAnn != null) {
- if (similarityClass != null) {
- throw new SearchException("Multiple Similarities defined in the same class hierarchy: " + beanClass.getName());
- }
- similarityClass = similarityAnn.impl();
- }
- }
+ //Get similarity
+ //TODO: similarity form @IndexedEmbedded are not taken care of. Exception??
+ if ( isRoot ) {
+ org.hibernate.search.annotations.Similarity similarityAnn = currClass.getAnnotation( org.hibernate.search.annotations.Similarity.class );
+ if ( similarityAnn != null ) {
+ if ( similarityClass != null ) {
+ throw new SearchException( "Multiple Similarities defined in the same class hierarchy: " + beanClass.getName() );
+ }
+ similarityClass = similarityAnn.impl();
+ }
+ }
- //rejecting non properties (ie regular methods) because the object is loaded from Hibernate,
- // so indexing a non property does not make sense
- List<XProperty> methods = currClass.getDeclaredProperties(XClass.ACCESS_PROPERTY);
- for (XProperty method : methods) {
- initializeMember(method, propertiesMetadata, isRoot, prefix, processedClasses, context);
- }
+ //rejecting non properties (ie regular methods) because the object is loaded from Hibernate,
+ // so indexing a non property does not make sense
+ List<XProperty> methods = currClass.getDeclaredProperties( XClass.ACCESS_PROPERTY );
+ for (XProperty method : methods) {
+ initializeMember( method, propertiesMetadata, isRoot, prefix, processedClasses, context );
+ }
- List<XProperty> fields = currClass.getDeclaredProperties(XClass.ACCESS_FIELD);
- for (XProperty field : fields) {
- initializeMember(field, propertiesMetadata, isRoot, prefix, processedClasses, context);
- }
- }
- if (isRoot && similarityClass != null) {
- try {
- similarity = (Similarity) similarityClass.newInstance();
- }
- catch (Exception e) {
- log.error("Exception attempting to instantiate Similarity '{}' set for {}",
- similarityClass.getName(), beanClass.getName());
- }
- }
- }
+ List<XProperty> fields = currClass.getDeclaredProperties( XClass.ACCESS_FIELD );
+ for (XProperty field : fields) {
+ initializeMember( field, propertiesMetadata, isRoot, prefix, processedClasses, context );
+ }
+ }
+ if ( isRoot && similarityClass != null ) {
+ try {
+ similarity = (Similarity) similarityClass.newInstance();
+ }
+ catch (Exception e) {
+ log.error( "Exception attempting to instantiate Similarity '{}' set for {}",
+ similarityClass.getName(), beanClass.getName() );
+ }
+ }
+ }
- private void getAnalyzerDefs(XAnnotatedElement annotatedElement, InitContext context) {
- AnalyzerDefs defs = annotatedElement.getAnnotation(AnalyzerDefs.class);
- if (defs != null) {
- for (AnalyzerDef def : defs.value()) {
- context.addAnalyzerDef(def);
- }
- }
- AnalyzerDef def = annotatedElement.getAnnotation(AnalyzerDef.class);
- context.addAnalyzerDef(def);
- }
+ private void getAnalyzerDefs(XAnnotatedElement annotatedElement, InitContext context) {
+ AnalyzerDefs defs = annotatedElement.getAnnotation( AnalyzerDefs.class );
+ if ( defs != null ) {
+ for (AnalyzerDef def : defs.value()) {
+ context.addAnalyzerDef( def );
+ }
+ }
+ AnalyzerDef def = annotatedElement.getAnnotation( AnalyzerDef.class );
+ context.addAnalyzerDef( def );
+ }
- public String getIdentifierName() {
- return idGetter.getName();
- }
+ public String getIdentifierName() {
+ return idGetter.getName();
+ }
- public Similarity getSimilarity() {
- return similarity;
- }
+ public Similarity getSimilarity() {
+ return similarity;
+ }
- private void initializeMember(XProperty member, PropertiesMetadata propertiesMetadata, boolean isRoot,
- String prefix, Set<XClass> processedClasses, InitContext context) {
+ private void initializeMember(XProperty member, PropertiesMetadata propertiesMetadata, boolean isRoot,
+ String prefix, Set<XClass> processedClasses, InitContext context) {
- DocumentId documentIdAnn = member.getAnnotation(DocumentId.class);
- if (documentIdAnn != null) {
- if (isRoot) {
- if (idKeywordName != null) {
- throw new AssertionFailure("Two document id assigned: "
- + idKeywordName + " and " + BinderHelper.getAttributeName(member, documentIdAnn.name()));
- }
- idKeywordName = prefix + BinderHelper.getAttributeName(member, documentIdAnn.name());
- FieldBridge fieldBridge = BridgeFactory.guessType(null, member, reflectionManager);
- if (fieldBridge instanceof TwoWayFieldBridge) {
- idBridge = (TwoWayFieldBridge) fieldBridge;
- }
- else {
- throw new SearchException(
- "Bridge for document id does not implement TwoWayFieldBridge: " + member.getName());
- }
- idBoost = getBoost(member);
- setAccessible(member);
- idGetter = member;
- }
- else {
- //component should index their document id
- setAccessible(member);
- propertiesMetadata.fieldGetters.add(member);
- String fieldName = prefix + BinderHelper.getAttributeName(member, documentIdAnn.name());
- propertiesMetadata.fieldNames.add(fieldName);
- propertiesMetadata.fieldStore.add(getStore(Store.YES));
- propertiesMetadata.fieldIndex.add(getIndex(Index.UN_TOKENIZED));
- propertiesMetadata.fieldTermVectors.add(getTermVector(TermVector.NO));
- propertiesMetadata.fieldBridges.add(BridgeFactory.guessType(null, member, reflectionManager));
- // property > entity analyzer (no field analyzer)
- Analyzer analyzer = getAnalyzer(member, context);
- if (analyzer == null) analyzer = propertiesMetadata.analyzer;
- if (analyzer == null) throw new AssertionFailure("Analizer should not be undefined");
- this.analyzer.addScopedAnalyzer(fieldName, analyzer);
- }
- }
- {
- org.hibernate.search.annotations.Field fieldAnn =
- member.getAnnotation(org.hibernate.search.annotations.Field.class);
- if (fieldAnn != null) {
- bindFieldAnnotation(member, propertiesMetadata, prefix, fieldAnn, context);
- }
- }
- {
- org.hibernate.search.annotations.Fields fieldsAnn =
- member.getAnnotation(org.hibernate.search.annotations.Fields.class);
- if (fieldsAnn != null) {
- for (org.hibernate.search.annotations.Field fieldAnn : fieldsAnn.value()) {
- bindFieldAnnotation(member, propertiesMetadata, prefix, fieldAnn, context);
- }
- }
- }
- getAnalyzerDefs(member, context);
+ DocumentId documentIdAnn = member.getAnnotation( DocumentId.class );
+ if ( documentIdAnn != null ) {
+ if ( isRoot ) {
+ if ( idKeywordName != null ) {
+ throw new AssertionFailure( "Two document id assigned: "
+ + idKeywordName + " and " + BinderHelper.getAttributeName( member, documentIdAnn.name() ) );
+ }
+ idKeywordName = prefix + BinderHelper.getAttributeName( member, documentIdAnn.name() );
+ FieldBridge fieldBridge = BridgeFactory.guessType( null, member, reflectionManager );
+ if ( fieldBridge instanceof TwoWayFieldBridge ) {
+ idBridge = (TwoWayFieldBridge) fieldBridge;
+ }
+ else {
+ throw new SearchException(
+ "Bridge for document id does not implement TwoWayFieldBridge: " + member.getName() );
+ }
+ idBoost = getBoost( member );
+ setAccessible( member );
+ idGetter = member;
+ }
+ else {
+ //component should index their document id
+ setAccessible( member );
+ propertiesMetadata.fieldGetters.add( member );
+ String fieldName = prefix + BinderHelper.getAttributeName( member, documentIdAnn.name() );
+ propertiesMetadata.fieldNames.add( fieldName );
+ propertiesMetadata.fieldStore.add( getStore( Store.YES ) );
+ propertiesMetadata.fieldIndex.add( getIndex( Index.UN_TOKENIZED ) );
+ propertiesMetadata.fieldTermVectors.add( getTermVector( TermVector.NO ) );
+ propertiesMetadata.fieldBridges.add( BridgeFactory.guessType( null, member, reflectionManager ) );
+ // property > entity analyzer (no field analyzer)
+ Analyzer analyzer = getAnalyzer( member, context );
+ if ( analyzer == null ) analyzer = propertiesMetadata.analyzer;
+ if ( analyzer == null ) throw new AssertionFailure( "Analizer should not be undefined" );
+ this.analyzer.addScopedAnalyzer( fieldName, analyzer );
+ }
+ }
+ {
+ org.hibernate.search.annotations.Field fieldAnn =
+ member.getAnnotation( org.hibernate.search.annotations.Field.class );
+ if ( fieldAnn != null ) {
+ bindFieldAnnotation( member, propertiesMetadata, prefix, fieldAnn, context );
+ }
+ }
+ {
+ org.hibernate.search.annotations.Fields fieldsAnn =
+ member.getAnnotation( org.hibernate.search.annotations.Fields.class );
+ if ( fieldsAnn != null ) {
+ for (org.hibernate.search.annotations.Field fieldAnn : fieldsAnn.value()) {
+ bindFieldAnnotation( member, propertiesMetadata, prefix, fieldAnn, context );
+ }
+ }
+ }
+ getAnalyzerDefs( member, context );
- IndexedEmbedded embeddedAnn = member.getAnnotation(IndexedEmbedded.class);
- if (embeddedAnn != null) {
- int oldMaxLevel = maxLevel;
- int potentialLevel = embeddedAnn.depth() + level;
- if (potentialLevel < 0) {
- potentialLevel = Integer.MAX_VALUE;
- }
- maxLevel = potentialLevel > maxLevel ? maxLevel : potentialLevel;
- level++;
+ IndexedEmbedded embeddedAnn = member.getAnnotation( IndexedEmbedded.class );
+ if ( embeddedAnn != null ) {
+ int oldMaxLevel = maxLevel;
+ int potentialLevel = embeddedAnn.depth() + level;
+ if ( potentialLevel < 0 ) {
+ potentialLevel = Integer.MAX_VALUE;
+ }
+ maxLevel = potentialLevel > maxLevel ? maxLevel : potentialLevel;
+ level++;
- XClass elementClass;
- if (void.class == embeddedAnn.targetElement()) {
- elementClass = member.getElementClass();
- }
- else {
- elementClass = reflectionManager.toXClass(embeddedAnn.targetElement());
- }
- if (maxLevel == Integer.MAX_VALUE //infinite
- && processedClasses.contains(elementClass)) {
- throw new SearchException(
- "Circular reference. Duplicate use of "
- + elementClass.getName()
- + " in root entity " + beanClass.getName()
- + "#" + buildEmbeddedPrefix(prefix, embeddedAnn, member)
- );
- }
- if (level <= maxLevel) {
- processedClasses.add(elementClass); //push
+ XClass elementClass;
+ if ( void.class == embeddedAnn.targetElement() ) {
+ elementClass = member.getElementClass();
+ }
+ else {
+ elementClass = reflectionManager.toXClass( embeddedAnn.targetElement() );
+ }
+ if ( maxLevel == Integer.MAX_VALUE //infinite
+ && processedClasses.contains( elementClass ) ) {
+ throw new SearchException(
+ "Circular reference. Duplicate use of "
+ + elementClass.getName()
+ + " in root entity " + beanClass.getName()
+ + "#" + buildEmbeddedPrefix( prefix, embeddedAnn, member )
+ );
+ }
+ if ( level <= maxLevel ) {
+ processedClasses.add( elementClass ); //push
- setAccessible(member);
- propertiesMetadata.embeddedGetters.add(member);
- PropertiesMetadata metadata = new PropertiesMetadata();
- propertiesMetadata.embeddedPropertiesMetadata.add(metadata);
- metadata.boost = getBoost(member);
- //property > entity analyzer
- Analyzer analyzer = getAnalyzer(member, context);
- metadata.analyzer = analyzer != null ? analyzer : propertiesMetadata.analyzer;
- String localPrefix = buildEmbeddedPrefix(prefix, embeddedAnn, member);
- initializeMembers(elementClass, metadata, false, localPrefix, processedClasses, context);
- /**
- * We will only index the "expected" type but that's OK, HQL cannot do downcasting either
- */
- if (member.isArray()) {
- propertiesMetadata.embeddedContainers.add(PropertiesMetadata.Container.ARRAY);
- }
- else
- if (member.isCollection()) {
- if (Map.class.equals(member.getCollectionClass())) {
- //hum subclasses etc etc??
- propertiesMetadata.embeddedContainers.add(PropertiesMetadata.Container.MAP);
- }
- else {
- propertiesMetadata.embeddedContainers.add(PropertiesMetadata.Container.COLLECTION);
- }
- }
- else {
- propertiesMetadata.embeddedContainers.add(PropertiesMetadata.Container.OBJECT);
- }
+ setAccessible( member );
+ propertiesMetadata.embeddedGetters.add( member );
+ PropertiesMetadata metadata = new PropertiesMetadata();
+ propertiesMetadata.embeddedPropertiesMetadata.add( metadata );
+ metadata.boost = getBoost( member );
+ //property > entity analyzer
+ Analyzer analyzer = getAnalyzer( member, context );
+ metadata.analyzer = analyzer != null ? analyzer : propertiesMetadata.analyzer;
+ String localPrefix = buildEmbeddedPrefix( prefix, embeddedAnn, member );
+ initializeMembers( elementClass, metadata, false, localPrefix, processedClasses, context );
+ /**
+ * We will only index the "expected" type but that's OK, HQL cannot do downcasting either
+ */
+ if ( member.isArray() ) {
+ propertiesMetadata.embeddedContainers.add( PropertiesMetadata.Container.ARRAY );
+ }
+ else if ( member.isCollection() ) {
+ if ( Map.class.equals( member.getCollectionClass() ) ) {
+ //hum subclasses etc etc??
+ propertiesMetadata.embeddedContainers.add( PropertiesMetadata.Container.MAP );
+ }
+ else {
+ propertiesMetadata.embeddedContainers.add( PropertiesMetadata.Container.COLLECTION );
+ }
+ }
+ else {
+ propertiesMetadata.embeddedContainers.add( PropertiesMetadata.Container.OBJECT );
+ }
- processedClasses.remove(elementClass); //pop
- }
- else
- if (log.isTraceEnabled()) {
- String localPrefix = buildEmbeddedPrefix(prefix, embeddedAnn, member);
- log.trace("depth reached, ignoring {}", localPrefix);
- }
+ processedClasses.remove( elementClass ); //pop
+ }
+ else if ( log.isTraceEnabled() ) {
+ String localPrefix = buildEmbeddedPrefix( prefix, embeddedAnn, member );
+ log.trace( "depth reached, ignoring {}", localPrefix );
+ }
- level--;
- maxLevel = oldMaxLevel; //set back the the old max level
- }
+ level--;
+ maxLevel = oldMaxLevel; //set back the the old max level
+ }
- ContainedIn containedAnn = member.getAnnotation(ContainedIn.class);
- if (containedAnn != null) {
- setAccessible(member);
- propertiesMetadata.containedInGetters.add(member);
- }
- }
+ ContainedIn containedAnn = member.getAnnotation( ContainedIn.class );
+ if ( containedAnn != null ) {
+ setAccessible( member );
+ propertiesMetadata.containedInGetters.add( member );
+ }
+ }
- private void bindClassAnnotation(String prefix, PropertiesMetadata propertiesMetadata, ClassBridge ann, InitContext context) {
- //FIXME name should be prefixed
- String fieldName = prefix + ann.name();
- propertiesMetadata.classNames.add(fieldName);
- propertiesMetadata.classStores.add(getStore(ann.store()));
- propertiesMetadata.classIndexes.add(getIndex(ann.index()));
- propertiesMetadata.classTermVectors.add(getTermVector(ann.termVector()));
- propertiesMetadata.classBridges.add(BridgeFactory.extractType(ann));
- propertiesMetadata.classBoosts.add(ann.boost().value());
+ private void bindClassAnnotation(String prefix, PropertiesMetadata propertiesMetadata, ClassBridge ann, InitContext context) {
+ //FIXME name should be prefixed
+ String fieldName = prefix + ann.name();
+ propertiesMetadata.classNames.add( fieldName );
+ propertiesMetadata.classStores.add( getStore( ann.store() ) );
+ propertiesMetadata.classIndexes.add( getIndex( ann.index() ) );
+ propertiesMetadata.classTermVectors.add( getTermVector( ann.termVector() ) );
+ propertiesMetadata.classBridges.add( BridgeFactory.extractType( ann ) );
+ propertiesMetadata.classBoosts.add( ann.boost().value() );
- Analyzer analyzer = getAnalyzer(ann.analyzer(), context);
- if (analyzer == null) analyzer = propertiesMetadata.analyzer;
- if (analyzer == null) throw new AssertionFailure("Analyzer should not be undefined");
- this.analyzer.addScopedAnalyzer(fieldName, analyzer);
- }
+ Analyzer analyzer = getAnalyzer( ann.analyzer(), context );
+ if ( analyzer == null ) analyzer = propertiesMetadata.analyzer;
+ if ( analyzer == null ) throw new AssertionFailure( "Analyzer should not be undefined" );
+ this.analyzer.addScopedAnalyzer( fieldName, analyzer );
+ }
- private void bindFieldAnnotation(XProperty member, PropertiesMetadata propertiesMetadata, String prefix, org.hibernate.search.annotations.Field fieldAnn, InitContext context) {
- setAccessible(member);
- propertiesMetadata.fieldGetters.add(member);
- String fieldName = prefix + BinderHelper.getAttributeName(member, fieldAnn.name());
- propertiesMetadata.fieldNames.add(fieldName);
- propertiesMetadata.fieldStore.add(getStore(fieldAnn.store()));
- propertiesMetadata.fieldIndex.add(getIndex(fieldAnn.index()));
- propertiesMetadata.fieldTermVectors.add(getTermVector(fieldAnn.termVector()));
- propertiesMetadata.fieldBridges.add(BridgeFactory.guessType(fieldAnn, member, reflectionManager));
+ private void bindFieldAnnotation(XProperty member, PropertiesMetadata propertiesMetadata, String prefix, org.hibernate.search.annotations.Field fieldAnn, InitContext context) {
+ setAccessible( member );
+ propertiesMetadata.fieldGetters.add( member );
+ String fieldName = prefix + BinderHelper.getAttributeName( member, fieldAnn.name() );
+ propertiesMetadata.fieldNames.add( fieldName );
+ propertiesMetadata.fieldStore.add( getStore( fieldAnn.store() ) );
+ propertiesMetadata.fieldIndex.add( getIndex( fieldAnn.index() ) );
+ propertiesMetadata.fieldTermVectors.add( getTermVector( fieldAnn.termVector() ) );
+ propertiesMetadata.fieldBridges.add( BridgeFactory.guessType( fieldAnn, member, reflectionManager ) );
- // Field > property > entity analyzer
- Analyzer analyzer = getAnalyzer(fieldAnn.analyzer(), context);
- if (analyzer == null) analyzer = getAnalyzer(member, context);
- if (analyzer == null) analyzer = propertiesMetadata.analyzer;
- if (analyzer == null) throw new AssertionFailure("Analizer should not be undefined");
- this.analyzer.addScopedAnalyzer(fieldName, analyzer);
- }
+ // Field > property > entity analyzer
+ Analyzer analyzer = getAnalyzer( fieldAnn.analyzer(), context );
+ if ( analyzer == null ) analyzer = getAnalyzer( member, context );
+ if ( analyzer == null ) analyzer = propertiesMetadata.analyzer;
+ if ( analyzer == null ) throw new AssertionFailure( "Analizer should not be undefined" );
+ this.analyzer.addScopedAnalyzer( fieldName, analyzer );
+ }
- private String buildEmbeddedPrefix(String prefix, IndexedEmbedded embeddedAnn, XProperty member) {
- String localPrefix = prefix;
- if (".".equals(embeddedAnn.prefix())) {
- //default to property name
- localPrefix += member.getName() + '.';
- }
- else {
- localPrefix += embeddedAnn.prefix();
- }
- return localPrefix;
- }
+ private String buildEmbeddedPrefix(String prefix, IndexedEmbedded embeddedAnn, XProperty member) {
+ String localPrefix = prefix;
+ if ( ".".equals( embeddedAnn.prefix() ) ) {
+ //default to property name
+ localPrefix += member.getName() + '.';
+ }
+ else {
+ localPrefix += embeddedAnn.prefix();
+ }
+ return localPrefix;
+ }
- private Field.Store getStore(Store store) {
- switch (store) {
- case NO:
- return Field.Store.NO;
- case YES:
- return Field.Store.YES;
- case COMPRESS:
- return Field.Store.COMPRESS;
- default:
- throw new AssertionFailure("Unexpected Store: " + store);
- }
- }
+ private Field.Store getStore(Store store) {
+ switch ( store ) {
+ case NO:
+ return Field.Store.NO;
+ case YES:
+ return Field.Store.YES;
+ case COMPRESS:
+ return Field.Store.COMPRESS;
+ default:
+ throw new AssertionFailure( "Unexpected Store: " + store );
+ }
+ }
- private Field.TermVector getTermVector(TermVector vector) {
- switch (vector) {
- case NO:
- return Field.TermVector.NO;
- case YES:
- return Field.TermVector.YES;
- case WITH_OFFSETS:
- return Field.TermVector.WITH_OFFSETS;
- case WITH_POSITIONS:
- return Field.TermVector.WITH_POSITIONS;
- case WITH_POSITION_OFFSETS:
- return Field.TermVector.WITH_POSITIONS_OFFSETS;
- default:
- throw new AssertionFailure("Unexpected TermVector: " + vector);
- }
- }
+ private Field.TermVector getTermVector(TermVector vector) {
+ switch ( vector ) {
+ case NO:
+ return Field.TermVector.NO;
+ case YES:
+ return Field.TermVector.YES;
+ case WITH_OFFSETS:
+ return Field.TermVector.WITH_OFFSETS;
+ case WITH_POSITIONS:
+ return Field.TermVector.WITH_POSITIONS;
+ case WITH_POSITION_OFFSETS:
+ return Field.TermVector.WITH_POSITIONS_OFFSETS;
+ default:
+ throw new AssertionFailure( "Unexpected TermVector: " + vector );
+ }
+ }
- private Field.Index getIndex(Index index) {
- switch (index) {
- case NO:
- return Field.Index.NO;
- case NO_NORMS:
- return Field.Index.NO_NORMS;
- case TOKENIZED:
- return Field.Index.TOKENIZED;
- case UN_TOKENIZED:
- return Field.Index.UN_TOKENIZED;
- default:
- throw new AssertionFailure("Unexpected Index: " + index);
- }
- }
+ private Field.Index getIndex(Index index) {
+ switch ( index ) {
+ case NO:
+ return Field.Index.NO;
+ case NO_NORMS:
+ return Field.Index.NO_NORMS;
+ case TOKENIZED:
+ return Field.Index.TOKENIZED;
+ case UN_TOKENIZED:
+ return Field.Index.UN_TOKENIZED;
+ default:
+ throw new AssertionFailure( "Unexpected Index: " + index );
+ }
+ }
- private Float getBoost(XAnnotatedElement element) {
- if (element == null) return null;
- Boost boost = element.getAnnotation(Boost.class);
- return boost != null ?
- boost.value() :
- null;
- }
+ private Float getBoost(XAnnotatedElement element) {
+ if ( element == null ) return null;
+ Boost boost = element.getAnnotation( Boost.class );
+ return boost != null ?
+ boost.value() :
+ null;
+ }
- private Object getMemberValue(Object bean, XMember getter) {
- Object value;
- try {
- value = getter.invoke(bean);
- }
- catch (Exception e) {
- throw new IllegalStateException("Could not get property value", e);
- }
- return value;
- }
+ private Object getMemberValue(Object bean, XMember getter) {
+ Object value;
+ try {
+ value = getter.invoke( bean );
+ }
+ catch (Exception e) {
+ throw new IllegalStateException( "Could not get property value", e );
+ }
+ return value;
+ }
- //TODO could we use T instead of EntityClass?
- public void addWorkToQueue(Class entityClass, T entity, Serializable id, WorkType workType, List<LuceneWork> queue, SearchFactoryImplementor searchFactoryImplementor) {
- //TODO with the caller loop we are in a n^2: optimize it using a HashMap for work recognition
- for (LuceneWork luceneWork : queue) {
- //any work on the same entity should be ignored
- if (luceneWork.getEntityClass() == entityClass
- ) {
- Serializable currentId = luceneWork.getId();
- if (currentId != null && currentId.equals(id)) { //find a way to use Type.equals(x,y)
- return;
- }
- //TODO do something to avoid multiple PURGE ALL and OPTIMIZE
- }
+ //TODO could we use T instead of EntityClass?
+ public void addWorkToQueue(Class entityClass, T entity, Serializable id, WorkType workType, List<LuceneWork> queue, SearchFactoryImplementor searchFactoryImplementor) {
+ //TODO with the caller loop we are in a n^2: optimize it using a HashMap for work recognition
+ for (LuceneWork luceneWork : queue) {
+ //any work on the same entity should be ignored
+ if ( luceneWork.getEntityClass() == entityClass
+ ) {
+ Serializable currentId = luceneWork.getId();
+ if ( currentId != null && currentId.equals( id ) ) { //find a way to use Type.equals(x,y)
+ return;
+ }
+ //TODO do something to avoid multiple PURGE ALL and OPTIMIZE
+ }
- }
- boolean searchForContainers = false;
- String idInString = idBridge.objectToString(id);
- if (workType == WorkType.ADD) {
- Document doc = getDocument(entity, id);
- queue.add(new AddLuceneWork(id, idInString, entityClass, doc));
- searchForContainers = true;
- }
- else
- if (workType == WorkType.DELETE || workType == WorkType.PURGE) {
- queue.add(new DeleteLuceneWork(id, idInString, entityClass));
- }
- else
- if (workType == WorkType.PURGE_ALL) {
- queue.add(new PurgeAllLuceneWork(entityClass));
- }
- else
- if (workType == WorkType.UPDATE || workType == WorkType.COLLECTION) {
- Document doc = getDocument(entity, id);
- /**
- * even with Lucene 2.1, use of indexWriter to update is not an option
- * We can only delete by term, and the index doesn't have a term that
- * uniquely identify the entry.
- * But essentially the optimization we are doing is the same Lucene is doing, the only extra cost is the
- * double file opening.
- */
- queue.add(new DeleteLuceneWork(id, idInString, entityClass));
- queue.add(new AddLuceneWork(id, idInString, entityClass, doc));
- searchForContainers = true;
- }
- else
- if (workType == WorkType.INDEX) {
- Document doc = getDocument(entity, id);
- queue.add(new DeleteLuceneWork(id, idInString, entityClass));
- LuceneWork work = new AddLuceneWork(id, idInString, entityClass, doc);
- work.setBatch(true);
- queue.add(work);
- searchForContainers = true;
- }
+ }
+ boolean searchForContainers = false;
+ String idInString = idBridge.objectToString( id );
+ if ( workType == WorkType.ADD ) {
+ Document doc = getDocument( entity, id );
+ queue.add( new AddLuceneWork( id, idInString, entityClass, doc ) );
+ searchForContainers = true;
+ }
+ else if ( workType == WorkType.DELETE || workType == WorkType.PURGE ) {
+ queue.add( new DeleteLuceneWork( id, idInString, entityClass ) );
+ }
+ else if ( workType == WorkType.PURGE_ALL ) {
+ queue.add( new PurgeAllLuceneWork( entityClass ) );
+ }
+ else if ( workType == WorkType.UPDATE || workType == WorkType.COLLECTION ) {
+ Document doc = getDocument( entity, id );
+ /**
+ * even with Lucene 2.1, use of indexWriter to update is not an option
+ * We can only delete by term, and the index doesn't have a term that
+ * uniquely identify the entry.
+ * But essentially the optimization we are doing is the same Lucene is doing, the only extra cost is the
+ * double file opening.
+ */
+ queue.add( new DeleteLuceneWork( id, idInString, entityClass ) );
+ queue.add( new AddLuceneWork( id, idInString, entityClass, doc ) );
+ searchForContainers = true;
+ }
+ else if ( workType == WorkType.INDEX ) {
+ Document doc = getDocument( entity, id );
+ queue.add( new DeleteLuceneWork( id, idInString, entityClass ) );
+ LuceneWork work = new AddLuceneWork( id, idInString, entityClass, doc );
+ work.setBatch( true );
+ queue.add( work );
+ searchForContainers = true;
+ }
- else {
- throw new AssertionFailure("Unknown WorkType: " + workType);
- }
+ else {
+ throw new AssertionFailure( "Unknown WorkType: " + workType );
+ }
- /**
- * When references are changed, either null or another one, we expect dirty checking to be triggered (both sides
- * have to be updated)
- * When the internal object is changed, we apply the {Add|Update}Work on containedIns
- */
- if (searchForContainers) {
- processContainedIn(entity, queue, rootPropertiesMetadata, searchFactoryImplementor);
- }
- }
+ /**
+ * When references are changed, either null or another one, we expect dirty checking to be triggered (both sides
+ * have to be updated)
+ * When the internal object is changed, we apply the {Add|Update}Work on containedIns
+ */
+ if ( searchForContainers ) {
+ processContainedIn( entity, queue, rootPropertiesMetadata, searchFactoryImplementor );
+ }
+ }
- private void processContainedIn(Object instance, List<LuceneWork> queue, PropertiesMetadata metadata, SearchFactoryImplementor searchFactoryImplementor) {
- for (int i = 0; i < metadata.containedInGetters.size(); i++) {
- XMember member = metadata.containedInGetters.get(i);
- Object value = getMemberValue(instance, member);
- if (value == null) continue;
+ private void processContainedIn(Object instance, List<LuceneWork> queue, PropertiesMetadata metadata, SearchFactoryImplementor searchFactoryImplementor) {
+ for (int i = 0; i < metadata.containedInGetters.size(); i++) {
+ XMember member = metadata.containedInGetters.get( i );
+ Object value = getMemberValue( instance, member );
+ if ( value == null ) continue;
- if (member.isArray()) {
- for (Object arrayValue : (Object[]) value) {
- //highly inneficient but safe wrt the actual targeted class
- Class valueClass = Hibernate.getClass(arrayValue);
- DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilders().get(valueClass);
- if (builder == null) continue;
- processContainedInValue(arrayValue, queue, valueClass, builder, searchFactoryImplementor);
- }
- }
- else
- if (member.isCollection()) {
- Collection collection;
- if (Map.class.equals(member.getCollectionClass())) {
- //hum
- collection = ((Map) value).values();
- }
- else {
- collection = (Collection) value;
- }
- for (Object collectionValue : collection) {
- //highly inneficient but safe wrt the actual targeted class
- Class valueClass = Hibernate.getClass(collectionValue);
- DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilders().get(valueClass);
- if (builder == null) continue;
- processContainedInValue(collectionValue, queue, valueClass, builder, searchFactoryImplementor);
- }
- }
- else {
- Class valueClass = Hibernate.getClass(value);
- DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilders().get(valueClass);
- if (builder == null) continue;
- processContainedInValue(value, queue, valueClass, builder, searchFactoryImplementor);
- }
- }
- //an embedded cannot have a useful @ContainedIn (no shared reference)
- //do not walk through them
- }
+ if ( member.isArray() ) {
+ for (Object arrayValue : (Object[]) value) {
+ //highly inneficient but safe wrt the actual targeted class
+ Class valueClass = Hibernate.getClass( arrayValue );
+ DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilders().get( valueClass );
+ if ( builder == null ) continue;
+ processContainedInValue( arrayValue, queue, valueClass, builder, searchFactoryImplementor );
+ }
+ }
+ else if ( member.isCollection() ) {
+ Collection collection;
+ if ( Map.class.equals( member.getCollectionClass() ) ) {
+ //hum
+ collection = ( (Map) value ).values();
+ }
+ else {
+ collection = (Collection) value;
+ }
+ for (Object collectionValue : collection) {
+ //highly inneficient but safe wrt the actual targeted class
+ Class valueClass = Hibernate.getClass( collectionValue );
+ DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilders().get( valueClass );
+ if ( builder == null ) continue;
+ processContainedInValue( collectionValue, queue, valueClass, builder, searchFactoryImplementor );
+ }
+ }
+ else {
+ Class valueClass = Hibernate.getClass( value );
+ DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilders().get( valueClass );
+ if ( builder == null ) continue;
+ processContainedInValue( value, queue, valueClass, builder, searchFactoryImplementor );
+ }
+ }
+ //an embedded cannot have a useful @ContainedIn (no shared reference)
+ //do not walk through them
+ }
- private void processContainedInValue(Object value, List<LuceneWork> queue, Class valueClass,
- DocumentBuilder builder, SearchFactoryImplementor searchFactoryImplementor) {
- Serializable id = (Serializable) builder.getMemberValue(value, builder.idGetter);
- builder.addWorkToQueue(valueClass, value, id, WorkType.UPDATE, queue, searchFactoryImplementor);
- }
+ private void processContainedInValue(Object value, List<LuceneWork> queue, Class valueClass,
+ DocumentBuilder builder, SearchFactoryImplementor searchFactoryImplementor) {
+ Serializable id = (Serializable) builder.getMemberValue( value, builder.idGetter );
+ builder.addWorkToQueue( valueClass, value, id, WorkType.UPDATE, queue, searchFactoryImplementor );
+ }
- public Document getDocument(T instance, Serializable id) {
- Document doc = new Document();
- XClass instanceClass = reflectionManager.toXClass(Hibernate.getClass(instance));
- if (rootPropertiesMetadata.boost != null) {
- doc.setBoost(rootPropertiesMetadata.boost);
- }
- {
- Field classField =
- new Field(CLASS_FIELDNAME, instanceClass.getName(), Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.NO);
- doc.add(classField);
- LuceneOptions luceneOptions = new LuceneOptions(Field.Store.YES,
- Field.Index.UN_TOKENIZED, Field.TermVector.NO, idBoost);
- idBridge.set(idKeywordName, id, doc, luceneOptions);
- }
- buildDocumentFields(instance, doc, rootPropertiesMetadata);
- return doc;
- }
+ public Document getDocument(T instance, Serializable id) {
+ Document doc = new Document();
+ XClass instanceClass = reflectionManager.toXClass( Hibernate.getClass( instance ) );
+ if ( rootPropertiesMetadata.boost != null ) {
+ doc.setBoost( rootPropertiesMetadata.boost );
+ }
+ {
+ Field classField =
+ new Field( CLASS_FIELDNAME, instanceClass.getName(), Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.NO );
+ doc.add( classField );
+ LuceneOptions luceneOptions = new LuceneOptions( Field.Store.YES,
+ Field.Index.UN_TOKENIZED, Field.TermVector.NO, idBoost );
+ idBridge.set( idKeywordName, id, doc, luceneOptions );
+ }
+ buildDocumentFields( instance, doc, rootPropertiesMetadata );
+ return doc;
+ }
- private void buildDocumentFields(Object instance, Document doc, PropertiesMetadata propertiesMetadata) {
- if (instance == null) return;
- //needed for field access: I cannot work in the proxied version
- Object unproxiedInstance = unproxy(instance);
- for (int i = 0; i < propertiesMetadata.classBridges.size(); i++) {
- FieldBridge fb = propertiesMetadata.classBridges.get(i);
- fb.set(propertiesMetadata.classNames.get(i), unproxiedInstance,
- doc, propertiesMetadata.getClassLuceneOptions(i));
- }
- for (int i = 0; i < propertiesMetadata.fieldNames.size(); i++) {
- XMember member = propertiesMetadata.fieldGetters.get(i);
- Object value = getMemberValue(unproxiedInstance, member);
- propertiesMetadata.fieldBridges.get(i).set(
- propertiesMetadata.fieldNames.get(i), value, doc,
- propertiesMetadata.getFieldLuceneOptions(i, getBoost(member)));
- }
- for (int i = 0; i < propertiesMetadata.embeddedGetters.size(); i++) {
- XMember member = propertiesMetadata.embeddedGetters.get(i);
- Object value = getMemberValue(unproxiedInstance, member);
- //TODO handle boost at embedded level: already stored in propertiesMedatada.boost
+ private void buildDocumentFields(Object instance, Document doc, PropertiesMetadata propertiesMetadata) {
+ if ( instance == null ) return;
+ //needed for field access: I cannot work in the proxied version
+ Object unproxiedInstance = unproxy( instance );
+ for (int i = 0; i < propertiesMetadata.classBridges.size(); i++) {
+ FieldBridge fb = propertiesMetadata.classBridges.get( i );
+ fb.set( propertiesMetadata.classNames.get( i ), unproxiedInstance,
+ doc, propertiesMetadata.getClassLuceneOptions( i ) );
+ }
+ for (int i = 0; i < propertiesMetadata.fieldNames.size(); i++) {
+ XMember member = propertiesMetadata.fieldGetters.get( i );
+ Object value = getMemberValue( unproxiedInstance, member );
+ propertiesMetadata.fieldBridges.get( i ).set(
+ propertiesMetadata.fieldNames.get( i ), value, doc,
+ propertiesMetadata.getFieldLuceneOptions( i, getBoost( member ) ) );
+ }
+ for (int i = 0; i < propertiesMetadata.embeddedGetters.size(); i++) {
+ XMember member = propertiesMetadata.embeddedGetters.get( i );
+ Object value = getMemberValue( unproxiedInstance, member );
+ //TODO handle boost at embedded level: already stored in propertiesMedatada.boost
- if (value == null) continue;
- PropertiesMetadata embeddedMetadata = propertiesMetadata.embeddedPropertiesMetadata.get(i);
- switch (propertiesMetadata.embeddedContainers.get(i)) {
- case ARRAY:
- for (Object arrayValue : (Object[]) value) {
- buildDocumentFields(arrayValue, doc, embeddedMetadata);
- }
- break;
- case COLLECTION:
- for (Object collectionValue : (Collection) value) {
- buildDocumentFields(collectionValue, doc, embeddedMetadata);
- }
- break;
- case MAP:
- for (Object collectionValue : ((Map) value).values()) {
- buildDocumentFields(collectionValue, doc, embeddedMetadata);
- }
- break;
- case OBJECT:
- buildDocumentFields(value, doc, embeddedMetadata);
- break;
- default:
- throw new AssertionFailure("Unknown embedded container: "
- + propertiesMetadata.embeddedContainers.get(i));
- }
- }
- }
+ if ( value == null ) continue;
+ PropertiesMetadata embeddedMetadata = propertiesMetadata.embeddedPropertiesMetadata.get( i );
+ switch ( propertiesMetadata.embeddedContainers.get( i ) ) {
+ case ARRAY:
+ for (Object arrayValue : (Object[]) value) {
+ buildDocumentFields( arrayValue, doc, embeddedMetadata );
+ }
+ break;
+ case COLLECTION:
+ for (Object collectionValue : (Collection) value) {
+ buildDocumentFields( collectionValue, doc, embeddedMetadata );
+ }
+ break;
+ case MAP:
+ for (Object collectionValue : ( (Map) value ).values()) {
+ buildDocumentFields( collectionValue, doc, embeddedMetadata );
+ }
+ break;
+ case OBJECT:
+ buildDocumentFields( value, doc, embeddedMetadata );
+ break;
+ default:
+ throw new AssertionFailure( "Unknown embedded container: "
+ + propertiesMetadata.embeddedContainers.get( i ) );
+ }
+ }
+ }
- private Object unproxy(Object value) {
- //FIXME this service should be part of Core?
- if (value instanceof HibernateProxy) {
- // .getImplementation() initializes the data by side effect
- value = ((HibernateProxy) value).getHibernateLazyInitializer()
- .getImplementation();
- }
- return value;
- }
+ private Object unproxy(Object value) {
+ //FIXME this service should be part of Core?
+ if ( value instanceof HibernateProxy ) {
+ // .getImplementation() initializes the data by side effect
+ value = ( (HibernateProxy) value ).getHibernateLazyInitializer()
+ .getImplementation();
+ }
+ return value;
+ }
- public Term getTerm(Serializable id) {
- if (idProvided) {
- return new Term(idKeywordName, (String) id);
- }
+ public Term getTerm(Serializable id) {
+ if ( idProvided ) {
+ return new Term( idKeywordName, (String) id );
+ }
- return new Term(idKeywordName, idBridge.objectToString(id));
- }
+ return new Term( idKeywordName, idBridge.objectToString( id ) );
+ }
- public DirectoryProvider[] getDirectoryProviders() {
- return directoryProviders;
- }
+ public DirectoryProvider[] getDirectoryProviders() {
+ return directoryProviders;
+ }
- public IndexShardingStrategy getDirectoryProviderSelectionStrategy() {
- return shardingStrategy;
- }
+ public IndexShardingStrategy getDirectoryProviderSelectionStrategy() {
+ return shardingStrategy;
+ }
- public Analyzer getAnalyzer() {
- return analyzer;
- }
+ public Analyzer getAnalyzer() {
+ return analyzer;
+ }
- private static void setAccessible(XMember member) {
- if (!Modifier.isPublic(member.getModifiers())) {
- member.setAccessible(true);
- }
- }
+ private static void setAccessible(XMember member) {
+ if ( !Modifier.isPublic( member.getModifiers() ) ) {
+ member.setAccessible( true );
+ }
+ }
- public TwoWayFieldBridge getIdBridge() {
- return idBridge;
- }
+ public TwoWayFieldBridge getIdBridge() {
+ return idBridge;
+ }
- public String getIdKeywordName() {
- return idKeywordName;
- }
+ public String getIdKeywordName() {
+ return idKeywordName;
+ }
- public static Class getDocumentClass(Document document) {
- String className = document.get(DocumentBuilder.CLASS_FIELDNAME);
- try {
- return ReflectHelper.classForName(className);
- }
- catch (ClassNotFoundException e) {
- throw new SearchException("Unable to load indexed class: " + className, e);
- }
- }
+ public static Class getDocumentClass(Document document) {
+ String className = document.get( DocumentBuilder.CLASS_FIELDNAME );
+ try {
+ return ReflectHelper.classForName( className );
+ }
+ catch (ClassNotFoundException e) {
+ throw new SearchException( "Unable to load indexed class: " + className, e );
+ }
+ }
- public static Serializable getDocumentId(SearchFactoryImplementor searchFactoryImplementor, Class clazz, Document document) {
- DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilders().get(clazz);
- if (builder == null) throw new SearchException("No Lucene configuration set up for: " + clazz.getName());
- return (Serializable) builder.getIdBridge().get(builder.getIdKeywordName(), document);
- }
+ public static Serializable getDocumentId(SearchFactoryImplementor searchFactoryImplementor, Class clazz, Document document) {
+ DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilders().get( clazz );
+ if ( builder == null ) throw new SearchException( "No Lucene configuration set up for: " + clazz.getName() );
+ return (Serializable) builder.getIdBridge().get( builder.getIdKeywordName(), document );
+ }
- public static Object[] getDocumentFields(SearchFactoryImplementor searchFactoryImplementor, Class clazz, Document document, String[] fields) {
- DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilders().get(clazz);
- if (builder == null) throw new SearchException("No Lucene configuration set up for: " + clazz.getName());
- final int fieldNbr = fields.length;
- Object[] result = new Object[fieldNbr];
+ public static Object[] getDocumentFields(SearchFactoryImplementor searchFactoryImplementor, Class clazz, Document document, String[] fields) {
+ DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilders().get( clazz );
+ if ( builder == null ) throw new SearchException( "No Lucene configuration set up for: " + clazz.getName() );
+ final int fieldNbr = fields.length;
+ Object[] result = new Object[fieldNbr];
- if (builder.idKeywordName != null) {
- populateResult(builder.idKeywordName, builder.idBridge, Field.Store.YES, fields, result, document);
- }
+ if ( builder.idKeywordName != null ) {
+ populateResult( builder.idKeywordName, builder.idBridge, Field.Store.YES, fields, result, document );
+ }
- final PropertiesMetadata metadata = builder.rootPropertiesMetadata;
- processFieldsForProjection(metadata, fields, result, document);
- return result;
- }
+ final PropertiesMetadata metadata = builder.rootPropertiesMetadata;
+ processFieldsForProjection( metadata, fields, result, document );
+ return result;
+ }
- private static void processFieldsForProjection(PropertiesMetadata metadata, String[] fields, Object[] result, Document document) {
- final int nbrFoEntityFields = metadata.fieldNames.size();
- for (int index = 0; index < nbrFoEntityFields; index++) {
- populateResult(metadata.fieldNames.get(index),
- metadata.fieldBridges.get(index),
- metadata.fieldStore.get(index),
- fields,
- result,
- document
- );
- }
- final int nbrOfEmbeddedObjects = metadata.embeddedPropertiesMetadata.size();
- for (int index = 0; index < nbrOfEmbeddedObjects; index++) {
- //there is nothing we can do for collections
- if (metadata.embeddedContainers.get(index) == PropertiesMetadata.Container.OBJECT) {
- processFieldsForProjection(metadata.embeddedPropertiesMetadata.get(index), fields, result, document);
- }
- }
- }
+ private static void processFieldsForProjection(PropertiesMetadata metadata, String[] fields, Object[] result, Document document) {
+ final int nbrFoEntityFields = metadata.fieldNames.size();
+ for (int index = 0; index < nbrFoEntityFields; index++) {
+ populateResult( metadata.fieldNames.get( index ),
+ metadata.fieldBridges.get( index ),
+ metadata.fieldStore.get( index ),
+ fields,
+ result,
+ document
+ );
+ }
+ final int nbrOfEmbeddedObjects = metadata.embeddedPropertiesMetadata.size();
+ for (int index = 0; index < nbrOfEmbeddedObjects; index++) {
+ //there is nothing we can do for collections
+ if ( metadata.embeddedContainers.get( index ) == PropertiesMetadata.Container.OBJECT ) {
+ processFieldsForProjection( metadata.embeddedPropertiesMetadata.get( index ), fields, result, document );
+ }
+ }
+ }
- private static void populateResult(String fieldName, FieldBridge fieldBridge, Field.Store store,
- String[] fields, Object[] result, Document document) {
- int matchingPosition = getFieldPosition(fields, fieldName);
- if (matchingPosition != -1) {
- //TODO make use of an isTwoWay() method
- if (store != Field.Store.NO && TwoWayFieldBridge.class.isAssignableFrom(fieldBridge.getClass())) {
- result[matchingPosition] = ((TwoWayFieldBridge) fieldBridge).get(fieldName, document);
- if (log.isTraceEnabled()) {
- log.trace("Field {} projected as {}", fieldName, result[matchingPosition]);
- }
- }
- else {
- if (store == Field.Store.NO) {
- throw new SearchException("Projecting an unstored field: " + fieldName);
- }
- else {
- throw new SearchException("FieldBridge is not a TwoWayFieldBridge: " + fieldBridge.getClass());
- }
- }
- }
- }
+ private static void populateResult(String fieldName, FieldBridge fieldBridge, Field.Store store,
+ String[] fields, Object[] result, Document document) {
+ int matchingPosition = getFieldPosition( fields, fieldName );
+ if ( matchingPosition != -1 ) {
+ //TODO make use of an isTwoWay() method
+ if ( store != Field.Store.NO && TwoWayFieldBridge.class.isAssignableFrom( fieldBridge.getClass() ) ) {
+ result[matchingPosition] = ( (TwoWayFieldBridge) fieldBridge ).get( fieldName, document );
+ if ( log.isTraceEnabled() ) {
+ log.trace( "Field {} projected as {}", fieldName, result[matchingPosition] );
+ }
+ }
+ else {
+ if ( store == Field.Store.NO ) {
+ throw new SearchException( "Projecting an unstored field: " + fieldName );
+ }
+ else {
+ throw new SearchException( "FieldBridge is not a TwoWayFieldBridge: " + fieldBridge.getClass() );
+ }
+ }
+ }
+ }
- private static int getFieldPosition(String[] fields, String fieldName) {
- int fieldNbr = fields.length;
- for (int index = 0; index < fieldNbr; index++) {
- if (fieldName.equals(fields[index])) return index;
- }
- return -1;
- }
+ private static int getFieldPosition(String[] fields, String fieldName) {
+ int fieldNbr = fields.length;
+ for (int index = 0; index < fieldNbr; index++) {
+ if ( fieldName.equals( fields[index] ) ) return index;
+ }
+ return -1;
+ }
- public void postInitialize(Set<Class> indexedClasses) {
- //this method does not requires synchronization
- Class plainClass = reflectionManager.toClass(beanClass);
- Set<Class> tempMappedSubclasses = new HashSet<Class>();
- //together with the caller this creates a o(2), but I think it's still faster than create the up hierarchy for each class
- for (Class currentClass : indexedClasses) {
- if (plainClass.isAssignableFrom(currentClass)) tempMappedSubclasses.add(currentClass);
- }
- this.mappedSubclasses = Collections.unmodifiableSet(tempMappedSubclasses);
- Class superClass = plainClass.getSuperclass();
- this.isRoot = true;
- while (superClass != null) {
- if (indexedClasses.contains(superClass)) {
- this.isRoot = false;
- break;
- }
- superClass = superClass.getSuperclass();
- }
- }
+ public void postInitialize(Set<Class> indexedClasses) {
+ //this method does not requires synchronization
+ Class plainClass = reflectionManager.toClass( beanClass );
+ Set<Class> tempMappedSubclasses = new HashSet<Class>();
+ //together with the caller this creates a o(2), but I think it's still faster than create the up hierarchy for each class
+ for (Class currentClass : indexedClasses) {
+ if ( plainClass.isAssignableFrom( currentClass ) ) tempMappedSubclasses.add( currentClass );
+ }
+ this.mappedSubclasses = Collections.unmodifiableSet( tempMappedSubclasses );
+ Class superClass = plainClass.getSuperclass();
+ this.isRoot = true;
+ while ( superClass != null ) {
+ if ( indexedClasses.contains( superClass ) ) {
+ this.isRoot = false;
+ break;
+ }
+ superClass = superClass.getSuperclass();
+ }
+ }
- public Set<Class> getMappedSubclasses() {
- return mappedSubclasses;
- }
+ public Set<Class> getMappedSubclasses() {
+ return mappedSubclasses;
+ }
- /**
- * Make sure to return false if there is a risk of composite id
- * if composite id, use of (a, b) in ((1,2), (3,4)) fails on most database
- */
- public boolean isSafeFromTupleId() {
- return safeFromTupleId;
- }
+ /**
+ * Make sure to return false if there is a risk of composite id
+ * if composite id, use of (a, b) in ((1,2), (3,4)) fails on most database
+ */
+ public boolean isSafeFromTupleId() {
+ return safeFromTupleId;
+ }
- /**
- * Wrapper class containing all the meta data extracted out of the entities.
- */
- private static class PropertiesMetadata {
- public Float boost;
- public Analyzer analyzer;
- public final List<String> fieldNames = new ArrayList<String>();
- public final List<XMember> fieldGetters = new ArrayList<XMember>();
- public final List<FieldBridge> fieldBridges = new ArrayList<FieldBridge>();
- public final List<Field.Store> fieldStore = new ArrayList<Field.Store>();
- public final List<Field.Index> fieldIndex = new ArrayList<Field.Index>();
- public final List<Field.TermVector> fieldTermVectors = new ArrayList<Field.TermVector>();
- public final List<XMember> embeddedGetters = new ArrayList<XMember>();
- public final List<PropertiesMetadata> embeddedPropertiesMetadata = new ArrayList<PropertiesMetadata>();
- public final List<Container> embeddedContainers = new ArrayList<Container>();
- public final List<XMember> containedInGetters = new ArrayList<XMember>();
- public final List<String> classNames = new ArrayList<String>();
- public final List<Field.Store> classStores = new ArrayList<Field.Store>();
- public final List<Field.Index> classIndexes = new ArrayList<Field.Index>();
- public final List<FieldBridge> classBridges = new ArrayList<FieldBridge>();
- public final List<Field.TermVector> classTermVectors = new ArrayList<Field.TermVector>();
- public final List<Float> classBoosts = new ArrayList<Float>();
+ /**
+ * Wrapper class containing all the meta data extracted out of the entities.
+ */
+ private static class PropertiesMetadata {
+ public Float boost;
+ public Analyzer analyzer;
+ public final List<String> fieldNames = new ArrayList<String>();
+ public final List<XMember> fieldGetters = new ArrayList<XMember>();
+ public final List<FieldBridge> fieldBridges = new ArrayList<FieldBridge>();
+ public final List<Field.Store> fieldStore = new ArrayList<Field.Store>();
+ public final List<Field.Index> fieldIndex = new ArrayList<Field.Index>();
+ public final List<Field.TermVector> fieldTermVectors = new ArrayList<Field.TermVector>();
+ public final List<XMember> embeddedGetters = new ArrayList<XMember>();
+ public final List<PropertiesMetadata> embeddedPropertiesMetadata = new ArrayList<PropertiesMetadata>();
+ public final List<Container> embeddedContainers = new ArrayList<Container>();
+ public final List<XMember> containedInGetters = new ArrayList<XMember>();
+ public final List<String> classNames = new ArrayList<String>();
+ public final List<Field.Store> classStores = new ArrayList<Field.Store>();
+ public final List<Field.Index> classIndexes = new ArrayList<Field.Index>();
+ public final List<FieldBridge> classBridges = new ArrayList<FieldBridge>();
+ public final List<Field.TermVector> classTermVectors = new ArrayList<Field.TermVector>();
+ public final List<Float> classBoosts = new ArrayList<Float>();
- public enum Container {
- OBJECT,
- COLLECTION,
- MAP,
- ARRAY
- }
+ public enum Container {
+ OBJECT,
+ COLLECTION,
+ MAP,
+ ARRAY
+ }
- private LuceneOptions getClassLuceneOptions(int i) {
- LuceneOptions options = new LuceneOptions(classStores.get(i),
- classIndexes.get(i), classTermVectors.get(i), classBoosts.get(i));
- return options;
- }
+ private LuceneOptions getClassLuceneOptions(int i) {
+ LuceneOptions options = new LuceneOptions( classStores.get( i ),
+ classIndexes.get( i ), classTermVectors.get( i ), classBoosts.get( i ) );
+ return options;
+ }
- private LuceneOptions getFieldLuceneOptions(int i, Float boost) {
- LuceneOptions options = new LuceneOptions(fieldStore.get(i),
- fieldIndex.get(i), fieldTermVectors.get(i), boost);
- return options;
- }
- }
+ private LuceneOptions getFieldLuceneOptions(int i, Float boost) {
+ LuceneOptions options = new LuceneOptions( fieldStore.get( i ),
+ fieldIndex.get( i ), fieldTermVectors.get( i ), boost );
+ return options;
+ }
+ }
}
16 years, 3 months