jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cko...@apache.org
Subject svn commit: r1182667 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: persistence/pool/PostgreSQLPersistenceManager.java util/db/ConnectionHelper.java util/db/PostgreSQLConnectionHelper.java
Date Thu, 13 Oct 2011 05:56:43 GMT
Author: ckoell
Date: Thu Oct 13 05:56:43 2011
New Revision: 1182667

URL: http://svn.apache.org/viewvc?rev=1182667&view=rev
Log:
JCR-2892 Large fetch sizes have potentially deleterious effects on VM memory requirements
when using Oracle

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/PostgreSQLConnectionHelper.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/PostgreSQLPersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/PostgreSQLPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/PostgreSQLPersistenceManager.java?rev=1182667&r1=1182666&r2=1182667&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/PostgreSQLPersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/PostgreSQLPersistenceManager.java
Thu Oct 13 05:56:43 2011
@@ -18,7 +18,11 @@ package org.apache.jackrabbit.core.persi
 
 import java.sql.SQLException;
 
+import javax.sql.DataSource;
+
 import org.apache.jackrabbit.core.persistence.PMContext;
+import org.apache.jackrabbit.core.util.db.ConnectionHelper;
+import org.apache.jackrabbit.core.util.db.PostgreSQLConnectionHelper;
 
 /**
  * Extends the {@link BundleDbPersistenceManager} by PostgreSQL specific code.
@@ -63,6 +67,14 @@ public class PostgreSQLPersistenceManage
     }
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
+    	return new PostgreSQLConnectionHelper(dataSrc, blockOnConnectionLoss);
+    }
+
+    /**
      * returns the storage model
      * @return the storage model
      */

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java?rev=1182667&r1=1182666&r2=1182667&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
Thu Oct 13 05:56:43 2011
@@ -77,6 +77,11 @@ public class ConnectionHelper {
     protected final DataSource dataSource;
 
     private ThreadLocal<Connection> batchConnectionTl = new ThreadLocal<Connection>();
+    
+    /**
+     * The default fetchSize is '0'. This means the fetchSize Hint will be ignored 
+     */
+    private int fetchSize = 0;
 
     /**
      * @param dataSrc the {@link DataSource} on which this instance acts
@@ -101,6 +106,19 @@ public class ConnectionHelper {
     }
 
     /**
+     * @param dataSrc the {@link DataSource} on which this instance acts
+     * @param checkWithUserName whether the username is to be used for the {@link #tableExists(String)}
method
+     * @param block whether the helper should transparently block on DB connection loss (otherwise
it throws exceptions)
+     * @param fetchSize the fetchSize that will be used per default
+     */
+    protected ConnectionHelper(DataSource dataSrc, boolean checkWithUserName, boolean block,
int fetchSize) {
+        dataSource = dataSrc;
+        checkTablesWithUserName = checkWithUserName;
+        blockOnConnectionLoss = block;
+        this.fetchSize = fetchSize;
+    }
+
+    /**
      * 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.
      *
@@ -326,7 +344,6 @@ public class ConnectionHelper {
      *
      * @param sql an SQL statement string
      * @param params the parameters for the SQL statement
-     * @param returnGeneratedKeys whether generated keys should be returned
      * @return a {@link ResultSet}
      */
     public final ResultSet query(String sql, Object... params) throws SQLException {
@@ -369,11 +386,11 @@ public class ConnectionHelper {
                 stmt = con.prepareStatement(sql);
             }
             stmt.setMaxRows(maxRows);
-            int fetchSize = 10000;
-            if (0 < maxRows && maxRows < fetchSize) {
-                fetchSize = maxRows; // JCR-3090
+            int currentFetchSize = this.fetchSize;
+            if (0 < maxRows && maxRows < currentFetchSize) {
+            	currentFetchSize = maxRows; // JCR-3090
             }
-            stmt.setFetchSize(fetchSize);
+            stmt.setFetchSize(currentFetchSize);
             execute(stmt, params);
             if (returnGeneratedKeys) {
                 rs = stmt.getGeneratedKeys();
@@ -395,7 +412,7 @@ public class ConnectionHelper {
         }
     }
 
-    /**
+	/**
      * Gets a connection based on the {@code batchMode} state of this helper. The connection
should be closed
      * by a call to {@link #closeResources(Connection, Statement, ResultSet)} which also
takes the {@code
      * batchMode} state into account.

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/PostgreSQLConnectionHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/PostgreSQLConnectionHelper.java?rev=1182667&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/PostgreSQLConnectionHelper.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/PostgreSQLConnectionHelper.java
Thu Oct 13 05:56:43 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.util.db;
+
+import javax.sql.DataSource;
+
+/**
+ * The connection helper for PSQL databases. It has special fetch size handling.
+ */
+public final class PostgreSQLConnectionHelper extends ConnectionHelper {
+
+    /**
+     * @param dataSrc the {@code DataSource} on which this helper acts
+     * @param block whether to block on connection loss until the db is up again
+     */
+    public PostgreSQLConnectionHelper(DataSource dataSrc, boolean block) {
+        super(dataSrc, false, block, 10000);
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/PostgreSQLConnectionHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message