jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marti...@apache.org
Subject svn commit: r810362 [1/2] - in /jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: fs/db/ journal/ persistence/bundle/ persistence/bundle/util/ persistence/db/ util/db/
Date Wed, 02 Sep 2009 05:11:48 GMT
Author: martijnh
Date: Wed Sep  2 05:11:45 2009
New Revision: 810362

URL: http://svn.apache.org/viewvc?rev=810362&view=rev
Log:
JCR-1456 Database connection pooling

* Moved the general DB utility classes to o.a.j.c.util.db package
* Refactored the o.a.j.c.fs.db package to use connection pooling

Added:
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/CheckSchemaOperation.java
      - copied, changed from r803244, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/CheckSchemaOperation.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionFactory.java
      - copied, changed from r801889, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
      - copied, changed from r803244, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionHelper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DataSourceWrapper.java
      - copied, changed from r801889, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DataSourceWrapper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DbUtility.java
      - copied, changed from r802341, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbUtility.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DerbyConnectionHelper.java
      - copied, changed from r802341, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DerbyConnectionHelper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/Oracle10R1ConnectionHelper.java
      - copied, changed from r803244, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/Oracle10R1ConnectionHelper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/OracleConnectionHelper.java
      - copied, changed from r803244, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/OracleConnectionHelper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ResultSetWrapper.java
      - copied, changed from r802341, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ResultSetWrapper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/StreamWrapper.java
      - copied, changed from r801889, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/StreamWrapper.java
Removed:
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/CheckSchemaOperation.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionHelper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DataSourceWrapper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbUtility.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DerbyConnectionHelper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/Oracle10R1ConnectionHelper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/OracleConnectionHelper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ResultSetWrapper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/StreamWrapper.java
Modified:
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystem.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/MSSqlFileSystem.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MSSqlPersistenceManager.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/PostgreSQLPersistenceManager.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbNameIndex.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NGKDbNameIndex.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/PostgreSQLNameIndex.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java Wed Sep  2 05:11:45 2009
@@ -21,31 +21,29 @@
 import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.fs.FileSystemPathUtil;
 import org.apache.jackrabbit.core.fs.RandomAccessOutputStream;
-import org.apache.jackrabbit.util.Text;
+import org.apache.jackrabbit.core.persistence.PMContext;
+import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
+import org.apache.jackrabbit.core.util.db.ConnectionHelper;
+import org.apache.jackrabbit.core.util.db.DbUtility;
+import org.apache.jackrabbit.core.util.db.StreamWrapper;
 import org.apache.jackrabbit.util.TransientFileFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.RepositoryException;
-import java.io.BufferedReader;
+import javax.sql.DataSource;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FilterInputStream;
 import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.FileInputStream;
 import java.io.RandomAccessFile;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.sql.Statement;
 import java.util.ArrayList;
-import java.util.HashMap;
 
 /**
  * Base class for database file systems. This class contains common
@@ -57,16 +55,13 @@
  * See the {@link DbFileSystem} for a detailed description of the available
  * configuration options and database behaviour.
  */
-public class DatabaseFileSystem implements FileSystem {
+public abstract class DatabaseFileSystem implements FileSystem {
 
     /**
      * Logger instance
      */
     private static Logger log = LoggerFactory.getLogger(DatabaseFileSystem.class);
 
-    protected static final String SCHEMA_OBJECT_PREFIX_VARIABLE =
-            "${schemaObjectPrefix}";
-
     protected boolean initialized;
 
     protected String schema;
@@ -75,14 +70,8 @@
     // initial size of buffer used to serialize objects
     protected static final int INITIAL_BUFFER_SIZE = 8192;
 
-    // jdbc connection
-    protected Connection con;
-
-    // time to sleep in ms before a reconnect is attempted
-    protected static final int SLEEP_BEFORE_RECONNECT = 10000;
-
-    // the map of prepared statements (key: sql stmt, value: prepared stmt)
-    private HashMap<String, PreparedStatement> preparedStatements = new HashMap<String, PreparedStatement>();
+    /** the {@link ConnectionHelper} set in the {@link #init()} method */
+    protected ConnectionHelper conHelper;
 
     // SQL statements
     protected String selectExistSQL;
@@ -179,21 +168,17 @@
         }
 
         try {
-            // setup jdbc connection
-            initConnection();
+            conHelper = createConnectionHelper(getDataSource());
 
             // make sure schemaObjectPrefix consists of legal name characters only
-            prepareSchemaObjectPrefix();
+            schemaObjectPrefix = conHelper.prepareDbIdentifier(schemaObjectPrefix);
 
             // check if schema objects exist and create them if necessary
-            checkSchema();
+            createCheckSchemaOperation().run();
 
             // build sql statements
             buildSQLStatements();
 
-            // prepare statements
-            initPreparedStatements();
-
             // finally verify that there's a file system root entry
             verifyRootExists();
 
@@ -206,29 +191,44 @@
     }
 
     /**
+     * @return
+     * @throws Exception
+     */
+    protected abstract DataSource getDataSource() throws Exception;
+
+    /**
+     * This method is called from the {@link #init(PMContext)} method of this class and returns a
+     * {@link ConnectionHelper} instance which is assigned to the {@code conHelper} field. Subclasses may
+     * override it to return a specialized connection helper.
+     * 
+     * @param dataSrc the {@link DataSource} of this persistence manager
+     * @return a {@link ConnectionHelper}
+     * @throws Exception on error
+     */
+    protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception {
+        return new ConnectionHelper(dataSrc);
+    }
+
+    /**
+     * This method is called from {@link #init(PMContext)} after the
+     * {@link #createConnectionHelper(DataSource)} method, and returns a default {@link CheckSchemaOperation}.
+     * Subclasses can overrride this implementation to get a customized implementation.
+     * 
+     * @return a new {@link CheckSchemaOperation} instance
+     */
+    protected CheckSchemaOperation createCheckSchemaOperation() {
+        InputStream in = DatabaseFileSystem.class.getResourceAsStream(getSchema() + ".ddl");
+        return new CheckSchemaOperation(conHelper, in, schemaObjectPrefix + "FSENTRY").addVariableReplacement(
+            CheckSchemaOperation.SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix);
+    }
+
+    /**
      * {@inheritDoc}
      */
     public void close() throws FileSystemException {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
-
-        try {
-            // close shared prepared statements
-            for (PreparedStatement prep : preparedStatements.values()) {
-                closeStatement(prep);
-            }
-            preparedStatements.clear();
-
-            // close jdbc connection
-            closeConnection(con);
-        } catch (SQLException e) {
-            String msg = "error closing file system";
-            log.error(msg, e);
-            throw new FileSystemException(msg, e);
-        } finally {
-            initialized = false;
-        }
     }
 
     /**
@@ -264,9 +264,8 @@
         int count = 0;
         synchronized (deleteFileSQL) {
             try {
-                Statement stmt = executeStmt(
+                count = conHelper.update(
                         deleteFileSQL, new Object[]{parentDir, name});
-                count = stmt.getUpdateCount();
             } catch (SQLException e) {
                 String msg = "failed to delete file: " + filePath;
                 log.error(msg, e);
@@ -299,12 +298,11 @@
         int count = 0;
         synchronized (deleteFolderSQL) {
             try {
-                Statement stmt = executeStmt(deleteFolderSQL, new Object[]{
+                count = conHelper.update(deleteFolderSQL, new Object[]{
                         parentDir,
                         name,
                         folderPath,
                         folderPath + FileSystem.SEPARATOR + "%"});
-                count = stmt.getUpdateCount();
             } catch (SQLException e) {
                 String msg = "failed to delete folder: " + folderPath;
                 log.error(msg, e);
@@ -333,9 +331,8 @@
         synchronized (selectExistSQL) {
             ResultSet rs = null;
             try {
-                Statement stmt = executeStmt(
-                        selectExistSQL, new Object[]{parentDir, name});
-                rs = stmt.getResultSet();
+                rs = conHelper.exec(
+                        selectExistSQL, new Object[]{parentDir, name}, false, 0);
 
                 // a file system entry exists if the result set
                 // has at least one entry
@@ -345,7 +342,7 @@
                 log.error(msg, e);
                 throw new FileSystemException(msg, e);
             } finally {
-                closeResultSet(rs);
+                DbUtility.close(rs);
             }
         }
     }
@@ -366,9 +363,8 @@
         synchronized (selectFileExistSQL) {
             ResultSet rs = null;
             try {
-                Statement stmt = executeStmt(
-                        selectFileExistSQL, new Object[]{parentDir, name});
-                rs = stmt.getResultSet();
+                rs = conHelper.exec(
+                        selectFileExistSQL, new Object[]{parentDir, name}, false, 0);
 
                 // a file exists if the result set has at least one entry
                 return rs.next();
@@ -377,7 +373,7 @@
                 log.error(msg, e);
                 throw new FileSystemException(msg, e);
             } finally {
-                closeResultSet(rs);
+                DbUtility.close(rs);
             }
         }
     }
@@ -398,9 +394,8 @@
         synchronized (selectFolderExistSQL) {
             ResultSet rs = null;
             try {
-                Statement stmt = executeStmt(
-                        selectFolderExistSQL, new Object[]{parentDir, name});
-                rs = stmt.getResultSet();
+                rs = conHelper.exec(
+                        selectFolderExistSQL, new Object[]{parentDir, name}, false, 0);
 
                 // a folder exists if the result set has at least one entry
                 return rs.next();
@@ -409,7 +404,7 @@
                 log.error(msg, e);
                 throw new FileSystemException(msg, e);
             } finally {
-                closeResultSet(rs);
+                DbUtility.close(rs);
             }
         }
     }
@@ -430,9 +425,8 @@
         synchronized (selectLastModifiedSQL) {
             ResultSet rs = null;
             try {
-                Statement stmt = executeStmt(
-                        selectLastModifiedSQL, new Object[]{parentDir, name});
-                rs = stmt.getResultSet();
+                rs = conHelper.exec(
+                        selectLastModifiedSQL, new Object[]{parentDir, name}, false, 0);
                 if (!rs.next()) {
                     throw new FileSystemException("no such file system entry: " + path);
                 }
@@ -442,7 +436,7 @@
                 log.error(msg, e);
                 throw new FileSystemException(msg, e);
             } finally {
-                closeResultSet(rs);
+                DbUtility.close(rs);
             }
         }
     }
@@ -463,9 +457,8 @@
         synchronized (selectLengthSQL) {
             ResultSet rs = null;
             try {
-                Statement stmt = executeStmt(
-                        selectLengthSQL, new Object[]{parentDir, name});
-                rs = stmt.getResultSet();
+                rs = conHelper.exec(
+                        selectLengthSQL, new Object[]{parentDir, name}, false, 0);
                 if (!rs.next()) {
                     throw new FileSystemException("no such file: " + filePath);
                 }
@@ -475,7 +468,7 @@
                 log.error(msg, e);
                 throw new FileSystemException(msg, e);
             } finally {
-                closeResultSet(rs);
+                DbUtility.close(rs);
             }
         }
     }
@@ -497,8 +490,7 @@
         synchronized (selectChildCountSQL) {
             ResultSet rs = null;
             try {
-                Statement stmt = executeStmt(selectChildCountSQL, new Object[]{path});
-                rs = stmt.getResultSet();
+                rs = conHelper.exec(selectChildCountSQL, new Object[]{path}, false, 0);
                 if (!rs.next()) {
                     return false;
                 }
@@ -513,7 +505,7 @@
                 log.error(msg, e);
                 throw new FileSystemException(msg, e);
             } finally {
-                closeResultSet(rs);
+                DbUtility.close(rs);
             }
         }
     }
@@ -535,9 +527,8 @@
         synchronized (selectFileAndFolderNamesSQL) {
             ResultSet rs = null;
             try {
-                Statement stmt = executeStmt(
-                        selectFileAndFolderNamesSQL, new Object[]{folderPath});
-                rs = stmt.getResultSet();
+                rs = conHelper.exec(
+                        selectFileAndFolderNamesSQL, new Object[]{folderPath}, false, 0);
                 ArrayList<String> names = new ArrayList<String>();
                 while (rs.next()) {
                     String name = rs.getString(1);
@@ -554,7 +545,7 @@
                 log.error(msg, e);
                 throw new FileSystemException(msg, e);
             } finally {
-                closeResultSet(rs);
+                DbUtility.close(rs);
             }
         }
     }
@@ -576,9 +567,8 @@
         synchronized (selectFileNamesSQL) {
             ResultSet rs = null;
             try {
-                Statement stmt = executeStmt(
-                        selectFileNamesSQL, new Object[]{folderPath});
-                rs = stmt.getResultSet();
+                rs = conHelper.exec(
+                        selectFileNamesSQL, new Object[]{folderPath}, false, 0);
                 ArrayList<String> names = new ArrayList<String>();
                 while (rs.next()) {
                     names.add(rs.getString(1));
@@ -589,7 +579,7 @@
                 log.error(msg, e);
                 throw new FileSystemException(msg, e);
             } finally {
-                closeResultSet(rs);
+                DbUtility.close(rs);
             }
         }
     }
@@ -611,9 +601,8 @@
         synchronized (selectFolderNamesSQL) {
             ResultSet rs = null;
             try {
-                Statement stmt = executeStmt(
-                        selectFolderNamesSQL, new Object[]{folderPath});
-                rs = stmt.getResultSet();
+                rs = conHelper.exec(
+                        selectFolderNamesSQL, new Object[]{folderPath}, false, 0);
                 ArrayList<String> names = new ArrayList<String>();
                 while (rs.next()) {
                     String name = rs.getString(1);
@@ -630,7 +619,7 @@
                 log.error(msg, e);
                 throw new FileSystemException(msg, e);
             } finally {
-                closeResultSet(rs);
+                DbUtility.close(rs);
             }
         }
     }
@@ -651,11 +640,10 @@
         int count = 0;
         synchronized (updateLastModifiedSQL) {
             try {
-                Statement stmt = executeStmt(updateLastModifiedSQL, new Object[]{
+                count = conHelper.update(updateLastModifiedSQL, new Object[]{
                         new Long(System.currentTimeMillis()),
                         parentDir,
                         name});
-                count = stmt.getUpdateCount();
             } catch (SQLException e) {
                 String msg = "failed to touch file: " + filePath;
                 log.error(msg, e);
@@ -683,10 +671,9 @@
 
         synchronized (selectDataSQL) {
             try {
-                Statement stmt = executeStmt(
-                        selectDataSQL, new Object[]{parentDir, name});
+                final ResultSet rs = conHelper.exec(
+                        selectDataSQL, new Object[]{parentDir, name}, false, 0);
 
-                final ResultSet rs = stmt.getResultSet();
                 if (!rs.next()) {
                     throw new FileSystemException("no such file: " + filePath);
                 }
@@ -699,7 +686,7 @@
                     public void close() throws IOException {
                         super.close();
                         // close ResultSet
-                        closeResultSet(rs);
+                       DbUtility.close(rs);
                     }
                 };
             } catch (SQLException e) {
@@ -753,9 +740,9 @@
                             synchronized (updateDataSQL) {
                                 long length = tmpFile.length();
                                 in = new FileInputStream(tmpFile);
-                                executeStmt(updateDataSQL,
+                                conHelper.exec(updateDataSQL,
                                         new Object[]{
-                                            new SizedInputStream(in, length),
+                                            new StreamWrapper(in, length),
                                             new Long(System.currentTimeMillis()),
                                             new Long(length),
                                             parentDir,
@@ -766,11 +753,11 @@
                             synchronized (insertFileSQL) {
                                 long length = tmpFile.length();
                                 in = new FileInputStream(tmpFile);
-                                executeStmt(insertFileSQL,
+                                conHelper.exec(insertFileSQL,
                                         new Object[]{
                                             parentDir,
                                             name,
-                                            new SizedInputStream(in, length),
+                                            new StreamWrapper(in, length),
                                             new Long(System.currentTimeMillis()),
                                             new Long(length)
                                         });
@@ -850,9 +837,9 @@
                             synchronized (updateDataSQL) {
                                 long length = tmpFile.length();
                                 in = new FileInputStream(tmpFile);
-                                executeStmt(updateDataSQL,
+                                conHelper.exec(updateDataSQL,
                                         new Object[]{
-                                            new SizedInputStream(in, length),
+                                            new StreamWrapper(in, length),
                                             new Long(System.currentTimeMillis()),
                                             new Long(length),
                                             parentDir,
@@ -863,11 +850,11 @@
                             synchronized (insertFileSQL) {
                                 long length = tmpFile.length();
                                 in = new FileInputStream(tmpFile);
-                                executeStmt(insertFileSQL,
+                                conHelper.exec(insertFileSQL,
                                         new Object[]{
                                             parentDir,
                                             name,
-                                            new SizedInputStream(in, length),
+                                            new StreamWrapper(in, length),
                                             new Long(System.currentTimeMillis()),
                                             new Long(length)
                                         });
@@ -957,249 +944,6 @@
     //----------------------------------< misc. helper methods & overridables >
 
     /**
-     * Initializes the database connection used by this file system.
-     * <p>
-     * Subclasses should normally override the {@link #getConnection()}
-     * method instead of this one. The default implementation calls
-     * {@link #getConnection()} to get the database connection and disables
-     * the autocommit feature.
-     *
-     * @throws Exception if an error occurs
-     */
-    protected void initConnection() throws Exception {
-        con = getConnection();
-        // JCR-1013: Setter may fail unnecessarily on a managed connection
-        if (!con.getAutoCommit()) {
-            con.setAutoCommit(true);
-        }
-    }
-
-    /**
-     * Abstract factory method for creating a new database connection. This
-     * method is called by {@link #initConnection()} when the file system is
-     * started. The returned connection should come with the default JDBC
-     * settings, as the {@link #initConnection()} method will explicitly set
-     * the <code>autoCommit</code> and other properties as needed.
-     * <p>
-     * Note that the returned database connection is kept during the entire
-     * lifetime of the file system, after which it is closed by
-     * {@link #close()} using the {@link #closeConnection(Connection)} method.
-     *
-     * @return new connection
-     * @throws Exception if an error occurs
-     */
-    protected Connection getConnection() throws Exception {
-        throw new UnsupportedOperationException("Override in a subclass!");
-    }
-
-    /**
-     * Closes the given database connection. This method is called by
-     * {@link #close()} to close the connection acquired using
-     * {@link #getConnection()} when the file system was started.
-     * <p>
-     * The default implementation just calls the {@link Connection#close()}
-     * method of the given connection, but subclasses can override this
-     * method to provide more extensive database and connection cleanup.
-     *
-     * @param connection database connection
-     * @throws SQLException if an error occurs
-     */
-    protected void closeConnection(Connection connection) throws SQLException {
-        connection.close();
-    }
-
-    /**
-     * Re-establishes the database connection. This method is called by
-     * {@link #executeStmt(String, Object[])} after a <code>SQLException</code>
-     * had been encountered.
-     *
-     * @return true if the connection could be successfully re-established,
-     *         false otherwise.
-     */
-    protected synchronized boolean reestablishConnection() {
-        // in any case try to shut down current connection
-        // gracefully in order to avoid potential memory leaks
-
-        // close shared prepared statements
-        for (PreparedStatement prep : preparedStatements.values()) {
-            closeStatement(prep);
-        }
-        try {
-            closeConnection(con);
-        } catch (Exception ignore) {
-        }
-
-        // sleep for a while to give database a chance
-        // to restart before a reconnect is attempted
-
-        try {
-            Thread.sleep(SLEEP_BEFORE_RECONNECT);
-        } catch (InterruptedException ignore) {
-        }
-
-        // now try to re-establish connection
-
-        try {
-            initConnection();
-            initPreparedStatements();
-            return true;
-        } catch (Exception e) {
-            log.error("failed to re-establish connection", e);
-            // reconnect failed
-            return false;
-        }
-    }
-
-    /**
-     * Executes the given SQL statement with the specified parameters.
-     * If a <code>SQLException</code> is encountered <i>one</i> attempt is made
-     * to re-establish the database connection and re-execute the statement.
-     *
-     * @param sql    statement to execute
-     * @param params parameters to set
-     * @return the <code>Statement</code> object that had been executed
-     * @throws SQLException if an error occurs
-     */
-    protected Statement executeStmt(String sql, Object[] params)
-            throws SQLException {
-        int trials = 2;
-        while (true) {
-            PreparedStatement stmt = (PreparedStatement) preparedStatements.get(sql);
-            try {
-                for (int i = 0; i < params.length; i++) {
-                    if (params[i] instanceof SizedInputStream) {
-                        SizedInputStream in = (SizedInputStream) params[i];
-                        stmt.setBinaryStream(i + 1, in, (int) in.getSize());
-                    } else {
-                        stmt.setObject(i + 1, params[i]);
-                    }
-                }
-                stmt.execute();
-                resetStatement(stmt);
-                return stmt;
-            } catch (SQLException se) {
-                if (--trials == 0) {
-                    // no more trials, re-throw
-                    throw se;
-                }
-                log.warn("execute failed, about to reconnect...", se.getMessage());
-
-                // try to reconnect
-                if (reestablishConnection()) {
-                    // reconnect succeeded; check whether it's possible to
-                    // re-execute the prepared stmt with the given parameters
-                    for (int i = 0; i < params.length; i++) {
-                        if (params[i] instanceof SizedInputStream) {
-                            SizedInputStream in = (SizedInputStream) params[i];
-                            if (in.isConsumed()) {
-                                // we're unable to re-execute the prepared stmt
-                                // since an InputStream paramater has already
-                                // been 'consumed';
-                                // re-throw previous SQLException
-                                throw se;
-                            }
-                        }
-                    }
-
-                    // try again to execute the statement
-                    continue;
-                } else {
-                    // reconnect failed, re-throw previous SQLException
-                    throw se;
-                }
-            }
-        }
-    }
-
-    /**
-     * Makes sure that <code>schemaObjectPrefix</code> does only consist of
-     * characters that are allowed in names on the target database. Illegal
-     * characters will be escaped as necessary.
-     *
-     * @throws Exception if an error occurs
-     */
-    protected void prepareSchemaObjectPrefix() throws Exception {
-        DatabaseMetaData metaData = con.getMetaData();
-        String legalChars = metaData.getExtraNameCharacters();
-        legalChars += "ABCDEFGHIJKLMNOPQRSTUVWXZY0123456789_";
-
-        String prefix = schemaObjectPrefix.toUpperCase();
-        StringBuffer escaped = new StringBuffer();
-        for (int i = 0; i < prefix.length(); i++) {
-            char c = prefix.charAt(i);
-            if (legalChars.indexOf(c) == -1) {
-                escaped.append("_x");
-                String hex = Integer.toHexString(c);
-                escaped.append("0000".toCharArray(), 0, 4 - hex.length());
-                escaped.append(hex);
-                escaped.append("_");
-            } else {
-                escaped.append(c);
-            }
-        }
-        schemaObjectPrefix = escaped.toString();
-    }
-
-    /**
-     * Checks if the required schema objects exist and creates them if they
-     * don't exist yet.
-     *
-     * @throws Exception if an error occurs
-     */
-    protected void checkSchema() throws Exception {
-        DatabaseMetaData metaData = con.getMetaData();
-        String tableName = schemaObjectPrefix + "FSENTRY";
-        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) {
-            // read ddl from resources
-            InputStream in = DatabaseFileSystem.class.getResourceAsStream(schema + ".ddl");
-            if (in == null) {
-                String msg = "Configuration error: unknown schema '" + schema + "'";
-                log.debug(msg);
-                throw new RepositoryException(msg);
-            }
-            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
-            Statement stmt = con.createStatement();
-            try {
-                String sql = reader.readLine();
-                while (sql != null) {
-                    // Skip comments and empty lines
-                    if (!sql.startsWith("#") && sql.length() > 0) {
-                        // replace prefix variable
-                        sql = createSchemaSql(sql);
-                        stmt.executeUpdate(sql);
-                    }
-                    // read next sql stmt
-                    sql = reader.readLine();
-                }
-            } finally {
-                IOUtils.closeQuietly(in);
-                closeStatement(stmt);
-            }
-        }
-    }
-
-    /**
-     * Replace wildcards.
-     */
-    protected String createSchemaSql(String sql) {
-        sql = Text.replace(sql, SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix);
-        return sql;
-    }
-
-    /**
      * Builds the SQL statements
      */
     protected void buildSQLStatements() {
@@ -1293,51 +1037,6 @@
     }
 
     /**
-     * Initializes the map of prepared statements.
-     *
-     * @throws SQLException if an error occurs
-     */
-    protected void initPreparedStatements() throws SQLException {
-        preparedStatements.put(
-                selectExistSQL, con.prepareStatement(selectExistSQL));
-        preparedStatements.put(
-                selectFileExistSQL, con.prepareStatement(selectFileExistSQL));
-        preparedStatements.put(
-                selectFolderExistSQL, con.prepareStatement(selectFolderExistSQL));
-        preparedStatements.put(
-                selectChildCountSQL, con.prepareStatement(selectChildCountSQL));
-        preparedStatements.put(
-                selectDataSQL, con.prepareStatement(selectDataSQL));
-        preparedStatements.put(
-                selectLastModifiedSQL, con.prepareStatement(selectLastModifiedSQL));
-        preparedStatements.put(
-                selectLengthSQL, con.prepareStatement(selectLengthSQL));
-        preparedStatements.put(
-                selectFileNamesSQL, con.prepareStatement(selectFileNamesSQL));
-        preparedStatements.put(
-                selectFolderNamesSQL, con.prepareStatement(selectFolderNamesSQL));
-        preparedStatements.put(
-                selectFileAndFolderNamesSQL, con.prepareStatement(selectFileAndFolderNamesSQL));
-        preparedStatements.put(
-                deleteFileSQL, con.prepareStatement(deleteFileSQL));
-        preparedStatements.put(
-                deleteFolderSQL, con.prepareStatement(deleteFolderSQL));
-        preparedStatements.put(
-                insertFileSQL, con.prepareStatement(insertFileSQL));
-        preparedStatements.put(
-                insertFolderSQL, con.prepareStatement(insertFolderSQL));
-        preparedStatements.put(
-                updateDataSQL, con.prepareStatement(updateDataSQL));
-        preparedStatements.put(
-                updateLastModifiedSQL, con.prepareStatement(updateLastModifiedSQL));
-        preparedStatements.put(
-                copyFileSQL, con.prepareStatement(copyFileSQL));
-        preparedStatements.put(
-                copyFilesSQL, con.prepareStatement(copyFilesSQL));
-
-    }
-
-    /**
      * Verifies that the root file system entry exists. If it doesn't exist yet
      * it will be automatically created.
      *
@@ -1348,10 +1047,9 @@
         synchronized (selectFolderExistSQL) {
             ResultSet rs = null;
             try {
-                Statement stmt = executeStmt(
+                rs = conHelper.exec(
                         selectFolderExistSQL,
-                        new Object[]{FileSystem.SEPARATOR, ""});
-                rs = stmt.getResultSet();
+                        new Object[]{FileSystem.SEPARATOR, ""}, false, 0);
 
                 if (rs.next()) {
                     // root entry exists
@@ -1362,7 +1060,7 @@
                 log.error(msg, e);
                 throw new FileSystemException(msg, e);
             } finally {
-                closeResultSet(rs);
+                DbUtility.close(rs);
             }
         }
 
@@ -1390,7 +1088,7 @@
 
         synchronized (insertFolderSQL) {
             try {
-                executeStmt(
+                conHelper.exec(
                         insertFolderSQL,
                         new Object[]{
                                 parentDir,
@@ -1430,7 +1128,7 @@
 
         synchronized (copyFilesSQL) {
             try {
-                executeStmt(copyFilesSQL, new Object[]{destPath, srcPath});
+                conHelper.exec(copyFilesSQL, new Object[]{destPath, srcPath});
             } catch (SQLException e) {
                 String msg = "failed to copy file entries from " + srcPath + " to " + destPath;
                 log.error(msg, e);
@@ -1468,14 +1166,13 @@
         int count = 0;
         synchronized (copyFileSQL) {
             try {
-                Statement stmt = executeStmt(
+                count = conHelper.update(
                         copyFileSQL,
                         new Object[]{
                                 destParentDir,
                                 destName,
                                 srcParentDir,
                                 srcName});
-                count = stmt.getUpdateCount();
             } catch (SQLException e) {
                 String msg = "failed to copy file from " + srcPath + " to " + destPath;
                 log.error(msg, e);
@@ -1487,89 +1184,4 @@
             throw new FileSystemException("no such file: " + srcPath);
         }
     }
-
-    /**
-     * Resets the given <code>PreparedStatement</code> by clearing the parameters
-     * and warnings contained.
-     * <p/>
-     * NOTE: This method MUST be called in a synchronized context as neither
-     * this method nor the <code>PreparedStatement</code> instance on which it
-     * operates are thread safe.
-     *
-     * @param stmt The <code>PreparedStatement</code> to reset. If
-     *             <code>null</code> this method does nothing.
-     */
-    protected void resetStatement(PreparedStatement stmt) {
-        if (stmt != null) {
-            try {
-                stmt.clearParameters();
-                stmt.clearWarnings();
-            } catch (SQLException se) {
-                log.error("failed resetting PreparedStatement", se);
-            }
-        }
-    }
-
-    protected void closeResultSet(ResultSet rs) {
-        if (rs != null) {
-            try {
-                rs.close();
-            } catch (SQLException se) {
-                log.error("failed closing ResultSet", se);
-            }
-        }
-    }
-
-    protected void closeStatement(Statement stmt) {
-        if (stmt != null) {
-            try {
-                stmt.close();
-            } catch (SQLException se) {
-                log.error("failed closing Statement", se);
-            }
-        }
-    }
-
-    //--------------------------------------------------------< inner classes >
-
-    /**
-     * An input stream that knows its size.
-     */
-    class SizedInputStream extends FilterInputStream {
-        private final long size;
-        private boolean consumed;
-
-        SizedInputStream(InputStream in, long size) {
-            super(in);
-            this.size = size;
-        }
-
-        long getSize() {
-            return size;
-        }
-
-        boolean isConsumed() {
-            return consumed;
-        }
-
-        public int read() throws IOException {
-            consumed = true;
-            return super.read();
-        }
-
-        public long skip(long n) throws IOException {
-            consumed = true;
-            return super.skip(n);
-        }
-
-        public int read(byte[] b) throws IOException {
-            consumed = true;
-            return super.read(b);
-        }
-
-        public int read(byte[] b, int off, int len) throws IOException {
-            consumed = true;
-            return super.read(b, off, len);
-        }
-    }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java Wed Sep  2 05:11:45 2009
@@ -16,12 +16,9 @@
  */
 package org.apache.jackrabbit.core.fs.db;
 
-import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionFactory;
+import org.apache.jackrabbit.core.util.db.ConnectionFactory;
 
-import java.sql.Connection;
-import java.sql.SQLException;
-
-import javax.jcr.RepositoryException;
+import javax.sql.DataSource;
 
 /**
  * <code>DbFileSystem</code> is a generic JDBC-based <code>FileSystem</code>
@@ -199,12 +196,10 @@
     //--------------------------------------------------< DatabaseFileSystem >
 
     /**
-     * Initialize the JDBC connection.
-     *
-     * @throws SQLException if an error occurs
+     * {@inheritDoc}
      */
-    protected Connection getConnection() throws RepositoryException, SQLException {
-        return ConnectionFactory.getConnection(driver, url, user, password);
+    @Override
+    protected final DataSource getDataSource() throws Exception {
+        return ConnectionFactory.getDataSource(getDriver(), getUrl(), getUser(), getPassword());
     }
-
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystem.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystem.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystem.java Wed Sep  2 05:11:45 2009
@@ -16,12 +16,15 @@
  */
 package org.apache.jackrabbit.core.fs.db;
 
+import org.apache.jackrabbit.core.fs.FileSystemException;
+import org.apache.jackrabbit.core.util.db.ConnectionHelper;
+import org.apache.jackrabbit.core.util.db.DerbyConnectionHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.sql.DriverManager;
 import java.sql.SQLException;
-import java.sql.Connection;
+
+import javax.sql.DataSource;
 
 /**
  * <code>DerbyFileSystem</code> is a JDBC-based <code>FileSystem</code>
@@ -56,11 +59,6 @@
 public class DerbyFileSystem extends DbFileSystem {
 
     /**
-     * Logger instance
-     */
-    private static Logger log = LoggerFactory.getLogger(DerbyFileSystem.class);
-
-    /**
      * Flag indicating whether this derby database should be shutdown on close.
      */
     protected boolean shutdownOnClose;
@@ -89,46 +87,24 @@
     //-----------------------------------------------< DbFileSystem overrides >
 
     /**
-     * Closes the given connection and shuts down the embedded Derby
-     * database if <code>shutdownOnClose</code> is set to true.
-     *
-     * @param connection database connection
-     * @throws SQLException if an error occurs
-     * @see DatabaseFileSystem#closeConnection(Connection)
+     * {@inheritDoc}
      */
-    protected void closeConnection(Connection connection) throws SQLException {
-        // prepare connection url for issuing shutdown command
-        String url;
-        try {
-            url = connection.getMetaData().getURL();
-        } catch (SQLException e) {
-            // JCR-1557: embedded derby db probably already shut down;
-            // this happens when configuring multiple FS/PM instances
-            // to use the same embedded derby db instance.
-            log.debug("failed to retrieve connection url: embedded db probably already shut down", e);
-            return;
-        }
-        int pos = url.lastIndexOf(';');
-        if (pos != -1) {
-            // strip any attributes from connection url
-            url = url.substring(0, pos);
-        }
-        url += ";shutdown=true";
-
-        // we have to reset the connection to 'autoCommit=true' before closing it;
-        // otherwise Derby would mysteriously complain about some pending uncommitted
-        // changes which can't possibly be true.
-        // @todo further investigate
-        connection.setAutoCommit(true);
-        connection.close();
+    @Override
+    protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception {
+        return new DerbyConnectionHelper(dataSrc);
+    }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close() throws FileSystemException {
+        super.close();
         if (shutdownOnClose) {
-            // now it's safe to shutdown the embedded Derby database
             try {
-                DriverManager.getConnection(url);
+                ((DerbyConnectionHelper) conHelper).shutDown(driver);
             } catch (SQLException e) {
-                // a shutdown command always raises a SQLException
-                log.info(e.getMessage());
+                throw new FileSystemException("failed to shutdown Derby", e);
             }
         }
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java Wed Sep  2 05:11:45 2009
@@ -17,10 +17,7 @@
 package org.apache.jackrabbit.core.fs.db;
 
 import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.SQLException;
 
 /**
  * @deprecated
@@ -68,17 +65,11 @@
     //--------------------------------------------------< DatabaseFileSystem >
 
     /**
-     * Returns a JDBC connection from a {@link DataSource} acquired from JNDI
-     * with the configured data source location.
-     *
-     * @return new database connection
-     * @throws NamingException if the given data source location does not exist
-     * @throws SQLException if a database access error occurs
+     * {@inheritDoc}
      */
-    protected Connection getConnection() throws NamingException, SQLException {
+    @Override
+    protected DataSource getDataSource() throws Exception {
         InitialContext ic = new InitialContext();
-        DataSource dataSource = (DataSource) ic.lookup(dataSourceLocation);
-        return dataSource.getConnection();
+        return (DataSource) ic.lookup(dataSourceLocation);
     }
-
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/MSSqlFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/MSSqlFileSystem.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/MSSqlFileSystem.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/MSSqlFileSystem.java Wed Sep  2 05:11:45 2009
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.core.fs.db;
 
-import org.apache.jackrabbit.util.Text;
+import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
 
 /**
  * <code>MSSqlFileSystem</code> is a JDBC-based <code>FileSystem</code>
@@ -89,8 +89,12 @@
         initialized = false;
     }
 
-   protected String createSchemaSql(String sql) {
-       return Text.replace(
-               super.createSchemaSql(sql), TABLE_SPACE_VARIABLE, tableSpace);
-  }
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected CheckSchemaOperation createCheckSchemaOperation() {
+        return super.createCheckSchemaOperation().addVariableReplacement(
+            CheckSchemaOperation.TABLE_SPACE_VARIABLE, tableSpace);
+    }
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java Wed Sep  2 05:11:45 2009
@@ -16,33 +16,11 @@
  */
 package org.apache.jackrabbit.core.fs.db;
 
-import org.apache.commons.io.IOUtils;
-import org.apache.jackrabbit.util.Text;
-import org.apache.jackrabbit.util.TransientFileFactory;
-import org.apache.jackrabbit.core.fs.FileSystemException;
-import org.apache.jackrabbit.core.fs.FileSystemPathUtil;
-import org.apache.jackrabbit.core.fs.RandomAccessOutputStream;
-import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.jcr.RepositoryException;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.sql.Blob;
-import java.sql.Connection;
-import java.io.InputStream;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.IOException;
-import java.io.File;
-import java.io.FilterOutputStream;
-import java.io.FileOutputStream;
-import java.io.FileInputStream;
-import java.io.RandomAccessFile;
-import java.lang.reflect.Method;
+import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
+import org.apache.jackrabbit.core.util.db.ConnectionHelper;
+import org.apache.jackrabbit.core.util.db.Oracle10R1ConnectionHelper;
+
+import javax.sql.DataSource;
 
 /**
  * <code>OracleFileSystem</code> is a JDBC-based <code>FileSystem</code>
@@ -77,19 +55,6 @@
  */
 public class OracleFileSystem extends DbFileSystem {
 
-    /**
-     * Logger instance
-     */
-    private static Logger log = LoggerFactory.getLogger(OracleFileSystem.class);
-
-    private Class< ? > blobClass;
-    private Integer durationSessionConstant;
-    private Integer modeReadWriteConstant;
-
-    /** the variable for the Oracle table space */
-    public static final String TABLE_SPACE_VARIABLE =
-        "${tableSpace}";
-
     /** the Oracle table space to use */
     protected String tableSpace;
 
@@ -117,136 +82,36 @@
      * @param tableSpace the Oracle table space.
      */
     public void setTableSpace(String tableSpace) {
-        if (tableSpace != null) {
-            this.tableSpace = tableSpace.trim();
+        if (tableSpace != null && tableSpace.trim().length() > 0) {
+            this.tableSpace = "tablespace " + tableSpace.trim();
         } else {
-            this.tableSpace = null;
+            this.tableSpace = "";
         }
     }
 
     //-----------------------------------------< DatabaseFileSystem overrides >
-    /**
-     * {@inheritDoc}
-     * <p/>
-     * Retrieve the <code>oracle.sql.BLOB</code> class via reflection, and
-     * initialize the values for the <code>DURATION_SESSION</code> and
-     * <code>MODE_READWRITE</code> constants defined there.
-     * @see oracle.sql.BLOB#DURATION_SESSION
-     * @see oracle.sql.BLOB#MODE_READWRITE
-     */
-    public void init() throws FileSystemException {
-        super.init();
-
-        // initialize oracle.sql.BLOB class & constants
-
-        // use the Connection object for using the exact same
-        // class loader that the Oracle driver was loaded with
-        try {
-            blobClass = con.getClass().getClassLoader().loadClass("oracle.sql.BLOB");
-            durationSessionConstant =
-                    new Integer(blobClass.getField("DURATION_SESSION").getInt(null));
-            modeReadWriteConstant =
-                    new Integer(blobClass.getField("MODE_READWRITE").getInt(null));
-        } catch (Exception e) {
-            String msg = "failed to load/introspect oracle.sql.BLOB";
-            log.error(msg, e);
-            throw new FileSystemException(msg, e);
-        }
-    }
 
     /**
-     * Makes sure that <code>schemaObjectPrefix</code> does only consist of
-     * characters that are allowed in names on the target database. Illegal
-     * characters will be replaced by '_'.
-     *
-     * @throws Exception if an error occurs
+     * {@inheritDoc}
      */
     @Override
-    protected void prepareSchemaObjectPrefix() throws Exception {
-        DatabaseMetaData metaData = con.getMetaData();
-        String legalChars = metaData.getExtraNameCharacters();
-        legalChars += "ABCDEFGHIJKLMNOPQRSTUVWXZY0123456789_";
-
-        String prefix = schemaObjectPrefix.toUpperCase();
-        StringBuffer escaped = new StringBuffer();
-        for (int i = 0; i < prefix.length(); i++) {
-            char c = prefix.charAt(i);
-            if (legalChars.indexOf(c) == -1) {
-                escaped.append("_");
-            } else {
-                escaped.append(c);
-            }
-        }
-        schemaObjectPrefix = escaped.toString();
+    protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception {
+        Oracle10R1ConnectionHelper helper = new Oracle10R1ConnectionHelper(dataSrc);
+        helper.init();
+        return helper;
     }
 
     /**
      * {@inheritDoc}
-     * <p/>
-     * Overridden in order to support multiple oracle schemas. Note that
-     * schema names in Oracle correspond to the username of the connection.
-     * See http://issues.apache.org/jira/browse/JCR-582
-     *
-     * @throws Exception if an error occurs
      */
-    protected void checkSchema() throws Exception {
-        DatabaseMetaData metaData = con.getMetaData();
-        String tableName = schemaObjectPrefix + "FSENTRY";
-        if (metaData.storesLowerCaseIdentifiers()) {
-            tableName = tableName.toLowerCase();
-        } else if (metaData.storesUpperCaseIdentifiers()) {
-            tableName = tableName.toUpperCase();
-        }
-        String userName = metaData.getUserName();
-
-        ResultSet rs = metaData.getTables(null, userName, tableName, null);
-        boolean schemaExists;
-        try {
-            schemaExists = rs.next();
-        } finally {
-            rs.close();
-        }
-
-        if (!schemaExists) {
-            // read ddl from resources
-            InputStream in = OracleFileSystem.class.getResourceAsStream(schema + ".ddl");
-            if (in == null) {
-                String msg = "Configuration error: unknown schema '" + schema + "'";
-                log.debug(msg);
-                throw new RepositoryException(msg);
-            }
-            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
-            Statement stmt = con.createStatement();
-            try {
-                String sql = reader.readLine();
-                while (sql != null) {
-                    // Skip comments and empty lines
-                    if (!sql.startsWith("#") && sql.length() > 0) {
-                        // replace prefix variable
-                        sql = Text.replace(sql, SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix);
-
-                        // set the tablespace if it is defined
-                        String tspace;
-                        if (tableSpace == null || "".equals(tableSpace)) {
-                            tspace = "";
-                        } else {
-                            tspace = "tablespace " + tableSpace;
-                        }
-                        sql = Text.replace(sql, TABLE_SPACE_VARIABLE, tspace).trim();
-
-                        // execute sql stmt
-                        stmt.executeUpdate(sql);
-                    }
-                    // read next sql stmt
-                    sql = reader.readLine();
-                }
-            } finally {
-                IOUtils.closeQuietly(in);
-                closeStatement(stmt);
-            }
-        }
+    @Override
+    protected CheckSchemaOperation createCheckSchemaOperation() {
+        return super.createCheckSchemaOperation().addVariableReplacement(
+            CheckSchemaOperation.TABLE_SPACE_VARIABLE, tableSpace);
     }
 
+    //-----------------------------------------< DatabaseFileSystem overrides >
+    
     /**
      * Builds the SQL statements
      * <p/>
@@ -355,273 +220,4 @@
                 + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
                 + "and FSENTRY_LENGTH is not null";
     }
-
-
-    /**
-     * {@inheritDoc}
-     * <p/>
-     * Overridden because we need to use <code>oracle.sql.BLOB</code>
-     * and <code>PreparedStatement#setBlob</code> instead of just
-     * <code>PreparedStatement#setBinaryStream</code>.
-     */
-    public OutputStream getOutputStream(final String filePath) throws FileSystemException {
-        if (!initialized) {
-            throw new IllegalStateException("not initialized");
-        }
-
-        FileSystemPathUtil.checkFormat(filePath);
-
-        final String parentDir = FileSystemPathUtil.getParentDir(filePath);
-        final String name = FileSystemPathUtil.getName(filePath);
-
-        if (!isFolder(parentDir)) {
-            throw new FileSystemException("path not found: " + parentDir);
-        }
-
-        if (isFolder(filePath)) {
-            throw new FileSystemException("path denotes folder: " + filePath);
-        }
-
-        try {
-            TransientFileFactory fileFactory = TransientFileFactory.getInstance();
-            final File tmpFile = fileFactory.createTransientFile("bin", null, null);
-
-            return new FilterOutputStream(new FileOutputStream(tmpFile)) {
-
-                public void write(byte[] bytes, int off, int len) throws IOException {
-                    out.write(bytes, off, len);
-                }
-
-                public void close() throws IOException {
-                    out.flush();
-                    ((FileOutputStream) out).getFD().sync();
-                    out.close();
-
-                    InputStream in = null;
-                    Blob blob = null;
-                    try {
-                        if (isFile(filePath)) {
-                            synchronized (updateDataSQL) {
-                                long length = tmpFile.length();
-                                in = new FileInputStream(tmpFile);
-                                blob = createTemporaryBlob(in);
-                                executeStmt(updateDataSQL,
-                                        new Object[]{
-                                            blob,
-                                            new Long(System.currentTimeMillis()),
-                                            new Long(length),
-                                            parentDir,
-                                            name
-                                        });
-                            }
-                        } else {
-                            synchronized (insertFileSQL) {
-                                long length = tmpFile.length();
-                                in = new FileInputStream(tmpFile);
-                                blob = createTemporaryBlob(in);
-                                executeStmt(insertFileSQL,
-                                        new Object[]{
-                                            parentDir,
-                                            name,
-                                            blob,
-                                            new Long(System.currentTimeMillis()),
-                                            new Long(length)
-                                        });
-                            }
-                        }
-                    } catch (Exception e) {
-                        IOException ioe = new IOException(e.getMessage());
-                        ioe.initCause(e);
-                        throw ioe;
-                    } finally {
-                        if (blob != null) {
-                            try {
-                                freeTemporaryBlob(blob);
-                            } catch (Exception e1) {
-                            }
-                        }
-                        IOUtils.closeQuietly(in);
-                        // temp file can now safely be removed
-                        tmpFile.delete();
-                    }
-                }
-            };
-        } catch (Exception e) {
-            String msg = "failed to open output stream to file: " + filePath;
-            log.error(msg, e);
-            throw new FileSystemException(msg, e);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public RandomAccessOutputStream getRandomAccessOutputStream(
-            final String filePath)
-            throws FileSystemException, UnsupportedOperationException {
-        if (!initialized) {
-            throw new IllegalStateException("not initialized");
-        }
-
-        FileSystemPathUtil.checkFormat(filePath);
-
-        final String parentDir = FileSystemPathUtil.getParentDir(filePath);
-        final String name = FileSystemPathUtil.getName(filePath);
-
-        if (!isFolder(parentDir)) {
-            throw new FileSystemException("path not found: " + parentDir);
-        }
-
-        if (isFolder(filePath)) {
-            throw new FileSystemException("path denotes folder: " + filePath);
-        }
-
-        try {
-            TransientFileFactory fileFactory = TransientFileFactory.getInstance();
-            final File tmpFile = fileFactory.createTransientFile("bin", null, null);
-
-            // @todo FIXME use java.sql.Blob
-
-            if (isFile(filePath)) {
-                // file entry exists, spool contents to temp file first
-                InputStream in = getInputStream(filePath);
-                OutputStream out = new FileOutputStream(tmpFile);
-                try {
-                    IOUtils.copy(in, out);
-                } finally {
-                    out.close();
-                    in.close();
-                }
-            }
-
-            return new RandomAccessOutputStream() {
-                private final RandomAccessFile raf =
-                    new RandomAccessFile(tmpFile, "rw");
-
-                public void close() throws IOException {
-                    raf.close();
-
-                    InputStream in = null;
-                    Blob blob = null;
-                    try {
-                        if (isFile(filePath)) {
-                            synchronized (updateDataSQL) {
-                                long length = tmpFile.length();
-                                in = new FileInputStream(tmpFile);
-                                blob = createTemporaryBlob(in);
-                                executeStmt(updateDataSQL,
-                                        new Object[]{
-                                            blob,
-                                            new Long(System.currentTimeMillis()),
-                                            new Long(length),
-                                            parentDir,
-                                            name
-                                        });
-                            }
-                        } else {
-                            synchronized (insertFileSQL) {
-                                long length = tmpFile.length();
-                                in = new FileInputStream(tmpFile);
-                                blob = createTemporaryBlob(in);
-                                executeStmt(insertFileSQL,
-                                        new Object[]{
-                                            parentDir,
-                                            name,
-                                            blob,
-                                            new Long(System.currentTimeMillis()),
-                                            new Long(length)
-                                        });
-                            }
-                        }
-                    } catch (Exception e) {
-                        IOException ioe = new IOException(e.getMessage());
-                        ioe.initCause(e);
-                        throw ioe;
-                    } finally {
-                        if (blob != null) {
-                            try {
-                                freeTemporaryBlob(blob);
-                            } catch (Exception e1) {
-                            }
-                        }
-                        IOUtils.closeQuietly(in);
-                        // temp file can now safely be removed
-                        tmpFile.delete();
-                    }
-                }
-
-                public void seek(long position) throws IOException {
-                    raf.seek(position);
-                }
-
-                public void write(int b) throws IOException {
-                    raf.write(b);
-                }
-
-                public void flush() /*throws IOException*/ {
-                    // nop
-                }
-
-                public void write(byte[] b) throws IOException {
-                    raf.write(b);
-                }
-
-                public void write(byte[] b, int off, int len) throws IOException {
-                    raf.write(b, off, len);
-                }
-            };
-        } catch (Exception e) {
-            String msg = "failed to open output stream to file: " + filePath;
-            log.error(msg, e);
-            throw new FileSystemException(msg, e);
-        }
-    }
-
-    //----------------------------------------< oracle-specific blob handling >
-    /**
-     * Creates a temporary oracle.sql.BLOB instance via reflection and spools
-     * the contents of the specified stream.
-     */
-    protected Blob createTemporaryBlob(InputStream in) throws Exception {
-        /*
-        BLOB blob = BLOB.createTemporary(con, false, BLOB.DURATION_SESSION);
-        blob.open(BLOB.MODE_READWRITE);
-        OutputStream out = blob.getBinaryOutputStream();
-        ...
-        out.flush();
-        out.close();
-        blob.close();
-        return blob;
-        */
-        Method createTemporary = blobClass.getMethod("createTemporary",
-                new Class[]{Connection.class, Boolean.TYPE, Integer.TYPE});
-        Object blob = createTemporary.invoke(null,
-                new Object[]{ConnectionFactory.unwrap(con), Boolean.FALSE, durationSessionConstant});
-        Method open = blobClass.getMethod("open", new Class[]{Integer.TYPE});
-        open.invoke(blob, new Object[]{modeReadWriteConstant});
-        Method getBinaryOutputStream =
-                blobClass.getMethod("getBinaryOutputStream", new Class[0]);
-        OutputStream out = (OutputStream) getBinaryOutputStream.invoke(blob);
-        try {
-            IOUtils.copy(in, out);
-        } finally {
-            try {
-                out.flush();
-            } catch (IOException ioe) {
-            }
-            out.close();
-        }
-        Method close = blobClass.getMethod("close", new Class[0]);
-        close.invoke(blob);
-        return (Blob) blob;
-    }
-
-    /**
-     * Frees a temporary oracle.sql.BLOB instance via reflection.
-     */
-    protected void freeTemporaryBlob(Object blob) throws Exception {
-        // blob.freeTemporary();
-        Method freeTemporary = blobClass.getMethod("freeTemporary", new Class[0]);
-        freeTemporary.invoke(blob);
-    }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java Wed Sep  2 05:11:45 2009
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.core.journal;
 
-import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionFactory;
+import org.apache.jackrabbit.core.util.db.ConnectionFactory;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java Wed Sep  2 05:11:45 2009
@@ -30,9 +30,7 @@
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import javax.jcr.RepositoryException;
 import javax.sql.DataSource;
@@ -45,14 +43,9 @@
 import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.persistence.PMContext;
 import org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding;
-import org.apache.jackrabbit.core.persistence.bundle.util.CheckSchemaOperation;
-import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionFactory;
-import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionHelper;
 import org.apache.jackrabbit.core.persistence.bundle.util.DbNameIndex;
-import org.apache.jackrabbit.core.persistence.bundle.util.DbUtility;
 import org.apache.jackrabbit.core.persistence.bundle.util.ErrorHandling;
 import org.apache.jackrabbit.core.persistence.bundle.util.NodePropBundle;
-import org.apache.jackrabbit.core.persistence.bundle.util.StreamWrapper;
 import org.apache.jackrabbit.core.persistence.util.BLOBStore;
 import org.apache.jackrabbit.core.persistence.util.FileSystemBLOBStore;
 import org.apache.jackrabbit.core.persistence.util.Serializer;
@@ -61,6 +54,11 @@
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
 import org.apache.jackrabbit.core.state.NodeReferences;
 import org.apache.jackrabbit.core.util.StringIndex;
+import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
+import org.apache.jackrabbit.core.util.db.ConnectionFactory;
+import org.apache.jackrabbit.core.util.db.ConnectionHelper;
+import org.apache.jackrabbit.core.util.db.DbUtility;
+import org.apache.jackrabbit.core.util.db.StreamWrapper;
 import org.apache.jackrabbit.uuid.UUID;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java Wed Sep  2 05:11:45 2009
@@ -17,8 +17,8 @@
 package org.apache.jackrabbit.core.persistence.bundle;
 
 import org.apache.jackrabbit.core.persistence.PMContext;
-import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionHelper;
-import org.apache.jackrabbit.core.persistence.bundle.util.DerbyConnectionHelper;
+import org.apache.jackrabbit.core.util.db.ConnectionHelper;
+import org.apache.jackrabbit.core.util.db.DerbyConnectionHelper;
 
 import java.sql.Connection;
 import java.sql.SQLException;

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MSSqlPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MSSqlPersistenceManager.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MSSqlPersistenceManager.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MSSqlPersistenceManager.java Wed Sep  2 05:11:45 2009
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.core.persistence.bundle;
 
-import org.apache.jackrabbit.core.persistence.bundle.util.CheckSchemaOperation;
+import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
 
 /**
  * Extends the {@link BundleDbPersistenceManager} by MS-SQL specific code. <p/> Configuration:<br>
@@ -24,8 +24,7 @@
  * <li>&lt;param name="{@link #setBundleCacheSize(String) bundleCacheSize}" value="8"/>
  * <li>&lt;param name="{@link #setConsistencyCheck(String) consistencyCheck}" value="false"/>
  * <li>&lt;param name="{@link #setMinBlobSize(String) minBlobSize}" value="16384"/>
- * <li>&lt;param name="{@link #setDriver(String) driver}
- * " value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
+ * <li>&lt;param name="{@link #setDriver(String) driver}" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
  * <li>&lt;param name="{@link #setUrl(String) url}" value=""/>
  * <li>&lt;param name="{@link #setUser(String) user}" value=""/>
  * <li>&lt;param name="{@link #setPassword(String) password}" value=""/>

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java Wed Sep  2 05:11:45 2009
@@ -18,8 +18,8 @@
 
 import javax.sql.DataSource;
 
-import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionHelper;
-import org.apache.jackrabbit.core.persistence.bundle.util.Oracle10R1ConnectionHelper;
+import org.apache.jackrabbit.core.util.db.ConnectionHelper;
+import org.apache.jackrabbit.core.util.db.Oracle10R1ConnectionHelper;
 
 /**
  * <code>OracleLegacyPersistenceManager</code> provides support for Oracle jdbc drivers prior to version 10

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java Wed Sep  2 05:11:45 2009
@@ -21,11 +21,11 @@
 import javax.sql.DataSource;
 
 import org.apache.jackrabbit.core.persistence.PMContext;
-import org.apache.jackrabbit.core.persistence.bundle.util.CheckSchemaOperation;
-import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionHelper;
 import org.apache.jackrabbit.core.persistence.bundle.util.DbNameIndex;
 import org.apache.jackrabbit.core.persistence.bundle.util.NGKDbNameIndex;
-import org.apache.jackrabbit.core.persistence.bundle.util.OracleConnectionHelper;
+import org.apache.jackrabbit.core.util.db.CheckSchemaOperation;
+import org.apache.jackrabbit.core.util.db.ConnectionHelper;
+import org.apache.jackrabbit.core.util.db.OracleConnectionHelper;
 
 /**
  * Extends the {@link BundleDbPersistenceManager} by Oracle specific code. <p/> Configuration:<br>

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/PostgreSQLPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/PostgreSQLPersistenceManager.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/PostgreSQLPersistenceManager.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/PostgreSQLPersistenceManager.java Wed Sep  2 05:11:45 2009
@@ -24,11 +24,11 @@
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.persistence.PMContext;
 import org.apache.jackrabbit.core.persistence.bundle.util.DbNameIndex;
-import org.apache.jackrabbit.core.persistence.bundle.util.DbUtility;
 import org.apache.jackrabbit.core.persistence.bundle.util.NodePropBundle;
 import org.apache.jackrabbit.core.persistence.bundle.util.PostgreSQLNameIndex;
 import org.apache.jackrabbit.core.persistence.bundle.util.TrackingInputStream;
 import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.util.db.DbUtility;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -121,5 +121,4 @@
            DbUtility.close(rs);
         }
     }
-
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java Wed Sep  2 05:11:45 2009
@@ -27,6 +27,7 @@
 
 import javax.jcr.RepositoryException;
 
+import org.apache.jackrabbit.core.util.db.ConnectionFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbNameIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbNameIndex.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbNameIndex.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbNameIndex.java Wed Sep  2 05:11:45 2009
@@ -21,6 +21,8 @@
 import java.util.HashMap;
 
 import org.apache.jackrabbit.core.util.StringIndex;
+import org.apache.jackrabbit.core.util.db.ConnectionHelper;
+import org.apache.jackrabbit.core.util.db.DbUtility;
 
 /**
  * Implements a {@link StringIndex} that stores and retrieves the names from a

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NGKDbNameIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NGKDbNameIndex.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NGKDbNameIndex.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NGKDbNameIndex.java Wed Sep  2 05:11:45 2009
@@ -19,6 +19,8 @@
 import java.sql.SQLException;
 import java.sql.Statement;
 
+import org.apache.jackrabbit.core.util.db.ConnectionHelper;
+
 /**
  * Same as {@link DbNameIndex} but does not make use of the
  * {@link Statement#RETURN_GENERATED_KEYS} feature as it might not be provided

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/PostgreSQLNameIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/PostgreSQLNameIndex.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/PostgreSQLNameIndex.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/PostgreSQLNameIndex.java Wed Sep  2 05:11:45 2009
@@ -19,6 +19,9 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import org.apache.jackrabbit.core.util.db.ConnectionHelper;
+import org.apache.jackrabbit.core.util.db.DbUtility;
+
 /**
  * Same as {@link DbNameIndex} but does not make use of the
  * {@link java.sql.Statement#RETURN_GENERATED_KEYS} feature as it is not

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java?rev=810362&r1=810361&r2=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java Wed Sep  2 05:11:45 2009
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.core.persistence.db;
 
-import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionFactory;
+import org.apache.jackrabbit.core.util.db.ConnectionFactory;
 
 import java.sql.Connection;
 import java.sql.SQLException;

Copied: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/CheckSchemaOperation.java (from r803244, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/CheckSchemaOperation.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/CheckSchemaOperation.java?p2=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/CheckSchemaOperation.java&p1=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/CheckSchemaOperation.java&r1=803244&r2=810362&rev=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/CheckSchemaOperation.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/CheckSchemaOperation.java Wed Sep  2 05:11:45 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.core.persistence.bundle.util;
+package org.apache.jackrabbit.core.util.db;
 
 import java.io.BufferedReader;
 import java.io.IOException;



Mime
View raw message