[hibernate-commits] Hibernate SVN: r13948 - in sandbox/trunk/jdbc-proxy/src: main/java/org/hibernate/jdbc/impl and 6 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Aug 22 11:36:17 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-08-22 11:36:17 -0400 (Wed, 22 Aug 2007)
New Revision: 13948

Added:
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainerBuilder.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractProxyHandler.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractResultSetProxyHandler.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/DatabaseMetaDataProxyHandler.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitResultSetProxyHandler.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitStatementProxyHandler.java
Removed:
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyJDBCContainer.java
Modified:
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractStatementProxyHandler.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ConnectionProxyHandler.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyBuilder.java
   sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetProxyHandler.java
   sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/TestingServiceImpl.java
   sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java
   sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java
   sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/BasicConnectionProxyTest.java
   sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/TestingServiceImpl.java
   sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java
   sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/TestingServiceImpl.java
Log:
refactoring

Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -52,6 +52,10 @@
 		getJdbcContainer().register( this );
 	}
 
+	protected String getSql() {
+		return null;
+	}
+
 	protected void errorIfInvalid() {
 		if ( !valid ) {
 			throw new HibernateException( "statement handle is invalid" );
@@ -99,7 +103,7 @@
 		return connectionDelegate;
 	}
 
-	public void close() throws SQLException {
+	public void close() {
 		if ( valid ) {
 			LogicalConnectionImplementor lc = connectionDelegate.getLogicalConnection();
 			getJdbcContainer().release( this );
@@ -109,24 +113,39 @@
 
 	// execution-related methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-	public ResultSet getGeneratedKeys() throws SQLException {
-		return new ResultSetDelegate( this, getWrappedStatement().getGeneratedKeys() );
+	public ResultSet getGeneratedKeys() {
+		try {
+			return new ResultSetDelegate( this, getWrappedStatement().getGeneratedKeys() );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get generated keys", getSql() );
+		}
 	}
 
-	public ResultSet getResultSet() throws SQLException {
-		currentResultSetDelegate = new ResultSetDelegate( this, getWrappedStatement().getResultSet() );
-		return currentResultSetDelegate;
+	public ResultSet getResultSet() {
+		try {
+			currentResultSetDelegate = new ResultSetDelegate( this, getWrappedStatement().getResultSet() );
+			return currentResultSetDelegate;
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get result set", getSql() );
+		}
 	}
 
-	public int getUpdateCount() throws SQLException {
-		return getWrappedStatement().getUpdateCount();
+	public int getUpdateCount() {
+		try {
+			return getWrappedStatement().getUpdateCount();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get update count", getSql() );
+		}
 	}
 
-	public boolean getMoreResults() throws SQLException {
+	public boolean getMoreResults() {
 		return getMoreResults( Statement.CLOSE_CURRENT_RESULT );
 	}
 
-	public boolean getMoreResults(int current) throws SQLException {
+	public boolean getMoreResults(int current) {
 		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;
@@ -135,89 +154,195 @@
 			getJdbcContainer().release( currentResultSetDelegate );
 		}
 		currentResultSetDelegate = null;
-		return getWrappedStatement().getMoreResults( current );
+
+		try {
+			return getWrappedStatement().getMoreResults( current );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to getMoreResults", getSql() );
+		}
 	}
 
-	public void cancel() throws SQLException {
-		getWrappedStatement().cancel();
+	public void cancel() {
+		try {
+			getWrappedStatement().cancel();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to cancel", getSql() );
+		}
 	}
 
-	public void clearBatch() throws SQLException {
-		getWrappedStatement().clearBatch();
+	public void clearBatch() {
+		try {
+			getWrappedStatement().clearBatch();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to clear batch", getSql() );
+		}
 	}
 
-	public int[] executeBatch() throws SQLException {
-		return getWrappedStatement().executeBatch();
+	public int[] executeBatch() {
+		try {
+			return getWrappedStatement().executeBatch();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute batch", getSql() );
+		}
 	}
 
 
 	// general Statement methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-	public int getMaxFieldSize() throws SQLException {
-		return getWrappedStatement().getMaxFieldSize();
+	public int getMaxFieldSize() {
+		try {
+			return getWrappedStatement().getMaxFieldSize();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get max field size", getSql() );
+		}
 	}
 
-	public void setMaxFieldSize(int max) throws SQLException {
-		getWrappedStatement().setMaxFieldSize( max );
+	public void setMaxFieldSize(int max) {
+		try {
+			getWrappedStatement().setMaxFieldSize( max );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set max field size", getSql() );
+		}
 	}
 
-	public int getMaxRows() throws SQLException {
-		return getWrappedStatement().getMaxRows();
+	public int getMaxRows() {
+		try {
+			return getWrappedStatement().getMaxRows();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get max rows", getSql() );
+		}
 	}
 
-	public void setMaxRows(int max) throws SQLException {
-		getWrappedStatement().setMaxRows( max );
+	public void setMaxRows(int max) {
+		try {
+			getWrappedStatement().setMaxRows( max );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set max rows", getSql() );
+		}
 	}
 
-	public void setEscapeProcessing(boolean enable) throws SQLException {
-		getWrappedStatement().setEscapeProcessing( enable );
+	public void setEscapeProcessing(boolean enable) {
+		try {
+			getWrappedStatement().setEscapeProcessing( enable );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set escape processing", getSql() );
+		}
 	}
 
-	public int getQueryTimeout() throws SQLException {
-		return getWrappedStatement().getQueryTimeout();
+	public int getQueryTimeout() {
+		try {
+			return getWrappedStatement().getQueryTimeout();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get query timeout", getSql() );
+		}
 	}
 
-	public void setQueryTimeout(int seconds) throws SQLException {
-		getWrappedStatement().setQueryTimeout( seconds );
+	public void setQueryTimeout(int seconds) {
+		try {
+			getWrappedStatement().setQueryTimeout( seconds );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set query timeout", getSql() );
+		}
 	}
 
-	public void setCursorName(String name) throws SQLException {
-		getWrappedStatement().setCursorName( name );
+	public void setCursorName(String name) {
+		try {
+			getWrappedStatement().setCursorName( name );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set cursor name", getSql() );
+		}
 	}
 
-	public void setFetchDirection(int direction) throws SQLException {
-		getWrappedStatement().setFetchDirection( direction );
+	public int getFetchDirection() {
+		try {
+			return getWrappedStatement().getFetchDirection();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get fetch direction", getSql() );
+		}
 	}
 
-	public int getFetchDirection() throws SQLException {
-		return getWrappedStatement().getFetchDirection();
+	public void setFetchDirection(int direction) {
+		try {
+			getWrappedStatement().setFetchDirection( direction );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set fetch direction", getSql() );
+		}
 	}
 
-	public void setFetchSize(int rows) throws SQLException {
-		getWrappedStatement().setFetchSize( rows );
+	public int getFetchSize() {
+		try {
+			return getWrappedStatement().getFetchSize();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get fetch size", getSql() );
+		}
 	}
 
-	public int getFetchSize() throws SQLException {
-		return getWrappedStatement().getFetchSize();
+	public void setFetchSize(int rows) {
+		try {
+			getWrappedStatement().setFetchSize( rows );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set fetch size", getSql() );
+		}
 	}
 
-	public int getResultSetConcurrency() throws SQLException {
-		return getWrappedStatement().getResultSetConcurrency();
+	public int getResultSetConcurrency() {
+		try {
+			return getWrappedStatement().getResultSetConcurrency();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get result set concurrency", getSql() );
+		}
 	}
 
-	public int getResultSetType() throws SQLException {
-		return getWrappedStatement().getResultSetType();
+	public int getResultSetType() {
+		try {
+			return getWrappedStatement().getResultSetType();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get result set type", getSql() );
+		}
 	}
 
-	public int getResultSetHoldability() throws SQLException {
-		return getWrappedStatement().getResultSetHoldability();
+	public int getResultSetHoldability() {
+		try {
+			return getWrappedStatement().getResultSetHoldability();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get result set holdability", getSql() );
+		}
 	}
 
-	public SQLWarning getWarnings() throws SQLException {
-		return getWrappedStatement().getWarnings();
+	public SQLWarning getWarnings() {
+		try {
+			return getWrappedStatement().getWarnings();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get warnings", getSql() );
+		}
 	}
 
-	public void clearWarnings() throws SQLException {
-		getWrappedStatement().clearWarnings();
+	public void clearWarnings() {
+		try {
+			getWrappedStatement().clearWarnings();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to clear warnings", getSql() );
+		}
 	}
 }

Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -29,53 +29,103 @@
 		super( connectionDelegate, statement );
 	}
 
-	public void addBatch(String sql) throws SQLException {
+	public void addBatch(String sql) {
 		getJdbcServices().getSqlStatementLogger().logStatement( sql );
-		getWrappedStatement().addBatch( sql );
+		try {
+			getWrappedStatement().addBatch( sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to add batch", sql );
+		}
 	}
 
-	public boolean execute(String sql) throws SQLException {
+	public boolean execute(String sql) {
 		getJdbcServices().getSqlStatementLogger().logStatement( sql );
-		return getWrappedStatement().execute( sql );
+		try {
+			return getWrappedStatement().execute( sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute", sql );
+		}
 	}
 
-	public ResultSet executeQuery(String sql) throws SQLException {
+	public ResultSet executeQuery(String sql) {
 		getJdbcServices().getSqlStatementLogger().logStatement( sql );
-		return new ResultSetDelegate( this, getWrappedStatement().executeQuery( sql ) );
+		try {
+			return new ResultSetDelegate( this, getWrappedStatement().executeQuery( sql ) );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute query", sql );
+		}
 	}
 
-	public int executeUpdate(String sql) throws SQLException {
+	public int executeUpdate(String sql) {
 		getJdbcServices().getSqlStatementLogger().logStatement( sql );
-		return getWrappedStatement().executeUpdate( sql );
+		try {
+			return getWrappedStatement().executeUpdate( sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute update", sql );
+		}
 	}
 
-	public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+	public int executeUpdate(String sql, int autoGeneratedKeys) {
 		getJdbcServices().getSqlStatementLogger().logStatement( sql );
-		return getWrappedStatement().executeUpdate( sql, autoGeneratedKeys );
+		try {
+			return getWrappedStatement().executeUpdate( sql, autoGeneratedKeys );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute update", sql );
+		}
 	}
 
-	public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+	public int executeUpdate(String sql, int[] columnIndexes) {
 		getJdbcServices().getSqlStatementLogger().logStatement( sql );
-		return getWrappedStatement().executeUpdate( sql, columnIndexes );
+		try {
+			return getWrappedStatement().executeUpdate( sql, columnIndexes );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute update", sql );
+		}
 	}
 
-	public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+	public int executeUpdate(String sql, String[] columnNames) {
 		getJdbcServices().getSqlStatementLogger().logStatement( sql );
-		return getWrappedStatement().executeUpdate( sql, columnNames );
+		try {
+			return getWrappedStatement().executeUpdate( sql, columnNames );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute update", sql );
+		}
 	}
 
-	public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+	public boolean execute(String sql, int autoGeneratedKeys) {
 		getJdbcServices().getSqlStatementLogger().logStatement( sql );
-		return getWrappedStatement().execute( sql, autoGeneratedKeys );
+		try {
+			return getWrappedStatement().execute( sql, autoGeneratedKeys );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute", sql );
+		}
 	}
 
-	public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+	public boolean execute(String sql, int[] columnIndexes) {
 		getJdbcServices().getSqlStatementLogger().logStatement( sql );
-		return getWrappedStatement().execute( sql, columnIndexes );
+		try {
+			return getWrappedStatement().execute( sql, columnIndexes );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute", sql );
+		}
 	}
 
-	public boolean execute(String sql, String[] columnNames) throws SQLException {
+	public boolean execute(String sql, String[] columnNames) {
 		getJdbcServices().getSqlStatementLogger().logStatement( sql );
-		return getWrappedStatement().execute( sql, columnNames );
+		try {
+			return getWrappedStatement().execute( sql, columnNames );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute", sql );
+		}
 	}
 }

Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -293,91 +293,202 @@
 		return !valid;
 	}
 
-	public void setAutoCommit(boolean autoCommit) throws SQLException {
-		getWrappedConnection().setAutoCommit( autoCommit );
+	public void setAutoCommit(boolean autoCommit) {
+		try {
+			getWrappedConnection().setAutoCommit( autoCommit );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set auto-commit" );
+		}
 	}
 
-	public boolean getAutoCommit() throws SQLException {
-		return getWrappedConnection().getAutoCommit();
+	public boolean getAutoCommit() {
+		try {
+			return getWrappedConnection().getAutoCommit();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get auto-commit" );
+		}
 	}
 
-	public void commit() throws SQLException {
-		getWrappedConnection().commit();
+	public void commit() {
+		try {
+			getWrappedConnection().commit();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to commit" );
+		}
 	}
 
-	public void rollback() throws SQLException {
-		getWrappedConnection().rollback();
+	public void rollback() {
+		try {
+			getWrappedConnection().rollback();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to rollback" );
+		}
 	}
 
-	public DatabaseMetaData getMetaData() throws SQLException {
-		return getWrappedConnection().getMetaData();
+	public DatabaseMetaData getMetaData() {
+		// todo : wrap...
+		try {
+			return getWrappedConnection().getMetaData();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get metadata" );
+		}
 	}
 
-	public String nativeSQL(String sql) throws SQLException {
-		return getWrappedConnection().nativeSQL( sql );
+	public String nativeSQL(String sql) {
+		try {
+			return getWrappedConnection().nativeSQL( sql );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to native-ize sql" );
+		}
 	}
 
-	public void setReadOnly(boolean readOnly) throws SQLException {
-		getWrappedConnection().setReadOnly( readOnly );
+	public void setReadOnly(boolean readOnly) {
+		try {
+			getWrappedConnection().setReadOnly( readOnly );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set readonly-ness" );
+		}
 	}
 
-	public boolean isReadOnly() throws SQLException {
-		return getWrappedConnection().isReadOnly();
+	public boolean isReadOnly()  {
+		try {
+			return getWrappedConnection().isReadOnly();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to query readonly-ness" );
+		}
 	}
 
-	public void setCatalog(String catalog) throws SQLException {
-		getWrappedConnection().setCatalog( catalog );
+	public void setCatalog(String catalog) {
+		try {
+			getWrappedConnection().setCatalog( catalog );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set catalog" );
+		}
 	}
 
-	public String getCatalog() throws SQLException {
-		return getWrappedConnection().getCatalog();
+	public String getCatalog() {
+		try {
+			return getWrappedConnection().getCatalog();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set auto-commit" );
+		}
 	}
 
-	public void setTransactionIsolation(int level) throws SQLException {
-		getWrappedConnection().setTransactionIsolation( level );
+	public void setTransactionIsolation(int level) {
+		try {
+			getWrappedConnection().setTransactionIsolation( level );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set isolation" );
+		}
 	}
 
-	public int getTransactionIsolation() throws SQLException {
-		return getWrappedConnection().getTransactionIsolation();
+	public int getTransactionIsolation() {
+		try {
+			return getWrappedConnection().getTransactionIsolation();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get isolation" );
+		}
 	}
 
-	public SQLWarning getWarnings() throws SQLException {
-		return getWrappedConnection().getWarnings();
+	public SQLWarning getWarnings() {
+		try {
+			return getWrappedConnection().getWarnings();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get wranings" );
+		}
 	}
 
-	public void clearWarnings() throws SQLException {
-		getWrappedConnection().clearWarnings();
+	public void clearWarnings() {
+		try {
+			getWrappedConnection().clearWarnings();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to clear warnings" );
+		}
 	}
 
-	public Map<String, Class<?>> getTypeMap() throws SQLException {
-		return getWrappedConnection().getTypeMap();
+	public Map<String, Class<?>> getTypeMap() {
+		try {
+			return getWrappedConnection().getTypeMap();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get type-map" );
+		}
 	}
 
-	public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
-		getWrappedConnection().setTypeMap( map );
+	public void setTypeMap(Map<String, Class<?>> map) {
+		try {
+			getWrappedConnection().setTypeMap( map );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set type-map" );
+		}
 	}
 
-	public void setHoldability(int holdability) throws SQLException {
-		getWrappedConnection().setHoldability( holdability );
+	public void setHoldability(int holdability) {
+		try {
+			getWrappedConnection().setHoldability( holdability );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set holdability" );
+		}
 	}
 
-	public int getHoldability() throws SQLException {
-		return getWrappedConnection().getHoldability();
+	public int getHoldability() {
+		try {
+			return getWrappedConnection().getHoldability();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get holdability" );
+		}
 	}
 
-	public Savepoint setSavepoint() throws SQLException {
-		return getWrappedConnection().setSavepoint();
+	public Savepoint setSavepoint() {
+		try {
+			return getWrappedConnection().setSavepoint();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set savepoint" );
+		}
 	}
 
-	public Savepoint setSavepoint(String name) throws SQLException {
-		return getWrappedConnection().setSavepoint( name );
+	public Savepoint setSavepoint(String name) {
+		try {
+			return getWrappedConnection().setSavepoint( name );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to set savepoint" );
+		}
 	}
 
-	public void rollback(Savepoint savepoint) throws SQLException {
-		getWrappedConnection().rollback( savepoint );
+	public void rollback(Savepoint savepoint) {
+		try {
+			getWrappedConnection().rollback( savepoint );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to rollback savepoint" );
+		}
 	}
 
-	public void releaseSavepoint(Savepoint savepoint) throws SQLException {
-		getWrappedConnection().releaseSavepoint( savepoint );
+	public void releaseSavepoint(Savepoint savepoint) {
+		try {
+			getWrappedConnection().releaseSavepoint( savepoint );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to release savepoint" );
+		}
 	}
 }

Deleted: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -1,62 +0,0 @@
-/*
- * 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.impl.StatementWrapperImplementor;
-import org.hibernate.jdbc.impl.ResultSetWrapperImplementor;
-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 );
-		}
-	}
-}

Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -53,6 +53,10 @@
 		getJdbcServices().getSqlStatementLogger().logStatement( sql );
 	}
 
+	protected String getSql() {
+		return sql;
+	}
+
 	private PreparedStatement getPreparedStatement() {
 		return ( PreparedStatement ) super.getWrappedStatement();
 	}
@@ -60,153 +64,338 @@
 
 	// PreparedStatement impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-	public void addBatch() throws SQLException {
-		getPreparedStatement().addBatch();
+	public void addBatch() {
+		try {
+			getPreparedStatement().addBatch();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to addBatch", sql );
+		}
 	}
 
-	public boolean execute() throws SQLException {
-		return getPreparedStatement().execute();
+	public boolean execute() {
+		try {
+			return getPreparedStatement().execute();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute", sql );
+		}
 	}
 
-	public ResultSet executeQuery() throws SQLException {
-		return new ResultSetDelegate( this, getPreparedStatement().executeQuery() );
+	public ResultSet executeQuery() {
+		try {
+			return new ResultSetDelegate( this, getPreparedStatement().executeQuery() );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute query", sql );
+		}
 	}
 
-	public int executeUpdate() throws SQLException {
-		return getPreparedStatement().executeUpdate();
+	public int executeUpdate() {
+		try {
+			return getPreparedStatement().executeUpdate();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute update", sql );
+		}
 	}
 
-	public ResultSetMetaData getMetaData() throws SQLException {
-		return getPreparedStatement().getMetaData();
+	public ResultSetMetaData getMetaData() {
+		try {
+			return getPreparedStatement().getMetaData();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get result set metadata", sql );
+		}
 	}
 
-	public ParameterMetaData getParameterMetaData() throws SQLException {
-		return getPreparedStatement().getParameterMetaData();
+	public ParameterMetaData getParameterMetaData() {
+		try {
+			return getPreparedStatement().getParameterMetaData();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to get parameter metadata", sql );
+		}
 	}
 
-	public void clearParameters() throws SQLException {
-		getPreparedStatement().clearParameters();
+	public void clearParameters() {
+		try {
+			getPreparedStatement().clearParameters();
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to clear parameters", sql );
+		}
 	}
 
-	public void setNull(int parameterIndex, int sqlType) throws SQLException {
-		getPreparedStatement().setNull( parameterIndex, sqlType );
+	public void setNull(int parameterIndex, int sqlType) {
+		try {
+			getPreparedStatement().setNull( parameterIndex, sqlType );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setNull", sql );
+		}
 	}
 
-	public void setBoolean(int parameterIndex, boolean x) throws SQLException {
-		getPreparedStatement().setBoolean( parameterIndex, x );
+	public void setNull(int parameterIndex, int sqlType, String typeName) {
+		try {
+			getPreparedStatement().setNull( parameterIndex, sqlType, typeName );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setNull", sql );
+		}
 	}
 
-	public void setByte(int parameterIndex, byte x) throws SQLException {
-		getPreparedStatement().setByte( parameterIndex, x );
+	public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) {
+		try {
+			getPreparedStatement().setObject( parameterIndex, x, targetSqlType, scale );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setObject", sql );
+		}
 	}
 
-	public void setShort(int parameterIndex, short x) throws SQLException {
-		getPreparedStatement().setShort( parameterIndex, x );
+	public void setObject(int parameterIndex, Object x, int targetSqlType) {
+		try {
+			getPreparedStatement().setObject( parameterIndex, x, targetSqlType );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setObject", sql );
+		}
 	}
 
-	public void setInt(int parameterIndex, int x) throws SQLException {
-		getPreparedStatement().setInt( parameterIndex, x );
+	public void setObject(int parameterIndex, Object x) {
+		try {
+			getPreparedStatement().setObject( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setObject", sql );
+		}
 	}
 
-	public void setLong(int parameterIndex, long x) throws SQLException {
-		getPreparedStatement().setLong( parameterIndex, x );
+	public void setBoolean(int parameterIndex, boolean x) {
+		try {
+			getPreparedStatement().setBoolean( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setBoolean", sql );
+		}
 	}
 
-	public void setFloat(int parameterIndex, float x) throws SQLException {
-		getPreparedStatement().setFloat( parameterIndex, x );
+	public void setByte(int parameterIndex, byte x) {
+		try {
+			getPreparedStatement().setByte( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setByte", sql );
+		}
 	}
 
-	public void setDouble(int parameterIndex, double x) throws SQLException {
-		getPreparedStatement().setDouble( parameterIndex, x );
+	public void setShort(int parameterIndex, short x) {
+		try {
+			getPreparedStatement().setShort( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setShort", sql );
+		}
 	}
 
-	public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
-		getPreparedStatement().setBigDecimal( parameterIndex, x );
+	public void setInt(int parameterIndex, int x)  {
+		try {
+			getPreparedStatement().setInt( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setInt", sql );
+		}
 	}
 
-	public void setString(int parameterIndex, String x) throws SQLException {
-		getPreparedStatement().setString( parameterIndex, x );
+	public void setLong(int parameterIndex, long x) {
+		try {
+			getPreparedStatement().setLong( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setLong", sql );
+		}
 	}
 
-	public void setBytes(int parameterIndex, byte[] x) throws SQLException {
-		getPreparedStatement().setBytes( parameterIndex, x );
+	public void setFloat(int parameterIndex, float x) {
+		try {
+			getPreparedStatement().setFloat( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setFloat", sql );
+		}
 	}
 
-	public void setDate(int parameterIndex, Date x) throws SQLException {
-		getPreparedStatement().setDate( parameterIndex, x );
+	public void setDouble(int parameterIndex, double x) {
+		try {
+			getPreparedStatement().setDouble( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setDouble", sql );
+		}
 	}
 
-	public void setTime(int parameterIndex, Time x) throws SQLException {
-		getPreparedStatement().setTime( parameterIndex, x );
+	public void setBigDecimal(int parameterIndex, BigDecimal x) {
+		try {
+			getPreparedStatement().setBigDecimal( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setBigDecimal", sql );
+		}
 	}
 
-	public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
-		getPreparedStatement().setTimestamp( parameterIndex, x );
+	public void setString(int parameterIndex, String x) {
+		try {
+			getPreparedStatement().setString( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setString", sql );
+		}
 	}
 
-	public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
-		getPreparedStatement().setAsciiStream( parameterIndex, x, length );
+	public void setBytes(int parameterIndex, byte[] x) {
+		try {
+			getPreparedStatement().setBytes( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setBytes", sql );
+		}
 	}
 
-	@Deprecated
-	public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
-		getPreparedStatement().setUnicodeStream( parameterIndex, x, length );
+	public void setDate(int parameterIndex, Date x) {
+		try {
+			getPreparedStatement().setDate( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setDate", sql );
+		}
 	}
 
-	public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
-		getPreparedStatement().setBinaryStream( parameterIndex, x, length );
+	public void setTime(int parameterIndex, Time x) {
+		try {
+			getPreparedStatement().setTime( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setTime", sql );
+		}
 	}
 
-	public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException {
-		getPreparedStatement().setObject( parameterIndex, x, targetSqlType, scale );
+	public void setTimestamp(int parameterIndex, Timestamp x) {
+		try {
+			getPreparedStatement().setTimestamp( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setTimestamp", sql );
+		}
 	}
 
-	public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
-		getPreparedStatement().setObject( parameterIndex, x, targetSqlType );
+	public void setAsciiStream(int parameterIndex, InputStream x, int length) {
+		try {
+			getPreparedStatement().setAsciiStream( parameterIndex, x, length );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setAsciiStream", sql );
+		}
 	}
 
-	public void setObject(int parameterIndex, Object x) throws SQLException {
-		getPreparedStatement().setObject( parameterIndex, x );
+	@Deprecated
+	public void setUnicodeStream(int parameterIndex, InputStream x, int length) {
+		try {
+			getPreparedStatement().setUnicodeStream( parameterIndex, x, length );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setUnicodeStream", sql );
+		}
 	}
 
-	public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
-		getPreparedStatement().setCharacterStream( parameterIndex, reader, length );
+	public void setBinaryStream(int parameterIndex, InputStream x, int length) {
+		try {
+			getPreparedStatement().setBinaryStream( parameterIndex, x, length );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setBinaryStream", sql );
+		}
 	}
 
-	public void setRef(int parameterIndex, Ref x) throws SQLException {
-		getPreparedStatement().setRef( parameterIndex, x );
+	public void setCharacterStream(int parameterIndex, Reader reader, int length) {
+		try {
+			getPreparedStatement().setCharacterStream( parameterIndex, reader, length );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setCharacterStream", sql );
+		}
 	}
 
-	public void setBlob(int parameterIndex, Blob x) throws SQLException {
-		getPreparedStatement().setBlob( parameterIndex, x );
+	public void setRef(int parameterIndex, Ref x) {
+		try {
+			getPreparedStatement().setRef( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setRef", sql );
+		}
 	}
 
-	public void setClob(int parameterIndex, Clob x) throws SQLException {
-		getPreparedStatement().setClob( parameterIndex, x );
+	public void setBlob(int parameterIndex, Blob x) {
+		try {
+			getPreparedStatement().setBlob( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setBlob", sql );
+		}
 	}
 
-	public void setArray(int parameterIndex, Array x) throws SQLException {
-		getPreparedStatement().setArray( parameterIndex, x );
+	public void setClob(int parameterIndex, Clob x) {
+		try {
+			getPreparedStatement().setClob( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setClob", sql );
+		}
 	}
 
-	public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
-		getPreparedStatement().setDate( parameterIndex, x, cal );
+	public void setArray(int parameterIndex, Array x) {
+		try {
+			getPreparedStatement().setArray( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setArray", sql );
+		}
 	}
 
-	public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
-		getPreparedStatement().setTime( parameterIndex, x, cal );
+	public void setDate(int parameterIndex, Date x, Calendar cal) {
+		try {
+			getPreparedStatement().setDate( parameterIndex, x, cal );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setDate", sql );
+		}
 	}
 
-	public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
-		getPreparedStatement().setTimestamp( parameterIndex, x, cal );
+	public void setTime(int parameterIndex, Time x, Calendar cal) {
+		try {
+			getPreparedStatement().setTime( parameterIndex, x, cal );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setTime", sql );
+		}
 	}
 
-	public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
-		getPreparedStatement().setNull( parameterIndex, sqlType, typeName );
+	public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) {
+		try {
+			getPreparedStatement().setTimestamp( parameterIndex, x, cal );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setTimestamp", sql );
+		}
 	}
 
-	public void setURL(int parameterIndex, URL x) throws SQLException {
-		getPreparedStatement().setURL( parameterIndex, x );
+	public void setURL(int parameterIndex, URL x) {
+		try {
+			getPreparedStatement().setURL( parameterIndex, x );
+		}
+		catch ( SQLException e ) {
+			throw getJdbcServices().getExceptionHelper().convert( e, "unable to setURL", sql );
+		}
 	}
 
 

Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -103,6 +103,9 @@
 		Set resultSets = ( Set ) xref.get( statement );
 		if ( resultSets != null ) {
 			resultSets.remove( resultSet );
+			if ( resultSets.isEmpty() ) {
+				xref.remove( statement );
+			}
 		}
 		close( resultSet );
 	}
@@ -141,6 +144,14 @@
 
 	protected void close(Statement statement) {
 		log.trace( "closing prepared statement [{}]", statement );
+
+		if ( statement instanceof StatementWrapperImplementor ) {
+			StatementWrapperImplementor wrapper = ( StatementWrapperImplementor ) statement;
+			close( wrapper.getWrappedStatement() );
+			wrapper.invalidate();
+			return;
+		}
+
 		try {
 			// if we are unable to "clean" the prepared statement,
 			// we do not close it
@@ -166,6 +177,13 @@
 
 	protected void close(ResultSet resultSet) {
 		log.trace( "closing result set [{}]", resultSet );
+
+		if ( resultSet instanceof ResultSetWrapperImplementor ) {
+			ResultSetWrapperImplementor wrapper = ( ResultSetWrapperImplementor ) resultSet;
+			close( wrapper.getWrappedResultSet() );
+			wrapper.invalidate();
+		}
+
 		try {
 			resultSet.close();
 		}

Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainerBuilder.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainerBuilder.java	                        (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainerBuilder.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -0,0 +1,37 @@
+/*
+ * 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.jdbc.JDBCContainerBuilder;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.util.ExceptionHelper;
+
+/**
+ * BasicJDBCContainerBuilder implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicJDBCContainerBuilder implements JDBCContainerBuilder {
+	private final ExceptionHelper exceptionHelper;
+
+	public BasicJDBCContainerBuilder(ExceptionHelper exceptionHelper) {
+		this.exceptionHelper = exceptionHelper;
+	}
+
+	public JDBCContainer buildJdbcContainer() {
+		return new BasicJDBCContainer( exceptionHelper );
+	}
+}

Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractProxyHandler.java	                        (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractProxyHandler.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -0,0 +1,77 @@
+/*
+ * 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.proxy;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import org.hibernate.HibernateException;
+
+/**
+ * Basic support for
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractProxyHandler implements InvocationHandler {
+	private boolean valid = true;
+	private final int hashCode;
+
+	public AbstractProxyHandler(int hashCode) {
+		this.hashCode = hashCode;
+	}
+
+	protected abstract Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable;
+
+	public String toString() {
+		return super.toString() + "[valid=" + valid + "]";
+	}
+
+	public final int hashCode() {
+		return hashCode;
+	}
+
+	protected final boolean isValid() {
+		return valid;
+	}
+
+	protected final void invalidate() {
+		valid = false;
+	}
+
+	protected final void errorIfInvalid() {
+		if ( !isValid() ) {
+			throw new HibernateException( "proxy handle is no longer valid" );
+		}
+	}
+
+	public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+		String methodName = method.getName();
+
+		// basic Object methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+		if ( "toString".equals( methodName ) ) {
+			return this.toString();
+		}
+		if ( "hashCode".equals( methodName ) ) {
+			return this.hashCode();
+		}
+		if ( "equals".equals( methodName ) ) {
+			return this.equals( args[0] );
+		}
+
+		return continueInvocation( proxy, method, args );
+	}
+
+}

Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractResultSetProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractResultSetProxyHandler.java	                        (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractResultSetProxyHandler.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -0,0 +1,110 @@
+/*
+ * 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.proxy;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.JDBCServices;
+
+/**
+ * AbstractResultSetProxyHandler implementation
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractResultSetProxyHandler extends AbstractProxyHandler {
+	private static final Logger log = LoggerFactory.getLogger( AbstractResultSetProxyHandler.class );
+
+	private ResultSet resultSet;
+
+	public AbstractResultSetProxyHandler(ResultSet resultSet) {
+		super( resultSet.hashCode() );
+		this.resultSet = resultSet;
+	}
+
+	protected abstract JDBCServices getJdbcServices();
+
+	protected abstract JDBCContainer getJdbcContainer();
+
+	protected abstract Statement getExposeableStatement();
+
+	protected final ResultSet getResultSet() {
+		errorIfInvalid();
+		return resultSet;
+	}
+
+	protected final ResultSet getResultSetWithoutChecks() {
+		return resultSet;
+	}
+
+	protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
+		String methodName = method.getName();
+		log.trace( "Handling invocation of resultset method [{}]", methodName );
+
+		// other methods allowed while invalid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+		if ( "close".equals( methodName ) ) {
+			explicitClose( ( ResultSet ) proxy );
+			return null;
+		}
+		if ( "invalidate".equals( methodName ) ) {
+			invalidateHandle();
+			return null;
+		}
+
+		errorIfInvalid();
+
+		if ( "getWrappedResultSet".equals( methodName ) ) {
+			return getResultSetWithoutChecks();
+		}
+
+		if ( "getStatement".equals( methodName ) ) {
+			return getExposeableStatement();
+		}
+
+		try {
+			return method.invoke( resultSet, args );
+		}
+		catch ( InvocationTargetException e ) {
+			Throwable realException = e.getTargetException();
+			if ( SQLException.class.isInstance( realException ) ) {
+				throw getJdbcServices().getExceptionHelper()
+						.convert( ( SQLException ) realException, realException.getMessage() );
+			}
+			else {
+				throw realException;
+			}
+		}
+	}
+
+	private void explicitClose(ResultSet proxy) {
+		if ( isValid() ) {
+			getJdbcContainer().release( proxy );
+		}
+	}
+
+	protected void invalidateHandle() {
+		resultSet = null;
+		invalidate();
+	}
+}

Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractStatementProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractStatementProxyHandler.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractStatementProxyHandler.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -15,7 +15,6 @@
  */
 package org.hibernate.jdbc.proxy;
 
-import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.sql.Connection;
@@ -26,7 +25,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.hibernate.HibernateException;
 import org.hibernate.jdbc.JDBCContainer;
 import org.hibernate.jdbc.JDBCServices;
 import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
@@ -36,31 +34,23 @@
  *
  * @author Steve Ebersole
  */
-public abstract class AbstractStatementProxyHandler implements InvocationHandler {
+public abstract class AbstractStatementProxyHandler extends AbstractProxyHandler {
 	private static final Logger log = LoggerFactory.getLogger( AbstractStatementProxyHandler.class );
 
 	private ConnectionProxyHandler connectionProxyHandler;
 	private Connection connectionProxy;
 	private Statement statement;
-	private boolean valid = true;
-	private final int hashCode;
 
 	protected AbstractStatementProxyHandler(
 			Statement statement,
 			ConnectionProxyHandler connectionProxyHandler,
 			Connection connectionProxy) {
+		super( statement.hashCode() );
 		this.statement = statement;
 		this.connectionProxyHandler = connectionProxyHandler;
 		this.connectionProxy = connectionProxy;
-		this.hashCode = statement.hashCode();
 	}
 
-	private void errorIfInvalid() {
-		if ( !valid ) {
-			throw new HibernateException( "statment proxy is no longer valid" );
-		}
-	}
-
 	protected ConnectionProxyHandler getConnectionProxy() {
 		errorIfInvalid();
 		return connectionProxyHandler;
@@ -83,21 +73,10 @@
 		return statement;
 	}
 
-	public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+	protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
 		String methodName = method.getName();
 		log.trace( "Handling invocation of statement method [{}]", methodName );
 
-		// basic Object methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-		if ( "toString".equals( methodName ) ) {
-			return this.toString();
-		}
-		if ( "equals".equals( methodName ) ) {
-			return this.equals( args[0] );
-		}
-		if ( "hashCode".equals( methodName ) ) {
-			return this.hashCode();
-		}
-
 		// other methods allowed while invalid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 		if ( "close".equals( methodName ) ) {
 			explicitClose( ( Statement ) proxy );
@@ -121,15 +100,8 @@
 		beginningInvocationHandling( method, args );
 
 		try {
-			boolean exposingResultSet = doesMethodExposeResultSet( method );
-
 			Object result = method.invoke( statement, args );
-
-			if ( exposingResultSet ) {
-				result = ProxyBuilder.buildResultSet( ( ResultSet ) result, this, ( Statement ) proxy );
-				getJdbcContainer().register( ( ResultSet ) result );
-			}
-
+			result = wrapIfNecessary( result, proxy, method );
 			return result;
 		}
 		catch ( InvocationTargetException e ) {
@@ -144,11 +116,27 @@
 		}
 	}
 
+	private Object wrapIfNecessary(Object result, Object proxy, Method method) {
+		if ( !( ResultSet.class.isAssignableFrom( method.getReturnType() ) ) ) {
+			return result;
+		}
+
+		final ResultSet wrapper;
+		if ( "getGeneratedKeys".equals( method.getName() ) ) {
+			wrapper = ProxyBuilder.buildImplicitResultSet( ( ResultSet ) result, connectionProxyHandler, connectionProxy );
+		}
+		else {
+			wrapper = ProxyBuilder.buildResultSet( ( ResultSet ) result, this, ( Statement ) proxy );
+		}
+		getJdbcContainer().register( wrapper );
+		return wrapper;
+	}
+
 	protected void beginningInvocationHandling(Method method, Object[] args) {
 	}
 
 	private void explicitClose(Statement proxy) {
-		if ( valid ) {
+		if ( isValid() ) {
 			LogicalConnectionImplementor lc = getConnectionProxy().getLogicalConnection();
 			getJdbcContainer().release( proxy );
 			lc.afterStatementExecution();
@@ -158,20 +146,6 @@
 	private void invalidateHandle() {
 		connectionProxyHandler = null;
 		statement = null;
-		valid = false;
+		invalidate();
 	}
-
-	protected boolean doesMethodExposeResultSet(Method method) {
-		// todo : we still need to handle getGeneratedKeys, since the resultset there would expose the statement
-		return ResultSet.class.isAssignableFrom( method.getReturnType() )
-				&& !method.getName().equals( "getGeneratedKeys" );
-	}
-
-	public String toString() {
-		return super.toString() + "[valid=" + valid + "]";
-	}
-
-	public int hashCode() {
-		return hashCode;
-	}
 }

Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ConnectionProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ConnectionProxyHandler.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ConnectionProxyHandler.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -20,6 +20,7 @@
 import java.lang.reflect.Method;
 import java.sql.CallableStatement;
 import java.sql.Connection;
+import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -27,7 +28,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.hibernate.HibernateException;
 import org.hibernate.jdbc.JDBCContainer;
 import org.hibernate.jdbc.JDBCServices;
 import org.hibernate.jdbc.impl.ConnectionObserver;
@@ -38,17 +38,15 @@
  *
  * @author Steve Ebersole
  */
-public class ConnectionProxyHandler implements InvocationHandler, ConnectionObserver {
+public class ConnectionProxyHandler extends AbstractProxyHandler implements InvocationHandler, ConnectionObserver {
 	private static final Logger log = LoggerFactory.getLogger( ConnectionProxyHandler.class );
 
 	private LogicalConnectionImplementor logicalConnection;
-	private boolean valid = true;
-	private final int hashCode;
 
 	public ConnectionProxyHandler(LogicalConnectionImplementor logicalConnection) {
+		super( logicalConnection.hashCode() );
 		this.logicalConnection = logicalConnection;
 		this.logicalConnection.addObserver( this );
-		this.hashCode = this.logicalConnection.hashCode();
 	}
 
 	/**
@@ -61,12 +59,6 @@
 		return logicalConnection;
 	}
 
-	private void errorIfInvalid() {
-		if ( !valid ) {
-			throw new HibernateException( "connection handle is invalid" );
-		}
-	}
-
 	/**
 	 * Get reference to physical connection.
 	 * <p/>
@@ -100,24 +92,10 @@
 		return logicalConnection.getJdbcContainer();
 	}
 
-	/**
-	 * {@inheritDoc}
-	 */
-	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+	protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
 		String methodName = method.getName();
 		log.trace( "Handling invocation of connection method [{}]", methodName );
 
-		// basic Object methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-		if ( "toString".equals( methodName ) ) {
-			return this.toString();
-		}
-		if ( "equals".equals( methodName ) ) {
-			return this.equals( args[0] );
-		}
-		if ( "hashCode".equals( methodName ) ) {
-			return this.hashCode();
-		}
-
 		// other methods allowed while invalid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 		if ( "close".equals( methodName ) ) {
 			explicitClose();
@@ -132,34 +110,8 @@
 
 		try {
 			Object result = method.invoke( extractPhysicalConnection(), args );
+			result = wrapIfNecessary( result, proxy, method, args );
 
-			if ( "createStatement".equals( methodName ) ) {
-				result = ProxyBuilder.buildStatement(
-						( Statement ) result,
-						this,
-						( Connection ) proxy
-				);
-				getJdbcContainer().register( ( Statement ) result );
-			}
-			else if ( "prepareStatement".equals( methodName ) ) {
-				result = ProxyBuilder.buildPreparedStatement(
-						( String ) args[0],
-						( PreparedStatement ) result,
-						this,
-						( Connection ) proxy
-				);
-				getJdbcContainer().register( ( Statement ) result );
-			}
-			else if ( "prepareCall".equals( methodName ) ) {
-				result = ProxyBuilder.buildCallableStatement(
-						( String ) args[0],
-						( CallableStatement ) result,
-						this,
-						( Connection ) proxy
-				);
-				getJdbcContainer().register( ( Statement ) result );
-			}
-
 			return result;
 		}
 		catch( InvocationTargetException e ) {
@@ -174,8 +126,43 @@
 		}
 	}
 
+	private Object wrapIfNecessary(Object result, Object proxy, Method method, Object[] args) {
+		String methodName = method.getName();
+		Object wrapped = result;
+		if ( "createStatement".equals( methodName ) ) {
+			wrapped = ProxyBuilder.buildStatement(
+					( Statement ) result,
+					this,
+					( Connection ) proxy
+			);
+			getJdbcContainer().register( ( Statement ) wrapped );
+		}
+		else if ( "prepareStatement".equals( methodName ) ) {
+			wrapped = ProxyBuilder.buildPreparedStatement(
+					( String ) args[0],
+					( PreparedStatement ) result,
+					this,
+					( Connection ) proxy
+			);
+			getJdbcContainer().register( ( Statement ) wrapped );
+		}
+		else if ( "prepareCall".equals( methodName ) ) {
+			wrapped = ProxyBuilder.buildCallableStatement(
+					( String ) args[0],
+					( CallableStatement ) result,
+					this,
+					( Connection ) proxy
+			);
+			getJdbcContainer().register( ( Statement ) wrapped );
+		}
+		else if ( "getMetaData".equals( methodName ) ) {
+			wrapped = ProxyBuilder.buildDatabaseMetaData( ( DatabaseMetaData ) result, this, ( Connection ) proxy );
+		}
+		return wrapped;
+	}
+
 	private void explicitClose() {
-		if ( valid ) {
+		if ( isValid() ) {
 			invalidateHandle();
 		}
 	}
@@ -183,7 +170,7 @@
 	private void invalidateHandle() {
 		log.trace( "Invalidating connection handle" );
 		logicalConnection = null;
-		valid = false;
+		invalidate();
 	}
 
 	/**
@@ -206,12 +193,4 @@
 		log.info( "*** logical connection closed ***" );
 		invalidateHandle();
 	}
-
-	public String toString() {
-		return super.toString() + "[valid=" + valid + "]";
-	}
-
-	public int hashCode() {
-		return hashCode;
-	}
 }

Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/DatabaseMetaDataProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/DatabaseMetaDataProxyHandler.java	                        (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/DatabaseMetaDataProxyHandler.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -0,0 +1,75 @@
+/*
+ * 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.proxy;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * The InvocationHandler for intercepting messages to {@link DatabaseMetaData} proxies.
+ * <p/>
+ * Mainly we need to intercept the methods defined on {@link DatabaseMetaData} which expose
+ * {@link java.sql.ResultSet} instances, which in turn expose {@link java.sql.Statement}
+ * instances, which in turn...
+ *
+ * @author Steve Ebersole
+ */
+public class DatabaseMetaDataProxyHandler extends AbstractProxyHandler {
+	private ConnectionProxyHandler connectionProxyHandler;
+	private Connection connectionProxy;
+	private DatabaseMetaData databaseMetaData;
+
+	public DatabaseMetaDataProxyHandler(DatabaseMetaData databaseMetaData, ConnectionProxyHandler connectionProxyHandler, Connection connectionProxy) {
+		super( databaseMetaData.hashCode() );
+		this.connectionProxyHandler = connectionProxyHandler;
+		this.connectionProxy = connectionProxy;
+		this.databaseMetaData = databaseMetaData;
+	}
+
+	protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
+		try {
+			boolean exposingResultSet = doesMethodExposeResultSet( method );
+
+			Object result = method.invoke( databaseMetaData, args );
+
+			if ( exposingResultSet ) {
+				result = ProxyBuilder.buildImplicitResultSet( ( ResultSet ) result, connectionProxyHandler, connectionProxy );
+				connectionProxyHandler.getJdbcContainer().register( ( ResultSet ) result );
+			}
+
+			return result;
+		}
+		catch ( InvocationTargetException e ) {
+			Throwable realException = e.getTargetException();
+			if ( SQLException.class.isInstance( realException ) ) {
+				throw connectionProxyHandler.getJdbcServices().getExceptionHelper()
+						.convert( ( SQLException ) realException, realException.getMessage() );
+			}
+			else {
+				throw realException;
+			}
+		}
+	}
+
+	protected boolean doesMethodExposeResultSet(Method method) {
+		return ResultSet.class.isAssignableFrom( method.getReturnType() );
+	}
+ 
+}

Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitResultSetProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitResultSetProxyHandler.java	                        (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitResultSetProxyHandler.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -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.proxy;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.sql.SQLException;
+
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.JDBCServices;
+
+/**
+ * ImplicitResultSetProxyHandler implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ImplicitResultSetProxyHandler extends AbstractResultSetProxyHandler {
+	private ConnectionProxyHandler connectionProxyHandler;
+	private Connection connectionProxy;
+	private Statement sourceStatement;
+
+	public ImplicitResultSetProxyHandler(ResultSet resultSet, ConnectionProxyHandler connectionProxyHandler, Connection connectionProxy) {
+		super( resultSet );
+		this.connectionProxyHandler = connectionProxyHandler;
+		this.connectionProxy = connectionProxy;
+	}
+
+	protected JDBCServices getJdbcServices() {
+		return connectionProxyHandler.getJdbcServices();
+	}
+
+	protected JDBCContainer getJdbcContainer() {
+		return connectionProxyHandler.getJdbcContainer();
+	}
+
+	protected Statement getExposeableStatement() {
+		if ( sourceStatement == null ) {
+			try {
+				Statement stmnt = getResultSet().getStatement();
+				sourceStatement = ProxyBuilder.buildImplicitStatement( stmnt, connectionProxyHandler, connectionProxy );
+			}
+			catch ( SQLException e ) {
+				throw getJdbcServices().getExceptionHelper().convert( e, e.getMessage() );
+			}
+		}
+		return sourceStatement;
+	}
+
+	protected void invalidateHandle() {
+		sourceStatement = null;
+		super.invalidateHandle();
+	}
+}

Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitStatementProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitStatementProxyHandler.java	                        (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitStatementProxyHandler.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -0,0 +1,40 @@
+/*
+ * 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.proxy;
+
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.Statement;
+
+import org.hibernate.HibernateException;
+
+/**
+ * ImplicitStatementProxyHandler implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ImplicitStatementProxyHandler extends AbstractStatementProxyHandler {
+	protected ImplicitStatementProxyHandler(Statement statement, ConnectionProxyHandler connectionProxyHandler, Connection connectionProxy) {
+		super( statement, connectionProxyHandler, connectionProxy );
+	}
+
+	protected void beginningInvocationHandling(Method method, Object[] args) {
+		// disallow executions...
+		if ( method.getName().startsWith( "execute" ) ) {
+			throw new HibernateException( "execution not allowed on implicit statement object" );
+		}
+	}
+}

Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyBuilder.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyBuilder.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyBuilder.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -18,6 +18,7 @@
 import java.lang.reflect.Proxy;
 import java.sql.CallableStatement;
 import java.sql.Connection;
+import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.Statement;
@@ -57,6 +58,7 @@
 			ResultSetWrapperImplementor.class
 	};
 
+	public static final Class[] METADATA_PROXY_INTERFACES = new Class[] { DatabaseMetaData.class };
 
 	public static Connection buildConnection(LogicalConnectionImplementor logicalConnection) {
 		ConnectionProxyHandler proxyHandler = new ConnectionProxyHandler( logicalConnection );
@@ -130,4 +132,40 @@
 				proxyHandler
 		);
 	}
+
+	public static DatabaseMetaData buildDatabaseMetaData(
+			DatabaseMetaData metaData,
+			ConnectionProxyHandler connectionProxyHandler,
+			Connection connectionProxy) {
+		DatabaseMetaDataProxyHandler handler = new DatabaseMetaDataProxyHandler( metaData, connectionProxyHandler, connectionProxy );
+		return ( DatabaseMetaData ) Proxy.newProxyInstance(
+				DatabaseMetaDataProxyHandler.class.getClassLoader(),
+				METADATA_PROXY_INTERFACES,
+				handler
+		);
+	}
+
+	public static ResultSet buildImplicitResultSet(
+			ResultSet resultSet,
+			ConnectionProxyHandler connectionProxyHandler,
+			Connection connectionProxy) {
+		ImplicitResultSetProxyHandler proxyHandler = new ImplicitResultSetProxyHandler( resultSet, connectionProxyHandler, connectionProxy );
+		return ( ResultSet ) Proxy.newProxyInstance(
+				ResultSetWrapperImplementor.class.getClassLoader(),
+				RESULTSET_PROXY_INTERFACES,
+				proxyHandler
+		);
+	}
+
+	public static Statement buildImplicitStatement(
+			Statement statement,
+			ConnectionProxyHandler connectionProxyHandler,
+			Connection connectionProxy) {
+		ImplicitStatementProxyHandler handler = new ImplicitStatementProxyHandler( statement, connectionProxyHandler, connectionProxy );
+		return ( Statement ) Proxy.newProxyInstance(
+				StatementWrapperImplementor.class.getClassLoader(),
+				STMNT_PROXY_INTERFACES,
+				handler
+		);
+	}
 }

Deleted: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyJDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyJDBCContainer.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyJDBCContainer.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -1,57 +0,0 @@
-/*
- * 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.proxy;
-
-import java.sql.ResultSet;
-import java.sql.Statement;
-
-import org.hibernate.jdbc.impl.BasicJDBCContainer;
-import org.hibernate.jdbc.impl.ResultSetWrapperImplementor;
-import org.hibernate.jdbc.impl.StatementWrapperImplementor;
-import org.hibernate.jdbc.util.ExceptionHelper;
-
-/**
- * ProxyJDBCContainer implementation
- *
- * @author Steve Ebersole
- */
-public class ProxyJDBCContainer extends BasicJDBCContainer {
-	public ProxyJDBCContainer(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 );
-		}
-	}
-}

Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetProxyHandler.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetProxyHandler.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -15,17 +15,9 @@
  */
 package org.hibernate.jdbc.proxy;
 
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.sql.ResultSet;
-import java.sql.SQLException;
 import java.sql.Statement;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.hibernate.HibernateException;
 import org.hibernate.jdbc.JDBCContainer;
 import org.hibernate.jdbc.JDBCServices;
 
@@ -34,44 +26,27 @@
  *
  * @author Steve Ebersole
  */
-public class ResultSetProxyHandler implements InvocationHandler {
-	private static final Logger log = LoggerFactory.getLogger( ResultSetProxyHandler.class );
-
+public class ResultSetProxyHandler extends AbstractResultSetProxyHandler {
 	private AbstractStatementProxyHandler statementProxyHandler;
 	private Statement statementProxy;
-	private ResultSet resultSet;
-	private boolean valid = true;
-	private final int hashCode;
 
 	public ResultSetProxyHandler(
 			ResultSet resultSet,
 			AbstractStatementProxyHandler statementProxyHandler,
 			Statement statementProxy) {
-		this.resultSet = resultSet;
+		super( resultSet );
 		this.statementProxyHandler = statementProxyHandler;
 		this.statementProxy = statementProxy;
-		this.hashCode = resultSet.hashCode();
 	}
 
-	protected ResultSet getResultSet() {
-		errorIfInvalid();
-		return resultSet;
-	}
-
-	protected ResultSet getResultSetWithoutChecks() {
-		return resultSet;
-	}
-
-	protected void errorIfInvalid() {
-		if ( !valid ) {
-			throw new HibernateException( "resultset handle is no longer valid" );
-		}
-	}
-
 	protected AbstractStatementProxyHandler getStatementProxy() {
 		return statementProxyHandler;
 	}
 
+	protected Statement getExposeableStatement() {
+		return statementProxy;
+	}
+
 	protected JDBCServices getJdbcServices() {
 		return getStatementProxy().getJdbcServices();
 	}
@@ -80,73 +55,8 @@
 		return getStatementProxy().getJdbcContainer();
 	}
 
-	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-		String methodName = method.getName();
-		log.trace( "Handling invocation of resultset method [{}]", methodName );
-
-		// basic Object methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-		if ( "toString".equals( methodName ) ) {
-			return this.toString();
-		}
-		if ( "equals".equals( methodName ) ) {
-			return this.equals( args[0] );
-		}
-		if ( "hashCode".equals( methodName ) ) {
-			return this.hashCode();
-		}
-
-		// other methods allowed while invalid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-		if ( "close".equals( methodName ) ) {
-			explicitClose( ( ResultSet ) proxy );
-			return null;
-		}
-		if ( "invalidate".equals( methodName ) ) {
-			invalidateHandle();
-			return null;
-		}
-
-		errorIfInvalid();
-
-		if ( "getWrappedResultSet".equals( methodName ) ) {
-			return getResultSetWithoutChecks();
-		}
-
-		if ( "getStatement".equals( methodName ) ) {
-			return statementProxy;
-		}
-
-		try {
-			return method.invoke( resultSet, args );
-		}
-		catch ( InvocationTargetException e ) {
-			Throwable realException = e.getTargetException();
-			if ( SQLException.class.isInstance( realException ) ) {
-				throw getJdbcServices().getExceptionHelper()
-						.convert( ( SQLException ) realException, realException.getMessage() );
-			}
-			else {
-				throw realException;
-			}
-		}
-	}
-
-	private void explicitClose(ResultSet proxy) {
-		if ( valid ) {
-			statementProxyHandler.getJdbcContainer().release( proxy );
-		}
-	}
-
-	private void invalidateHandle() {
+	protected void invalidateHandle() {
 		statementProxyHandler = null;
-		resultSet = null;
-		valid = false;
+		super.invalidateHandle();
 	}
-
-	public String toString() {
-		return super.toString() + "[valid=" + valid + "]";
-	}
-
-	public int hashCode() {
-		return hashCode;
-	}
 }

Modified: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/TestingServiceImpl.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/TestingServiceImpl.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -15,17 +15,11 @@
  */
 package org.hibernate.jdbc.batch;
 
-import java.sql.SQLException;
-
-import org.hibernate.cfg.Settings;
 import org.hibernate.connection.ConnectionProvider;
-import org.hibernate.exception.SQLStateConverter;
-import org.hibernate.exception.ViolatedConstraintNameExtracter;
 import org.hibernate.jdbc.ConnectionProviderBuilder;
-import org.hibernate.jdbc.JDBCContainer;
 import org.hibernate.jdbc.JDBCContainerBuilder;
 import org.hibernate.jdbc.JDBCServices;
-import org.hibernate.jdbc.proxy.ProxyJDBCContainer;
+import org.hibernate.jdbc.impl.BasicJDBCContainerBuilder;
 import org.hibernate.jdbc.util.ExceptionHelper;
 import org.hibernate.jdbc.util.SQLStatementLogger;
 
@@ -43,20 +37,8 @@
 	public void prepare(boolean allowAggressiveRelease) {
 		connectionProvider = ConnectionProviderBuilder.buildConnectionProvider( allowAggressiveRelease );
 		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 ProxyJDBCContainer( exceptionHelper );
-			}
-		};
+		exceptionHelper = new ExceptionHelper();
+		jdbcContainerBuilder = new BasicJDBCContainerBuilder( exceptionHelper );
 	}
 
 	public void release() {

Modified: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -18,7 +18,7 @@
 import org.hibernate.jdbc.JDBCServices;
 import org.hibernate.jdbc.JDBCContainerBuilder;
 import org.hibernate.jdbc.ConnectionProviderBuilder;
-import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.impl.BasicJDBCContainerBuilder;
 import org.hibernate.jdbc.util.SQLStatementLogger;
 import org.hibernate.jdbc.util.ExceptionHelper;
 import org.hibernate.connection.ConnectionProvider;
@@ -38,11 +38,7 @@
 		connectionProvider = ConnectionProviderBuilder.buildConnectionProvider( allowAggressiveRelease );
 		sqlStatementLogger = new SQLStatementLogger( true );
 		exceptionHelper = new ExceptionHelper();
-		jdbcContainerBuilder = new JDBCContainerBuilder() {
-			public JDBCContainer buildJdbcContainer() {
-				return new DelegateJDBCContainer( exceptionHelper );
-			}
-		};
+		jdbcContainerBuilder = new BasicJDBCContainerBuilder( exceptionHelper );
 	}
 
 	public void release() {

Modified: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -20,12 +20,9 @@
 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
@@ -41,20 +38,8 @@
 	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 );
-			}
-		};
+		exceptionHelper = new ExceptionHelper();
+		jdbcContainerBuilder = new BasicJDBCContainerBuilder( exceptionHelper );
 	}
 
 	public void release() {

Modified: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/BasicConnectionProxyTest.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/BasicConnectionProxyTest.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/BasicConnectionProxyTest.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -15,24 +15,24 @@
  */
 package org.hibernate.jdbc.proxy;
 
-import java.lang.reflect.Proxy;
 import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.sql.PreparedStatement;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.assertFalse;
 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.ConnectionWrapper;
 import org.hibernate.jdbc.impl.LogicalConnectionImpl;
 
 /**
@@ -56,6 +56,30 @@
 	}
 
 	@Test
+	public void testDatabaseMetaDataHandling() throws Throwable {
+		LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+		Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
+		try {
+			DatabaseMetaData metaData = proxiedConnection.getMetaData();
+			assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+			ResultSet rs1 = metaData.getCatalogs();
+			assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+			rs1.close();
+			assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+			metaData.getCatalogs();
+			metaData.getSchemas();
+			assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+		}
+		catch ( SQLException sqle ) {
+			fail( "incorrect exception type : sqlexception" );
+		}
+		finally {
+			logicalConnection.close();
+			assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+		}
+	}
+
+	@Test
 	public void testExceptionHandling() {
 		LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
 		Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );

Modified: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/TestingServiceImpl.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/TestingServiceImpl.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -20,12 +20,10 @@
 import org.hibernate.jdbc.JDBCServices;
 import org.hibernate.jdbc.JDBCContainerBuilder;
 import org.hibernate.jdbc.ConnectionProviderBuilder;
-import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.impl.BasicJDBCContainerBuilder;
 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
@@ -41,20 +39,8 @@
 	public void prepare(boolean allowAggressiveRelease) {
 		connectionProvider = ConnectionProviderBuilder.buildConnectionProvider( allowAggressiveRelease );
 		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 ProxyJDBCContainer( exceptionHelper );
-			}
-		};
+		exceptionHelper = new ExceptionHelper();
+		jdbcContainerBuilder = new BasicJDBCContainerBuilder( exceptionHelper );
 	}
 
 	public void release() {

Modified: sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -129,9 +129,6 @@
 		System.gc();
 		System.gc();
 
-		Connection c;
-		LogicalConnectionImpl lc;
-
 		// prime ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 		for ( int a = 0, Z = datums.length; a < Z; a++ ) {

Modified: sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/TestingServiceImpl.java	2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/TestingServiceImpl.java	2007-08-22 15:36:17 UTC (rev 13948)
@@ -15,14 +15,10 @@
  */
 package org.hibernate.jdbc;
 
-import java.sql.SQLException;
-
-import org.hibernate.jdbc.proxy.ProxyJDBCContainer;
-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;
+import org.hibernate.jdbc.impl.BasicJDBCContainerBuilder;
+import org.hibernate.jdbc.util.ExceptionHelper;
+import org.hibernate.jdbc.util.SQLStatementLogger;
 
 /**
  * TestingServiceImpl implementation
@@ -38,20 +34,8 @@
 	public void prepare(boolean allowAggressiveRelease) {
 		connectionProvider = ConnectionProviderBuilder.buildConnectionProvider( allowAggressiveRelease );
 		sqlStatementLogger = new SQLStatementLogger( false );
-		exceptionHelper = new ExceptionHelper(
-				new SQLStateConverter(
-						new ViolatedConstraintNameExtracter() {
-							public String extractConstraintName(SQLException e) {
-								return null;
-							}
-						}
-				)
-		);
-		jdbcContainerBuilder = new JDBCContainerBuilder() {
-			public JDBCContainer buildJdbcContainer() {
-				return new ProxyJDBCContainer( exceptionHelper );
-			}
-		};
+		exceptionHelper = new ExceptionHelper();
+		jdbcContainerBuilder = new BasicJDBCContainerBuilder( exceptionHelper );
 	}
 
 	public void release() {




More information about the hibernate-commits mailing list