Hibernate SVN: r13937 - core/trunk/core/src/main/java/org/hibernate/engine/loading.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2007-08-19 19:09:11 -0400 (Sun, 19 Aug 2007)
New Revision: 13937
Modified:
core/trunk/core/src/main/java/org/hibernate/engine/loading/CollectionLoadContext.java
core/trunk/core/src/main/java/org/hibernate/engine/loading/LoadContexts.java
Log:
HHH-2795 : CollectionLoadContext processing for empty collections
Modified: core/trunk/core/src/main/java/org/hibernate/engine/loading/CollectionLoadContext.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/loading/CollectionLoadContext.java 2007-08-19 23:06:39 UTC (rev 13936)
+++ core/trunk/core/src/main/java/org/hibernate/engine/loading/CollectionLoadContext.java 2007-08-19 23:09:11 UTC (rev 13937)
@@ -152,7 +152,7 @@
public void endLoadingCollections(CollectionPersister persister) {
SessionImplementor session = getLoadContext().getPersistenceContext().getSession();
if ( !loadContexts.hasLoadingCollectionEntries()
- || localLoadingCollectionKeys.isEmpty() ) {
+ && localLoadingCollectionKeys.isEmpty() ) {
return;
}
Modified: core/trunk/core/src/main/java/org/hibernate/engine/loading/LoadContexts.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/loading/LoadContexts.java 2007-08-19 23:06:39 UTC (rev 13936)
+++ core/trunk/core/src/main/java/org/hibernate/engine/loading/LoadContexts.java 2007-08-19 23:09:11 UTC (rev 13937)
@@ -132,6 +132,17 @@
* false otherwise.
*/
public boolean hasLoadingCollectionEntries() {
+ return ( collectionLoadContexts != null && !collectionLoadContexts.isEmpty() );
+ }
+
+ /**
+ * Do we currently have any registered internal entries corresponding to loading
+ * collections?
+ *
+ * @return True if we currently hold state pertaining to a registered loading collections;
+ * false otherwise.
+ */
+ public boolean hasRegisteredLoadingCollectionEntries() {
return ( xrefLoadingCollectionEntries != null && !xrefLoadingCollectionEntries.isEmpty() );
}
@@ -186,9 +197,6 @@
}
}
-
-
-
// loading collection xrefs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
@@ -228,7 +236,7 @@
* @param key The key of the collection we are done processing.
*/
void unregisterLoadingCollectionXRef(CollectionKey key) {
- if ( !hasLoadingCollectionEntries() ) {
+ if ( !hasRegisteredLoadingCollectionEntries() ) {
return;
}
xrefLoadingCollectionEntries.remove(key);
16 years, 8 months
Hibernate SVN: r13936 - core/branches/Branch_3_2/src/org/hibernate/engine/loading.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2007-08-19 19:06:39 -0400 (Sun, 19 Aug 2007)
New Revision: 13936
Modified:
core/branches/Branch_3_2/src/org/hibernate/engine/loading/CollectionLoadContext.java
core/branches/Branch_3_2/src/org/hibernate/engine/loading/LoadContexts.java
Log:
HHH-2795 : CollectionLoadContext processing for empty collections
Modified: core/branches/Branch_3_2/src/org/hibernate/engine/loading/CollectionLoadContext.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/engine/loading/CollectionLoadContext.java 2007-08-18 13:48:50 UTC (rev 13935)
+++ core/branches/Branch_3_2/src/org/hibernate/engine/loading/CollectionLoadContext.java 2007-08-19 23:06:39 UTC (rev 13936)
@@ -153,7 +153,7 @@
public void endLoadingCollections(CollectionPersister persister) {
SessionImplementor session = getLoadContext().getPersistenceContext().getSession();
if ( !loadContexts.hasLoadingCollectionEntries()
- || localLoadingCollectionKeys.isEmpty() ) {
+ && localLoadingCollectionKeys.isEmpty() ) {
return;
}
Modified: core/branches/Branch_3_2/src/org/hibernate/engine/loading/LoadContexts.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/engine/loading/LoadContexts.java 2007-08-18 13:48:50 UTC (rev 13935)
+++ core/branches/Branch_3_2/src/org/hibernate/engine/loading/LoadContexts.java 2007-08-19 23:06:39 UTC (rev 13936)
@@ -132,6 +132,17 @@
* false otherwise.
*/
public boolean hasLoadingCollectionEntries() {
+ return ( collectionLoadContexts != null && !collectionLoadContexts.isEmpty() );
+ }
+
+ /**
+ * Do we currently have any registered internal entries corresponding to loading
+ * collections?
+ *
+ * @return True if we currently hold state pertaining to a registered loading collections;
+ * false otherwise.
+ */
+ public boolean hasRegisteredLoadingCollectionEntries() {
return ( xrefLoadingCollectionEntries != null && !xrefLoadingCollectionEntries.isEmpty() );
}
@@ -228,7 +239,7 @@
* @param key The key of the collection we are done processing.
*/
void unregisterLoadingCollectionXRef(CollectionKey key) {
- if ( !hasLoadingCollectionEntries() ) {
+ if ( !hasRegisteredLoadingCollectionEntries() ) {
return;
}
xrefLoadingCollectionEntries.remove(key);
16 years, 8 months
Hibernate SVN: r13935 - in sandbox/trunk/jdbc-proxy/src: main/java/org/hibernate/jdbc/batch and 11 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-18 09:48:50 -0400 (Sat, 18 Aug 2007)
New Revision: 13935
Added:
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/
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/CallableStatementDelegate.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/DelegateJDBCContainer.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/ResultSetWrapperImplementor.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/StatementWrapperImplementor.java
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/AggressiveReleaseTest.java
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java
sandbox/trunk/jdbc-proxy/src/test/perf/
sandbox/trunk/jdbc-proxy/src/test/perf/org/
sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/
sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/
sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/Data.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
Removed:
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetWrapperImplementor.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/StatementWrapperImplementor.java
Modified:
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchBuilder.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/ProxyJDBCContainer.java
sandbox/trunk/jdbc-proxy/src/test/resources/log4j.properties
Log:
moved delegation PoC code here for the purpose of combined performance testing
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchBuilder.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchBuilder.java 2007-08-18 08:34:26 UTC (rev 13934)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchBuilder.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -28,7 +28,7 @@
public class BatchBuilder {
private static final Logger log = LoggerFactory.getLogger( BatchBuilder.class );
- // todo : eventually have this take the Settings; this form is needed for testing because Settings is final :(
+ // todo : eventually have this take the Settings; this form is needed for testing because Settings is currently final :(
private int size;
Added: 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 (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
+import org.hibernate.jdbc.impl.StatementWrapperImplementor;
+
+/**
+ * AbstractStatementDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractStatementDelegate implements Statement, StatementWrapperImplementor {
+ private static final Logger log = LoggerFactory.getLogger( AbstractStatementDelegate.class );
+
+ private ConnectionDelegate connectionDelegate;
+ private Statement statement;
+ private boolean valid = true;
+ private final int hashCode;
+
+ private ResultSet currentResultSetDelegate;
+
+ public AbstractStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement) {
+ this.connectionDelegate = connectionDelegate;
+ this.statement = statement;
+ this.hashCode = statement.hashCode();
+ getJdbcContainer().register( this );
+ }
+
+ protected void errorIfInvalid() {
+ if ( !valid ) {
+ throw new HibernateException( "statement handle is invalid" );
+ }
+ }
+
+ protected JDBCServices getJdbcServices() {
+ errorIfInvalid();
+ return connectionDelegate.getJdbcServices();
+ }
+
+ protected JDBCContainer getJdbcContainer() {
+ errorIfInvalid();
+ return connectionDelegate.getJdbcContainer();
+ }
+
+ protected Statement getWrappedStatementWithoutChecks() {
+ return statement;
+ }
+
+ public Statement getWrappedStatement() {
+ errorIfInvalid();
+ return statement;
+ }
+
+ public void invalidate() {
+ connectionDelegate = null;
+ statement = null;
+ valid = false;
+ }
+
+ public String toString() {
+ return super.toString() + "[valid=" + valid + "]";
+ }
+
+ public int hashCode() {
+ return hashCode;
+ }
+
+
+ // special Statement methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public Connection getConnection() throws SQLException {
+ errorIfInvalid();
+ return connectionDelegate;
+ }
+
+ public void close() throws SQLException {
+ if ( valid ) {
+ LogicalConnectionImplementor lc = connectionDelegate.getLogicalConnection();
+ getJdbcContainer().release( this );
+ lc.afterStatementExecution();
+ }
+ }
+
+ // execution-related methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public ResultSet getGeneratedKeys() throws SQLException {
+ return new ResultSetDelegate( this, getWrappedStatement().getGeneratedKeys() );
+ }
+
+ public ResultSet getResultSet() throws SQLException {
+ currentResultSetDelegate = new ResultSetDelegate( this, getWrappedStatement().getResultSet() );
+ return currentResultSetDelegate;
+ }
+
+ public int getUpdateCount() throws SQLException {
+ return getWrappedStatement().getUpdateCount();
+ }
+
+ public boolean getMoreResults() throws SQLException {
+ return getMoreResults( Statement.CLOSE_CURRENT_RESULT );
+ }
+
+ public boolean getMoreResults(int current) throws SQLException {
+ if ( current == Statement.CLOSE_ALL_RESULTS ) {
+ log.warn( "getMoreResults call requested all previous results be closed, but thats not possible here" );
+ current = Statement.CLOSE_CURRENT_RESULT;
+ }
+ if ( current == Statement.CLOSE_CURRENT_RESULT && currentResultSetDelegate != null ) {
+ getJdbcContainer().release( currentResultSetDelegate );
+ }
+ currentResultSetDelegate = null;
+ return getWrappedStatement().getMoreResults( current );
+ }
+
+ public void cancel() throws SQLException {
+ getWrappedStatement().cancel();
+ }
+
+ public void clearBatch() throws SQLException {
+ getWrappedStatement().clearBatch();
+ }
+
+ public int[] executeBatch() throws SQLException {
+ return getWrappedStatement().executeBatch();
+ }
+
+
+ // general Statement methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public int getMaxFieldSize() throws SQLException {
+ return getWrappedStatement().getMaxFieldSize();
+ }
+
+ public void setMaxFieldSize(int max) throws SQLException {
+ getWrappedStatement().setMaxFieldSize( max );
+ }
+
+ public int getMaxRows() throws SQLException {
+ return getWrappedStatement().getMaxRows();
+ }
+
+ public void setMaxRows(int max) throws SQLException {
+ getWrappedStatement().setMaxRows( max );
+ }
+
+ public void setEscapeProcessing(boolean enable) throws SQLException {
+ getWrappedStatement().setEscapeProcessing( enable );
+ }
+
+ public int getQueryTimeout() throws SQLException {
+ return getWrappedStatement().getQueryTimeout();
+ }
+
+ public void setQueryTimeout(int seconds) throws SQLException {
+ getWrappedStatement().setQueryTimeout( seconds );
+ }
+
+ public void setCursorName(String name) throws SQLException {
+ getWrappedStatement().setCursorName( name );
+ }
+
+ public void setFetchDirection(int direction) throws SQLException {
+ getWrappedStatement().setFetchDirection( direction );
+ }
+
+ public int getFetchDirection() throws SQLException {
+ return getWrappedStatement().getFetchDirection();
+ }
+
+ public void setFetchSize(int rows) throws SQLException {
+ getWrappedStatement().setFetchSize( rows );
+ }
+
+ public int getFetchSize() throws SQLException {
+ return getWrappedStatement().getFetchSize();
+ }
+
+ public int getResultSetConcurrency() throws SQLException {
+ return getWrappedStatement().getResultSetConcurrency();
+ }
+
+ public int getResultSetType() throws SQLException {
+ return getWrappedStatement().getResultSetType();
+ }
+
+ public int getResultSetHoldability() throws SQLException {
+ return getWrappedStatement().getResultSetHoldability();
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ return getWrappedStatement().getWarnings();
+ }
+
+ public void clearWarnings() throws SQLException {
+ getWrappedStatement().clearWarnings();
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.Statement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * BasicStatementDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicStatementDelegate extends AbstractStatementDelegate {
+ public BasicStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement) {
+ super( connectionDelegate, statement );
+ }
+
+ public void addBatch(String sql) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ getWrappedStatement().addBatch( sql );
+ }
+
+ public boolean execute(String sql) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().execute( sql );
+ }
+
+ public ResultSet executeQuery(String sql) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return new ResultSetDelegate( this, getWrappedStatement().executeQuery( sql ) );
+ }
+
+ public int executeUpdate(String sql) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().executeUpdate( sql );
+ }
+
+ public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().executeUpdate( sql, autoGeneratedKeys );
+ }
+
+ public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().executeUpdate( sql, columnIndexes );
+ }
+
+ public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().executeUpdate( sql, columnNames );
+ }
+
+ public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().execute( sql, autoGeneratedKeys );
+ }
+
+ public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().execute( sql, columnIndexes );
+ }
+
+ public boolean execute(String sql, String[] columnNames) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().execute( sql, columnNames );
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/CallableStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/CallableStatementDelegate.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/CallableStatementDelegate.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,376 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.Ref;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Map;
+
+import org.hibernate.HibernateException;
+
+/**
+ * CallableStatementDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public class CallableStatementDelegate extends PreparedStatementDelegate implements CallableStatement {
+ public CallableStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement, String sql) {
+ super( connectionDelegate, statement, sql );
+ if ( ! ( statement instanceof CallableStatement ) ) {
+ throw new HibernateException( "iilegal argument: statement should be PreparedStatement" );
+ }
+ }
+
+ protected CallableStatement getCallableStatement() {
+ return ( CallableStatement ) super.getWrappedStatement();
+ }
+
+
+ // CallableStatement impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
+ getCallableStatement().registerOutParameter( parameterIndex, sqlType );
+ }
+
+ public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
+ getCallableStatement().registerOutParameter( parameterIndex, sqlType, scale );
+ }
+
+ public void registerOutParameter(int paramIndex, int sqlType, String typeName) throws SQLException {
+ getCallableStatement().registerOutParameter( paramIndex, sqlType, typeName );
+ }
+
+ public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
+ getCallableStatement().registerOutParameter( parameterName, sqlType );
+ }
+
+ public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
+ getCallableStatement().registerOutParameter( parameterName, sqlType, scale );
+ }
+
+ public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
+ getCallableStatement().registerOutParameter( parameterName, sqlType, typeName );
+ }
+
+
+ public boolean wasNull() throws SQLException {
+ return getCallableStatement().wasNull();
+ }
+
+ public void setNull(String parameterName, int sqlType) throws SQLException {
+ getCallableStatement().setNull( parameterName, sqlType );
+ }
+
+ public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
+ getCallableStatement().setNull( parameterName, sqlType, typeName );
+ }
+
+ public Object getObject(int parameterIndex) throws SQLException {
+ return getCallableStatement().getObject( parameterIndex );
+ }
+
+ public Object getObject(int i, Map<String, Class<?>> map) throws SQLException {
+ return getCallableStatement().getObject( i, map );
+ }
+
+ public Object getObject(String parameterName) throws SQLException {
+ return getCallableStatement().getObject( parameterName );
+ }
+
+ public Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException {
+ return getCallableStatement().getObject( parameterName, map );
+ }
+
+ public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {
+ getCallableStatement().setObject( parameterName, x, targetSqlType, scale );
+ }
+
+ public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
+ getCallableStatement().setObject( parameterName, x, targetSqlType );
+ }
+
+ public void setObject(String parameterName, Object x) throws SQLException {
+ getCallableStatement().setObject( parameterName, x );
+ }
+
+ public String getString(int parameterIndex) throws SQLException {
+ return getCallableStatement().getString( parameterIndex );
+ }
+
+ public String getString(String parameterName) throws SQLException {
+ return getCallableStatement().getString( parameterName );
+ }
+
+ public void setString(String parameterName, String x) throws SQLException {
+ getCallableStatement().setString( parameterName, x );
+ }
+
+ public boolean getBoolean(int parameterIndex) throws SQLException {
+ return getCallableStatement().getBoolean( parameterIndex );
+ }
+
+ public boolean getBoolean(String parameterName) throws SQLException {
+ return getCallableStatement().getBoolean( parameterName );
+ }
+
+ public void setBoolean(String parameterName, boolean x) throws SQLException {
+ getCallableStatement().setBoolean( parameterName, x );
+ }
+
+ public byte getByte(int parameterIndex) throws SQLException {
+ return getCallableStatement().getByte( parameterIndex );
+ }
+
+ public byte getByte(String parameterName) throws SQLException {
+ return getCallableStatement().getByte( parameterName );
+ }
+
+ public void setByte(String parameterName, byte x) throws SQLException {
+ getCallableStatement().setByte( parameterName, x );
+ }
+
+ public short getShort(int parameterIndex) throws SQLException {
+ return getCallableStatement().getShort( parameterIndex );
+ }
+
+ public short getShort(String parameterName) throws SQLException {
+ return getCallableStatement().getShort( parameterName );
+ }
+
+ public void setShort(String parameterName, short x) throws SQLException {
+ getCallableStatement().setShort( parameterName, x );
+ }
+
+ public int getInt(int parameterIndex) throws SQLException {
+ return getCallableStatement().getInt( parameterIndex );
+ }
+
+ public int getInt(String parameterName) throws SQLException {
+ return getCallableStatement().getInt( parameterName );
+ }
+
+ public void setInt(String parameterName, int x) throws SQLException {
+ getCallableStatement().setInt( parameterName, x );
+ }
+
+ public long getLong(int parameterIndex) throws SQLException {
+ return getCallableStatement().getLong( parameterIndex );
+ }
+
+ public long getLong(String parameterName) throws SQLException {
+ return getCallableStatement().getLong( parameterName );
+ }
+
+ public void setLong(String parameterName, long x) throws SQLException {
+ getCallableStatement().setLong( parameterName, x );
+ }
+
+ public float getFloat(int parameterIndex) throws SQLException {
+ return getCallableStatement().getFloat( parameterIndex );
+ }
+
+ public float getFloat(String parameterName) throws SQLException {
+ return getCallableStatement().getFloat( parameterName );
+ }
+
+ public void setFloat(String parameterName, float x) throws SQLException {
+ getCallableStatement().setFloat( parameterName, x );
+ }
+
+ public double getDouble(int parameterIndex) throws SQLException {
+ return getCallableStatement().getDouble( parameterIndex );
+ }
+
+ public double getDouble(String parameterName) throws SQLException {
+ return getCallableStatement().getDouble( parameterName );
+ }
+
+ public void setDouble(String parameterName, double x) throws SQLException {
+ getCallableStatement().setDouble( parameterName, x );
+ }
+
+ public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
+ return getCallableStatement().getBigDecimal( parameterIndex );
+ }
+
+ @Deprecated
+ public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
+ return getCallableStatement().getBigDecimal( parameterIndex, scale );
+ }
+
+ public BigDecimal getBigDecimal(String parameterName) throws SQLException {
+ return getCallableStatement().getBigDecimal( parameterName );
+ }
+
+ public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
+ getCallableStatement().setBigDecimal( parameterName, x );
+ }
+
+ public byte[] getBytes(int parameterIndex) throws SQLException {
+ return getCallableStatement().getBytes( parameterIndex );
+ }
+
+ public byte[] getBytes(String parameterName) throws SQLException {
+ return getCallableStatement().getBytes( parameterName );
+ }
+
+ public void setBytes(String parameterName, byte[] x) throws SQLException {
+ getCallableStatement().setBytes( parameterName, x );
+ }
+
+ public Date getDate(int parameterIndex) throws SQLException {
+ return getCallableStatement().getDate( parameterIndex );
+ }
+
+ public Date getDate(String parameterName) throws SQLException {
+ return getCallableStatement().getDate( parameterName );
+ }
+
+ public Date getDate(String parameterName, Calendar cal) throws SQLException {
+ return getCallableStatement().getDate( parameterName, cal );
+ }
+
+ public void setDate(String parameterName, Date x) throws SQLException {
+ getCallableStatement().setDate( parameterName, x );
+ }
+
+ public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
+ getCallableStatement().setDate( parameterName, x, cal );
+ }
+
+ public Time getTime(int parameterIndex) throws SQLException {
+ return getCallableStatement().getTime( parameterIndex );
+ }
+
+ public Timestamp getTimestamp(int parameterIndex) throws SQLException {
+ return getCallableStatement().getTimestamp( parameterIndex );
+ }
+
+ public Ref getRef(int i) throws SQLException {
+ return getCallableStatement().getRef( i );
+ }
+
+ public Ref getRef(String parameterName) throws SQLException {
+ return getCallableStatement().getRef( parameterName );
+ }
+
+ public Blob getBlob(int i) throws SQLException {
+ return getCallableStatement().getBlob( i );
+ }
+
+ public Blob getBlob(String parameterName) throws SQLException {
+ return getCallableStatement().getBlob( parameterName );
+ }
+
+ public Clob getClob(int i) throws SQLException {
+ return getCallableStatement().getClob( i );
+ }
+
+ public Clob getClob(String parameterName) throws SQLException {
+ return getCallableStatement().getClob( parameterName );
+ }
+
+ public Array getArray(int i) throws SQLException {
+ return getCallableStatement().getArray( i );
+ }
+
+ public Array getArray(String parameterName) throws SQLException {
+ return getCallableStatement().getArray( parameterName );
+ }
+
+ public Date getDate(int parameterIndex, Calendar cal) throws SQLException {
+ return getCallableStatement().getDate( parameterIndex, cal );
+ }
+
+ public Time getTime(int parameterIndex, Calendar cal) throws SQLException {
+ return getCallableStatement().getTime( parameterIndex, cal );
+ }
+
+ public Time getTime(String parameterName) throws SQLException {
+ return getCallableStatement().getTime( parameterName );
+ }
+
+ public Time getTime(String parameterName, Calendar cal) throws SQLException {
+ return getCallableStatement().getTime( parameterName, cal );
+ }
+
+ public void setTime(String parameterName, Time x) throws SQLException {
+ getCallableStatement().setTime( parameterName, x );
+ }
+
+ public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
+ getCallableStatement().setTime( parameterName, x, cal );
+ }
+
+ public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {
+ return getCallableStatement().getTimestamp( parameterIndex, cal );
+ }
+
+ public Timestamp getTimestamp(String parameterName) throws SQLException {
+ return getCallableStatement().getTimestamp( parameterName );
+ }
+
+ public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
+ return getCallableStatement().getTimestamp( parameterName, cal );
+ }
+
+ public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
+ getCallableStatement().setTimestamp( parameterName, x );
+ }
+
+ public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
+ getCallableStatement().setTimestamp( parameterName, x, cal );
+ }
+
+ public URL getURL(int parameterIndex) throws SQLException {
+ return getCallableStatement().getURL( parameterIndex );
+ }
+
+ public URL getURL(String parameterName) throws SQLException {
+ return getCallableStatement().getURL( parameterName );
+ }
+
+ public void setURL(String parameterName, URL val) throws SQLException {
+ getCallableStatement().setURL( parameterName, val );
+ }
+
+ public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
+ getCallableStatement().setAsciiStream( parameterName, x, length );
+ }
+
+ public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
+ getCallableStatement().setBinaryStream( parameterName, x, length );
+ }
+
+ public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
+ getCallableStatement().setCharacterStream( parameterName, reader, length );
+ }
+
+
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,383 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.jdbc.impl.ConnectionObserver;
+import org.hibernate.jdbc.ConnectionWrapper;
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
+import org.hibernate.HibernateException;
+
+/**
+ * Connection implementation which delegates to the current connection as defined
+ * by its logical connection.
+ *
+ * @author Steve Ebersole
+ */
+public class ConnectionDelegate implements Connection, ConnectionWrapper, ConnectionObserver {
+ private static final Logger log = LoggerFactory.getLogger( ConnectionDelegate.class );
+
+ private LogicalConnectionImplementor logicalConnection;
+ private boolean valid = true;
+ private final int hashCode;
+
+ /**
+ * Builds a connection delegate with the given logical connection.
+ *
+ * @param logicalConnection The logical connection handling this
+ * connection delegate's access to physical connections.
+ */
+ public ConnectionDelegate(LogicalConnectionImplementor logicalConnection) {
+ this.logicalConnection = logicalConnection;
+ logicalConnection.addObserver( this );
+ this.hashCode = this.logicalConnection.hashCode();
+ }
+
+ /**
+ * Access to our logical connection.
+ *
+ * @return the logical connection
+ */
+ protected LogicalConnectionImplementor getLogicalConnection() {
+ errorIfInvalid();
+ return logicalConnection;
+ }
+
+ private void errorIfInvalid() {
+ if ( !valid ) {
+ throw new HibernateException( "connection handle is invalid" );
+ }
+ }
+
+ /**
+ * Provide access to JDBCServices.
+ * <p/>
+ * NOTE : package-protected
+ *
+ * @return JDBCServices
+ */
+ JDBCServices getJdbcServices() {
+ return logicalConnection.getJdbcServices();
+ }
+
+ /**
+ * Provide access to JDBCContainer.
+ * <p/>
+ * NOTE : package-protected
+ *
+ * @return JDBCContainer
+ */
+ JDBCContainer getJdbcContainer() {
+ return logicalConnection.getJdbcContainer();
+ }
+
+ public Connection getWrappedConnection() {
+ if ( !valid ) {
+ throw new HibernateException( "connection handle is invalid" );
+ }
+ return logicalConnection.getConnection();
+ }
+
+ protected Connection getWrappedConnectionWithoutChecks() {
+ return logicalConnection.getConnection();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void physicalConnectionObtained(Connection connection) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void physicalConnectionReleased() {
+ log.info( "logical connection releasing its physical connection");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void logicalConnectionClosed() {
+ log.info( "*** logical connection closed ***" );
+ invalidateDelegate();
+ }
+
+ private void invalidateDelegate() {
+ log.trace( "Invalidating connection delegate" );
+ logicalConnection = null;
+ valid = false;
+ }
+
+ public String toString() {
+ return super.toString() + "[valid=" + valid + "]";
+ }
+
+ public int hashCode() {
+ return hashCode;
+ }
+
+
+ // statement-creation methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public Statement createStatement() {
+ try {
+ Statement statement = getWrappedConnection().createStatement();
+ return new BasicStatementDelegate( this, statement );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to create basic statement" );
+ }
+ }
+
+ public Statement createStatement(int resultSetType, int resultSetConcurrency) {
+ try {
+ Statement statement = getWrappedConnection().createStatement( resultSetType, resultSetConcurrency );
+ return new BasicStatementDelegate( this, statement );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to create basic statement" );
+ }
+ }
+
+ public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) {
+ try {
+ Statement statement = getWrappedConnection()
+ .createStatement( resultSetType, resultSetConcurrency, resultSetHoldability );
+ return new BasicStatementDelegate( this, statement );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to create basic statement" );
+ }
+ }
+
+ public PreparedStatement prepareStatement(String sql) {
+ try {
+ PreparedStatement statement = getWrappedConnection().prepareStatement( sql );
+ return new PreparedStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+ }
+ }
+
+ public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) {
+ try {
+ PreparedStatement statement = getWrappedConnection()
+ .prepareStatement( sql, resultSetType, resultSetConcurrency );
+ return new PreparedStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+ }
+ }
+
+ public PreparedStatement prepareStatement(
+ String sql,
+ int resultSetType,
+ int resultSetConcurrency,
+ int resultSetHoldability) {
+ try {
+ PreparedStatement statement = getWrappedConnection()
+ .prepareStatement( sql, resultSetType, resultSetConcurrency, resultSetHoldability );
+ return new PreparedStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+ }
+ }
+
+ public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) {
+ try {
+ PreparedStatement statement = getWrappedConnection().prepareStatement( sql, autoGeneratedKeys );
+ return new PreparedStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+ }
+ }
+
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes) {
+ try {
+ PreparedStatement statement = getWrappedConnection().prepareStatement( sql, columnIndexes );
+ return new PreparedStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+ }
+ }
+
+ public PreparedStatement prepareStatement(String sql, String[] columnNames) {
+ try {
+ PreparedStatement statement = getWrappedConnection().prepareStatement( sql, columnNames );
+ return new PreparedStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+ }
+ }
+
+ public CallableStatement prepareCall(String sql) {
+ try {
+ CallableStatement statement = getWrappedConnection().prepareCall( sql );
+ return new CallableStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare call", sql );
+ }
+ }
+
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) {
+ try {
+ CallableStatement statement = getWrappedConnection()
+ .prepareCall( sql, resultSetType, resultSetConcurrency );
+ return new CallableStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare call", sql );
+ }
+ }
+
+ public CallableStatement prepareCall(
+ String sql,
+ int resultSetType,
+ int resultSetConcurrency,
+ int resultSetHoldability) {
+ try {
+ CallableStatement statement = getWrappedConnection()
+ .prepareCall( sql, resultSetType, resultSetConcurrency, resultSetHoldability );
+ return new CallableStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare call", sql );
+ }
+ }
+
+
+ // other Connection methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public void close() {
+ if ( valid ) {
+ invalidateDelegate();
+ }
+ }
+
+ public boolean isClosed() {
+ return !valid;
+ }
+
+ public void setAutoCommit(boolean autoCommit) throws SQLException {
+ getWrappedConnection().setAutoCommit( autoCommit );
+ }
+
+ public boolean getAutoCommit() throws SQLException {
+ return getWrappedConnection().getAutoCommit();
+ }
+
+ public void commit() throws SQLException {
+ getWrappedConnection().commit();
+ }
+
+ public void rollback() throws SQLException {
+ getWrappedConnection().rollback();
+ }
+
+ public DatabaseMetaData getMetaData() throws SQLException {
+ return getWrappedConnection().getMetaData();
+ }
+
+ public String nativeSQL(String sql) throws SQLException {
+ return getWrappedConnection().nativeSQL( sql );
+ }
+
+ public void setReadOnly(boolean readOnly) throws SQLException {
+ getWrappedConnection().setReadOnly( readOnly );
+ }
+
+ public boolean isReadOnly() throws SQLException {
+ return getWrappedConnection().isReadOnly();
+ }
+
+ public void setCatalog(String catalog) throws SQLException {
+ getWrappedConnection().setCatalog( catalog );
+ }
+
+ public String getCatalog() throws SQLException {
+ return getWrappedConnection().getCatalog();
+ }
+
+ public void setTransactionIsolation(int level) throws SQLException {
+ getWrappedConnection().setTransactionIsolation( level );
+ }
+
+ public int getTransactionIsolation() throws SQLException {
+ return getWrappedConnection().getTransactionIsolation();
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ return getWrappedConnection().getWarnings();
+ }
+
+ public void clearWarnings() throws SQLException {
+ getWrappedConnection().clearWarnings();
+ }
+
+ public Map<String, Class<?>> getTypeMap() throws SQLException {
+ return getWrappedConnection().getTypeMap();
+ }
+
+ public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
+ getWrappedConnection().setTypeMap( map );
+ }
+
+ public void setHoldability(int holdability) throws SQLException {
+ getWrappedConnection().setHoldability( holdability );
+ }
+
+ public int getHoldability() throws SQLException {
+ return getWrappedConnection().getHoldability();
+ }
+
+ public Savepoint setSavepoint() throws SQLException {
+ return getWrappedConnection().setSavepoint();
+ }
+
+ public Savepoint setSavepoint(String name) throws SQLException {
+ return getWrappedConnection().setSavepoint( name );
+ }
+
+ public void rollback(Savepoint savepoint) throws SQLException {
+ getWrappedConnection().rollback( savepoint );
+ }
+
+ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+ getWrappedConnection().releaseSavepoint( savepoint );
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.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 );
+ }
+ }
+}
Added: 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 (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Ref;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Array;
+import java.sql.ResultSetMetaData;
+import java.sql.ParameterMetaData;
+import java.math.BigDecimal;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Calendar;
+import java.net.URL;
+
+import org.hibernate.HibernateException;
+
+/**
+ * PreparedStatementDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public class PreparedStatementDelegate extends AbstractStatementDelegate implements PreparedStatement {
+ private String sql;
+
+ public PreparedStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement, String sql) {
+ super( connectionDelegate, statement );
+ if ( ! ( statement instanceof PreparedStatement ) ) {
+ throw new HibernateException( "iilegal argument: statement should be PreparedStatement" );
+ }
+ this.sql = sql;
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ }
+
+ private PreparedStatement getPreparedStatement() {
+ return ( PreparedStatement ) super.getWrappedStatement();
+ }
+
+
+ // PreparedStatement impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public void addBatch() throws SQLException {
+ getPreparedStatement().addBatch();
+ }
+
+ public boolean execute() throws SQLException {
+ return getPreparedStatement().execute();
+ }
+
+ public ResultSet executeQuery() throws SQLException {
+ return new ResultSetDelegate( this, getPreparedStatement().executeQuery() );
+ }
+
+ public int executeUpdate() throws SQLException {
+ return getPreparedStatement().executeUpdate();
+ }
+
+ public ResultSetMetaData getMetaData() throws SQLException {
+ return getPreparedStatement().getMetaData();
+ }
+
+ public ParameterMetaData getParameterMetaData() throws SQLException {
+ return getPreparedStatement().getParameterMetaData();
+ }
+
+ public void clearParameters() throws SQLException {
+ getPreparedStatement().clearParameters();
+ }
+
+ public void setNull(int parameterIndex, int sqlType) throws SQLException {
+ getPreparedStatement().setNull( parameterIndex, sqlType );
+ }
+
+ public void setBoolean(int parameterIndex, boolean x) throws SQLException {
+ getPreparedStatement().setBoolean( parameterIndex, x );
+ }
+
+ public void setByte(int parameterIndex, byte x) throws SQLException {
+ getPreparedStatement().setByte( parameterIndex, x );
+ }
+
+ public void setShort(int parameterIndex, short x) throws SQLException {
+ getPreparedStatement().setShort( parameterIndex, x );
+ }
+
+ public void setInt(int parameterIndex, int x) throws SQLException {
+ getPreparedStatement().setInt( parameterIndex, x );
+ }
+
+ public void setLong(int parameterIndex, long x) throws SQLException {
+ getPreparedStatement().setLong( parameterIndex, x );
+ }
+
+ public void setFloat(int parameterIndex, float x) throws SQLException {
+ getPreparedStatement().setFloat( parameterIndex, x );
+ }
+
+ public void setDouble(int parameterIndex, double x) throws SQLException {
+ getPreparedStatement().setDouble( parameterIndex, x );
+ }
+
+ public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
+ getPreparedStatement().setBigDecimal( parameterIndex, x );
+ }
+
+ public void setString(int parameterIndex, String x) throws SQLException {
+ getPreparedStatement().setString( parameterIndex, x );
+ }
+
+ public void setBytes(int parameterIndex, byte[] x) throws SQLException {
+ getPreparedStatement().setBytes( parameterIndex, x );
+ }
+
+ public void setDate(int parameterIndex, Date x) throws SQLException {
+ getPreparedStatement().setDate( parameterIndex, x );
+ }
+
+ public void setTime(int parameterIndex, Time x) throws SQLException {
+ getPreparedStatement().setTime( parameterIndex, x );
+ }
+
+ public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
+ getPreparedStatement().setTimestamp( parameterIndex, x );
+ }
+
+ public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
+ getPreparedStatement().setAsciiStream( parameterIndex, x, length );
+ }
+
+ @Deprecated
+ public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
+ getPreparedStatement().setUnicodeStream( parameterIndex, x, length );
+ }
+
+ public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
+ getPreparedStatement().setBinaryStream( parameterIndex, x, length );
+ }
+
+ public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException {
+ getPreparedStatement().setObject( parameterIndex, x, targetSqlType, scale );
+ }
+
+ public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
+ getPreparedStatement().setObject( parameterIndex, x, targetSqlType );
+ }
+
+ public void setObject(int parameterIndex, Object x) throws SQLException {
+ getPreparedStatement().setObject( parameterIndex, x );
+ }
+
+ public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
+ getPreparedStatement().setCharacterStream( parameterIndex, reader, length );
+ }
+
+ public void setRef(int parameterIndex, Ref x) throws SQLException {
+ getPreparedStatement().setRef( parameterIndex, x );
+ }
+
+ public void setBlob(int parameterIndex, Blob x) throws SQLException {
+ getPreparedStatement().setBlob( parameterIndex, x );
+ }
+
+ public void setClob(int parameterIndex, Clob x) throws SQLException {
+ getPreparedStatement().setClob( parameterIndex, x );
+ }
+
+ public void setArray(int parameterIndex, Array x) throws SQLException {
+ getPreparedStatement().setArray( parameterIndex, x );
+ }
+
+ public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
+ getPreparedStatement().setDate( parameterIndex, x, cal );
+ }
+
+ public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
+ getPreparedStatement().setTime( parameterIndex, x, cal );
+ }
+
+ public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
+ getPreparedStatement().setTimestamp( parameterIndex, x, cal );
+ }
+
+ public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
+ getPreparedStatement().setNull( parameterIndex, sqlType, typeName );
+ }
+
+ public void setURL(int parameterIndex, URL x) throws SQLException {
+ getPreparedStatement().setURL( parameterIndex, x );
+ }
+
+
+ // Statement methods not really valid on PreparedStatements ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public boolean execute(String sql) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public ResultSet executeQuery(String sql) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public int executeUpdate(String sql) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public boolean execute(String sql, String[] columnNames) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public void addBatch(String sql) throws SQLException {
+ throw new HibernateException( "This form of addBatch not allowed here" );
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,666 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.SQLWarning;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
+import java.sql.Ref;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Array;
+import java.math.BigDecimal;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Map;
+import java.util.Calendar;
+import java.net.URL;
+
+import org.hibernate.HibernateException;
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.impl.ResultSetWrapperImplementor;
+
+/**
+ * ResultSetDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ResultSetDelegate implements ResultSet, ResultSetWrapperImplementor {
+
+ private AbstractStatementDelegate statementDelegate;
+ private ResultSet resultSet;
+ private boolean valid = true;
+ private final int hashCode;
+
+ public ResultSetDelegate(AbstractStatementDelegate statementDelegate, ResultSet resultSet) {
+ this.statementDelegate = statementDelegate;
+ this.resultSet = resultSet;
+ this.hashCode = resultSet.hashCode();
+ statementDelegate.getJdbcContainer().register( this );
+ }
+
+ protected JDBCServices getJdbcServices() {
+ return statementDelegate.getJdbcServices();
+ }
+
+ protected JDBCContainer getJdbcContainer() {
+ return statementDelegate.getJdbcContainer();
+ }
+
+ public ResultSet getWrappedResultSetWithoutChecks() {
+ return resultSet;
+ }
+
+ public ResultSet getWrappedResultSet() {
+ if ( !valid ) {
+ throw new HibernateException( "resultset handle is invalid" );
+ }
+ return resultSet;
+ }
+
+ public void invalidate() {
+ statementDelegate = null;
+ resultSet = null;
+ valid = false;
+ }
+
+ public String toString() {
+ return super.toString() + "[valid=" + valid + "]";
+ }
+
+ public int hashCode() {
+ return hashCode;
+ }
+
+
+ // special ResultSet methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public Statement getStatement() throws SQLException {
+ return statementDelegate;
+ }
+
+ public void close() throws SQLException {
+ if ( valid ) {
+ getJdbcContainer().release( this );
+ }
+ }
+
+
+ // Navigational ResultSet methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public boolean next() throws SQLException {
+ return getWrappedResultSet().next();
+ }
+
+ public boolean isBeforeFirst() throws SQLException {
+ return getWrappedResultSet().isBeforeFirst();
+ }
+
+ public boolean isAfterLast() throws SQLException {
+ return getWrappedResultSet().isAfterLast();
+ }
+
+ public boolean isFirst() throws SQLException {
+ return getWrappedResultSet().isFirst();
+ }
+
+ public boolean isLast() throws SQLException {
+ return getWrappedResultSet().isLast();
+ }
+
+ public void beforeFirst() throws SQLException {
+ getWrappedResultSet().beforeFirst();
+ }
+
+ public void afterLast() throws SQLException {
+ getWrappedResultSet().afterLast();
+ }
+
+ public boolean first() throws SQLException {
+ return getWrappedResultSet().first();
+ }
+
+ public boolean last() throws SQLException {
+ return getWrappedResultSet().last();
+ }
+
+ public int getRow() throws SQLException {
+ return getWrappedResultSet().getRow();
+ }
+
+ public boolean absolute(int row) throws SQLException {
+ return getWrappedResultSet().absolute( row );
+ }
+
+ public boolean relative(int rows) throws SQLException {
+ return getWrappedResultSet().relative( rows );
+ }
+
+ public boolean previous() throws SQLException {
+ return getWrappedResultSet().previous();
+ }
+
+
+ // informational ResultSet methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public String getCursorName() throws SQLException {
+ return getWrappedResultSet().getCursorName();
+ }
+
+ public ResultSetMetaData getMetaData() throws SQLException {
+ return getWrappedResultSet().getMetaData();
+ }
+
+ public void setFetchDirection(int direction) throws SQLException {
+ getWrappedResultSet().setFetchDirection( direction );
+ }
+
+ public int getFetchDirection() throws SQLException {
+ return getWrappedResultSet().getFetchDirection();
+ }
+
+ public void setFetchSize(int rows) throws SQLException {
+ getWrappedResultSet().setFetchSize( rows );
+ }
+
+ public int getFetchSize() throws SQLException {
+ return getWrappedResultSet().getFetchSize();
+ }
+
+ public int getType() throws SQLException {
+ return getWrappedResultSet().getType();
+ }
+
+ public int getConcurrency() throws SQLException {
+ return getWrappedResultSet().getConcurrency();
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ return getWrappedResultSet().getWarnings();
+ }
+
+ public void clearWarnings() throws SQLException {
+ getWrappedResultSet().clearWarnings();
+ }
+
+
+ // value accessors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public boolean wasNull() throws SQLException {
+ return getWrappedResultSet().wasNull();
+ }
+
+ public String getString(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getString( columnIndex );
+ }
+
+ public boolean getBoolean(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getBoolean( columnIndex );
+ }
+
+ public byte getByte(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getByte( columnIndex );
+ }
+
+ public short getShort(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getShort( columnIndex );
+ }
+
+ public int getInt(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getInt( columnIndex );
+ }
+
+ public long getLong(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getLong( columnIndex );
+ }
+
+ public float getFloat(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getFloat( columnIndex );
+ }
+
+ public double getDouble(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getDouble( columnIndex );
+ }
+
+ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+ return getWrappedResultSet().getBigDecimal( columnIndex, scale );
+ }
+
+ public byte[] getBytes(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getBytes( columnIndex );
+ }
+
+ public Date getDate(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getDate( columnIndex );
+ }
+
+ public Time getTime(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getTime( columnIndex );
+ }
+
+ public Timestamp getTimestamp(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getTimestamp( columnIndex );
+ }
+
+ public InputStream getAsciiStream(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getAsciiStream( columnIndex );
+ }
+
+ public InputStream getUnicodeStream(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getUnicodeStream( columnIndex );
+ }
+
+ public InputStream getBinaryStream(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getBinaryStream( columnIndex );
+ }
+
+ public String getString(String columnName) throws SQLException {
+ return getWrappedResultSet().getString( columnName );
+ }
+
+ public boolean getBoolean(String columnName) throws SQLException {
+ return getWrappedResultSet().getBoolean( columnName );
+ }
+
+ public byte getByte(String columnName) throws SQLException {
+ return getWrappedResultSet().getByte( columnName );
+ }
+
+ public short getShort(String columnName) throws SQLException {
+ return getWrappedResultSet().getShort( columnName );
+ }
+
+ public int getInt(String columnName) throws SQLException {
+ return getWrappedResultSet().getInt( columnName );
+ }
+
+ public long getLong(String columnName) throws SQLException {
+ return getWrappedResultSet().getLong( columnName );
+ }
+
+ public float getFloat(String columnName) throws SQLException {
+ return getWrappedResultSet().getFloat( columnName );
+ }
+
+ public double getDouble(String columnName) throws SQLException {
+ return getWrappedResultSet().getDouble( columnName );
+ }
+
+ public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
+ return getWrappedResultSet().getBigDecimal( columnName, scale );
+ }
+
+ public byte[] getBytes(String columnName) throws SQLException {
+ return getWrappedResultSet().getBytes( columnName );
+ }
+
+ public Date getDate(String columnName) throws SQLException {
+ return getWrappedResultSet().getDate( columnName );
+ }
+
+ public Time getTime(String columnName) throws SQLException {
+ return getWrappedResultSet().getTime( columnName );
+ }
+
+ public Timestamp getTimestamp(String columnName) throws SQLException {
+ return getWrappedResultSet().getTimestamp( columnName );
+ }
+
+ public InputStream getAsciiStream(String columnName) throws SQLException {
+ return getWrappedResultSet().getAsciiStream( columnName );
+ }
+
+ public InputStream getUnicodeStream(String columnName) throws SQLException {
+ return getWrappedResultSet().getUnicodeStream( columnName );
+ }
+
+ public InputStream getBinaryStream(String columnName) throws SQLException {
+ return getWrappedResultSet().getBinaryStream( columnName );
+ }
+
+ public Object getObject(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getObject( columnIndex );
+ }
+
+ public Object getObject(String columnName) throws SQLException {
+ return getWrappedResultSet().getObject( columnName );
+ }
+
+ public int findColumn(String columnName) throws SQLException {
+ return getWrappedResultSet().findColumn( columnName );
+ }
+
+ public Reader getCharacterStream(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getCharacterStream( columnIndex );
+ }
+
+ public Reader getCharacterStream(String columnName) throws SQLException {
+ return getWrappedResultSet().getCharacterStream( columnName );
+ }
+
+ public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getBigDecimal( columnIndex );
+ }
+
+ public BigDecimal getBigDecimal(String columnName) throws SQLException {
+ return getWrappedResultSet().getBigDecimal( columnName );
+ }
+
+ public Object getObject(int i, Map<String, Class<?>> map) throws SQLException {
+ return getWrappedResultSet().getObject( i, map );
+ }
+
+ public Ref getRef(int i) throws SQLException {
+ return getWrappedResultSet().getRef( i );
+ }
+
+ public Blob getBlob(int i) throws SQLException {
+ return getWrappedResultSet().getBlob( i );
+ }
+
+ public Clob getClob(int i) throws SQLException {
+ return getWrappedResultSet().getClob( i );
+ }
+
+ public Array getArray(int i) throws SQLException {
+ return getWrappedResultSet().getArray( i );
+ }
+
+ public Object getObject(String colName, Map<String, Class<?>> map) throws SQLException {
+ return getWrappedResultSet().getObject( colName, map );
+ }
+
+ public Ref getRef(String colName) throws SQLException {
+ return getWrappedResultSet().getRef( colName );
+ }
+
+ public Blob getBlob(String colName) throws SQLException {
+ return getWrappedResultSet().getBlob( colName );
+ }
+
+ public Clob getClob(String colName) throws SQLException {
+ return getWrappedResultSet().getClob( colName );
+ }
+
+ public Array getArray(String colName) throws SQLException {
+ return getWrappedResultSet().getArray( colName );
+ }
+
+ public Date getDate(int columnIndex, Calendar cal) throws SQLException {
+ return getWrappedResultSet().getDate( columnIndex, cal );
+ }
+
+ public Date getDate(String columnName, Calendar cal) throws SQLException {
+ return getWrappedResultSet().getDate( columnName, cal );
+ }
+
+ public Time getTime(int columnIndex, Calendar cal) throws SQLException {
+ return getWrappedResultSet().getTime( columnIndex, cal );
+ }
+
+ public Time getTime(String columnName, Calendar cal) throws SQLException {
+ return getWrappedResultSet().getTime( columnName, cal );
+ }
+
+ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
+ return getWrappedResultSet().getTimestamp( columnIndex, cal );
+ }
+
+ public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException {
+ return getWrappedResultSet().getTimestamp( columnName, cal );
+ }
+
+ public URL getURL(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getURL( columnIndex );
+ }
+
+ public URL getURL(String columnName) throws SQLException {
+ return getWrappedResultSet().getURL( columnName );
+ }
+
+
+ // ResultSet mutability ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public boolean rowUpdated() throws SQLException {
+ return getWrappedResultSet().rowUpdated();
+ }
+
+ public boolean rowInserted() throws SQLException {
+ return getWrappedResultSet().rowInserted();
+ }
+
+ public boolean rowDeleted() throws SQLException {
+ return getWrappedResultSet().rowDeleted();
+ }
+
+ public void updateNull(int columnIndex) throws SQLException {
+ getWrappedResultSet().updateNull( columnIndex );
+ }
+
+ public void updateBoolean(int columnIndex, boolean x) throws SQLException {
+ getWrappedResultSet().updateBoolean( columnIndex, x );
+ }
+
+ public void updateByte(int columnIndex, byte x) throws SQLException {
+ getWrappedResultSet().updateByte( columnIndex, x );
+ }
+
+ public void updateShort(int columnIndex, short x) throws SQLException {
+ getWrappedResultSet().updateShort( columnIndex, x );
+ }
+
+ public void updateInt(int columnIndex, int x) throws SQLException {
+ getWrappedResultSet().updateInt( columnIndex, x );
+ }
+
+ public void updateLong(int columnIndex, long x) throws SQLException {
+ getWrappedResultSet().updateLong( columnIndex, x );
+ }
+
+ public void updateFloat(int columnIndex, float x) throws SQLException {
+ getWrappedResultSet().updateFloat( columnIndex, x );
+ }
+
+ public void updateDouble(int columnIndex, double x) throws SQLException {
+ getWrappedResultSet().updateDouble( columnIndex, x );
+ }
+
+ public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
+ getWrappedResultSet().updateBigDecimal( columnIndex, x );
+ }
+
+ public void updateString(int columnIndex, String x) throws SQLException {
+ getWrappedResultSet().updateString( columnIndex, x );
+ }
+
+ public void updateBytes(int columnIndex, byte[] x) throws SQLException {
+ getWrappedResultSet().updateBytes( columnIndex, x );
+ }
+
+ public void updateDate(int columnIndex, Date x) throws SQLException {
+ getWrappedResultSet().updateDate( columnIndex, x );
+ }
+
+ public void updateTime(int columnIndex, Time x) throws SQLException {
+ getWrappedResultSet().updateTime( columnIndex, x );
+ }
+
+ public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
+ getWrappedResultSet().updateTimestamp( columnIndex, x );
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
+ getWrappedResultSet().updateAsciiStream( columnIndex, x, length );
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
+ getWrappedResultSet().updateBinaryStream( columnIndex, x, length );
+ }
+
+ public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
+ getWrappedResultSet().updateCharacterStream( columnIndex, x, length );
+ }
+
+ public void updateObject(int columnIndex, Object x, int scale) throws SQLException {
+ getWrappedResultSet().updateObject( columnIndex, x, scale );
+ }
+
+ public void updateObject(int columnIndex, Object x) throws SQLException {
+ getWrappedResultSet().updateObject( columnIndex, x );
+ }
+
+ public void updateNull(String columnName) throws SQLException {
+ getWrappedResultSet().updateNull( columnName );
+ }
+
+ public void updateBoolean(String columnName, boolean x) throws SQLException {
+ getWrappedResultSet().updateBoolean( columnName, x );
+ }
+
+ public void updateByte(String columnName, byte x) throws SQLException {
+ getWrappedResultSet().updateByte( columnName, x );
+ }
+
+ public void updateShort(String columnName, short x) throws SQLException {
+ getWrappedResultSet().updateShort( columnName, x );
+ }
+
+ public void updateInt(String columnName, int x) throws SQLException {
+ getWrappedResultSet().updateInt( columnName, x );
+ }
+
+ public void updateLong(String columnName, long x) throws SQLException {
+ getWrappedResultSet().updateLong( columnName, x );
+ }
+
+ public void updateFloat(String columnName, float x) throws SQLException {
+ getWrappedResultSet().updateFloat( columnName, x );
+ }
+
+ public void updateDouble(String columnName, double x) throws SQLException {
+ getWrappedResultSet().updateDouble( columnName, x );
+ }
+
+ public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException {
+ getWrappedResultSet().updateBigDecimal( columnName, x );
+ }
+
+ public void updateString(String columnName, String x) throws SQLException {
+ getWrappedResultSet().updateString( columnName, x );
+ }
+
+ public void updateBytes(String columnName, byte[] x) throws SQLException {
+ getWrappedResultSet().updateBytes( columnName, x );
+ }
+
+ public void updateDate(String columnName, Date x) throws SQLException {
+ getWrappedResultSet().updateDate( columnName, x );
+ }
+
+ public void updateTime(String columnName, Time x) throws SQLException {
+ getWrappedResultSet().updateTime( columnName, x );
+ }
+
+ public void updateTimestamp(String columnName, Timestamp x) throws SQLException {
+ getWrappedResultSet().updateTimestamp( columnName, x );
+ }
+
+ public void updateAsciiStream(String columnName, InputStream x, int length) throws SQLException {
+ getWrappedResultSet().updateAsciiStream( columnName, x, length );
+ }
+
+ public void updateBinaryStream(String columnName, InputStream x, int length) throws SQLException {
+ getWrappedResultSet().updateBinaryStream( columnName, x, length );
+ }
+
+ public void updateCharacterStream(String columnName, Reader reader, int length) throws SQLException {
+ getWrappedResultSet().updateCharacterStream( columnName, reader, length );
+ }
+
+ public void updateObject(String columnName, Object x, int scale) throws SQLException {
+ getWrappedResultSet().updateObject( columnName, x, scale );
+ }
+
+ public void updateObject(String columnName, Object x) throws SQLException {
+ getWrappedResultSet().updateObject( columnName, x );
+ }
+
+ public void insertRow() throws SQLException {
+ getWrappedResultSet().insertRow();
+ }
+
+ public void updateRow() throws SQLException {
+ getWrappedResultSet().updateRow();
+ }
+
+ public void deleteRow() throws SQLException {
+ getWrappedResultSet().deleteRow();
+ }
+
+ public void refreshRow() throws SQLException {
+ getWrappedResultSet().refreshRow();
+ }
+
+ public void cancelRowUpdates() throws SQLException {
+ getWrappedResultSet().cancelRowUpdates();
+ }
+
+ public void moveToInsertRow() throws SQLException {
+ getWrappedResultSet().moveToInsertRow();
+ }
+
+ public void moveToCurrentRow() throws SQLException {
+ getWrappedResultSet().moveToCurrentRow();
+ }
+
+ public void updateRef(int columnIndex, Ref x) throws SQLException {
+ getWrappedResultSet().updateRef( columnIndex, x );
+ }
+
+ public void updateRef(String columnName, Ref x) throws SQLException {
+ getWrappedResultSet().updateRef( columnName, x );
+ }
+
+ public void updateBlob(int columnIndex, Blob x) throws SQLException {
+ getWrappedResultSet().updateBlob( columnIndex, x );
+ }
+
+ public void updateBlob(String columnName, Blob x) throws SQLException {
+ getWrappedResultSet().updateBlob( columnName, x );
+ }
+
+ public void updateClob(int columnIndex, Clob x) throws SQLException {
+ getWrappedResultSet().updateClob( columnIndex, x );
+ }
+
+ public void updateClob(String columnName, Clob x) throws SQLException {
+ getWrappedResultSet().updateClob( columnName, x );
+ }
+
+ public void updateArray(int columnIndex, Array x) throws SQLException {
+ getWrappedResultSet().updateArray( columnIndex, x );
+ }
+
+ public void updateArray(String columnName, Array x) throws SQLException {
+ getWrappedResultSet().updateArray( columnName, x );
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/ResultSetWrapperImplementor.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/ResultSetWrapperImplementor.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/ResultSetWrapperImplementor.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+import org.hibernate.jdbc.ResultSetWrapper;
+
+/**
+ * Extra, internal contract for implementations of ResultSetWrapper for allowing
+ * invalidation of the wrapper.
+ *
+ * @author Steve Ebersole
+ */
+public interface ResultSetWrapperImplementor extends ResultSetWrapper {
+ /**
+ * Make the wrapper invalid for further usage.
+ */
+ public void invalidate();
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/StatementWrapperImplementor.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/StatementWrapperImplementor.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/StatementWrapperImplementor.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+import org.hibernate.jdbc.StatementWrapper;
+
+/**
+ * Extra, internal contract for implementations of StatementWrapper for allowing
+ * invalidation of the wrapper.
+ *
+ * @author Steve Ebersole
+ */
+public interface StatementWrapperImplementor extends StatementWrapper {
+ /**
+ * Make the wrapper invalid for further usage.
+ */
+ public void invalidate();
+}
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-18 08:34:26 UTC (rev 13934)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyBuilder.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -15,15 +15,17 @@
*/
package org.hibernate.jdbc.proxy;
+import java.lang.reflect.Proxy;
+import java.sql.CallableStatement;
import java.sql.Connection;
-import java.sql.Statement;
import java.sql.PreparedStatement;
-import java.sql.CallableStatement;
import java.sql.ResultSet;
-import java.lang.reflect.Proxy;
+import java.sql.Statement;
import org.hibernate.jdbc.ConnectionWrapper;
import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
+import org.hibernate.jdbc.impl.ResultSetWrapperImplementor;
+import org.hibernate.jdbc.impl.StatementWrapperImplementor;
/**
* ProxyBuilder implementation
Modified: 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-18 08:34:26 UTC (rev 13934)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyJDBCContainer.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -15,10 +15,12 @@
*/
package org.hibernate.jdbc.proxy;
+import java.sql.ResultSet;
import java.sql.Statement;
-import java.sql.ResultSet;
import org.hibernate.jdbc.impl.BasicJDBCContainer;
+import org.hibernate.jdbc.impl.ResultSetWrapperImplementor;
+import org.hibernate.jdbc.impl.StatementWrapperImplementor;
import org.hibernate.jdbc.util.ExceptionHelper;
/**
Deleted: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetWrapperImplementor.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetWrapperImplementor.java 2007-08-18 08:34:26 UTC (rev 13934)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetWrapperImplementor.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -1,31 +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 org.hibernate.jdbc.ResultSetWrapper;
-
-/**
- * Extra, internal contract for implementations of ResultSetWrapper for allowing
- * invalidation of the wrapper.
- *
- * @author Steve Ebersole
- */
-public interface ResultSetWrapperImplementor extends ResultSetWrapper {
- /**
- * Make the wrapper invalid for further usage.
- */
- public void invalidate();
-}
Deleted: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/StatementWrapperImplementor.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/StatementWrapperImplementor.java 2007-08-18 08:34:26 UTC (rev 13934)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/StatementWrapperImplementor.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -1,31 +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 org.hibernate.jdbc.StatementWrapper;
-
-/**
- * Extra, internal contract for implementations of StatementWrapper for allowing
- * invalidation of the wrapper.
- *
- * @author Steve Ebersole
- */
-public interface StatementWrapperImplementor extends StatementWrapper {
- /**
- * Make the wrapper invalid for further usage.
- */
- public void invalidate();
-}
Added: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/AggressiveReleaseTest.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/AggressiveReleaseTest.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/AggressiveReleaseTest.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,268 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.fail;
+
+import org.hibernate.jdbc.impl.ConnectionObserver;
+import org.hibernate.jdbc.impl.LogicalConnectionImpl;
+import org.hibernate.ConnectionReleaseMode;
+
+/**
+ * AggressiveReleaseTest implementation
+ *
+ * @author Steve Ebersole
+ */
+public class AggressiveReleaseTest {
+ private static final Logger log = LoggerFactory.getLogger( AggressiveReleaseTest.class );
+ private TestingServiceImpl services = new TestingServiceImpl();
+
+ private static class ConnectionCounter implements ConnectionObserver {
+ public int obtainCount = 0;
+ public int releaseCount = 0;
+
+ public void physicalConnectionObtained(Connection connection) {
+ obtainCount++;
+ }
+
+ public void physicalConnectionReleased() {
+ releaseCount++;
+ }
+
+ public void logicalConnectionClosed() {
+ }
+ }
+
+ @BeforeClass
+ protected void create() {
+ log.debug( "starting @BeforeClass" );
+ services.prepare( true );
+ }
+
+ @AfterClass
+ protected void destroy() {
+ services.release();
+ }
+
+ @BeforeMethod
+ protected void setUpSchema() throws SQLException {
+ log.debug( "starting @BeforeMethod" );
+ Connection connection = null;
+ Statement stmnt = null;
+ try {
+ connection = services.getConnectionProvider().getConnection();
+ stmnt = connection.createStatement();
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
+ }
+ finally {
+ if ( stmnt != null ) {
+ try {
+ stmnt.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close statement used to set up schema", ignore );
+ }
+ }
+ if ( connection != null ) {
+ try {
+ connection.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close connection used to set up schema", ignore );
+ }
+ }
+ }
+ }
+
+ @AfterMethod
+ protected void tearDownSchema() throws SQLException {
+ Connection connection = null;
+ Statement stmnt = null;
+ try {
+ connection = services.getConnectionProvider().getConnection();
+ stmnt = connection.createStatement();
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ }
+ finally {
+ if ( stmnt != null ) {
+ try {
+ stmnt.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close statement used to set up schema", ignore );
+ }
+ }
+ if ( connection != null ) {
+ try {
+ connection.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close connection used to set up schema", ignore );
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testBasicRelease() {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services );
+ Connection proxiedConnection = new ConnectionDelegate( logicalConnection );
+ ConnectionCounter observer = new ConnectionCounter();
+ logicalConnection.addObserver( observer );
+
+ try {
+ PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ ps.execute();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 0, observer.releaseCount );
+ ps.close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ finally {
+ logicalConnection.close();
+ }
+
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ }
+
+ @Test
+ public void testReleaseCircumventedByHeldResources() {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services );
+ Connection proxiedConnection = new ConnectionDelegate( logicalConnection );
+ ConnectionCounter observer = new ConnectionCounter();
+ logicalConnection.addObserver( observer );
+
+ try {
+ PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ ps.execute();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 0, observer.releaseCount );
+ ps.close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // open a result set and hold it open...
+ ps = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
+ ps.executeQuery();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // open a second result set
+ PreparedStatement ps2 = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
+ ps2.execute();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+ // and close it...
+ ps2.close();
+ // the release should be circumvented...
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // let the close of the logical connection below release all resources (hopefully)...
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ finally {
+ logicalConnection.close();
+ }
+
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 2, observer.releaseCount );
+ }
+
+ @Test
+ public void testReleaseCircumventedManually() {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services );
+ Connection proxiedConnection = new ConnectionDelegate( logicalConnection );
+ ConnectionCounter observer = new ConnectionCounter();
+ logicalConnection.addObserver( observer );
+
+ try {
+ PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ ps.execute();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 0, observer.releaseCount );
+ ps.close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // disable releases...
+ logicalConnection.disableReleases();
+
+ // open a result set...
+ ps = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
+ ps.executeQuery();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+ // and close it...
+ ps.close();
+ // the release should be circumvented...
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // let the close of the logical connection below release all resources (hopefully)...
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ finally {
+ logicalConnection.close();
+ }
+
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 2, observer.releaseCount );
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.JDBCException;
+import org.hibernate.jdbc.impl.LogicalConnectionImpl;
+
+/**
+ * BasicDelegationTests implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicDelegationTests {
+
+ private TestingServiceImpl services = new TestingServiceImpl();
+
+ @BeforeClass
+ protected void create() {
+ services.prepare( false );
+ }
+
+ @AfterClass
+ protected void destroy() {
+ services.release();
+ }
+
+ @Test
+ public void testExceptionHandling() {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ ConnectionDelegate connection = new ConnectionDelegate( logicalConnection );
+ try {
+ connection.prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery();
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ catch ( JDBCException ok ) {
+ // expected outcome
+ }
+ finally {
+ logicalConnection.close();
+ }
+ }
+
+ @Test
+ public void testBasicJdbcUsage() throws JDBCException {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ ConnectionDelegate connection = new ConnectionDelegate( logicalConnection );
+
+ try {
+ Statement stmnt = connection.createStatement();
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ logicalConnection.getJdbcContainer().close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+
+ PreparedStatement ps = connection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ ps.execute();
+
+ ps = connection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
+ ps.executeQuery();
+
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ finally {
+ logicalConnection.close();
+ }
+
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -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.delegation;
+
+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;
+
+/**
+ * TestingServiceImpl implementation
+ *
+ * @author Steve Ebersole
+ */
+public class TestingServiceImpl implements JDBCServices {
+ private ConnectionProvider connectionProvider;
+ private SQLStatementLogger sqlStatementLogger;
+ private JDBCContainerBuilder jdbcContainerBuilder;
+ private ExceptionHelper exceptionHelper;
+
+ public void prepare(boolean allowAggressiveRelease) {
+ connectionProvider = ConnectionProviderBuilder.buildConnectionProvider( allowAggressiveRelease );
+ sqlStatementLogger = new SQLStatementLogger( true );
+ exceptionHelper = new ExceptionHelper();
+ jdbcContainerBuilder = new JDBCContainerBuilder() {
+ public JDBCContainer buildJdbcContainer() {
+ return new DelegateJDBCContainer( exceptionHelper );
+ }
+ };
+ }
+
+ public void release() {
+ connectionProvider.close();
+ }
+
+ public ConnectionProvider getConnectionProvider() {
+ return connectionProvider;
+ }
+
+ public JDBCContainerBuilder getJdbcContainerBuilder() {
+ return jdbcContainerBuilder;
+ }
+
+ public SQLStatementLogger getSqlStatementLogger() {
+ return sqlStatementLogger;
+ }
+
+ public ExceptionHelper getExceptionHelper() {
+ return exceptionHelper;
+ }
+}
\ No newline at end of file
Added: sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/Data.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/Data.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/Data.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+/**
+ * Data implementation
+ *
+ * @author Steve Ebersole
+ */
+public class Data {
+ private long id;
+ private String name;
+
+ public Data() {
+ }
+
+ public Data(long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,370 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.jdbc.delegation.ConnectionDelegate;
+import org.hibernate.jdbc.impl.LogicalConnectionImpl;
+import org.hibernate.jdbc.proxy.ProxyBuilder;
+
+/**
+ * PerformanceTest implementation
+ *
+ * @author Steve Ebersole
+ */
+public class PerformanceTest {
+ private static final Logger log = LoggerFactory.getLogger( PerformanceTest.class );
+ private TestingServiceImpl services = new TestingServiceImpl();
+
+ @BeforeClass
+ protected void create() {
+ services.prepare( true );
+ }
+
+ @AfterClass
+ protected void destroy() {
+ services.release();
+ }
+
+ @BeforeMethod
+ protected void setUpSchema() throws SQLException {
+ Connection connection = null;
+ Statement stmnt = null;
+ try {
+ connection = services.getConnectionProvider().getConnection();
+ stmnt = connection.createStatement();
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
+ }
+ finally {
+ if ( stmnt != null ) {
+ try {
+ stmnt.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close statement used to set up schema", ignore );
+ }
+ }
+ if ( connection != null ) {
+ try {
+ connection.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close connection used to set up schema", ignore );
+ }
+ }
+ }
+ }
+
+ @AfterMethod
+ protected void tearDownSchema() throws SQLException {
+ Connection connection = null;
+ Statement stmnt = null;
+ try {
+ connection = services.getConnectionProvider().getConnection();
+ stmnt = connection.createStatement();
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ }
+ finally {
+ if ( stmnt != null ) {
+ try {
+ stmnt.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close statement used to set up schema", ignore );
+ }
+ }
+ if ( connection != null ) {
+ try {
+ connection.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close connection used to set up schema", ignore );
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testSimultaneous() throws Throwable {
+ System.gc();
+ System.gc();
+
+ for ( int n = 2; n < 5000; n *= 2 ) {
+ Data[] datum = new Data[n];
+ for ( int i = 0; i < n; i++ ) {
+ datum[i] = new Data( i, "test - many [" + i + "]" );
+ }
+
+ // prime ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Connection c;
+ LogicalConnectionImpl lc;
+
+ c = services.getConnectionProvider().getConnection();
+ process( c, datum );
+ services.getConnectionProvider().closeConnection( c );
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = ProxyBuilder.buildConnection( lc );
+ process( c, datum );
+ c.close();
+ lc.close();
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = new ConnectionDelegate( lc );
+ process( c, datum );
+ c.close();
+ lc.close();
+
+ c = services.getConnectionProvider().getConnection();
+ process( c, datum );
+ services.getConnectionProvider().closeConnection( c );
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = ProxyBuilder.buildConnection( lc );
+ process( c, datum );
+ c.close();
+ lc.close();
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = new ConnectionDelegate( lc );
+ process( c, datum );
+ c.close();
+ lc.close();
+
+ // Now do timings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ long proxies = 0, deleg = 0, jdbc = 0, start = 0;
+
+ c = services.getConnectionProvider().getConnection();
+ start = System.currentTimeMillis();
+ process( c, datum );
+ jdbc += System.currentTimeMillis() - start;
+ services.getConnectionProvider().closeConnection( c );
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = ProxyBuilder.buildConnection( lc );
+ start = System.currentTimeMillis();
+ process( c, datum );
+ proxies += System.currentTimeMillis() - start;
+ c.close();
+ lc.close();
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = new ConnectionDelegate( lc );
+ start = System.currentTimeMillis();
+ process( c, datum );
+ deleg += System.currentTimeMillis() - start;
+ c.close();
+ lc.close();
+
+ c = services.getConnectionProvider().getConnection();
+ start = System.currentTimeMillis();
+ process( c, datum );
+ jdbc += System.currentTimeMillis() - start;
+ services.getConnectionProvider().closeConnection( c );
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = ProxyBuilder.buildConnection( lc );
+ start = System.currentTimeMillis();
+ process( c, datum );
+ proxies += System.currentTimeMillis() - start;
+ c.close();
+ lc.close();
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = new ConnectionDelegate( lc );
+ start = System.currentTimeMillis();
+ process( c, datum );
+ deleg += System.currentTimeMillis() - start;
+ c.close();
+ lc.close();
+
+ c = services.getConnectionProvider().getConnection();
+ start = System.currentTimeMillis();
+ process( c, datum );
+ jdbc += System.currentTimeMillis() - start;
+ services.getConnectionProvider().closeConnection( c );
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = ProxyBuilder.buildConnection( lc );
+ start = System.currentTimeMillis();
+ process( c, datum );
+ proxies += System.currentTimeMillis() - start;
+ c.close();
+ lc.close();
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = new ConnectionDelegate( lc );
+ start = System.currentTimeMillis();
+ process( c, datum );
+ deleg += System.currentTimeMillis() - start;
+ c.close();
+ lc.close();
+
+ System.out.println( "-----------------------------------------------------------------------------------" );
+ System.out.println( " Objects : " + n );
+ System.out.println( "Direct JDBC : " + jdbc + " ms" );
+ System.out.println( " Proxies : " + proxies + " ms (ratio=" + ( ( (float) proxies )/jdbc ) + ")" );
+ System.out.println( " Delegation : " + deleg + " ms (ratio=" + ( ( (float) deleg )/jdbc ) + ")" );
+ System.out.println( "-----------------------------------------------------------------------------------" );
+
+ }
+ }
+
+ @Test
+ public void testMany() throws Throwable {
+ System.gc();
+ System.gc();
+
+ int N = 30;
+ long proxies = 0, jdbc = 0, deleg = 0, start = 0;
+
+ for ( int n = 1; n < 20; n++ ) {
+ Data[] datum = new Data[n];
+ for ( int i = 0; i < n; i++ ) {
+ datum[i] = new Data( i, "test - many [" + i + "]" );
+ }
+
+ Connection c;
+ LogicalConnectionImpl lc;
+
+ // prime ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ c = services.getConnectionProvider().getConnection();
+ process( c, datum );
+ services.getConnectionProvider().closeConnection( c );
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = ProxyBuilder.buildConnection( lc );
+ process( c, datum );
+ c.close();
+ lc.close();
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = new ConnectionDelegate( lc );
+ process( c, datum );
+ c.close();
+ lc.close();
+
+ c = services.getConnectionProvider().getConnection();
+ process( c, datum );
+ services.getConnectionProvider().closeConnection( c );
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = ProxyBuilder.buildConnection( lc );
+ process( c, datum );
+ c.close();
+ lc.close();
+
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = new ConnectionDelegate( lc );
+ process( c, datum );
+ c.close();
+ lc.close();
+
+ // Now do timings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ start = System.currentTimeMillis();
+ c = services.getConnectionProvider().getConnection();
+ for ( int i = 0; i < N; i++ ) {
+ process( c, datum );
+ }
+ services.getConnectionProvider().closeConnection( c );
+ jdbc += System.currentTimeMillis() - start;
+
+ start = System.currentTimeMillis();
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = ProxyBuilder.buildConnection( lc );
+ for ( int i = 0; i < N; i++ ) {
+ process( c, datum );
+ }
+ c.close();
+ lc.close();
+ proxies += ( System.currentTimeMillis() - start );
+
+ start = System.currentTimeMillis();
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ c = new ConnectionDelegate( lc );
+ for ( int i = 0; i < N; i++ ) {
+ process( c, datum );
+ }
+ c.close();
+ lc.close();
+ deleg += ( System.currentTimeMillis() - start );
+
+ }
+
+ System.out.println( "-----------------------------------------------------------------------------------" );
+ System.out.println( "Direct JDBC : " + jdbc + " ms" );
+ System.out.println( " Proxies : " + proxies + " ms (ratio=" + ( (float) proxies )/jdbc + ")" );
+ System.out.println( " Delegation : " + deleg + " ms (ratio=" + ( (float) deleg )/jdbc + ")" );
+ System.out.println( "-----------------------------------------------------------------------------------" );
+ }
+
+ private void process(Connection connection, Data[] datums) throws Throwable {
+ connection.setAutoCommit( false );
+
+ PreparedStatement insert = connection.prepareStatement( "insert into SANDBOX_JDBC_TST ( name, id ) values ( ?, ? )" );
+ for ( int i = 0, n = datums.length; i < n; i++ ) {
+ insert.setString( 1, datums[i].getName() );
+ insert.setLong( 2, datums[i].getId() );
+ insert.executeUpdate();
+ }
+ insert.close();
+
+ PreparedStatement update = connection.prepareStatement( "update SANDBOX_JDBC_TST set name = ? where id = ?" );
+ for ( int i = 0, n = datums.length; i < n; i++ ) {
+ update.setString( 1, "A Different Name!" + i + n );
+ update.setLong( 2, datums[i].getId() );
+ update.executeUpdate();
+ }
+ update.close();
+
+ PreparedStatement select = connection.prepareStatement( "select s.id s_id, s.name s_name FROM SANDBOX_JDBC_TST s" );
+ ResultSet rs = select.executeQuery();
+ while ( rs.next() ) {
+ rs.getLong( "s_id" );
+ rs.getString( "s_name" );
+ }
+ rs.close();
+ select.close();
+
+ PreparedStatement delete = connection.prepareStatement( "delete from SANDBOX_JDBC_TST where id = ?" );
+ for ( int i = 0, n = datums.length; i < n; i++ ) {
+ delete.setLong( 1, datums[i].getId() );
+ delete.executeUpdate();
+ }
+ delete.close();
+
+ connection.commit();
+ }
+}
Copied: sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/TestingServiceImpl.java (from rev 13928, sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/TestingServiceImpl.java)
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/TestingServiceImpl.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/TestingServiceImpl.java 2007-08-18 13:48:50 UTC (rev 13935)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.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;
+
+/**
+ * TestingServiceImpl implementation
+ *
+ * @author Steve Ebersole
+ */
+public class TestingServiceImpl implements JDBCServices {
+ private ConnectionProvider connectionProvider;
+ private SQLStatementLogger sqlStatementLogger;
+ private JDBCContainerBuilder jdbcContainerBuilder;
+ private ExceptionHelper exceptionHelper;
+
+ public void prepare(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 );
+ }
+ };
+ }
+
+ public void release() {
+ connectionProvider.close();
+ }
+
+ public ConnectionProvider getConnectionProvider() {
+ return connectionProvider;
+ }
+
+ public JDBCContainerBuilder getJdbcContainerBuilder() {
+ return jdbcContainerBuilder;
+ }
+
+ public SQLStatementLogger getSqlStatementLogger() {
+ return sqlStatementLogger;
+ }
+
+ public ExceptionHelper getExceptionHelper() {
+ return exceptionHelper;
+ }
+}
\ No newline at end of file
Modified: sandbox/trunk/jdbc-proxy/src/test/resources/log4j.properties
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/resources/log4j.properties 2007-08-18 08:34:26 UTC (rev 13934)
+++ sandbox/trunk/jdbc-proxy/src/test/resources/log4j.properties 2007-08-18 13:48:50 UTC (rev 13935)
@@ -18,6 +18,6 @@
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
-log4j.rootLogger=info, stdout
+log4j.rootLogger=error, stdout
-log4j.logger.org.hibernate=trace
\ No newline at end of file
+#log4j.logger.org.hibernate=error
\ No newline at end of file
16 years, 8 months
Hibernate SVN: r13934 - search/trunk.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2007-08-18 04:34:26 -0400 (Sat, 18 Aug 2007)
New Revision: 13934
Modified:
search/trunk/
Log:
Modified svn:ignore pattern in top level directory
Property changes on: search/trunk
___________________________________________________________________
Name: svn:ignore
+ build
indextemp
lucenedirs
target
test_output
16 years, 8 months
Hibernate SVN: r13933 - in core/trunk: testsuite/src/test/java/org/hibernate/test/legacy and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-17 14:46:02 -0400 (Fri, 17 Aug 2007)
New Revision: 13933
Modified:
core/trunk/testing/src/main/java/org/hibernate/junit/functional/FunctionalTestCase.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java
Log:
skip org.hibernate.test.legacy.MasterDetailTest#testCachedCollectionRefresh when connection is enforcing (at least) serializable isolation
Modified: core/trunk/testing/src/main/java/org/hibernate/junit/functional/FunctionalTestCase.java
===================================================================
--- core/trunk/testing/src/main/java/org/hibernate/junit/functional/FunctionalTestCase.java 2007-08-17 18:45:35 UTC (rev 13932)
+++ core/trunk/testing/src/main/java/org/hibernate/junit/functional/FunctionalTestCase.java 2007-08-17 18:46:02 UTC (rev 13933)
@@ -4,6 +4,7 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
+import java.sql.Connection;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Mappings;
@@ -279,6 +280,29 @@
+ /**
+ * Do connections enforce SERIALIZABLE isolation...
+ *
+ * @return
+ * @throws Exception
+ */
+ protected boolean isSerializableIsolationEnforced() throws Exception {
+ Connection conn = null;
+ try {
+ conn = sfi().getConnectionProvider().getConnection();
+ return conn.getTransactionIsolation() >= Connection.TRANSACTION_SERIALIZABLE;
+ }
+ finally {
+ if ( conn != null ) {
+ try {
+ sfi().getConnectionProvider().closeConnection( conn );
+ }
+ catch ( Throwable ignore ) {
+ // ignore...
+ }
+ }
+ }
+ }
/**
* Is connection at least read committed?
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java 2007-08-17 18:45:35 UTC (rev 13932)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java 2007-08-17 18:46:02 UTC (rev 13933)
@@ -835,6 +835,10 @@
}
public void testCachedCollectionRefresh() throws Exception {
+ if ( isSerializableIsolationEnforced() ) {
+ reportSkip( "SERIALIZABLE isolation", "cached collection refreshing" );
+ return;
+ }
Session s = openSession();
Category c = new Category();
List list = new ArrayList();
@@ -853,7 +857,9 @@
s.close();
s = openSession();
- if ( (getDialect() instanceof MySQLDialect) ) s.connection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+ if ( (getDialect() instanceof MySQLDialect) ) {
+ s.connection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+ }
c = (Category) s.load(Category.class, id);
c.getSubcategories().size(); //force load
16 years, 8 months
Hibernate SVN: r13932 - in core/branches/Branch_3_2/test/org/hibernate: test/legacy and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-17 14:45:35 -0400 (Fri, 17 Aug 2007)
New Revision: 13932
Modified:
core/branches/Branch_3_2/test/org/hibernate/junit/functional/FunctionalTestCase.java
core/branches/Branch_3_2/test/org/hibernate/test/legacy/MasterDetailTest.java
Log:
skip org.hibernate.test.legacy.MasterDetailTest#testCachedCollectionRefresh when connection is enforcing (at least) serializable isolation
Modified: core/branches/Branch_3_2/test/org/hibernate/junit/functional/FunctionalTestCase.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/junit/functional/FunctionalTestCase.java 2007-08-17 04:04:34 UTC (rev 13931)
+++ core/branches/Branch_3_2/test/org/hibernate/junit/functional/FunctionalTestCase.java 2007-08-17 18:45:35 UTC (rev 13932)
@@ -4,6 +4,7 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
+import java.sql.Connection;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Mappings;
@@ -278,8 +279,30 @@
}
+ /**
+ * Do connections enforce SERIALIZABLE isolation...
+ *
+ * @return
+ * @throws Exception
+ */
+ protected boolean isSerializableIsolationEnforced() throws Exception {
+ Connection conn = null;
+ try {
+ conn = sfi().getConnectionProvider().getConnection();
+ return conn.getTransactionIsolation() >= Connection.TRANSACTION_SERIALIZABLE;
+ }
+ finally {
+ if ( conn != null ) {
+ try {
+ sfi().getConnectionProvider().closeConnection( conn );
+ }
+ catch ( Throwable ignore ) {
+ // ignore...
+ }
+ }
+ }
+ }
-
/**
* Is connection at least read committed?
* <p/>
Modified: core/branches/Branch_3_2/test/org/hibernate/test/legacy/MasterDetailTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/legacy/MasterDetailTest.java 2007-08-17 04:04:34 UTC (rev 13931)
+++ core/branches/Branch_3_2/test/org/hibernate/test/legacy/MasterDetailTest.java 2007-08-17 18:45:35 UTC (rev 13932)
@@ -3,6 +3,7 @@
import java.io.Serializable;
import java.sql.Connection;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -835,6 +836,10 @@
}
public void testCachedCollectionRefresh() throws Exception {
+ if ( isSerializableIsolationEnforced() ) {
+ reportSkip( "SERIALIZABLE isolation", "cached collection refreshing" );
+ return;
+ }
Session s = openSession();
Category c = new Category();
List list = new ArrayList();
@@ -853,7 +858,9 @@
s.close();
s = openSession();
- if ( (getDialect() instanceof MySQLDialect) ) s.connection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+ if ( (getDialect() instanceof MySQLDialect) ) {
+ s.connection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+ }
c = (Category) s.load(Category.class, id);
c.getSubcategories().size(); //force load
16 years, 8 months
Hibernate SVN: r13931 - in sandbox/trunk/jdbc-proxy/src: main/java/org/hibernate/jdbc/batch and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-17 00:04:34 -0400 (Fri, 17 Aug 2007)
New Revision: 13931
Added:
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/AbstractBatchImpl.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/Batch.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchBuilder.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchObserver.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchingBatch.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/NonBatchingBatch.java
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/BasicBatchTest.java
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/TestingServiceImpl.java
Log:
initial batch support on top of proxies
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/AbstractBatchImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/AbstractBatchImpl.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/AbstractBatchImpl.java 2007-08-17 04:04:34 UTC (rev 13931)
@@ -0,0 +1,145 @@
+/*
+ * 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.batch;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
+import org.hibernate.jdbc.proxy.ProxyBuilder;
+
+/**
+ * AbstractBatchImpl implementation
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractBatchImpl implements Batch {
+ private static final Logger log = LoggerFactory.getLogger( AbstractBatchImpl.class );
+
+ private Object key;
+ private LogicalConnectionImplementor logicalConnection;
+ private Connection connectionProxy;
+ private LinkedHashMap statements = new LinkedHashMap();
+ private LinkedHashSet observers = new LinkedHashSet();
+
+ protected AbstractBatchImpl(Object key, LogicalConnectionImplementor logicalConnection) {
+ this.key = key;
+ this.logicalConnection = logicalConnection;
+ this.connectionProxy = ProxyBuilder.buildConnection( logicalConnection );
+ }
+
+ protected abstract void doExecuteBatch();
+
+ protected JDBCServices getJdbcServices() {
+ return logicalConnection.getJdbcServices();
+ }
+
+ protected LinkedHashMap getStatements() {
+ return statements;
+ }
+
+ public final Object getKey() {
+ return key;
+ }
+
+ public final PreparedStatement getBatchStatement(String sql, boolean callable) {
+ PreparedStatement statement = ( PreparedStatement ) statements.get( sql );
+ if ( statement == null ) {
+ statement = buildBatchStatement( sql, callable );
+ statements.put( sql, statement );
+ }
+ else {
+ log.debug( "reusing batch statement" );
+ logicalConnection.getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ }
+ return statement;
+ }
+
+ private PreparedStatement buildBatchStatement(String sql, boolean callable) {
+ try {
+ if ( callable ) {
+ return connectionProxy.prepareCall( sql );
+ }
+ else {
+ return connectionProxy.prepareStatement( sql );
+ }
+ }
+ catch ( SQLException sqle ) {
+ log.error( "sqlexception escaped proxy", sqle );
+ throw logicalConnection.getJdbcServices().getExceptionHelper().convert( sqle, "could not prepare batch statement", sql );
+ }
+ }
+
+ public final void execute() {
+ notifyObserversExplicitExecution();
+ if ( statements.isEmpty() ) {
+ return;
+ }
+ try {
+ try {
+ doExecuteBatch();
+ }
+ finally {
+ releaseStatements();
+ }
+ }
+ finally {
+ statements.clear();
+ }
+ }
+
+ private void releaseStatements() {
+ Iterator itr = getStatements().entrySet().iterator();
+ while ( itr.hasNext() ) {
+ final Map.Entry entry = ( Map.Entry ) itr.next();
+ try {
+ final PreparedStatement statement = ( PreparedStatement ) entry.getValue();
+ statement.close();
+ }
+ catch ( SQLException e ) {
+ log.error( "unable to release batch statement..." );
+ log.error( "sqlexception escaped proxy", e );
+ }
+ }
+ }
+
+ public void addObserver(BatchObserver observer) {
+ observers.add( observer );
+ }
+
+ private void notifyObserversExplicitExecution() {
+ Iterator itr = observers.iterator();
+ while ( itr.hasNext() ) {
+ ( ( BatchObserver ) itr.next() ).batchExplicitlyExecuted();
+ }
+ }
+
+ protected void notifyObserversImplicitExecution() {
+ Iterator itr = observers.iterator();
+ while ( itr.hasNext() ) {
+ ( ( BatchObserver ) itr.next() ).batchImplicitlyExecuted();
+ }
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/Batch.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/Batch.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/Batch.java 2007-08-17 04:04:34 UTC (rev 13931)
@@ -0,0 +1,34 @@
+/*
+ * 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.batch;
+
+import java.sql.PreparedStatement;
+
+import org.hibernate.jdbc.Expectation;
+
+/**
+ * Conceptually models a batch, but unlike directly in JDBC, here we add the ability to
+ * batch together multiple statements at a time.
+ *
+ * @author Steve Ebersole
+ */
+public interface Batch {
+ public Object getKey();
+ public void addObserver(BatchObserver observer);
+ public PreparedStatement getBatchStatement(String sql, boolean callable);
+ public void addToBatch(Expectation expectation);
+ public void execute();
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchBuilder.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchBuilder.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchBuilder.java 2007-08-17 04:04:34 UTC (rev 13931)
@@ -0,0 +1,52 @@
+/*
+ * 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.batch;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
+
+/**
+ * BatchBuilder implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BatchBuilder {
+ private static final Logger log = LoggerFactory.getLogger( BatchBuilder.class );
+
+ // todo : eventually have this take the Settings; this form is needed for testing because Settings is final :(
+
+ private int size;
+
+ public BatchBuilder() {
+ }
+
+ public BatchBuilder(int size) {
+ this.size = size;
+ }
+
+ public void setSize(int size) {
+ this.size = size;
+ }
+
+ public Batch buildBatch(Object key, LogicalConnectionImplementor logicalConnection) {
+ log.trace( "building batch [size={}]", size );
+ return size > 1
+ ? new BatchingBatch( key, logicalConnection, size )
+ : new NonBatchingBatch( key, logicalConnection );
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchObserver.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchObserver.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchObserver.java 2007-08-17 04:04:34 UTC (rev 13931)
@@ -0,0 +1,26 @@
+/*
+ * 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.batch;
+
+/**
+ * BatchObserver contract
+ *
+ * @author Steve Ebersole
+ */
+public interface BatchObserver {
+ public void batchExplicitlyExecuted();
+ public void batchImplicitlyExecuted();
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchingBatch.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchingBatch.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/BatchingBatch.java 2007-08-17 04:04:34 UTC (rev 13931)
@@ -0,0 +1,117 @@
+/*
+ * 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.batch;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.jdbc.Expectation;
+import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
+import org.hibernate.HibernateException;
+
+/**
+ * BatchingBatch implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BatchingBatch extends AbstractBatchImpl {
+ private static final Logger log = LoggerFactory.getLogger( BatchingBatch.class );
+
+ private final int batchSize;
+ private Expectation[] expectations;
+ private int batchPosition;
+
+ public BatchingBatch(Object key, LogicalConnectionImplementor logicalConnection, int batchSize) {
+ super( key, logicalConnection );
+ this.batchSize = batchSize;
+ this.expectations = new Expectation[ batchSize ];
+ }
+
+ public void addToBatch(Expectation expectation) {
+ if ( !expectation.canBeBatched() ) {
+ throw new HibernateException( "attempting to batch an operation which cannot be batched" );
+ }
+ Iterator itr = getStatements().entrySet().iterator();
+ while ( itr.hasNext() ) {
+ final Map.Entry entry = ( Map.Entry ) itr.next();
+ try {
+ final PreparedStatement statement = ( PreparedStatement ) entry.getValue();
+ statement.addBatch();
+ }
+ catch ( SQLException e ) {
+ log.error( "sqlexception escaped proxy", e );
+ throw getJdbcServices().getExceptionHelper()
+ .convert( e, "could not perform addBatch", ( String ) entry.getKey() );
+ }
+ }
+ expectations[ batchPosition++ ] = expectation;
+ if ( batchPosition == batchSize ) {
+ notifyObserversImplicitExecution();
+ doExecuteBatch();
+ }
+ }
+
+ protected void doExecuteBatch() {
+ if ( batchPosition == 0 ) {
+ log.debug( "no batched statements to execute" );
+ }
+ else {
+ if ( log.isDebugEnabled() ) {
+ log.debug( "Executing batch size: " + batchPosition );
+ }
+
+ try {
+ Iterator itr = getStatements().entrySet().iterator();
+ while ( itr.hasNext() ) {
+ final Map.Entry entry = ( Map.Entry ) itr.next();
+ try {
+ final PreparedStatement statement = ( PreparedStatement ) entry.getValue();
+ checkRowCounts( statement.executeBatch(), statement );
+ }
+ catch ( SQLException e ) {
+ log.error( "sqlexception escaped proxy", e );
+ throw getJdbcServices().getExceptionHelper()
+ .convert( e, "could not perform addBatch", ( String ) entry.getKey() );
+ }
+ }
+ }
+ catch ( RuntimeException re ) {
+ log.error( "Exception executing batch [{}]", re.getMessage() );
+ throw re;
+ }
+ finally {
+ batchPosition = 0;
+ }
+
+ }
+ }
+
+ private void checkRowCounts(int[] rowCounts, PreparedStatement ps) throws SQLException, HibernateException {
+ int numberOfRowCounts = rowCounts.length;
+ if ( numberOfRowCounts != batchPosition ) {
+ log.warn( "JDBC driver did not return the expected number of row counts" );
+ }
+ for ( int i = 0; i < numberOfRowCounts; i++ ) {
+ expectations[i].verifyOutcome( rowCounts[i], ps, i );
+ }
+ }
+
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/NonBatchingBatch.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/NonBatchingBatch.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/batch/NonBatchingBatch.java 2007-08-17 04:04:34 UTC (rev 13931)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.batch;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.jdbc.Expectation;
+import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
+
+/**
+ * NonBatchingBatch implementation
+ *
+ * @author Steve Ebersole
+ */
+public class NonBatchingBatch extends AbstractBatchImpl {
+ private static final Logger log = LoggerFactory.getLogger( NonBatchingBatch.class );
+
+ protected NonBatchingBatch(Object key, LogicalConnectionImplementor logicalConnection) {
+ super( key, logicalConnection );
+ }
+
+ public void addToBatch(Expectation expectation) {
+ notifyObserversImplicitExecution();
+ Iterator itr = getStatements().entrySet().iterator();
+ while ( itr.hasNext() ) {
+ final Map.Entry entry = ( Map.Entry ) itr.next();
+ try {
+ final PreparedStatement statement = ( PreparedStatement ) entry.getValue();
+ final int rowCount = statement.executeUpdate();
+ expectation.verifyOutcome( rowCount, statement, 0 );
+ }
+ catch ( SQLException e ) {
+ log.error( "sqlexception escaped proxy", e );
+ throw getJdbcServices().getExceptionHelper()
+ .convert( e, "could not execute batch statement", ( String ) entry.getKey() );
+ }
+ }
+ }
+
+ protected void doExecuteBatch() {
+ // nothing to do
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/BasicBatchTest.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/BasicBatchTest.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/BasicBatchTest.java 2007-08-17 04:04:34 UTC (rev 13931)
@@ -0,0 +1,219 @@
+/*
+ * 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.batch;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static org.testng.Assert.*;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.jdbc.Expectations;
+import org.hibernate.jdbc.impl.LogicalConnectionImpl;
+import org.hibernate.jdbc.proxy.ProxyBuilder;
+
+/**
+ * BasicBatchTest implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicBatchTest {
+ private static final Logger log = LoggerFactory.getLogger( BasicBatchTest.class );
+
+ private TestingServiceImpl services = new TestingServiceImpl();
+
+ private static class BatchCounter implements BatchObserver {
+ public int explicitBatchCount;
+ public int implicitBatchCount;
+
+ public void batchExplicitlyExecuted() {
+ explicitBatchCount++;
+ }
+
+ public void batchImplicitlyExecuted() {
+ implicitBatchCount++;
+ }
+ }
+
+ @BeforeClass
+ protected void create() {
+ services.prepare( false );
+ }
+
+ @AfterClass
+ protected void destroy() {
+ services.release();
+ }
+
+ @BeforeMethod
+ protected void setUpSchema() throws SQLException {
+ log.debug( "starting @BeforeMethod" );
+ Connection connection = null;
+ Statement stmnt = null;
+ try {
+ connection = services.getConnectionProvider().getConnection();
+ stmnt = connection.createStatement();
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
+ }
+ finally {
+ if ( stmnt != null ) {
+ try {
+ stmnt.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close statement used to set up schema", ignore );
+ }
+ }
+ if ( connection != null ) {
+ try {
+ connection.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close connection used to set up schema", ignore );
+ }
+ }
+ }
+ }
+
+ @AfterMethod
+ protected void tearDownSchema() throws SQLException {
+ Connection connection = null;
+ Statement stmnt = null;
+ try {
+ connection = services.getConnectionProvider().getConnection();
+ stmnt = connection.createStatement();
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ }
+ finally {
+ if ( stmnt != null ) {
+ try {
+ stmnt.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close statement used to set up schema", ignore );
+ }
+ }
+ if ( connection != null ) {
+ try {
+ connection.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close connection used to set up schema", ignore );
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testBatchingBatches() throws SQLException {
+ LogicalConnectionImpl lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ BatchBuilder batchBuilder = new BatchBuilder( 2 );
+
+ // test an explicit batch execution...
+ Batch batch = batchBuilder.buildBatch( this, lc );
+ BatchCounter counter = new BatchCounter();
+ batch.addObserver( counter );
+ PreparedStatement ps = batch.getBatchStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )", false );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ batch.addToBatch( Expectations.BASIC );
+ assertTrue( lc.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 0, counter.explicitBatchCount );
+ assertEquals( 0, counter.implicitBatchCount );
+ batch.execute();
+ assertEquals( 1, getRowCount() );
+ assertFalse( lc.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, counter.explicitBatchCount );
+ assertEquals( 0, counter.implicitBatchCount );
+
+ lc.close();
+ lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+
+ // test an implicit batch execution...
+ batch = batchBuilder.buildBatch( this, lc );
+ counter = new BatchCounter();
+ batch.addObserver( counter );
+ ps = batch.getBatchStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )", false );
+ ps.setLong( 1, 2 );
+ ps.setString( 2, "me" );
+ assertTrue( lc.getJdbcContainer().hasRegisteredResources() );
+ batch.addToBatch( Expectations.BASIC );
+ assertTrue( lc.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 0, counter.explicitBatchCount );
+ assertEquals( 0, counter.implicitBatchCount );
+ ps.setLong( 1, 3 );
+ ps.setString( 2, "you" );
+ // this should force execution of the batch...
+ batch.addToBatch( Expectations.BASIC );
+ assertEquals( 3, getRowCount() );
+ assertEquals( 0, counter.explicitBatchCount );
+ assertEquals( 1, counter.implicitBatchCount );
+ batch.execute();
+ assertEquals( 3, getRowCount() );
+ assertFalse( lc.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, counter.explicitBatchCount );
+ assertEquals( 1, counter.implicitBatchCount );
+ lc.close();
+ }
+
+ private int getRowCount() throws SQLException {
+ LogicalConnectionImpl lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ try {
+ Connection conn = ProxyBuilder.buildConnection( lc );
+ ResultSet rs = conn.createStatement().executeQuery( "select count(*) from SANDBOX_JDBC_TST" );
+ assert true == rs.next();
+ return rs.getInt( 1 );
+ }
+ finally {
+ lc.close();
+ }
+ }
+
+ @Test
+ public void testNonBatchingBatches() throws SQLException {
+ LogicalConnectionImpl lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ BatchBuilder batchBuilder = new BatchBuilder( -1 );
+
+ Batch batch = batchBuilder.buildBatch( this, lc );
+ BatchCounter counter = new BatchCounter();
+ batch.addObserver( counter );
+ PreparedStatement ps = batch.getBatchStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )", false );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ batch.addToBatch( Expectations.BASIC );
+ assertEquals( 1, getRowCount() );
+ assertTrue( lc.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 0, counter.explicitBatchCount );
+ assertEquals( 1, counter.implicitBatchCount );
+ batch.execute();
+ assertEquals( 1, getRowCount() );
+ assertFalse( lc.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, counter.explicitBatchCount );
+ assertEquals( 1, counter.implicitBatchCount );
+ lc.close();
+ }
+}
Copied: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/TestingServiceImpl.java (from rev 13928, sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/TestingServiceImpl.java)
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/TestingServiceImpl.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/TestingServiceImpl.java 2007-08-17 04:04:34 UTC (rev 13931)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.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.util.ExceptionHelper;
+import org.hibernate.jdbc.util.SQLStatementLogger;
+
+/**
+ * TestingServiceImpl implementation
+ *
+ * @author Steve Ebersole
+ */
+public class TestingServiceImpl implements JDBCServices {
+ private ConnectionProvider connectionProvider;
+ private SQLStatementLogger sqlStatementLogger;
+ private JDBCContainerBuilder jdbcContainerBuilder;
+ private ExceptionHelper exceptionHelper;
+
+ public void prepare(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 );
+ }
+ };
+ }
+
+ public void release() {
+ connectionProvider.close();
+ }
+
+ public ConnectionProvider getConnectionProvider() {
+ return connectionProvider;
+ }
+
+ public JDBCContainerBuilder getJdbcContainerBuilder() {
+ return jdbcContainerBuilder;
+ }
+
+ public SQLStatementLogger getSqlStatementLogger() {
+ return sqlStatementLogger;
+ }
+
+ public ExceptionHelper getExceptionHelper() {
+ return exceptionHelper;
+ }
+}
\ No newline at end of file
16 years, 8 months
Hibernate SVN: r13930 - core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-16 18:28:16 -0400 (Thu, 16 Aug 2007)
New Revision: 13930
Modified:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder/MultiplexingCacheInstanceManager.java
Log:
jbosscache 2.x work
Modified: core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder/MultiplexingCacheInstanceManager.java
===================================================================
--- core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder/MultiplexingCacheInstanceManager.java 2007-08-16 19:34:04 UTC (rev 13929)
+++ core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder/MultiplexingCacheInstanceManager.java 2007-08-16 22:28:16 UTC (rev 13930)
@@ -20,8 +20,8 @@
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.jbc2.CacheInstanceManager;
@@ -33,7 +33,7 @@
* using the jgroups multiplexer under the covers to re-use the same group
* communication stack.
* <p/>
- * todo : this can get simplified once JBC implemants their "configuration factory" (the stuff akin to channel factory)
+ * todo : this can get simplified once JBC implemants their "configuration factory" (the stuff akin to channel factory) - http://jira.jboss.com/jira/browse/JBCACHE-1156
*
* @author Steve Ebersole
*/
@@ -50,7 +50,7 @@
public static final String OPTIMISTIC_LOCKING_SCHEME = "OPTIMISTIC";
- private static final Log log = LogFactory.getLog( MultiplexingCacheInstanceManager.class );
+ private static final Logger log = LoggerFactory.getLogger( MultiplexingCacheInstanceManager.class );
private final Cache jbcEntityCache;
private final Cache jbcCollectionCache;
16 years, 8 months
Hibernate SVN: r13929 - in sandbox/trunk/jdbc-impl/src: main/java/org/hibernate/jdbc/delegation and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-16 15:34:04 -0400 (Thu, 16 Aug 2007)
New Revision: 13929
Added:
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/AggressiveReleaseTest.java
Modified:
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainer.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainerBuilder.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCServices.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/ExceptionHelper.java
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java
Log:
import ideas from proxy approach + after_statement releases
Modified: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainer.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainer.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -19,18 +19,57 @@
import java.sql.Statement;
/**
- * JDBCContainer contract
+ * Contract for a JDBCContainer, which acts as a container (or holder) for JDBC objects.
*
* @author Steve Ebersole
*/
public interface JDBCContainer {
+ /**
+ * Register a JDBC statement with the container.
+ *
+ * @param statement The statement to register.
+ */
public void register(Statement statement);
+
+ /**
+ * Release a statement (un-register it).
+ *
+ * @param statement The statement to release.
+ */
public void release(Statement statement);
+ /**
+ * Register a JDBC resultset with the container.
+ *
+ * @param resultSet The resultset to register.
+ */
public void register(ResultSet resultSet);
+
+ /**
+ * Release a resultset (un-register it).
+ *
+ * @param resultSet The resultset to release.
+ */
public void release(ResultSet resultSet);
+ /**
+ * Does this container currently have registered resources?
+ *
+ * @return True if the container does have registered resources; false otherwise.
+ */
public boolean hasRegisteredResources();
+ /**
+ * Release all registered resources.
+ */
+ public void releaseResources();
+
+ /**
+ * Close this container. Also releases resources, but additionally indicates that
+ * the container is expected to no longer be used. As such the implemntation is
+ * free to render itself unusable.
+ *
+ * @see #releaseResources()
+ */
public void close();
}
Modified: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainerBuilder.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainerBuilder.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainerBuilder.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -24,5 +24,10 @@
* @author Steve Ebersole
*/
public interface JDBCContainerBuilder {
+ /**
+ * Build a container.
+ *
+ * @return The container.
+ */
public JDBCContainer buildJdbcContainer();
}
Modified: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCServices.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCServices.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCServices.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -20,13 +20,37 @@
import org.hibernate.jdbc.util.SQLStatementLogger;
/**
- * Contract for services around JDBC operations.
+ * Contract for services around JDBC operations. These represent
+ * shared resources, aka not varied by session/use.
*
* @author Steve Ebersole
*/
public interface JDBCServices {
+ /**
+ * Obtain service for providing JDBC connections.
+ *
+ * @return The connection provider.
+ */
public ConnectionProvider getConnectionProvider();
+
+ /**
+ * Obtain service for building JDBCContainers instances.
+ *
+ * @return The JDBCContainer builder.
+ */
public JDBCContainerBuilder getJdbcContainerBuilder();
+
+ /**
+ * Obtain service for logging SQL statements.
+ *
+ * @return The SQL statement logger.
+ */
public SQLStatementLogger getSqlStatementLogger();
+
+ /**
+ * Obtain service for dealing with exceptions.
+ *
+ * @return The exception helper service.
+ */
public ExceptionHelper getExceptionHelper();
}
Modified: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -27,6 +27,7 @@
import org.hibernate.HibernateException;
import org.hibernate.jdbc.JDBCServices;
import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
/**
* AbstractStatementDelegate implementation
@@ -36,15 +37,17 @@
public abstract class AbstractStatementDelegate implements Statement, StatementWrapperImplementor {
private static final Logger log = LoggerFactory.getLogger( AbstractStatementDelegate.class );
- private boolean valid = true;
private ConnectionDelegate connectionDelegate;
private Statement statement;
+ private boolean valid = true;
+ private final int hashCode;
private ResultSet currentResultSetDelegate;
public AbstractStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement) {
this.connectionDelegate = connectionDelegate;
this.statement = statement;
+ this.hashCode = statement.hashCode();
getJdbcContainer().register( this );
}
@@ -54,11 +57,13 @@
}
}
- /*package-protected*/ JDBCServices getJdbcServices() {
+ protected JDBCServices getJdbcServices() {
+ errorIfInvalid();
return connectionDelegate.getJdbcServices();
}
- /*package-protected*/ JDBCContainer getJdbcContainer() {
+ protected JDBCContainer getJdbcContainer() {
+ errorIfInvalid();
return connectionDelegate.getJdbcContainer();
}
@@ -77,7 +82,15 @@
valid = false;
}
+ public String toString() {
+ return super.toString() + "[valid=" + valid + "]";
+ }
+ public int hashCode() {
+ return hashCode;
+ }
+
+
// special Statement methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public Connection getConnection() throws SQLException {
@@ -87,7 +100,9 @@
public void close() throws SQLException {
if ( valid ) {
+ LogicalConnectionImplementor lc = connectionDelegate.getLogicalConnection();
getJdbcContainer().release( this );
+ lc.afterStatementExecution();
}
}
Modified: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -44,8 +44,9 @@
public class ConnectionDelegate implements Connection, ConnectionWrapper, ConnectionObserver {
private static final Logger log = LoggerFactory.getLogger( ConnectionDelegate.class );
+ private LogicalConnectionImplementor logicalConnection;
private boolean valid = true;
- private LogicalConnectionImplementor logicalConnection;
+ private final int hashCode;
/**
* Builds a connection delegate with the given logical connection.
@@ -56,13 +57,44 @@
public ConnectionDelegate(LogicalConnectionImplementor logicalConnection) {
this.logicalConnection = logicalConnection;
logicalConnection.addObserver( this );
+ this.hashCode = this.logicalConnection.hashCode();
}
- /*package-protected*/ JDBCServices getJdbcServices() {
+ /**
+ * Access to our logical connection.
+ *
+ * @return the logical connection
+ */
+ protected LogicalConnectionImplementor getLogicalConnection() {
+ errorIfInvalid();
+ return logicalConnection;
+ }
+
+ private void errorIfInvalid() {
+ if ( !valid ) {
+ throw new HibernateException( "connection handle is invalid" );
+ }
+ }
+
+ /**
+ * Provide access to JDBCServices.
+ * <p/>
+ * NOTE : package-protected
+ *
+ * @return JDBCServices
+ */
+ JDBCServices getJdbcServices() {
return logicalConnection.getJdbcServices();
}
- /*package-protected*/ JDBCContainer getJdbcContainer() {
+ /**
+ * Provide access to JDBCContainer.
+ * <p/>
+ * NOTE : package-protected
+ *
+ * @return JDBCContainer
+ */
+ JDBCContainer getJdbcContainer() {
return logicalConnection.getJdbcContainer();
}
@@ -77,12 +109,22 @@
return logicalConnection.getConnection();
}
- public void physicalConnectionObtained() {
+ /**
+ * {@inheritDoc}
+ */
+ public void physicalConnectionObtained(Connection connection) {
}
+ /**
+ * {@inheritDoc}
+ */
public void physicalConnectionReleased() {
+ log.info( "logical connection releasing its physical connection");
}
+ /**
+ * {@inheritDoc}
+ */
public void logicalConnectionClosed() {
log.info( "*** logical connection closed ***" );
invalidateDelegate();
@@ -94,7 +136,15 @@
valid = false;
}
+ public String toString() {
+ return super.toString() + "[valid=" + valid + "]";
+ }
+ public int hashCode() {
+ return hashCode;
+ }
+
+
// statement-creation methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public Statement createStatement() {
Modified: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -44,41 +44,53 @@
* @author Steve Ebersole
*/
public class ResultSetDelegate implements ResultSet, ResultSetWrapperImplementor {
+
+ private AbstractStatementDelegate statementDelegate;
+ private ResultSet resultSet;
private boolean valid = true;
- private AbstractStatementDelegate statementDelegate;
- private ResultSet wrappedResultSet;
+ private final int hashCode;
- public ResultSetDelegate(AbstractStatementDelegate statementDelegate, ResultSet wrappedResultSet) {
+ public ResultSetDelegate(AbstractStatementDelegate statementDelegate, ResultSet resultSet) {
this.statementDelegate = statementDelegate;
- this.wrappedResultSet = wrappedResultSet;
+ this.resultSet = resultSet;
+ this.hashCode = resultSet.hashCode();
+ statementDelegate.getJdbcContainer().register( this );
}
- /*package-protected*/ JDBCServices getJdbcServices() {
+ protected JDBCServices getJdbcServices() {
return statementDelegate.getJdbcServices();
}
- /*package-protected*/ JDBCContainer getJdbcContainer() {
+ protected JDBCContainer getJdbcContainer() {
return statementDelegate.getJdbcContainer();
}
public ResultSet getWrappedResultSetWithoutChecks() {
- return wrappedResultSet;
+ return resultSet;
}
public ResultSet getWrappedResultSet() {
if ( !valid ) {
throw new HibernateException( "resultset handle is invalid" );
}
- return wrappedResultSet;
+ return resultSet;
}
public void invalidate() {
statementDelegate = null;
- wrappedResultSet = null;
+ resultSet = null;
valid = false;
}
+ public String toString() {
+ return super.toString() + "[valid=" + valid + "]";
+ }
+ public int hashCode() {
+ return hashCode;
+ }
+
+
// special ResultSet methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public Statement getStatement() throws SQLException {
Modified: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -16,20 +16,19 @@
package org.hibernate.jdbc.impl;
import java.sql.ResultSet;
+import java.sql.SQLException;
import java.sql.Statement;
-import java.sql.SQLException;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
-import java.util.Map;
import java.util.Set;
-import java.util.HashSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
+import org.hibernate.jdbc.JDBCContainer;
import org.hibernate.jdbc.util.ExceptionHelper;
-import org.hibernate.jdbc.JDBCContainer;
/**
* BasicJDBCContainer implementation
@@ -90,7 +89,7 @@
}
public void release(ResultSet resultSet) {
- log.trace( "releasing result set [" + resultSet + "]" );
+ log.trace( "releasing result set [{}]", resultSet );
Statement statement;
try {
statement = resultSet.getStatement();
@@ -112,8 +111,12 @@
return !xref.isEmpty();
}
- public void close() {
- log.trace( "closing JDBC container [" + this + "]" );
+ public void releaseResources() {
+ log.trace( "releasing JDBC container resources [{}]", this );
+ cleanup();
+ }
+
+ private void cleanup() {
Iterator statementIterator = xref.keySet().iterator();
while ( statementIterator.hasNext() ) {
final Statement statement = ( Statement ) statementIterator.next();
@@ -131,10 +134,15 @@
xref.clear();
}
+ public void close() {
+ log.trace( "closing JDBC container [{}]", this );
+ cleanup();
+ }
+
protected void close(Statement statement) {
log.trace( "closing prepared statement [" + statement + "]" );
try {
- // if we are unable to "clan" the prepared statement,
+ // if we are unable to "clean" the prepared statement,
// we do not close it
try {
if ( statement.getMaxRows() != 0 ) {
@@ -146,13 +154,13 @@
}
catch( SQLException sqle ) {
// there was a problem "cleaning" the prepared statement
- log.debug( "Exception clearing maxRows/queryTimeout [" + sqle.getMessage() + "]" );
+ log.debug( "Exception clearing maxRows/queryTimeout [{}]", sqle.getMessage() );
return; // EARLY EXIT!!!
}
statement.close();
}
catch( SQLException sqle ) {
- log.debug( "Unable to release statement [" + sqle.getMessage() + "]" );
+ log.debug( "Unable to release statement [{}]", sqle.getMessage() );
}
}
@@ -162,7 +170,7 @@
resultSet.close();
}
catch( SQLException e ) {
- log.debug( "Unable to release result set [" + e.getMessage() + "]" );
+ log.debug( "Unable to release result set [{}]", e.getMessage() );
}
}
}
Modified: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -15,13 +15,28 @@
*/
package org.hibernate.jdbc.impl;
+import java.sql.Connection;
+
/**
- * Observer contract
+ * An observer of logical connection events.
*
* @author Steve Ebersole
*/
public interface ConnectionObserver {
- public void physicalConnectionObtained();
+ /**
+ * A physical connection was obtained.
+ *
+ * @param connection The physical connection just obtained.
+ */
+ public void physicalConnectionObtained(Connection connection);
+
+ /**
+ * A physical connection was released.
+ */
public void physicalConnectionReleased();
+
+ /**
+ * The logical connection was closed.
+ */
public void logicalConnectionClosed();
}
Modified: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -27,9 +27,8 @@
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException;
import org.hibernate.JDBCException;
-import org.hibernate.jdbc.impl.ConnectionObserver;
+import org.hibernate.jdbc.JDBCServices;
import org.hibernate.jdbc.JDBCContainer;
-import org.hibernate.jdbc.JDBCServices;
/**
* LogicalConnectionImpl implementation
@@ -44,6 +43,7 @@
private final JDBCServices jdbcServices;
private final JDBCContainer jdbcContainer;
private final List observers = new ArrayList();
+ private boolean releasesEnabled = true;
private final boolean isUserSuppliedConnection;
private boolean isClosed;
@@ -52,6 +52,11 @@
Connection userSuppliedConnection,
ConnectionReleaseMode connectionReleaseMode,
JDBCServices jdbcServices) {
+ if ( connectionReleaseMode == ConnectionReleaseMode.AFTER_STATEMENT &&
+ ! jdbcServices.getConnectionProvider().supportsAggressiveRelease() ) {
+ log.debug( "connection provider reports to not support aggressive release; overriding" );
+ connectionReleaseMode = ConnectionReleaseMode.AFTER_TRANSACTION;
+ }
this.physicalConnection = userSuppliedConnection;
this.connectionReleaseMode = connectionReleaseMode;
this.jdbcServices = jdbcServices;
@@ -70,13 +75,6 @@
/**
* {@inheritDoc}
*/
- public ConnectionReleaseMode getConnectionReleaseMode() {
- return connectionReleaseMode;
- }
-
- /**
- * {@inheritDoc}
- */
public JDBCContainer getJdbcContainer() {
return jdbcContainer;
}
@@ -126,12 +124,12 @@
log.trace( "closing logical connection" );
Connection c = physicalConnection;
if ( !isUserSuppliedConnection && physicalConnection != null ) {
+ jdbcContainer.close();
releaseConnection();
}
// not matter what
physicalConnection = null;
isClosed = true;
- jdbcContainer.close();
for ( Iterator itr = observers.iterator(); itr.hasNext(); ) {
( ( ConnectionObserver ) itr.next() ).logicalConnectionClosed();
}
@@ -152,15 +150,56 @@
// }
/**
+ * {@inheritDoc}
+ */
+ public ConnectionReleaseMode getConnectionReleaseMode() {
+ return connectionReleaseMode;
+ }
+
+ public void afterStatementExecution() {
+ log.trace( "starting after statement execution processing [{}]", connectionReleaseMode );
+ if ( connectionReleaseMode == ConnectionReleaseMode.AFTER_STATEMENT ) {
+ if ( ! releasesEnabled ) {
+ log.debug( "skipping aggressive release due to manual disabling" );
+ return;
+ }
+ if ( jdbcContainer.hasRegisteredResources() ) {
+ log.debug( "skipping aggressive release due to registered resources" );
+ return;
+ }
+ releaseConnection();
+ }
+ }
+
+ public void afterTransaction() {
+ if ( connectionReleaseMode == ConnectionReleaseMode.AFTER_STATEMENT ||
+ connectionReleaseMode == ConnectionReleaseMode.AFTER_TRANSACTION ) {
+ if ( jdbcContainer.hasRegisteredResources() ) {
+ log.info( "forcing container resource cleanup on transaction completion" );
+ jdbcContainer.releaseResources();
+ }
+ aggressiveRelease();
+ }
+ }
+
+ public void disableReleases() {
+ log.trace( "disabling releases" );
+ releasesEnabled = false;
+ }
+
+ public void enableReleases() {
+ log.trace( "(re)enabling releases" );
+ releasesEnabled = true;
+ afterStatementExecution();
+ }
+
+ /**
* Force aggresive release of the underlying connection.
*/
public void aggressiveRelease() {
if ( isUserSuppliedConnection ) {
log.debug( "cannot aggresively release user-supplied connection; skipping" );
}
- else if ( ! getJdbcServices().getConnectionProvider().supportsAggressiveRelease() ) {
- log.debug( "connection provider reports to not support aggreswsive release; skipping" );
- }
else {
log.debug( "aggressively releasing JDBC connection" );
if ( physicalConnection != null ) {
@@ -171,7 +210,6 @@
/**
- * Obtains a physical connection from the
* Pysically opens a JDBC Connection.
*
* @throws JDBCException Indicates problem opening a connection
@@ -181,7 +219,7 @@
try {
physicalConnection = getJdbcServices().getConnectionProvider().getConnection();
for ( Iterator itr = observers.iterator(); itr.hasNext(); ) {
- ( ( ConnectionObserver ) itr.next() ).physicalConnectionObtained();
+ ( ( ConnectionObserver ) itr.next() ).physicalConnectionObtained( physicalConnection );
}
log.debug( "obtained JDBC connection" );
}
@@ -191,9 +229,9 @@
}
/**
- * Releases the physical JDBC connection back to the provider.
+ * Physically closes the JDBC Connection.
*
- * @throws JDBCException Indicates problem releasing the connection
+ * @throws JDBCException Indicates problem closing a connection
*/
private void releaseConnection() throws JDBCException {
log.debug( "releasing JDBC connection" );
@@ -201,11 +239,11 @@
if ( !physicalConnection.isClosed() ) {
getJdbcServices().getExceptionHelper().logAndClearWarnings( physicalConnection );
}
- getJdbcServices().getConnectionProvider().closeConnection( physicalConnection );
- physicalConnection = null;
for ( Iterator itr = observers.iterator(); itr.hasNext(); ) {
( ( ConnectionObserver ) itr.next() ).physicalConnectionReleased();
}
+ getJdbcServices().getConnectionProvider().closeConnection( physicalConnection );
+ physicalConnection = null;
log.debug( "released JDBC connection" );
}
catch (SQLException sqle) {
Modified: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -16,24 +16,65 @@
package org.hibernate.jdbc.impl;
import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.jdbc.JDBCContainer;
import org.hibernate.jdbc.JDBCServices;
-import org.hibernate.jdbc.JDBCContainer;
-import org.hibernate.jdbc.impl.ConnectionObserver;
import org.hibernate.jdbc.LogicalConnection;
/**
- * LogicalConnectionImplementor implementation
+ * The "internal" contract for LogicalConnection
*
* @author Steve Ebersole
*/
public interface LogicalConnectionImplementor extends LogicalConnection {
+ /**
+ * Obtains the JDBC services associated with this logical connection.
+ *
+ * @return JDBC services
+ */
public JDBCServices getJdbcServices();
- public ConnectionReleaseMode getConnectionReleaseMode();
-
+ /**
+ * Obtains the JDBC object container associated with this logical connection.
+ *
+ * @return The JDBC object container.
+ */
public JDBCContainer getJdbcContainer();
+ /**
+ * Add an observer interested in notification of connection events.
+ *
+ * @param observer The observer.
+ */
public void addObserver(ConnectionObserver observer);
- public void aggressiveRelease();
+ /**
+ * The release mode under which this logical connection is operating.
+ *
+ * @return the release mode.
+ */
+ public ConnectionReleaseMode getConnectionReleaseMode();
+
+ /**
+ * Used to signify that a statement has completed execution which may
+ * indicate that this logical connection need to perform an
+ * aggressive release of its physical connection.
+ */
+ public void afterStatementExecution();
+
+ /**
+ * Used to signify that a transaction has completed which may indicate
+ * that this logical connection need to perform an aggressive release
+ * of its physical connection.
+ */
+ public void afterTransaction();
+
+ /**
+ * Manually (and termporarily) circumvent aggressive release processing.
+ */
+ public void disableReleases();
+
+ /**
+ * Re enable aggressive release processing (after a prior {@link #disableReleases()} call.
+ */
+ public void enableReleases();
}
Modified: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/ExceptionHelper.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/ExceptionHelper.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/ExceptionHelper.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -24,10 +24,12 @@
import org.hibernate.JDBCException;
import org.hibernate.exception.SQLExceptionConverter;
+import org.hibernate.exception.SQLStateConverter;
+import org.hibernate.exception.ViolatedConstraintNameExtracter;
import org.hibernate.util.StringHelper;
/**
- * ExceptionHelper implementation
+ * Helper for handling SQLExceptions in various manners.
*
* @author Steve Ebersole
*/
@@ -35,31 +37,83 @@
public static final String DEFAULT_EXCEPTION_MSG = "SQL Exception";
public static final String DEFAULT_WARNING_MSG = "SQL Warning";
+ public static final SQLExceptionConverter DEFAULT_CONVERTER = new SQLStateConverter(
+ new ViolatedConstraintNameExtracter() {
+ public String extractConstraintName(SQLException e) {
+ return null;
+ }
+ }
+ );
+
private static final Logger log = LoggerFactory.getLogger( ExceptionHelper.class );
private SQLExceptionConverter sqlExceptionConverter;
+ /**
+ * Create an exception helper with a default exception converter.
+ */
+ public ExceptionHelper() {
+ sqlExceptionConverter = DEFAULT_CONVERTER;
+ }
+
+ /**
+ * Create an exception helper with a specific exception converter.
+ *
+ * @param sqlExceptionConverter The exception converter to use.
+ */
public ExceptionHelper(SQLExceptionConverter sqlExceptionConverter) {
this.sqlExceptionConverter = sqlExceptionConverter;
}
+ /**
+ * Access the current exception converter being used internally.
+ *
+ * @return The current exception converter.
+ */
public SQLExceptionConverter getSqlExceptionConverter() {
return sqlExceptionConverter;
}
+ /**
+ * Inject the exception converter to use.
+ * <p/>
+ * NOTE : <tt>null</tt> is allowed and signifies to use the default.
+ *
+ * @param sqlExceptionConverter The converter to use.
+ */
public void setSqlExceptionConverter(SQLExceptionConverter sqlExceptionConverter) {
- this.sqlExceptionConverter = sqlExceptionConverter;
+ this.sqlExceptionConverter = ( sqlExceptionConverter == null ? DEFAULT_CONVERTER : sqlExceptionConverter );
}
+ /**
+ * Convert an SQLException using the current converter, doing some logging first.
+ *
+ * @param sqle The exception to convert
+ * @param message An error message.
+ * @return The converted exception
+ */
public JDBCException convert(SQLException sqle, String message) {
return convert( sqle, message, "n/a" );
}
+ /**
+ * Convert an SQLException using the current converter, doing some logging first.
+ *
+ * @param sqle The exception to convert
+ * @param message An error message.
+ * @param sql The SQL being executed when the exception occurred
+ * @return The converted exception
+ */
public JDBCException convert(SQLException sqle, String message, String sql) {
logExceptions( sqle, message + " [" + sql + "]" );
return sqlExceptionConverter.convert( sqle, message, sql );
}
+ /**
+ * Log any {@link SQLWarning}s registered with the connection.
+ *
+ * @param connection The connection to check for warnings.
+ */
public void logAndClearWarnings(Connection connection) {
if ( log.isWarnEnabled() ) {
try {
@@ -80,10 +134,21 @@
}
+ /**
+ * Log the given (and any nested) warning.
+ *
+ * @param warning The warning
+ */
public void logWarnings(SQLWarning warning) {
logWarnings( warning, null );
}
+ /**
+ * Log the given (and any nested) warning.
+ *
+ * @param warning The warning
+ * @param message The message text to use as a preamble.
+ */
public void logWarnings(SQLWarning warning, String message) {
if ( log.isWarnEnabled() ) {
if ( log.isDebugEnabled() && warning != null ) {
@@ -103,25 +168,36 @@
}
}
- public void logExceptions(SQLException ex) {
- logExceptions( ex, null );
+ /**
+ * Log the given (and any nested) exception.
+ *
+ * @param sqlException The exception to log
+ */
+ public void logExceptions(SQLException sqlException) {
+ logExceptions( sqlException, null );
}
- public void logExceptions(SQLException ex, String message) {
+ /**
+ * Log the given (and any nested) exception.
+ *
+ * @param sqlException The exception to log
+ * @param message The message text to use as a preamble.
+ */
+ public void logExceptions(SQLException sqlException, String message) {
if ( log.isErrorEnabled() ) {
if ( log.isDebugEnabled() ) {
message = StringHelper.isNotEmpty( message ) ? message : DEFAULT_EXCEPTION_MSG;
- log.debug( message, ex );
+ log.debug( message, sqlException );
}
- while ( ex != null ) {
+ while ( sqlException != null ) {
StringBuffer buf = new StringBuffer( 30 )
.append( "SQL Error: " )
- .append( ex.getErrorCode() )
+ .append( sqlException.getErrorCode() )
.append( ", SQLState: " )
- .append( ex.getSQLState() );
+ .append( sqlException.getSQLState() );
log.warn( buf.toString() );
- log.error( ex.getMessage() );
- ex = ex.getNextException();
+ log.error( sqlException.getMessage() );
+ sqlException = sqlException.getNextException();
}
}
}
Modified: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -28,11 +28,19 @@
*/
public class ConnectionProviderBuilder {
public static ConnectionProvider buildConnectionProvider() {
+ return buildConnectionProvider( false );
+ }
+
+ public static ConnectionProvider buildConnectionProvider(final boolean allowAggressiveRelease) {
Properties props = new Properties( null );
props.put( Environment.DRIVER, "org.hsqldb.jdbcDriver" );
props.put( Environment.URL, "jdbc:hsqldb:mem:target/test/db/hsqldb/hibernate" );
props.put( Environment.USER, "sa" );
- DriverManagerConnectionProvider connectionProvider = new DriverManagerConnectionProvider();
+ DriverManagerConnectionProvider connectionProvider = new DriverManagerConnectionProvider() {
+ public boolean supportsAggressiveRelease() {
+ return allowAggressiveRelease;
+ }
+ };
connectionProvider.configure( props );
return connectionProvider;
}
Added: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/AggressiveReleaseTest.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/AggressiveReleaseTest.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/AggressiveReleaseTest.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -0,0 +1,268 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.fail;
+
+import org.hibernate.jdbc.impl.ConnectionObserver;
+import org.hibernate.jdbc.impl.LogicalConnectionImpl;
+import org.hibernate.ConnectionReleaseMode;
+
+/**
+ * AggressiveReleaseTest implementation
+ *
+ * @author Steve Ebersole
+ */
+public class AggressiveReleaseTest {
+ private static final Logger log = LoggerFactory.getLogger( AggressiveReleaseTest.class );
+ private TestingServiceImpl services = new TestingServiceImpl();
+
+ private static class ConnectionCounter implements ConnectionObserver {
+ public int obtainCount = 0;
+ public int releaseCount = 0;
+
+ public void physicalConnectionObtained(Connection connection) {
+ obtainCount++;
+ }
+
+ public void physicalConnectionReleased() {
+ releaseCount++;
+ }
+
+ public void logicalConnectionClosed() {
+ }
+ }
+
+ @BeforeClass
+ protected void create() {
+ log.debug( "starting @BeforeClass" );
+ services.prepare( true );
+ }
+
+ @AfterClass
+ protected void destroy() {
+ services.release();
+ }
+
+ @BeforeMethod
+ protected void setUpSchema() throws SQLException {
+ log.debug( "starting @BeforeMethod" );
+ Connection connection = null;
+ Statement stmnt = null;
+ try {
+ connection = services.getConnectionProvider().getConnection();
+ stmnt = connection.createStatement();
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
+ }
+ finally {
+ if ( stmnt != null ) {
+ try {
+ stmnt.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close statement used to set up schema", ignore );
+ }
+ }
+ if ( connection != null ) {
+ try {
+ connection.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close connection used to set up schema", ignore );
+ }
+ }
+ }
+ }
+
+ @AfterMethod
+ protected void tearDownSchema() throws SQLException {
+ Connection connection = null;
+ Statement stmnt = null;
+ try {
+ connection = services.getConnectionProvider().getConnection();
+ stmnt = connection.createStatement();
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ }
+ finally {
+ if ( stmnt != null ) {
+ try {
+ stmnt.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close statement used to set up schema", ignore );
+ }
+ }
+ if ( connection != null ) {
+ try {
+ connection.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close connection used to set up schema", ignore );
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testBasicRelease() {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services );
+ Connection proxiedConnection = new ConnectionDelegate( logicalConnection );
+ ConnectionCounter observer = new ConnectionCounter();
+ logicalConnection.addObserver( observer );
+
+ try {
+ PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ ps.execute();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 0, observer.releaseCount );
+ ps.close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ finally {
+ logicalConnection.close();
+ }
+
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ }
+
+ @Test
+ public void testReleaseCircumventedByHeldResources() {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services );
+ Connection proxiedConnection = new ConnectionDelegate( logicalConnection );
+ ConnectionCounter observer = new ConnectionCounter();
+ logicalConnection.addObserver( observer );
+
+ try {
+ PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ ps.execute();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 0, observer.releaseCount );
+ ps.close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // open a result set and hold it open...
+ ps = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
+ ps.executeQuery();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // open a second result set
+ PreparedStatement ps2 = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
+ ps2.execute();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+ // and close it...
+ ps2.close();
+ // the release should be circumvented...
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // let the close of the logical connection below release all resources (hopefully)...
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ finally {
+ logicalConnection.close();
+ }
+
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 2, observer.releaseCount );
+ }
+
+ @Test
+ public void testReleaseCircumventedManually() {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services );
+ Connection proxiedConnection = new ConnectionDelegate( logicalConnection );
+ ConnectionCounter observer = new ConnectionCounter();
+ logicalConnection.addObserver( observer );
+
+ try {
+ PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ ps.execute();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 0, observer.releaseCount );
+ ps.close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // disable releases...
+ logicalConnection.disableReleases();
+
+ // open a result set...
+ ps = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
+ ps.executeQuery();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+ // and close it...
+ ps.close();
+ // the release should be circumvented...
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // let the close of the logical connection below release all resources (hopefully)...
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ finally {
+ logicalConnection.close();
+ }
+
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 2, observer.releaseCount );
+ }
+}
Modified: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -41,7 +41,7 @@
@BeforeClass
protected void create() {
- services.prepare();
+ services.prepare( false );
}
@AfterClass
@@ -50,18 +50,29 @@
}
@Test
+ public void testExceptionHandling() {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ ConnectionDelegate connection = new ConnectionDelegate( logicalConnection );
+ try {
+ connection.prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery();
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ catch ( JDBCException ok ) {
+ // expected outcome
+ }
+ finally {
+ logicalConnection.close();
+ }
+ }
+
+ @Test
public void testBasicJdbcUsage() throws JDBCException {
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
ConnectionDelegate connection = new ConnectionDelegate( logicalConnection );
try {
- try {
- connection.prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery();
- }
- catch ( JDBCException ok ) {
- // expected outcome
- }
-
Statement stmnt = connection.createStatement();
stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
Modified: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java 2007-08-16 19:02:03 UTC (rev 13928)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java 2007-08-16 19:34:04 UTC (rev 13929)
@@ -15,8 +15,6 @@
*/
package org.hibernate.jdbc.delegation;
-import java.sql.SQLException;
-
import org.hibernate.jdbc.JDBCServices;
import org.hibernate.jdbc.JDBCContainerBuilder;
import org.hibernate.jdbc.ConnectionProviderBuilder;
@@ -24,8 +22,6 @@
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
@@ -38,18 +34,10 @@
private JDBCContainerBuilder jdbcContainerBuilder;
private ExceptionHelper exceptionHelper;
- public void prepare() {
- connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
+ 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;
- }
- }
- )
- );
+ exceptionHelper = new ExceptionHelper();
jdbcContainerBuilder = new JDBCContainerBuilder() {
public JDBCContainer buildJdbcContainer() {
return new DelegateJDBCContainer( exceptionHelper );
16 years, 8 months
Hibernate SVN: r13928 - in sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc: proxy and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-16 15:02:03 -0400 (Thu, 16 Aug 2007)
New Revision: 13928
Added:
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/AggressiveReleaseTest.java
Modified:
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.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
Log:
tests of after_statement release
Modified: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java 2007-08-16 12:46:28 UTC (rev 13927)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java 2007-08-16 19:02:03 UTC (rev 13928)
@@ -28,11 +28,19 @@
*/
public class ConnectionProviderBuilder {
public static ConnectionProvider buildConnectionProvider() {
+ return buildConnectionProvider( false );
+ }
+
+ public static ConnectionProvider buildConnectionProvider(final boolean allowAggressiveRelease) {
Properties props = new Properties( null );
props.put( Environment.DRIVER, "org.hsqldb.jdbcDriver" );
props.put( Environment.URL, "jdbc:hsqldb:mem:target/test/db/hsqldb/hibernate" );
props.put( Environment.USER, "sa" );
- DriverManagerConnectionProvider connectionProvider = new DriverManagerConnectionProvider();
+ DriverManagerConnectionProvider connectionProvider = new DriverManagerConnectionProvider() {
+ public boolean supportsAggressiveRelease() {
+ return allowAggressiveRelease;
+ }
+ };
connectionProvider.configure( props );
return connectionProvider;
}
Added: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/AggressiveReleaseTest.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/AggressiveReleaseTest.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/AggressiveReleaseTest.java 2007-08-16 19:02:03 UTC (rev 13928)
@@ -0,0 +1,268 @@
+/*
+ * 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.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.jdbc.impl.ConnectionObserver;
+import org.hibernate.jdbc.impl.LogicalConnectionImpl;
+
+/**
+ * AggressiveReleaseTest implementation
+ *
+ * @author Steve Ebersole
+ */
+public class AggressiveReleaseTest {
+ private static final Logger log = LoggerFactory.getLogger( AggressiveReleaseTest.class );
+ private TestingServiceImpl services = new TestingServiceImpl();
+
+ private static class ConnectionCounter implements ConnectionObserver {
+ public int obtainCount = 0;
+ public int releaseCount = 0;
+
+ public void physicalConnectionObtained(Connection connection) {
+ obtainCount++;
+ }
+
+ public void physicalConnectionReleased() {
+ releaseCount++;
+ }
+
+ public void logicalConnectionClosed() {
+ }
+ }
+
+ @BeforeClass
+ protected void create() {
+ log.debug( "starting @BeforeClass" );
+ services.prepare( true );
+ }
+
+ @AfterClass
+ protected void destroy() {
+ services.release();
+ }
+
+ @BeforeMethod
+ protected void setUpSchema() throws SQLException {
+ log.debug( "starting @BeforeMethod" );
+ Connection connection = null;
+ Statement stmnt = null;
+ try {
+ connection = services.getConnectionProvider().getConnection();
+ stmnt = connection.createStatement();
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
+ }
+ finally {
+ if ( stmnt != null ) {
+ try {
+ stmnt.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close statement used to set up schema", ignore );
+ }
+ }
+ if ( connection != null ) {
+ try {
+ connection.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close connection used to set up schema", ignore );
+ }
+ }
+ }
+ }
+
+ @AfterMethod
+ protected void tearDownSchema() throws SQLException {
+ Connection connection = null;
+ Statement stmnt = null;
+ try {
+ connection = services.getConnectionProvider().getConnection();
+ stmnt = connection.createStatement();
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ }
+ finally {
+ if ( stmnt != null ) {
+ try {
+ stmnt.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close statement used to set up schema", ignore );
+ }
+ }
+ if ( connection != null ) {
+ try {
+ connection.close();
+ }
+ catch ( SQLException ignore ) {
+ log.warn( "could not close connection used to set up schema", ignore );
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testBasicRelease() {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services );
+ Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
+ ConnectionCounter observer = new ConnectionCounter();
+ logicalConnection.addObserver( observer );
+
+ try {
+ PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ ps.execute();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 0, observer.releaseCount );
+ ps.close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ finally {
+ logicalConnection.close();
+ }
+
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ }
+
+ @Test
+ public void testReleaseCircumventedByHeldResources() {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services );
+ Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
+ ConnectionCounter observer = new ConnectionCounter();
+ logicalConnection.addObserver( observer );
+
+ try {
+ PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ ps.execute();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 0, observer.releaseCount );
+ ps.close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // open a result set and hold it open...
+ ps = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
+ ps.executeQuery();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // open a second result set
+ PreparedStatement ps2 = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
+ ps2.execute();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+ // and close it...
+ ps2.close();
+ // the release should be circumvented...
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // let the close of the logical connection below release all resources (hopefully)...
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ finally {
+ logicalConnection.close();
+ }
+
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 2, observer.releaseCount );
+ }
+
+ @Test
+ public void testReleaseCircumventedManually() {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_STATEMENT, services );
+ Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
+ ConnectionCounter observer = new ConnectionCounter();
+ logicalConnection.addObserver( observer );
+
+ try {
+ PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ ps.execute();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 0, observer.releaseCount );
+ ps.close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 1, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // disable releases...
+ logicalConnection.disableReleases();
+
+ // open a result set...
+ ps = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
+ ps.executeQuery();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+ // and close it...
+ ps.close();
+ // the release should be circumvented...
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 1, observer.releaseCount );
+
+ // let the close of the logical connection below release all resources (hopefully)...
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ finally {
+ logicalConnection.close();
+ }
+
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ assertEquals( 2, observer.obtainCount );
+ assertEquals( 2, observer.releaseCount );
+ }
+}
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-16 12:46:28 UTC (rev 13927)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/BasicConnectionProxyTest.java 2007-08-16 19:02:03 UTC (rev 13928)
@@ -47,7 +47,7 @@
@BeforeClass
protected void create() {
- services.prepare();
+ services.prepare( false );
}
@AfterClass
@@ -56,18 +56,29 @@
}
@Test
+ public void testExceptionHandling() {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
+ try {
+ proxiedConnection.prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery();
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ catch ( JDBCException ok ) {
+ // expected outcome
+ }
+ finally {
+ logicalConnection.close();
+ }
+ }
+
+ @Test
public void testBasicJdbcUsage() throws JDBCException {
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
try {
- try {
- proxiedConnection.prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery();
- }
- catch ( JDBCException ok ) {
- // expected outcome
- }
-
Statement stmnt = proxiedConnection.createStatement();
stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
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-16 12:46:28 UTC (rev 13927)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/TestingServiceImpl.java 2007-08-16 19:02:03 UTC (rev 13928)
@@ -38,8 +38,8 @@
private JDBCContainerBuilder jdbcContainerBuilder;
private ExceptionHelper exceptionHelper;
- public void prepare() {
- connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
+ public void prepare(boolean allowAggressiveRelease) {
+ connectionProvider = ConnectionProviderBuilder.buildConnectionProvider( allowAggressiveRelease );
sqlStatementLogger = new SQLStatementLogger( true );
exceptionHelper = new ExceptionHelper(
new SQLStateConverter(
16 years, 8 months