Hibernate SVN: r20828 - search/trunk/hibernate-search/src/main/docbook/en-US/modules.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-10-13 12:08:50 -0400 (Wed, 13 Oct 2010)
New Revision: 20828
Modified:
search/trunk/hibernate-search/src/main/docbook/en-US/modules/mapping.xml
Log:
HSEARCH-593 Updated documentation
Modified: search/trunk/hibernate-search/src/main/docbook/en-US/modules/mapping.xml
===================================================================
--- search/trunk/hibernate-search/src/main/docbook/en-US/modules/mapping.xml 2010-10-13 16:04:44 UTC (rev 20827)
+++ search/trunk/hibernate-search/src/main/docbook/en-US/modules/mapping.xml 2010-10-13 16:08:50 UTC (rev 20828)
@@ -25,7 +25,6 @@
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<chapter id="search-mapping" revision="3">
-
<title>Mapping entities to the index structure</title>
<para>All the metadata information needed to index entities is described
@@ -679,11 +678,11 @@
<section>
<title>Analyzer definitions</title>
- <para>Analyzers can become quite complex to deal with for which reason
- Hibernate Search introduces the notion of analyzer definitions. An
+ <para>Analyzers can become quite complex to deal with. For this reason
+ introduces Hibernate Search the notion of analyzer definitions. An
analyzer definition can be reused by many
- <classname>@Analyzer</classname> declarations. An analyzer definition
- is composed of:</para>
+ <classname>@Analyzer</classname> declarations and is composed
+ of:</para>
<itemizedlist>
<listitem>
@@ -713,23 +712,39 @@
<para>This separation of tasks - a list of char filters, and a
tokenizer followed by a list of filters - allows for easy reuse of
each individual component and let you build your customized analyzer
- in a very flexible way (just like Lego). Generally speaking the
- <classname>char filters</classname> do some pre-processing in the
- character input, then the <classname>Tokenizer</classname> starts the
- tokenizing process by turning the character input into tokens which
- are then further processed by the <classname>TokenFilter</classname>s.
- Hibernate Search supports this infrastructure by utilizing the Solr
- analyzer framework. Make sure to add<filename> solr-core.jar and
- </filename><filename>solr-solrj.jar</filename> to your classpath to
- use analyzer definitions. In case you also want to use the snowball
- stemmer also include the <filename>lucene-snowball.jar.</filename>
- Other Solr analyzers might depend on more libraries. For example, the
- <classname>PhoneticFilterFactory</classname> depends on <ulink
- url="http://commons.apache.org/codec">commons-codec</ulink>. Your
- distribution of Hibernate Search provides these dependencies in its
- <filename>lib</filename> directory.</para>
+ in a very flexible way (just like Lego). Generally speaking the char
+ filters do some pre-processing in the character input, then the
+ <classname>Tokenizer</classname> starts the tokenizing process by
+ turning the character input into tokens which are then further
+ processed by the <classname>TokenFilter</classname>s. Hibernate Search
+ supports this infrastructure by utilizing the Solr analyzer framework.
+ </para>
- <example>
+ <tip>
+ <para>Some of the analyzers and filters will require additional
+ dependencies. For example to use the snowball stemmer you have to
+ also include the <literal>lucene-snowball</literal> jar and for the
+ <classname>PhoneticFilterFactory</classname> you need the <ulink
+ url="http://commons.apache.org/codec">commons-codec</ulink> jar.
+ Your distribution of Hibernate Search provides these dependencies in
+ its <filename>lib/optional</filename> directory. Have a look at
+ <xref linkend="table-available-tokenizers" /> and <xref
+ linkend="table-available-filters" /> to see which anaylzers and
+ filters have additional dependencies</para>
+ </tip>
+
+ <para>Let's have a look at a concrete example now - <xref
+ linkend="example-analyzer-def" />. First a char filter is defined by
+ its factory. In our example, a mapping char filter is used, and will
+ replace characters in the input based on the rules specified in the
+ mapping file. Next a tokenizer is defined. This example uses the
+ standard tokenizer. Last but not least, a list of filters is defined
+ by their factories. In our example, the
+ <classname>StopFilter</classname> filter is built reading the
+ dedicated words property file. The filter is also expected to ignore
+ case.</para>
+
+ <example id="example-analyzer-def">
<title><classname>@AnalyzerDef</classname> and the Solr
framework</title>
@@ -753,29 +768,19 @@
}</programlisting>
</example>
- <para>A char filter is defined by its factory which is responsible for
- building the char filter and using the optional list of parameters. In
- our example, a mapping char filter is used, and will replace
- characters in the input based on the rules specified in the mapping
- file. A tokenizer is also defined by its factory. This example use the
- standard tokenizer. A filter is defined by its factory which is
- responsible for creating the filter instance using the optional
- parameters. In our example, the StopFilter filter is built reading the
- dedicated words property file and is expected to ignore case. The list
- of parameters is dependent on the tokenizer or filter factory.</para>
-
- <warning>
+ <tip>
<para>Filters and char filters are applied in the order they are
- defined in the <classname>@AnalyzerDef</classname> annotation. Make
- sure to think twice about this order.</para>
- </warning>
+ defined in the <classname>@AnalyzerDef</classname> annotation. Order
+ matters!</para>
+ </tip>
<para>Once defined, an analyzer definition can be reused by an
- <classname>@Analyzer</classname> declaration using the definition name
- rather than declaring an implementation class.</para>
+ <classname>@Analyzer</classname> declaration as seen in <xref
+ linkend="example-referencing-analyzer-def" />.</para>
<example>
- <title>Referencing an analyzer by name</title>
+ <title id="example-referencing-analyzer-def" remap="">Referencing an
+ analyzer by name</title>
<programlisting>@Entity
@Indexed
@@ -798,17 +803,17 @@
</example>
<para>Analyzer instances declared by
- <classname>@AnalyzerDef</classname> are available by their name in the
- <classname>SearchFactory</classname>.</para>
+ <classname>@AnalyzerDef</classname> are also available by their name
+ in the <classname>SearchFactory</classname> which is quite useful wen
+ building queries.</para>
<programlisting>Analyzer analyzer = fullTextSession.getSearchFactory().getAnalyzer("customanalyzer");</programlisting>
- <para>This is quite useful wen building queries. Fields in queries
- should be analyzed with the same analyzer used to index the field so
- that they speak a common "language": the same tokens are reused
- between the query and the indexing process. This rule has some
- exceptions but is true most of the time. Respect it unless you know
- what you are doing.</para>
+ <para>Fields in queries should be analyzed with the same analyzer used
+ to index the field so that they speak a common "language": the same
+ tokens are reused between the query and the indexing process. This
+ rule has some exceptions but is true most of the time. Respect it
+ unless you know what you are doing.</para>
</section>
<section>
@@ -820,23 +825,25 @@
url="http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters">http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters</ulink>.
Let check a few of them.</para>
- <table>
- <title>Some of the available char filters</title>
+ <table id="table-available-char-filters">
+ <title>Example of available char filters</title>
- <tgroup cols="3">
+ <tgroup cols="4">
<thead>
<row>
<entry align="center">Factory</entry>
<entry align="center">Description</entry>
- <entry align="center">parameters</entry>
+ <entry align="center">Parameters</entry>
+
+ <entry align="center">Additional dependencies</entry>
</row>
</thead>
<tbody>
<row>
- <entry>MappingCharFilterFactory</entry>
+ <entry><classname>MappingCharFilterFactory</classname></entry>
<entry>Replaces one or more characters with one or more
characters, based on mappings specified in the resource
@@ -848,100 +855,131 @@
"ñ" => "n"
"ø" => "o"
</literallayout> </para></entry>
+
+ <entry>none</entry>
</row>
<row>
- <entry>HTMLStripCharFilterFactory</entry>
+ <entry><classname>HTMLStripCharFilterFactory</classname></entry>
<entry>Remove HTML standard tags, keeping the text</entry>
<entry>none</entry>
+
+ <entry>none</entry>
</row>
</tbody>
</tgroup>
</table>
- <table>
- <title>Some of the available tokenizers</title>
+ <table id="table-available-tokenizers">
+ <title>Example of available tokenizers</title>
- <tgroup cols="3">
+ <tgroup cols="4">
<thead>
<row>
<entry align="center">Factory</entry>
<entry align="center">Description</entry>
- <entry align="center">parameters</entry>
+ <entry align="center">Parameters</entry>
+
+ <entry align="center">Additional dependencies</entry>
</row>
</thead>
<tbody>
<row>
- <entry>StandardTokenizerFactory</entry>
+ <entry><classname>StandardTokenizerFactory</classname></entry>
<entry>Use the Lucene StandardTokenizer</entry>
<entry>none</entry>
+
+ <entry>none</entry>
</row>
<row>
- <entry>HTMLStripStandardTokenizerFactory</entry>
+ <entry><classname>HTMLStripStandardTokenizerFactory</classname></entry>
<entry>Remove HTML tags, keep the text and pass it to a
StandardTokenizer. @Deprecated, use the
HTMLStripCharFilterFactory instead</entry>
<entry>none</entry>
+
+ <entry>none</entry>
</row>
+
+ <row>
+ <entry><classname>PatternTokenizerFactory</classname></entry>
+
+ <entry>Breaks text at the specified regular expression
+ pattern. </entry>
+
+ <entry><para><literal>pattern</literal>: the regular
+ expression to use for tokenizing</para><para>group: says which
+ pattern group to extract into tokens</para></entry>
+
+ <entry><literal>commons-io</literal></entry>
+ </row>
</tbody>
</tgroup>
</table>
- <table>
- <title>Some of the available filters</title>
+ <table id="table-available-filters">
+ <title>Examples of available filters</title>
- <tgroup cols="3">
+ <tgroup cols="4">
<thead>
<row>
<entry align="center">Factory</entry>
<entry align="center">Description</entry>
- <entry align="center">parameters</entry>
+ <entry align="center">Parameters</entry>
+
+ <entry align="center">Additional dependencies</entry>
</row>
</thead>
<tbody>
<row>
- <entry>StandardFilterFactory</entry>
+ <entry><classname>StandardFilterFactory</classname></entry>
<entry>Remove dots from acronyms and 's from words</entry>
<entry>none</entry>
+
+ <entry>none</entry>
</row>
<row>
- <entry>LowerCaseFilterFactory</entry>
+ <entry><classname>LowerCaseFilterFactory</classname></entry>
- <entry>Lowercase words</entry>
+ <entry>Lowercases all words</entry>
<entry>none</entry>
+
+ <entry>none</entry>
</row>
<row>
- <entry>StopFilterFactory</entry>
+ <entry><classname>StopFilterFactory</classname></entry>
- <entry>remove words (tokens) matching a list of stop
+ <entry>Remove words (tokens) matching a list of stop
words</entry>
<entry><para><literal>words</literal>: points to a resource
file containing the stop words</para><para>ignoreCase: true if
<literal>case</literal> should be ignore when comparing stop
words, <literal>false</literal> otherwise </para></entry>
+
+ <entry>none</entry>
</row>
<row>
- <entry>SnowballPorterFilterFactory</entry>
+ <entry><classname>SnowballPorterFilterFactory</classname></entry>
<entry>Reduces a word to it's root in a given language. (eg.
protect, protects, protection share the same root). Using such
@@ -950,15 +988,56 @@
<entry><literal>language</literal>: Danish, Dutch, English,
Finnish, French, German, Italian, Norwegian, Portuguese,
Russian, Spanish, Swedish and a few more</entry>
+
+ <entry><literal>lucene-snowball</literal></entry>
</row>
<row>
- <entry>ISOLatin1AccentFilterFactory</entry>
+ <entry><classname>ISOLatin1AccentFilterFactory</classname></entry>
- <entry>remove accents for languages like French</entry>
+ <entry>Remove accents for languages like French</entry>
<entry>none</entry>
+
+ <entry>none</entry>
</row>
+
+ <row>
+ <entry><classname>PhoneticFilterFactory</classname></entry>
+
+ <entry>Inserts phonetically similar tokens into the token
+ stream</entry>
+
+ <entry><para><literal>encoder</literal>: One of
+ DoubleMetaphone, Metaphone, Soundex or
+ RefinedSoundex</para><para>inject: <constant>true</constant>
+ will add tokens to the stream, <constant>false</constant> will
+ replace the existing token
+ </para><para><literal>maxCodeLength</literal>: sets the
+ maximum length of the code to be generated. Supported only for
+ Metaphone and DoubleMetaphone encodings</para></entry>
+
+ <entry><literal>commons-codec</literal></entry>
+ </row>
+
+ <row>
+ <entry><classname>CollationKeyFilterFactory</classname></entry>
+
+ <entry>Converts each token into its
+ <classname>java.text.CollationKey</classname>, and then
+ encodes the <classname>CollationKey</classname> with
+ <classname>IndexableBinaryStringTools</classname>, to allow it
+ to be stored as an index term. </entry>
+
+ <entry><literal>custom</literal>, <literal>language</literal>,
+ <literal>country</literal>, <literal>variant</literal>,
+ <literal>strength</literal>, <literal>decomposition
+ </literal>see Lucene's
+ <classname>CollationKeyFilter</classname> javadocs for more
+ info</entry>
+
+ <entry><literal>lucene-collation, commons-io</literal></entry>
+ </row>
</tbody>
</tgroup>
</table>
15 years, 1 month
Hibernate SVN: r20826 - in search/trunk/hibernate-search/src/main/java/org/hibernate/search: engine and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-10-13 10:31:48 -0400 (Wed, 13 Oct 2010)
New Revision: 20826
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/bridge/FieldBridge.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/bridge/LuceneOptions.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/LuceneOptionsImpl.java
Log:
\HSEARCH-572 Do not deprecate LuceneOptions.get*()
After consideration, no longer deprecate getStore, getIndex etc
but heavily recommend the use of #addFieldToDocument in lieue of these.
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/bridge/FieldBridge.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/bridge/FieldBridge.java 2010-10-13 13:35:28 UTC (rev 20825)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/bridge/FieldBridge.java 2010-10-13 14:31:48 UTC (rev 20826)
@@ -42,6 +42,11 @@
* A common implementation is to add a Field with the given {@code name} to {@code document} following
* the parameters {@code luceneOptions} if the {@code value} is not {@code null}.
*
+ * {code}
+ * String fieldValue = convertToString(value);
+ * luceneOptions.addFieldToDocument(name, fieldValue, document);
+ * {code}
+ *
* @param name The field to add to the Lucene document
* @param value The actual value to index
* @param document The Lucene document into which we want to index the value.
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/bridge/LuceneOptions.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/bridge/LuceneOptions.java 2010-10-13 13:35:28 UTC (rev 20825)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/bridge/LuceneOptions.java 2010-10-13 14:31:48 UTC (rev 20826)
@@ -27,8 +27,17 @@
import org.apache.lucene.document.Field;
/**
+ * A helper class for building Field objects and associating them to Documents.
* A wrapper class for Lucene parameters needed for indexing.
*
+ * The recommended approach to index is to use {@link #addFieldToDocument(String, String, org.apache.lucene.document.Document)}
+ * as all the options delcared by the user are transparently carried over. Compression is also provided transparently.
+
+ * {code}
+ * String fieldValue = convertToString(value);
+ * luceneOptions.addFieldToDocument(name, fieldValue, document);
+ * {code}
+ *
* @author Emmanuel Bernard
* @author Sanne Grinovero
* @author Hardy Ferentschik
@@ -38,7 +47,14 @@
/**
* Add a new field with the name {@code fieldName} to the Lucene Document {@code document} using the value
* {@code indexedString}.
+ * If the indexedString is null then the field is not added to the document.
*
+ * The field options are following the user declaration:
+ * - stored or not
+ * - compressed or not
+ * - what type of indexing strategy
+ * - what type of term vector strategy
+ *
* @param fieldName The field name
* @param indexedString The value to index
* @param document the document to which to add the the new field
@@ -46,33 +62,56 @@
void addFieldToDocument(String fieldName, String indexedString, Document document);
/**
- * @return {@code true} if the field value is compressed, {@code false} otherwise.
+ * Prefer the use of {@link #addFieldToDocument(String, String, org.apache.lucene.document.Document)}
+ * over manually building your Field objects and adding them to the Document.
+ *
+ * To use compression either use #addFieldToDocument or refer
+ * to Lucene documentation to implement your own compression
+ * strategy.
+ *
+ * @return the compression strategy declared by the user {@code true} if the field value is compressed, {@code false} otherwise.
*/
boolean isCompressed();
/**
- * Might be removed in version 3.3 to better support Lucene 3
- * which is missing COMPRESS Store Type.
+ * Prefer the use of {@link #addFieldToDocument(String, String, org.apache.lucene.document.Document)}
+ * over manually building your Field objects and adding them to the Document.
+ *
+ * Return the storage strategy declared by the user
+ * {@code org.apache.lucene.document.Field.Store.YES} if the field is stored
+ * {@code org.apache.lucene.document.Field.Store.NO} otherwise.
+ *
+ * To determine if the field must be compressed, use {@link #isCompressed()}.
+ *
+ * Starting from version 3.3, Store.COMPRESS is no longer returned, use {@link #isCompressed()}
+ *
* To use compression either use #addFieldToDocument or refer
* to Lucene documentation to implement your own compression
* strategy.
- *
- * @deprecated use addToDocument to add fields to the Document if possible
*/
Field.Store getStore();
/**
- * @deprecated likely to be removed in version 3.3, use #addFieldToDocument
+ * Prefer the use of {@link #addFieldToDocument(String, String, org.apache.lucene.document.Document)}
+ * over manually building your Field objects and adding them to the Document.
+ *
+ * Return the indexing strategy declared by the user
*/
Field.Index getIndex();
/**
- * @deprecated likely to be removed in version 3.3, use #addFieldToDocument
+ * Prefer the use of {@link #addFieldToDocument(String, String, org.apache.lucene.document.Document)}
+ * over manually building your Field objects and adding them to the Document.
+ *
+ * Return the term vector strategy declared by the user
*/
Field.TermVector getTermVector();
/**
- * @deprecated likely to be removed in version 3.3, use #addFieldToDocument
+ * Prefer the use of {@link #addFieldToDocument(String, String, org.apache.lucene.document.Document)}
+ * over manually building your Field objects and adding them to the Document.
+ *
+ * Return the boost factor declared by the user
*/
Float getBoost();
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/LuceneOptionsImpl.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/LuceneOptionsImpl.java 2010-10-13 13:35:28 UTC (rev 20825)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/LuceneOptionsImpl.java 2010-10-13 14:31:48 UTC (rev 20826)
@@ -103,9 +103,6 @@
return this.indexMode;
}
- /**
- * @deprecated likely to be removed in 3.3
- */
public org.apache.lucene.document.Field.Store getStore() {
if ( storeUncompressed || storeCompressed ) {
return org.apache.lucene.document.Field.Store.YES;
15 years, 1 month
Hibernate SVN: r20825 - search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-10-13 09:35:28 -0400 (Wed, 13 Oct 2010)
New Revision: 20825
Added:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Comment.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IComment.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IProfile.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Profile.java
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/ProxyTest.java
Log:
HSEARCH-577 IllegalArgumentException when using a @Proxy and deleting a lazy proxy
Adding test to reproduce the issue
Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Comment.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Comment.java (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Comment.java 2010-10-13 13:35:28 UTC (rev 20825)
@@ -0,0 +1,84 @@
+package org.hibernate.search.test.proxy;
+
+import org.hibernate.annotations.Cascade;
+import org.hibernate.annotations.CascadeType;
+import org.hibernate.annotations.Proxy;
+import org.hibernate.search.annotations.ContainedIn;
+import org.hibernate.search.annotations.Field;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Emmanuel Bernard
+ * @author Tom Kuo
+ */
+@Entity
+@Table(name = "comment")
+@Proxy(proxyClass = IComment.class)
+public class Comment implements IComment {
+
+ private Integer id;
+ private IProfile parent;
+ private String name;
+ private IComment root;
+ private List<IComment> replies = new ArrayList<IComment>();
+
+ @Id
+ @Column(name = "commentid")
+ public Integer getId() {
+ return id;
+ }
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ @ManyToOne(targetEntity = Profile.class, fetch = FetchType.LAZY)
+ @JoinColumn(name = "profileid")
+ @ContainedIn
+ public IProfile getProfile() {
+ if (parent == null && getRootComment() != null) {
+ return getRootComment().getProfile();
+ }
+ return parent;
+ }
+ public void setProfile(IProfile p) {
+ this.parent = p;
+ }
+
+ @Column(name = "content")
+ @Field(name = "content")
+ public String getContent() {
+ return name;
+ }
+ public void setContent(String name) {
+ this.name = name;
+ }
+
+ @ManyToOne(targetEntity = Comment.class, fetch = FetchType.LAZY)
+ @JoinColumn(name = "rootid")
+ public IComment getRootComment() {
+ return root;
+ }
+ public void setRootComment(IComment root) {
+ this.root = root;
+ }
+
+ @OneToMany(targetEntity = Comment.class, mappedBy = "rootComment", fetch = FetchType.LAZY)
+ @Cascade(CascadeType.DELETE)
+ public List<IComment> getReplies() {
+ return replies;
+ }
+
+ public void setReplies(List<IComment> replies) {
+ this.replies = replies;
+ }
+}
Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IComment.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IComment.java (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IComment.java 2010-10-13 13:35:28 UTC (rev 20825)
@@ -0,0 +1,31 @@
+package org.hibernate.search.test.proxy;
+
+import java.util.List;
+
+/**
+ * @author Emmanuel Bernard
+ * @author Tom Kuo
+ */
+public interface IComment {
+
+ public Integer getId();
+
+ public void setId(Integer id);
+
+ public IProfile getProfile();
+
+ public void setProfile(IProfile p);
+
+ public String getContent();
+
+ public void setContent(String name);
+
+ public IComment getRootComment();
+
+ public void setRootComment(IComment root);
+
+ public List<IComment> getReplies();
+
+ public void setReplies(List<IComment> replies);
+
+}
Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IProfile.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IProfile.java (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IProfile.java 2010-10-13 13:35:28 UTC (rev 20825)
@@ -0,0 +1,18 @@
+package org.hibernate.search.test.proxy;
+
+import java.util.Set;
+
+/**
+ * @author Emmanuel Bernard
+ * @author Tom Kuo
+ */
+public interface IProfile {
+
+ public Integer getId();
+
+ public void setId(Integer id);
+
+ public Set<IComment> getComments();
+
+ public void setComments(Set<IComment> c);
+}
Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Profile.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Profile.java (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Profile.java 2010-10-13 13:35:28 UTC (rev 20825)
@@ -0,0 +1,43 @@
+package org.hibernate.search.test.proxy;
+
+import org.hibernate.annotations.Proxy;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import java.util.Set;
+
+@Entity
+@Indexed
+@Table(name = "profile")
+@Proxy(proxyClass = IProfile.class)
+public class Profile implements IProfile {
+
+ private Integer id;
+ private Set<IComment> comments;
+
+ @Id
+ @DocumentId
+ @Column(name = "profileid")
+ public Integer getId() {
+ return id;
+ }
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ @OneToMany(targetEntity = Comment.class, mappedBy = "profile")
+ @IndexedEmbedded(targetElement = Comment.class)
+ public Set<IComment> getComments() {
+ return comments;
+ }
+ public void setComments(Set<IComment> c) {
+ this.comments = c;
+ }
+
+}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/ProxyTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/ProxyTest.java 2010-10-13 13:19:30 UTC (rev 20824)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/ProxyTest.java 2010-10-13 13:35:28 UTC (rev 20825)
@@ -29,6 +29,7 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.search.test.SearchTestCase;
+import org.hibernate.testing.junit.FailureExpected;
/**
@@ -63,8 +64,57 @@
session.close();
}
+ @FailureExpected(jiraKey = "HSEARCH-577")
+ public void testDeteleProxy() throws Exception {
+ createTestData();
+
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ IComment c = (IComment)s.get(Comment.class, 2);
+ s.delete(c);
+ tx.commit();
+ s.close();
+ }
+
+ public void createTestData() {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ IProfile p = new Profile();
+ p.setId(1);
+ s.save(p);
+
+ IComment c1 = new Comment();
+ c1.setId(2);
+ c1.setProfile((IProfile)s.get(Profile.class, 1));
+ c1.setContent("c1");
+ c1.setRootComment(null);
+ s.save(c1);
+
+ IComment c2 = new Comment();
+ c2.setId(3);
+ c2.setProfile((IProfile)s.get(Profile.class, 1));
+ c2.setContent("c2");
+ c2.setRootComment(c1);
+ s.save(c2);
+
+ IComment c3 = new Comment();
+ c3.setId(4);
+ c3.setProfile((IProfile)s.get(Profile.class, 1));
+ c3.setContent("c3");
+ c3.setRootComment(c1);
+ s.save(c3);
+
+ tx.commit();
+ s.close();
+ }
+
@Override
protected Class<?>[] getAnnotatedClasses() {
- return new Class[] { Book.class, Author.class };
+ return new Class[] {
+ Book.class,
+ Author.class,
+ Comment.class,
+ Profile.class
+ };
}
}
15 years, 1 month
Hibernate SVN: r20824 - in search/trunk: hibernate-search/src/main/assembly and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-10-13 09:19:30 -0400 (Wed, 13 Oct 2010)
New Revision: 20824
Modified:
search/trunk/hibernate-search-analyzers/pom.xml
search/trunk/hibernate-search/pom.xml
search/trunk/hibernate-search/src/main/assembly/dist.xml
Log:
HSEARCH-593 Fixed dependency scopes. Dependencies of hibernate-search-analyzers are now optional. Updated dist assembly and split the lib directory into three sub-directories: required, optional and provided
Modified: search/trunk/hibernate-search/pom.xml
===================================================================
--- search/trunk/hibernate-search/pom.xml 2010-10-13 11:46:15 UTC (rev 20823)
+++ search/trunk/hibernate-search/pom.xml 2010-10-13 13:19:30 UTC (rev 20824)
@@ -42,6 +42,10 @@
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
+ <artifactId>hibernate-search-analyzers</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
@@ -53,10 +57,6 @@
<artifactId>lucene-core</artifactId>
</dependency>
<dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-search-analyzers</artifactId>
- </dependency>
- <dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers</artifactId>
</dependency>
@@ -81,6 +81,26 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-snowball</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-collation</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<scope>test</scope>
Modified: search/trunk/hibernate-search/src/main/assembly/dist.xml
===================================================================
--- search/trunk/hibernate-search/src/main/assembly/dist.xml 2010-10-13 11:46:15 UTC (rev 20823)
+++ search/trunk/hibernate-search/src/main/assembly/dist.xml 2010-10-13 13:19:30 UTC (rev 20824)
@@ -9,7 +9,7 @@
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
- <outputDirectory>/dist/lib</outputDirectory>
+ <outputDirectory>/dist/lib/required</outputDirectory>
<scope>runtime</scope>
<excludes>
<exclude>jgroups:jgroups</exclude>
@@ -25,7 +25,24 @@
</includes>
</dependencySet>
+ <!--
+ Need to manually put the optional analyzer dependencies into their place.
+ The maven-assembly-plugin does not have any options to handle <optional/> dependencies
+ They are added as test dependencies in the pom.
+ -->
<dependencySet>
+ <outputDirectory>/dist/lib/optional</outputDirectory>
+ <scope>test</scope>
+ <includes>
+ <include>org.apache.lucene:lucene-snowball</include>
+ <include>org.apache.lucene:lucene-collation</include>
+ <include>commons-codec:commons-codec</include>
+ <include>commons-io:commons-io</include>
+ <include>org.slf4j:slf4j-log4j12</include>
+ </includes>
+ </dependencySet>
+
+ <dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>/dist/lib/provided</outputDirectory>
<scope>provided</scope>
Modified: search/trunk/hibernate-search-analyzers/pom.xml
===================================================================
--- search/trunk/hibernate-search-analyzers/pom.xml 2010-10-13 11:46:15 UTC (rev 20823)
+++ search/trunk/hibernate-search-analyzers/pom.xml 2010-10-13 13:19:30 UTC (rev 20824)
@@ -51,20 +51,24 @@
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-snowball</artifactId>
+ <optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-collation</artifactId>
+ <optional>true</optional>
</dependency>
<!-- Apache Commons -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
+ <optional>true</optional>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
+ <optional>true</optional>
</dependency>
</dependencies>
15 years, 1 month
Hibernate SVN: r20823 - search/trunk/hibernate-search/src/main/java/org/hibernate/search/query.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-10-13 07:46:15 -0400 (Wed, 13 Oct 2010)
New Revision: 20823
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
Log:
HSEARCH-546 Support THIS Projection and fetching definition
remove legacy method call that was causing compilation errors
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2010-10-13 11:26:45 UTC (rev 20822)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2010-10-13 11:46:15 UTC (rev 20823)
@@ -232,7 +232,6 @@
private Loader getProjectionLoader(ObjectLoaderBuilder loaderBuilder) {
ProjectionLoader loader = new ProjectionLoader();
loader.init( ( Session ) session, searchFactoryImplementor, resultTransformer, loaderBuilder, indexProjection );
- loader.setEntityTypes( indexedTargetedEntities );
return loader;
}
15 years, 1 month
Hibernate SVN: r20822 - search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-10-13 07:26:45 -0400 (Wed, 13 Oct 2010)
New Revision: 20822
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java
Log:
HSEARCH-546 Support THIS Projection and fetching definition
Clean up ProjectionLoader after LoaderBuilder refactoring
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java 2010-10-13 11:26:14 UTC (rev 20821)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java 2010-10-13 11:26:45 UTC (rev 20822)
@@ -25,7 +25,6 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
import org.hibernate.Session;
import org.hibernate.annotations.common.AssertionFailure;
@@ -40,40 +39,31 @@
* @author Hardy Ferentschik
*/
public class ProjectionLoader implements Loader {
- private SearchFactoryImplementor searchFactoryImplementor;
- private Session session;
private Loader objectLoader;
private Boolean projectThis;
private ResultTransformer transformer;
private String[] aliases;
- private Set<Class<?>> entityTypes;
private ObjectLoaderBuilder loaderBuilder;
public void init(Session session, SearchFactoryImplementor searchFactoryImplementor) {
- this.session = session;
- this.searchFactoryImplementor = searchFactoryImplementor;
}
public void init(Session session, SearchFactoryImplementor searchFactoryImplementor, ResultTransformer transformer, ObjectLoaderBuilder loaderBuilder, String[] aliases) {
- init( session, searchFactoryImplementor );
+ init(session, searchFactoryImplementor);
this.transformer = transformer;
this.aliases = aliases;
this.loaderBuilder = loaderBuilder;
}
- public void setEntityTypes(Set<Class<?>> entityTypes) {
- this.entityTypes = entityTypes;
- }
-
public Object load(EntityInfo entityInfo) {
- initThisProjectionFlag( entityInfo );
- if ( projectThis ) {
- for ( int index : entityInfo.indexesOfThis ) {
- entityInfo.projection[index] = objectLoader.load( entityInfo );
+ initThisProjectionFlag(entityInfo);
+ if (projectThis) {
+ for (int index : entityInfo.indexesOfThis) {
+ entityInfo.projection[index] = objectLoader.load(entityInfo);
}
}
- if ( transformer != null ) {
- return transformer.transformTuple( entityInfo.projection, aliases );
+ if (transformer != null) {
+ return transformer.transformTuple(entityInfo.projection, aliases);
}
else {
return entityInfo.projection;
@@ -85,37 +75,37 @@
}
private void initThisProjectionFlag(EntityInfo entityInfo) {
- if ( projectThis == null ) {
+ if (projectThis == null) {
projectThis = entityInfo.indexesOfThis.size() != 0;
- if ( projectThis ) {
+ if (projectThis) {
objectLoader = loaderBuilder.buildLoader();
}
}
}
public List load(EntityInfo... entityInfos) {
- List results = new ArrayList( entityInfos.length );
- if ( entityInfos.length == 0 ) {
+ List results = new ArrayList(entityInfos.length);
+ if (entityInfos.length == 0) {
return results;
}
- initThisProjectionFlag( entityInfos[0] );
- if ( projectThis ) {
- objectLoader.load( entityInfos ); // load by batch
- for ( EntityInfo entityInfo : entityInfos ) {
- for ( int index : entityInfo.indexesOfThis ) {
+ initThisProjectionFlag(entityInfos[0]);
+ if (projectThis) {
+ objectLoader.load(entityInfos); // load by batch
+ for (EntityInfo entityInfo : entityInfos) {
+ for (int index : entityInfo.indexesOfThis) {
// set one by one to avoid loosing null objects (skipped in the objectLoader.load( EntityInfo[] ))
// use objectLoader.executeLoad to prevent measuring load time again (see AbstractLoader)
- entityInfo.projection[index] = objectLoader.loadWithoutTiming( entityInfo );
+ entityInfo.projection[index] = objectLoader.loadWithoutTiming(entityInfo);
}
}
}
- for ( EntityInfo entityInfo : entityInfos ) {
- if ( transformer != null ) {
- results.add( transformer.transformTuple( entityInfo.projection, aliases ) );
+ for (EntityInfo entityInfo : entityInfos) {
+ if (transformer != null) {
+ results.add(transformer.transformTuple(entityInfo.projection, aliases));
}
else {
- results.add( entityInfo.projection );
+ results.add(entityInfo.projection);
}
}
15 years, 1 month
Hibernate SVN: r20821 - in search/trunk/hibernate-search/src/main/java/org/hibernate/search: query and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-10-13 07:26:14 -0400 (Wed, 13 Oct 2010)
New Revision: 20821
Added:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/ObjectLoaderBuilder.java
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
Log:
HSEARCH-546 Support THIS Projection and fetching definition
Extract object loader strategy in a dedicated class
Make use of this loader strategy in ProjectionLoader
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java 2010-10-13 11:25:36 UTC (rev 20820)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java 2010-10-13 11:26:14 UTC (rev 20821)
@@ -28,6 +28,8 @@
import java.util.Set;
import org.hibernate.Session;
+import org.hibernate.annotations.common.AssertionFailure;
+import org.hibernate.search.query.ObjectLoaderBuilder;
import org.hibernate.transform.ResultTransformer;
/**
@@ -40,21 +42,23 @@
public class ProjectionLoader implements Loader {
private SearchFactoryImplementor searchFactoryImplementor;
private Session session;
- private MultiClassesQueryLoader objectLoader;
+ private Loader objectLoader;
private Boolean projectThis;
private ResultTransformer transformer;
private String[] aliases;
private Set<Class<?>> entityTypes;
+ private ObjectLoaderBuilder loaderBuilder;
public void init(Session session, SearchFactoryImplementor searchFactoryImplementor) {
this.session = session;
this.searchFactoryImplementor = searchFactoryImplementor;
}
- public void init(Session session, SearchFactoryImplementor searchFactoryImplementor, ResultTransformer transformer, String[] aliases) {
+ public void init(Session session, SearchFactoryImplementor searchFactoryImplementor, ResultTransformer transformer, ObjectLoaderBuilder loaderBuilder, String[] aliases) {
init( session, searchFactoryImplementor );
this.transformer = transformer;
this.aliases = aliases;
+ this.loaderBuilder = loaderBuilder;
}
public void setEntityTypes(Set<Class<?>> entityTypes) {
@@ -84,10 +88,7 @@
if ( projectThis == null ) {
projectThis = entityInfo.indexesOfThis.size() != 0;
if ( projectThis ) {
- MultiClassesQueryLoader loader = new MultiClassesQueryLoader();
- loader.init( session, searchFactoryImplementor );
- loader.setEntityTypes( entityTypes );
- objectLoader = loader;
+ objectLoader = loaderBuilder.buildLoader();
}
}
}
@@ -105,7 +106,7 @@
for ( int index : entityInfo.indexesOfThis ) {
// set one by one to avoid loosing null objects (skipped in the objectLoader.load( EntityInfo[] ))
// use objectLoader.executeLoad to prevent measuring load time again (see AbstractLoader)
- entityInfo.projection[index] = objectLoader.executeLoad( entityInfo );
+ entityInfo.projection[index] = objectLoader.loadWithoutTiming( entityInfo );
}
}
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2010-10-13 11:25:36 UTC (rev 20820)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2010-10-13 11:26:14 UTC (rev 20821)
@@ -215,65 +215,23 @@
* @return The loader instance to use to load the results of the query.
*/
private Loader getLoader() {
- Loader loader;
+ ObjectLoaderBuilder loaderBuilder = new ObjectLoaderBuilder()
+ .criteria(criteria)
+ .targetedEntities(targetedEntities)
+ .indexedTargetedEntities(indexedTargetedEntities)
+ .session(session)
+ .searchFactory(searchFactoryImplementor);
if ( indexProjection != null ) {
- loader = getProjectionLoader();
+ return getProjectionLoader( loaderBuilder );
}
- else if ( criteria != null ) {
- loader = getCriteriaLoader();
- }
- else if ( targetedEntities.size() == 1 ) {
- loader = getSingleEntityLoader();
- }
else {
- loader = getMultipleEntitiesLoader();
+ return loaderBuilder.buildLoader();
}
- return loader;
}
- private Loader getMultipleEntitiesLoader() {
- final MultiClassesQueryLoader multiClassesLoader = new MultiClassesQueryLoader();
- multiClassesLoader.init( ( Session ) session, searchFactoryImplementor );
- multiClassesLoader.setEntityTypes( indexedTargetedEntities );
- return multiClassesLoader;
- }
-
- private Loader getSingleEntityLoader() {
- final QueryLoader queryLoader = new QueryLoader();
- queryLoader.init( ( Session ) session, searchFactoryImplementor );
- queryLoader.setEntityType( targetedEntities.iterator().next() );
- return queryLoader;
- }
-
- private Loader getCriteriaLoader() {
- if ( targetedEntities.size() > 1 ) {
- throw new SearchException( "Cannot mix criteria and multiple entity types" );
- }
- Class entityType = targetedEntities.size() == 0 ? null : targetedEntities.iterator().next();
- if ( criteria instanceof CriteriaImpl ) {
- String targetEntity = ( ( CriteriaImpl ) criteria ).getEntityOrClassName();
- if ( entityType != null && !entityType.getName().equals( targetEntity ) ) {
- throw new SearchException( "Criteria query entity should match query entity" );
- }
- else {
- try {
- entityType = ReflectHelper.classForName( targetEntity );
- }
- catch ( ClassNotFoundException e ) {
- throw new SearchException( "Unable to load entity class from criteria: " + targetEntity, e );
- }
- }
- }
- QueryLoader queryLoader = new QueryLoader();
- queryLoader.init( ( Session ) session, searchFactoryImplementor );
- queryLoader.setEntityType( entityType );
- queryLoader.setCriteria( criteria );
- return queryLoader;
- }
-
- private Loader getProjectionLoader() {
+ private Loader getProjectionLoader(ObjectLoaderBuilder loaderBuilder) {
ProjectionLoader loader = new ProjectionLoader();
- loader.init( ( Session ) session, searchFactoryImplementor, resultTransformer, indexProjection );
+ loader.init( ( Session ) session, searchFactoryImplementor, resultTransformer, loaderBuilder, indexProjection );
loader.setEntityTypes( indexedTargetedEntities );
return loader;
}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/ObjectLoaderBuilder.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/ObjectLoaderBuilder.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/ObjectLoaderBuilder.java 2010-10-13 11:26:14 UTC (rev 20821)
@@ -0,0 +1,103 @@
+package org.hibernate.search.query;
+
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.impl.CriteriaImpl;
+import org.hibernate.search.SearchException;
+import org.hibernate.search.engine.Loader;
+import org.hibernate.search.engine.MultiClassesQueryLoader;
+import org.hibernate.search.engine.QueryLoader;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ObjectLoaderBuilder {
+ private Criteria criteria;
+ private List<Class<?>> targetedEntities;
+ private SessionImplementor session;
+ private SearchFactoryImplementor searchFactoryImplementor;
+ private Set<Class<?>> indexedTargetedEntities;
+
+ public ObjectLoaderBuilder criteria(Criteria criteria) {
+ this.criteria = criteria;
+ return this;
+ }
+
+ public ObjectLoaderBuilder targetedEntities(List<Class<?>> targetedEntities) {
+ this.targetedEntities = targetedEntities;
+ return this;
+ }
+
+ public Loader buildLoader() {
+ if ( criteria != null ) {
+ return getCriteriaLoader();
+ }
+ else if ( targetedEntities.size() == 1 ) {
+ return getSingleEntityLoader();
+ }
+ else {
+ return getMultipleEntitiesLoader();
+ }
+ }
+
+ private Loader getMultipleEntitiesLoader() {
+ final MultiClassesQueryLoader multiClassesLoader = new MultiClassesQueryLoader();
+ multiClassesLoader.init( (Session) session, searchFactoryImplementor );
+ multiClassesLoader.setEntityTypes( indexedTargetedEntities );
+ return multiClassesLoader;
+ }
+
+ private Loader getSingleEntityLoader() {
+ final QueryLoader queryLoader = new QueryLoader();
+ queryLoader.init( ( Session ) session, searchFactoryImplementor );
+ queryLoader.setEntityType( targetedEntities.iterator().next() );
+ return queryLoader;
+ }
+
+ private Loader getCriteriaLoader() {
+ if ( targetedEntities.size() > 1 ) {
+ throw new SearchException( "Cannot mix criteria and multiple entity types" );
+ }
+ Class entityType = targetedEntities.size() == 0 ? null : targetedEntities.iterator().next();
+ if ( criteria instanceof CriteriaImpl) {
+ String targetEntity = ( ( CriteriaImpl ) criteria ).getEntityOrClassName();
+ if ( entityType != null && !entityType.getName().equals( targetEntity ) ) {
+ throw new SearchException( "Criteria query entity should match query entity" );
+ }
+ else {
+ try {
+ entityType = ReflectHelper.classForName( targetEntity );
+ }
+ catch ( ClassNotFoundException e ) {
+ throw new SearchException( "Unable to load entity class from criteria: " + targetEntity, e );
+ }
+ }
+ }
+ QueryLoader queryLoader = new QueryLoader();
+ queryLoader.init( ( Session ) session, searchFactoryImplementor );
+ queryLoader.setEntityType( entityType );
+ queryLoader.setCriteria( criteria );
+ return queryLoader;
+ }
+
+ public ObjectLoaderBuilder session(SessionImplementor session) {
+ this.session = session;
+ return this;
+ }
+
+ public ObjectLoaderBuilder searchFactory(SearchFactoryImplementor searchFactoryImplementor) {
+ this.searchFactoryImplementor = searchFactoryImplementor;
+ return this;
+ }
+
+ public ObjectLoaderBuilder indexedTargetedEntities(Set<Class<?>> indexedTargetedEntities) {
+ this.indexedTargetedEntities = indexedTargetedEntities;
+ return this;
+ }
+}
15 years, 1 month
Hibernate SVN: r20820 - in search/trunk/hibernate-search/src/main/java/org/hibernate/search: query and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-10-13 07:25:36 -0400 (Wed, 13 Oct 2010)
New Revision: 20820
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/AbstractLoader.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/Loader.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
Log:
HSEARCH-546 Support THIS Projection and fetching definition
Define loadWithoutTiming on Loader interface for its use by ProjectionLoader
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/AbstractLoader.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/AbstractLoader.java 2010-10-13 10:21:56 UTC (rev 20819)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/AbstractLoader.java 2010-10-13 11:25:36 UTC (rev 20820)
@@ -55,6 +55,10 @@
return loadedObject;
}
+ public Object loadWithoutTiming(EntityInfo entityInfo) {
+ return executeLoad(entityInfo);
+ }
+
public abstract Object executeLoad(EntityInfo entityInfo);
public List load(EntityInfo... entityInfos) {
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/Loader.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/Loader.java 2010-10-13 10:21:56 UTC (rev 20819)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/Loader.java 2010-10-13 11:25:36 UTC (rev 20820)
@@ -40,5 +40,7 @@
Object load(EntityInfo entityInfo);
+ Object loadWithoutTiming(EntityInfo entityInfo);
+
List load(EntityInfo... entityInfos);
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java 2010-10-13 10:21:56 UTC (rev 20819)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java 2010-10-13 11:25:36 UTC (rev 20820)
@@ -76,6 +76,10 @@
}
}
+ public Object loadWithoutTiming(EntityInfo entityInfo) {
+ throw new AssertionFailure("This method is not meant to be used on ProjectionLoader");
+ }
+
private void initThisProjectionFlag(EntityInfo entityInfo) {
if ( projectThis == null ) {
projectThis = entityInfo.indexesOfThis.size() != 0;
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2010-10-13 10:21:56 UTC (rev 20819)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2010-10-13 11:25:36 UTC (rev 20820)
@@ -997,6 +997,10 @@
throw new UnsupportedOperationException( "noLoader should not be used" );
}
+ public Object loadWithoutTiming(EntityInfo entityInfo) {
+ throw new UnsupportedOperationException( "noLoader should not be used" );
+ }
+
public List load(EntityInfo... entityInfos) {
throw new UnsupportedOperationException( "noLoader should not be used" );
}
15 years, 1 month