jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marti...@apache.org
Subject svn commit: r803244 - in /jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle: ./ util/
Date Tue, 11 Aug 2009 18:48:02 GMT
Author: martijnh
Date: Tue Aug 11 18:48:02 2009
New Revision: 803244

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

* Moved the checkSchema code to a configurable CheckSchemaOperation class.
* The BundleDbPersistenceManager and subtypes are factories for CheckSchemaOperation instances.


Added:
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/CheckSchemaOperation.java
  (with props)
Modified:
    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/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/util/ConnectionHelper.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

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=803244&r1=803243&r2=803244&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
Tue Aug 11 18:48:02 2009
@@ -30,19 +30,22 @@
 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;
 
 import org.apache.commons.io.IOUtils;
-import org.apache.jackrabbit.core.id.NodeId;
-import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
+import org.apache.jackrabbit.core.id.NodeId;
+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;
@@ -58,7 +61,6 @@
 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.util.Text;
 import org.apache.jackrabbit.uuid.UUID;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -88,10 +90,6 @@
     /** the default logger */
     private static Logger log = LoggerFactory.getLogger(BundleDbPersistenceManager.class);
 
-    /** the variable for the schema prefix */
-    public static final String SCHEMA_OBJECT_PREFIX_VARIABLE =
-            "${schemaObjectPrefix}";
-
     /** storage model modifier: binary keys */
     public static final int SM_BINARY_KEYS = 1;
 
@@ -116,6 +114,7 @@
     /** the database type */
     protected String databaseType;
     
+    /** the {@link ConnectionHelper} set in the {@link #init(PMContext)} method */
     protected ConnectionHelper conHelper;
 
     /** the prefix for the database objects */
@@ -424,17 +423,6 @@
     }
 
     /**
-     * Creates an SQL statement for schema creation by variable substitution.
-     *
-     * @param sql a SQL string which may contain variables to substitute
-     * @return a valid SQL string
-     */
-    public String createSchemaSQL(String sql) {
-        // replace prefix variable
-        return Text.replace(sql, SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix).trim();
-    }
-
-    /**
      * {@inheritDoc}
      *
      * Basically wraps a JDBC transaction around super.store().
@@ -479,8 +467,7 @@
         schemaObjectPrefix = conHelper.prepareDbIdentifier(schemaObjectPrefix);
 
         // check if schema objects exist and create them if necessary
-        conHelper.checkSchema(BundleDbPersistenceManager.class.getResourceAsStream(databaseType
+ ".ddl"),
-            schemaObjectPrefix + "BUNDLE", this);
+        createCheckSchemaOperation().run();
 
         // create correct blob store
         blobStore = createBlobStore();
@@ -502,8 +489,8 @@
 
     /**
      * This method is called from the {@link #init(PMContext)} method of this class and returns
a
-     * {@link ConnectionHelper} instance. Subclasses may override it to return a specialized
-     * connection helper.
+     * {@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}
@@ -514,14 +501,16 @@
     }
 
     /**
-     * Indicates if the user name should be included when retrieving the tables during
-     * {@link #checkTablesExist()}. <p/> Please note that this currently only needs
to be changed for oracle
-     * based persistence managers.
+     * 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 <code>false</code>
+     * @return a new {@link CheckSchemaOperation} instance
      */
-    public boolean checkTablesWithUser() {
-        return false;
+    protected CheckSchemaOperation createCheckSchemaOperation() {
+        InputStream in = BundleDbPersistenceManager.class.getResourceAsStream(databaseType
+ ".ddl");
+        return new CheckSchemaOperation(conHelper, in, schemaObjectPrefix + "BUNDLE").addVariableReplacement(
+            CheckSchemaOperation.SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix);
     }
 
     /**

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=803244&r1=803243&r2=803244&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
Tue Aug 11 18:48:02 2009
@@ -16,17 +16,16 @@
  */
 package org.apache.jackrabbit.core.persistence.bundle;
 
-import org.apache.jackrabbit.util.Text;
+import org.apache.jackrabbit.core.persistence.bundle.util.CheckSchemaOperation;
 
 /**
- * Extends the {@link BundleDbPersistenceManager} by MS-SQL specific code.
- * <p/>
- * Configuration:<br>
+ * Extends the {@link BundleDbPersistenceManager} by MS-SQL specific code. <p/> Configuration:<br>
  * <ul>
  * <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=""/>
@@ -50,13 +49,14 @@
      * {@inheritDoc}
      */
     @Override
-    public String createSchemaSQL(String sql) {
-        return Text.replace(super.createSchemaSQL(sql), "${tableSpace}", tableSpace);
+    protected CheckSchemaOperation createCheckSchemaOperation() {
+        return super.createCheckSchemaOperation().addVariableReplacement(
+            CheckSchemaOperation.TABLE_SPACE_VARIABLE, tableSpace);
     }
 
     /**
      * Returns the configured MS SQL table space.
-     *
+     * 
      * @return the configured MS SQL table space.
      */
     public String getTableSpace() {
@@ -65,11 +65,11 @@
 
     /**
      * Sets the MS SQL table space.
-     *
+     * 
      * @param tableSpace the MS SQL table space.
      */
     public void setTableSpace(String tableSpace) {
-        if (tableSpace != null && tableSpace.length() > 0) {
+        if (tableSpace != null && tableSpace.trim().length() > 0) {
             this.tableSpace = "on " + tableSpace.trim();
         } else {
             this.tableSpace = "";

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=803244&r1=803243&r2=803244&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
Tue Aug 11 18:48:02 2009
@@ -44,7 +44,7 @@
      */
     @Override
     protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
-        Oracle10R1ConnectionHelper helper =  new Oracle10R1ConnectionHelper(dataSrc);
+        Oracle10R1ConnectionHelper helper = new Oracle10R1ConnectionHelper(dataSrc, user);
         helper.init();
         return helper;
     }

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=803244&r1=803243&r2=803244&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
Tue Aug 11 18:48:02 2009
@@ -21,16 +21,14 @@
 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.util.Text;
 
 /**
- * Extends the {@link BundleDbPersistenceManager} by Oracle specific code.
- * <p/>
- * Configuration:<br>
+ * Extends the {@link BundleDbPersistenceManager} by Oracle specific code. <p/> Configuration:<br>
  * <ul>
  * <li>&lt;param name="{@link #setExternalBLOBs(String)} externalBLOBs}" value="false"/>
  * <li>&lt;param name="{@link #setBundleCacheSize(String) bundleCacheSize}" value="8"/>
@@ -48,10 +46,6 @@
  */
 public class OraclePersistenceManager extends BundleDbPersistenceManager {
 
-    /** the variable for the Oracle table space */
-    public static final String TABLE_SPACE_VARIABLE =
-        "${tableSpace}";
-
     /** the Oracle table space to use */
     protected String tableSpace;
 
@@ -65,6 +59,7 @@
 
     /**
      * Returns the configured Oracle table space.
+     * 
      * @return the configured Oracle table space.
      */
     public String getTableSpace() {
@@ -73,13 +68,14 @@
 
     /**
      * Sets the Oracle table space.
+     * 
      * @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 = "";
         }
     }
 
@@ -102,6 +98,7 @@
 
     /**
      * Returns a new instance of a NGKDbNameIndex.
+     * 
      * @return a new instance of a NGKDbNameIndex.
      * @throws SQLException if an SQL error occurs.
      */
@@ -111,36 +108,20 @@
 
     /**
      * {@inheritDoc}
-     *
-     * @return <code>true</code>
-     */
-    @Override
-    public boolean checkTablesWithUser() {
-        return true;
-    }
-
-    /**
-     * {@inheritDoc}
      */
     @Override
-    public String createSchemaSQL(String sql) {
-        // set the tablespace if it is defined
-        String tspace;
-        if (tableSpace == null || "".equals(tableSpace)) {
-            tspace = "";
-        } else {
-            tspace = "tablespace " + tableSpace;
-        }
-        return Text.replace(super.createSchemaSQL(sql), TABLE_SPACE_VARIABLE, tspace).trim();
+    protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
+        OracleConnectionHelper helper = new OracleConnectionHelper(dataSrc, user);
+        helper.init();
+        return helper;
     }
 
     /**
      * {@inheritDoc}
      */
     @Override
-    protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
-        OracleConnectionHelper helper =  new OracleConnectionHelper(dataSrc);
-        helper.init();
-        return helper;
+    protected CheckSchemaOperation createCheckSchemaOperation() {
+        return super.createCheckSchemaOperation().addVariableReplacement(
+            CheckSchemaOperation.TABLE_SPACE_VARIABLE, tableSpace);
     }
 }

Added: 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/persistence/bundle/util/CheckSchemaOperation.java?rev=803244&view=auto
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/CheckSchemaOperation.java
(added)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/CheckSchemaOperation.java
Tue Aug 11 18:48:02 2009
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.persistence.bundle.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.util.Text;
+
+/**
+ * An operation which synchronously checks the DB schema in the {@link #run()} method. The
+ * {@link #addVariableReplacement(String, String)} method return the instance to enable method
chaining.
+ */
+public class CheckSchemaOperation {
+
+    public static final String SCHEMA_OBJECT_PREFIX_VARIABLE = "${schemaObjectPrefix}";
+
+    public static final String TABLE_SPACE_VARIABLE = "${tableSpace}";
+
+    private final ConnectionHelper conHelper;
+
+    private final InputStream ddl;
+
+    private final String table;
+
+    private final Map<String, String> varReplacement = new HashMap<String, String>();
+
+    /**
+     * @param connectionhelper the connection helper
+     * @param ddlStream the stream of the DDL to use to create the schema if necessary (closed
by this method)
+     * @param tableName the name of the table to use for the schema-existence-check
+     */
+    public CheckSchemaOperation(ConnectionHelper connectionhelper, InputStream ddlStream,
String tableName) {
+        conHelper = connectionhelper;
+        ddl = ddlStream;
+        table = tableName;
+    }
+
+    /**
+     * Adds a variable replacement mapping.
+     * 
+     * @param var the variable
+     * @param replacement the replacement value
+     * @return this
+     */
+    public CheckSchemaOperation addVariableReplacement(String var, String replacement) {
+        varReplacement.put(var, replacement);
+        return this;
+    }
+
+    /**
+     * Checks if the required schema objects exist and creates them if they don't exist yet.
+     * 
+     * @throws SQLException if an error occurs
+     * @throws IOException if an error occurs
+     */
+    public void run() throws SQLException, IOException {
+        if (!conHelper.tableExists(table)) {
+            BufferedReader reader = new BufferedReader(new InputStreamReader(ddl));
+            try {
+                String sql = reader.readLine();
+                while (sql != null) {
+                    // Skip comments and empty lines
+                    if (!sql.startsWith("#") && sql.length() > 0) {
+                        // replace prefix variable
+                        sql = replace(sql);
+                        // execute sql stmt
+                        conHelper.exec(sql);
+                    }
+                    // read next sql stmt
+                    sql = reader.readLine();
+                }
+            } finally {
+                IOUtils.closeQuietly(ddl);
+            }
+        }
+    }
+
+    /**
+     * Applies the variable replacement to the given string.
+     * 
+     * @param sql the string in which to replace variables
+     * @return the new string
+     */
+    private String replace(String sql) {
+        String result = sql;
+        for (Map.Entry<String, String> entry : varReplacement.entrySet()) {
+            result = Text.replace(result, entry.getKey(), entry.getValue()).trim();
+        }
+        return result;
+    }
+}

Propchange: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/CheckSchemaOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionHelper.java?rev=803244&r1=803243&r2=803244&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionHelper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionHelper.java
Tue Aug 11 18:48:02 2009
@@ -16,10 +16,6 @@
  */
 package org.apache.jackrabbit.core.persistence.bundle.util;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
@@ -29,9 +25,6 @@
 
 import javax.sql.DataSource;
 
-import org.apache.commons.io.IOUtils;
-import org.apache.jackrabbit.core.persistence.bundle.BundleDbPersistenceManager;
-
 /**
  * This class provides convenience methods to execute SQL statements.
  * 
@@ -57,6 +50,8 @@
  */
 public class ConnectionHelper {
 
+    private final String userName;
+
     protected final DataSource dataSource;
 
     private boolean inBatchMode = false;
@@ -70,9 +65,21 @@
      */
     public ConnectionHelper(DataSource dataSrc) {
         dataSource = dataSrc;
+        userName = null;
     }
 
     /**
+     * Constructor, typically used for Oracle subtypes.
+     * 
+     * @param dataSrc the {@link DataSource} on which this instance acts
+     * @param user the username which is to be used for the {@link #tableExists(String)}
method
+     */
+    protected ConnectionHelper(DataSource dataSrc, String user) {
+        dataSource = dataSrc;
+        userName = user;
+    }
+    
+    /**
      * A utility method that makes sure that <code>identifier</code> does only
consist of characters that are
      * allowed in names on the target database. Illegal characters will be escaped as necessary.
      * 
@@ -131,48 +138,13 @@
     }
 
     /**
-     * Checks if the required schema objects exist and creates them if they don't exist yet.
-     * 
-     * @param ddlStream the stream of the DDL to use to create the schema if necessary (closed
by this method)
-     * @param tableName the name of the table to use for the schema-existence-check
-     * @param pm the associated {@link BundleDbPersistenceManager}
-     * @throws SQLException if an error occurs
-     * @throws IOException if an error occurs
-     */
-    public final void checkSchema(InputStream ddlStream, String tableName, BundleDbPersistenceManager
pm)
-            throws SQLException, IOException {
-        String userName = pm.checkTablesWithUser() ? pm.getUser() : null;
-        if (!tableExists(userName, tableName)) {
-            BufferedReader reader = new BufferedReader(new InputStreamReader(ddlStream));
-            try {
-                String sql = reader.readLine();
-                while (sql != null) {
-                    // Skip comments and empty lines
-                    if (!sql.startsWith("#") && sql.length() > 0) {
-                        // replace prefix variable
-                        sql = pm.createSchemaSQL(sql);
-                        // execute sql stmt
-                        exec(sql);
-                    }
-                    // read next sql stmt
-                    sql = reader.readLine();
-                }
-            } finally {
-                IOUtils.closeQuietly(ddlStream);
-            }
-        }
-    }
-
-    /**
-     * Checks whether the given table exists in the database. The {@code schemaPattern} is
used at least on
-     * Oracle databases and should then be equal to the user who owns the table.
+     * Checks whether the given table exists in the database.
      * 
-     * @param schemaPattern the schema pattern, may be null
      * @param tableName the name of the table
      * @return whether the given table exists
      * @throws SQLException on error
      */
-    private boolean tableExists(String schemaPattern, String tableName) throws SQLException
{
+    public final boolean tableExists(String tableName) throws SQLException {
         Connection con = dataSource.getConnection();
         ResultSet rs = null;
         boolean schemaExists = false;
@@ -184,7 +156,7 @@
             } else if (metaData.storesUpperCaseIdentifiers()) {
                 name = tableName.toUpperCase();
             }
-            rs = metaData.getTables(null, schemaPattern, name, null);
+            rs = metaData.getTables(null, userName, name, null);
             schemaExists = rs.next();
         } finally {
             DbUtility.close(con, null, rs);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/Oracle10R1ConnectionHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/Oracle10R1ConnectionHelper.java?rev=803244&r1=803243&r2=803244&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/Oracle10R1ConnectionHelper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/Oracle10R1ConnectionHelper.java
Tue Aug 11 18:48:02 2009
@@ -51,9 +51,10 @@
 
     /**
      * @param dataSrc
+     * @param userName
      */
-    public Oracle10R1ConnectionHelper(DataSource dataSrc) {
-        super(dataSrc);
+    public Oracle10R1ConnectionHelper(DataSource dataSrc, String userName) {
+        super(dataSrc, userName);
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/OracleConnectionHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/OracleConnectionHelper.java?rev=803244&r1=803243&r2=803244&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/OracleConnectionHelper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/OracleConnectionHelper.java
Tue Aug 11 18:48:02 2009
@@ -37,9 +37,10 @@
 
     /**
      * @param dataSrc
+     * @param userName
      */
-    public OracleConnectionHelper(DataSource dataSrc) {
-        super(dataSrc);
+    public OracleConnectionHelper(DataSource dataSrc, String userName) {
+        super(dataSrc, userName);
     }
 
     public void init() throws Exception {



Mime
View raw message