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/10/17 15:35:22 UTC
svn commit: r1632572 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb:
RDBDocumentStore.java RDBRow.java
Author: reschke
Date: Fri Oct 17 13:35:22 2014
New Revision: 1632572
URL: http://svn.apache.org/r1632572
Log:
OAK-1941 - refactoring
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.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=1632572&r1=1632571&r2=1632572&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 Fri Oct 17 13:35:22 2014
@@ -725,9 +725,9 @@ public class RDBDocumentStore implements
}
try {
connection = getConnection();
- List<DBRow> dbresult = dbQuery(connection, tableName, fromKey, toKey, indexedProperty, startValue, limit);
- for (DBRow r : dbresult) {
- T doc = fromDBRow(collection, r);
+ List<RDBRow> dbresult = dbQuery(connection, tableName, fromKey, toKey, indexedProperty, startValue, limit);
+ for (RDBRow r : dbresult) {
+ T doc = fromRow(collection, r);
doc.seal();
result.add(doc);
addToCacheIfNotNewer(collection, doc);
@@ -753,20 +753,21 @@ public class RDBDocumentStore implements
}
}
- private <T extends Document> T fromDBRow(Collection<T> collection, DBRow row) throws ParseException {
+ private <T extends Document> T fromRow(Collection<T> collection, RDBRow row) throws ParseException {
T doc = collection.newDocument(this);
- doc.put(ID, row.id);
- doc.put(MODIFIED, row.modified);
- doc.put(MODCOUNT, row.modcount);
+ doc.put(ID, row.getId());
+ doc.put(MODIFIED, row.getModified());
+ doc.put(MODCOUNT, row.getModcount());
JSONParser jp = new JSONParser();
Map<String, Object> baseData = null;
- if (row.bdata != null && row.bdata.length != 0) {
- baseData = (Map<String, Object>) jp.parse(fromBlobData(row.bdata));
+ byte[] bdata = row.getBdata();
+ if (bdata != null && bdata.length != 0) {
+ baseData = (Map<String, Object>) jp.parse(fromBlobData(bdata));
}
// TODO figure out a faster way
- JSONArray arr = (JSONArray) new JSONParser().parse("[" + row.data + "]");
+ JSONArray arr = (JSONArray) new JSONParser().parse("[" + row.getData() + "]");
int updatesStartAt = 0;
if (baseData == null) {
@@ -882,8 +883,8 @@ public class RDBDocumentStore implements
String tableName = getTable(collection);
try {
connection = getConnection();
- DBRow row = dbRead(connection, tableName, id);
- return row != null ? fromDBRow(collection, row) : null;
+ RDBRow row = dbRead(connection, tableName, id);
+ return row != null ? fromRow(collection, row) : null;
} catch (Exception ex) {
throw new DocumentStoreException(ex);
} finally {
@@ -1141,7 +1142,7 @@ public class RDBDocumentStore implements
}
@CheckForNull
- private DBRow dbRead(Connection connection, String tableName, String id) throws SQLException {
+ private RDBRow dbRead(Connection connection, String tableName, String id) throws SQLException {
PreparedStatement stmt = connection.prepareStatement("select MODIFIED, MODCOUNT, DATA, BDATA from " + tableName + " where ID = ?");
try {
stmt.setString(1, id);
@@ -1151,7 +1152,7 @@ public class RDBDocumentStore implements
long modcount = rs.getLong(2);
String data = rs.getString(3);
byte[] bdata = rs.getBytes(4);
- return new DBRow(id, modified, modcount, data, bdata);
+ return new RDBRow(id, modified, modcount, data, bdata);
} else {
return null;
}
@@ -1170,7 +1171,7 @@ public class RDBDocumentStore implements
}
}
- private List<DBRow> dbQuery(Connection connection, String tableName, String minId, String maxId, String indexedProperty,
+ private List<RDBRow> dbQuery(Connection connection, String tableName, String minId, String maxId, String indexedProperty,
long startValue, int limit) throws SQLException {
String t = "select ID, MODIFIED, MODCOUNT, DATA, BDATA from " + tableName + " where ID > ? and ID < ?";
if (indexedProperty != null) {
@@ -1186,7 +1187,7 @@ public class RDBDocumentStore implements
}
t += " order by ID";
PreparedStatement stmt = connection.prepareStatement(t);
- List<DBRow> result = new ArrayList<DBRow>();
+ List<RDBRow> result = new ArrayList<RDBRow>();
try {
int si = 1;
stmt.setString(si++, minId);
@@ -1207,7 +1208,7 @@ public class RDBDocumentStore implements
long modcount = rs.getLong(3);
String data = rs.getString(4);
byte[] bdata = rs.getBytes(5);
- result.add(new DBRow(id, modified, modcount, data, bdata));
+ result.add(new RDBRow(id, modified, modcount, data, bdata));
}
} finally {
stmt.close();
@@ -1547,20 +1548,6 @@ public class RDBDocumentStore implements
return false;
}
- private static class DBRow {
- public final String id, data;
- public final long modified, modcount;
- public final byte[] bdata;
-
- public DBRow(String id, long modified, long modcount, String data, byte[] bdata) {
- this.id = id;
- this.modified = modified;
- this.modcount = modcount;
- this.data = data;
- this.bdata = bdata;
- }
- }
-
// custom serializer
private static String asString(@Nonnull Document doc) {
StringBuilder sb = new StringBuilder(32768);
Added: 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=1632572&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java Fri Oct 17 13:35:22 2014
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document.rdb;
+
+/**
+ * Container for the information in a RDB database column.
+ */
+public class RDBRow {
+
+ private final String id, data;
+ private final long modified, modcount;
+ private final byte[] bdata;
+
+ public RDBRow(String id, long modified, long modcount, String data, byte[] bdata) {
+ this.id = id;
+ this.modified = modified;
+ this.modcount = modcount;
+ this.data = data;
+ this.bdata = bdata;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public long getModified() {
+ return modified;
+ }
+
+ public long getModcount() {
+ return modcount;
+ }
+
+ public byte[] getBdata() {
+ return bdata;
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java
------------------------------------------------------------------------------
svn:eol-style = native