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 2015/08/11 13:52:41 UTC
svn commit: r1695280 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb:
RDBBlobStore.java RDBBlobStoreDB.java RDBHelper.java
Author: reschke
Date: Tue Aug 11 11:52:41 2015
New Revision: 1695280
URL: http://svn.apache.org/r1695280
Log:
OAK-3198: RDB code cleanup: RDBBlobStore DB specific code factored out
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStoreDB.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBHelper.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java?rev=1695280&r1=1695279&r2=1695280&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java Tue Aug 11 11:52:41 2015
@@ -34,7 +34,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import javax.annotation.Nonnull;
import javax.sql.DataSource;
import org.apache.jackrabbit.oak.commons.StringUtils;
@@ -116,11 +115,8 @@ public class RDBBlobStore extends Cachin
private static final Logger LOG = LoggerFactory.getLogger(RDBBlobStore.class);
- // blob size we need to support
- private static final int MINBLOB = 2 * 1024 * 1024;
-
// ID size we need to support; is 2 * (hex) size of digest length
- private static final int IDSIZE;
+ protected static final int IDSIZE;
static {
try {
MessageDigest md = MessageDigest.getInstance(AbstractBlobStore.HASH_ALGORITHM);
@@ -131,6 +127,7 @@ public class RDBBlobStore extends Cachin
}
}
+
private Exception callStack;
protected RDBConnectionHandler ch;
@@ -140,125 +137,6 @@ public class RDBBlobStore extends Cachin
protected String tnMeta;
private Set<String> tablesToBeDropped = new HashSet<String>();
- /**
- * Defines variation in the capabilities of different RDBs.
- */
- protected enum DB {
- H2("H2") {
- @Override
- public String checkVersion(DatabaseMetaData md) throws SQLException {
- return RDBJDBCTools.versionCheck(md, 1, 4, description);
- }
- },
-
- DERBY("Apache Derby") {
- @Override
- public String checkVersion(DatabaseMetaData md) throws SQLException {
- return RDBJDBCTools.versionCheck(md, 10, 11, description);
- }
- },
-
- DB2("DB2") {
- @Override
- public String checkVersion(DatabaseMetaData md) throws SQLException {
- return RDBJDBCTools.versionCheck(md, 10, 1, description);
- }
-
- @Override
- public String getDataTableCreationStatement(String tableName) {
- return "create table " + tableName + " (ID varchar(" + IDSIZE + ") not null primary key, DATA blob(" + MINBLOB + "))";
- }
- },
-
- MSSQL("Microsoft SQL Server") {
- @Override
- public String checkVersion(DatabaseMetaData md) throws SQLException {
- return RDBJDBCTools.versionCheck(md, 11, 0, description);
- }
-
- @Override
- public String getDataTableCreationStatement(String tableName) {
- return "create table " + tableName + " (ID varchar(" + IDSIZE + ") not null primary key, DATA varbinary(max))";
- }
- },
-
- MYSQL("MySQL") {
- @Override
- public String checkVersion(DatabaseMetaData md) throws SQLException {
- return RDBJDBCTools.versionCheck(md, 5, 5, description);
- }
-
- @Override
- public String getDataTableCreationStatement(String tableName) {
- return "create table " + tableName + " (ID varchar(" + IDSIZE + ") not null primary key, DATA mediumblob)";
- }
- },
-
- ORACLE("Oracle") {
- @Override
- public String checkVersion(DatabaseMetaData md) throws SQLException {
- return RDBJDBCTools.versionCheck(md, 12, 1, description);
- }
-
- @Override
- public String getMetaTableCreationStatement(String tableName) {
- return "create table " + tableName + " (ID varchar(" + IDSIZE + ") not null primary key, LVL number, LASTMOD number)";
- }
- },
-
- POSTGRES("PostgreSQL") {
- @Override
- public String checkVersion(DatabaseMetaData md) throws SQLException {
- return RDBJDBCTools.versionCheck(md, 9, 3, description);
- }
-
- @Override
- public String getDataTableCreationStatement(String tableName) {
- return "create table " + tableName + " (ID varchar(" + IDSIZE + ") not null primary key, DATA bytea)";
- }
- },
-
- DEFAULT("default") {
- };
-
- public String checkVersion(DatabaseMetaData md) throws SQLException {
- return "Unknown database type: " + md.getDatabaseProductName();
- }
-
- public String getDataTableCreationStatement(String tableName) {
- return "create table " + tableName + " (ID varchar(" + IDSIZE + ") not null primary key, DATA blob)";
- }
-
- public String getMetaTableCreationStatement(String tableName) {
- return "create table " + tableName + " (ID varchar(" + IDSIZE + ") not null primary key, LVL int, LASTMOD bigint)";
- }
-
- protected String description;
-
- private DB(String description) {
- this.description = description;
- }
-
- @Override
- public String toString() {
- return this.description;
- }
-
- @Nonnull
- public static DB getValue(String desc) {
- for (DB db : DB.values()) {
- if (db.description.equals(desc)) {
- return db;
- } else if (db == DB2 && desc.startsWith("DB2/")) {
- return db;
- }
- }
-
- LOG.error("DB type " + desc + " unknown, trying default settings");
- DEFAULT.description = desc + " - using default settings";
- return DEFAULT;
- }
- }
private void initialize(DataSource ds, RDBOptions options) throws Exception {
@@ -278,7 +156,7 @@ public class RDBBlobStore extends Cachin
}
DatabaseMetaData md = con.getMetaData();
- DB db = DB.getValue(md.getDatabaseProductName());
+ RDBBlobStoreDB db = RDBBlobStoreDB.getValue(md.getDatabaseProductName());
String versionDiags = db.checkVersion(md);
if (!versionDiags.isEmpty()) {
LOG.info(versionDiags);
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStoreDB.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStoreDB.java?rev=1695280&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStoreDB.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStoreDB.java Tue Aug 11 11:52:41 2015
@@ -0,0 +1,154 @@
+/*
+ * 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;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+
+import javax.annotation.Nonnull;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Defines variation in the capabilities of different RDBs.
+ */
+public enum RDBBlobStoreDB {
+ H2("H2") {
+ @Override
+ public String checkVersion(DatabaseMetaData md) throws SQLException {
+ return RDBJDBCTools.versionCheck(md, 1, 4, description);
+ }
+ },
+
+ DERBY("Apache Derby") {
+ @Override
+ public String checkVersion(DatabaseMetaData md) throws SQLException {
+ return RDBJDBCTools.versionCheck(md, 10, 11, description);
+ }
+ },
+
+ DB2("DB2") {
+ @Override
+ public String checkVersion(DatabaseMetaData md) throws SQLException {
+ return RDBJDBCTools.versionCheck(md, 10, 1, description);
+ }
+
+ @Override
+ public String getDataTableCreationStatement(String tableName) {
+ return "create table " + tableName + " (ID varchar(" + RDBBlobStore.IDSIZE + ") not null primary key, DATA blob("
+ + MINBLOB + "))";
+ }
+ },
+
+ MSSQL("Microsoft SQL Server") {
+ @Override
+ public String checkVersion(DatabaseMetaData md) throws SQLException {
+ return RDBJDBCTools.versionCheck(md, 11, 0, description);
+ }
+
+ @Override
+ public String getDataTableCreationStatement(String tableName) {
+ return "create table " + tableName + " (ID varchar(" + RDBBlobStore.IDSIZE
+ + ") not null primary key, DATA varbinary(max))";
+ }
+ },
+
+ MYSQL("MySQL") {
+ @Override
+ public String checkVersion(DatabaseMetaData md) throws SQLException {
+ return RDBJDBCTools.versionCheck(md, 5, 5, description);
+ }
+
+ @Override
+ public String getDataTableCreationStatement(String tableName) {
+ return "create table " + tableName + " (ID varchar(" + RDBBlobStore.IDSIZE + ") not null primary key, DATA mediumblob)";
+ }
+ },
+
+ ORACLE("Oracle") {
+ @Override
+ public String checkVersion(DatabaseMetaData md) throws SQLException {
+ return RDBJDBCTools.versionCheck(md, 12, 1, description);
+ }
+
+ @Override
+ public String getMetaTableCreationStatement(String tableName) {
+ return "create table " + tableName + " (ID varchar(" + RDBBlobStore.IDSIZE
+ + ") not null primary key, LVL number, LASTMOD number)";
+ }
+ },
+
+ POSTGRES("PostgreSQL") {
+ @Override
+ public String checkVersion(DatabaseMetaData md) throws SQLException {
+ return RDBJDBCTools.versionCheck(md, 9, 3, description);
+ }
+
+ @Override
+ public String getDataTableCreationStatement(String tableName) {
+ return "create table " + tableName + " (ID varchar(" + RDBBlobStore.IDSIZE + ") not null primary key, DATA bytea)";
+ }
+ },
+
+ DEFAULT("default") {
+ };
+
+ private static final Logger LOG = LoggerFactory.getLogger(RDBBlobStoreDB.class);
+
+ // blob size we need to support
+ private static final int MINBLOB = 2 * 1024 * 1024;
+
+ public String checkVersion(DatabaseMetaData md) throws SQLException {
+ return "Unknown database type: " + md.getDatabaseProductName();
+ }
+
+ public String getDataTableCreationStatement(String tableName) {
+ return "create table " + tableName + " (ID varchar(" + RDBBlobStore.IDSIZE + ") not null primary key, DATA blob)";
+ }
+
+ public String getMetaTableCreationStatement(String tableName) {
+ return "create table " + tableName + " (ID varchar(" + RDBBlobStore.IDSIZE
+ + ") not null primary key, LVL int, LASTMOD bigint)";
+ }
+
+ protected String description;
+
+ private RDBBlobStoreDB(String description) {
+ this.description = description;
+ }
+
+ @Override
+ public String toString() {
+ return this.description;
+ }
+
+ @Nonnull
+ public static RDBBlobStoreDB getValue(String desc) {
+ for (RDBBlobStoreDB db : RDBBlobStoreDB.values()) {
+ if (db.description.equals(desc)) {
+ return db;
+ } else if (db == DB2 && desc.startsWith("DB2/")) {
+ return db;
+ }
+ }
+
+ LOG.error("DB type " + desc + " unknown, trying default settings");
+ DEFAULT.description = desc + " - using default settings";
+ return DEFAULT;
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStoreDB.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBHelper.java?rev=1695280&r1=1695279&r2=1695280&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBHelper.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBHelper.java Tue Aug 11 11:52:41 2015
@@ -31,7 +31,7 @@ public class RDBHelper {
System.out.println();
RDBDocumentStoreDB ddb = RDBDocumentStoreDB.getValue(database);
- RDBBlobStore.DB bdb = RDBBlobStore.DB.getValue(database);
+ RDBBlobStoreDB bdb = RDBBlobStoreDB.getValue(database);
for (String table : RDBDocumentStore.getTableNames()) {
System.out.println(" " + ddb.getTableCreationStatement(table));