You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2013/12/11 17:47:35 UTC

svn commit: r1550185 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLDocumentStore.java

Author: reschke
Date: Wed Dec 11 16:47:34 2013
New Revision: 1550185

URL: http://svn.apache.org/r1550185
Log:
OAK-1266 - work in progress SQL/JDBC DocumentStore implementation - add support for "limit"

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLDocumentStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLDocumentStore.java?rev=1550185&r1=1550184&r2=1550185&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLDocumentStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/sqlpersistence/SQLDocumentStore.java Wed Dec 11 16:47:34 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.plugins.sqlpersistence;
 
-import java.io.File;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
@@ -89,7 +88,7 @@ public class SQLDocumentStore implements
 
     @Override
     public <T extends Document> List<T> query(Collection<T> collection, String fromKey, String toKey, int limit) {
-        return query(collection, fromKey, toKey, null, 0, 0);
+        return query(collection, fromKey, toKey, null, 0, limit);
     }
 
     @Override
@@ -238,7 +237,7 @@ public class SQLDocumentStore implements
             throw new RuntimeException("indexed property " + indexedProperty + " not supported");
         }
         try {
-            List<String> dbresult = dbQuery(connection, tableName, fromKey, toKey, indexedProperty, startValue);
+            List<String> dbresult = dbQuery(connection, tableName, fromKey, toKey, indexedProperty, startValue, limit);
             for (String data : dbresult) {
                 T doc = fromString(collection, data);
                 doc.seal();
@@ -357,18 +356,25 @@ public class SQLDocumentStore implements
     }
 
     private List<String> dbQuery(Connection connection, String tableName, String minId, String maxId, String indexedProperty,
-            long startValue) throws SQLException {
+            long startValue, int limit) throws SQLException {
         String t = "select DATA from " + tableName + " where ID > ? and ID < ?";
         if (indexedProperty != null) {
             t += " and MODIFIED >= ?";
         }
+        if (limit != Integer.MAX_VALUE) {
+            t += " limit ?";
+        }
         PreparedStatement stmt = connection.prepareStatement(t);
         List<String> result = new ArrayList<String>();
         try {
-            stmt.setString(1, minId);
-            stmt.setString(2, maxId);
+            int si = 1;
+            stmt.setString(si++, minId);
+            stmt.setString(si++, maxId);
             if (indexedProperty != null) {
-                stmt.setLong(3, startValue);
+                stmt.setLong(si++, startValue);
+            }
+            if (limit != Integer.MAX_VALUE) {
+                stmt.setInt(si++, limit);
             }
             ResultSet rs = stmt.executeQuery();
             while (rs.next()) {