[hibernate-commits] Hibernate SVN: r11376 - trunk/HibernateExt/shards/src/java/org/hibernate/shards/query.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Mar 29 18:10:03 EDT 2007


Author: maulik
Date: 2007-03-29 18:10:03 -0400 (Thu, 29 Mar 2007)
New Revision: 11376

Modified:
   trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ExitOperationsQueryCollector.java
   trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ShardedQueryImpl.java
Log:
fixes bugs regard setMaxResults and setFirstResult on ShardedQueryImpl

Modified: trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ExitOperationsQueryCollector.java
===================================================================
--- trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ExitOperationsQueryCollector.java	2007-03-29 19:36:33 UTC (rev 11375)
+++ trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ExitOperationsQueryCollector.java	2007-03-29 22:10:03 UTC (rev 11376)
@@ -1,5 +1,5 @@
 /**
- * Copyright (C) 2007 Google Inc.
+ * Copyright (C) 2006 Google Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,6 +19,8 @@
 package org.hibernate.shards.query;
 
 import org.hibernate.shards.strategy.exit.ExitOperationsCollector;
+import org.hibernate.shards.strategy.exit.FirstResultExitOperation;
+import org.hibernate.shards.strategy.exit.MaxResultsExitOperation;
 
 import org.hibernate.engine.SessionFactoryImplementor;
 
@@ -29,15 +31,44 @@
  * is to record a set of aggregation type operations to be executed on the
  * combined results for a query executed on each shard.
  *
+ * We do implement setMaxResults and setFirstResult as these operations do not
+ * require parsing the query string.
+ *
+ * {@inheritDoc}
+ *
  * @author maulik at google.com (Maulik Shah)
  */
 public class ExitOperationsQueryCollector implements ExitOperationsCollector {
 
+  // maximum number of results requested by the client
+  private Integer maxResults = null;
+
+  // index of the first result requested by the client
+  private Integer firstResult = null;
+
   public List<Object> apply(List<Object> result) {
+    if (firstResult != null) {
+      result = new FirstResultExitOperation(firstResult).apply(result);
+    }
+    if (maxResults != null) {
+      result = new MaxResultsExitOperation(maxResults).apply(result);
+    }
+
     return result;
   }
 
   public void setSessionFactory(SessionFactoryImplementor sessionFactoryImplementor) {
     throw new UnsupportedOperationException();
   }
+
+  public ExitOperationsCollector setMaxResults(int maxResults) {
+    this.maxResults = maxResults;
+    return this;
+  }
+
+  public ExitOperationsCollector setFirstResult(int firstResult) {
+    this.firstResult = firstResult;
+    return this;
+  }
+
 }

Modified: trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ShardedQueryImpl.java
===================================================================
--- trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ShardedQueryImpl.java	2007-03-29 19:36:33 UTC (rev 11375)
+++ trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ShardedQueryImpl.java	2007-03-29 22:10:03 UTC (rev 11376)
@@ -261,27 +261,12 @@
   }
 
   public Query setMaxResults(int maxResults) {
-    SetMaxResultsEvent event = new SetMaxResultsEvent(maxResults);
-    for (Shard shard : shards) {
-      if (shard.getQueryById(queryId) != null) {
-        shard.getQueryById(queryId).setMaxResults(maxResults);
-      } else {
-        shard.addQueryEvent(queryId, event);
-      }
-    }
-
+    queryCollector.setMaxResults(maxResults);
     return this;
   }
 
   public Query setFirstResult(int firstResult) {
-    QueryEvent event = new SetFirstResultEvent(firstResult);
-    for (Shard shard : shards) {
-      if (shard.getQueryById(queryId) != null) {
-        shard.getQueryById(queryId).setFirstResult(firstResult);
-      } else {
-        shard.addQueryEvent(queryId, event);
-      }
-    }
+    queryCollector.setFirstResult(firstResult);
     return this;
   }
 




More information about the hibernate-commits mailing list