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 14:26:58 UTC
svn commit: r1695293 - in /jackrabbit/oak/branches/1.2: ./
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/
Author: reschke
Date: Tue Aug 11 12:26:58 2015
New Revision: 1695293
URL: http://svn.apache.org/r1695293
Log:
OAK-3198: reduce RDBDocumentStore class size, avoid code duplication with RDBBlobStore (ported to 1.2)
Added:
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStoreDB.java
- copied unchanged from r1695280, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStoreDB.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreDB.java
- copied unchanged from r1695122, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreDB.java
Modified:
jackrabbit/oak/branches/1.2/ (props changed)
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBHelper.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBJDBCTools.java
Propchange: jackrabbit/oak/branches/1.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 11 12:26:58 2015
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673713,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678023,1678095-1678096,1678124,1678171,1678173,1678211,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679503,1679958,1679961,1680170,1680172,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680747,1680805-1680806,1680903,1681282,1681767,1681918,1682042,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683059,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1683700,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684820,1684868
,1685023,1685075,1685370,1685552,1685589-1685590,1685840,1685964,1685977,1685989,1685999,1686023,1686032,1686097,1686162,1686229,1686234,1686253,1686414,1686780,1686854,1686857,1686971,1687053-1687055,1687175,1687196,1687198,1687220,1687239-1687240,1687301,1687441,1687553,1688089-1688090,1688172,1688179,1688349,1688421,1688436,1688453,1688616,1688622,1688634,1688636,1688817,1689003-1689004,1689008,1689577,1689581,1689623,1689810,1689828,1689831,1689833,1689903,1690017,1690043,1690047,1690057,1690247,1690249,1690634-1690637,1690650,1690669,1690674,1690885,1690941,1691139,1691151,1691159,1691167,1691183,1691188,1691210,1691280,1691307,1691331-1691333,1691345,1691384-1691385,1691401,1691509,1692133-1692134,1692156,1692250,1692274,1692363,1692382,1692478,1692955,1693002,1693030,1693209,1693421,1693525-1693526,1694007,1694393-1694394
+/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673713,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678023,1678095-1678096,1678124,1678171,1678173,1678211,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679503,1679958,1679961,1680170,1680172,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680747,1680805-1680806,1680903,1681282,1681767,1681918,1682042,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683059,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1683700,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684820,1684868
,1685023,1685075,1685370,1685552,1685589-1685590,1685840,1685964,1685977,1685989,1685999,1686023,1686032,1686097,1686162,1686229,1686234,1686253,1686414,1686780,1686854,1686857,1686971,1687053-1687055,1687175,1687196,1687198,1687220,1687239-1687240,1687301,1687441,1687553,1688089-1688090,1688172,1688179,1688349,1688421,1688436,1688453,1688616,1688622,1688634,1688636,1688817,1689003-1689004,1689008,1689577,1689581,1689623,1689810,1689828,1689831,1689833,1689903,1690017,1690043,1690047,1690057,1690247,1690249,1690634-1690637,1690650,1690669,1690674,1690885,1690941,1691139,1691151,1691159,1691167,1691183,1691188,1691210,1691280,1691307,1691331-1691333,1691345,1691384-1691385,1691401,1691509,1692133-1692134,1692156,1692250,1692274,1692363,1692382,1692478,1692955,1693002,1693030,1693209,1693421,1693525-1693526,1694007,1694393-1694394,1695050,1695122,1695280
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java?rev=1695293&r1=1695292&r2=1695293&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java Tue Aug 11 12:26:58 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,133 +137,6 @@ public class RDBBlobStore extends Cachin
protected String tnMeta;
private Set<String> tablesToBeDropped = new HashSet<String>();
- private static void versionCheck(DatabaseMetaData md, int xmaj, int xmin, String description) throws SQLException {
- int maj = md.getDatabaseMajorVersion();
- int min = md.getDatabaseMinorVersion();
- if (maj < xmaj || (maj == xmaj && min < xmin)) {
- LOG.info("Unsupported " + description + " version: " + maj + "." + min + ", expected at least " + xmaj + "." + xmin);
- }
- }
-
- /**
- * Defines variation in the capabilities of different RDBs.
- */
- protected enum DB {
- H2("H2") {
- @Override
- public void checkVersion(DatabaseMetaData md) throws SQLException {
- versionCheck(md, 1, 4, description);
- }
- },
-
- DERBY("Apache Derby") {
- @Override
- public void checkVersion(DatabaseMetaData md) throws SQLException {
- versionCheck(md, 10, 11, description);
- }
- },
-
- DB2("DB2") {
- @Override
- public void checkVersion(DatabaseMetaData md) throws SQLException {
- 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 void checkVersion(DatabaseMetaData md) throws SQLException {
- 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 void checkVersion(DatabaseMetaData md) throws SQLException {
- 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 void checkVersion(DatabaseMetaData md) throws SQLException {
- 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 void checkVersion(DatabaseMetaData md) throws SQLException {
- 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 void checkVersion(DatabaseMetaData md) throws SQLException {
- LOG.info("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 {
@@ -286,6 +156,12 @@ public class RDBBlobStore extends Cachin
}
DatabaseMetaData md = con.getMetaData();
+ RDBBlobStoreDB db = RDBBlobStoreDB.getValue(md.getDatabaseProductName());
+ String versionDiags = db.checkVersion(md);
+ if (!versionDiags.isEmpty()) {
+ LOG.info(versionDiags);
+ }
+
String dbDesc = String.format("%s %s (%d.%d)", md.getDatabaseProductName(), md.getDatabaseProductVersion(),
md.getDatabaseMajorVersion(), md.getDatabaseMinorVersion());
String driverDesc = String.format("%s %s (%d.%d)", md.getDriverName(), md.getDriverVersion(), md.getDriverMajorVersion(),
@@ -314,8 +190,6 @@ public class RDBBlobStore extends Cachin
// table does not appear to exist
con.rollback();
- DB db = DB.getValue(md.getDatabaseProductName());
-
createStatement = con.createStatement();
if (this.tnMeta.equals(tableName)) {
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1695293&r1=1695292&r2=1695293&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java Tue Aug 11 12:26:58 2015
@@ -68,6 +68,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.UpdateUtils;
import org.apache.jackrabbit.oak.plugins.document.cache.CacheInvalidationStats;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStoreDB.FETCHFIRSTSYNTAX;
import org.apache.jackrabbit.oak.plugins.document.util.StringValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -399,373 +400,6 @@ public class RDBDocumentStore implements
// implementation
- enum FETCHFIRSTSYNTAX { FETCHFIRST, LIMIT, TOP};
-
-
- private static void versionCheck(DatabaseMetaData md, int xmaj, int xmin, String description) throws SQLException {
- int maj = md.getDatabaseMajorVersion();
- int min = md.getDatabaseMinorVersion();
- if (maj < xmaj || (maj == xmaj && min < xmin)) {
- LOG.info("Unsupported " + description + " version: " + maj + "." + min + ", expected at least " + xmaj + "." + xmin);
- }
- }
-
- /**
- * Defines variation in the capabilities of different RDBs.
- */
- protected enum DB {
- DEFAULT("default") {
- },
-
- H2("H2") {
- @Override
- public void checkVersion(DatabaseMetaData md) throws SQLException {
- versionCheck(md, 1, 4, description);
- }
- },
-
- DERBY("Apache Derby") {
- @Override
- public void checkVersion(DatabaseMetaData md) throws SQLException {
- versionCheck(md, 10, 11, description);
- }
-
- public boolean allowsCaseInSelect() {
- return false;
- }
- },
-
- POSTGRES("PostgreSQL") {
- @Override
- public void checkVersion(DatabaseMetaData md) throws SQLException {
- versionCheck(md, 9, 3, description);
- }
-
- @Override
- public String getTableCreationStatement(String tableName) {
- return ("create table " + tableName + " (ID varchar(512) not null primary key, MODIFIED bigint, HASBINARY smallint, DELETEDONCE smallint, MODCOUNT bigint, CMODCOUNT bigint, DSIZE bigint, DATA varchar(16384), BDATA bytea)");
- }
-
- @Override
- public String getAdditionalDiagnostics(RDBConnectionHandler ch, String tableName) {
- Connection con = null;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- Map<String, String> result = new HashMap<String, String>();
- try {
- con = ch.getROConnection();
- String cat = con.getCatalog();
- stmt = con.prepareStatement("SELECT pg_encoding_to_char(encoding), datcollate FROM pg_database WHERE datname=?");
- stmt.setString(1, cat);
- rs = stmt.executeQuery();
- while (rs.next()) {
- result.put("pg_encoding_to_char(encoding)", rs.getString(1));
- result.put("datcollate", rs.getString(2));
- }
- stmt.close();
- con.commit();
- } catch (SQLException ex) {
- LOG.debug("while getting diagnostics", ex);
- } finally {
- ch.closeResultSet(rs);
- ch.closeStatement(stmt);
- ch.closeConnection(con);
- }
- return result.toString();
- }
- },
-
- DB2("DB2") {
- @Override
- public void checkVersion(DatabaseMetaData md) throws SQLException {
- versionCheck(md, 10, 1, description);
- }
-
- @Override
- public String getAdditionalDiagnostics(RDBConnectionHandler ch, String tableName) {
- Connection con = null;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- Map<String, String> result = new HashMap<String, String>();
- try {
- con = ch.getROConnection();
- // we can't look up by schema as con.getSchema is JDK 1.7
- stmt = con.prepareStatement("SELECT CODEPAGE, COLLATIONSCHEMA, COLLATIONNAME, TABSCHEMA FROM SYSCAT.COLUMNS WHERE COLNAME=? and COLNO=0 AND UPPER(TABNAME)=UPPER(?)");
- stmt.setString(1, "ID");
- stmt.setString(2, tableName);
- rs = stmt.executeQuery();
- while (rs.next() && result.size() < 20) {
- // thus including the schema name here
- String schema = rs.getString("TABSCHEMA").trim();
- result.put(schema + ".CODEPAGE", rs.getString("CODEPAGE").trim());
- result.put(schema + ".COLLATIONSCHEMA", rs.getString("COLLATIONSCHEMA").trim());
- result.put(schema + ".COLLATIONNAME", rs.getString("COLLATIONNAME").trim());
- }
- stmt.close();
- con.commit();
- } catch (SQLException ex) {
- LOG.debug("while getting diagnostics", ex);
- } finally {
- ch.closeResultSet(rs);
- ch.closeStatement(stmt);
- ch.closeConnection(con);
- }
- return result.toString();
- }
-},
-
- ORACLE("Oracle") {
- @Override
- public void checkVersion(DatabaseMetaData md) throws SQLException {
- versionCheck(md, 12, 1, description);
- }
-
- @Override
- public String getInitializationStatement() {
- // see https://issues.apache.org/jira/browse/OAK-1914
- // for some reason, the default for NLS_SORT is incorrect
- return ("ALTER SESSION SET NLS_SORT='BINARY'");
- }
-
- @Override
- public String getTableCreationStatement(String tableName) {
- // see https://issues.apache.org/jira/browse/OAK-1914
- return ("create table " + tableName + " (ID varchar(512) not null primary key, MODIFIED number, HASBINARY number, DELETEDONCE number, MODCOUNT number, CMODCOUNT number, DSIZE number, DATA varchar(4000), BDATA blob)");
- }
-
- @Override
- public String getAdditionalDiagnostics(RDBConnectionHandler ch, String tableName) {
- Connection con = null;
- Statement stmt = null;
- ResultSet rs = null;
- Map<String, String> result = new HashMap<String, String>();
- try {
- con = ch.getROConnection();
- stmt = con.createStatement();
- rs = stmt.executeQuery("SELECT PARAMETER, VALUE from NLS_DATABASE_PARAMETERS WHERE PARAMETER IN ('NLS_COMP', 'NLS_CHARACTERSET')");
- while (rs.next()) {
- result.put(rs.getString(1), rs.getString(2));
- }
- stmt.close();
- con.commit();
- } catch (SQLException ex) {
- LOG.debug("while getting diagnostics", ex);
- } finally {
- ch.closeResultSet(rs);
- ch.closeStatement(stmt);
- ch.closeConnection(con);
- }
- return result.toString();
- }
- },
-
- MYSQL("MySQL") {
- @Override
- public void checkVersion(DatabaseMetaData md) throws SQLException {
- versionCheck(md, 5, 5, description);
- }
-
- @Override
- public String getTableCreationStatement(String tableName) {
- // see https://issues.apache.org/jira/browse/OAK-1913
- return ("create table " + tableName + " (ID varbinary(512) not null primary key, MODIFIED bigint, HASBINARY smallint, DELETEDONCE smallint, MODCOUNT bigint, CMODCOUNT bigint, DSIZE bigint, DATA varchar(16000), BDATA longblob)");
- }
-
- @Override
- public FETCHFIRSTSYNTAX getFetchFirstSyntax() {
- return FETCHFIRSTSYNTAX.LIMIT;
- }
-
- @Override
- public String getConcatQueryString(int dataOctetLimit, int dataLength) {
- return "CONCAT(DATA, ?)";
- }
-
- @Override
- public String getAdditionalDiagnostics(RDBConnectionHandler ch, String tableName) {
- Connection con = null;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- Map<String, String> result = new HashMap<String, String>();
- try {
- con = ch.getROConnection();
- stmt = con.prepareStatement("SHOW TABLE STATUS LIKE ?");
- stmt.setString(1, tableName);
- rs = stmt.executeQuery();
- while (rs.next()) {
- result.put("collation", rs.getString("Collation"));
- }
- stmt.close();
- con.commit();
- } catch (SQLException ex) {
- LOG.debug("while getting diagnostics", ex);
- } finally {
- ch.closeResultSet(rs);
- ch.closeStatement(stmt);
- ch.closeConnection(con);
- }
- return result.toString();
- }
- },
-
- MSSQL("Microsoft SQL Server") {
- @Override
- public void checkVersion(DatabaseMetaData md) throws SQLException {
- versionCheck(md, 11, 0, description);
- }
-
- @Override
- public String getTableCreationStatement(String tableName) {
- // see https://issues.apache.org/jira/browse/OAK-2395
- return ("create table " + tableName + " (ID varbinary(512) not null primary key, MODIFIED bigint, HASBINARY smallint, DELETEDONCE smallint, MODCOUNT bigint, CMODCOUNT bigint, DSIZE bigint, DATA nvarchar(4000), BDATA varbinary(max))");
- }
-
- @Override
- public FETCHFIRSTSYNTAX getFetchFirstSyntax() {
- return FETCHFIRSTSYNTAX.TOP;
- }
-
- @Override
- public String getConcatQueryString(int dataOctetLimit, int dataLength) {
- /*
- * To avoid truncation when concatenating force an error when
- * limit is above the octet limit
- */
- return "CASE WHEN LEN(DATA) <= " + (dataOctetLimit - dataLength) + " THEN (DATA + CAST(? AS nvarchar("
- + dataOctetLimit + "))) ELSE (DATA + CAST(DATA AS nvarchar(max))) END";
-
- }
-
- @Override
- public String getAdditionalDiagnostics(RDBConnectionHandler ch, String tableName) {
- Connection con = null;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- Map<String, String> result = new HashMap<String, String>();
- try {
- con = ch.getROConnection();
- String cat = con.getCatalog();
- stmt = con.prepareStatement("SELECT collation_name FROM sys.databases WHERE name=?");
- stmt.setString(1, cat);
- rs = stmt.executeQuery();
- while (rs.next()) {
- result.put("collation_name", rs.getString(1));
- }
- stmt.close();
- con.commit();
- } catch (SQLException ex) {
- LOG.debug("while getting diagnostics", ex);
- } finally {
- ch.closeResultSet(rs);
- ch.closeStatement(stmt);
- ch.closeConnection(con);
- }
- return result.toString();
- }
- };
-
- /**
- * Check the database brand and version
- */
- public void checkVersion(DatabaseMetaData md) throws SQLException {
- LOG.info("Unknown database type: " + md.getDatabaseProductName());
- }
-
- /**
- * Allows case in select. Default true.
- */
- public boolean allowsCaseInSelect() {
- return true;
- }
-
- /**
- * Query syntax for "FETCH FIRST"
- */
- public FETCHFIRSTSYNTAX getFetchFirstSyntax() {
- return FETCHFIRSTSYNTAX.FETCHFIRST;
- }
-
- /**
- * Returns the CONCAT function or its equivalent function or sub-query.
- * Note that the function MUST NOT cause a truncated value to be
- * written!
- *
- * @param dataOctetLimit
- * expected capacity of data column
- * @param dataLength
- * length of string to be inserted
- *
- * @return the concat query string
- */
- public String getConcatQueryString(int dataOctetLimit, int dataLength) {
- return "DATA || CAST(? AS varchar(" + dataOctetLimit + "))";
- }
-
- /**
- * Query for any required initialization of the DB.
- *
- * @return the DB initialization SQL string
- */
- public @Nonnull String getInitializationStatement() {
- return "";
- }
-
- /**
- * Table creation statement string
- *
- * @param tableName
- * @return the table creation string
- */
- public String getTableCreationStatement(String tableName) {
- return "create table "
- + tableName
- + " (ID varchar(512) not null primary key, MODIFIED bigint, HASBINARY smallint, DELETEDONCE smallint, MODCOUNT bigint, CMODCOUNT bigint, DSIZE bigint, DATA varchar(16384), BDATA blob("
- + 1024 * 1024 * 1024 + "))";
- }
-
- public List<String> getIndexCreationStatements(String tableName) {
- if (CREATEINDEX.equals("modified-id")) {
- return Collections.singletonList("create index " + tableName + "_MI on " + tableName + " (MODIFIED, ID)");
- } else if (CREATEINDEX.equals("id-modified")) {
- return Collections.singletonList("create index " + tableName + "_MI on " + tableName + " (ID, MODIFIED)");
- } else if (CREATEINDEX.equals("modified")) {
- return Collections.singletonList("create index " + tableName + "_MI on " + tableName + " (MODIFIED)");
- } else {
- return Collections.emptyList();
- }
- }
-
- public String getAdditionalDiagnostics(RDBConnectionHandler ch, String tableName) {
- return "";
- }
-
- 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 static final String MODIFIED = "_modified";
private static final String MODCOUNT = "_modCount";
@@ -811,7 +445,7 @@ public class RDBDocumentStore implements
private static final Key MODIFIEDKEY = new Key(MODIFIED, null);
// DB-specific information
- private DB db;
+ private RDBDocumentStoreDB db;
private Map<String, String> metadata;
@@ -856,13 +490,16 @@ public class RDBDocumentStore implements
md.getDriverMinorVersion());
String dbUrl = md.getURL();
- this.db = DB.getValue(md.getDatabaseProductName());
+ this.db = RDBDocumentStoreDB.getValue(md.getDatabaseProductName());
this.metadata = ImmutableMap.<String,String>builder()
.put("type", "rdb")
.put("db", md.getDatabaseProductName())
.put("version", md.getDatabaseProductVersion())
.build();
- db.checkVersion(md);
+ String versionDiags = db.checkVersion(md);
+ if (!versionDiags.isEmpty()) {
+ LOG.info(versionDiags);
+ }
if (! "".equals(db.getInitializationStatement())) {
Statement stmt = null;
@@ -1579,9 +1216,6 @@ public class RDBDocumentStore implements
// Number of elapsed ms in a query above which a diagnostic warning is generated
private static final int QUERYTIMELIMIT = Integer.getInteger(
"org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QUERYTIMELIMIT", 10000);
- // whether to create indices
- private static final String CREATEINDEX = System.getProperty(
- "org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.CREATEINDEX", "");
private static byte[] asBytes(String data) {
byte[] bytes;
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBHelper.java?rev=1695293&r1=1695292&r2=1695293&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBHelper.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBHelper.java Tue Aug 11 12:26:58 2015
@@ -30,10 +30,10 @@ public class RDBHelper {
System.out.println(database);
System.out.println();
- RDBDocumentStore.DB ddb = RDBDocumentStore.DB.getValue(database);
- RDBBlobStore.DB bdb = RDBBlobStore.DB.getValue(database);
+ RDBDocumentStoreDB ddb = RDBDocumentStoreDB.getValue(database);
+ RDBBlobStoreDB bdb = RDBBlobStoreDB.getValue(database);
- for (String table : RDBDocumentStore.getTableNames()) {
+ for (String table : RDBDocumentStore.getTableNames()) {
System.out.println(" " + ddb.getTableCreationStatement(table));
for (String s : ddb.getIndexCreationStatements(table)) {
System.out.println(" " + s);
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBJDBCTools.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBJDBCTools.java?rev=1695293&r1=1695292&r2=1695293&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBJDBCTools.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBJDBCTools.java Tue Aug 11 12:26:58 2015
@@ -17,11 +17,11 @@
package org.apache.jackrabbit.oak.plugins.document.rdb;
import java.sql.Connection;
+import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
import javax.annotation.Nonnull;
@@ -154,4 +154,18 @@ public class RDBJDBCTools {
}
return false;
}
+
+ /**
+ * Generate version diagnostics.
+ */
+ protected static String versionCheck(DatabaseMetaData md, int xmaj, int xmin, String description) throws SQLException {
+ int maj = md.getDatabaseMajorVersion();
+ int min = md.getDatabaseMinorVersion();
+ if (maj < xmaj || (maj == xmaj && min < xmin)) {
+ return "Unsupported " + description + " version: " + maj + "." + min + ", expected at least " + xmaj + "." + xmin;
+ }
+ else {
+ return "";
+ }
+ }
}