jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r391012 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db: DB2FileSystem.java DatabaseFileSystem.java DbFileSystem.java JNDIDatabaseFileSystem.java
Date Mon, 03 Apr 2006 11:30:24 GMT
Author: tripod
Date: Mon Apr  3 04:30:18 2006
New Revision: 391012

URL: http://svn.apache.org/viewcvs?rev=391012&view=rev
Log:
[JCR-384] Changes of JCR-313 introduced db-transaction problem

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DB2FileSystem.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DB2FileSystem.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DB2FileSystem.java?rev=391012&r1=391011&r2=391012&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DB2FileSystem.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DB2FileSystem.java
Mon Apr  3 04:30:18 2006
@@ -15,9 +15,9 @@
  */
 package org.apache.jackrabbit.core.fs.db;
 
-import org.apache.jackrabbit.core.fs.FileSystemException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.sql.SQLException;
+import java.util.LinkedList;
+import java.util.List;
 
 /**
  * <code>DB2FileSystem</code> is a JDBC-based <code>FileSystem</code>
@@ -40,7 +40,7 @@
  * <p/>
  * The following is a fragment from a sample configuration:
  * <pre>
- *   &lt;FileSystem class="org.apache.jackrabbit.core.fs.db.DB2FileSystem"&gt;
+ *   &lt;FileSystem class="com.day.crx.core.fs.db.DB2FileSystem"&gt;
  *       &lt;param name="url" value="jdbc:db2:test"/&gt;
  *       &lt;param name="schemaObjectPrefix" value="rep_"/&gt;
  *   &lt;/FileSystem&gt;
@@ -49,11 +49,6 @@
 public class DB2FileSystem extends DbFileSystem {
 
     /**
-     * Logger instance
-     */
-    private static Logger log = LoggerFactory.getLogger(DB2FileSystem.class);
-
-    /**
      * Creates a new <code>DB2FileSystem</code> instance.
      */
     public DB2FileSystem() {
@@ -74,119 +69,96 @@
      * explicitly typed using <code>cast(? as type_name)</code> some statements
      * had to be changed accordingly.
      */
-    public void init() throws FileSystemException {
-        if (initialized) {
-            throw new IllegalStateException("already initialized");
-        }
-
-        try {
-            // setup jdbc connection
-            con = getConnection();
-            con.setAutoCommit(false);
-
-            // make sure schemaObjectPrefix consists of legal name characters only
-            prepareSchemaObjectPrefix();
-
-            // check if schema objects exist and create them if necessary
-            checkSchema();
-
-            // prepare statements
-            insertFileStmt = con.prepareStatement("insert into "
-                    + schemaObjectPrefix + "FSENTRY "
-                    + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
-                    + "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
-                    + "values (?, ?, ?, ?, ?)");
-
-            insertFolderStmt = con.prepareStatement("insert into "
-                    + schemaObjectPrefix + "FSENTRY "
-                    + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_LASTMOD, FSENTRY_LENGTH) "
-                    + "values (?, ?, ?, 0)");
-
-            updateDataStmt = con.prepareStatement("update "
-                    + schemaObjectPrefix + "FSENTRY "
-                    + "set FSENTRY_DATA = ?, FSENTRY_LASTMOD = ?, FSENTRY_LENGTH = ? "
-                    + "where FSENTRY_PATH = ? and FSENTRY_NAME = ? "
-                    + "and FSENTRY_DATA is not null");
-
-            updateLastModifiedStmt = con.prepareStatement("update "
-                    + schemaObjectPrefix + "FSENTRY set FSENTRY_LASTMOD = ? "
-                    + "where FSENTRY_PATH = ? and FSENTRY_NAME = ? "
-                    + "and FSENTRY_DATA is not null");
-
-            selectExistStmt = con.prepareStatement("select 1 from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ?");
-
-            selectFileExistStmt = con.prepareStatement("select 1 from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
-
-            selectFolderExistStmt = con.prepareStatement("select 1 from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ? and FSENTRY_DATA is null");
-
-            selectFileNamesStmt = con.prepareStatement("select FSENTRY_NAME from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_DATA is not null");
-
-            selectFolderNamesStmt = con.prepareStatement("select FSENTRY_NAME from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_DATA is null");
-
-            selectFileAndFolderNamesStmt = con.prepareStatement("select FSENTRY_NAME from
"
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ?");
-
-            selectChildCountStmt = con.prepareStatement("select count(FSENTRY_NAME) from
"
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ?  ");
-
-            selectDataStmt = con.prepareStatement("select FSENTRY_DATA from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
-
-            selectLastModifiedStmt = con.prepareStatement("select FSENTRY_LASTMOD from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ?");
-
-            selectLengthStmt = con.prepareStatement("select FSENTRY_LENGTH from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
-
-            deleteFileStmt = con.prepareStatement("delete from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
-
-            deleteFolderStmt = con.prepareStatement("delete from "
-                    + schemaObjectPrefix + "FSENTRY where "
-                    + "(FSENTRY_PATH = ? and FSENTRY_NAME = ? and FSENTRY_DATA is null) "
-                    + "or (FSENTRY_PATH = ?) "
-                    + "or (FSENTRY_PATH like ?) ");
-
-            copyFileStmt = con.prepareStatement("insert into "
-                    + schemaObjectPrefix + "FSENTRY "
-                    + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
-                    + "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
-                    + "select cast(? as varchar(745)), cast(? as varchar(255)), FSENTRY_DATA,
"
-                    + "FSENTRY_LASTMOD, FSENTRY_LENGTH from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
-
-            copyFilesStmt = con.prepareStatement("insert into "
-                    + schemaObjectPrefix + "FSENTRY "
-                    + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
-                    + "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
-                    + "select cast(? as varchar(745)), FSENTRY_NAME, FSENTRY_DATA, "
-                    + "FSENTRY_LASTMOD, FSENTRY_LENGTH from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_DATA is not null");
-
-            // finally verify that there's a file system root entry
-            verifyRoodExists();
-
-            initialized = true;
-        } catch (Exception e) {
-            String msg = "failed to initialize file system";
-            log.error(msg, e);
-            throw new FileSystemException(msg, e);
-        }
+    protected List initPreparedStatements() throws SQLException {
+        List stmts = new LinkedList();
+        stmts.add(insertFileStmt = con.prepareStatement("insert into "
+                + schemaObjectPrefix + "FSENTRY "
+                + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
+                + "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
+                + "values (?, ?, ?, ?, ?)"));
+
+        stmts.add(insertFolderStmt = con.prepareStatement("insert into "
+                + schemaObjectPrefix + "FSENTRY "
+                + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_LASTMOD, FSENTRY_LENGTH) "
+                + "values (?, ?, ?, 0)"));
+
+        stmts.add(updateDataStmt = con.prepareStatement("update "
+                + schemaObjectPrefix + "FSENTRY "
+                + "set FSENTRY_DATA = ?, FSENTRY_LASTMOD = ?, FSENTRY_LENGTH = ? "
+                + "where FSENTRY_PATH = ? and FSENTRY_NAME = ? "
+                + "and FSENTRY_DATA is not null"));
+
+        stmts.add(updateLastModifiedStmt = con.prepareStatement("update "
+                + schemaObjectPrefix + "FSENTRY set FSENTRY_LASTMOD = ? "
+                + "where FSENTRY_PATH = ? and FSENTRY_NAME = ? "
+                + "and FSENTRY_DATA is not null"));
+
+        stmts.add(selectExistStmt = con.prepareStatement("select 1 from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ?"));
+
+        stmts.add(selectFileExistStmt = con.prepareStatement("select 1 from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null"));
+
+        stmts.add(selectFolderExistStmt = con.prepareStatement("select 1 from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ? and FSENTRY_DATA is null"));
+
+        stmts.add(selectFileNamesStmt = con.prepareStatement("select FSENTRY_NAME from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_DATA is not null"));
+
+        stmts.add(selectFolderNamesStmt = con.prepareStatement("select FSENTRY_NAME from
"
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_DATA is null"));
+
+        stmts.add(selectFileAndFolderNamesStmt = con.prepareStatement("select FSENTRY_NAME
from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ?"));
+
+        stmts.add(selectChildCountStmt = con.prepareStatement("select count(FSENTRY_NAME)
from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ?  "));
+
+        stmts.add(selectDataStmt = con.prepareStatement("select FSENTRY_DATA from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null"));
+
+        stmts.add(selectLastModifiedStmt = con.prepareStatement("select FSENTRY_LASTMOD from
"
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ?"));
+
+        stmts.add(selectLengthStmt = con.prepareStatement("select FSENTRY_LENGTH from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null"));
+
+        stmts.add(deleteFileStmt = con.prepareStatement("delete from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null"));
+
+        stmts.add(deleteFolderStmt = con.prepareStatement("delete from "
+                + schemaObjectPrefix + "FSENTRY where "
+                + "(FSENTRY_PATH = ? and FSENTRY_NAME = ? and FSENTRY_DATA is null) "
+                + "or (FSENTRY_PATH = ?) "
+                + "or (FSENTRY_PATH like ?) "));
+
+        stmts.add(copyFileStmt = con.prepareStatement("insert into "
+                + schemaObjectPrefix + "FSENTRY "
+                + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
+                + "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
+                + "select cast(? as varchar(745)), cast(? as varchar(255)), FSENTRY_DATA,
"
+                + "FSENTRY_LASTMOD, FSENTRY_LENGTH from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null"));
+
+        stmts.add(copyFilesStmt = con.prepareStatement("insert into "
+                + schemaObjectPrefix + "FSENTRY "
+                + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
+                + "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
+                + "select cast(? as varchar(745)), FSENTRY_NAME, FSENTRY_DATA, "
+                + "FSENTRY_LASTMOD, FSENTRY_LENGTH from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_DATA is not null"));
+
+        return stmts;
     }
 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java?rev=391012&r1=391011&r2=391012&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
Mon Apr  3 04:30:18 2006
@@ -43,6 +43,8 @@
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
+import java.util.List;
+import java.util.LinkedList;
 
 /**
  * Base class for database file systems. This class contains common
@@ -75,6 +77,9 @@
     // jdbc connection
     protected Connection con;
 
+    // the list of prepared statements, used in close()
+    private List preparedStatements;
+
     // shared prepared statements
     protected PreparedStatement selectExistStmt;
     protected PreparedStatement selectFileExistStmt;
@@ -152,6 +157,108 @@
     }
 
     //-----------------------------------------------------------< FileSystem >
+
+    /**
+     * initializes the prepared statements and returns the list of them. please
+     * note, that this list is used to close the statements in the {@link #close()}
+     * call.
+     *
+     * @return the list of prepared statements.
+     * @throws SQLException
+     */
+    protected List initPreparedStatements() throws SQLException {
+        List stmts = new LinkedList();
+        stmts.add(insertFileStmt = con.prepareStatement("insert into "
+                + schemaObjectPrefix + "FSENTRY "
+                + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
+                + "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
+                + "values (?, ?, ?, ?, ?)"));
+
+        stmts.add(insertFolderStmt = con.prepareStatement("insert into "
+                + schemaObjectPrefix + "FSENTRY "
+                + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_LASTMOD, FSENTRY_LENGTH) "
+                + "values (?, ?, ?, 0)"));
+
+        stmts.add(updateDataStmt = con.prepareStatement("update "
+                + schemaObjectPrefix + "FSENTRY "
+                + "set FSENTRY_DATA = ?, FSENTRY_LASTMOD = ?, FSENTRY_LENGTH = ? "
+                + "where FSENTRY_PATH = ? and FSENTRY_NAME = ? "
+                + "and FSENTRY_DATA is not null"));
+
+        stmts.add(updateLastModifiedStmt = con.prepareStatement("update "
+                + schemaObjectPrefix + "FSENTRY set FSENTRY_LASTMOD = ? "
+                + "where FSENTRY_PATH = ? and FSENTRY_NAME = ? "
+                + "and FSENTRY_DATA is not null"));
+
+        stmts.add(selectExistStmt = con.prepareStatement("select 1 from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ?"));
+
+        stmts.add(selectFileExistStmt = con.prepareStatement("select 1 from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null"));
+
+        stmts.add(selectFolderExistStmt = con.prepareStatement("select 1 from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ? and FSENTRY_DATA is null"));
+
+        stmts.add(selectFileNamesStmt = con.prepareStatement("select FSENTRY_NAME from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_DATA is not null"));
+
+        stmts.add(selectFolderNamesStmt = con.prepareStatement("select FSENTRY_NAME from
"
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_DATA is null"));
+
+        stmts.add(selectFileAndFolderNamesStmt = con.prepareStatement("select FSENTRY_NAME
from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ?"));
+
+        stmts.add(selectChildCountStmt = con.prepareStatement("select count(FSENTRY_NAME)
from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ?  "));
+
+        stmts.add(selectDataStmt = con.prepareStatement("select FSENTRY_DATA from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null"));
+
+        stmts.add(selectLastModifiedStmt = con.prepareStatement("select FSENTRY_LASTMOD from
"
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ?"));
+
+        stmts.add(selectLengthStmt = con.prepareStatement("select FSENTRY_LENGTH from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null"));
+
+        stmts.add(deleteFileStmt = con.prepareStatement("delete from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null"));
+
+        stmts.add(deleteFolderStmt = con.prepareStatement("delete from "
+                + schemaObjectPrefix + "FSENTRY where "
+                + "(FSENTRY_PATH = ? and FSENTRY_NAME = ? and FSENTRY_DATA is null) "
+                + "or (FSENTRY_PATH = ?) "
+                + "or (FSENTRY_PATH like ?) "));
+
+        stmts.add(copyFileStmt = con.prepareStatement("insert into "
+                + schemaObjectPrefix + "FSENTRY "
+                + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
+                + "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
+                + "select ?, ?, FSENTRY_DATA, "
+                + "FSENTRY_LASTMOD, FSENTRY_LENGTH from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null"));
+
+        stmts.add(copyFilesStmt = con.prepareStatement("insert into "
+                + schemaObjectPrefix + "FSENTRY "
+                + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
+                + "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
+                + "select ?, FSENTRY_NAME, FSENTRY_DATA, "
+                + "FSENTRY_LASTMOD, FSENTRY_LENGTH from "
+                + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
+                + "and FSENTRY_DATA is not null"));
+
+        return stmts;
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -171,96 +278,10 @@
             checkSchema();
 
             // prepare statements
-            insertFileStmt = con.prepareStatement("insert into "
-                    + schemaObjectPrefix + "FSENTRY "
-                    + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
-                    + "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
-                    + "values (?, ?, ?, ?, ?)");
-
-            insertFolderStmt = con.prepareStatement("insert into "
-                    + schemaObjectPrefix + "FSENTRY "
-                    + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_LASTMOD, FSENTRY_LENGTH) "
-                    + "values (?, ?, ?, 0)");
-
-            updateDataStmt = con.prepareStatement("update "
-                    + schemaObjectPrefix + "FSENTRY "
-                    + "set FSENTRY_DATA = ?, FSENTRY_LASTMOD = ?, FSENTRY_LENGTH = ? "
-                    + "where FSENTRY_PATH = ? and FSENTRY_NAME = ? "
-                    + "and FSENTRY_DATA is not null");
-
-            updateLastModifiedStmt = con.prepareStatement("update "
-                    + schemaObjectPrefix + "FSENTRY set FSENTRY_LASTMOD = ? "
-                    + "where FSENTRY_PATH = ? and FSENTRY_NAME = ? "
-                    + "and FSENTRY_DATA is not null");
-
-            selectExistStmt = con.prepareStatement("select 1 from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ?");
-
-            selectFileExistStmt = con.prepareStatement("select 1 from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
-
-            selectFolderExistStmt = con.prepareStatement("select 1 from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ? and FSENTRY_DATA is null");
-
-            selectFileNamesStmt = con.prepareStatement("select FSENTRY_NAME from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_DATA is not null");
-
-            selectFolderNamesStmt = con.prepareStatement("select FSENTRY_NAME from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_DATA is null");
-
-            selectFileAndFolderNamesStmt = con.prepareStatement("select FSENTRY_NAME from
"
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ?");
-
-            selectChildCountStmt = con.prepareStatement("select count(FSENTRY_NAME) from
"
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ?  ");
-
-            selectDataStmt = con.prepareStatement("select FSENTRY_DATA from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
-
-            selectLastModifiedStmt = con.prepareStatement("select FSENTRY_LASTMOD from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ?");
-
-            selectLengthStmt = con.prepareStatement("select FSENTRY_LENGTH from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
-
-            deleteFileStmt = con.prepareStatement("delete from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
-
-            deleteFolderStmt = con.prepareStatement("delete from "
-                    + schemaObjectPrefix + "FSENTRY where "
-                    + "(FSENTRY_PATH = ? and FSENTRY_NAME = ? and FSENTRY_DATA is null) "
-                    + "or (FSENTRY_PATH = ?) "
-                    + "or (FSENTRY_PATH like ?) ");
-
-            copyFileStmt = con.prepareStatement("insert into "
-                    + schemaObjectPrefix + "FSENTRY "
-                    + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
-                    + "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
-                    + "select ?, ?, FSENTRY_DATA, "
-                    + "FSENTRY_LASTMOD, FSENTRY_LENGTH from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
-
-            copyFilesStmt = con.prepareStatement("insert into "
-                    + schemaObjectPrefix + "FSENTRY "
-                    + "(FSENTRY_PATH, FSENTRY_NAME, FSENTRY_DATA, "
-                    + "FSENTRY_LASTMOD, FSENTRY_LENGTH) "
-                    + "select ?, FSENTRY_NAME, FSENTRY_DATA, "
-                    + "FSENTRY_LASTMOD, FSENTRY_LENGTH from "
-                    + schemaObjectPrefix + "FSENTRY where FSENTRY_PATH = ? "
-                    + "and FSENTRY_DATA is not null");
+            preparedStatements = initPreparedStatements();
 
             // finally verify that there's a file system root entry
-            verifyRoodExists();
+            verifyRootExists();
 
             initialized = true;
         } catch (Exception e) {
@@ -280,24 +301,14 @@
 
         try {
             // close shared prepared statements
-            closeStatement(insertFileStmt);
-            closeStatement(insertFolderStmt);
-            closeStatement(updateDataStmt);
-            closeStatement(updateLastModifiedStmt);
-            closeStatement(selectExistStmt);
-            closeStatement(selectFileExistStmt);
-            closeStatement(selectFolderExistStmt);
-            closeStatement(selectFileNamesStmt);
-            closeStatement(selectFolderNamesStmt);
-            closeStatement(selectFileAndFolderNamesStmt);
-            closeStatement(selectChildCountStmt);
-            closeStatement(selectDataStmt);
-            closeStatement(selectLastModifiedStmt);
-            closeStatement(selectLengthStmt);
-            closeStatement(deleteFolderStmt);
-            closeStatement(deleteFileStmt);
-            closeStatement(copyFileStmt);
-            closeStatement(copyFilesStmt);
+            if (preparedStatements != null) {
+                while (!preparedStatements.isEmpty()) {
+                    closeStatement(
+                            (PreparedStatement) preparedStatements.remove(0)
+                    );
+                }
+            }
+            preparedStatements = null;
 
             // close jdbc connection
             closeConnection(con);
@@ -1075,7 +1086,7 @@
      */
     protected void initConnection() throws Exception {
         con = getConnection();
-        con.setAutoCommit(false);
+        con.setAutoCommit(true);
     }
 
     /**
@@ -1106,7 +1117,7 @@
      * method to provide more extensive database and connection cleanup.
      *
      * @param connection database connection
-     * @throws Exception if an error occurs
+     * @throws SQLException if an error occurs
      */
     protected void closeConnection(Connection connection) throws SQLException {
         connection.close();
@@ -1196,7 +1207,7 @@
      *
      * @throws Exception if an error occurs
      */
-    protected void verifyRoodExists() throws Exception {
+    protected void verifyRootExists() throws Exception {
         // check if root file system entry exists
         PreparedStatement stmt = selectFolderExistStmt;
         synchronized (stmt) {
@@ -1386,6 +1397,7 @@
             try {
                 in.close();
             } catch (IOException ignore) {
+                // ignore
             }
         }
     }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java?rev=391012&r1=391011&r2=391012&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java
Mon Apr  3 04:30:18 2006
@@ -44,7 +44,7 @@
  * <p/>
  * The following is a fragment from a sample configuration using MySQL:
  * <pre>
- *   &lt;FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"&gt;
+ *   &lt;FileSystem class="com.day.crx.core.fs.db.DbFileSystem"&gt;
  *       &lt;param name="driver" value="com.mysql.jdbc.Driver"/&gt;
  *       &lt;param name="url" value="jdbc:mysql:///test"/&gt;
  *       &lt;param name="schema" value="mysql"/&gt;
@@ -53,7 +53,7 @@
  * </pre>
  * The following is a fragment from a sample configuration using Daffodil One$DB Embedded:
  * <pre>
- *   &lt;FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"&gt;
+ *   &lt;FileSystem class="com.day.crx.core.fs.db.DbFileSystem"&gt;
  *       &lt;param name="driver" value="in.co.daffodil.db.jdbc.DaffodilDBDriver"/&gt;
  *       &lt;param name="url" value="jdbc:daffodilDB_embedded:rep;path=${rep.home}/databases;create=true"/&gt;
  *       &lt;param name="user" value="daffodil"/&gt;
@@ -64,7 +64,7 @@
  * </pre>
  * The following is a fragment from a sample configuration using MSSQL:
  * <pre>
- *   &lt;FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"&gt;
+ *   &lt;FileSystem class="com.day.crx.core.fs.db.DbFileSystem"&gt;
  *       &lt;param name="driver" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/&gt;
  *       &lt;param name="url" value="jdbc:microsoft:sqlserver://localhost:1433;;DatabaseName=test;SelectMethod=Cursor;"/&gt;
  *       &lt;param name="schema" value="mssql"/&gt;
@@ -75,7 +75,7 @@
  * </pre>
  * The following is a fragment from a sample configuration using PostgreSQL:
  * <pre>
- *   &lt;FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"&gt;
+ *   &lt;FileSystem class="com.day.crx.core.fs.db.DbFileSystem"&gt;
  *       &lt;param name="driver" value="org.postgresql.Driver"/&gt;
  *       &lt;param name="url" value="jdbc:postgresql://localhost/test"/&gt;
  *       &lt;param name="schema" value="postgresql"/&gt;
@@ -88,9 +88,24 @@
  */
 public class DbFileSystem extends DatabaseFileSystem {
 
+    /**
+     * the full qualified JDBC driver name
+     */
     protected String driver;
+
+    /**
+     * the JDBC connection URL
+     */
     protected String url;
+
+    /**
+     * the JDBC connection user
+     */
     protected String user;
+
+    /**
+     * the JDBC connection password
+     */
     protected String password;
 
     //----------------------------------------------------< setters & getters >
@@ -164,12 +179,11 @@
     /**
      * Initialize the JDBC connection.
      *
-     * @throws Exception if an error occurs
+     * @throws SQLException if an error occurs
      */
     protected Connection getConnection() throws ClassNotFoundException, SQLException {
         Class.forName(driver);
-        Connection connection = DriverManager.getConnection(url, user, password);
-        return connection;
+        return DriverManager.getConnection(url, user, password);
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java?rev=391012&r1=391011&r2=391012&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java
Mon Apr  3 04:30:18 2006
@@ -15,12 +15,11 @@
  */
 package org.apache.jackrabbit.core.fs.db;
 
-import java.sql.Connection;
-import java.sql.SQLException;
-
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
 
 /**
  * Database file system that uses JNDI to acquire the database connection.
@@ -67,8 +66,7 @@
      *
      * @return new database connection
      * @throws NamingException if the given data source location does not exist
-     * @throws Exception if a database access error occurs
-     * @see DatabaseFileManager#getConnection()
+     * @throws SQLException if a database access error occurs
      */
     protected Connection getConnection() throws NamingException, SQLException {
         InitialContext ic = new InitialContext();



Mime
View raw message