dirkv 2003/09/13 15:29:39 Modified: dbcp/src/java/org/apache/commons/dbcp BasicDataSource.java BasicDataSourceFactory.java PoolingDataSource.java Log: Bugzilla Bug 23138: getDelegate no longer useful - restored the getDelegate & getInnermostDelegate feature but it has to be enabled by setting the accessToUnderlyingConnectionAllowed property. (it is a potential dangerous operation) Revision Changes Path 1.24 +28 -5 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java Index: BasicDataSource.java =================================================================== RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- BasicDataSource.java 27 Aug 2003 15:43:55 -0000 1.23 +++ BasicDataSource.java 13 Sep 2003 22:29:39 -0000 1.24 @@ -423,6 +423,30 @@ this.validationQuery = validationQuery; } + /** + * Controls access to the underlying connection + */ + private boolean accessToUnderlyingConnectionAllowed = false; + + /** + * Returns the value of the accessToUnderlyingConnectionAllowed property. + * + * @return true if access to the underlying is allowed, false otherwise. + */ + public boolean isAccessToUnderlyingConnectionAllowed() { + return this.accessToUnderlyingConnectionAllowed; + } + + /** + * Sets the value of the accessToUnderlyingConnectionAllowed property. + * It controls if the PoolGuard allows access to the underlying connection. + * (Default: false) + * + * @param allow Access to the underlying connection is granted when true. + */ + public void setAccessToUnderlyingConnectionAllowed(boolean allow) { + this.accessToUnderlyingConnectionAllowed = allow; + } // ----------------------------------------------------- Instance Variables @@ -624,10 +648,8 @@ abandonedConfig.setLogAbandoned(logAbandoned); } - // --------------------------------------------------------- Public Methods - /** * Add a custom connection property to the set that will be passed to our * JDBC driver. This <strong>MUST</strong> be called before the first @@ -786,6 +808,7 @@ // Create and return the pooling data source to manage the connections dataSource = new PoolingDataSource(connectionPool); + ((PoolingDataSource) dataSource).setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed()); dataSource.setLogWriter(logWriter); return (dataSource); 1.10 +9 -3 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java Index: BasicDataSourceFactory.java =================================================================== RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSourceFactory.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- BasicDataSourceFactory.java 26 Aug 2003 14:19:28 -0000 1.9 +++ BasicDataSourceFactory.java 13 Sep 2003 22:29:39 -0000 1.10 @@ -255,6 +255,12 @@ dataSource.setValidationQuery(ra.getContent().toString()); } + ra = ref.get("accessToUnderlyingConnectionAllowed"); + if (ra != null) { + dataSource.setAccessToUnderlyingConnectionAllowed + (Boolean.valueOf(ra.getContent().toString()).booleanValue()); + } + ra = ref.get("removeAbandoned"); if (ra != null) { dataSource.setRemoveAbandoned 1.9 +56 -8 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolingDataSource.java Index: PoolingDataSource.java =================================================================== RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolingDataSource.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- PoolingDataSource.java 22 Aug 2003 16:08:31 -0000 1.8 +++ PoolingDataSource.java 13 Sep 2003 22:29:39 -0000 1.9 @@ -87,6 +87,10 @@ * @version $Id$ */ public class PoolingDataSource implements DataSource { + + /** Controls access to the underlying connection */ + private boolean accessToUnderlyingConnectionAllowed = false; + public PoolingDataSource() { this(null); } @@ -104,6 +108,27 @@ _pool = pool; } } + + /** + * Returns the value of the accessToUnderlyingConnectionAllowed property. + * + * @return true if access to the underlying is allowed, false otherwise. + */ + public boolean isAccessToUnderlyingConnectionAllowed() { + return this.accessToUnderlyingConnectionAllowed; + } + + /** + * Sets the value of the accessToUnderlyingConnectionAllowed property. + * It controls if the PoolGuard allows access to the underlying connection. + * (Default: false) + * + * @param allow Access to the underlying connection is granted when true. + */ + public void setAccessToUnderlyingConnectionAllowed(boolean allow) { + this.accessToUnderlyingConnectionAllowed = allow; + } + //--- DataSource methods ----------------------------------------- /** @@ -179,14 +204,13 @@ /** * PoolGuardConnectionWrapper is a Connection wrapper that makes sure a * closed connection cannot be used anymore. - * - * @author Dirk Verbeeck */ - private class PoolGuardConnectionWrapper implements Connection { + private class PoolGuardConnectionWrapper extends DelegatingConnection { private Connection delegate; PoolGuardConnectionWrapper(Connection delegate) { + super(delegate); this.delegate = delegate; } @@ -198,7 +222,9 @@ public void close() throws SQLException { checkOpen(); - delegate.close(); + this.delegate.close(); + this.delegate = null; + super.setDelegate(null); } public boolean isClosed() throws SQLException { @@ -405,5 +431,27 @@ } /* JDBC_3_ANT_KEY_END */ + + /** + * @see org.apache.commons.dbcp.DelegatingConnection#getDelegate() + */ + public Connection getDelegate() { + if (isAccessToUnderlyingConnectionAllowed()) { + return super.getDelegate(); + } else { + return null; + } + } + + /** + * @see org.apache.commons.dbcp.DelegatingConnection#getInnermostDelegate() + */ + public Connection getInnermostDelegate() { + if (isAccessToUnderlyingConnectionAllowed()) { + return super.getInnermostDelegate(); + } else { + return null; + } + } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]