jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r792165 [2/2] - in /jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle: ./ util/
Date Wed, 08 Jul 2009 14:39:08 GMT
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NGKDbNameIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NGKDbNameIndex.java?rev=792165&r1=792164&r2=792165&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NGKDbNameIndex.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NGKDbNameIndex.java
Wed Jul  8 14:39:08 2009
@@ -16,7 +16,11 @@
  */
 package org.apache.jackrabbit.core.persistence.bundle.util;
 
+import java.sql.Connection;
 import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.sql.DataSource;
 
 /**
  * Same as {@link DbNameIndex} but does not make use of the
@@ -31,9 +35,9 @@
      * @param schemaObjectPrefix the prefix for table names
      * @throws SQLException if the statements cannot be prepared.
      */
-    public NGKDbNameIndex(ConnectionRecoveryManager conMgr, String schemaObjectPrefix)
+    public NGKDbNameIndex(DataSource dataSource, String schemaObjectPrefix)
             throws SQLException {
-        super(conMgr, schemaObjectPrefix);
+        super(dataSource, schemaObjectPrefix);
     }
 
     /**
@@ -57,13 +61,17 @@
      */
     protected int insertString(String string) {
         // assert index does not exist
+    	Connection connection = null;
         try {
-            connectionManager.executeStmt(nameInsertSQL, new Object[] { string });
+        	connection = dataSource.getConnection();
+            new ConnectionHelper(connection).executeStmt(nameInsertSQL, new Object[] { string
});
         } catch (Exception e) {
             IllegalStateException ise = new IllegalStateException(
                     "Unable to insert index for string: " + string);
             ise.initCause(e);
             throw ise;
+        } finally {
+        	ConnectionHelper.closeSilently(connection);
         }
 
         return getIndex(string);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/PostgreSQLNameIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/PostgreSQLNameIndex.java?rev=792165&r1=792164&r2=792165&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/PostgreSQLNameIndex.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/PostgreSQLNameIndex.java
Wed Jul  8 14:39:08 2009
@@ -16,9 +16,12 @@
  */
 package org.apache.jackrabbit.core.persistence.bundle.util;
 
+import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import javax.sql.DataSource;
+
 /**
  * Same as {@link DbNameIndex} but does not make use of the
  * {@link java.sql.Statement#RETURN_GENERATED_KEYS} feature as it is not
@@ -28,9 +31,9 @@
 
     protected String generatedKeySelectSQL;
 
-    public PostgreSQLNameIndex(ConnectionRecoveryManager conMgr, String schemaObjectPrefix)
+    public PostgreSQLNameIndex(DataSource dataSource, String schemaObjectPrefix)
             throws SQLException {
-        super(conMgr, schemaObjectPrefix);
+        super(dataSource, schemaObjectPrefix);
     }
 
     /**
@@ -59,13 +62,17 @@
      */
     protected int insertString(String string) {
         // assert index does not exist
+    	Connection connection = null;
         try {
-            connectionManager.executeStmt(nameInsertSQL, new Object[]{string});
+        	connection = dataSource.getConnection();
+            new ConnectionHelper(connection).executeStmt(nameInsertSQL, new Object[]{string});
             return getGeneratedKey();
-        } catch (Exception e) {
+        } catch (Exception e) {        	
             IllegalStateException ise = new IllegalStateException("Unable to insert index
for string: " + string);
             ise.initCause(e);
             throw ise;
+        } finally {
+        	ConnectionHelper.closeSilently(connection);
         }
     }
 
@@ -74,8 +81,10 @@
      * @return the index.
      */
     protected int getGeneratedKey() {
+    	Connection connection = null;
         try {
-            ResultSet rs = connectionManager.executeQuery(generatedKeySelectSQL);
+        	connection = dataSource.getConnection();        	
+            ResultSet rs = new ConnectionHelper(connection).executeQuery(generatedKeySelectSQL);
             try {
                 if (!rs.next()) {
                     return -1;
@@ -89,6 +98,8 @@
             IllegalStateException ise = new IllegalStateException("Unable to read generated
index");
             ise.initCause(e);
             throw ise;
+        } finally {
+        	ConnectionHelper.closeSilently(connection);
         }
     }
 

Added: 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/persistence/bundle/util/StreamWrapper.java?rev=792165&view=auto
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/StreamWrapper.java
(added)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/StreamWrapper.java
Wed Jul  8 14:39:08 2009
@@ -0,0 +1,46 @@
+/*
+ * 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.InputStream;
+
+public class StreamWrapper {
+
+    private final InputStream stream;
+    private final long size;
+
+    /**
+     * Creates a wrapper for the given InputStream that can
+     * safely be passed as a parameter to the <code>executeStmt</code>
+     * methods in the {@link ConnectionRecoveryManager} class.
+     *
+     * @param in the InputStream to wrap
+     * @param size the size of the input stream
+     */
+    public StreamWrapper(InputStream in, long size) {
+        this.stream = in;
+        this.size = size;
+    }
+    
+    public InputStream getStream() {
+        return stream;
+    }
+    
+    public long getSize() {
+        return size;
+    }
+}

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



Mime
View raw message