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 2014/11/03 16:37:17 UTC

svn commit: r1636375 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb: RDBDocumentStore.java RDBRow.java

Author: reschke
Date: Mon Nov  3 15:37:16 2014
New Revision: 1636375

URL: http://svn.apache.org/r1636375
Log:
OAK-1941 - when fetching documents for which a previous version is in the cache: avoid fetching the JSON data when the modcount did not change

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1636375&r1=1636374&r2=1636375&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java Mon Nov  3 15:37:16 2014
@@ -345,6 +345,9 @@ public class RDBDocumentStore implements
     // for DBs that prefer "limit" over "fetch first"
     private boolean needsLimit = false;
 
+    // for DBs that do not support CASE in SELECT (currently all)
+    private boolean allowsCaseInSelect = true;
+
     // set of supported indexed properties
     private static Set<String> INDEXEDPROPERTIES = new HashSet<String>(Arrays.asList(new String[] { MODIFIED,
             NodeDocument.HAS_BINARY_FLAG }));
@@ -761,7 +764,7 @@ public class RDBDocumentStore implements
                 lastmodcount = cachedDoc.getModCount().longValue();
             }
             connection = getConnection();
-            RDBRow row = dbRead(connection, tableName, id);
+            RDBRow row = dbRead(connection, tableName, id, lastmodcount);
             if (row == null) {
                 return null;
             }
@@ -968,12 +971,29 @@ public class RDBDocumentStore implements
     }
 
     @CheckForNull
-    private RDBRow dbRead(Connection connection, String tableName, String id) throws SQLException {
+    private RDBRow dbRead(Connection connection, String tableName, String id, long lastmodcount) throws SQLException {
         PreparedStatement stmt;
-        stmt = connection.prepareStatement("select MODIFIED, MODCOUNT, DATA, BDATA from " + tableName + " where ID = ?");
+        boolean useCaseStatement = lastmodcount != -1 && allowsCaseInSelect;
+        if (useCaseStatement) {
+            // either we don't have a previous version of the document
+            // or the database does not support CASE in SELECT
+            stmt = connection.prepareStatement("select MODIFIED, MODCOUNT, DATA, BDATA from " + tableName + " where ID = ?");
+        } else {
+            // the case statement causes the actual row data not to be
+            // sent in case we already have it
+            stmt = connection.prepareStatement("select MODIFIED, MODCOUNT, case MODCOUNT when ? then null else DATA end as DATA, "
+                    + "case MODCOUNT when ? then null else BDATA end as BDATA from " + tableName + " where ID = ?");
+        }
 
         try {
-            stmt.setString(1, id);
+            if (useCaseStatement) {
+                stmt.setString(1, id);
+            }
+            else {
+                stmt.setLong(1, lastmodcount);
+                stmt.setLong(2, lastmodcount);
+                stmt.setString(3, id);
+            }
             ResultSet rs = stmt.executeQuery();
             if (rs.next()) {
                 long modified = rs.getLong(1);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java?rev=1636375&r1=1636374&r2=1636375&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java Mon Nov  3 15:37:16 2014
@@ -16,8 +16,15 @@
  */
 package org.apache.jackrabbit.oak.plugins.document.rdb;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
 /**
  * Container for the information in a RDB database column.
+ * <p>
+ * Note that the String "data" and the byte[] "bdata" may be null
+ * when the SQL SELECT request was conditional on "modcount" being
+ * unchanged.
  */
 public class RDBRow {
 
@@ -33,22 +40,27 @@ public class RDBRow {
         this.bdata = bdata;
     }
 
+    @Nonnull
     public String getId() {
         return id;
     }
 
+    @CheckForNull
     public String getData() {
         return data;
     }
 
+    @Nonnull
     public long getModified() {
         return modified;
     }
 
+    @Nonnull
     public long getModcount() {
         return modcount;
     }
 
+    @CheckForNull
     public byte[] getBdata() {
         return bdata;
     }