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

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Nov 12 10:01:44 EST 2008


Author: hardy.ferentschik
Date: 2008-11-12 10:01:44 -0500 (Wed, 12 Nov 2008)
New Revision: 15553

Modified:
   search/trunk/src/java/org/hibernate/search/engine/Loader.java
   search/trunk/src/java/org/hibernate/search/engine/ProjectionLoader.java
Log:
HSEARCH-224
Use MultiClassesQueryLoader in ProjectionLoader

Modified: search/trunk/src/java/org/hibernate/search/engine/Loader.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/Loader.java	2008-11-12 13:05:39 UTC (rev 15552)
+++ search/trunk/src/java/org/hibernate/search/engine/Loader.java	2008-11-12 15:01:44 UTC (rev 15553)
@@ -7,10 +7,16 @@
 import org.hibernate.search.engine.EntityInfo;
 
 /**
+ * Interface defining a set of operations in order to load entities which matched a query. Depending on the type of
+ * indexed entities and the type of query different strategies can be used.
+ *
+ *
  * @author Emmanuel Bernard
  */
 public interface Loader {
 	void init(Session session, SearchFactoryImplementor searchFactoryImplementor);
+
 	Object load(EntityInfo entityInfo);
+
 	List load(EntityInfo... entityInfos);
 }

Modified: search/trunk/src/java/org/hibernate/search/engine/ProjectionLoader.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/ProjectionLoader.java	2008-11-12 13:05:39 UTC (rev 15552)
+++ search/trunk/src/java/org/hibernate/search/engine/ProjectionLoader.java	2008-11-12 15:01:44 UTC (rev 15553)
@@ -8,13 +8,16 @@
 import org.hibernate.transform.ResultTransformer;
 
 /**
+ * Implementation of the <code>Loader</code> interface used for loading entities which are projected via
+ * {@link org.hibernate.search.ProjectionConstants#THIS}.
+ *
  * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
  */
-//TODO change the underlying ObjectLoader to a MutliClassesQueryLoader
 public class ProjectionLoader implements Loader {
 	private SearchFactoryImplementor searchFactoryImplementor;
 	private Session session;
-	private ObjectLoader objectLoader;
+	private Loader objectLoader;
 	private Boolean projectThis;
 	private ResultTransformer transformer;
 	private String[] aliases;
@@ -27,13 +30,13 @@
 	public void init(Session session, SearchFactoryImplementor searchFactoryImplementor, ResultTransformer transformer, String[] aliases) {
 		init( session, searchFactoryImplementor );
 		this.transformer = transformer;
-		this.aliases =  aliases;
+		this.aliases = aliases;
 	}
 
 	public Object load(EntityInfo entityInfo) {
 		initThisProjectionFlag( entityInfo );
 		if ( projectThis ) {
-			for (int index : entityInfo.indexesOfThis) {
+			for ( int index : entityInfo.indexesOfThis ) {
 				entityInfo.projection[index] = objectLoader.load( entityInfo );
 			}
 		}
@@ -49,29 +52,32 @@
 		if ( projectThis == null ) {
 			projectThis = entityInfo.indexesOfThis.size() != 0;
 			if ( projectThis ) {
-				//TODO use QueryLoader when possible
-				objectLoader = new ObjectLoader();
-				objectLoader.init( session, searchFactoryImplementor );
+				MultiClassesQueryLoader loader = new MultiClassesQueryLoader();
+				loader.init( session, searchFactoryImplementor );
+				loader.setEntityTypes( new Class[]{} );
+				objectLoader = loader;
 			}
 		}
 	}
 
 	public List load(EntityInfo... entityInfos) {
 		List results = new ArrayList( entityInfos.length );
-		if ( entityInfos.length == 0 ) return results;
+		if ( entityInfos.length == 0 ) {
+			return results;
+		}
 
 		initThisProjectionFlag( entityInfos[0] );
 		if ( projectThis ) {
-			objectLoader.load( entityInfos ); //load by batch
-			for (EntityInfo entityInfo : entityInfos) {
-				for (int index : entityInfo.indexesOfThis) {
-					//set one by one to avoid loosing null objects (skipped in the objectLoader.load( EntityInfo[] ))
+			objectLoader.load( entityInfos ); // load by batch
+			for ( EntityInfo entityInfo : entityInfos ) {
+				for ( int index : entityInfo.indexesOfThis ) {
+					// set one by one to avoid loosing null objects (skipped in the objectLoader.load( EntityInfo[] ))
 					entityInfo.projection[index] = objectLoader.load( entityInfo );
 				}
 			}
 		}
-		for (EntityInfo entityInfo : entityInfos) {
-			if ( transformer != null) {
+		for ( EntityInfo entityInfo : entityInfos ) {
+			if ( transformer != null ) {
 				results.add( transformer.transformTuple( entityInfo.projection, aliases ) );
 			}
 			else {




More information about the hibernate-commits mailing list