You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Apache Wiki <wi...@apache.org> on 2010/05/17 10:06:52 UTC

[Commons Wiki] Update of "DBCP/Hibernate" by martinschaaf

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Commons Wiki" for change notification.

The "DBCP/Hibernate" page has been changed by martinschaaf.
The comment on this change is: add method implementation for supportAggressiveRelease.
http://wiki.apache.org/jakarta-commons/DBCP/Hibernate?action=diff&rev1=5&rev2=6

--------------------------------------------------

  = About Hibernate & DBCP =
+ [[http://www.hibernate.org/|Hibernate]] 2 includes a limited [[DBCP]] ConnectionProvider. Not all features of DBCP were supported and with Hibernate3 this limited implementation was deprecated.
- 
- [[http://www.hibernate.org/|Hibernate]] 2 includes a limited [[DBCP]] ConnectionProvider.
- Not all features of DBCP were supported and with Hibernate3 this limited implementation was deprecated.
  
  There is an implementation on this page. The original author said:
  
-    The implementation below supports all DBCP features and is a drop in replacement for the default version.
+  . The implementation below supports all DBCP features and is a drop in replacement for the default version.
  
  However this is untrue. It fails to support:
  
-   * Almost all `hibernate.dbcp.ps.*` properties
+  * Almost all `hibernate.dbcp.ps.*` properties
-   * `hibernate.dbcp.whenExhaustedAction`
+  * `hibernate.dbcp.whenExhaustedAction`
-   * ... maybe more?
+  * ... maybe more?
  
  so personally I feel rather dubious about using it.
  
@@ -23, +21 @@

  {{{
  /*
   * Copyright 2004 The Apache Software Foundation.
-  * 
+  *
   * 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.
@@ -54, +52 @@

  
  /**
   * <p>A connection provider that uses an Apache commons DBCP connection pool.</p>
-  * 
+  *
   * <p>To use this connection provider set:<br>
   * <code>hibernate.connection.provider_class&nbsp;org.hibernate.connection.DBCPConnectionProvider</code></p>
   *
@@ -82, +80 @@

   *   hibernate.dbcp.initialSize 10
   *   hibernate.dbcp.maxWait 3000
   *   hibernate.dbcp.validationQuery select 1 from dual</pre>
-  * 
+  *
-  * <p>More information about configuring/using DBCP can be found on the 
+  * <p>More information about configuring/using DBCP can be found on the
   * <a href="http://jakarta.apache.org/commons/dbcp/">DBCP website</a>.
-  * There you will also find the DBCP wiki, mailing lists, issue tracking 
+  * There you will also find the DBCP wiki, mailing lists, issue tracking
-  * and other support facilities</p>  
+  * and other support facilities</p>
-  * 
+  *
   * @see org.hibernate.connection.ConnectionProvider
   * @author Dirk Verbeeck
   */
@@ -106, +104 @@

      public void configure(Properties props) throws HibernateException {
          try {
              log.debug("Configure DBCPConnectionProvider");
-             
+ 
              // DBCP properties used to create the BasicDataSource
              Properties dbcpProperties = new Properties();
  
@@ -115, +113 @@

              String jdbcUrl = props.getProperty(Environment.URL);
              dbcpProperties.put("driverClassName", jdbcDriverClass);
              dbcpProperties.put("url", jdbcUrl);
-             
+ 
              // Username / password
              String username = props.getProperty(Environment.USER);
              String password = props.getProperty(Environment.PASS);
@@ -127, +125 @@

              if ((isolationLevel != null) && (isolationLevel.trim().length() > 0)) {
                  dbcpProperties.put("defaultTransactionIsolation", isolationLevel);
              }
-             
+ 
-             // Turn off autocommit (unless autocommit property is set) 
+             // Turn off autocommit (unless autocommit property is set)
              String autocommit = props.getProperty(AUTOCOMMIT);
              if ((autocommit != null) && (autocommit.trim().length() > 0)) {
                  dbcpProperties.put("defaultAutoCommit", autocommit);
@@ -138, +136 @@

  
              // Pool size
              String poolSize = props.getProperty(Environment.POOL_SIZE);
-             if ((poolSize != null) && (poolSize.trim().length() > 0) 
+             if ((poolSize != null) && (poolSize.trim().length() > 0)
                  && (Integer.parseInt(poolSize) > 0))  {
                  dbcpProperties.put("maxActive", poolSize);
              }
@@ -169, +167 @@

                      dbcpProperties.put(property, value);
                  }
              }
-             
+ 
              // Backward-compatibility
              if (props.getProperty(DBCP_PS_MAXACTIVE) != null) {
                  dbcpProperties.put("poolPreparedStatements", String.valueOf(Boolean.TRUE));
                  dbcpProperties.put("maxOpenPreparedStatements", props.getProperty(DBCP_PS_MAXACTIVE));
              }
-             
+ 
              // Some debug info
              if (log.isDebugEnabled()) {
                  log.debug("Creating a DBCP BasicDataSource with the following DBCP factory properties:");
@@ -186, +184 @@

  
              // Let the factory create the pool
              ds = (BasicDataSource) BasicDataSourceFactory.createDataSource(dbcpProperties);
-             
+ 
              // The BasicDataSource has lazy initialization
              // borrowing a connection will start the DataSource
              // and make sure it is configured correctly.
@@ -216, +214 @@

      public Connection getConnection() throws SQLException {
          Connection conn = null;
          try {
- 	        conn = ds.getConnection();
+                 conn = ds.getConnection();
          }
          finally {
              logStatistics();
@@ -239, +237 @@

          try {
              if (ds != null) {
                  ds.close();
- 	            ds = null;
+                     ds = null;
              }
              else {
                  log.warn("Cannot close DBCP pool (not initialized)");
@@ -250, +248 @@

          }
          log.debug("Close DBCPConnectionProvider complete");
      }
-     
+ 
      protected void logStatistics() {
          if (log.isInfoEnabled()) {
              log.info("active: " + ds.getNumActive() + " (max: " + ds.getMaxActive() + ")   "
                      + "idle: " + ds.getNumIdle() + "(max: " + ds.getMaxIdle() + ")");
          }
      }
+ 
+     public boolean supportsAggressiveRelease()
+     {
+         return false;
+     }
  }
  }}}
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org