[hibernate-commits] Hibernate SVN: r12935 - in sandbox/trunk: jdbc-impl and 17 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Aug 14 13:19:22 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-08-14 13:19:22 -0400 (Tue, 14 Aug 2007)
New Revision: 12935

Added:
   sandbox/trunk/jdbc-impl/
   sandbox/trunk/jdbc-impl/pom.xml
   sandbox/trunk/jdbc-impl/src/
   sandbox/trunk/jdbc-impl/src/main/
   sandbox/trunk/jdbc-impl/src/main/java/
   sandbox/trunk/jdbc-impl/src/main/java/org/
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ConnectionWrapper.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainer.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainerBuilder.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCServices.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/LogicalConnection.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ResultSetWrapper.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/StatementWrapper.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/CallableStatementDelegate.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetWrapperImplementor.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/StatementWrapperImplementor.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/ExceptionHelper.java
   sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/SQLStatementLogger.java
   sandbox/trunk/jdbc-impl/src/test/
   sandbox/trunk/jdbc-impl/src/test/java/
   sandbox/trunk/jdbc-impl/src/test/java/org/
   sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/
   sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/
   sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java
   sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/
   sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java
   sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java
   sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/
   sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/BasicConnectionTests.java
   sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java
   sandbox/trunk/jdbc-impl/src/test/resources/
   sandbox/trunk/jdbc-impl/src/test/resources/log4j.properties
Log:
crude direct-impl approach


Property changes on: sandbox/trunk/jdbc-impl
___________________________________________________________________
Name: svn:ignore
   + target
test-output
local
*.ipr
*.iws
*.iml
.classpath
.project
.nbattrs
*.log
*.properties
.clover


Added: sandbox/trunk/jdbc-impl/pom.xml
===================================================================
--- sandbox/trunk/jdbc-impl/pom.xml	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/pom.xml	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,73 @@
+ <project xmlns="http://maven.apache.org/POM/4.0.0" 
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    
+    <parent>
+        <groupId>org.hibernate</groupId>
+        <artifactId>hibernate-core-parent</artifactId>
+        <version>1</version>
+    </parent>
+
+    <groupId>org.hibernate.sandbox</groupId>
+    <artifactId>jdbc-impl</artifactId>
+    <version>1</version>
+    <packaging>jar</packaging>
+
+    <name>JDBC Implementation (sandbox)</name>
+    <description>PoC of a impl/delegation-based approach to JDBC interaction</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.hibernate</groupId>
+            <artifactId>hibernate-core</artifactId>
+            <version>3.3.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.4.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>1.4.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.14</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+            <version>5.5</version>
+            <classifier>jdk15</classifier>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>hsqldb</groupId>
+            <artifactId>hsqldb</artifactId>
+            <version>1.8.0.2</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+     <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+              </plugin>
+         </plugins>
+     </build>
+
+</project>
+

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ConnectionWrapper.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ConnectionWrapper.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ConnectionWrapper.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.Connection;
+
+/**
+ * Extra contract for {@link java.sql.Connection} proxies, for clients to be able to
+ * obtain the wrapped connection.
+ *
+ * @author Steve Ebersole
+ */
+public interface ConnectionWrapper {
+	/**
+	 * Obtain the wrapped connection being delegated to.
+	 * <p/>
+	 * NOTE : The scope of validity for the returned connection is
+	 * undefined.
+	 *
+	 * @return The wrapped connection.
+	 */
+	public Connection getWrappedConnection();
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainer.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainer.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+/**
+ * JDBCContainer contract
+ *
+ * @author Steve Ebersole
+ */
+public interface JDBCContainer {
+	public void register(Statement statement);
+	public void release(Statement statement);
+
+	public void register(ResultSet resultSet);
+	public void release(ResultSet resultSet);
+
+	public boolean hasRegisteredResources();
+
+	public void close();
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainerBuilder.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainerBuilder.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainerBuilder.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+/**
+ * Contract for building {@link JDBCContainer} instances.
+ * <p/>
+ * Used mainly to make explicit the contract that a
+ * {@link LogicalConnection} owns the lifecycle of the container.
+ *
+ * @author Steve Ebersole
+ */
+public interface JDBCContainerBuilder {
+	public JDBCContainer buildJdbcContainer();
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCServices.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCServices.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCServices.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.jdbc.util.ExceptionHelper;
+import org.hibernate.jdbc.util.SQLStatementLogger;
+
+/**
+ * Contract for services around JDBC operations.
+ *
+ * @author Steve Ebersole
+ */
+public interface JDBCServices {
+	public ConnectionProvider getConnectionProvider();
+	public JDBCContainerBuilder getJdbcContainerBuilder();
+	public SQLStatementLogger getSqlStatementLogger();
+	public ExceptionHelper getExceptionHelper();
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/LogicalConnection.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/LogicalConnection.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/LogicalConnection.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.Connection;
+
+/**
+ * LogicalConnection contract
+ *
+ * @author Steve Ebersole
+ */
+public interface LogicalConnection {
+	/**
+	 * Is this LogicalConnection open?  Another phraseology sometimes used is: "are we
+	 * logically connected"?
+	 *
+	 * @return True if physically connected; false otherwise.
+	 */
+	public boolean isOpen();
+
+	/**
+	 * Is this LogicalConnection instance "physically" connected.  Meaning
+	 * do we currently internally have a cached connection.
+	 *
+	 * @return True if physically connected; false otherwise.
+	 */
+	public boolean isPhysicallyConnected();
+
+	/**
+	 * Retreives the connection currently "logically" managed by this LogicalConnectionImpl.
+	 * <p/>
+	 * Note, that we may need to obtain a connection to return here if a
+	 * connection has either not yet been obtained (non-UserSuppliedConnectionProvider)
+	 * or has previously been aggressively released.
+	 *
+	 * @return The current Connection.
+	 */
+	public Connection getConnection();
+
+	/**
+	 * Release the underlying connection and clean up any other resources associated
+	 * with this logical connection.
+	 * <p/>
+	 * This leaves the logical connection in a "no longer useable" state.
+	 *
+	 * @return The physical connection which was being used.
+	 */
+	public Connection close();
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ResultSetWrapper.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ResultSetWrapper.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ResultSetWrapper.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.ResultSet;
+
+/**
+ * Extra contract for {@link ResultSet} proxies, for clients to be able to
+ * obtain the wrapped resultset.
+ *
+ * @author Steve Ebersole
+ */
+public interface ResultSetWrapper {
+	/**
+	 * Obtain the wrapped resultset to which this wrapper is delegating.
+	 *
+	 * @return The wrapped resultset.
+	 */
+	public ResultSet getWrappedResultSet();
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/StatementWrapper.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/StatementWrapper.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/StatementWrapper.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.Statement;
+
+/**
+ * Extra contract for {@link Statement} proxies, for clients to be able to
+ * obtain the wrapped statement.
+ *
+ * @author Steve Ebersole
+ */
+public interface StatementWrapper {
+	/**
+	 * Obtain the wrapped statement to which this wrapper is delegating.
+	 *
+	 * @return The wrapped statement.
+	 */
+	public Statement getWrappedStatement();
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainer;
+
+/**
+ * AbstractStatementDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractStatementDelegate implements Statement, StatementWrapperImplementor {
+	private static final Logger log = LoggerFactory.getLogger( AbstractStatementDelegate.class );
+
+	private boolean valid = true;
+	private ConnectionDelegate connectionDelegate;
+	private Statement statement;
+
+	private ResultSet currentResultSetDelegate;
+
+	public AbstractStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement) {
+		this.connectionDelegate = connectionDelegate;
+		this.statement = statement;
+		getJdbcContainer().register( this );
+	}
+
+	protected void errorIfInvalid() {
+		if ( !valid ) {
+			throw new HibernateException( "statement handle is invalid" );
+		}
+	}
+
+	/*package-protected*/ JDBCServices getJdbcServices() {
+		return connectionDelegate.getJdbcServices();
+	}
+
+	/*package-protected*/ JDBCContainer getJdbcContainer() {
+		return connectionDelegate.getJdbcContainer();
+	}
+
+	protected Statement getWrappedStatementWithoutChecks() {
+		return statement;
+	}
+
+	public Statement getWrappedStatement() {
+		errorIfInvalid();
+		return statement;
+	}
+
+	public void invalidate() {
+		connectionDelegate = null;
+		statement = null;
+		valid = false;
+	}
+
+
+	// special Statement methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public Connection getConnection() throws SQLException {
+		errorIfInvalid();
+		return connectionDelegate;
+	}
+
+	public void close() throws SQLException {
+		if ( valid ) {
+			getJdbcContainer().release( this );
+		}
+	}
+
+	// execution-related methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public ResultSet getGeneratedKeys() throws SQLException {
+		return new ResultSetDelegate( this, getWrappedStatement().getGeneratedKeys() );
+	}
+
+	public ResultSet getResultSet() throws SQLException {
+		currentResultSetDelegate = new ResultSetDelegate( this, getWrappedStatement().getResultSet() );
+		return currentResultSetDelegate;
+	}
+
+	public int getUpdateCount() throws SQLException {
+		return getWrappedStatement().getUpdateCount();
+	}
+
+	public boolean getMoreResults() throws SQLException {
+		return getMoreResults( Statement.CLOSE_CURRENT_RESULT );
+	}
+
+	public boolean getMoreResults(int current) throws SQLException {
+		if ( current == Statement.CLOSE_ALL_RESULTS ) {
+			log.warn( "getMoreResults call requested all previous results be closed, but thats not possible here" );
+			current = Statement.CLOSE_CURRENT_RESULT;
+		}
+		if ( current == Statement.CLOSE_CURRENT_RESULT && currentResultSetDelegate != null ) {
+			getJdbcContainer().release( currentResultSetDelegate );
+		}
+		currentResultSetDelegate = null;
+		return getWrappedStatement().getMoreResults( current );
+	}
+
+	public void cancel() throws SQLException {
+		getWrappedStatement().cancel();
+	}
+
+	public void clearBatch() throws SQLException {
+		getWrappedStatement().clearBatch();
+	}
+
+	public int[] executeBatch() throws SQLException {
+		return getWrappedStatement().executeBatch();
+	}
+
+
+	// general Statement methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public int getMaxFieldSize() throws SQLException {
+		return getWrappedStatement().getMaxFieldSize();
+	}
+
+	public void setMaxFieldSize(int max) throws SQLException {
+		getWrappedStatement().setMaxFieldSize( max );
+	}
+
+	public int getMaxRows() throws SQLException {
+		return getWrappedStatement().getMaxRows();
+	}
+
+	public void setMaxRows(int max) throws SQLException {
+		getWrappedStatement().setMaxRows( max );
+	}
+
+	public void setEscapeProcessing(boolean enable) throws SQLException {
+		getWrappedStatement().setEscapeProcessing( enable );
+	}
+
+	public int getQueryTimeout() throws SQLException {
+		return getWrappedStatement().getQueryTimeout();
+	}
+
+	public void setQueryTimeout(int seconds) throws SQLException {
+		getWrappedStatement().setQueryTimeout( seconds );
+	}
+
+	public void setCursorName(String name) throws SQLException {
+		getWrappedStatement().setCursorName( name );
+	}
+
+	public void setFetchDirection(int direction) throws SQLException {
+		getWrappedStatement().setFetchDirection( direction );
+	}
+
+	public int getFetchDirection() throws SQLException {
+		return getWrappedStatement().getFetchDirection();
+	}
+
+	public void setFetchSize(int rows) throws SQLException {
+		getWrappedStatement().setFetchSize( rows );
+	}
+
+	public int getFetchSize() throws SQLException {
+		return getWrappedStatement().getFetchSize();
+	}
+
+	public int getResultSetConcurrency() throws SQLException {
+		return getWrappedStatement().getResultSetConcurrency();
+	}
+
+	public int getResultSetType() throws SQLException {
+		return getWrappedStatement().getResultSetType();
+	}
+
+	public int getResultSetHoldability() throws SQLException {
+		return getWrappedStatement().getResultSetHoldability();
+	}
+
+	public SQLWarning getWarnings() throws SQLException {
+		return getWrappedStatement().getWarnings();
+	}
+
+	public void clearWarnings() throws SQLException {
+		getWrappedStatement().clearWarnings();
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.Statement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * BasicStatementDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicStatementDelegate extends AbstractStatementDelegate {
+	public BasicStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement) {
+		super( connectionDelegate, statement );
+	}
+
+	public void addBatch(String sql) throws SQLException {
+		getJdbcServices().getSqlStatementLogger().logStatement( sql );
+		getWrappedStatement().addBatch( sql );
+	}
+
+	public boolean execute(String sql) throws SQLException {
+		getJdbcServices().getSqlStatementLogger().logStatement( sql );
+		return getWrappedStatement().execute( sql );
+	}
+
+	public ResultSet executeQuery(String sql) throws SQLException {
+		getJdbcServices().getSqlStatementLogger().logStatement( sql );
+		return new ResultSetDelegate( this, getWrappedStatement().executeQuery( sql ) );
+	}
+
+	public int executeUpdate(String sql) throws SQLException {
+		getJdbcServices().getSqlStatementLogger().logStatement( sql );
+		return getWrappedStatement().executeUpdate( sql );
+	}
+
+	public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+		getJdbcServices().getSqlStatementLogger().logStatement( sql );
+		return getWrappedStatement().executeUpdate( sql, autoGeneratedKeys );
+	}
+
+	public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+		getJdbcServices().getSqlStatementLogger().logStatement( sql );
+		return getWrappedStatement().executeUpdate( sql, columnIndexes );
+	}
+
+	public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+		getJdbcServices().getSqlStatementLogger().logStatement( sql );
+		return getWrappedStatement().executeUpdate( sql, columnNames );
+	}
+
+	public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+		getJdbcServices().getSqlStatementLogger().logStatement( sql );
+		return getWrappedStatement().execute( sql, autoGeneratedKeys );
+	}
+
+	public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+		getJdbcServices().getSqlStatementLogger().logStatement( sql );
+		return getWrappedStatement().execute( sql, columnIndexes );
+	}
+
+	public boolean execute(String sql, String[] columnNames) throws SQLException {
+		getJdbcServices().getSqlStatementLogger().logStatement( sql );
+		return getWrappedStatement().execute( sql, columnNames );
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/CallableStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/CallableStatementDelegate.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/CallableStatementDelegate.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,376 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.Ref;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Map;
+
+import org.hibernate.HibernateException;
+
+/**
+ * CallableStatementDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public class CallableStatementDelegate extends PreparedStatementDelegate implements CallableStatement {
+	public CallableStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement, String sql) {
+		super( connectionDelegate, statement, sql );
+		if ( ! ( statement instanceof CallableStatement ) ) {
+			throw new HibernateException( "iilegal argument: statement should be PreparedStatement" );
+		}
+	}
+
+	protected CallableStatement getCallableStatement() {
+		return ( CallableStatement ) super.getWrappedStatement();
+	}
+
+
+	// CallableStatement impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
+		getCallableStatement().registerOutParameter( parameterIndex, sqlType );
+	}
+
+	public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
+		getCallableStatement().registerOutParameter( parameterIndex, sqlType, scale );
+	}
+
+	public void registerOutParameter(int paramIndex, int sqlType, String typeName) throws SQLException {
+		getCallableStatement().registerOutParameter( paramIndex, sqlType, typeName );
+	}
+
+	public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
+		getCallableStatement().registerOutParameter( parameterName, sqlType );
+	}
+
+	public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
+		getCallableStatement().registerOutParameter( parameterName, sqlType, scale );
+	}
+
+	public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
+		getCallableStatement().registerOutParameter( parameterName, sqlType, typeName );
+	}
+
+
+	public boolean wasNull() throws SQLException {
+		return getCallableStatement().wasNull();
+	}
+
+	public void setNull(String parameterName, int sqlType) throws SQLException {
+		getCallableStatement().setNull( parameterName, sqlType );
+	}
+
+	public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
+		getCallableStatement().setNull( parameterName, sqlType, typeName );
+	}
+
+	public Object getObject(int parameterIndex) throws SQLException {
+		return getCallableStatement().getObject( parameterIndex );
+	}
+
+	public Object getObject(int i, Map<String, Class<?>> map) throws SQLException {
+		return getCallableStatement().getObject( i, map );
+	}
+
+	public Object getObject(String parameterName) throws SQLException {
+		return getCallableStatement().getObject( parameterName );
+	}
+
+	public Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException {
+		return getCallableStatement().getObject( parameterName, map );
+	}
+
+	public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {
+		getCallableStatement().setObject( parameterName, x, targetSqlType, scale );
+	}
+
+	public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
+		getCallableStatement().setObject( parameterName, x, targetSqlType );
+	}
+
+	public void setObject(String parameterName, Object x) throws SQLException {
+		getCallableStatement().setObject( parameterName, x );
+	}
+
+	public String getString(int parameterIndex) throws SQLException {
+		return getCallableStatement().getString( parameterIndex );
+	}
+
+	public String getString(String parameterName) throws SQLException {
+		return getCallableStatement().getString( parameterName );
+	}
+
+	public void setString(String parameterName, String x) throws SQLException {
+		getCallableStatement().setString( parameterName, x );
+	}
+
+	public boolean getBoolean(int parameterIndex) throws SQLException {
+		return getCallableStatement().getBoolean( parameterIndex );
+	}
+
+	public boolean getBoolean(String parameterName) throws SQLException {
+		return getCallableStatement().getBoolean( parameterName );
+	}
+
+	public void setBoolean(String parameterName, boolean x) throws SQLException {
+		getCallableStatement().setBoolean( parameterName, x );
+	}
+
+	public byte getByte(int parameterIndex) throws SQLException {
+		return getCallableStatement().getByte( parameterIndex );
+	}
+
+	public byte getByte(String parameterName) throws SQLException {
+		return getCallableStatement().getByte( parameterName );
+	}
+
+	public void setByte(String parameterName, byte x) throws SQLException {
+		getCallableStatement().setByte( parameterName, x );
+	}
+
+	public short getShort(int parameterIndex) throws SQLException {
+		return getCallableStatement().getShort( parameterIndex );
+	}
+
+	public short getShort(String parameterName) throws SQLException {
+		return getCallableStatement().getShort( parameterName );
+	}
+
+	public void setShort(String parameterName, short x) throws SQLException {
+		getCallableStatement().setShort( parameterName, x );
+	}
+
+	public int getInt(int parameterIndex) throws SQLException {
+		return getCallableStatement().getInt( parameterIndex );
+	}
+
+	public int getInt(String parameterName) throws SQLException {
+		return getCallableStatement().getInt( parameterName );
+	}
+
+	public void setInt(String parameterName, int x) throws SQLException {
+		getCallableStatement().setInt( parameterName, x );
+	}
+
+	public long getLong(int parameterIndex) throws SQLException {
+		return getCallableStatement().getLong( parameterIndex );
+	}
+
+	public long getLong(String parameterName) throws SQLException {
+		return getCallableStatement().getLong( parameterName );
+	}
+
+	public void setLong(String parameterName, long x) throws SQLException {
+		getCallableStatement().setLong( parameterName, x );
+	}
+
+	public float getFloat(int parameterIndex) throws SQLException {
+		return getCallableStatement().getFloat( parameterIndex );
+	}
+
+	public float getFloat(String parameterName) throws SQLException {
+		return getCallableStatement().getFloat( parameterName );
+	}
+
+	public void setFloat(String parameterName, float x) throws SQLException {
+		getCallableStatement().setFloat( parameterName, x );
+	}
+
+	public double getDouble(int parameterIndex) throws SQLException {
+		return getCallableStatement().getDouble( parameterIndex );
+	}
+
+	public double getDouble(String parameterName) throws SQLException {
+		return getCallableStatement().getDouble( parameterName );
+	}
+
+	public void setDouble(String parameterName, double x) throws SQLException {
+		getCallableStatement().setDouble( parameterName, x );
+	}
+
+	public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
+		return getCallableStatement().getBigDecimal( parameterIndex );
+	}
+
+	@Deprecated
+	public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
+		return getCallableStatement().getBigDecimal( parameterIndex, scale );
+	}
+
+	public BigDecimal getBigDecimal(String parameterName) throws SQLException {
+		return getCallableStatement().getBigDecimal( parameterName );
+	}
+
+	public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
+		getCallableStatement().setBigDecimal( parameterName, x );
+	}
+
+	public byte[] getBytes(int parameterIndex) throws SQLException {
+		return getCallableStatement().getBytes( parameterIndex );
+	}
+
+	public byte[] getBytes(String parameterName) throws SQLException {
+		return getCallableStatement().getBytes( parameterName );
+	}
+
+	public void setBytes(String parameterName, byte[] x) throws SQLException {
+		getCallableStatement().setBytes( parameterName, x );
+	}
+
+	public Date getDate(int parameterIndex) throws SQLException {
+		return getCallableStatement().getDate( parameterIndex );
+	}
+
+	public Date getDate(String parameterName) throws SQLException {
+		return getCallableStatement().getDate( parameterName );
+	}
+
+	public Date getDate(String parameterName, Calendar cal) throws SQLException {
+		return getCallableStatement().getDate( parameterName, cal );
+	}
+
+	public void setDate(String parameterName, Date x) throws SQLException {
+		getCallableStatement().setDate( parameterName, x );
+	}
+
+	public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
+		getCallableStatement().setDate( parameterName, x, cal );
+	}
+
+	public Time getTime(int parameterIndex) throws SQLException {
+		return getCallableStatement().getTime( parameterIndex );
+	}
+
+	public Timestamp getTimestamp(int parameterIndex) throws SQLException {
+		return getCallableStatement().getTimestamp( parameterIndex );
+	}
+
+	public Ref getRef(int i) throws SQLException {
+		return getCallableStatement().getRef( i );
+	}
+
+	public Ref getRef(String parameterName) throws SQLException {
+		return getCallableStatement().getRef( parameterName );
+	}
+
+	public Blob getBlob(int i) throws SQLException {
+		return getCallableStatement().getBlob( i );
+	}
+
+	public Blob getBlob(String parameterName) throws SQLException {
+		return getCallableStatement().getBlob( parameterName );
+	}
+
+	public Clob getClob(int i) throws SQLException {
+		return getCallableStatement().getClob( i );
+	}
+
+	public Clob getClob(String parameterName) throws SQLException {
+		return getCallableStatement().getClob( parameterName );
+	}
+
+	public Array getArray(int i) throws SQLException {
+		return getCallableStatement().getArray( i );
+	}
+
+	public Array getArray(String parameterName) throws SQLException {
+		return getCallableStatement().getArray( parameterName );
+	}
+
+	public Date getDate(int parameterIndex, Calendar cal) throws SQLException {
+		return getCallableStatement().getDate( parameterIndex, cal );
+	}
+
+	public Time getTime(int parameterIndex, Calendar cal) throws SQLException {
+		return getCallableStatement().getTime( parameterIndex, cal );
+	}
+
+	public Time getTime(String parameterName) throws SQLException {
+		return getCallableStatement().getTime( parameterName );
+	}
+
+	public Time getTime(String parameterName, Calendar cal) throws SQLException {
+		return getCallableStatement().getTime( parameterName, cal );
+	}
+
+	public void setTime(String parameterName, Time x) throws SQLException {
+		getCallableStatement().setTime( parameterName, x );
+	}
+
+	public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
+		getCallableStatement().setTime( parameterName, x, cal );
+	}
+
+	public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {
+		return getCallableStatement().getTimestamp( parameterIndex, cal );
+	}
+
+	public Timestamp getTimestamp(String parameterName) throws SQLException {
+		return getCallableStatement().getTimestamp( parameterName );
+	}
+
+	public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
+		return getCallableStatement().getTimestamp( parameterName, cal );
+	}
+
+	public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
+		getCallableStatement().setTimestamp( parameterName, x );
+	}
+
+	public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
+		getCallableStatement().setTimestamp( parameterName, x, cal );
+	}
+
+	public URL getURL(int parameterIndex) throws SQLException {
+		return getCallableStatement().getURL( parameterIndex );
+	}
+
+	public URL getURL(String parameterName) throws SQLException {
+		return getCallableStatement().getURL( parameterName );
+	}
+
+	public void setURL(String parameterName, URL val) throws SQLException {
+		getCallableStatement().setURL( parameterName, val );
+	}
+
+	public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
+		getCallableStatement().setAsciiStream( parameterName, x, length );
+	}
+
+	public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
+		getCallableStatement().setBinaryStream( parameterName, x, length );
+	}
+
+	public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
+		getCallableStatement().setCharacterStream( parameterName, reader, length );
+	}
+
+
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,333 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.jdbc.impl.ConnectionObserver;
+import org.hibernate.jdbc.ConnectionWrapper;
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
+import org.hibernate.HibernateException;
+
+/**
+ * Connection implementation which delegates to the current connection as defined
+ * by its logical connection.
+ *
+ * @author Steve Ebersole
+ */
+public class ConnectionDelegate implements Connection, ConnectionWrapper, ConnectionObserver {
+	private static final Logger log = LoggerFactory.getLogger( ConnectionDelegate.class );
+
+	private boolean valid = true;
+	private LogicalConnectionImplementor logicalConnection;
+
+	/**
+	 * Builds a connection delegate with the given logical connection.
+	 *
+	 * @param logicalConnection The logical connection handling this
+	 * connection delegate's access to physical connections.
+	 */
+	public ConnectionDelegate(LogicalConnectionImplementor logicalConnection) {
+		this.logicalConnection = logicalConnection;
+		logicalConnection.addObserver( this );
+	}
+
+	/*package-protected*/ JDBCServices getJdbcServices() {
+		return logicalConnection.getJdbcServices();
+	}
+
+	/*package-protected*/ JDBCContainer getJdbcContainer() {
+		return logicalConnection.getJdbcContainer();
+	}
+
+	public Connection getWrappedConnection() {
+		if ( !valid ) {
+			throw new HibernateException( "connection handle is invalid" );
+		}
+		return logicalConnection.getConnection();
+	}
+
+	protected Connection getWrappedConnectionWithoutChecks() {
+		return logicalConnection.getConnection();
+	}
+
+	public void physicalConnectionObtained() {
+	}
+
+	public void physicalConnectionReleased() {
+	}
+
+	public void logicalConnectionClosed() {
+		log.info( "*** logical connection closed ***" );
+		invalidateDelegate();
+	}
+
+	private void invalidateDelegate() {
+		log.trace( "Invalidating connection delegate" );
+		logicalConnection = null;
+		valid = false;
+	}
+
+
+	// statement-creation methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public Statement createStatement() {
+		try {
+			Statement statement = getWrappedConnection().createStatement();
+			return new BasicStatementDelegate( this, statement );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to create basic statement" );
+		}
+	}
+
+	public Statement createStatement(int resultSetType, int resultSetConcurrency) {
+		try {
+			Statement statement = getWrappedConnection().createStatement( resultSetType, resultSetConcurrency );
+			return new BasicStatementDelegate( this, statement );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to create basic statement" );
+		}
+	}
+
+	public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)  {
+		try {
+			Statement statement = getWrappedConnection()
+					.createStatement( resultSetType, resultSetConcurrency, resultSetHoldability );
+			return new BasicStatementDelegate( this, statement );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to create basic statement" );
+		}
+	}
+
+	public PreparedStatement prepareStatement(String sql) {
+		try {
+			PreparedStatement statement = getWrappedConnection().prepareStatement( sql );
+			return new PreparedStatementDelegate( this, statement, sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+		}
+	}
+
+	public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) {
+		try {
+			PreparedStatement statement = getWrappedConnection()
+					.prepareStatement( sql, resultSetType, resultSetConcurrency );
+			return new PreparedStatementDelegate( this, statement, sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+		}
+	}
+
+	public PreparedStatement prepareStatement(
+			String sql,
+			int resultSetType,
+			int resultSetConcurrency,
+			int resultSetHoldability) {
+		try {
+			PreparedStatement statement = getWrappedConnection()
+					.prepareStatement( sql, resultSetType, resultSetConcurrency, resultSetHoldability );
+			return new PreparedStatementDelegate( this, statement, sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+		}
+	}
+
+	public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) {
+		try {
+			PreparedStatement statement = getWrappedConnection().prepareStatement( sql, autoGeneratedKeys );
+			return new PreparedStatementDelegate( this, statement, sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+		}
+	}
+
+	public PreparedStatement prepareStatement(String sql, int[] columnIndexes) {
+		try {
+			PreparedStatement statement = getWrappedConnection().prepareStatement( sql, columnIndexes );
+			return new PreparedStatementDelegate( this, statement, sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+		}
+	}
+
+	public PreparedStatement prepareStatement(String sql, String[] columnNames) {
+		try {
+			PreparedStatement statement = getWrappedConnection().prepareStatement( sql, columnNames );
+			return new PreparedStatementDelegate( this, statement, sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+		}
+	}
+
+	public CallableStatement prepareCall(String sql) {
+		try {
+			CallableStatement statement = getWrappedConnection().prepareCall( sql );
+			return new CallableStatementDelegate( this, statement, sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare call", sql );
+		}
+	}
+
+	public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) {
+		try {
+			CallableStatement statement = getWrappedConnection()
+					.prepareCall( sql, resultSetType, resultSetConcurrency );
+			return new CallableStatementDelegate( this, statement, sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare call", sql );
+		}
+	}
+
+	public CallableStatement prepareCall(
+			String sql,
+			int resultSetType,
+			int resultSetConcurrency,
+			int resultSetHoldability) {
+		try {
+			CallableStatement statement = getWrappedConnection()
+					.prepareCall( sql, resultSetType, resultSetConcurrency, resultSetHoldability );
+			return new CallableStatementDelegate( this, statement, sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare call", sql );
+		}
+	}
+
+
+	// other Connection methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public void close() {
+		if ( valid ) {
+			invalidateDelegate();
+		}
+	}
+
+	public boolean isClosed() {
+		return !valid;
+	}
+
+	public void setAutoCommit(boolean autoCommit) throws SQLException {
+		getWrappedConnection().setAutoCommit( autoCommit );
+	}
+
+	public boolean getAutoCommit() throws SQLException {
+		return getWrappedConnection().getAutoCommit();
+	}
+
+	public void commit() throws SQLException {
+		getWrappedConnection().commit();
+	}
+
+	public void rollback() throws SQLException {
+		getWrappedConnection().rollback();
+	}
+
+	public DatabaseMetaData getMetaData() throws SQLException {
+		return getWrappedConnection().getMetaData();
+	}
+
+	public String nativeSQL(String sql) throws SQLException {
+		return getWrappedConnection().nativeSQL( sql );
+	}
+
+	public void setReadOnly(boolean readOnly) throws SQLException {
+		getWrappedConnection().setReadOnly( readOnly );
+	}
+
+	public boolean isReadOnly() throws SQLException {
+		return getWrappedConnection().isReadOnly();
+	}
+
+	public void setCatalog(String catalog) throws SQLException {
+		getWrappedConnection().setCatalog( catalog );
+	}
+
+	public String getCatalog() throws SQLException {
+		return getWrappedConnection().getCatalog();
+	}
+
+	public void setTransactionIsolation(int level) throws SQLException {
+		getWrappedConnection().setTransactionIsolation( level );
+	}
+
+	public int getTransactionIsolation() throws SQLException {
+		return getWrappedConnection().getTransactionIsolation();
+	}
+
+	public SQLWarning getWarnings() throws SQLException {
+		return getWrappedConnection().getWarnings();
+	}
+
+	public void clearWarnings() throws SQLException {
+		getWrappedConnection().clearWarnings();
+	}
+
+	public Map<String, Class<?>> getTypeMap() throws SQLException {
+		return getWrappedConnection().getTypeMap();
+	}
+
+	public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
+		getWrappedConnection().setTypeMap( map );
+	}
+
+	public void setHoldability(int holdability) throws SQLException {
+		getWrappedConnection().setHoldability( holdability );
+	}
+
+	public int getHoldability() throws SQLException {
+		return getWrappedConnection().getHoldability();
+	}
+
+	public Savepoint setSavepoint() throws SQLException {
+		return getWrappedConnection().setSavepoint();
+	}
+
+	public Savepoint setSavepoint(String name) throws SQLException {
+		return getWrappedConnection().setSavepoint( name );
+	}
+
+	public void rollback(Savepoint savepoint) throws SQLException {
+		getWrappedConnection().rollback( savepoint );
+	}
+
+	public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+		getWrappedConnection().releaseSavepoint( savepoint );
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.jdbc.impl.BasicJDBCContainer;
+import org.hibernate.jdbc.util.ExceptionHelper;
+
+/**
+ * DelegateJDBCContainer implementation
+ *
+ * @author Steve Ebersole
+ */
+public class DelegateJDBCContainer extends BasicJDBCContainer {
+	private static final Logger log = LoggerFactory.getLogger( DelegateJDBCContainer.class );
+
+	public DelegateJDBCContainer(ExceptionHelper exceptionHelper) {
+		super( exceptionHelper );
+	}
+
+	protected void close(Statement statement) {
+		if ( statement instanceof StatementWrapperImplementor ) {
+			StatementWrapperImplementor wrapper = ( StatementWrapperImplementor ) statement;
+			super.close( wrapper.getWrappedStatement() );
+			wrapper.invalidate();
+		}
+		else {
+			super.close( statement );
+		}
+	}
+
+	protected void close(ResultSet resultSet) {
+		if ( resultSet instanceof ResultSetWrapperImplementor ) {
+			ResultSetWrapperImplementor wrapper = ( ResultSetWrapperImplementor ) resultSet;
+			super.close( wrapper.getWrappedResultSet() );
+			wrapper.invalidate();
+		}
+		else {
+			super.close( resultSet );
+		}
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Ref;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Array;
+import java.sql.ResultSetMetaData;
+import java.sql.ParameterMetaData;
+import java.math.BigDecimal;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Calendar;
+import java.net.URL;
+
+import org.hibernate.HibernateException;
+
+/**
+ * PreparedStatementDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public class PreparedStatementDelegate extends AbstractStatementDelegate implements PreparedStatement {
+	private String sql;
+
+	public PreparedStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement, String sql) {
+		super( connectionDelegate, statement );
+		if ( ! ( statement instanceof PreparedStatement ) ) {
+			throw new HibernateException( "iilegal argument: statement should be PreparedStatement" );
+		}
+		this.sql = sql;
+		getJdbcServices().getSqlStatementLogger().logStatement( sql );
+	}
+
+	private PreparedStatement getPreparedStatement() {
+		return ( PreparedStatement ) super.getWrappedStatement();
+	}
+
+
+	// PreparedStatement impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public void addBatch() throws SQLException {
+		getPreparedStatement().addBatch();
+	}
+
+	public boolean execute() throws SQLException {
+		return getPreparedStatement().execute();
+	}
+
+	public ResultSet executeQuery() throws SQLException {
+		return new ResultSetDelegate( this, getPreparedStatement().executeQuery() );
+	}
+
+	public int executeUpdate() throws SQLException {
+		return getPreparedStatement().executeUpdate();
+	}
+
+	public ResultSetMetaData getMetaData() throws SQLException {
+		return getPreparedStatement().getMetaData();
+	}
+
+	public ParameterMetaData getParameterMetaData() throws SQLException {
+		return getPreparedStatement().getParameterMetaData();
+	}
+
+	public void clearParameters() throws SQLException {
+		getPreparedStatement().clearParameters();
+	}
+
+	public void setNull(int parameterIndex, int sqlType) throws SQLException {
+		getPreparedStatement().setNull( parameterIndex, sqlType );
+	}
+
+	public void setBoolean(int parameterIndex, boolean x) throws SQLException {
+		getPreparedStatement().setBoolean( parameterIndex, x );
+	}
+
+	public void setByte(int parameterIndex, byte x) throws SQLException {
+		getPreparedStatement().setByte( parameterIndex, x );
+	}
+
+	public void setShort(int parameterIndex, short x) throws SQLException {
+		getPreparedStatement().setShort( parameterIndex, x );
+	}
+
+	public void setInt(int parameterIndex, int x) throws SQLException {
+		getPreparedStatement().setInt( parameterIndex, x );
+	}
+
+	public void setLong(int parameterIndex, long x) throws SQLException {
+		getPreparedStatement().setLong( parameterIndex, x );
+	}
+
+	public void setFloat(int parameterIndex, float x) throws SQLException {
+		getPreparedStatement().setFloat( parameterIndex, x );
+	}
+
+	public void setDouble(int parameterIndex, double x) throws SQLException {
+		getPreparedStatement().setDouble( parameterIndex, x );
+	}
+
+	public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
+		getPreparedStatement().setBigDecimal( parameterIndex, x );
+	}
+
+	public void setString(int parameterIndex, String x) throws SQLException {
+		getPreparedStatement().setString( parameterIndex, x );
+	}
+
+	public void setBytes(int parameterIndex, byte[] x) throws SQLException {
+		getPreparedStatement().setBytes( parameterIndex, x );
+	}
+
+	public void setDate(int parameterIndex, Date x) throws SQLException {
+		getPreparedStatement().setDate( parameterIndex, x );
+	}
+
+	public void setTime(int parameterIndex, Time x) throws SQLException {
+		getPreparedStatement().setTime( parameterIndex, x );
+	}
+
+	public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
+		getPreparedStatement().setTimestamp( parameterIndex, x );
+	}
+
+	public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
+		getPreparedStatement().setAsciiStream( parameterIndex, x, length );
+	}
+
+	@Deprecated
+	public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
+		getPreparedStatement().setUnicodeStream( parameterIndex, x, length );
+	}
+
+	public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
+		getPreparedStatement().setBinaryStream( parameterIndex, x, length );
+	}
+
+	public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException {
+		getPreparedStatement().setObject( parameterIndex, x, targetSqlType, scale );
+	}
+
+	public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
+		getPreparedStatement().setObject( parameterIndex, x, targetSqlType );
+	}
+
+	public void setObject(int parameterIndex, Object x) throws SQLException {
+		getPreparedStatement().setObject( parameterIndex, x );
+	}
+
+	public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
+		getPreparedStatement().setCharacterStream( parameterIndex, reader, length );
+	}
+
+	public void setRef(int parameterIndex, Ref x) throws SQLException {
+		getPreparedStatement().setRef( parameterIndex, x );
+	}
+
+	public void setBlob(int parameterIndex, Blob x) throws SQLException {
+		getPreparedStatement().setBlob( parameterIndex, x );
+	}
+
+	public void setClob(int parameterIndex, Clob x) throws SQLException {
+		getPreparedStatement().setClob( parameterIndex, x );
+	}
+
+	public void setArray(int parameterIndex, Array x) throws SQLException {
+		getPreparedStatement().setArray( parameterIndex, x );
+	}
+
+	public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
+		getPreparedStatement().setDate( parameterIndex, x, cal );
+	}
+
+	public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
+		getPreparedStatement().setTime( parameterIndex, x, cal );
+	}
+
+	public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
+		getPreparedStatement().setTimestamp( parameterIndex, x, cal );
+	}
+
+	public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
+		getPreparedStatement().setNull( parameterIndex, sqlType, typeName );
+	}
+
+	public void setURL(int parameterIndex, URL x) throws SQLException {
+		getPreparedStatement().setURL( parameterIndex, x );
+	}
+
+
+	// Statement methods not really valid on PreparedStatements ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public boolean execute(String sql) throws SQLException {
+		throw new HibernateException( "This form of execute not allowed here" );
+	}
+
+	public ResultSet executeQuery(String sql) throws SQLException {
+		throw new HibernateException( "This form of execute not allowed here" );
+	}
+
+	public int executeUpdate(String sql) throws SQLException {
+		throw new HibernateException( "This form of execute not allowed here" );
+	}
+
+	public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+		throw new HibernateException( "This form of execute not allowed here" );
+	}
+
+	public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+		throw new HibernateException( "This form of execute not allowed here" );
+	}
+
+	public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+		throw new HibernateException( "This form of execute not allowed here" );
+	}
+
+	public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+		throw new HibernateException( "This form of execute not allowed here" );
+	}
+
+	public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+		throw new HibernateException( "This form of execute not allowed here" );
+	}
+
+	public boolean execute(String sql, String[] columnNames) throws SQLException {
+		throw new HibernateException( "This form of execute not allowed here" );
+	}
+
+	public void addBatch(String sql) throws SQLException {
+		throw new HibernateException( "This form of addBatch not allowed here" );
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,653 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.SQLWarning;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
+import java.sql.Ref;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Array;
+import java.math.BigDecimal;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Map;
+import java.util.Calendar;
+import java.net.URL;
+
+import org.hibernate.HibernateException;
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainer;
+
+/**
+ * ResultSetDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ResultSetDelegate implements ResultSet, ResultSetWrapperImplementor {
+	private boolean valid = true;
+	private AbstractStatementDelegate statementDelegate;
+	private ResultSet wrappedResultSet;
+
+	public ResultSetDelegate(AbstractStatementDelegate statementDelegate, ResultSet wrappedResultSet) {
+		this.statementDelegate = statementDelegate;
+		this.wrappedResultSet = wrappedResultSet;
+	}
+
+	/*package-protected*/ JDBCServices getJdbcServices() {
+		return statementDelegate.getJdbcServices();
+	}
+
+	/*package-protected*/ JDBCContainer getJdbcContainer() {
+		return statementDelegate.getJdbcContainer();
+	}
+
+	public ResultSet getWrappedResultSetWithoutChecks() {
+		return wrappedResultSet;
+	}
+
+	public ResultSet getWrappedResultSet() {
+		if ( !valid ) {
+			throw new HibernateException( "resultset handle is invalid" );
+		}
+		return wrappedResultSet;
+	}
+
+	public void invalidate() {
+		statementDelegate = null;
+		wrappedResultSet = null;
+		valid = false;
+	}
+
+
+	// special ResultSet methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public Statement getStatement() throws SQLException {
+		return statementDelegate;
+	}
+
+	public void close() throws SQLException {
+		if ( valid ) {
+			getJdbcContainer().release( this );
+		}
+	}
+
+
+	// Navigational ResultSet methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public boolean next() throws SQLException {
+		return getWrappedResultSet().next();
+	}
+
+	public boolean isBeforeFirst() throws SQLException {
+		return getWrappedResultSet().isBeforeFirst();
+	}
+
+	public boolean isAfterLast() throws SQLException {
+		return getWrappedResultSet().isAfterLast();
+	}
+
+	public boolean isFirst() throws SQLException {
+		return getWrappedResultSet().isFirst();
+	}
+
+	public boolean isLast() throws SQLException {
+		return getWrappedResultSet().isLast();
+	}
+
+	public void beforeFirst() throws SQLException {
+		getWrappedResultSet().beforeFirst();
+	}
+
+	public void afterLast() throws SQLException {
+		getWrappedResultSet().afterLast();
+	}
+
+	public boolean first() throws SQLException {
+		return getWrappedResultSet().first();
+	}
+
+	public boolean last() throws SQLException {
+		return getWrappedResultSet().last();
+	}
+
+	public int getRow() throws SQLException {
+		return getWrappedResultSet().getRow();
+	}
+
+	public boolean absolute(int row) throws SQLException {
+		return getWrappedResultSet().absolute( row );
+	}
+
+	public boolean relative(int rows) throws SQLException {
+		return getWrappedResultSet().relative( rows );
+	}
+
+	public boolean previous() throws SQLException {
+		return getWrappedResultSet().previous();
+	}
+
+
+	// informational ResultSet methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public String getCursorName() throws SQLException {
+		return getWrappedResultSet().getCursorName();
+	}
+
+	public ResultSetMetaData getMetaData() throws SQLException {
+		return getWrappedResultSet().getMetaData();
+	}
+
+	public void setFetchDirection(int direction) throws SQLException {
+		getWrappedResultSet().setFetchDirection( direction );
+	}
+
+	public int getFetchDirection() throws SQLException {
+		return getWrappedResultSet().getFetchDirection();
+	}
+
+	public void setFetchSize(int rows) throws SQLException {
+		getWrappedResultSet().setFetchSize( rows );
+	}
+
+	public int getFetchSize() throws SQLException {
+		return getWrappedResultSet().getFetchSize();
+	}
+
+	public int getType() throws SQLException {
+		return getWrappedResultSet().getType();
+	}
+
+	public int getConcurrency() throws SQLException {
+		return getWrappedResultSet().getConcurrency();
+	}
+
+	public SQLWarning getWarnings() throws SQLException {
+		return getWrappedResultSet().getWarnings();
+	}
+
+	public void clearWarnings() throws SQLException {
+		getWrappedResultSet().clearWarnings();
+	}
+
+
+	// value accessors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public boolean wasNull() throws SQLException {
+		return getWrappedResultSet().wasNull();
+	}
+
+	public String getString(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getString( columnIndex );
+	}
+
+	public boolean getBoolean(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getBoolean( columnIndex );
+	}
+
+	public byte getByte(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getByte( columnIndex );
+	}
+
+	public short getShort(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getShort( columnIndex );
+	}
+
+	public int getInt(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getInt( columnIndex );
+	}
+
+	public long getLong(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getLong( columnIndex );
+	}
+
+	public float getFloat(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getFloat( columnIndex );
+	}
+
+	public double getDouble(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getDouble( columnIndex );
+	}
+
+	public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+		return getWrappedResultSet().getBigDecimal( columnIndex, scale );
+	}
+
+	public byte[] getBytes(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getBytes( columnIndex );
+	}
+
+	public Date getDate(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getDate( columnIndex );
+	}
+
+	public Time getTime(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getTime( columnIndex );
+	}
+
+	public Timestamp getTimestamp(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getTimestamp( columnIndex );
+	}
+
+	public InputStream getAsciiStream(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getAsciiStream( columnIndex );
+	}
+
+	public InputStream getUnicodeStream(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getUnicodeStream( columnIndex );
+	}
+
+	public InputStream getBinaryStream(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getBinaryStream( columnIndex );
+	}
+
+	public String getString(String columnName) throws SQLException {
+		return getWrappedResultSet().getString( columnName );
+	}
+
+	public boolean getBoolean(String columnName) throws SQLException {
+		return getWrappedResultSet().getBoolean( columnName );
+	}
+
+	public byte getByte(String columnName) throws SQLException {
+		return getWrappedResultSet().getByte( columnName );
+	}
+
+	public short getShort(String columnName) throws SQLException {
+		return getWrappedResultSet().getShort( columnName );
+	}
+
+	public int getInt(String columnName) throws SQLException {
+		return getWrappedResultSet().getInt( columnName );
+	}
+
+	public long getLong(String columnName) throws SQLException {
+		return getWrappedResultSet().getLong( columnName );
+	}
+
+	public float getFloat(String columnName) throws SQLException {
+		return getWrappedResultSet().getFloat( columnName );
+	}
+
+	public double getDouble(String columnName) throws SQLException {
+		return getWrappedResultSet().getDouble( columnName );
+	}
+
+	public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
+		return getWrappedResultSet().getBigDecimal( columnName, scale );
+	}
+
+	public byte[] getBytes(String columnName) throws SQLException {
+		return getWrappedResultSet().getBytes( columnName );
+	}
+
+	public Date getDate(String columnName) throws SQLException {
+		return getWrappedResultSet().getDate( columnName );
+	}
+
+	public Time getTime(String columnName) throws SQLException {
+		return getWrappedResultSet().getTime( columnName );
+	}
+
+	public Timestamp getTimestamp(String columnName) throws SQLException {
+		return getWrappedResultSet().getTimestamp( columnName );
+	}
+
+	public InputStream getAsciiStream(String columnName) throws SQLException {
+		return getWrappedResultSet().getAsciiStream( columnName );
+	}
+
+	public InputStream getUnicodeStream(String columnName) throws SQLException {
+		return getWrappedResultSet().getUnicodeStream( columnName );
+	}
+
+	public InputStream getBinaryStream(String columnName) throws SQLException {
+		return getWrappedResultSet().getBinaryStream( columnName );
+	}
+
+	public Object getObject(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getObject( columnIndex );
+	}
+
+	public Object getObject(String columnName) throws SQLException {
+		return getWrappedResultSet().getObject( columnName );
+	}
+
+	public int findColumn(String columnName) throws SQLException {
+		return getWrappedResultSet().findColumn( columnName );
+	}
+
+	public Reader getCharacterStream(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getCharacterStream( columnIndex );
+	}
+
+	public Reader getCharacterStream(String columnName) throws SQLException {
+		return getWrappedResultSet().getCharacterStream( columnName );
+	}
+
+	public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getBigDecimal( columnIndex );
+	}
+
+	public BigDecimal getBigDecimal(String columnName) throws SQLException {
+		return getWrappedResultSet().getBigDecimal( columnName );
+	}
+
+	public Object getObject(int i, Map<String, Class<?>> map) throws SQLException {
+		return getWrappedResultSet().getObject( i, map );
+	}
+
+	public Ref getRef(int i) throws SQLException {
+		return getWrappedResultSet().getRef( i );
+	}
+
+	public Blob getBlob(int i) throws SQLException {
+		return getWrappedResultSet().getBlob( i );
+	}
+
+	public Clob getClob(int i) throws SQLException {
+		return getWrappedResultSet().getClob( i );
+	}
+
+	public Array getArray(int i) throws SQLException {
+		return getWrappedResultSet().getArray( i );
+	}
+
+	public Object getObject(String colName, Map<String, Class<?>> map) throws SQLException {
+		return getWrappedResultSet().getObject( colName, map );
+	}
+
+	public Ref getRef(String colName) throws SQLException {
+		return getWrappedResultSet().getRef( colName );
+	}
+
+	public Blob getBlob(String colName) throws SQLException {
+		return getWrappedResultSet().getBlob( colName );
+	}
+
+	public Clob getClob(String colName) throws SQLException {
+		return getWrappedResultSet().getClob( colName );
+	}
+
+	public Array getArray(String colName) throws SQLException {
+		return getWrappedResultSet().getArray( colName );
+	}
+
+	public Date getDate(int columnIndex, Calendar cal) throws SQLException {
+		return getWrappedResultSet().getDate( columnIndex, cal );
+	}
+
+	public Date getDate(String columnName, Calendar cal) throws SQLException {
+		return getWrappedResultSet().getDate( columnName, cal );
+	}
+
+	public Time getTime(int columnIndex, Calendar cal) throws SQLException {
+		return getWrappedResultSet().getTime( columnIndex, cal );
+	}
+
+	public Time getTime(String columnName, Calendar cal) throws SQLException {
+		return getWrappedResultSet().getTime( columnName, cal );
+	}
+
+	public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
+		return getWrappedResultSet().getTimestamp( columnIndex, cal );
+	}
+
+	public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException {
+		return getWrappedResultSet().getTimestamp( columnName, cal );
+	}
+
+	public URL getURL(int columnIndex) throws SQLException {
+		return getWrappedResultSet().getURL( columnIndex );
+	}
+
+	public URL getURL(String columnName) throws SQLException {
+		return getWrappedResultSet().getURL( columnName );
+	}
+
+
+	// ResultSet mutability ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public boolean rowUpdated() throws SQLException {
+		return getWrappedResultSet().rowUpdated();
+	}
+
+	public boolean rowInserted() throws SQLException {
+		return getWrappedResultSet().rowInserted();
+	}
+
+	public boolean rowDeleted() throws SQLException {
+		return getWrappedResultSet().rowDeleted();
+	}
+
+	public void updateNull(int columnIndex) throws SQLException {
+		getWrappedResultSet().updateNull( columnIndex );
+	}
+
+	public void updateBoolean(int columnIndex, boolean x) throws SQLException {
+		getWrappedResultSet().updateBoolean( columnIndex, x );
+	}
+
+	public void updateByte(int columnIndex, byte x) throws SQLException {
+		getWrappedResultSet().updateByte( columnIndex, x );
+	}
+
+	public void updateShort(int columnIndex, short x) throws SQLException {
+		getWrappedResultSet().updateShort( columnIndex, x );
+	}
+
+	public void updateInt(int columnIndex, int x) throws SQLException {
+		getWrappedResultSet().updateInt( columnIndex, x );
+	}
+
+	public void updateLong(int columnIndex, long x) throws SQLException {
+		getWrappedResultSet().updateLong( columnIndex, x );
+	}
+
+	public void updateFloat(int columnIndex, float x) throws SQLException {
+		getWrappedResultSet().updateFloat( columnIndex, x );
+	}
+
+	public void updateDouble(int columnIndex, double x) throws SQLException {
+		getWrappedResultSet().updateDouble( columnIndex, x );
+	}
+
+	public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
+		getWrappedResultSet().updateBigDecimal( columnIndex, x );
+	}
+
+	public void updateString(int columnIndex, String x) throws SQLException {
+		getWrappedResultSet().updateString( columnIndex, x );
+	}
+
+	public void updateBytes(int columnIndex, byte[] x) throws SQLException {
+		getWrappedResultSet().updateBytes( columnIndex, x );
+	}
+
+	public void updateDate(int columnIndex, Date x) throws SQLException {
+		getWrappedResultSet().updateDate( columnIndex, x );
+	}
+
+	public void updateTime(int columnIndex, Time x) throws SQLException {
+		getWrappedResultSet().updateTime( columnIndex, x );
+	}
+
+	public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
+		getWrappedResultSet().updateTimestamp( columnIndex, x );
+	}
+
+	public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
+		getWrappedResultSet().updateAsciiStream( columnIndex, x, length );
+	}
+
+	public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
+		getWrappedResultSet().updateBinaryStream( columnIndex, x, length );
+	}
+
+	public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
+		getWrappedResultSet().updateCharacterStream( columnIndex, x, length );
+	}
+
+	public void updateObject(int columnIndex, Object x, int scale) throws SQLException {
+		getWrappedResultSet().updateObject( columnIndex, x, scale );
+	}
+
+	public void updateObject(int columnIndex, Object x) throws SQLException {
+		getWrappedResultSet().updateObject( columnIndex, x );
+	}
+
+	public void updateNull(String columnName) throws SQLException {
+		getWrappedResultSet().updateNull( columnName );
+	}
+
+	public void updateBoolean(String columnName, boolean x) throws SQLException {
+		getWrappedResultSet().updateBoolean( columnName, x );
+	}
+
+	public void updateByte(String columnName, byte x) throws SQLException {
+		getWrappedResultSet().updateByte( columnName, x );
+	}
+
+	public void updateShort(String columnName, short x) throws SQLException {
+		getWrappedResultSet().updateShort( columnName, x );
+	}
+
+	public void updateInt(String columnName, int x) throws SQLException {
+		getWrappedResultSet().updateInt( columnName, x );
+	}
+
+	public void updateLong(String columnName, long x) throws SQLException {
+		getWrappedResultSet().updateLong( columnName, x );
+	}
+
+	public void updateFloat(String columnName, float x) throws SQLException {
+		getWrappedResultSet().updateFloat( columnName, x );
+	}
+
+	public void updateDouble(String columnName, double x) throws SQLException {
+		getWrappedResultSet().updateDouble( columnName, x );
+	}
+
+	public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException {
+		getWrappedResultSet().updateBigDecimal( columnName, x );
+	}
+
+	public void updateString(String columnName, String x) throws SQLException {
+		getWrappedResultSet().updateString( columnName, x );
+	}
+
+	public void updateBytes(String columnName, byte[] x) throws SQLException {
+		getWrappedResultSet().updateBytes( columnName, x );
+	}
+
+	public void updateDate(String columnName, Date x) throws SQLException {
+		getWrappedResultSet().updateDate( columnName, x );
+	}
+
+	public void updateTime(String columnName, Time x) throws SQLException {
+		getWrappedResultSet().updateTime( columnName, x );
+	}
+
+	public void updateTimestamp(String columnName, Timestamp x) throws SQLException {
+		getWrappedResultSet().updateTimestamp( columnName, x );
+	}
+
+	public void updateAsciiStream(String columnName, InputStream x, int length) throws SQLException {
+		getWrappedResultSet().updateAsciiStream( columnName, x, length );
+	}
+
+	public void updateBinaryStream(String columnName, InputStream x, int length) throws SQLException {
+		getWrappedResultSet().updateBinaryStream( columnName, x, length );
+	}
+
+	public void updateCharacterStream(String columnName, Reader reader, int length) throws SQLException {
+		getWrappedResultSet().updateCharacterStream( columnName, reader, length );
+	}
+
+	public void updateObject(String columnName, Object x, int scale) throws SQLException {
+		getWrappedResultSet().updateObject( columnName, x, scale );
+	}
+
+	public void updateObject(String columnName, Object x) throws SQLException {
+		getWrappedResultSet().updateObject( columnName, x );
+	}
+
+	public void insertRow() throws SQLException {
+		getWrappedResultSet().insertRow();
+	}
+
+	public void updateRow() throws SQLException {
+		getWrappedResultSet().updateRow();
+	}
+
+	public void deleteRow() throws SQLException {
+		getWrappedResultSet().deleteRow();
+	}
+
+	public void refreshRow() throws SQLException {
+		getWrappedResultSet().refreshRow();
+	}
+
+	public void cancelRowUpdates() throws SQLException {
+		getWrappedResultSet().cancelRowUpdates();
+	}
+
+	public void moveToInsertRow() throws SQLException {
+		getWrappedResultSet().moveToInsertRow();
+	}
+
+	public void moveToCurrentRow() throws SQLException {
+		getWrappedResultSet().moveToCurrentRow();
+	}
+
+	public void updateRef(int columnIndex, Ref x) throws SQLException {
+		getWrappedResultSet().updateRef( columnIndex, x );
+	}
+
+	public void updateRef(String columnName, Ref x) throws SQLException {
+		getWrappedResultSet().updateRef( columnName, x );
+	}
+
+	public void updateBlob(int columnIndex, Blob x) throws SQLException {
+		getWrappedResultSet().updateBlob( columnIndex, x );
+	}
+
+	public void updateBlob(String columnName, Blob x) throws SQLException {
+		getWrappedResultSet().updateBlob( columnName, x );
+	}
+
+	public void updateClob(int columnIndex, Clob x) throws SQLException {
+		getWrappedResultSet().updateClob( columnIndex, x );
+	}
+
+	public void updateClob(String columnName, Clob x) throws SQLException {
+		getWrappedResultSet().updateClob( columnName, x );
+	}
+
+	public void updateArray(int columnIndex, Array x) throws SQLException {
+		getWrappedResultSet().updateArray( columnIndex, x );
+	}
+
+	public void updateArray(String columnName, Array x) throws SQLException {
+		getWrappedResultSet().updateArray( columnName, x );
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetWrapperImplementor.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetWrapperImplementor.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetWrapperImplementor.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import org.hibernate.jdbc.ResultSetWrapper;
+
+/**
+ * Extra, internal contract for implementations of ResultSetWrapper for allowing
+ * invalidation of the wrapper.
+ *
+ * @author Steve Ebersole
+ */
+public interface ResultSetWrapperImplementor extends ResultSetWrapper {
+	/**
+	 * Make the wrapper invalid for further usage.
+	 */
+	public void invalidate();
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/StatementWrapperImplementor.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/StatementWrapperImplementor.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/StatementWrapperImplementor.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import org.hibernate.jdbc.StatementWrapper;
+
+/**
+ * Extra, internal contract for implementations of StatementWrapper for allowing
+ * invalidation of the wrapper.
+ *
+ * @author Steve Ebersole
+ */
+public interface StatementWrapperImplementor extends StatementWrapper {
+	/**
+	 * Make the wrapper invalid for further usage.
+	 */
+	public void invalidate();
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
+import org.hibernate.jdbc.util.ExceptionHelper;
+import org.hibernate.jdbc.JDBCContainer;
+
+/**
+ * BasicJDBCContainer implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicJDBCContainer implements JDBCContainer {
+	private static final Logger log = LoggerFactory.getLogger( BasicJDBCContainer.class );
+
+	private final ExceptionHelper exceptionHelper;
+	protected final HashMap xref = new HashMap();
+
+	public BasicJDBCContainer(ExceptionHelper exceptionHelper) {
+		this.exceptionHelper = exceptionHelper;
+	}
+
+	public void register(Statement statement) {
+		log.trace( "registering statement [" + statement + "]" );
+		if ( xref.containsKey( statement ) ) {
+			throw new HibernateException( "statement already registered with JDBCContainer" );
+		}
+		xref.put( statement, null );
+	}
+
+	public void release(Statement statement) {
+		log.trace( "releasing statement [" + statement + "]" );
+		Set resultSets = ( Set ) xref.get( statement );
+		if ( resultSets != null ) {
+			Iterator itr = resultSets.iterator();
+			while ( itr.hasNext() ) {
+				final ResultSet resultSet = ( ResultSet ) itr.next();
+				close( resultSet );
+			}
+			resultSets.clear();
+		}
+		xref.remove( statement );
+		close( statement );
+	}
+
+	public void register(ResultSet resultSet) {
+		log.trace( "registering result set [" + resultSet + "]" );
+		Statement statement;
+		try {
+			statement = resultSet.getStatement();
+		}
+		catch ( SQLException e ) {
+			throw exceptionHelper.convert( e, "unable to access statement from resultset" );
+		}
+		if ( log.isWarnEnabled() && !xref.containsKey( statement ) ) {
+			log.warn( "resultset's statement was not yet registered" );
+		}
+		Set resultSets = ( Set ) xref.get( statement );
+		if ( resultSets == null ) {
+			resultSets = new HashSet();
+			xref.put( statement, resultSets );
+		}
+		resultSets.add( resultSet );
+	}
+
+	public void release(ResultSet resultSet) {
+		log.trace( "releasing result set [" + resultSet + "]" );
+		Statement statement;
+		try {
+			statement = resultSet.getStatement();
+		}
+		catch ( SQLException e ) {
+			throw exceptionHelper.convert( e, "unable to access statement from resultset" );
+		}
+		if ( log.isWarnEnabled() && !xref.containsKey( statement ) ) {
+			log.warn( "resultset's statement was not registered" );
+		}
+		Set resultSets = ( Set ) xref.get( statement );
+		if ( resultSets != null ) {
+			resultSets.remove( resultSet );
+		}
+		close( resultSet );
+	}
+
+	public boolean hasRegisteredResources() {
+		return !xref.isEmpty();
+	}
+
+	public void close() {
+		log.trace( "closing JDBC container [" + this + "]" );
+		Iterator statementIterator = xref.keySet().iterator();
+		while ( statementIterator.hasNext() ) {
+			final Statement statement = ( Statement ) statementIterator.next();
+			final Set resultSets = ( Set ) xref.get( statement );
+			if ( resultSets != null ) {
+				Iterator resultSetIterator = resultSets.iterator();
+				while ( resultSetIterator.hasNext() ) {
+					final ResultSet resultSet = ( ResultSet ) resultSetIterator.next();
+					close( resultSet );
+				}
+				resultSets.clear();
+			}
+			close( statement );
+		}
+		xref.clear();
+	}
+
+	protected void close(Statement statement) {
+		log.trace( "closing prepared statement [" + statement + "]" );
+		try {
+			// if we are unable to "clan" the prepared statement,
+			// we do not close it
+			try {
+				if ( statement.getMaxRows() != 0 ) {
+					statement.setMaxRows( 0 );
+				}
+				if ( statement.getQueryTimeout() != 0 ) {
+					statement.setQueryTimeout( 0 );
+				}
+			}
+			catch( SQLException sqle ) {
+				// there was a problem "cleaning" the prepared statement
+				log.debug( "Exception clearing maxRows/queryTimeout [" + sqle.getMessage() + "]" );
+				return; // EARLY EXIT!!!
+			}
+			statement.close();
+		}
+		catch( SQLException sqle ) {
+			log.debug( "Unable to release statement [" + sqle.getMessage() + "]" );
+		}
+	}
+
+	protected void close(ResultSet resultSet) {
+		log.trace( "closing result set [" + resultSet + "]" );
+		try {
+			resultSet.close();
+		}
+		catch( SQLException e ) {
+			log.debug( "Unable to release result set [" + e.getMessage() + "]" );
+		}
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+/**
+ * Observer contract
+ *
+ * @author Steve Ebersole
+ */
+public interface ConnectionObserver {
+	public void physicalConnectionObtained();
+	public void physicalConnectionReleased();
+	public void logicalConnectionClosed();
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,215 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.HibernateException;
+import org.hibernate.JDBCException;
+import org.hibernate.jdbc.impl.ConnectionObserver;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.JDBCServices;
+
+/**
+ * LogicalConnectionImpl implementation
+ *
+ * @author Steve Ebersole
+ */
+public class LogicalConnectionImpl implements LogicalConnectionImplementor {
+	private static final Logger log = LoggerFactory.getLogger( LogicalConnectionImpl.class );
+
+	private transient Connection physicalConnection;
+	private final ConnectionReleaseMode connectionReleaseMode;
+	private final JDBCServices jdbcServices;
+	private final JDBCContainer jdbcContainer;
+	private final List observers = new ArrayList();
+
+	private final boolean isUserSuppliedConnection;
+	private boolean isClosed;
+
+	public LogicalConnectionImpl(
+	        Connection userSuppliedConnection,
+	        ConnectionReleaseMode connectionReleaseMode,
+	        JDBCServices jdbcServices) {
+		this.physicalConnection = userSuppliedConnection;
+		this.connectionReleaseMode = connectionReleaseMode;
+		this.jdbcServices = jdbcServices;
+		this.jdbcContainer = jdbcServices.getJdbcContainerBuilder().buildJdbcContainer();
+
+		this.isUserSuppliedConnection = ( userSuppliedConnection != null );
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public JDBCServices getJdbcServices() {
+		return jdbcServices;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public ConnectionReleaseMode getConnectionReleaseMode() {
+		return connectionReleaseMode;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public JDBCContainer getJdbcContainer() {
+		return jdbcContainer;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public void addObserver(ConnectionObserver observer) {
+		observers.add( observer );
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean isOpen() {
+		return !isClosed;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean isPhysicallyConnected() {
+		return physicalConnection != null;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public Connection getConnection() throws HibernateException {
+		if ( isClosed ) {
+			throw new HibernateException( "Logical connection is closed" );
+		}
+		if ( physicalConnection == null ) {
+			if ( isUserSuppliedConnection ) {
+				// should never happen
+				throw new HibernateException( "User-supplied connection was null" );
+			}
+			obtainConnection();
+		}
+		return physicalConnection;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public Connection close() {
+		log.trace( "closing logical connection" );
+		Connection c = physicalConnection;
+		if ( !isUserSuppliedConnection && physicalConnection != null ) {
+			releaseConnection();
+		}
+		// not matter what
+		physicalConnection = null;
+		isClosed = true;
+		jdbcContainer.close();
+		for ( Iterator itr = observers.iterator(); itr.hasNext(); ) {
+			( ( ConnectionObserver ) itr.next() ).logicalConnectionClosed();
+		}
+		log.trace( "logical connection closed" );
+		return c;
+	}
+
+//	/**
+//	 * Is the connection considered "auto-commit"?
+//	 *
+//	 * @return True if we either do not have a connection, or the connection
+//	 * really is in auto-commit mode.
+//	 *
+//	 * @throws SQLException Can be thrown by the Connection.isAutoCommit() check.
+//	 */
+//	public boolean isAutoCommit() throws SQLException {
+//		return physicalConnection == null || physicalConnection.getAutoCommit();
+//	}
+
+	/**
+	 * Force aggresive release of the underlying connection.
+	 */
+	public void aggressiveRelease() {
+		if ( isUserSuppliedConnection ) {
+			log.debug( "cannot aggresively release user-supplied connection; skipping" );
+		}
+		else if ( ! getJdbcServices().getConnectionProvider().supportsAggressiveRelease() ) {
+			log.debug( "connection provider reports to not support aggreswsive release; skipping" );
+		}
+		else {
+			log.debug( "aggressively releasing JDBC connection" );
+			if ( physicalConnection != null ) {
+				releaseConnection();
+			}
+		}
+	}
+
+
+	/**
+	 * Obtains a physical connection from the 
+	 * Pysically opens a JDBC Connection.
+	 *
+	 * @throws JDBCException Indicates problem opening a connection
+	 */
+	private void obtainConnection() throws JDBCException {
+		log.debug( "obtaining JDBC connection" );
+		try {
+			physicalConnection = getJdbcServices().getConnectionProvider().getConnection();
+			for ( Iterator itr = observers.iterator(); itr.hasNext(); ) {
+				( ( ConnectionObserver ) itr.next() ).physicalConnectionObtained();
+			}
+			log.debug( "obtained JDBC connection" );
+		}
+		catch (SQLException sqle) {
+			throw getJdbcServices().getExceptionHelper().convert( sqle, "Could not open connection" );
+		}
+	}
+
+	/**
+	 * Releases the physical JDBC connection back to the provider.
+	 *
+	 * @throws JDBCException Indicates problem releasing the connection
+	 */
+	private void releaseConnection() throws JDBCException {
+		log.debug( "releasing JDBC connection" );
+		try {
+			if ( !physicalConnection.isClosed() ) {
+				getJdbcServices().getExceptionHelper().logAndClearWarnings( physicalConnection );
+			}
+			getJdbcServices().getConnectionProvider().closeConnection( physicalConnection );
+			physicalConnection = null;
+			for ( Iterator itr = observers.iterator(); itr.hasNext(); ) {
+				( ( ConnectionObserver ) itr.next() ).physicalConnectionReleased();
+			}
+			log.debug( "released JDBC connection" );
+		}
+		catch (SQLException sqle) {
+			throw getJdbcServices().getExceptionHelper().convert( sqle, "Could not close connection" );
+		}
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.impl.ConnectionObserver;
+import org.hibernate.jdbc.LogicalConnection;
+
+/**
+ * LogicalConnectionImplementor implementation
+ *
+ * @author Steve Ebersole
+ */
+public interface LogicalConnectionImplementor extends LogicalConnection {
+	public JDBCServices getJdbcServices();
+
+	public ConnectionReleaseMode getConnectionReleaseMode();
+
+	public JDBCContainer getJdbcContainer();
+
+	public void addObserver(ConnectionObserver observer);
+
+	public void aggressiveRelease();
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/ExceptionHelper.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/ExceptionHelper.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/ExceptionHelper.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.util;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.JDBCException;
+import org.hibernate.exception.SQLExceptionConverter;
+import org.hibernate.util.StringHelper;
+
+/**
+ * ExceptionHelper implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ExceptionHelper {
+	public static final String DEFAULT_EXCEPTION_MSG = "SQL Exception";
+	public static final String DEFAULT_WARNING_MSG = "SQL Warning";
+
+	private static final Logger log = LoggerFactory.getLogger( ExceptionHelper.class );
+
+	private SQLExceptionConverter sqlExceptionConverter;
+
+	public ExceptionHelper(SQLExceptionConverter sqlExceptionConverter) {
+		this.sqlExceptionConverter = sqlExceptionConverter;
+	}
+
+	public SQLExceptionConverter getSqlExceptionConverter() {
+		return sqlExceptionConverter;
+	}
+
+	public void setSqlExceptionConverter(SQLExceptionConverter sqlExceptionConverter) {
+		this.sqlExceptionConverter = sqlExceptionConverter;
+	}
+
+	public JDBCException convert(SQLException sqle, String message) {
+		return convert( sqle, message, "n/a" );
+	}
+
+	public JDBCException convert(SQLException sqle, String message, String sql) {
+		logExceptions( sqle, message + " [" + sql + "]" );
+		return sqlExceptionConverter.convert( sqle, message, sql );
+	}
+
+	public void logAndClearWarnings(Connection connection) {
+		if ( log.isWarnEnabled() ) {
+			try {
+				logWarnings( connection.getWarnings() );
+			}
+			catch ( SQLException sqle ) {
+				//workaround for WebLogic
+				log.debug( "could not log warnings", sqle );
+			}
+		}
+		try {
+			//Sybase fail if we don't do that, sigh...
+			connection.clearWarnings();
+		}
+		catch ( SQLException sqle ) {
+			log.debug( "could not clear warnings", sqle );
+		}
+
+	}
+
+	public void logWarnings(SQLWarning warning) {
+		logWarnings( warning, null );
+	}
+
+	public void logWarnings(SQLWarning warning, String message) {
+		if ( log.isWarnEnabled() ) {
+			if ( log.isDebugEnabled() && warning != null ) {
+				message = StringHelper.isNotEmpty( message ) ? message : DEFAULT_WARNING_MSG;
+				log.debug( message, warning );
+			}
+			while ( warning != null ) {
+				StringBuffer buf = new StringBuffer( 30 )
+						.append( "SQL Warning: " )
+						.append( warning.getErrorCode() )
+						.append( ", SQLState: " )
+						.append( warning.getSQLState() );
+				log.warn( buf.toString() );
+				log.warn( warning.getMessage() );
+				warning = warning.getNextWarning();
+			}
+		}
+	}
+
+	public void logExceptions(SQLException ex) {
+		logExceptions( ex, null );
+	}
+
+	public void logExceptions(SQLException ex, String message) {
+		if ( log.isErrorEnabled() ) {
+			if ( log.isDebugEnabled() ) {
+				message = StringHelper.isNotEmpty( message ) ? message : DEFAULT_EXCEPTION_MSG;
+				log.debug( message, ex );
+			}
+			while ( ex != null ) {
+				StringBuffer buf = new StringBuffer( 30 )
+						.append( "SQL Error: " )
+						.append( ex.getErrorCode() )
+						.append( ", SQLState: " )
+						.append( ex.getSQLState() );
+				log.warn( buf.toString() );
+				log.error( ex.getMessage() );
+				ex = ex.getNextException();
+			}
+		}
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/SQLStatementLogger.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/SQLStatementLogger.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/SQLStatementLogger.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Centralize logging for SQL statements.
+ *
+ * @author Steve Ebersole
+ */
+public class SQLStatementLogger {
+	private static final Logger log = LoggerFactory.getLogger( SQLStatementLogger.class );
+
+	private boolean logToStdout;
+
+	/**
+	 * Constructs a new SQLStatementLogger instance.
+	 */
+	public SQLStatementLogger() {
+		this( false );
+	}
+
+	/**
+	 * Constructs a new SQLStatementLogger instance.
+	 *
+	 * @param logToStdout Should we log to STDOUT in addition to our internal logger.
+	 */
+	public SQLStatementLogger(boolean logToStdout) {
+		this.logToStdout = logToStdout;
+	}
+
+	/**
+	 * Setter for property 'logToStdout'.
+	 *
+	 * @param logToStdout Value to set for property 'logToStdout'.
+	 */
+	public void setLogToStdout(boolean logToStdout) {
+		this.logToStdout = logToStdout;
+	}
+
+	/**
+	 * Log a SQL statement string.
+	 *
+	 * @param statement The SQL statement.
+	 */
+	public void logStatement(String statement) {
+		log.debug( statement );
+		if ( logToStdout ) {
+			System.out.println( "Hibernate: " + statement );
+		}
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.util.Properties;
+
+import org.hibernate.cfg.Environment;
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.connection.DriverManagerConnectionProvider;
+
+/**
+ * ConnectionProviderBuilder implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ConnectionProviderBuilder {
+	public static ConnectionProvider buildConnectionProvider() {
+		Properties props = new Properties( null );
+		props.put( Environment.DRIVER, "org.hsqldb.jdbcDriver" );
+		props.put( Environment.URL, "jdbc:hsqldb:mem:target/test/db/hsqldb/hibernate" );
+		props.put( Environment.USER, "sa" );
+		DriverManagerConnectionProvider connectionProvider = new DriverManagerConnectionProvider();
+		connectionProvider.configure( props );
+		return connectionProvider;
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.JDBCException;
+import org.hibernate.jdbc.impl.LogicalConnectionImpl;
+
+/**
+ * BasicDelegationTests implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicDelegationTests {
+
+	private TestingServiceImpl services = new TestingServiceImpl();
+
+	@BeforeClass
+	protected void create() {
+		services.prepare();
+	}
+
+	@AfterClass
+	protected void destroy() {
+		services.release();
+	}
+
+	@Test
+	public void testBasicJdbcUsage() throws JDBCException {
+		LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+		ConnectionDelegate connection = new ConnectionDelegate( logicalConnection );
+
+		try {
+			try {
+				connection.prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery();
+			}
+			catch ( JDBCException ok ) {
+				// expected outcome
+			}
+
+			Statement stmnt = connection.createStatement();
+			stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+			stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
+			assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+			logicalConnection.getJdbcContainer().close();
+			assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+
+			PreparedStatement ps = connection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+			ps.setLong( 1, 1 );
+			ps.setString( 2, "name" );
+			ps.execute();
+
+			ps = connection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
+			ps.executeQuery();
+
+			assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+		}
+		catch ( SQLException sqle ) {
+			fail( "incorrect exception type : sqlexception" );
+		}
+		finally {
+			logicalConnection.close();
+		}
+
+		assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.SQLException;
+
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainerBuilder;
+import org.hibernate.jdbc.ConnectionProviderBuilder;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.util.SQLStatementLogger;
+import org.hibernate.jdbc.util.ExceptionHelper;
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.exception.SQLStateConverter;
+import org.hibernate.exception.ViolatedConstraintNameExtracter;
+
+/**
+ * TestingServiceImpl implementation
+ *
+ * @author Steve Ebersole
+ */
+public class TestingServiceImpl implements JDBCServices {
+	private ConnectionProvider connectionProvider;
+	private SQLStatementLogger sqlStatementLogger;
+	private JDBCContainerBuilder jdbcContainerBuilder;
+	private ExceptionHelper exceptionHelper;
+
+	public void prepare() {
+		connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
+		sqlStatementLogger = new SQLStatementLogger( true );
+		exceptionHelper = new ExceptionHelper(
+				new SQLStateConverter(
+						new ViolatedConstraintNameExtracter() {
+							public String extractConstraintName(SQLException e) {
+								return null;
+							}
+						}
+				)
+		);
+		jdbcContainerBuilder = new JDBCContainerBuilder() {
+			public JDBCContainer buildJdbcContainer() {
+				return new DelegateJDBCContainer( exceptionHelper );
+			}
+		};
+	}
+
+	public void release() {
+		connectionProvider.close();
+	}
+
+	public ConnectionProvider getConnectionProvider() {
+		return connectionProvider;
+	}
+
+	public JDBCContainerBuilder getJdbcContainerBuilder() {
+		return jdbcContainerBuilder;
+	}
+
+	public SQLStatementLogger getSqlStatementLogger() {
+		return sqlStatementLogger;
+	}
+
+	public ExceptionHelper getExceptionHelper() {
+		return exceptionHelper;
+	}
+}
\ No newline at end of file

Added: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/BasicConnectionTests.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/BasicConnectionTests.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/BasicConnectionTests.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ConnectionReleaseMode;
+
+/**
+ * BasicConnectionTests implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicConnectionTests {
+	private static final Logger log = LoggerFactory.getLogger( BasicConnectionTests.class );
+
+	private TestingServiceImpl services = new TestingServiceImpl();
+
+	@BeforeClass
+	protected void create() {
+		services.prepare();
+	}
+
+	@AfterClass
+	protected void destroy() {
+		services.release();
+	}
+
+	@Test
+	public void testBasicJdbcUsage() throws SQLException {
+		LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+		try {
+			try {
+				logicalConnection.getConnection().prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery();
+			}
+			catch ( SQLException e ) {
+				// expected outcome
+			}
+
+			Statement stmnt = logicalConnection.getConnection().createStatement();
+			logicalConnection.getJdbcContainer().register( stmnt );
+			stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+			stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
+			assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+			logicalConnection.getJdbcContainer().close();
+			assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+
+
+			PreparedStatement ps = logicalConnection.getConnection().prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+			logicalConnection.getJdbcContainer().register( ps );
+			ps.setLong( 1, 1 );
+			ps.setString( 2, "name" );
+			ps.executeUpdate();
+
+			ps = logicalConnection.getConnection().prepareStatement( "select * from SANDBOX_JDBC_TST" );
+			logicalConnection.getJdbcContainer().register( ps );
+			ResultSet rs = ps.executeQuery();
+			logicalConnection.getJdbcContainer().register( rs );
+
+			assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+		}
+		finally {
+			logicalConnection.close();
+		}
+
+		assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+import java.sql.SQLException;
+
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainerBuilder;
+import org.hibernate.jdbc.ConnectionProviderBuilder;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.util.SQLStatementLogger;
+import org.hibernate.jdbc.util.ExceptionHelper;
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.exception.SQLStateConverter;
+import org.hibernate.exception.ViolatedConstraintNameExtracter;
+
+/**
+ * TestingServiceImpl implementation
+ *
+ * @author Steve Ebersole
+ */
+public class TestingServiceImpl implements JDBCServices {
+	private ConnectionProvider connectionProvider;
+	private SQLStatementLogger sqlStatementLogger;
+	private JDBCContainerBuilder jdbcContainerBuilder;
+	private ExceptionHelper exceptionHelper;
+
+	public void prepare() {
+		connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
+		sqlStatementLogger = new SQLStatementLogger( true );
+		exceptionHelper = new ExceptionHelper(
+				new SQLStateConverter(
+						new ViolatedConstraintNameExtracter() {
+							public String extractConstraintName(SQLException e) {
+								return null;
+							}
+						}
+				)
+		);
+		jdbcContainerBuilder = new JDBCContainerBuilder() {
+			public JDBCContainer buildJdbcContainer() {
+				return new BasicJDBCContainer( exceptionHelper );
+			}
+		};
+	}
+
+	public void release() {
+		connectionProvider.close();
+	}
+
+	public ConnectionProvider getConnectionProvider() {
+		return connectionProvider;
+	}
+
+	public JDBCContainerBuilder getJdbcContainerBuilder() {
+		return jdbcContainerBuilder;
+	}
+
+	public SQLStatementLogger getSqlStatementLogger() {
+		return sqlStatementLogger;
+	}
+
+	public ExceptionHelper getExceptionHelper() {
+		return exceptionHelper;
+	}
+}

Added: sandbox/trunk/jdbc-impl/src/test/resources/log4j.properties
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/resources/log4j.properties	                        (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/resources/log4j.properties	2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,23 @@
+################################################################################
+# Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.            #
+#                                                                              #
+# This copyrighted material is made available to anyone wishing to use, modify,#
+# copy, or redistribute it subject to the terms and conditions of the GNU      #
+# Lesser General Public License, v. 2.1. This program is distributed in the    #
+# hope that it will be useful, but WITHOUT A WARRANTY; without even the implied#
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# Lesser General Public License for more details. You should have received a   #
+# copy of the GNU Lesser General Public License, v.2.1 along with this         #
+# distribution; if not, write to the Free Software Foundation, Inc.,           #
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.                 #
+#                                                                              #
+# Red Hat Author(s): Steve Ebersole                                            #
+################################################################################
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+
+log4j.rootLogger=info, stdout
+
+log4j.logger.org.hibernate=trace
\ No newline at end of file




More information about the hibernate-commits mailing list