jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marti...@apache.org
Subject svn commit: r810362 [2/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
Copied: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionFactory.java
(from r801889, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionFactory.java?p2=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionFactory.java&p1=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java&r1=801889&r2=810362&rev=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionFactory.java
Wed Sep  2 05:11:45 2009
@@ -14,8 +14,9 @@
  * 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.lang.reflect.Field;
 import java.sql.Connection;
 import java.sql.SQLException;
 
@@ -25,6 +26,7 @@
 import javax.sql.DataSource;
 
 import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.commons.dbcp.DelegatingConnection;
 
 /**
  * A factory for new database connections.
@@ -92,6 +94,31 @@
     }
 
     /**
+     * Needed for pre-10R2 Oracle blob support....:(
+     * 
+     * This method actually assumes that we are using commons DBCP 1.2.2.
+     * 
+     * @param con the commons-DBCP pooled connection to unwrap
+     * @return the unwrapped connection
+     */
+    public static Connection unwrap(Connection con) throws SQLException {
+        try {
+            Field f1 = con.getClass().getDeclaredField("delegate");
+            f1.setAccessible(true);
+            Object con2 = f1.get(con);
+            Field f2 = DelegatingConnection.class.getDeclaredField("_conn");
+            f2.setAccessible(true);
+            return (Connection) f2.get(con2);
+        } catch (IllegalArgumentException e) {
+            throw new SQLException("failed to unwrap connection: " + e.getMessage());
+        } catch (NoSuchFieldException e) {
+            throw new SQLException("failed to unwrap connection: " + e.getMessage());
+        } catch (IllegalAccessException e) {
+            throw new SQLException("failed to unwrap connection: " + e.getMessage());
+        }
+    }
+
+    /**
      * Loads and returns the given JDBC driver (or JNDI context) class.
      * Returns <code>null</code> if a class name is not given.
      *

Copied: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
(from r803244, 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/util/db/ConnectionHelper.java?p2=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java&p1=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionHelper.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/ConnectionHelper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.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.sql.Connection;
 import java.sql.DatabaseMetaData;
@@ -50,7 +50,7 @@
  */
 public class ConnectionHelper {
 
-    private final String userName;
+    private final boolean checkTablesWithUserName;
 
     protected final DataSource dataSource;
 
@@ -65,18 +65,18 @@
      */
     public ConnectionHelper(DataSource dataSrc) {
         dataSource = dataSrc;
-        userName = null;
+        checkTablesWithUserName = false;
     }
 
     /**
      * 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
+     * @param checkWithUserName whether the username is to be used for the {@link #tableExists(String)}
method
      */
-    protected ConnectionHelper(DataSource dataSrc, String user) {
+    protected ConnectionHelper(DataSource dataSrc, boolean checkWithUserName) {
         dataSource = dataSrc;
-        userName = user;
+        checkTablesWithUserName = checkWithUserName;
     }
     
     /**
@@ -156,6 +156,10 @@
             } else if (metaData.storesUpperCaseIdentifiers()) {
                 name = tableName.toUpperCase();
             }
+            String userName = null;
+            if (checkTablesWithUserName) {
+                userName = metaData.getUserName();
+            }
             rs = metaData.getTables(null, userName, name, null);
             schemaExists = rs.next();
         } finally {
@@ -217,17 +221,25 @@
     /**
      * Executes a general SQL statement and immediately closes all resources.
      * 
+     * Note: We use a Statement if there are no parameters to avoid a problem on
+     * the Oracle 10g JDBC driver w.r.t. :NEW and :OLD keywords that triggers ORA-17041.
+     *
      * @param sql an SQL statement string
      * @param params the parameters for the SQL statement
      * @throws SQLException on error
      */
     public final void exec(String sql, Object... params) throws SQLException {
         Connection con = null;
-        PreparedStatement stmt = null;
+        Statement stmt = null;
         try {
             con = getConnection();
-            stmt = con.prepareStatement(sql);
-            execute(stmt, params);
+            if (params == null || params.length == 0) {
+                stmt = con.createStatement();
+                stmt.execute(sql);
+            } else {
+                stmt = con.prepareStatement(sql);
+                execute((PreparedStatement) stmt, params);
+            }
         } finally {
             closeResources(con, stmt, null);
         }

Copied: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DataSourceWrapper.java
(from r801889, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DataSourceWrapper.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DataSourceWrapper.java?p2=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DataSourceWrapper.java&p1=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DataSourceWrapper.java&r1=801889&r2=810362&rev=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DataSourceWrapper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DataSourceWrapper.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.PrintWriter;
 import java.sql.Connection;

Copied: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DbUtility.java
(from r802341, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbUtility.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DbUtility.java?p2=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DbUtility.java&p1=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbUtility.java&r1=802341&r2=810362&rev=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbUtility.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DbUtility.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.sql.Connection;
 import java.sql.ResultSet;

Copied: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DerbyConnectionHelper.java
(from r802341, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DerbyConnectionHelper.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DerbyConnectionHelper.java?p2=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DerbyConnectionHelper.java&p1=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DerbyConnectionHelper.java&r1=802341&r2=810362&rev=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DerbyConnectionHelper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DerbyConnectionHelper.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.sql.Connection;
 import java.sql.DriverManager;
@@ -60,8 +60,15 @@
         
         try {
             con = dataSource.getConnection();
-            url = con.getMetaData().getURL();
-            
+            try {
+                url = con.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;
+            }
             // 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.

Copied: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/Oracle10R1ConnectionHelper.java
(from r803244, 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/util/db/Oracle10R1ConnectionHelper.java?p2=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/Oracle10R1ConnectionHelper.java&p1=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/Oracle10R1ConnectionHelper.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/Oracle10R1ConnectionHelper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/Oracle10R1ConnectionHelper.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.IOException;
 import java.io.InputStream;
@@ -51,10 +51,9 @@
 
     /**
      * @param dataSrc
-     * @param userName
      */
-    public Oracle10R1ConnectionHelper(DataSource dataSrc, String userName) {
-        super(dataSrc, userName);
+    public Oracle10R1ConnectionHelper(DataSource dataSrc) {
+        super(dataSrc);
     }
 
     /**
@@ -99,11 +98,11 @@
                     StreamWrapper wrapper = (StreamWrapper) p;
                     Blob tmp = createTemporaryBlob(stmt.getConnection(), wrapper.getStream());
                     tmpBlobs.add(tmp);
-                    stmt.setObject(i + 1, tmp);
+                    stmt.setBlob(i + 1, tmp);
                 } else if (p instanceof InputStream) {
                     Blob tmp = createTemporaryBlob(stmt.getConnection(), (InputStream) p);
                     tmpBlobs.add(tmp);
-                    stmt.setObject(i + 1, tmp);
+                    stmt.setBlob(i + 1, tmp);
                 } else {
                     stmt.setObject(i + 1, p);
                 }
@@ -135,7 +134,9 @@
          */
         Method createTemporary =
             blobClass.getMethod("createTemporary", new Class[]{Connection.class, Boolean.TYPE,
Integer.TYPE});
-        Object blob = createTemporary.invoke(null, new Object[]{con, Boolean.FALSE, durationSessionConstant});
+        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]);

Copied: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/OracleConnectionHelper.java
(from r803244, 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/util/db/OracleConnectionHelper.java?p2=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/OracleConnectionHelper.java&p1=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/OracleConnectionHelper.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/OracleConnectionHelper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/OracleConnectionHelper.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.sql.Connection;
 import java.sql.DatabaseMetaData;
@@ -37,10 +37,9 @@
 
     /**
      * @param dataSrc
-     * @param userName
      */
-    public OracleConnectionHelper(DataSource dataSrc, String userName) {
-        super(dataSrc, userName);
+    public OracleConnectionHelper(DataSource dataSrc) {
+        super(dataSrc, true);
     }
 
     public void init() throws Exception {
@@ -58,7 +57,7 @@
         } catch (SQLException e) {
             log.warn("Can not retrieve driver version", e);
         } finally {
-          DbUtility.close(connection, null, null);
+            DbUtility.close(connection, null, null);
         }
     }
 

Copied: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ResultSetWrapper.java
(from r802341, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ResultSetWrapper.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ResultSetWrapper.java?p2=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ResultSetWrapper.java&p1=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ResultSetWrapper.java&r1=802341&r2=810362&rev=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ResultSetWrapper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ResultSetWrapper.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.InputStream;
 import java.io.Reader;

Copied: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/StreamWrapper.java
(from r801889, jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/StreamWrapper.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/StreamWrapper.java?p2=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/StreamWrapper.java&p1=jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/StreamWrapper.java&r1=801889&r2=810362&rev=810362&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/StreamWrapper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/StreamWrapper.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.InputStream;
 



Mime
View raw message