Hibernate SVN: r16312 - in search/trunk: src/main/java/org/hibernate/search/backend and 6 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2009-04-13 19:29:04 -0400 (Mon, 13 Apr 2009)
New Revision: 16312
Modified:
search/trunk/readme.txt
search/trunk/src/main/java/org/hibernate/search/backend/BackendQueueProcessorFactory.java
search/trunk/src/main/java/org/hibernate/search/backend/Workspace.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/DpSelectionDelegate.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java
search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java
search/trunk/src/main/java/org/hibernate/search/engine/DocumentExtractor.java
search/trunk/src/main/java/org/hibernate/search/engine/EntityInfo.java
search/trunk/src/main/java/org/hibernate/search/event/FullTextIndexEventListener.java
search/trunk/src/main/java/org/hibernate/search/filter/FilterOptimizationHelper.java
search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java
search/trunk/src/main/java/org/hibernate/search/impl/SolrAnalyzerBuilder.java
Log:
typos in comments/docs and removal of TODOs which don't appply any more
Modified: search/trunk/readme.txt
===================================================================
--- search/trunk/readme.txt 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/readme.txt 2009-04-13 23:29:04 UTC (rev 16312)
@@ -6,7 +6,7 @@
-----------
Full text search engines like Apache Lucene(tm) are a very powerful technology to
-bring free text/efficient queries to applications. If suffers several mismatches
+bring free text/efficient queries to applications. It suffers several mismatches
when dealing with a object domain model (keeping the index up to date, mismatch
between the index structure and the domain model, ...)
Hibernate Search indexes your domain model thanks to a few annotations, takes
Modified: search/trunk/src/main/java/org/hibernate/search/backend/BackendQueueProcessorFactory.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/BackendQueueProcessorFactory.java 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/src/main/java/org/hibernate/search/backend/BackendQueueProcessorFactory.java 2009-04-13 23:29:04 UTC (rev 16312)
@@ -31,7 +31,7 @@
/**
* Used to shutdown and eventually release resources.
- * no other method should used after this one.
+ * No other method should be used after this one.
*/
void close();
Modified: search/trunk/src/main/java/org/hibernate/search/backend/Workspace.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/Workspace.java 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/src/main/java/org/hibernate/search/backend/Workspace.java 2009-04-13 23:29:04 UTC (rev 16312)
@@ -76,7 +76,7 @@
}
/**
- * If optimization has not been forced give a change to configured OptimizerStrategy
+ * If optimization has not been forced give a chance to configured OptimizerStrategy
* to optimize the index.
* To enter the optimization phase you need to acquire the lock first.
* @throws AssertionFailure if the lock is not owned.
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2009-04-13 23:29:04 UTC (rev 16312)
@@ -169,7 +169,6 @@
}
}
- //TODO implements parallel batchWorkers (one per Directory)
public void performWorks(WorkQueue workQueue) {
Runnable processor = backendQueueProcessorFactory.getProcessor( workQueue.getSealedQueue() );
if ( sync ) {
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/DpSelectionDelegate.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/DpSelectionDelegate.java 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/DpSelectionDelegate.java 2009-04-13 23:29:04 UTC (rev 16312)
@@ -12,7 +12,7 @@
* The LuceneWork must be applied to different indexes.
* @param work the work to split.
* @param queues the target queue to add work to.
- * @param shardingStrategy the Sharding strategy is usually needed to indetify affected Directories.
+ * @param shardingStrategy the Sharding strategy is usually needed to identify affected Directories.
*/
void addAsPayLoadsToQueue(LuceneWork work,
IndexShardingStrategy shardingStrategy, QueueProcessors queues);
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java 2009-04-13 23:29:04 UTC (rev 16312)
@@ -8,6 +8,12 @@
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.store.DirectoryProvider;
+/**
+ * Collects all resources needed to apply changes to one index,
+ * and are reused across several WorkQueues.
+ *
+ * @author Sanne Grinovero
+ */
class PerDPResources {
private final ExecutorService executor;
Modified: search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java 2009-04-13 23:29:04 UTC (rev 16312)
@@ -341,7 +341,7 @@
*
* @param instance The entity for which to build the matching Lucene <code>Document</code>
* @param id the entity id.
- * @param fieldToAnalyzerMap this maps gets populated while generateing the <code>Document</code>.
+ * @param fieldToAnalyzerMap this maps gets populated while generating the <code>Document</code>.
* It allows to specify for any document field a named analyzer to use. This parameter cannot be <code>null</code>.
*
* @return The Lucene <code>Document</code> for the specified entity.
@@ -479,7 +479,7 @@
value = ReflectionHelper.getMemberValue( unproxiedInstance, propertiesMetadata.discriminatorGetter );
}
- // now we give the discriminator the oppertunity to specify a analyzer per field level
+ // now we give the discriminator the opportunity to specify a analyzer per field level
for ( Object o : doc.getFields() ) {
Field field = ( Field ) o;
if ( !processedFieldNames.contains( field.name() ) ) {
Modified: search/trunk/src/main/java/org/hibernate/search/engine/DocumentExtractor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/engine/DocumentExtractor.java 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/src/main/java/org/hibernate/search/engine/DocumentExtractor.java 2009-04-13 23:29:04 UTC (rev 16312)
@@ -13,7 +13,6 @@
import org.apache.lucene.document.FieldSelector;
import org.hibernate.search.ProjectionConstants;
-import org.hibernate.search.SearchException;
import org.hibernate.search.query.QueryHits;
/**
Modified: search/trunk/src/main/java/org/hibernate/search/engine/EntityInfo.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/engine/EntityInfo.java 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/src/main/java/org/hibernate/search/engine/EntityInfo.java 2009-04-13 23:29:04 UTC (rev 16312)
@@ -9,7 +9,6 @@
*
* @author Emmanuel Bernard
*/
-//TODO Move to egine?
public class EntityInfo {
public final Class clazz;
Modified: search/trunk/src/main/java/org/hibernate/search/event/FullTextIndexEventListener.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/event/FullTextIndexEventListener.java 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/src/main/java/org/hibernate/search/event/FullTextIndexEventListener.java 2009-04-13 23:29:04 UTC (rev 16312)
@@ -123,7 +123,7 @@
}
}
- protected <T> void processWork(T entity, Serializable id, WorkType workType, AbstractEvent event) {
+ protected <T> void processWork(T entity, Serializable id, WorkType workType, AbstractEvent event) {
Work<T> work = new Work<T>( entity, id, workType );
final EventSourceTransactionContext transactionContext = new EventSourceTransactionContext( event.getSession() );
searchFactoryImplementor.getWorker().performWork( work, transactionContext );
Modified: search/trunk/src/main/java/org/hibernate/search/filter/FilterOptimizationHelper.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/filter/FilterOptimizationHelper.java 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/src/main/java/org/hibernate/search/filter/FilterOptimizationHelper.java 2009-04-13 23:29:04 UTC (rev 16312)
@@ -21,7 +21,7 @@
* Returns a new list of DocIdSet, applying binary AND
* on all DocIdSet implemented by using BitSet or OpenBitSet.
* @param docIdSets
- * @return the same list if not change was done
+ * @return the same list if no changes were done
*/
public static List<DocIdSet> mergeByBitAnds(List<DocIdSet> docIdSets) {
int size = docIdSets.size();
Modified: search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java 2009-04-13 23:29:04 UTC (rev 16312)
@@ -119,7 +119,7 @@
Work<T> work;
for ( Class clazz : targetedClasses ) {
if ( id == null ) {
- work = new Work<T>( clazz, id, WorkType.PURGE_ALL );
+ work = new Work<T>( clazz, null, WorkType.PURGE_ALL );
searchFactoryImplementor.getWorker().performWork( work, transactionContext );
}
else {
Modified: search/trunk/src/main/java/org/hibernate/search/impl/SolrAnalyzerBuilder.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/SolrAnalyzerBuilder.java 2009-04-13 22:52:23 UTC (rev 16311)
+++ search/trunk/src/main/java/org/hibernate/search/impl/SolrAnalyzerBuilder.java 2009-04-13 23:29:04 UTC (rev 16312)
@@ -21,7 +21,7 @@
/**
* Instances of this class are used to build Lucene analyzers which are defined using the solr <code>TokenFilterFactory</code>.
* To make the dependency to the solr framework optional only this class has direct dependecies to solr. Solr dependencies
- * are not supposed to be used anywhere else (except the actual configuration of the analzers in the domain model).
+ * are not supposed to be used anywhere else (except the actual configuration of the analyzers in the domain model).
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
15 years, 7 months
Hibernate SVN: r16311 - in search/trunk/src/main/java/org/hibernate/search: backend/impl and 6 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2009-04-13 18:52:23 -0400 (Mon, 13 Apr 2009)
New Revision: 16311
Modified:
search/trunk/src/main/java/org/hibernate/search/backend/configuration/ConfigurationParseHelper.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
search/trunk/src/main/java/org/hibernate/search/bridge/builtin/BooleanBridge.java
search/trunk/src/main/java/org/hibernate/search/bridge/builtin/ClassBridge.java
search/trunk/src/main/java/org/hibernate/search/bridge/builtin/EnumBridge.java
search/trunk/src/main/java/org/hibernate/search/bridge/builtin/UriBridge.java
search/trunk/src/main/java/org/hibernate/search/bridge/builtin/UrlBridge.java
search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java
search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java
search/trunk/src/main/java/org/hibernate/search/engine/LoaderHelper.java
search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderHelper.java
search/trunk/src/main/java/org/hibernate/search/util/HibernateSearchResourceLoader.java
Log:
HSEARCH-359 change usage of deprecated helpers from commons-annotation to core
Modified: search/trunk/src/main/java/org/hibernate/search/backend/configuration/ConfigurationParseHelper.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/configuration/ConfigurationParseHelper.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/backend/configuration/ConfigurationParseHelper.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -3,7 +3,7 @@
import java.util.Properties;
-import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.util.StringHelper;
import org.hibernate.search.SearchException;
/**
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -12,8 +12,8 @@
import org.slf4j.Logger;
import org.hibernate.Hibernate;
-import org.hibernate.annotations.common.util.ReflectHelper;
-import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.util.ReflectHelper;
+import org.hibernate.util.StringHelper;
import org.hibernate.search.Environment;
import org.hibernate.search.SearchException;
import org.hibernate.search.backend.BackendQueueProcessorFactory;
Modified: search/trunk/src/main/java/org/hibernate/search/bridge/builtin/BooleanBridge.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/bridge/builtin/BooleanBridge.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/bridge/builtin/BooleanBridge.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -2,9 +2,8 @@
package org.hibernate.search.bridge.builtin;
import org.hibernate.search.bridge.TwoWayStringBridge;
-import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.util.StringHelper;
-
/**
* Map a boolean field
*
Modified: search/trunk/src/main/java/org/hibernate/search/bridge/builtin/ClassBridge.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/bridge/builtin/ClassBridge.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/bridge/builtin/ClassBridge.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -3,8 +3,8 @@
import org.hibernate.search.bridge.TwoWayStringBridge;
import org.hibernate.search.SearchException;
-import org.hibernate.annotations.common.util.StringHelper;
-import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.util.StringHelper;
+import org.hibernate.util.ReflectHelper;
/**
* Convert a Class back and forth
Modified: search/trunk/src/main/java/org/hibernate/search/bridge/builtin/EnumBridge.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/bridge/builtin/EnumBridge.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/bridge/builtin/EnumBridge.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -2,7 +2,7 @@
package org.hibernate.search.bridge.builtin;
import org.hibernate.search.bridge.TwoWayStringBridge;
-import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.util.StringHelper;
/**
Modified: search/trunk/src/main/java/org/hibernate/search/bridge/builtin/UriBridge.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/bridge/builtin/UriBridge.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/bridge/builtin/UriBridge.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -4,7 +4,7 @@
import java.net.URI;
import java.net.URISyntaxException;
-import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.util.StringHelper;
import org.hibernate.search.SearchException;
import org.hibernate.search.bridge.TwoWayStringBridge;
Modified: search/trunk/src/main/java/org/hibernate/search/bridge/builtin/UrlBridge.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/bridge/builtin/UrlBridge.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/bridge/builtin/UrlBridge.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -6,7 +6,7 @@
import org.hibernate.search.bridge.TwoWayStringBridge;
import org.hibernate.search.SearchException;
-import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.util.StringHelper;
/**
* Bridge for <code>URL</code>s.
Modified: search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -24,7 +24,7 @@
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XMember;
import org.hibernate.annotations.common.reflection.XProperty;
-import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.util.StringHelper;
import org.hibernate.search.SearchException;
import org.hibernate.search.analyzer.Discriminator;
import org.hibernate.search.annotations.AnalyzerDef;
Modified: search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -23,7 +23,7 @@
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XMember;
import org.hibernate.annotations.common.reflection.XProperty;
-import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.util.ReflectHelper;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.search.SearchException;
import org.hibernate.search.analyzer.Discriminator;
Modified: search/trunk/src/main/java/org/hibernate/search/engine/LoaderHelper.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/engine/LoaderHelper.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/engine/LoaderHelper.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -4,7 +4,7 @@
import java.util.ArrayList;
import java.util.List;
-import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.util.ReflectHelper;
/**
* @author Emmanuel Bernard
Modified: search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -24,7 +24,8 @@
import org.hibernate.annotations.common.reflection.MetadataProvider;
import org.hibernate.annotations.common.reflection.MetadataProviderInjector;
import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
-import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.util.ReflectHelper;
+import org.hibernate.util.StringHelper;
import org.hibernate.search.Environment;
import org.hibernate.search.SearchException;
import org.hibernate.search.Version;
@@ -477,11 +478,7 @@
}
else {
try {
- Class filterCachingStrategyClass = org.hibernate
- .annotations
- .common
- .util
- .ReflectHelper
+ Class filterCachingStrategyClass = ReflectHelper
.classForName( impl, SearchFactoryImpl.class );
filterCachingStrategy = ( FilterCachingStrategy ) filterCachingStrategyClass.newInstance();
}
Modified: search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -33,7 +33,7 @@
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
-import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.util.ReflectHelper;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.query.ParameterMetadata;
import org.hibernate.impl.AbstractQueryImpl;
Modified: search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderHelper.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderHelper.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderHelper.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -16,7 +16,7 @@
import org.apache.lucene.store.SingleInstanceLockFactory;
import org.slf4j.Logger;
-import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.util.StringHelper;
import org.hibernate.search.SearchException;
import org.hibernate.search.util.FileHelper;
import org.hibernate.search.util.LoggerFactory;
Modified: search/trunk/src/main/java/org/hibernate/search/util/HibernateSearchResourceLoader.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/util/HibernateSearchResourceLoader.java 2009-04-13 22:37:42 UTC (rev 16310)
+++ search/trunk/src/main/java/org/hibernate/search/util/HibernateSearchResourceLoader.java 2009-04-13 22:52:23 UTC (rev 16311)
@@ -11,7 +11,7 @@
import org.apache.solr.common.ResourceLoader;
import org.apache.solr.util.plugin.ResourceLoaderAware;
-import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.util.ReflectHelper;
import org.hibernate.search.SearchException;
/**
15 years, 7 months
Hibernate SVN: r16310 - in search/trunk/src: main/java/org/hibernate/search/backend/impl and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2009-04-13 18:37:42 -0400 (Mon, 13 Apr 2009)
New Revision: 16310
Added:
search/trunk/src/main/java/org/hibernate/search/backend/impl/blackhole/
search/trunk/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java
search/trunk/src/test/java/org/hibernate/search/test/configuration/CustomBackendTest.java
Modified:
search/trunk/src/main/docbook/en-US/modules/configuration.xml
search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
Log:
HSEARCH-347 adding the "blackhole" backend as a tool to tweak indexing process
Modified: search/trunk/src/main/docbook/en-US/modules/configuration.xml
===================================================================
--- search/trunk/src/main/docbook/en-US/modules/configuration.xml 2009-04-13 17:46:22 UTC (rev 16309)
+++ search/trunk/src/main/docbook/en-US/modules/configuration.xml 2009-04-13 22:37:42 UTC (rev 16310)
@@ -367,7 +367,7 @@
<entry>Out of the box support for the Apache Lucene back end and
the JMS back end. Default to <literal>lucene</literal>. Supports
- also <literal>jms</literal>.</entry>
+ also <literal>jms</literal> and <literal>blackhole</literal>.</entry>
</row>
<row>
@@ -852,6 +852,24 @@
</tbody>
</tgroup>
</table>
+
+ <para>To tune the indexing speed it might be useful to time the
+ object loading from database in isolation from the writes to the index.
+ To achieve this set the <literal>blackhole</literal> as worker backend and start
+ you indexing routines.
+ This backend does not disable Hibernate Search: it will still generate the needed
+ changesets to the index, but will discard them instead of flushing them to the index.
+ As opposite to setting the <literal>hibernate.search.indexing_strategy</literal>
+ to <literal>manual</literal> when using <literal>blackhole</literal> it will possibly load
+ more data to rebuild the index from associated entities.</para>
+
+ <programlisting>hibernate.search.worker.backend blackhole</programlisting>
+
+ <para>The recommended approach is to focus first on optimizing the object loading, and then
+ use the timings you achieve as a baseline to tune the indexing process.</para>
+ <para>The <literal>blackhole</literal> backend is not meant to be used in production, only
+ as a tool to identify indexing bottlenecks.</para>
+
</section>
<section id="search-configuration-directory-lockfactories" revision="1">
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2009-04-13 17:46:22 UTC (rev 16309)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2009-04-13 22:37:42 UTC (rev 16310)
@@ -23,6 +23,7 @@
import org.hibernate.search.backend.WorkQueue;
import org.hibernate.search.backend.WorkType;
import org.hibernate.search.backend.configuration.ConfigurationParseHelper;
+import org.hibernate.search.backend.impl.blackhole.BlackHoleBackendQueueProcessorFactory;
import org.hibernate.search.backend.impl.jms.JMSBackendQueueProcessorFactory;
import org.hibernate.search.backend.impl.lucene.LuceneBackendQueueProcessorFactory;
import org.hibernate.search.engine.DocumentBuilderIndexedEntity;
@@ -83,6 +84,9 @@
else if ( "jms".equalsIgnoreCase( backend ) ) {
backendQueueProcessorFactory = new JMSBackendQueueProcessorFactory();
}
+ else if ( "blackhole".equalsIgnoreCase( backend ) ) {
+ backendQueueProcessorFactory = new BlackHoleBackendQueueProcessorFactory();
+ }
else {
try {
Class processorFactoryClass = ReflectHelper.classForName( backend, BatchedQueueingProcessor.class );
Added: search/trunk/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java 2009-04-13 22:37:42 UTC (rev 16310)
@@ -0,0 +1,51 @@
+// $Id$
+package org.hibernate.search.backend.impl.blackhole;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.hibernate.search.backend.BackendQueueProcessorFactory;
+import org.hibernate.search.backend.LuceneWork;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.util.LoggerFactory;
+import org.slf4j.Logger;
+
+/**
+ * This backend does not do anything: the Documents are not
+ * sent to any index but are discarded.
+ * Useful to identify the bottleneck in indexing performance problems,
+ * fully disabling the backend system but still building the Documents
+ * needed to update an index (loading data from DB).
+ *
+ * @author Sanne Grinovero
+ */
+public class BlackHoleBackendQueueProcessorFactory implements BackendQueueProcessorFactory {
+
+ private static final Logger log = LoggerFactory.make();
+
+ private final NoOp noOp = new NoOp();
+
+ public Runnable getProcessor(List<LuceneWork> queue) {
+ return noOp;
+ }
+
+ public void initialize(Properties props, SearchFactoryImplementor searchFactory) {
+ // no-op
+ log.warn( "initialized \"blackhole\" backend. Index changes will be prepared but discarded!" );
+ }
+
+ public void close() {
+ // no-op
+ log.info( "closed \"blackhole\" backend." );
+ }
+
+ private static class NoOp implements Runnable {
+
+ public void run() {
+ // no-op
+ log.debug( "Discarding a list of LuceneWork" );
+ }
+
+ }
+
+}
Property changes on: search/trunk/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: search/trunk/src/test/java/org/hibernate/search/test/configuration/CustomBackendTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/configuration/CustomBackendTest.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/configuration/CustomBackendTest.java 2009-04-13 22:37:42 UTC (rev 16310)
@@ -0,0 +1,39 @@
+// $Id$
+package org.hibernate.search.test.configuration;
+
+import junit.framework.TestCase;
+
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.backend.BackendQueueProcessorFactory;
+import org.hibernate.search.backend.impl.blackhole.BlackHoleBackendQueueProcessorFactory;
+import org.hibernate.search.backend.impl.lucene.LuceneBackendQueueProcessorFactory;
+import org.hibernate.search.impl.SearchFactoryImpl;
+import org.hibernate.search.test.util.FullTextSessionBuilder;
+
+/**
+ * @author Sanne Grinovero
+ */
+public class CustomBackendTest extends TestCase {
+
+ public void test() {
+ verifyBackendUsage( "blackhole", BlackHoleBackendQueueProcessorFactory.class );
+ verifyBackendUsage( "lucene", LuceneBackendQueueProcessorFactory.class );
+ verifyBackendUsage( BlackHoleBackendQueueProcessorFactory.class );
+ verifyBackendUsage( LuceneBackendQueueProcessorFactory.class );
+ }
+
+ private void verifyBackendUsage(String name, Class<? extends BackendQueueProcessorFactory> backendType) {
+ FullTextSessionBuilder builder = new FullTextSessionBuilder();
+ FullTextSession ftSession = builder
+ .setProperty( "hibernate.search.worker.backend", name )
+ .build();
+ SearchFactoryImpl searchFactory = (SearchFactoryImpl) ftSession.getSearchFactory();
+ assertEquals( backendType, searchFactory.getBackendQueueProcessorFactory().getClass() );
+ builder.close();
+ }
+
+ public void verifyBackendUsage(Class<? extends BackendQueueProcessorFactory> backendType) {
+ verifyBackendUsage( backendType.getName(), backendType );
+ }
+
+}
Property changes on: search/trunk/src/test/java/org/hibernate/search/test/configuration/CustomBackendTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
15 years, 7 months
Hibernate SVN: r16309 - core/branches.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-04-13 13:46:22 -0400 (Mon, 13 Apr 2009)
New Revision: 16309
Added:
core/branches/antlr3/
Log:
creating antlr3 branch
15 years, 7 months
Hibernate SVN: r16307 - in core/branches/SQL_GEN_REDESIGN/src/main: antlr/v3 and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-04-13 12:42:44 -0400 (Mon, 13 Apr 2009)
New Revision: 16307
Added:
core/branches/SQL_GEN_REDESIGN/src/main/antlr/v3/
core/branches/SQL_GEN_REDESIGN/src/main/antlr/v3/order/
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/render/
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/render/TableAliasBuilder.java
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ASTFactoryImpl.java
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/AliasRef.java
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Column.java
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ExpectedTypeAware.java
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HqlResolver.java
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Name.java
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableProcesser.java
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/RowValueConstructorList.java
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Table.java
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Typed.java
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/load/
core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/load/LoadPlan.java
Log:
Added: core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/render/TableAliasBuilder.java
===================================================================
--- core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/render/TableAliasBuilder.java (rev 0)
+++ core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/render/TableAliasBuilder.java 2009-04-13 16:42:44 UTC (rev 16307)
@@ -0,0 +1,68 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.sql.ast.phase.hql.render;
+
+import org.hibernate.persister.entity.Queryable;
+import org.hibernate.persister.collection.QueryableCollection;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public interface TableAliasBuilder {
+
+ public static class AliasRoot {
+ private final String base;
+
+ public AliasRoot(String base) {
+ this.base = base;
+ }
+
+ public String generate(int suffix) {
+ return base + Integer.toString( suffix ) + '_';
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+ AliasRoot aliasRoot = ( AliasRoot ) o;
+ return base.equals( aliasRoot.base );
+ }
+
+ public int hashCode() {
+ return base.hashCode();
+ }
+ }
+
+ public AliasRoot getSqlAliasRoot(Queryable persister, String alias);
+
+ public AliasRoot getSqlAliasRoot(QueryableCollection persister, String alias);
+
+ public AliasRoot getSimpleSqlAliasRoot(QueryableCollection persister);
+}
Added: core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ASTFactoryImpl.java
===================================================================
--- core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ASTFactoryImpl.java (rev 0)
+++ core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ASTFactoryImpl.java 2009-04-13 16:42:44 UTC (rev 16307)
@@ -0,0 +1,50 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.sql.ast.phase.hql.resolve;
+
+import org.hibernate.sql.ast.common.NodeFactory;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class ASTFactoryImpl extends NodeFactory implements HqlResolveTokenTypes {
+ public Class getASTNodeType(int tokenType) {
+ switch ( tokenType ) {
+ case TABLE :
+ return Table.class;
+ case COLUMN :
+ return Column.class;
+ case ALIAS_REF :
+ return AliasRef.class;
+ case NAME :
+ return Name.class;
+ case ROW_VALUE_CONSTRUCTOR_LIST :
+ return RowValueConstructorList.class;
+ default:
+ return determineDefaultNodeClass();
+ }
+ }
+}
Added: core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/AliasRef.java
===================================================================
--- core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/AliasRef.java (rev 0)
+++ core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/AliasRef.java 2009-04-13 16:42:44 UTC (rev 16307)
@@ -0,0 +1,41 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.sql.ast.phase.hql.resolve;
+
+import org.hibernate.sql.ast.common.Node;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class AliasRef extends Node {
+ public AliasRef() {
+ }
+
+ public AliasRef(String alias) {
+ setType( HqlResolveTokenTypes.ALIAS_REF );
+ setText( alias );
+ }
+}
Added: core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Column.java
===================================================================
--- core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Column.java (rev 0)
+++ core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Column.java 2009-04-13 16:42:44 UTC (rev 16307)
@@ -0,0 +1,55 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.sql.ast.phase.hql.resolve;
+
+import org.hibernate.sql.ast.common.Node;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Column extends Node {
+ private String selectAlias;
+
+ public Column() {
+ }
+
+ public Column(String tableAlias, String columnName) {
+ super();
+ setType( HqlResolveTokenTypes.COLUMN );
+ setText( '{' + tableAlias + '.' + columnName + '}' );
+ addChild( new AliasRef( tableAlias ) );
+ addChild( new Name( columnName ) );
+ }
+
+ public Column injectSelectAlias(String selectAlias) {
+ this.selectAlias = selectAlias;
+ return this;
+ }
+
+ public String getSelectAlias() {
+ return selectAlias;
+ }
+}
Added: core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ExpectedTypeAware.java
===================================================================
--- core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ExpectedTypeAware.java (rev 0)
+++ core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ExpectedTypeAware.java 2009-04-13 16:42:44 UTC (rev 16307)
@@ -0,0 +1,35 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.sql.ast.phase.hql.resolve;
+
+import org.hibernate.type.Type;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public interface ExpectedTypeAware extends Typed {
+ public void setExpectedType(Type expectedType);
+}
Added: core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HqlResolver.java
===================================================================
--- core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HqlResolver.java (rev 0)
+++ core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HqlResolver.java 2009-04-13 16:42:44 UTC (rev 16307)
@@ -0,0 +1,303 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.sql.ast.phase.hql.resolve;
+
+import java.util.HashMap;
+
+import antlr.ASTFactory;
+import antlr.RecognitionException;
+import antlr.collections.AST;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.MappingException;
+import org.hibernate.QueryException;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.persister.collection.QueryableCollection;
+import org.hibernate.persister.entity.Queryable;
+import org.hibernate.sql.ast.alias.DefaultTableAliasGenerator;
+import org.hibernate.sql.ast.util.ASTPrinter;
+import org.hibernate.sql.ast.util.ErrorHandlerDelegateImpl;
+import org.hibernate.sql.ast.util.ErrorHandlerDelegate;
+import org.hibernate.sql.ast.alias.TableAliasGenerator;
+import org.hibernate.sql.ast.phase.hql.resolve.expression.ExpressionResolutionStrategyStack;
+import org.hibernate.sql.ast.phase.hql.resolve.expression.DefaultExpressionResolutionStrategy;
+import org.hibernate.sql.ast.phase.hql.resolve.expression.SelectClauseExpressionResolutionStrategy;
+import org.hibernate.sql.ast.phase.hql.resolve.expression.FunctionArgumentExpressionResolutionStrategy;
+import org.hibernate.type.AssociationType;
+import org.hibernate.util.StringHelper;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class HqlResolver extends GeneratedHqlResolver {
+ private static final Logger log = LoggerFactory.getLogger( HqlResolver.class );
+
+ private final SessionFactoryImplementor sessionFactory;
+ private final ErrorHandlerDelegate parseErrorHandler = new ErrorHandlerDelegateImpl();
+ private final ASTPrinter printer = new ASTPrinter( HqlResolveTokenTypes.class );
+
+ private final TableAliasGenerator tableAliasGenerator;
+ private final PersisterTableProcesser persisterTableProcesser;
+
+ private ExpressionResolutionStrategyStack expressionResolverStack = new ExpressionResolutionStrategyStack();
+
+ private AST collectionFilterCondition;
+
+ public HqlResolver(SessionFactoryImplementor sessionFactory) {
+ super();
+ super.setASTFactory( new ASTFactoryImpl() );
+ this.sessionFactory = sessionFactory;
+ // todo : make this configurable
+ this.tableAliasGenerator = new DefaultTableAliasGenerator( sessionFactory.getDialect() );
+ this.persisterTableProcesser = new PersisterTableProcesser( getASTFactory() );
+ expressionResolverStack.push( new DefaultExpressionResolutionStrategy( this ) );
+ }
+
+ public ASTPrinter getPrinter() {
+ return printer;
+ }
+
+
+ // overrides of Antlr infastructure methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public void reportError(RecognitionException e) {
+ getParseErrorHandler().reportError( e );
+ }
+
+ public void reportError(String s) {
+ getParseErrorHandler().reportError( s );
+ }
+
+ public void reportWarning(String s) {
+ getParseErrorHandler().reportWarning( s );
+ }
+
+ public ErrorHandlerDelegate getParseErrorHandler() {
+ return parseErrorHandler;
+ }
+
+ static public void panic() {
+ //overriden to avoid System.exit
+ throw new QueryException( "Parser: panic" );
+ }
+
+ public void setASTFactory(ASTFactory astFactory) {
+ throw new UnsupportedOperationException( "not allowed!" );
+ }
+
+
+ // handle trace logging ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public void traceIn(String ruleName, AST tree) {
+ if ( inputState.guessing > 0 ) {
+ return;
+ }
+ String prefix = StringHelper.repeat( '-', (traceDepth++ * 2) ) + "-> ";
+ String traceText = ruleName + " (" + buildTraceNodeName(tree) + ")";
+ trace( prefix + traceText );
+ }
+
+ private String buildTraceNodeName(AST tree) {
+ return tree == null
+ ? "???"
+ : tree.getText() + " [" + printer.getTokenTypeName( tree.getType() ) + "]";
+ }
+
+ public void traceOut(String ruleName, AST tree) {
+ if ( inputState.guessing > 0 ) {
+ return;
+ }
+ String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth * 2) ) + " ";
+ trace( prefix + ruleName );
+ }
+
+ private void trace(String msg) {
+ System.out.println( msg );
+// log.trace( msg );
+ }
+
+
+ // semantic action overrides ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ private HashMap aliasToTableSpaceMap = new HashMap();
+
+ public Table.TableSpace resolveTableSpaceByAlias(String alias) {
+ return ( Table.TableSpace ) aliasToTableSpaceMap.get( alias );
+ }
+
+ protected AST resolveEntityPersister(AST entityName, AST alias, AST filter) {
+ final Queryable persister = ( Queryable ) sessionFactory.getEntityPersister( entityName.getText() );
+ final String aliasText = alias.getText();
+
+ Table.EntityTableSpace tableSpace = new Table.EntityTableSpace( persister, aliasText );
+ aliasToTableSpaceMap.put( aliasText, tableSpace );
+
+ TableAliasGenerator.TableAliasRoot aliasRoot = tableAliasGenerator.generateSqlAliasRoot( persister, aliasText );
+
+ Table table = persisterTableProcesser.buildTables(
+ persister,
+ aliasRoot,
+ tableSpace
+ );
+
+ if ( filter != null ) {
+ String filteredCollectionRole = filter.getText();
+ QueryableCollection filteredCollectionPersister =
+ ( QueryableCollection ) sessionFactory.getCollectionPersister( filteredCollectionRole );
+ collectionFilterCondition = persisterTableProcesser.handleCollectionFilterConditions(
+ table,
+ aliasRoot,
+ filteredCollectionPersister
+ );
+ }
+
+ return table;
+ }
+
+ protected void postProcessQuery(AST query) {
+ if ( collectionFilterCondition != null ) {
+ AST selectClause = query.getFirstChild();
+ AST fromClause = selectClause.getNextSibling();
+ AST whereClause = fromClause.getNextSibling();
+ if ( whereClause == null ) {
+ // there was no where-clause, group-by-clause or having-clause...
+ whereClause = astFactory.create( WHERE, "where" );
+ fromClause.setNextSibling( whereClause );
+ }
+ else if ( whereClause.getType() == GROUP_BY ) {
+ // there was no where-clause, but was a group-by-clause
+ AST groupByClause = whereClause;
+ whereClause = astFactory.create( WHERE, "where" );
+ whereClause.setNextSibling( groupByClause );
+ fromClause.setNextSibling( whereClause );
+ }
+ assert whereClause.getType() == WHERE : "mis-structured AST";
+ log.trace( printer.showAsString( collectionFilterCondition, "collection-filter key condition" ) );
+ appendSearchCondition( collectionFilterCondition, whereClause );
+ collectionFilterCondition = null;
+ }
+ }
+
+ protected AST resolveCollectionPersister(AST collectionRole, AST alias) {
+ return super.resolveCollectionPersister( collectionRole, alias );
+ }
+
+ protected void applyPropertyJoin(AST lhs, AST rhs, AST propertyName, AST joinType, AST with) {
+ final AST correlation = generateAssociationJoinCondition( lhs, rhs, propertyName );
+ AST on = astFactory.create( ON, "on" );
+ if ( with == null ) {
+ on.addChild( correlation );
+ }
+ else {
+ AST and = astFactory.create( AND, "and" );
+ and.addChild( correlation );
+ and.addChild( with );
+ on.addChild( and );
+ }
+
+ AST join = astFactory.create( JOIN, "join" );
+ join.addChild( joinType );
+ join.addChild( rhs );
+ join.addChild( on );
+
+ lhs.addChild( join );
+ }
+
+ private AST generateAssociationJoinCondition(AST lhs, AST rhs, AST propertyName) {
+ final String propertyNameText = propertyName.getText();
+ Table lhsTable = ( Table ) lhs;
+ Table.TableSpace lhsTableSpace = lhsTable.getTableSpace();
+ String lhsTableAlias = lhsTableSpace.getContainingTable( propertyNameText ).getAliasText();
+ String[] lhsJoinColumns = lhsTableSpace.getPropertyColumnNames( propertyNameText );
+
+ AssociationType propertyType = ( AssociationType ) lhsTableSpace.getPropertyType( propertyNameText );
+ String rhsPropertyName = propertyType.getRHSUniqueKeyPropertyName();
+ Table.TableSpace rhsTableSpace = ( ( Table ) rhs ).getTableSpace();
+ String rhsTableAlias;
+ String[] rhsJoinColumns;
+ if ( rhsPropertyName == null ) {
+ // reference to RHS PK
+ rhsTableAlias = rhsTableSpace.getJoinIntoTable().getAliasText();
+ rhsJoinColumns = rhsTableSpace.getJoinIntoColumns();
+ }
+ else {
+ // reference to RHS property-ref
+ Table rhsTable = rhsTableSpace.getContainingTable( rhsPropertyName );
+ rhsTableAlias = rhsTable.getAliasText();
+ rhsJoinColumns = rhsTableSpace.getPropertyColumnNames( rhsPropertyName );
+ }
+
+ if ( lhsJoinColumns.length != rhsJoinColumns.length ) {
+ throw new MappingException( "Association had unequal number of columns : " + propertyType.getName() );
+ }
+
+ return persisterTableProcesser.generateJoinCorrelation( lhsTableAlias, lhsJoinColumns, rhsTableAlias, rhsJoinColumns );
+ }
+
+ protected AST generateIndexValueCondition(AST lhs, AST rhs, AST propertyName, AST selector) {
+ return super.generateIndexValueCondition( lhs, rhs, propertyName, selector );
+ }
+
+ protected void startSelectClause() {
+ expressionResolverStack.push( new SelectClauseExpressionResolutionStrategy( this ) );
+ }
+
+ protected void finishSelectClause() {
+ expressionResolverStack.pop();
+ }
+
+ protected void startFunction() {
+ expressionResolverStack.push( new FunctionArgumentExpressionResolutionStrategy( this ) );
+ }
+
+ protected void finishFunction() {
+ expressionResolverStack.pop();
+ }
+
+ protected void appendSearchCondition(AST condition, AST container) {
+ if ( container.getFirstChild() == null ) {
+ container.setFirstChild( condition );
+ }
+ else {
+ AST and = getASTFactory().create( AND, "and" );
+ and.setFirstChild( container.getFirstChild() );
+ and.addChild( condition );
+ container.setFirstChild( and );
+ }
+ }
+
+ protected AST resolvePropertyReference(AST persisterAlias, AST propertyName) {
+ final String aliasText = persisterAlias.getText();
+ final String propertyNameText = propertyName.getText();
+
+ return expressionResolverStack.getCurrent().resolvePropertyReference( aliasText, propertyNameText );
+ }
+
+ protected AST resolveAliasReference(AST aliasReference) {
+ return expressionResolverStack.getCurrent().resolveAliasReference( aliasReference.getText() );
+ }
+}
Added: core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Name.java
===================================================================
--- core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Name.java (rev 0)
+++ core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Name.java 2009-04-13 16:42:44 UTC (rev 16307)
@@ -0,0 +1,41 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.sql.ast.phase.hql.resolve;
+
+import org.hibernate.sql.ast.common.Node;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Name extends Node {
+ public Name() {
+ }
+
+ public Name(String name) {
+ setType( HqlResolveTokenTypes.NAME );
+ setText( name );
+ }
+}
Added: core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableProcesser.java
===================================================================
--- core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableProcesser.java (rev 0)
+++ core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableProcesser.java 2009-04-13 16:42:44 UTC (rev 16307)
@@ -0,0 +1,226 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.sql.ast.phase.hql.resolve;
+
+import antlr.ASTFactory;
+import antlr.collections.AST;
+
+import org.hibernate.persister.entity.Queryable;
+import org.hibernate.persister.entity.Joinable;
+import org.hibernate.persister.MappedTableMetadata;
+import org.hibernate.persister.collection.QueryableCollection;
+import org.hibernate.sql.ast.alias.TableAliasGenerator;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class PersisterTableProcesser implements HqlResolveTokenTypes {
+ private final ASTFactory astFactory;
+
+ public PersisterTableProcesser(ASTFactory astFactory) {
+ this.astFactory = astFactory;
+ }
+
+ public Table buildTables(Queryable persister, TableAliasGenerator.TableAliasRoot aliasRoot, Table.EntityTableSpace tableSpace) {
+ MappedTableMetadata tableMetadata = persister.getMappedTableMetadata();
+
+ final String drivingTableName = tableMetadata.getDrivingTableName();
+ final String[] drivingTableJoinColumns = tableMetadata.getIdentifierColumnNames();
+ final String drivingTableAlias = aliasRoot.generate( 0 );
+ final Table drivingTable = generateTableReference( drivingTableName, drivingTableAlias );
+ tableSpace.registerTable( drivingTable );
+
+ int suffix = 0;
+
+ MappedTableMetadata.JoinedTable[] tables = tableMetadata.getJoinedTables();
+ for ( int i = 0; i < tables.length; i++ ) {
+ final String joinTableAlias = aliasRoot.generate( ++suffix );
+ final Table table = generateTableReference( tables[i].getName(), joinTableAlias );
+ tableSpace.registerTable( table );
+
+ final AST join = astFactory.create( JOIN, "join" );
+ drivingTable.addChild( join );
+ join.setFirstChild( tables[i].useInnerJoin() ? astFactory.create( INNER, "inner" ) : astFactory.create( LEFT, "left outer" ) );
+ join.addChild( table );
+
+ final AST on = astFactory.create( ON, "on" );
+ join.addChild( on );
+ on.setFirstChild( generateJoinCorrelation( drivingTableAlias, drivingTableJoinColumns, joinTableAlias, tables[i].getKeyColumns() ) );
+ }
+
+ return drivingTable;
+ }
+
+ public Table buildTables(
+ QueryableCollection collectionPersister,
+ TableAliasGenerator.TableAliasRoot aliasRoot,
+ Table.CollectionTableSpace tableSpace) {
+ if ( collectionPersister.isOneToMany() ) {
+ Table table = buildTables(
+ ( Queryable ) collectionPersister.getElementPersister(),
+ aliasRoot,
+ tableSpace.getEntityElementTableSpace()
+ );
+ tableSpace.setCollectionTable( table );
+ return table;
+ }
+ else {
+ Table associationTable = generateTableReference(
+ collectionPersister.getTableName(),
+ aliasRoot.generateCollectionTableAlias()
+ );
+ tableSpace.setCollectionTable( associationTable );
+
+ if ( collectionPersister.isManyToMany() ) {
+ Queryable elementPersister = ( Queryable ) collectionPersister.getElementPersister();
+ Table drivingTable = buildTables(
+ elementPersister,
+ aliasRoot,
+ tableSpace.getEntityElementTableSpace()
+ );
+
+ AST join = astFactory.create( JOIN, "join" );
+ associationTable.addChild( join );
+ join.addChild( astFactory.create( LEFT, "left outer" ) );
+ join.addChild( drivingTable );
+
+ String[] entityFkColumnNames = collectionPersister.getElementColumnNames();
+ String[] entityPkColumnNames = elementPersister.getKeyColumnNames();
+
+ AST on = astFactory.create( ON, "on" );
+ join.addChild( on );
+ on.setFirstChild(
+ generateJoinCorrelation(
+ associationTable.getAliasText(),
+ entityFkColumnNames,
+ drivingTable.getAliasText(),
+ entityPkColumnNames
+ )
+ );
+ }
+ return associationTable;
+ }
+ }
+
+ public AST handleCollectionFilterConditions(
+ Table drivingEntityTable,
+ TableAliasGenerator.TableAliasRoot aliasRoot,
+ QueryableCollection filteredCollectionPersister) {
+ Table collectionKeyTable = drivingEntityTable;
+
+ if ( !filteredCollectionPersister.isOneToMany() ) {
+ // need to deal with the collection table, which is where the collection-key would be...
+ Table associationTable = generateTableReference(
+ filteredCollectionPersister.getTableName(),
+ aliasRoot.generateCollectionTableAlias()
+ );
+
+ String[] entityFkColumnNames = filteredCollectionPersister.getElementColumnNames();
+ String[] entityPkColumnNames = ( ( Joinable ) filteredCollectionPersister.getElementPersister() ).getKeyColumnNames();
+
+ AST join = astFactory.create( JOIN, "join" );
+ drivingEntityTable.addChild( join );
+ join.addChild( astFactory.create( LEFT, "left outer" ) );
+ join.addChild( associationTable );
+
+ AST on = astFactory.create( ON, "on" );
+ join.addChild( on );
+ on.setFirstChild(
+ generateJoinCorrelation(
+ drivingEntityTable.getAliasText(),
+ entityPkColumnNames,
+ associationTable.getAliasText(),
+ entityFkColumnNames
+ )
+ );
+
+ collectionKeyTable = associationTable;
+ }
+
+ return generateCollectionFilterRestriction(
+ collectionKeyTable.getAliasText(),
+ filteredCollectionPersister.getKeyColumnNames()
+ );
+ }
+
+ private Table generateTableReference(String tableName, String alias) {
+ Table tableReference = ( Table ) astFactory.create( TABLE, "table" );
+ tableReference.addChild( astFactory.create( NAME, tableName ) );
+ tableReference.addChild( astFactory.create( ALIAS, alias ) );
+ return tableReference;
+ }
+
+ public AST generateJoinCorrelation(
+ String lhsAlias,
+ String[] lhsColumns,
+ String rhsAlias,
+ String[] rhsColumns) {
+ AST correlation = generateJoinCorrelation( lhsAlias, lhsColumns[0], rhsAlias, rhsColumns[0] );
+ if ( lhsColumns.length > 1 ) {
+ for ( int i = 1; i < lhsColumns.length; i++ ) {
+ AST previous = correlation;
+ correlation = astFactory.create( AND, "and" );
+ correlation.setFirstChild( previous );
+ correlation.addChild( generateJoinCorrelation( lhsAlias, lhsColumns[i], rhsAlias, rhsColumns[i] ) );
+ }
+ }
+ return correlation;
+ }
+
+ public AST generateJoinCorrelation(String lhsAlias, String lhsColumn, String rhsAlias, String rhsColumn) {
+ AST lhs = astFactory.create( COLUMN, "column" );
+ lhs.addChild( astFactory.create( ALIAS_REF, lhsAlias ) );
+ lhs.addChild( astFactory.create( NAME, lhsColumn ) );
+
+ AST rhs = astFactory.create( COLUMN, "column" );
+ rhs.addChild( astFactory.create( ALIAS_REF, rhsAlias ) );
+ rhs.addChild( astFactory.create( NAME, rhsColumn ) );
+
+ AST correlation = astFactory.create( EQUALS_OP, "=" );
+ correlation.addChild( lhs );
+ correlation.addChild( rhs );
+
+ return correlation;
+ }
+
+ private AST generateCollectionFilterRestriction(String alias, String[] keyColumns) {
+ // todo : for now we restrict this to single-column FKs
+ // Looks like this is true of old code as well...
+
+ AST column = astFactory.create( COLUMN, "column" );
+ column.addChild( astFactory.create( ALIAS_REF, alias ) );
+ column.addChild( astFactory.create( NAME, keyColumns[0] ) );
+
+ AST param = astFactory.create( NAMED_PARAM, "collection-filter-key" ); // todo : put this in a well known place
+
+ AST correlation = astFactory.create( EQUALS_OP, "=" );
+ correlation.addChild( column );
+ correlation.addChild( param );
+
+ return correlation;
+ }
+
+}
Added: core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/RowValueConstructorList.java
===================================================================
--- core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/RowValueConstructorList.java (rev 0)
+++ core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/RowValueConstructorList.java 2009-04-13 16:42:44 UTC (rev 16307)
@@ -0,0 +1,75 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.sql.ast.phase.hql.resolve;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.sql.ast.common.Node;
+import org.hibernate.type.Type;
+import org.hibernate.type.ComponentType;
+
+import antlr.collections.AST;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class RowValueConstructorList extends Node implements ExpectedTypeAware {
+ private static final Logger log = LoggerFactory.getLogger( RowValueConstructorList.class );
+
+ private Type hibernateType;
+
+ public RowValueConstructorList() {
+ setType( HqlResolveTokenTypes.ROW_VALUE_CONSTRUCTOR_LIST );
+ setText( "row-value-ctor-list" );
+ }
+
+ public void setExpectedType(Type expectedType) {
+ if ( hibernateType != null ) {
+ log.info( "Over-setting expected type [{} -> {}]", hibernateType.getName(), expectedType.getName() );
+ }
+ hibernateType = expectedType;
+ if ( expectedType.isComponentType() ) {
+ final ComponentType componentType = ( ComponentType ) expectedType;
+ final Type[] subtypes = componentType.getSubtypes();
+ final int length = subtypes.length;
+ if ( length == getNumberOfChildren() ) {
+ AST child = getFirstChild();
+ for ( int i = 0, max = subtypes.length; i < max; i++ ) {
+ if ( child instanceof ExpectedTypeAware ) {
+ log.debug( "propogating expected type info for component sub-property [{}]", componentType.getPropertyNames()[i] );
+ ( ( ExpectedTypeAware ) child ).setExpectedType( subtypes[i] );
+ }
+ child = child.getNextSibling();
+ }
+ }
+ }
+ }
+
+ public Type getHibernateType() {
+ return hibernateType;
+ }
+}
Added: core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Table.java
===================================================================
--- core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Table.java (rev 0)
+++ core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Table.java 2009-04-13 16:42:44 UTC (rev 16307)
@@ -0,0 +1,237 @@
+package org.hibernate.sql.ast.phase.hql.resolve;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.sql.ast.common.Node;
+import org.hibernate.sql.ast.alias.ImplicitAliasGenerator;
+import org.hibernate.sql.ast.util.DisplayableNode;
+import org.hibernate.persister.entity.Queryable;
+import org.hibernate.persister.collection.QueryableCollection;
+import org.hibernate.util.StringHelper;
+import org.hibernate.type.Type;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Table extends Node implements DisplayableNode {
+ private TableSpace tableSpace;
+
+ public Table() {
+ setType( HqlResolveTokenTypes.TABLE );
+ setText( "table" );
+ }
+
+ public TableSpace getTableSpace() {
+ return tableSpace;
+ }
+
+ public Node getTableName() {
+ return ( Node ) getFirstChild();
+ }
+
+ public String getTableNameText() {
+ return getTableName().getText();
+ }
+
+ public Node getAlias() {
+ return ( Node ) getFirstChild().getNextSibling();
+ }
+
+ public String getAliasText() {
+ return getAlias().getText();
+ }
+
+ public String getText() {
+ return getTableNameText() + " (" + getAliasText() + ")";
+ }
+
+ public String getDisplayText() {
+ return "[source-alias=" + tableSpace.getSourceAlias() + "]";
+ }
+
+ public static interface TableSpace {
+ /**
+ * Used as a unique identification since each table space originates from a single source alias (persister reference).
+ *
+ * @return The source alias.
+ */
+ public String getSourceAlias();
+
+ /**
+ * Get the table reference that should act as the RHS for this table space whenever we join to into it.
+ *
+ * @return The RHS table for joining into this table space structure.
+ */
+ public Table getJoinIntoTable();
+
+ public String[] getJoinIntoColumns();
+
+ /**
+ * Get the table reference that contains the columns to which the given property is mapped.
+ *
+ * @param propertyName The name of the property for which to locate the containing table.
+ *
+ * @return The containing table.
+ */
+ public Table getContainingTable(String propertyName);
+
+ public Type getPropertyType(String propertyName);
+
+ public String[] getPropertyColumnNames(String propertyName);
+
+ public List buildIdentifierColumnReferences();
+
+ public List buildCompleteColumnReferences();
+ }
+
+ public static abstract class AbstractTableSpace implements Table.TableSpace {
+ private final String sourceAlias;
+ private final String sqlAliasBaseRoot;
+
+ private AbstractTableSpace(String sourceAlias, String persisterName) {
+ this.sourceAlias = sourceAlias;
+ this.sqlAliasBaseRoot = ImplicitAliasGenerator.isImplicitAlias( sourceAlias ) ? persisterName : sourceAlias;
+ }
+
+ public String getSourceAlias() {
+ return sourceAlias;
+ }
+
+ public String getSqlAliasBaseRoot() {
+ return sqlAliasBaseRoot;
+ }
+ }
+
+ public static class EntityTableSpace extends AbstractTableSpace {
+ private final Queryable entityPersister;
+ private final ArrayList tables;
+
+ public EntityTableSpace(Queryable entityPersister, String sourecAlias) {
+ super( sourecAlias, StringHelper.unqualifyEntityName( entityPersister.getEntityName() ) );
+ this.entityPersister = entityPersister;
+ int numberOfTables = entityPersister.getMappedTableMetadata().getJoinedTables().length + 1;
+ int listSize = numberOfTables + (int) ( numberOfTables * .75 ) + 1;
+ this.tables = new ArrayList( listSize );
+ }
+
+ public Queryable getEntityPersister() {
+ return entityPersister;
+ }
+
+ public void registerTable(Table table) {
+ table.tableSpace = this;
+ tables.add( table );
+ }
+
+ public Table getDrivingTable() {
+ return ( Table ) tables.get( 0 );
+ }
+
+ public Table getJoinIntoTable() {
+ return getDrivingTable();
+ }
+
+ public String[] getJoinIntoColumns() {
+ return entityPersister.getIdentifierColumnNames();
+ }
+
+ public Table getContainingTable(String propertyName) {
+ return ( Table ) tables.get( entityPersister.getSubclassPropertyTableNumber( propertyName ) );
+ }
+
+ public Type getPropertyType(String propertyName) {
+ return entityPersister.getPropertyType( propertyName );
+ }
+
+ public String[] getPropertyColumnNames(String propertyName) {
+ int index = entityPersister.getEntityMetamodel().getPropertyIndex( propertyName );
+ return entityPersister.getPropertyColumnNames( index );
+ }
+
+ public List buildIdentifierColumnReferences() {
+ String[] identifierColumnsNames = entityPersister.getIdentifierColumnNames();
+ ArrayList columnsReferences = new ArrayList( collectionSizeWithoutRehashing( identifierColumnsNames.length ) );
+ for ( int i = 0; i < identifierColumnsNames.length; i++ ) {
+ columnsReferences.add( new Column( getDrivingTable().getAliasText(), identifierColumnsNames[i] ) );
+ }
+ return columnsReferences;
+ }
+
+ public List buildCompleteColumnReferences() {
+ // todo : implement
+ return null;
+ }
+ }
+
+ private static int collectionSizeWithoutRehashing(int elements) {
+ // usually collection load factors are .75
+ return collectionSizeWithoutRehashing( elements, .75 );
+ }
+
+ private static int collectionSizeWithoutRehashing(int elements, double factor) {
+ return elements + ( (int) ( elements * factor ) + 1 );
+ }
+
+ public static class CollectionTableSpace extends AbstractTableSpace {
+ private final QueryableCollection persister;
+ private final boolean areElementsEntities;
+
+ private Table collectionTable;
+ private EntityTableSpace entityElementTableSpace;
+
+ public CollectionTableSpace(QueryableCollection persister, String sourceAlias) {
+ super( sourceAlias, StringHelper.unqualify( persister.getRole() ) );
+ this.persister = persister;
+ this.areElementsEntities = persister.getElementType().isEntityType();
+ if ( areElementsEntities ) {
+ entityElementTableSpace = new EntityTableSpace( ( Queryable ) persister.getElementPersister(), sourceAlias );
+ }
+ }
+
+ public QueryableCollection getPersister() {
+ return persister;
+ }
+
+ public void setCollectionTable(Table collectionTable) {
+ this.collectionTable = collectionTable;
+ }
+
+ public EntityTableSpace getEntityElementTableSpace() {
+ return entityElementTableSpace;
+ }
+
+ public Table getJoinIntoTable() {
+ return collectionTable;
+ }
+
+ public String[] getJoinIntoColumns() {
+ return persister.getKeyColumnNames();
+ }
+
+ public Table getContainingTable(String propertyName) {
+ // todo : are we needing to handle "collection properties" (SIZE, etc) here still?
+ return getEntityElementTableSpace().getContainingTable( propertyName );
+ }
+
+ public Type getPropertyType(String propertyName) {
+ return getEntityElementTableSpace().getPropertyType( propertyName );
+ }
+
+ public String[] getPropertyColumnNames(String propertyName) {
+ return getEntityElementTableSpace().getPropertyColumnNames( propertyName );
+ }
+
+ public List buildIdentifierColumnReferences() {
+ // todo : implement
+ return null;
+ }
+
+ public List buildCompleteColumnReferences() {
+ // todo : implement
+ return null;
+ }
+ }
+}
Added: core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Typed.java
===================================================================
--- core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Typed.java (rev 0)
+++ core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/Typed.java 2009-04-13 16:42:44 UTC (rev 16307)
@@ -0,0 +1,35 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.sql.ast.phase.hql.resolve;
+
+import org.hibernate.type.Type;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public interface Typed {
+ public Type getHibernateType();
+}
Added: core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/load/LoadPlan.java
===================================================================
--- core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/load/LoadPlan.java (rev 0)
+++ core/branches/SQL_GEN_REDESIGN/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/load/LoadPlan.java 2009-04-13 16:42:44 UTC (rev 16307)
@@ -0,0 +1,38 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.sql.ast.phase.hql.resolve.load;
+
+import org.hibernate.type.Type;
+
+/**
+ * I want this to be an encapsulation of the information needed by Loader. Stuff like the persisters, the aliases, etc...
+ *
+ * @author Steve Ebersole
+ */
+public class LoadPlan {
+ // todo : distinguish (interfaces/impls?) between dynamic-instantiation, scalar, and entity load plans
+
+ private Type[] queryReturnTypes;
+
+}
15 years, 7 months
Hibernate SVN: r16306 - in search/trunk/src: main/java and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2009-04-13 11:26:20 -0400 (Mon, 13 Apr 2009)
New Revision: 16306
Added:
search/trunk/src/test/java/org/hibernate/search/test/engine/EventListenerSerializationTest.java
Removed:
search/trunk/src/main/java/org/hibernate/search/event/IndexWorkFlushEventListener.java
Modified:
search/trunk/src/main/docbook/en-US/modules/configuration.xml
search/trunk/src/main/java/
search/trunk/src/main/java/org/hibernate/search/backend/impl/EventSourceTransactionContext.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/TransactionalWorker.java
search/trunk/src/main/java/org/hibernate/search/event/EventListenerRegister.java
search/trunk/src/main/java/org/hibernate/search/event/FullTextIndexEventListener.java
search/trunk/src/test/java/org/hibernate/search/test/TestCase.java
Log:
HSEARCH-178 for trunk only
Modified: search/trunk/src/main/docbook/en-US/modules/configuration.xml
===================================================================
--- search/trunk/src/main/docbook/en-US/modules/configuration.xml 2009-04-11 04:54:37 UTC (rev 16305)
+++ search/trunk/src/main/docbook/en-US/modules/configuration.xml 2009-04-13 15:26:20 UTC (rev 16306)
@@ -605,8 +605,8 @@
<para>To enable Hibernate Search in Hibernate Core (ie. if you don't use
Hibernate Annotations), add the
<literal>FullTextIndexEventListener</literal> for the following six
- Hibernate events and add the <literal>IndexWorkFlushEventListener</literal> after
- the default <literal>DefaultFlushEventListener</literal>, as in the following example.</para>
+ Hibernate events and also add it after the default
+ <literal>DefaultFlushEventListener</literal>, as in the following example.</para>
<example>
<title>Explicitly enabling Hibernate Search by configuring the
@@ -635,7 +635,7 @@
</event>
<event type="flush">
<listener class="org.hibernate.event.def.DefaultFlushEventListener"/>
- <listener class="org.hibernate.search.event.IndexWorkFlushEventListener"/>
+ <listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
</event>
</session-factory>
</hibernate-configuration></programlisting>
Property changes on: search/trunk/src/main/java
___________________________________________________________________
Name: svn:mergeinfo
-
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/EventSourceTransactionContext.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/EventSourceTransactionContext.java 2009-04-11 04:54:37 UTC (rev 16305)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/EventSourceTransactionContext.java 2009-04-13 15:26:20 UTC (rev 16306)
@@ -5,12 +5,12 @@
import javax.transaction.Synchronization;
-import org.hibernate.AssertionFailure;
import org.hibernate.Transaction;
import org.hibernate.event.EventSource;
import org.hibernate.event.FlushEventListener;
+import org.hibernate.search.SearchException;
import org.hibernate.search.backend.TransactionContext;
-import org.hibernate.search.event.IndexWorkFlushEventListener;
+import org.hibernate.search.event.FullTextIndexEventListener;
import org.hibernate.search.util.LoggerFactory;
import org.slf4j.Logger;
@@ -26,7 +26,9 @@
private static final Logger log = LoggerFactory.make();
private final EventSource eventSource;
- private final IndexWorkFlushEventListener flushListener;
+
+ //this transient is required to break recursive serialization
+ private transient FullTextIndexEventListener flushListener;
//constructor time is too early to define the value of realTxInProgress,
//postpone it, otherwise doing
@@ -36,7 +38,7 @@
public EventSourceTransactionContext(EventSource eventSource) {
this.eventSource = eventSource;
- this.flushListener = findIndexWorkFlushEventListener();
+ this.flushListener = getIndexWorkFlushEventListener();
}
public Object getTransactionIdentifier() {
@@ -54,25 +56,32 @@
transaction.registerSynchronization( synchronization );
}
else {
- if ( flushListener != null ) {
+ //registerSynchronization is only called if isRealTransactionInProgress or if
+ // a flushListener was found; still we might need to find the listener again
+ // as it might have been cleared by serialization (is transient).
+ FullTextIndexEventListener flushList = getIndexWorkFlushEventListener();
+ if ( flushList != null ) {
flushListener.addSynchronization( eventSource, synchronization );
}
else {
- //It appears we are flushing out of transaction and have no way to perform the index update
- //Not expected: see check in isTransactionInProgress()
- throw new AssertionFailure( "On flush out of transaction: IndexWorkFlushEventListener not registered" );
+ //shouldn't happen if the code about serialization is fine:
+ throw new SearchException( "AssertionFailure: flushListener not registered any more.");
}
}
}
- private IndexWorkFlushEventListener findIndexWorkFlushEventListener() {
+ private FullTextIndexEventListener getIndexWorkFlushEventListener() {
+ if ( this.flushListener != null) {
+ //for the "transient" case: might have been nullified.
+ return flushListener;
+ }
FlushEventListener[] flushEventListeners = eventSource.getListeners().getFlushEventListeners();
for (FlushEventListener listener : flushEventListeners) {
- if ( listener.getClass().equals( IndexWorkFlushEventListener.class ) ) {
- return (IndexWorkFlushEventListener) listener;
+ if ( listener.getClass().equals( FullTextIndexEventListener.class ) ) {
+ return (FullTextIndexEventListener) listener;
}
}
- log.debug( "No IndexWorkFlushEventListener was registered" );
+ log.debug( "No FullTextIndexEventListener was registered" );
return null;
}
@@ -81,7 +90,7 @@
//This is because we want to behave as "inTransaction" if the flushListener is registered.
public boolean isTransactionInProgress() {
// either it is a real transaction, or if we are capable to manage this in the IndexWorkFlushEventListener
- return isRealTransactionInProgress() || flushListener != null;
+ return getIndexWorkFlushEventListener() != null || isRealTransactionInProgress();
}
private boolean isRealTransactionInProgress() {
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/TransactionalWorker.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2009-04-11 04:54:37 UTC (rev 16305)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2009-04-13 15:26:20 UTC (rev 16306)
@@ -30,8 +30,8 @@
private static final Logger log = LoggerFactory.make();
- //FIXME: discuss the next line! it looks like there actually is concurrent access
- //not a synchronized map since for a given transaction, we have not concurrent access
+ //this is being used from different threads, but doesn't need a
+ //synchronized map since for a given transaction, we have not concurrent access
protected final WeakIdentityHashMap<Object, Synchronization> synchronizationPerTransaction = new WeakIdentityHashMap<Object, Synchronization>();
private QueueingProcessor queueingProcessor;
Modified: search/trunk/src/main/java/org/hibernate/search/event/EventListenerRegister.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/event/EventListenerRegister.java 2009-04-11 04:54:37 UTC (rev 16305)
+++ search/trunk/src/main/java/org/hibernate/search/event/EventListenerRegister.java 2009-04-13 15:26:20 UTC (rev 16306)
@@ -6,6 +6,7 @@
import org.slf4j.Logger;
import org.hibernate.event.EventListeners;
+import org.hibernate.event.FlushEventListener;
import org.hibernate.event.PostCollectionRecreateEventListener;
import org.hibernate.event.PostCollectionRemoveEventListener;
import org.hibernate.event.PostCollectionUpdateEventListener;
@@ -15,7 +16,6 @@
import org.hibernate.search.Environment;
import org.hibernate.search.util.LoggerFactory;
-
/**
* Helper methods initializing Hibernate Search event listeners.
*
@@ -94,13 +94,14 @@
new PostCollectionUpdateEventListener[] { searchListener }
)
);
- // Adding IndexWorkFlushEventListener to manage events out-of-transaction
- if ( ! isFlushEventListenerRegistered( listeners.getFlushEventListeners() ) ) {
- listeners.setFlushEventListeners( appendToArray(
- listeners.getFlushEventListeners(),
- new IndexWorkFlushEventListener()
- ) );
- }
+ // Adding also as FlushEventListener to manage events out-of-transaction
+ listeners.setFlushEventListeners(
+ addIfNeeded(
+ listeners.getFlushEventListeners(),
+ searchListener,
+ new FlushEventListener[] { searchListener }
+ )
+ );
}
/**
@@ -166,18 +167,4 @@
return false;
}
- /**
- * Verifies if an IndexWorkFlushEventListener is contained in the array of listeners.
- * @param listeners
- * @return true if it found in the listeners, false otherwise.
- */
- private static boolean isFlushEventListenerRegistered(Object[] listeners) {
- for ( Object eventListener : listeners ) {
- if ( IndexWorkFlushEventListener.class == eventListener.getClass() ) {
- return true;
- }
- }
- return false;
- }
-
}
Modified: search/trunk/src/main/java/org/hibernate/search/event/FullTextIndexEventListener.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/event/FullTextIndexEventListener.java 2009-04-11 04:54:37 UTC (rev 16305)
+++ search/trunk/src/main/java/org/hibernate/search/event/FullTextIndexEventListener.java 2009-04-13 15:26:20 UTC (rev 16306)
@@ -1,15 +1,27 @@
//$Id$
package org.hibernate.search.event;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Field;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+
import org.slf4j.Logger;
+import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.EntityEntry;
import org.hibernate.event.AbstractCollectionEvent;
import org.hibernate.event.AbstractEvent;
import org.hibernate.event.Destructible;
+import org.hibernate.event.EventSource;
+import org.hibernate.event.FlushEvent;
+import org.hibernate.event.FlushEventListener;
import org.hibernate.event.Initializable;
import org.hibernate.event.PostCollectionRecreateEvent;
import org.hibernate.event.PostCollectionRecreateEventListener;
@@ -36,20 +48,29 @@
* @author Gavin King
* @author Emmanuel Bernard
* @author Mattias Arbin
+ * @author Sanne Grinovero
*/
-//TODO work on sharing the same indexWriters and readers across a single post operation...
//TODO implement and use a LockableDirectoryProvider that wraps a DP to handle the lock inside the LDP
//TODO make this class final as soon as FullTextIndexCollectionEventListener is removed.
@SuppressWarnings( "serial" )
public class FullTextIndexEventListener implements PostDeleteEventListener,
PostInsertEventListener, PostUpdateEventListener,
PostCollectionRecreateEventListener, PostCollectionRemoveEventListener,
- PostCollectionUpdateEventListener, Initializable, Destructible {
+ PostCollectionUpdateEventListener, FlushEventListener, Initializable, Destructible {
private static final Logger log = LoggerFactory.make();
protected boolean used;
protected SearchFactoryImplementor searchFactoryImplementor;
+
+ //only used by the FullTextIndexEventListener instance playing in the FlushEventListener role.
+ // transient because it's not serializable (and state doesn't need to live longer than a flush).
+ // final because it's initialization should be published to other threads.
+ // T.Local because different threads could be flushing on this listener, still the reference
+ // to session should be weak so that sessions which had errors on flush can be discarded.
+ // ! update the readObject() method in case of name changes !
+ // It's not static as we couldn't properly cleanup otherwise.
+ private transient final ThreadLocal<FlushContextContainer> flushSynch = new ThreadLocal<FlushContextContainer>();
/**
* Initialize method called by Hibernate Core when the SessionFactory starts
@@ -157,4 +178,70 @@
}
return id;
}
+
+ /**
+ * Make sure the indexes are updated right after the hibernate flush,
+ * avoiding object loading during a flush. Not needed during transactions.
+ */
+ public void onFlush(FlushEvent event) {
+ if ( used ) {
+ Session session = event.getSession();
+ FlushContextContainer flushContextContainer = this.flushSynch.get();
+ if ( flushContextContainer != null ) {
+ //first cleanup the ThreadLocal
+ this.flushSynch.set( null );
+ EventSource registeringEventSource = flushContextContainer.eventSource.get();
+ //check that we are still in the same session which registered the flushSync:
+ if ( registeringEventSource != null && registeringEventSource == session ) {
+ log.debug( "flush event causing index update out of transaction" );
+ Synchronization synchronization = flushContextContainer.synchronization;
+ synchronization.beforeCompletion();
+ synchronization.afterCompletion( Status.STATUS_COMMITTED );
+ }
+ }
+ }
+ }
+
+ public void addSynchronization(EventSource eventSource, Synchronization synchronization) {
+ //no need to check for "unused" state, as this method is used by Search itself only.
+ FlushContextContainer flushContext = new FlushContextContainer(eventSource, synchronization);
+ //ignoring previously set data: if there was something, it's coming from a previous thread
+ //which had some error when flushing and couldn't cleanup.
+ this.flushSynch.set( flushContext );
+ }
+
+ /* Might want to implement AutoFlushEventListener in future?
+ public void onAutoFlush(AutoFlushEvent event) throws HibernateException {
+ // Currently not needed as auto-flush is not happening
+ // when out of transaction.
+ }
+ */
+
+ private static class FlushContextContainer {
+
+ private final WeakReference<EventSource> eventSource;
+ private final Synchronization synchronization;
+
+ public FlushContextContainer(EventSource eventSource, Synchronization synchronization) {
+ this.eventSource = new WeakReference<EventSource>( eventSource );
+ this.synchronization = synchronization;
+ }
+
+ }
+
+ private void writeObject(ObjectOutputStream os) throws IOException {
+ os.defaultWriteObject();
+ }
+
+ //needs to implement custom readObject to restore the transient fields
+ private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
+ is.defaultReadObject();
+ Class<FullTextIndexEventListener> cl = FullTextIndexEventListener.class;
+ Field f = cl.getDeclaredField("flushSynch");
+ f.setAccessible( true );
+ ThreadLocal<FlushContextContainer> flushSynch = new ThreadLocal<FlushContextContainer>();
+ // setting a final field by reflection during a readObject is considered as safe as in a constructor:
+ f.set( this, flushSynch );
+ }
+
}
Deleted: search/trunk/src/main/java/org/hibernate/search/event/IndexWorkFlushEventListener.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/event/IndexWorkFlushEventListener.java 2009-04-11 04:54:37 UTC (rev 16305)
+++ search/trunk/src/main/java/org/hibernate/search/event/IndexWorkFlushEventListener.java 2009-04-13 15:26:20 UTC (rev 16306)
@@ -1,61 +0,0 @@
-// $Id$
-package org.hibernate.search.event;
-
-import java.io.Serializable;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.transaction.Status;
-import javax.transaction.Synchronization;
-
-import org.hibernate.AssertionFailure;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.event.EventSource;
-import org.hibernate.event.FlushEvent;
-import org.hibernate.event.FlushEventListener;
-import org.hibernate.search.util.LoggerFactory;
-import org.slf4j.Logger;
-
-/**
- * FlushEventListener to make sure the indexes are updated right after the hibernate flush,
- * avoiding object loading during a flush. Not needed during transactions.
- *
- * @author Sanne Grinovero
- */
-public final class IndexWorkFlushEventListener implements FlushEventListener, Serializable {
-
- private static final Logger log = LoggerFactory.make();
-
- private final ConcurrentHashMap<Session, Synchronization> synchronizationPerTransaction
- = new ConcurrentHashMap<Session, Synchronization>();
-
- public IndexWorkFlushEventListener() {
- }
-
- public void onFlush(FlushEvent event) throws HibernateException {
- Session session = event.getSession();
- Synchronization synchronization = synchronizationPerTransaction.get( session );
- if ( synchronization != null ) {
- log.debug( "flush event causing index update out of transaction" );
- synchronizationPerTransaction.remove( session );
- synchronization.beforeCompletion();
- synchronization.afterCompletion( Status.STATUS_COMMITTED );
- }
- }
-
- public void addSynchronization(EventSource eventSource, Synchronization synchronization) {
- Synchronization previousSync = synchronizationPerTransaction.put( eventSource, synchronization );
- if ( previousSync != null ) {
- throw new AssertionFailure( "previous registered sync not discarded in IndexWorkFlushEventListener" );
- }
- }
-
- /*
- * Might want to implement AutoFlushEventListener in future?
- public void onAutoFlush(AutoFlushEvent event) throws HibernateException {
- // Currently not needed as auto-flush is not happening
- // when out of transaction.
- }
- */
-
-}
Modified: search/trunk/src/test/java/org/hibernate/search/test/TestCase.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/TestCase.java 2009-04-11 04:54:37 UTC (rev 16305)
+++ search/trunk/src/test/java/org/hibernate/search/test/TestCase.java 2009-04-13 15:26:20 UTC (rev 16306)
@@ -15,7 +15,7 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.event.FlushEventListener;
import org.hibernate.event.def.DefaultFlushEventListener;
-import org.hibernate.search.event.IndexWorkFlushEventListener;
+import org.hibernate.search.event.FullTextIndexEventListener;
/**
* A modified base class for tests without annotations.
@@ -154,7 +154,7 @@
cfg.setListener( "post-collection-remove", "org.hibernate.search.event.FullTextIndexEventListener" );
cfg.setListener( "post-collection-update", "org.hibernate.search.event.FullTextIndexEventListener" );
- cfg.setListeners( "flush", new FlushEventListener[]{new DefaultFlushEventListener(), new IndexWorkFlushEventListener()} );
+ cfg.setListeners( "flush", new FlushEventListener[]{new DefaultFlushEventListener(), new FullTextIndexEventListener()} );
cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
cfg.setProperty( org.hibernate.search.Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
Added: search/trunk/src/test/java/org/hibernate/search/test/engine/EventListenerSerializationTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/engine/EventListenerSerializationTest.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/engine/EventListenerSerializationTest.java 2009-04-13 15:26:20 UTC (rev 16306)
@@ -0,0 +1,26 @@
+package org.hibernate.search.test.engine;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.hibernate.search.event.FullTextIndexEventListener;
+import org.hibernate.search.test.SerializationTestHelper;
+
+/**
+ * Tests that the FullTextIndexEventListener is Serializable
+ *
+ * @author Sanne Grinovero
+ */
+public class EventListenerSerializationTest extends TestCase {
+
+ public void testEventListenerSerializable() throws IOException, ClassNotFoundException {
+ FullTextIndexEventListener eventListener = new FullTextIndexEventListener();
+ eventListener.addSynchronization( null, null );
+ Object secondListener = SerializationTestHelper
+ .duplicateBySerialization(eventListener);
+ assertNotNull(secondListener);
+ assertFalse(secondListener == eventListener);
+ }
+
+}
15 years, 7 months
Hibernate SVN: r16305 - core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/ejb3.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-04-11 00:54:37 -0400 (Sat, 11 Apr 2009)
New Revision: 16305
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/ejb3/Ejb3XmlTest.java
Log:
ANN-817 : 8-bit characters in string values cause unit test failures
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/ejb3/Ejb3XmlTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/ejb3/Ejb3XmlTest.java 2009-04-11 04:43:19 UTC (rev 16304)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/ejb3/Ejb3XmlTest.java 2009-04-11 04:54:37 UTC (rev 16305)
@@ -45,7 +45,7 @@
s.getTransaction().begin();
Lighter l = new Lighter();
l.name = "Blue";
- l.power = "400�F";
+ l.power = "400F";
s.persist( l );
s.flush();
s.getTransaction().rollback();
15 years, 7 months
Hibernate SVN: r16304 - core/trunk/annotations/src/test/java/org/hibernate/test/annotations/inheritance/singletable.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-04-11 00:43:19 -0400 (Sat, 11 Apr 2009)
New Revision: 16304
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/inheritance/singletable/Music.java
Log:
ANN-818 - @DiscriminatorFormula for an integer column with default discriminator type causes failure for DB2/Sybase
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/inheritance/singletable/Music.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/inheritance/singletable/Music.java 2009-04-11 04:42:16 UTC (rev 16303)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/inheritance/singletable/Music.java 2009-04-11 04:43:19 UTC (rev 16304)
@@ -3,6 +3,8 @@
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@@ -14,6 +16,7 @@
* @author Emmanuel Bernard
*/
@Entity
+(a)DiscriminatorColumn(discriminatorType=DiscriminatorType.INTEGER)
@DiscriminatorFormula("case when zik_type is null then 0 else zik_type end")
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"avgBeat", "starred"} ))
public abstract class Music {
15 years, 7 months
Hibernate SVN: r16303 - annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/inheritance/singletable.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-04-11 00:42:16 -0400 (Sat, 11 Apr 2009)
New Revision: 16303
Modified:
annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/inheritance/singletable/Music.java
Log:
JBPAPP-1879 ANN-818 - @DiscriminatorFormula for an integer column with default discriminator type causes failure for DB2/Sybase
Modified: annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/inheritance/singletable/Music.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/inheritance/singletable/Music.java 2009-04-11 04:41:19 UTC (rev 16302)
+++ annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/inheritance/singletable/Music.java 2009-04-11 04:42:16 UTC (rev 16303)
@@ -3,6 +3,8 @@
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@@ -14,6 +16,7 @@
* @author Emmanuel Bernard
*/
@Entity
+(a)DiscriminatorColumn(discriminatorType=DiscriminatorType.INTEGER)
@DiscriminatorFormula("case when zik_type is null then 0 else zik_type end")
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"avgBeat", "starred"} ))
public abstract class Music {
15 years, 7 months
Hibernate SVN: r16302 - annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/inheritance/singletable.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-04-11 00:41:19 -0400 (Sat, 11 Apr 2009)
New Revision: 16302
Modified:
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/inheritance/singletable/Music.java
Log:
JBPAPP-1879 ANN-818 - @DiscriminatorFormula for an integer column with default discriminator type causes failure for DB2/Sybase
Modified: annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/inheritance/singletable/Music.java
===================================================================
--- annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/inheritance/singletable/Music.java 2009-04-10 23:26:04 UTC (rev 16301)
+++ annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/inheritance/singletable/Music.java 2009-04-11 04:41:19 UTC (rev 16302)
@@ -3,6 +3,8 @@
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@@ -14,6 +16,7 @@
* @author Emmanuel Bernard
*/
@Entity
+(a)DiscriminatorColumn(discriminatorType=DiscriminatorType.INTEGER)
@DiscriminatorFormula("case when zik_type is null then 0 else zik_type end")
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"avgBeat", "starred"} ))
public abstract class Music {
15 years, 7 months