Author: epbernard
Date: 2008-06-29 04:18:20 -0400 (Sun, 29 Jun 2008)
New Revision: 14819
Modified:
search/trunk/src/java/org/hibernate/search/engine/MultiClassesQueryLoader.java
search/trunk/src/java/org/hibernate/search/engine/ObjectLoader.java
Log:
Minor optimization: use simple object loading when the List of EntityInfo is of size one
Modified: search/trunk/src/java/org/hibernate/search/engine/MultiClassesQueryLoader.java
===================================================================
---
search/trunk/src/java/org/hibernate/search/engine/MultiClassesQueryLoader.java 2008-06-28
10:51:13 UTC (rev 14818)
+++
search/trunk/src/java/org/hibernate/search/engine/MultiClassesQueryLoader.java 2008-06-29
08:18:20 UTC (rev 14819)
@@ -58,6 +58,18 @@
public List load(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;
+ }
+ }
+
//split EntityInfo per root entity
Map<RootEntityMetadata, List<EntityInfo>> entityinfoBuckets =
new HashMap<RootEntityMetadata, List<EntityInfo>>(
entityMatadata.size());
Modified: search/trunk/src/java/org/hibernate/search/engine/ObjectLoader.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/ObjectLoader.java 2008-06-28
10:51:13 UTC (rev 14818)
+++ search/trunk/src/java/org/hibernate/search/engine/ObjectLoader.java 2008-06-29
08:18:20 UTC (rev 14819)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Collections;
import org.hibernate.Hibernate;
import org.hibernate.Session;
@@ -25,6 +26,18 @@
}
public List load(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) {
Show replies by date