[hibernate-commits] Hibernate SVN: r20206 - search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Aug 20 07:01:35 EDT 2010


Author: hardy.ferentschik
Date: 2010-08-20 07:01:35 -0400 (Fri, 20 Aug 2010)
New Revision: 20206

Removed:
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ObjectLoader.java
Modified:
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java
Log:
HSEARCH-278 Made sure that ProjectionLoader does not skew object loading times

Deleted: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ObjectLoader.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ObjectLoader.java	2010-08-20 11:01:03 UTC (rev 20205)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ObjectLoader.java	2010-08-20 11:01:35 UTC (rev 20206)
@@ -1,93 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- *  Copyright (c) 2010, 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.engine;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.slf4j.Logger;
-
-import org.hibernate.Session;
-import org.hibernate.search.util.HibernateHelper;
-import org.hibernate.search.util.LoggerFactory;
-
-/**
- * @author Emmanuel Bernard
- */
-public class ObjectLoader extends AbstractLoader {
-	private static final Logger log = LoggerFactory.make();
-	private Session session;
-
-	public void init(Session session, SearchFactoryImplementor searchFactoryImplementor) {
-		super.init( session, searchFactoryImplementor );
-		this.session = session;
-	}
-
-	public final Object executeLoad(EntityInfo entityInfo) {
-		return ObjectLoaderHelper.load( entityInfo, session );
-	}
-
-	public final List executeLoad(EntityInfo... entityInfos) {
-		if ( entityInfos.length == 0 ) {
-			return Collections.EMPTY_LIST;
-		}
-		if ( entityInfos.length == 1 ) {
-			final Object entity = load( entityInfos[0] );
-			if ( entity == null ) {
-				return Collections.EMPTY_LIST;
-			}
-			else {
-				final List<Object> list = new ArrayList<Object>( 1 );
-				list.add( entity );
-				return list;
-			}
-		}
-		//use load to benefit from the batch-size
-		//we don't face proxy casting issues since the exact class is extracted from the index
-		for ( EntityInfo entityInfo : entityInfos ) {
-			session.load( entityInfo.clazz, entityInfo.id );
-		}
-		List result = new ArrayList( entityInfos.length );
-		for ( EntityInfo entityInfo : entityInfos ) {
-			try {
-				Object entity = session.load( entityInfo.clazz, entityInfo.id );
-				HibernateHelper.initialize( entity );
-				result.add( entity );
-			}
-			catch ( RuntimeException e ) {
-				if ( LoaderHelper.isObjectNotFoundException( e ) ) {
-					log.debug(
-							"Object found in Search index but not in database: {} with id {}",
-							entityInfo.clazz, entityInfo.id
-					);
-				}
-				else {
-					throw e;
-				}
-			}
-		}
-		return result;
-	}
-}

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java	2010-08-20 11:01:03 UTC (rev 20205)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/ProjectionLoader.java	2010-08-20 11:01:35 UTC (rev 20206)
@@ -1,26 +1,25 @@
-/* $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
+ *
+ *  Copyright (c) 2010, 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.engine;
 
@@ -32,7 +31,7 @@
 import org.hibernate.transform.ResultTransformer;
 
 /**
- * Implementation of the <code>Loader</code> interface used for loading entities which are projected via
+ * Implementation of the {@code Loader} interface used for loading entities which are projected via
  * {@link org.hibernate.search.ProjectionConstants#THIS}.
  *
  * @author Emmanuel Bernard
@@ -41,7 +40,7 @@
 public class ProjectionLoader implements Loader {
 	private SearchFactoryImplementor searchFactoryImplementor;
 	private Session session;
-	private Loader objectLoader;
+	private MultiClassesQueryLoader objectLoader;
 	private Boolean projectThis;
 	private ResultTransformer transformer;
 	private String[] aliases;
@@ -101,7 +100,8 @@
 			for ( EntityInfo entityInfo : entityInfos ) {
 				for ( int index : entityInfo.indexesOfThis ) {
 					// set one by one to avoid loosing null objects (skipped in the objectLoader.load( EntityInfo[] ))
-					entityInfo.projection[index] = objectLoader.load( entityInfo );
+					// use objectLoader.executeLoad to prevent measuring load time again (see AbstractLoader)
+					entityInfo.projection[index] = objectLoader.executeLoad( entityInfo );
 				}
 			}
 		}



More information about the hibernate-commits mailing list