You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by dp...@apache.org on 2007/10/02 09:49:45 UTC

svn commit: r581150 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal: DatabaseJournal.java OracleDatabaseJournal.java

Author: dpfister
Date: Tue Oct  2 00:49:44 2007
New Revision: 581150

URL: http://svn.apache.org/viewvc?rev=581150&view=rev
Log:
JCR-1156 DatabaseJournal refactoring for subclassing capability
  - Missing license in OracleDatabaseJournal.java

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/OracleDatabaseJournal.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java?rev=581150&r1=581149&r2=581150&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java Tue Oct  2 00:49:44 2007
@@ -71,6 +71,11 @@
     private static final String DEFAULT_DDL_NAME = "default.ddl";
 
     /**
+     * Default journal table name, used to check schema completeness.
+     */
+    private static final String DEFAULT_JOURNAL_TABLE = "JOURNAL";
+
+    /**
      * Default reconnect delay in milliseconds.
      */
     private static final long DEFAULT_RECONNECT_DELAY_MS = 10000;
@@ -96,11 +101,6 @@
     private String schema;
 
     /**
-     * Schema object prefix, bean property.
-     */
-    protected String schemaObjectPrefix;
-
-    /**
      * User name, bean property.
      */
     private String user;
@@ -151,6 +151,31 @@
     private long reconnectTimeMs;
 
     /**
+     * SQL statement returning all revisions within a range.
+     */
+    protected String selectRevisionsStmtSQL;
+
+    /**
+     * SQL statement updating the global revision.
+     */
+    protected String updateGlobalStmtSQL;
+
+    /**
+     * SQL statement returning the global revision.
+     */
+    protected String selectGlobalStmtSQL;
+
+    /**
+     * SQL statement appending a new record.
+     */
+    protected String insertRevisionStmtSQL;
+
+    /**
+     * Schema object prefix, bean property.
+     */
+    protected String schemaObjectPrefix;
+
+    /**
      * {@inheritDoc}
      */
     public void init(String id, NamespaceResolver resolver)
@@ -172,6 +197,7 @@
             connection = getConnection();
             connection.setAutoCommit(true);
             checkSchema();
+            buildSQLStatements();
             prepareStatements();
         } catch (Exception e) {
             String msg = "Unable to create connection.";
@@ -541,23 +567,7 @@
      * @throws Exception if an error occurs
      */
     private void checkSchema() throws Exception {
-        DatabaseMetaData metaData = connection.getMetaData();
-        String tableName = schemaObjectPrefix + "JOURNAL";
-        if (metaData.storesLowerCaseIdentifiers()) {
-            tableName = tableName.toLowerCase();
-        } else if (metaData.storesUpperCaseIdentifiers()) {
-            tableName = tableName.toUpperCase();
-        }
-
-        ResultSet rs = metaData.getTables(null, null, tableName, null);
-        boolean schemaExists;
-        try {
-            schemaExists = rs.next();
-        } finally {
-            rs.close();
-        }
-
-        if (!schemaExists) {
+        if (!schemaExists(connection.getMetaData())) {
             // read ddl from resources
             InputStream in = DatabaseJournal.class.getResourceAsStream(schema + ".ddl");
             if (in == null) {
@@ -593,6 +603,33 @@
     }
 
     /**
+     * Checks whether the required table(s) exist in the schema. May be
+     * overridden by subclasses to allow different table names.
+     *
+     * @param metaData database meta data
+     * @return <code>true</code> if the schema exists
+     * @throws SQLException if an SQL error occurs
+     */
+    protected boolean schemaExists(DatabaseMetaData metaData)
+            throws SQLException {
+
+        String tableName = schemaObjectPrefix + DEFAULT_JOURNAL_TABLE;
+        if (metaData.storesLowerCaseIdentifiers()) {
+            tableName = tableName.toLowerCase();
+        } else if (metaData.storesUpperCaseIdentifiers()) {
+            tableName = tableName.toUpperCase();
+        }
+
+        ResultSet rs = metaData.getTables(null, null, tableName, null);
+
+        try {
+            return rs.next();
+        } finally {
+            rs.close();
+        }
+    }
+
+    /**
      * Creates an SQL statement for schema creation by variable substitution.
      *
      * @param sql a SQL string which may contain variables to substitute
@@ -603,25 +640,36 @@
     }
 
     /**
-     * Builds and prepares the SQL statements.
-     *
-     * @throws SQLException if an error occurs
+     * Builds the SQL statements. May be overridden by subclasses to allow
+     * different table and/or column names.
      */
-    private void prepareStatements() throws SQLException {
-        selectRevisionsStmt = connection.prepareStatement(
+    protected void buildSQLStatements() {
+        selectRevisionsStmtSQL =
                 "select REVISION_ID, JOURNAL_ID, PRODUCER_ID, REVISION_DATA " +
                 "from " + schemaObjectPrefix + "JOURNAL " +
-                "where REVISION_ID > ?");
-        updateGlobalStmt = connection.prepareStatement(
+                "where REVISION_ID > ?";
+        updateGlobalStmtSQL =
                 "update " + schemaObjectPrefix + "GLOBAL_REVISION " +
-                "set revision_id = revision_id + 1");
-        selectGlobalStmt = connection.prepareStatement(
+                "set revision_id = revision_id + 1";
+        selectGlobalStmtSQL =
                 "select revision_id " +
-                "from " + schemaObjectPrefix + "GLOBAL_REVISION");
-        insertRevisionStmt = connection.prepareStatement(
+                "from " + schemaObjectPrefix + "GLOBAL_REVISION";
+        insertRevisionStmtSQL =
                 "insert into " + schemaObjectPrefix + "JOURNAL" +
                 "(REVISION_ID, JOURNAL_ID, PRODUCER_ID, REVISION_DATA) " +
-                "values (?,?,?,?)");
+                "values (?,?,?,?)";
+    }
+
+    /**
+     * Prepares the SQL statements.
+     *
+     * @throws SQLException if an error occurs
+     */
+    private void prepareStatements() throws SQLException {
+        selectRevisionsStmt = connection.prepareStatement(selectRevisionsStmtSQL);
+        updateGlobalStmt = connection.prepareStatement(updateGlobalStmtSQL);
+        selectGlobalStmt = connection.prepareStatement(selectGlobalStmtSQL);
+        insertRevisionStmt = connection.prepareStatement(insertRevisionStmtSQL);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/OracleDatabaseJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/OracleDatabaseJournal.java?rev=581150&r1=581149&r2=581150&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/OracleDatabaseJournal.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/OracleDatabaseJournal.java Tue Oct  2 00:49:44 2007
@@ -1,9 +1,23 @@
+/*
+ * 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.core.journal;
 
 import org.apache.jackrabbit.util.Text;
 
-
-
 /**
  * It has the following property in addition to those of the DatabaseJournal:
  * <ul>
@@ -54,7 +68,4 @@
         }
         return Text.replace(sql, TABLE_SPACE_VARIABLE, tspace).trim();
     }
-
-
-
 }