Hibernate SVN: r19168 - core/trunk/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-04-05 09:37:52 -0400 (Mon, 05 Apr 2010)
New Revision: 19168
Modified:
core/trunk/core/src/main/java/org/hibernate/dialect/IngresDialect.java
Log:
HHH-5003 IngresDialect requires query substitutions for boolean values
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/IngresDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/IngresDialect.java 2010-04-05 13:29:17 UTC (rev 19167)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/IngresDialect.java 2010-04-05 13:37:52 UTC (rev 19168)
@@ -155,6 +155,10 @@
// rows, a single row with one column, or a single row with two columns.
// Ingres JDBC Driver returns table and object keys as BINARY values.
getDefaultProperties().setProperty(Environment.USE_GET_GENERATED_KEYS, "false");
+ // There is no support for a native boolean type that accepts values
+ // of true, false or unknown. Using the tinyint type requires
+ // substitions of true and false.
+ getDefaultProperties().setProperty(Environment.QUERY_SUBSTITUTIONS, "true=1,false=0");
}
/**
14 years
Hibernate SVN: r19167 - core/trunk/testsuite/src/test/java/org/hibernate/test/hql.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-04-05 09:29:17 -0400 (Mon, 05 Apr 2010)
New Revision: 19167
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
HHH-4976 Ingres 9.3 does not support sub-selects in the select list.
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-04-05 13:27:47 UTC (rev 19166)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-04-05 13:29:17 UTC (rev 19167)
@@ -1605,6 +1605,10 @@
}
public void testImplicitPolymorphism() {
+ if(getDialect() instanceof IngresDialect){
+ //HHH-4976 Ingres 9.3 does not support sub-selects in the select list.
+ return;
+ }
Session s = openSession();
Transaction t = s.beginTransaction();
14 years
Hibernate SVN: r19166 - core/trunk/testsuite/src/test/java/org/hibernate/test/hql.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-04-05 09:27:47 -0400 (Mon, 05 Apr 2010)
New Revision: 19166
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
HHH-4977 Ingres 9.3 does not support sub-selects in the select list.
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-04-05 13:24:54 UTC (rev 19165)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-04-05 13:27:47 UTC (rev 19166)
@@ -1710,6 +1710,11 @@
}
public void testOneToManyFilter() throws Throwable {
+ if ( getDialect() instanceof IngresDialect ) {
+ // HHH-4977 Ingres 9.3 does not support sub-selects in the select
+ // list.
+ return;
+ }
Session session = openSession();
Transaction txn = session.beginTransaction();
14 years
Hibernate SVN: r19165 - core/trunk/testsuite/src/test/java/org/hibernate/test/hql.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-04-05 09:24:54 -0400 (Mon, 05 Apr 2010)
New Revision: 19165
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
HHH-4961 HHH-4970 HHH-4973 skip some tests that ingres does not support this syntax
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-04-04 16:31:41 UTC (rev 19164)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-04-05 13:24:54 UTC (rev 19165)
@@ -27,6 +27,7 @@
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.HSQLDialect;
+import org.hibernate.dialect.IngresDialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.Oracle8iDialect;
import org.hibernate.dialect.PostgreSQLDialect;
@@ -237,6 +238,10 @@
}
public void testPaginationWithPolymorphicQuery() {
+ if ( getDialect() instanceof IngresDialect ) {
+ // HHH-4961 Ingres does not support this scoping in 9.3.
+ return;
+ }
Session s = openSession();
s.beginTransaction();
Human h = new Human();
@@ -704,6 +709,11 @@
}
public void testComponentParameterBinding() {
+ if ( getDialect() instanceof IngresDialect ) {
+ // HHH-4970 Subselects are not supported within select target lists
+ // in Ingres
+ return;
+ }
// HHH-1774 : parameters are bound incorrectly with component parameters...
Session s = openSession();
s.beginTransaction();
@@ -1107,6 +1117,11 @@
}
public void testSelectClauseSubselect() {
+ if ( getDialect() instanceof IngresDialect ) {
+ // HHH-4973 Ingres 9.3 does not support sub-selects in the select
+ // list.
+ return;
+ }
Session s = openSession();
Transaction t = s.beginTransaction();
Zoo zoo = new Zoo();
14 years
Hibernate SVN: r19164 - in search/trunk/hibernate-search/src: main/java/org/hibernate/search/backend/impl/lucene and 6 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2010-04-04 12:31:41 -0400 (Sun, 04 Apr 2010)
New Revision: 19164
Added:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/
search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/ErrorContext.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/ErrorHandler.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/
search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/ErrorContextBuilder.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/ErrorContextImpl.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/LogErrorHandler.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/RethrowErrorHandler.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/LuceneErrorHandlingTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/MockErrorHandler.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/RethrowErrorHandlingTest.java
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/Environment.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessor.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/QueueProcessors.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/SearchFactoryImplementor.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
Log:
HSEARCH-421 Exceptions happening in backend are unnoticed
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/Environment.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/Environment.java 2010-04-03 20:56:15 UTC (rev 19163)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/Environment.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -115,5 +115,13 @@
*
*/
public static final String MODEL_MAPPING = "hibernate.search.model_mapping";
+
+ /**
+ * Set to a fully qualified classname of a type implementing org.hibernate.search.exception.ErrorHandler
+ * to override the error strategy used during processing of the Lucene updates.
+ * Default is to log errors.
+ */
+ public static final String ERROR_HANDLER = "hibernate.search.error_handler";
+
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessor.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessor.java 2010-04-03 20:56:15 UTC (rev 19163)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessor.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -34,6 +34,8 @@
import org.hibernate.search.store.IndexShardingStrategy;
import org.hibernate.search.util.LoggerFactory;
import org.slf4j.Logger;
+import org.hibernate.search.exception.ErrorHandler;
+import org.hibernate.search.exception.impl.ErrorContextBuilder;
/**
* Apply the operations to Lucene directories.
@@ -49,6 +51,7 @@
private final SearchFactoryImplementor searchFactoryImplementor;
private final Map<DirectoryProvider,PerDPResources> resourcesMap;
private final boolean sync;
+ private final ErrorHandler errorHandler;
private static final DpSelectionVisitor providerSelectionVisitor = new DpSelectionVisitor();
private static final Logger log = LoggerFactory.make();
@@ -61,6 +64,7 @@
this.queue = queue;
this.searchFactoryImplementor = searchFactoryImplementor;
this.resourcesMap = resourcesMap;
+ this.errorHandler = searchFactoryImplementor.getErrorHandler();
}
public void run() {
@@ -75,8 +79,11 @@
}
//this Runnable splits tasks in more runnables and then runs them:
processors.runAll( sync );
- } catch (InterruptedException e) {
- log.error( "Index update task has been interrupted", e );
+ } catch ( Exception e ) {
+ log.error( "Error in backend", e );
+ ErrorContextBuilder builder = new ErrorContextBuilder();
+ builder.errorThatOccurred( e );
+ errorHandler.handle( builder.createErrorContext() );
}
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java 2010-04-03 20:56:15 UTC (rev 19163)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -34,12 +34,19 @@
import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.backend.Workspace;
import org.hibernate.search.backend.impl.lucene.works.LuceneWorkVisitor;
+import org.hibernate.search.exception.ErrorHandler;
+import org.hibernate.search.exception.impl.ErrorContextBuilder;
import org.hibernate.search.util.LoggerFactory;
/**
* A Runnable containing a unit of changes to be applied to a specific index.
* After creation, use addWork(LuceneWork) to fill the changes queue and then
* run it to apply all changes. After run() this object should be discarded.
+ *
+ * A new PerDPQueueProcessor is created for each unit of work, expensive
+ * resources to be shared across multiple transactions should be created once
+ * in PerDPResources.
+ *
* @see Runnable
* @see #addWork(LuceneWork)
* @author Sanne Grinovero
@@ -47,11 +54,13 @@
class PerDPQueueProcessor implements Runnable {
private static final Logger log = LoggerFactory.make();
+
private final Workspace workspace;
private final LuceneWorkVisitor worker;
private final ExecutorService executor;
private final boolean exclusiveIndexUsage;
private final List<LuceneWork> workOnWriter = new ArrayList<LuceneWork>();
+ private final ErrorHandler handler;
// if any work needs batchmode, set corresponding flag to true:
private boolean batchmode = false;
@@ -65,6 +74,7 @@
this.workspace = resources.getWorkspace();
this.executor = resources.getExecutor();
this.exclusiveIndexUsage = resources.isExclusiveIndexUsageEnabled();
+ this.handler = resources.getErrorHandler();
}
/**
@@ -87,11 +97,14 @@
return;
}
log.debug( "Opening an IndexWriter for update" );
+ ErrorContextBuilder builder = new ErrorContextBuilder();
+ builder.allWorkToBeDone( workOnWriter );
try {
IndexWriter indexWriter = workspace.getIndexWriter( batchmode );
try {
for ( LuceneWork lw : workOnWriter ) {
lw.getWorkDelegate( worker ).performWork( lw, indexWriter );
+ builder.workCompleted( lw );
}
workspace.commitIndexWriter();
performOptimizations();
@@ -100,10 +113,11 @@
if ( ! exclusiveIndexUsage ) workspace.closeIndexWriter();
}
}
- catch (Throwable tw) {
+ catch ( Throwable tw ) {
//needs to be attempted even for out of memory errors, therefore we catch Throwable
log.error( "Unexpected error in Lucene Backend: ", tw );
try {
+ handler.handle( builder.errorThatOccurred( tw ).createErrorContext() );
workspace.closeIndexWriter();
}
finally {
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java 2010-04-03 20:56:15 UTC (rev 19163)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -28,6 +28,7 @@
import org.hibernate.search.backend.impl.lucene.works.LuceneWorkVisitor;
import org.hibernate.search.batchindexing.Executors;
import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.exception.ErrorHandler;
import org.hibernate.search.store.DirectoryProvider;
import java.util.concurrent.ExecutorService;
@@ -44,12 +45,14 @@
private final LuceneWorkVisitor visitor;
private final Workspace workspace;
private final boolean exclusiveIndexUsage;
+ private final ErrorHandler errorHandler;
PerDPResources(SearchFactoryImplementor searchFactoryImp, DirectoryProvider<?> dp) {
workspace = new Workspace( searchFactoryImp, dp );
visitor = new LuceneWorkVisitor( workspace );
executor = Executors.newFixedThreadPool( 1, "Directory writer" );
exclusiveIndexUsage = searchFactoryImp.isExclusiveIndexUsageEnabled( dp );
+ errorHandler = searchFactoryImp.getErrorHandler();
}
public ExecutorService getExecutor() {
@@ -75,5 +78,9 @@
}
executor.shutdown();
}
+
+ public ErrorHandler getErrorHandler() {
+ return errorHandler;
+ }
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/QueueProcessors.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/QueueProcessors.java 2010-04-03 20:56:15 UTC (rev 19163)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/QueueProcessors.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -34,6 +34,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
+import org.hibernate.search.SearchException;
import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.store.DirectoryProvider;
@@ -102,16 +103,21 @@
}
// and then wait for all tasks to be finished:
for ( Future<Object> f : futures ) {
- if ( !f.isDone() ) {
- try {
- f.get();
- } catch(CancellationException ignore) {
- //ignored, as in java.util.concurrent.AbstractExecutorService.invokeAll(Collection<Callable<T>> tasks)
- } catch(ExecutionException ignore) {
- //ignored, as in java.util.concurrent.AbstractExecutorService.invokeAll(Collection<Callable<T>> tasks)
- }
- }
- }
+ if ( !f.isDone() ) {
+ try {
+ f.get();
+ }
+ catch (CancellationException ignore) {
+ // ignored, as in java.util.concurrent.AbstractExecutorService.invokeAll(Collection<Callable<T>>
+ // tasks)
+ }
+ catch (ExecutionException error) {
+ // rethrow cause to serviced thread - this could hide more exception:
+ Throwable cause = error.getCause();
+ throw new SearchException( cause );
+ }
+ }
+ }
}
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/SearchFactoryImplementor.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/SearchFactoryImplementor.java 2010-04-03 20:56:15 UTC (rev 19163)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/SearchFactoryImplementor.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -38,6 +38,7 @@
import org.hibernate.search.filter.FilterCachingStrategy;
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.store.optimization.OptimizerStrategy;
+import org.hibernate.search.exception.ErrorHandler;
/**
* Interface which gives access to the different directory providers and their configuration.
@@ -93,4 +94,7 @@
Similarity getSimilarity(DirectoryProvider<?> directoryProvider);
boolean isExclusiveIndexUsageEnabled(DirectoryProvider<?> provider);
+
+ ErrorHandler getErrorHandler();
+
}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/ErrorContext.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/ErrorContext.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/ErrorContext.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -0,0 +1,45 @@
+/* $Id: SearchFactoryImplementor.java 19002 2010-03-16 01:28:07Z hardy.ferentschik $
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.exception;
+
+import java.util.List;
+
+import org.hibernate.search.backend.LuceneWork;
+
+/**
+ * @author Amin Mohammed-Coleman
+ * @since 3.2
+ */
+public interface ErrorContext {
+
+ List<LuceneWork> getFailingOperations();
+
+ LuceneWork getOperationAtFault();
+
+ Throwable getThrowable();
+
+ boolean hasErrors();
+
+}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/ErrorHandler.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/ErrorHandler.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/ErrorHandler.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -0,0 +1,35 @@
+/* $Id: SearchFactoryImplementor.java 19002 2010-03-16 01:28:07Z hardy.ferentschik $
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.exception;
+
+/**
+ * @author Amin Mohammed-Coleman
+ * @since 3.2
+ */
+public interface ErrorHandler {
+
+ void handle( ErrorContext context );
+
+}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/ErrorContextBuilder.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/ErrorContextBuilder.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/ErrorContextBuilder.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -0,0 +1,86 @@
+/* $Id: SearchFactoryImplementor.java 19002 2010-03-16 01:28:07Z hardy.ferentschik $
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.exception.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.search.backend.LuceneWork;
+import org.hibernate.search.exception.ErrorContext;
+
+/**
+ * @author Amin Mohammed-Coleman
+ * @since 3.2
+ */
+public class ErrorContextBuilder {
+
+ private Throwable th;
+ private List<LuceneWork> workToBeDone;
+ private List<LuceneWork> failingOperations = new ArrayList<LuceneWork>();
+ private List<LuceneWork> operationsThatWorked = new ArrayList<LuceneWork>();
+
+ public ErrorContextBuilder errorThatOccurred(Throwable th) {
+ this.th = th;
+ return this;
+ }
+
+ public ErrorContextBuilder addAllWorkThatFailed(List<LuceneWork> worksThatFailed) {
+ this.failingOperations.addAll( worksThatFailed );
+ return this;
+ }
+
+ public ErrorContextBuilder workCompleted(LuceneWork luceneWork) {
+ this.operationsThatWorked.add( luceneWork );
+ return this;
+
+ }
+
+ public ErrorContextBuilder allWorkToBeDone(List<LuceneWork> workOnWriter) {
+ this.workToBeDone = new ArrayList<LuceneWork>( workOnWriter );
+ return this;
+ }
+
+ public ErrorContext createErrorContext() {
+ ErrorContextImpl context = new ErrorContextImpl();
+
+ context.setThrowable( th );
+
+ // for situation when there is a primary failure
+ if ( workToBeDone != null ) {
+ List<LuceneWork> workLeft = new ArrayList<LuceneWork>( workToBeDone );
+ if ( !operationsThatWorked.isEmpty() ) {
+ workLeft.removeAll( operationsThatWorked );
+ }
+
+ if ( !workLeft.isEmpty() ) {
+ context.setOperationAtFault( workLeft.remove( 0 ) );
+ failingOperations.addAll( workLeft );
+ }
+ }
+ context.setFailingOperations( failingOperations );
+ return context;
+ }
+
+}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/ErrorContextImpl.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/ErrorContextImpl.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/ErrorContextImpl.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -0,0 +1,77 @@
+/* $Id: SearchFactoryImplementor.java 19002 2010-03-16 01:28:07Z hardy.ferentschik $
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.exception.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.hibernate.search.backend.LuceneWork;
+import org.hibernate.search.exception.ErrorContext;
+
+/**
+ * @author Amin Mohammed-Coleman
+ * @since 3.2
+ */
+class ErrorContextImpl implements ErrorContext {
+
+ private List<LuceneWork> failingOperations;
+
+ private LuceneWork operationAtFault;
+
+ private Throwable throwable;
+
+ public List<LuceneWork> getFailingOperations() {
+ if ( failingOperations == null ) {
+ failingOperations = new ArrayList<LuceneWork>();
+ }
+ return Collections.unmodifiableList( failingOperations );
+ }
+
+ public LuceneWork getOperationAtFault() {
+ return this.operationAtFault;
+ }
+
+ public Throwable getThrowable() {
+ return this.throwable;
+ }
+
+ public void setFailingOperations(List<LuceneWork> failingOperations) {
+ this.failingOperations = failingOperations;
+ }
+
+ public void setThrowable(Throwable th) {
+ this.throwable = th;
+ }
+
+ public void setOperationAtFault(LuceneWork operationAtFault) {
+ this.operationAtFault = operationAtFault;
+ }
+
+ public boolean hasErrors() {
+ return failingOperations != null || failingOperations.size() > 0;
+ }
+
+}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/LogErrorHandler.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/LogErrorHandler.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/LogErrorHandler.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -0,0 +1,86 @@
+/* $Id: SearchFactoryImplementor.java 19002 2010-03-16 01:28:07Z hardy.ferentschik $
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.exception.impl;
+
+import java.util.List;
+
+import org.hibernate.search.backend.LuceneWork;
+import org.hibernate.search.exception.ErrorContext;
+import org.hibernate.search.exception.ErrorHandler;
+import org.hibernate.search.util.LoggerFactory;
+import org.slf4j.Logger;
+
+/**
+ * @author Amin Mohammed-Coleman
+ * @author Sanne Grinovero
+ * @since 3.2
+ */
+public class LogErrorHandler implements ErrorHandler {
+
+ private static final Logger log = LoggerFactory.make();
+
+ public void handle(ErrorContext context) {
+
+ final List<LuceneWork> failingOperations = context.getFailingOperations();
+ final LuceneWork primaryFailure = context.getOperationAtFault();
+ final Throwable exceptionThatOccurred = context.getThrowable();
+
+ final StringBuilder errorMsg = new StringBuilder();
+
+ if ( exceptionThatOccurred != null ) {
+ errorMsg.append( "Exception occurred " )
+ .append( exceptionThatOccurred )
+ .append( "\n" );
+ }
+ if ( primaryFailure != null ) {
+ errorMsg.append( "Primary Failure:\n" );
+ appendFailureMessage( errorMsg, primaryFailure );
+ }
+
+ if ( ! failingOperations.isEmpty() ) {
+ errorMsg.append( "Subsequent failures:\n" );
+ for ( LuceneWork workThatFailed : failingOperations ) {
+ appendFailureMessage( errorMsg, workThatFailed );
+ }
+ }
+
+ logError( errorMsg.toString(), exceptionThatOccurred );
+ }
+
+ public static final void appendFailureMessage(StringBuilder message, LuceneWork workThatFailed) {
+ message.append( "\tEntity " )
+ .append( workThatFailed.getEntityClass().getName() )
+ .append( " " )
+ .append( " Id " ).append( workThatFailed.getIdInString() )
+ .append( " " ).append( " Work Type " )
+ .append( " " ).append( workThatFailed.getClass().getName() )
+ .append( "\n" );
+ }
+
+ protected void logError(String errorMsg, Throwable exceptionThatOccurred) {
+ log.error( errorMsg, exceptionThatOccurred );
+ }
+
+}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/RethrowErrorHandler.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/RethrowErrorHandler.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/RethrowErrorHandler.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -0,0 +1,45 @@
+/* $Id$
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.exception.impl;
+
+import org.hibernate.search.SearchException;
+import org.hibernate.search.exception.ErrorHandler;
+
+/**
+ * This ErrorHandler will throw the exceptions it caught,
+ * appending some context to the exception message.
+ *
+ * @author Sanne Grinovero
+ * @since 3.2
+ */
+public class RethrowErrorHandler extends LogErrorHandler implements ErrorHandler {
+
+ @Override
+ protected void logError(String errorMsg, Throwable exceptionThatOccurred) {
+ throw new SearchException( errorMsg, exceptionThatOccurred );
+ }
+
+}
+
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2010-04-03 20:56:15 UTC (rev 19163)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -64,6 +64,7 @@
import org.hibernate.search.backend.WorkerFactory;
import org.hibernate.search.backend.configuration.ConfigurationParseHelper;
import org.hibernate.search.backend.configuration.MaskedProperty;
+import org.hibernate.search.backend.impl.BatchedQueueingProcessor;
import org.hibernate.search.backend.impl.batchlucene.BatchBackend;
import org.hibernate.search.backend.impl.batchlucene.LuceneBatchBackend;
import org.hibernate.search.batchindexing.MassIndexerProgressMonitor;
@@ -89,6 +90,9 @@
import org.hibernate.search.util.PluginLoader;
import org.hibernate.util.StringHelper;
import org.slf4j.Logger;
+import org.hibernate.search.exception.ErrorHandler;
+import org.hibernate.search.exception.impl.LogErrorHandler;
+import org.hibernate.search.exception.impl.RethrowErrorHandler;
/**
* @author Emmanuel Bernard
@@ -114,6 +118,7 @@
private final AtomicBoolean stopped = new AtomicBoolean( false );
private final int cacheBitResultsSize;
private final Properties configurationProperties;
+ private final ErrorHandler errorHandler;
private final PolymorphicIndexHierarchy indexHierarchy = new PolymorphicIndexHierarchy();
@@ -148,6 +153,8 @@
}
public SearchFactoryImpl(SearchConfiguration cfg) {
+ this.configurationProperties = cfg.getProperties();
+ this.errorHandler = createErrorHandler( configurationProperties );
ReflectionManager reflectionManager = getReflectionManager(cfg);
final SearchMapping mapping = SearchMappingBuilder.getSearchMapping(cfg);
if ( mapping != null) {
@@ -179,12 +186,9 @@
this.cacheBitResultsSize = ConfigurationParseHelper.getIntValue(
cfg.getProperties(), Environment.CACHE_DOCIDRESULTS_SIZE, CachingWrapperFilter.DEFAULT_SIZE
);
- this.configurationProperties = cfg.getProperties();
this.barrier = 1; //write barrier
}
-
-
private void fillSimilarityMapping() {
for ( DirectoryProviderData directoryConfiguration : dirProviderData.values() ) {
for (Class<?> indexedType : directoryConfiguration.classes) {
@@ -689,4 +693,43 @@
return dirProviderData.get( provider ).exclusiveIndexUsage;
}
+ /**
+ * @param configuration
+ * @return the configured ErrorHandler
+ * @since 3.2
+ */
+ private static ErrorHandler createErrorHandler(Properties configuration) {
+ boolean sync = BatchedQueueingProcessor.isConfiguredAsSync( configuration );
+ String errorHandlerClassName = configuration.getProperty( Environment.ERROR_HANDLER );
+ if ( StringHelper.isEmpty( errorHandlerClassName ) ) {
+ // default error handler depends on sync/async:
+ if ( sync ) {
+ return new RethrowErrorHandler();
+ }
+ else {
+ return new LogErrorHandler();
+ }
+ }
+ else if ( errorHandlerClassName.trim().equals( "log" ) ) {
+ return new LogErrorHandler();
+ }
+ else if ( errorHandlerClassName.trim().equals( "rethrow" ) ) {
+ if ( ! sync ) {
+ // RethrowErrorHandler won't work when backend is async:
+ throw new SearchException( "The \"rethrow\" ErrorHandler is not compatible with aync backend" );
+ }
+ else {
+ return new RethrowErrorHandler();
+ }
+ }
+ else {
+ return PluginLoader.instanceFromName( ErrorHandler.class, errorHandlerClassName,
+ SearchFactoryImpl.class, "Error Handler" );
+ }
+ }
+
+ public ErrorHandler getErrorHandler() {
+ return errorHandler;
+ }
+
}
Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/LuceneErrorHandlingTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/LuceneErrorHandlingTest.java (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/LuceneErrorHandlingTest.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -0,0 +1,205 @@
+/* $Id$
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.test.errorhandling;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import junit.framework.Assert;
+
+import org.apache.lucene.index.IndexWriter;
+import org.hibernate.search.Environment;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.SearchException;
+import org.hibernate.search.SearchFactory;
+import org.hibernate.search.backend.BackendQueueProcessorFactory;
+import org.hibernate.search.backend.DeleteLuceneWork;
+import org.hibernate.search.backend.LuceneWork;
+import org.hibernate.search.backend.WorkVisitor;
+import org.hibernate.search.backend.impl.lucene.DpSelectionVisitor;
+import org.hibernate.search.backend.impl.lucene.works.LuceneWorkDelegate;
+import org.hibernate.search.batchindexing.MassIndexerProgressMonitor;
+import org.hibernate.search.exception.ErrorHandler;
+import org.hibernate.search.exception.impl.LogErrorHandler;
+import org.hibernate.search.impl.SearchFactoryImpl;
+import org.hibernate.search.test.Document;
+import org.hibernate.search.test.SearchTestCase;
+
+/**
+ * Test to verify the configured ErrorHandler is used in the Lucene
+ * backend, and the backend exceptions are logged as expected.
+ *
+ * @see Environment#ERROR_HANDLER
+ *
+ * @author Sanne Grinovero
+ * @since 3.2
+ */
+public class LuceneErrorHandlingTest extends SearchTestCase {
+
+ static final AtomicInteger workcounter = new AtomicInteger();
+
+ public void testErrorHandling() {
+ SearchFactoryImpl searchFactoryImpl = getSearchFactoryImpl();
+ ErrorHandler errorHandler = searchFactoryImpl.getErrorHandler();
+ Assert.assertTrue( errorHandler instanceof MockErrorHandler );
+ MockErrorHandler mockErrorHandler = (MockErrorHandler)errorHandler;
+ BackendQueueProcessorFactory queueProcessorFactory = searchFactoryImpl.getBackendQueueProcessorFactory();
+ List<LuceneWork> queue = new ArrayList<LuceneWork>();
+ queue.add( new HarmlessWork( "firstWork" ) );
+ queue.add( new HarmlessWork( "secondWork" ) );
+ Runnable processor = queueProcessorFactory.getProcessor( queue );
+ workcounter.set( 0 ); // reset work counter
+ processor.run();
+ Assert.assertEquals( 2, workcounter.get() );
+
+ workcounter.set( 0 ); // reset work counter
+ final FailingWork firstFailure = new FailingWork("firstFailure");
+ queue.add(firstFailure);
+ final HarmlessWork thirdWork = new HarmlessWork("thirdWork");
+ queue.add(thirdWork);
+ final HarmlessWork fourthWork = new HarmlessWork("fourthWork");
+ queue.add(fourthWork);
+ processor = queueProcessorFactory.getProcessor( queue );
+ processor.run();
+ Assert.assertEquals( 2, workcounter.get() );
+ String errorMessage = mockErrorHandler.getErrorMessage();
+ Throwable exception = mockErrorHandler.getLastException();
+
+ StringBuilder expectedErrorMessage = new StringBuilder();
+ expectedErrorMessage.append( "Exception occurred " ).append ( exception ).append ("\n");
+ expectedErrorMessage.append( "Primary Failure:\n");
+ LogErrorHandler.appendFailureMessage(expectedErrorMessage, firstFailure);
+
+ expectedErrorMessage.append( "Subsequent failures:\n" );
+ LogErrorHandler.appendFailureMessage(expectedErrorMessage, thirdWork );
+ LogErrorHandler.appendFailureMessage(expectedErrorMessage, fourthWork );
+
+ // should verify the errorHandler logs the work which was not processed (third and fourth)
+ // and which work was failing
+ Assert.assertEquals( expectedErrorMessage.toString() , errorMessage );
+ Assert.assertTrue( exception instanceof SearchException );
+ Assert.assertEquals( "failed work message", exception.getMessage() );
+ }
+
+ protected Class<?>[] getMappings() {
+ return new Class[] { Document.class };
+ }
+
+ protected void configure(org.hibernate.cfg.Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( Environment.ERROR_HANDLER, MockErrorHandler.class.getName() );
+ }
+
+ protected SearchFactoryImpl getSearchFactoryImpl() {
+ FullTextSession s = Search.getFullTextSession( openSession() );
+ s.close();
+ SearchFactory searchFactory = s.getSearchFactory();
+ return (SearchFactoryImpl) searchFactory;
+ }
+
+ /**
+ * A LuceneWork which doesn't fail and delegates to a NoOp
+ * operation on the index.
+ */
+ static class HarmlessWork extends DeleteLuceneWork {
+
+ public HarmlessWork(String workIdentifier) {
+ super( workIdentifier, workIdentifier, Document.class );
+ }
+
+ @Override
+ public <T> T getWorkDelegate(WorkVisitor<T> visitor) {
+ if ( visitor instanceof DpSelectionVisitor ) {
+ //during shard-selection visitor this work is applied to
+ //all DirectoryProviders as this extends DeleteLuceneWork
+ return visitor.getDelegate( this );
+ }
+ else {
+ return (T) new NoOpLuceneWorkDelegate();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "HarmlessWork: " + this.getIdInString();
+ }
+
+ }
+
+ static class NoOpLuceneWorkDelegate implements LuceneWorkDelegate {
+
+ public void logWorkDone(LuceneWork work, MassIndexerProgressMonitor monitor) {
+ }
+
+ public void performWork(LuceneWork work, IndexWriter writer) {
+ workcounter.incrementAndGet();
+ }
+
+ }
+
+ /**
+ * A LuceneWork which will throw a SearchException when applied to
+ * the index, which is the type thrown to wrap real IOExceptions.
+ */
+ static class FailingWork extends DeleteLuceneWork {
+
+ public FailingWork(String workIdentifier) {
+ super( workIdentifier, workIdentifier, Document.class );
+ }
+
+ @Override
+ public <T> T getWorkDelegate(WorkVisitor<T> visitor) {
+ if ( visitor instanceof DpSelectionVisitor ) {
+ //during shard-selection visitor this work is applied to
+ //all DirectoryProviders as this extends DeleteLuceneWork
+ return visitor.getDelegate( this );
+ }
+ else {
+ return (T) new FailingLuceneWorkDelegate();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "FailingWork: " + this.getIdInString();
+ }
+
+ }
+
+ static class FailingLuceneWorkDelegate implements LuceneWorkDelegate {
+
+ public void logWorkDone(LuceneWork work, MassIndexerProgressMonitor monitor) {
+ }
+
+ public void performWork(LuceneWork work, IndexWriter writer) {
+ throw new SearchException( "failed work message" );
+ }
+
+ }
+
+}
+
Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/MockErrorHandler.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/MockErrorHandler.java (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/MockErrorHandler.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -0,0 +1,57 @@
+/* $Id$
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.test.errorhandling;
+
+import org.hibernate.search.exception.impl.LogErrorHandler;
+
+/**
+ * This is a LogErrorHandler used for testing only,
+ * NOT to be used as a template or example for a real
+ * error handler.
+ *
+ * @author Sanne Grinovero
+ * @since 3.2
+ */
+public class MockErrorHandler extends LogErrorHandler {
+
+ private volatile String errorMessage;
+ private volatile Throwable lastException;
+
+ @Override
+ protected void logError(String errorMsg, Throwable exceptionThatOccurred) {
+ errorMessage = errorMsg;
+ lastException = exceptionThatOccurred;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public Throwable getLastException() {
+ return lastException;
+ }
+
+}
+
Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/RethrowErrorHandlingTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/RethrowErrorHandlingTest.java (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/RethrowErrorHandlingTest.java 2010-04-04 16:31:41 UTC (rev 19164)
@@ -0,0 +1,82 @@
+/* $Id$
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.test.errorhandling;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.hibernate.search.Environment;
+import org.hibernate.search.SearchException;
+import org.hibernate.search.backend.BackendQueueProcessorFactory;
+import org.hibernate.search.backend.LuceneWork;
+import org.hibernate.search.exception.ErrorHandler;
+import org.hibernate.search.exception.impl.RethrowErrorHandler;
+import org.hibernate.search.impl.SearchFactoryImpl;
+
+/**
+ * Verifies the RethrowErrorHandler is able to propagate exceptions back to the
+ * committing thread.
+ *
+ * @author Sanne Grinovero
+ */
+public class RethrowErrorHandlingTest extends LuceneErrorHandlingTest {
+
+ @Override
+ public void testErrorHandling(){
+ SearchFactoryImpl searchFactoryImpl = getSearchFactoryImpl();
+ ErrorHandler errorHandler = searchFactoryImpl.getErrorHandler();
+ Assert.assertTrue( errorHandler instanceof RethrowErrorHandler );
+ BackendQueueProcessorFactory queueProcessorFactory = searchFactoryImpl.getBackendQueueProcessorFactory();
+ List<LuceneWork> queue = new ArrayList<LuceneWork>();
+ queue.add( new HarmlessWork( "firstWork" ) );
+ queue.add( new HarmlessWork( "secondWork" ) );
+ Runnable processor = queueProcessorFactory.getProcessor( queue );
+ workcounter.set( 0 ); // reset work counter
+ processor.run();
+ Assert.assertEquals( 2, workcounter.get() );
+
+ workcounter.set( 0 ); // reset work counter
+ queue.add( new FailingWork( "firstFailure" ) );
+ queue.add( new HarmlessWork( "thirdWork" ) );
+ queue.add( new HarmlessWork( "fourthWork" ) );
+ processor = queueProcessorFactory.getProcessor( queue );
+ try {
+ processor.run();
+ Assert.fail( "should have thrown a SearchException" );
+ }
+ catch (SearchException se) {
+ //expected
+ }
+ }
+
+ protected void configure(org.hibernate.cfg.Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( Environment.ERROR_HANDLER, "rethrow" );
+ }
+
+}
+
14 years
Hibernate SVN: r19163 - in search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test: jpa and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2010-04-03 16:56:15 -0400 (Sat, 03 Apr 2010)
New Revision: 19163
Added:
search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/jpa/JPATestCase.java
Removed:
search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/JPATestCase.java
Log:
moving JPATestCase to correct package
Deleted: search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/JPATestCase.java
===================================================================
--- search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/JPATestCase.java 2010-04-02 17:02:49 UTC (rev 19162)
+++ search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/JPATestCase.java 2010-04-03 20:56:15 UTC (rev 19163)
@@ -1,138 +0,0 @@
-/* $Id$
- *
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
- *
- * 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.search.test.jpa;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Properties;
-import java.util.ArrayList;import java.util.Arrays;
-import java.io.InputStream;
-import java.io.IOException;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-
-import org.hibernate.cfg.Environment;
-import org.hibernate.ejb.AvailableSettings;
-import org.hibernate.ejb.HibernatePersistence;
-import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.search.test.SearchTestCase;
-import org.apache.lucene.analysis.StopAnalyzer;
-import org.apache.lucene.util.Version;
-
-/**
- * @author Emmanuel Bernard
- */
-public abstract class JPATestCase extends junit.framework.TestCase {
- protected EntityManagerFactory factory;
-
- public JPATestCase() {
- super();
- }
-
- public JPATestCase(String name) {
- super( name );
- }
-
- public void setUp() {
- factory = new HibernatePersistence().createEntityManagerFactory( getConfig() );
- }
-
- public void tearDown() {
- factory.close();
- }
-
- public abstract Class[] getAnnotatedClasses();
-
- public String[] getEjb3DD() {
- return new String[]{};
- }
-
- public Map<Class, String> getCachedClasses() {
- return new HashMap<Class, String>();
- }
-
- public Map<String, String> getCachedCollections() {
- return new HashMap<String, String>();
- }
-
- public static Properties loadProperties() {
- Properties props = new Properties();
- InputStream stream = Persistence.class.getResourceAsStream( "/hibernate.properties" );
- if ( stream != null ) {
- try {
- props.load( stream );
- }
- catch (Exception e) {
- throw new RuntimeException( "could not load hibernate.properties" );
- }
- finally {
- try {
- stream.close();
- }
- catch (IOException ioe) {
- }
- }
- }
- props.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
- return props;
- }
-
- public Map getConfig() {
- Map config = loadProperties();
- ArrayList<Class> classes = new ArrayList<Class>();
-
- classes.addAll( Arrays.asList( getAnnotatedClasses() ) );
- config.put( AvailableSettings.LOADED_CLASSES, classes );
- for ( Map.Entry<Class, String> entry : getCachedClasses().entrySet() ) {
- config.put(
- AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(),
- entry.getValue()
- );
- }
- for ( Map.Entry<String, String> entry : getCachedCollections().entrySet() ) {
- config.put(
- AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(),
- entry.getValue()
- );
- }
- if ( getEjb3DD().length > 0 ) {
- ArrayList<String> dds = new ArrayList<String>();
- dds.addAll( Arrays.asList( getEjb3DD() ) );
- config.put( AvailableSettings.XML_FILE_NAMES, dds );
- }
-
- //Search config
- config.put( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
- config.put( org.hibernate.search.Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
-
- return config;
- }
-
- public static Version getTargetLuceneVersion() {
- return SearchTestCase.getTargetLuceneVersion();
- }
-
-}
-
Copied: search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/jpa/JPATestCase.java (from rev 19156, search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/JPATestCase.java)
===================================================================
--- search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/jpa/JPATestCase.java (rev 0)
+++ search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/jpa/JPATestCase.java 2010-04-03 20:56:15 UTC (rev 19163)
@@ -0,0 +1,138 @@
+/* $Id$
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.test.jpa;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Properties;
+import java.util.ArrayList;import java.util.Arrays;
+import java.io.InputStream;
+import java.io.IOException;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+import org.hibernate.cfg.Environment;
+import org.hibernate.ejb.AvailableSettings;
+import org.hibernate.ejb.HibernatePersistence;
+import org.hibernate.search.store.RAMDirectoryProvider;
+import org.hibernate.search.test.SearchTestCase;
+import org.apache.lucene.analysis.StopAnalyzer;
+import org.apache.lucene.util.Version;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public abstract class JPATestCase extends junit.framework.TestCase {
+ protected EntityManagerFactory factory;
+
+ public JPATestCase() {
+ super();
+ }
+
+ public JPATestCase(String name) {
+ super( name );
+ }
+
+ public void setUp() {
+ factory = new HibernatePersistence().createEntityManagerFactory( getConfig() );
+ }
+
+ public void tearDown() {
+ factory.close();
+ }
+
+ public abstract Class[] getAnnotatedClasses();
+
+ public String[] getEjb3DD() {
+ return new String[]{};
+ }
+
+ public Map<Class, String> getCachedClasses() {
+ return new HashMap<Class, String>();
+ }
+
+ public Map<String, String> getCachedCollections() {
+ return new HashMap<String, String>();
+ }
+
+ public static Properties loadProperties() {
+ Properties props = new Properties();
+ InputStream stream = Persistence.class.getResourceAsStream( "/hibernate.properties" );
+ if ( stream != null ) {
+ try {
+ props.load( stream );
+ }
+ catch (Exception e) {
+ throw new RuntimeException( "could not load hibernate.properties" );
+ }
+ finally {
+ try {
+ stream.close();
+ }
+ catch (IOException ioe) {
+ }
+ }
+ }
+ props.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
+ return props;
+ }
+
+ public Map getConfig() {
+ Map config = loadProperties();
+ ArrayList<Class> classes = new ArrayList<Class>();
+
+ classes.addAll( Arrays.asList( getAnnotatedClasses() ) );
+ config.put( AvailableSettings.LOADED_CLASSES, classes );
+ for ( Map.Entry<Class, String> entry : getCachedClasses().entrySet() ) {
+ config.put(
+ AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(),
+ entry.getValue()
+ );
+ }
+ for ( Map.Entry<String, String> entry : getCachedCollections().entrySet() ) {
+ config.put(
+ AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(),
+ entry.getValue()
+ );
+ }
+ if ( getEjb3DD().length > 0 ) {
+ ArrayList<String> dds = new ArrayList<String>();
+ dds.addAll( Arrays.asList( getEjb3DD() ) );
+ config.put( AvailableSettings.XML_FILE_NAMES, dds );
+ }
+
+ //Search config
+ config.put( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
+ config.put( org.hibernate.search.Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
+
+ return config;
+ }
+
+ public static Version getTargetLuceneVersion() {
+ return SearchTestCase.getTargetLuceneVersion();
+ }
+
+}
+
14 years
Hibernate SVN: r19162 - search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-04-02 13:02:49 -0400 (Fri, 02 Apr 2010)
New Revision: 19162
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ObjectLoaderHelper.java
Log:
HSEARCH-489 remove code handling Restriction.in usage in case of composite id as Core 3.5 does it now
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java 2010-04-02 15:24:51 UTC (rev 19161)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java 2010-04-02 17:02:49 UTC (rev 19162)
@@ -132,10 +132,6 @@
*/
private boolean idProvided = false;
-
- //if composite id, use of (a, b) in ((1,2), (3,4)) fails on most database
- private boolean safeFromTupleId;
-
/**
* Creates a document builder for entities annotated with <code>@Indexed</code>.
*
@@ -169,10 +165,6 @@
throw new SearchException( "No document id in: " + clazz.getName() );
}
- //if composite id, use of (a, b) in ((1,2),(3,4)) fails on most database
- //a TwoWayString2FieldBridgeAdaptor is never a composite id
- safeFromTupleId = TwoWayString2FieldBridgeAdaptor.class.isAssignableFrom( idBridge.getClass() );
-
checkAllowFieldSelection();
if ( log.isDebugEnabled() ) {
log.debug(
@@ -567,13 +559,6 @@
return allowFieldSelectionInProjection;
}
- /**
- * @return <code>false</code> if there is a risk of composite id. If composite id, use of (a, b) in ((1,2), (3,4)) fails on most database
- */
- public boolean isSafeFromTupleId() {
- return safeFromTupleId;
- }
-
public Term getTerm(Serializable id) {
if ( idProvided ) {
return new Term( idKeywordName, ( String ) id );
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ObjectLoaderHelper.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ObjectLoaderHelper.java 2010-04-02 15:24:51 UTC (rev 19161)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ObjectLoaderHelper.java 2010-04-02 17:02:49 UTC (rev 19162)
@@ -73,31 +73,22 @@
Set<Class<?>> indexedEntities = searchFactoryImplementor.getIndexedTypesPolymorphic( new Class<?>[]{entityType} );
DocumentBuilderIndexedEntity<?> builder = searchFactoryImplementor.getDocumentBuilderIndexedEntity( indexedEntities.iterator().next() );
- //FIXME starting from Core 3.5, this loging is handled in Restrictions.in so we should remove this code.
- boolean useInClause = builder.isSafeFromTupleId();
String idName = builder.getIdentifierName();
-
Disjunction disjunction = Restrictions.disjunction();
- if (useInClause) {
- int loop = maxResults / MAX_IN_CLAUSE;
- boolean exact = maxResults % MAX_IN_CLAUSE == 0;
- if ( !exact ) loop++;
- for (int index = 0; index < loop; index++) {
- int max = index * MAX_IN_CLAUSE + MAX_IN_CLAUSE <= maxResults ?
- index * MAX_IN_CLAUSE + MAX_IN_CLAUSE :
- maxResults;
- List<Serializable> ids = new ArrayList<Serializable>( max - index * MAX_IN_CLAUSE );
- for (int entityInfoIndex = index * MAX_IN_CLAUSE; entityInfoIndex < max; entityInfoIndex++) {
- ids.add( entityInfos[entityInfoIndex].id );
- }
- disjunction.add( Restrictions.in( idName, ids ) );
+
+ int loop = maxResults / MAX_IN_CLAUSE;
+ boolean exact = maxResults % MAX_IN_CLAUSE == 0;
+ if ( !exact ) loop++;
+ for (int index = 0; index < loop; index++) {
+ int max = index * MAX_IN_CLAUSE + MAX_IN_CLAUSE <= maxResults ?
+ index * MAX_IN_CLAUSE + MAX_IN_CLAUSE :
+ maxResults;
+ List<Serializable> ids = new ArrayList<Serializable>( max - index * MAX_IN_CLAUSE );
+ for (int entityInfoIndex = index * MAX_IN_CLAUSE; entityInfoIndex < max; entityInfoIndex++) {
+ ids.add( entityInfos[entityInfoIndex].id );
}
+ disjunction.add( Restrictions.in( idName, ids ) );
}
- else {
- for (EntityInfo entityInfo : entityInfos) {
- disjunction.add( Restrictions.eq( idName, entityInfo.id ) );
- }
- }
criteria.add( disjunction );
criteria.list(); //load all objects
}
14 years
Hibernate SVN: r19161 - search/trunk/hibernate-search/src/main/java/org/hibernate/search/sandbox/standalone.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2010-04-02 11:24:51 -0400 (Fri, 02 Apr 2010)
New Revision: 19161
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/sandbox/standalone/package-info.java
Log:
fix package-info package statement
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/sandbox/standalone/package-info.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/sandbox/standalone/package-info.java 2010-04-02 14:37:20 UTC (rev 19160)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/sandbox/standalone/package-info.java 2010-04-02 15:24:51 UTC (rev 19161)
@@ -28,4 +28,4 @@
* Temptative to externalize the query functions from Hibernate Core specifics.
* This will open the doors to easier back end alternatives, including search-wise.
*/
-package org.hibernate.search.sandbox.standaloone;
\ No newline at end of file
+package org.hibernate.search.sandbox.standalone;
\ No newline at end of file
14 years
Hibernate SVN: r19160 - search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-04-02 10:37:20 -0400 (Fri, 02 Apr 2010)
New Revision: 19160
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/MultiClassesQueryLoader.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ObjectLoaderHelper.java
Log:
HSEARCH-478 generalize the use of the composite pk protection when using in restrictions
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/MultiClassesQueryLoader.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/MultiClassesQueryLoader.java 2010-04-02 12:58:46 UTC (rev 19159)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/MultiClassesQueryLoader.java 2010-04-02 14:37:20 UTC (rev 19160)
@@ -117,13 +117,9 @@
final RootEntityMetadata key = entry.getKey();
final List<EntityInfo> value = entry.getValue();
final EntityInfo[] bucketEntityInfos = value.toArray( new EntityInfo[value.size()] );
- if ( key.useObjectLoader ) {
- objectLoader.load( bucketEntityInfos );
- }
- else {
- ObjectLoaderHelper.initializeObjects( bucketEntityInfos,
- key.criteria, key.rootEntity, searchFactoryImplementor);
- }
+
+ ObjectLoaderHelper.initializeObjects( bucketEntityInfos,
+ key.criteria, key.rootEntity, searchFactoryImplementor);
}
return ObjectLoaderHelper.returnAlreadyLoadedObjectsInCorrectOrder( entityInfos, session );
}
@@ -132,7 +128,6 @@
public final Class<?> rootEntity;
public final Set<Class<?>> mappedSubclasses;
private final Criteria criteria;
- public final boolean useObjectLoader;
RootEntityMetadata(Class<?> rootEntity, SearchFactoryImplementor searchFactoryImplementor, Session session) {
this.rootEntity = rootEntity;
@@ -140,7 +135,6 @@
if ( provider == null) throw new AssertionFailure("Provider not found for class: " + rootEntity);
this.mappedSubclasses = provider.getMappedSubclasses();
this.criteria = session.createCriteria( rootEntity );
- this.useObjectLoader = !provider.isSafeFromTupleId();
}
}
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ObjectLoaderHelper.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ObjectLoaderHelper.java 2010-04-02 12:58:46 UTC (rev 19159)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ObjectLoaderHelper.java 2010-04-02 14:37:20 UTC (rev 19160)
@@ -65,28 +65,39 @@
return maybeProxy;
}
- public static void initializeObjects(EntityInfo[] entityInfos, Criteria criteria, Class<?> entityType,
+ public static void initializeObjects(EntityInfo[] entityInfos,
+ Criteria criteria, Class<?> entityType,
SearchFactoryImplementor searchFactoryImplementor) {
final int maxResults = entityInfos.length;
if ( maxResults == 0 ) return;
Set<Class<?>> indexedEntities = searchFactoryImplementor.getIndexedTypesPolymorphic( new Class<?>[]{entityType} );
DocumentBuilderIndexedEntity<?> builder = searchFactoryImplementor.getDocumentBuilderIndexedEntity( indexedEntities.iterator().next() );
+ //FIXME starting from Core 3.5, this loging is handled in Restrictions.in so we should remove this code.
+ boolean useInClause = builder.isSafeFromTupleId();
String idName = builder.getIdentifierName();
- int loop = maxResults / MAX_IN_CLAUSE;
- boolean exact = maxResults % MAX_IN_CLAUSE == 0;
- if ( !exact ) loop++;
+
Disjunction disjunction = Restrictions.disjunction();
- for (int index = 0; index < loop; index++) {
- int max = index * MAX_IN_CLAUSE + MAX_IN_CLAUSE <= maxResults ?
- index * MAX_IN_CLAUSE + MAX_IN_CLAUSE :
- maxResults;
- List<Serializable> ids = new ArrayList<Serializable>( max - index * MAX_IN_CLAUSE );
- for (int entityInfoIndex = index * MAX_IN_CLAUSE; entityInfoIndex < max; entityInfoIndex++) {
- ids.add( entityInfos[entityInfoIndex].id );
+ if (useInClause) {
+ int loop = maxResults / MAX_IN_CLAUSE;
+ boolean exact = maxResults % MAX_IN_CLAUSE == 0;
+ if ( !exact ) loop++;
+ for (int index = 0; index < loop; index++) {
+ int max = index * MAX_IN_CLAUSE + MAX_IN_CLAUSE <= maxResults ?
+ index * MAX_IN_CLAUSE + MAX_IN_CLAUSE :
+ maxResults;
+ List<Serializable> ids = new ArrayList<Serializable>( max - index * MAX_IN_CLAUSE );
+ for (int entityInfoIndex = index * MAX_IN_CLAUSE; entityInfoIndex < max; entityInfoIndex++) {
+ ids.add( entityInfos[entityInfoIndex].id );
+ }
+ disjunction.add( Restrictions.in( idName, ids ) );
}
- disjunction.add( Restrictions.in( idName, ids ) );
}
+ else {
+ for (EntityInfo entityInfo : entityInfos) {
+ disjunction.add( Restrictions.eq( idName, entityInfo.id ) );
+ }
+ }
criteria.add( disjunction );
criteria.list(); //load all objects
}
14 years
Hibernate SVN: r19159 - search/trunk.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-04-02 08:58:46 -0400 (Fri, 02 Apr 2010)
New Revision: 19159
Modified:
search/trunk/readme.txt
Log:
HSEARCH-483 add jira link
Modified: search/trunk/readme.txt
===================================================================
--- search/trunk/readme.txt 2010-04-02 12:54:17 UTC (rev 19158)
+++ search/trunk/readme.txt 2010-04-02 12:58:46 UTC (rev 19159)
@@ -31,7 +31,7 @@
Bug Reports:
- Hibernate JIRA (preferred)
+ Hibernate JIRA (preferred): http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH
hibernate-dev(a)lists.jboss.org
Free Technical Support:
14 years