jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r366200 - in /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: fs/db/DB2FileSystem.java fs/db/DbFileSystem.java fs/db/db2.ddl state/db/SimpleDbPersistenceManager.java state/db/db2.ddl
Date Thu, 05 Jan 2006 15:27:15 GMT
Author: stefan
Date: Thu Jan  5 07:27:09 2006
New Revision: 366200

URL: http://svn.apache.org/viewcvs?rev=366200&view=rev
Log:
added db2 support (PersistenceManager & FileSystem)

Added:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DB2FileSystem.java
  (with props)
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/db2.ddl
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/db2.ddl
Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/SimpleDbPersistenceManager.java

Added: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DB2FileSystem.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DB2FileSystem.java?rev=366200&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DB2FileSystem.java
(added)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DB2FileSystem.java
Thu Jan  5 07:27:09 2006
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.fs.db;
+
+import org.apache.jackrabbit.core.fs.FileSystemException;
+import org.apache.log4j.Logger;
+
+import java.sql.DriverManager;
+
+/**
+ * <code>DB2FileSystem</code> is a JDBC-based <code>FileSystem</code>
+ * implementation for Jackrabbit that persists file system entries in a
+ * DB2 database.
+ * <p/>
+ * It is configured through the following properties:
+ * <ul>
+ * <li><code>driver</code>: the FQN name of the JDBC driver class
+ * (default: <code>"com.ibm.db2.jcc.DB2Driver"</code>)</li>
+ * <li><code>schema</code>: type of schema to be used
+ * (default: <code>"db2"</code>)</li>
+ * <li><code>url</code>: the database url (e.g.
+ * <code>"jdbc:db2:[database]"</code>)</li>
+ * <li><code>user</code>: the database user</li>
+ * <li><code>password</code>: the user's password</li>
+ * <li><code>schemaObjectPrefix</code>: prefix to be prepended to schema
objects</li>
+ * </ul>
+ * See also {@link DbFileSystem}.
+ * <p/>
+ * The following is a fragment from a sample configuration:
+ * <pre>
+ *   &lt;FileSystem class="org.apache.jackrabbit.core.fs.db.DB2FileSystem"&gt;
+ *       &lt;param name="url" value="jdbc:db2:test"/&gt;
+ *       &lt;param name="schemaObjectPrefix" value="rep_"/&gt;
+ *   &lt;/FileSystem&gt;
+ * </pre>
+ */
+public class DB2FileSystem extends DbFileSystem {
+
+    /**
+     * Logger instance
+     */
+    private static Logger log = Logger.getLogger(DB2FileSystem.class);
+
+    /**
+     * Creates a new <code>DB2FileSystem</code> instance.
+     */
+    public DB2FileSystem() {
+        // preset some attributes to reasonable defaults
+        schema = "db2";
+        driver = "com.ibm.db2.jcc.DB2Driver";
+        schemaObjectPrefix = "";
+        user = "";
+        password = "";
+        initialized = false;
+    }
+
+    //-----------------------------------------------< DbFileSystem overrides >
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * Since DB2 requires parameter markers within the select clause to be
+     * 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
+            Class.forName(driver);
+            con = DriverManager.getConnection(url, user, password);
+            con.setAutoCommit(true);
+
+            // 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);
+        }
+    }
+}

Propchange: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DB2FileSystem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DB2FileSystem.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java?rev=366200&r1=366199&r2=366200&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java
Thu Jan  5 07:27:09 2006
@@ -88,7 +88,29 @@
  *       &lt;param name="schemaObjectPrefix" value="rep_"/&gt;
  *   &lt;/FileSystem&gt;
  * </pre>
- * See also {@link DerbyFileSystem}.
+ * The following is a fragment from a sample configuration using MSSQL:
+ * <pre>
+ *   &lt;FileSystem class="org.apache.jackrabbit.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;
+ *       &lt;param name="user" value="sa"/&gt;
+ *       &lt;param name="password" value=""/&gt;
+ *       &lt;param name="schemaObjectPrefix" value="rep_"/&gt;
+ *   &lt;/FileSystem&gt;
+ * </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;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;
+ *       &lt;param name="user" value="postgres"/&gt;
+ *       &lt;param name="password" value="postgres"/&gt;
+ *       &lt;param name="schemaObjectPrefix" value="rep_"/&gt;
+ *   &lt;/FileSystem&gt;
+ * </pre>
+ * See also {@link DerbyFileSystem}, {@link DB2FileSystem}.
  */
 public class DbFileSystem implements FileSystem {
 

Added: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/db2.ddl
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/db2.ddl?rev=366200&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/db2.ddl
(added)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/fs/db/db2.ddl
Thu Jan  5 07:27:09 2006
@@ -0,0 +1,2 @@
+create table ${schemaObjectPrefix}FSENTRY (FSENTRY_PATH varchar(745) not null, FSENTRY_NAME
varchar(255) not null, FSENTRY_DATA blob(100M), FSENTRY_LASTMOD bigint not null, FSENTRY_LENGTH
bigint not null)
+create unique index ${schemaObjectPrefix}FSENTRY_IDX on ${schemaObjectPrefix}FSENTRY (FSENTRY_PATH,
FSENTRY_NAME)

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/SimpleDbPersistenceManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/SimpleDbPersistenceManager.java?rev=366200&r1=366199&r2=366200&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/SimpleDbPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/SimpleDbPersistenceManager.java
Thu Jan  5 07:27:09 2006
@@ -107,6 +107,40 @@
  *       &lt;param name="externalBLOBs" value="false"/&gt;
  *   &lt;/PersistenceManager&gt;
  * </pre>
+ * The following is a fragment from a sample configuration using DB2:
+ * <pre>
+ *   &lt;PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager"&gt;
+ *       &lt;param name="driver" value="com.ibm.db2.jcc.DB2Driver"/&gt;
+ *       &lt;param name="url" value="jdbc:db2:test"/&gt;
+ *       &lt;param name="schema" value="db2"/&gt;
+ *       &lt;param name="schemaObjectPrefix" value="${wsp.name}_"/&gt;
+ *       &lt;param name="externalBLOBs" value="false"/&gt;
+ *   &lt;/PersistenceManager&gt;
+ * </pre>
+ * The following is a fragment from a sample configuration using MSSQL:
+ * <pre>
+ *   &lt;PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager"&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;
+ *       &lt;param name="user" value="sa"/&gt;
+ *       &lt;param name="password" value=""/&gt;
+ *       &lt;param name="schemaObjectPrefix" value="${wsp.name}_"/&gt;
+ *       &lt;param name="externalBLOBs" value="false"/&gt;
+ *   &lt;/PersistenceManager&gt;
+ * </pre>
+ * The following is a fragment from a sample configuration using PostgreSQL:
+ * <pre>
+ *   &lt;PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager"&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;
+ *       &lt;param name="user" value="postgres"/&gt;
+ *       &lt;param name="password" value="postgres"/&gt;
+ *       &lt;param name="schemaObjectPrefix" value="${wsp.name}_"/&gt;
+ *       &lt;param name="externalBLOBs" value="false"/&gt;
+ *   &lt;/PersistenceManager&gt;
+ * </pre>
  * See also {@link DerbyPersistenceManager}.
  */
 public class SimpleDbPersistenceManager extends AbstractPersistenceManager {

Added: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/db2.ddl
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/db2.ddl?rev=366200&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/db2.ddl
(added)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/db2.ddl
Thu Jan  5 07:27:09 2006
@@ -0,0 +1,8 @@
+create table ${schemaObjectPrefix}NODE (NODE_ID char(36) not null, NODE_DATA blob not null)
+create unique index ${schemaObjectPrefix}NODE_IDX on ${schemaObjectPrefix}NODE (NODE_ID)
+create table ${schemaObjectPrefix}PROP (PROP_ID varchar(1000) not null, PROP_DATA blob not
null)
+create unique index ${schemaObjectPrefix}PROP_IDX on ${schemaObjectPrefix}PROP (PROP_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID char(36) not null, REFS_DATA blob not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(1000) not null, BINVAL_DATA blob(100M)
not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)



Mime
View raw message