Title: [502] trunk/activerecord-jdbc: Improve limit performance of Derby, by using Statement.setMaxRows.
Revision
502
Author
olabini
Date
2007-04-25 14:23:00 -0400 (Wed, 25 Apr 2007)

Log Message

Improve limit performance of Derby, by using Statement.setMaxRows.

Modified Paths


Diff

Modified: trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb (501 => 502)


--- trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb	2007-04-25 17:14:07 UTC (rev 501)
+++ trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb	2007-04-25 18:23:00 UTC (rev 502)
@@ -85,10 +85,12 @@
           @offset ||= 0
           if [EMAIL PROTECTED] || @limit == -1
             range = @offset..-1
+            max = 0
           else
             range = @offset...(@[EMAIL PROTECTED])
+            max = @[EMAIL PROTECTED]
           end
-          @connection.execute_query(sql)[range]
+          @connection.execute_query(sql,max)[range]
         else
           @connection.execute_update(sql)
         end

Modified: trunk/activerecord-jdbc/src/java/JdbcAdapterInternalService.java (501 => 502)


--- trunk/activerecord-jdbc/src/java/JdbcAdapterInternalService.java	2007-04-25 17:14:07 UTC (rev 501)
+++ trunk/activerecord-jdbc/src/java/JdbcAdapterInternalService.java	2007-04-25 18:23:00 UTC (rev 502)
@@ -70,7 +70,7 @@
         cJdbcConn.defineMethod("unmarshal_result",cf.getSingletonMethod("unmarshal_result", IRubyObject.class));
         cJdbcConn.defineFastMethod("set_connection",cf.getFastSingletonMethod("set_connection", IRubyObject.class));
         cJdbcConn.defineFastMethod("execute_update",cf.getFastSingletonMethod("execute_update", IRubyObject.class));
-        cJdbcConn.defineFastMethod("execute_query",cf.getFastSingletonMethod("execute_query", IRubyObject.class)); 
+        cJdbcConn.defineFastMethod("execute_query",cf.getFastOptSingletonMethod("execute_query")); 
         cJdbcConn.defineFastMethod("execute_insert",cf.getFastSingletonMethod("execute_insert", IRubyObject.class));
         cJdbcConn.defineFastMethod("ps",cf.getFastSingletonMethod("prepareStatement", IRubyObject.class));
         cJdbcConn.defineFastMethod("primary_keys",cf.getFastSingletonMethod("primary_keys", IRubyObject.class));
@@ -337,12 +337,18 @@
         }
     }
 
-    public static IRubyObject execute_query(IRubyObject recv, IRubyObject sql) throws SQLException, IOException {
+    public static IRubyObject execute_query(IRubyObject recv, IRubyObject[] args) throws SQLException, IOException {
+        IRubyObject sql = args[0];
+        int maxrows = 0;
+        if(args.length > 1) {
+            maxrows = RubyNumeric.fix2int(args[1]);
+        }
         while(true) {
             Connection c = (Connection)recv.dataGetStruct();
             Statement stmt = null;
             try {
                 stmt = c.createStatement();
+                stmt.setMaxRows(0);
                 return unmarshal_result(recv, stmt.executeQuery(sql.toString()));
             } catch(SQLException e) {
                 if(c.isClosed()) {
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to