HHH-7902 Replace JDBC proxies with a set of contracts/helpers
HHH-7902 Merged JdbcResourceRegistry into JdbcCoordinator. Parts of LogicalConnection moved into JdbcCoordinator as well. HHH-7902 Replaced Statement#close and ResultSet#close calls with JdbcCoordinator#release HHH-7902 Enforced the use of StatementPreparer, instead of Connection HHH-7902 ResultSetExtractor. Replaced all instances of execute, executeQuery, executeUpdate, etc. HHH-7902 Refactored AbstractReturningDelegate to give access to jdbcCoordinator HHH-7902 Corrected test failures HHH-7902 Removed resource registry use from JdbcIsolation workers HHH-7902 Corrected a few bugs in JdbcCoordinator and ResultSetExtractor. HHH-7902 ResultSetExtractor -> ResultSetReturn. Reworked proxy tests to test the new APIs.
This commit is contained in:
parent
2fc81e9d98
commit
f70234c5ee
|
@ -85,7 +85,7 @@ public class PessimisticReadSelectLockingStrategy extends AbstractSelectLockingS
|
|||
);
|
||||
}
|
||||
|
||||
ResultSet rs = st.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
|
||||
try {
|
||||
if ( !rs.next() ) {
|
||||
if ( factory.getStatistics().isStatisticsEnabled() ) {
|
||||
|
@ -96,11 +96,11 @@ public class PessimisticReadSelectLockingStrategy extends AbstractSelectLockingS
|
|||
}
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ public class PessimisticReadUpdateLockingStrategy implements LockingStrategy {
|
|||
lockable.getVersionType().nullSafeSet( st, version, offset, session );
|
||||
}
|
||||
|
||||
int affected = st.executeUpdate();
|
||||
int affected = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st );
|
||||
if ( affected < 0 ) { // todo: should this instead check for exactly one row modified?
|
||||
if (factory.getStatistics().isStatisticsEnabled()) {
|
||||
factory.getStatisticsImplementor().optimisticFailure( lockable.getEntityName() );
|
||||
|
@ -114,7 +114,7 @@ public class PessimisticReadUpdateLockingStrategy implements LockingStrategy {
|
|||
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ public class PessimisticWriteSelectLockingStrategy extends AbstractSelectLocking
|
|||
);
|
||||
}
|
||||
|
||||
ResultSet rs = st.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
|
||||
try {
|
||||
if ( !rs.next() ) {
|
||||
if ( factory.getStatistics().isStatisticsEnabled() ) {
|
||||
|
@ -95,11 +95,11 @@ public class PessimisticWriteSelectLockingStrategy extends AbstractSelectLocking
|
|||
}
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
|
|
|
@ -103,7 +103,7 @@ public class PessimisticWriteUpdateLockingStrategy implements LockingStrategy {
|
|||
lockable.getVersionType().nullSafeSet( st, version, offset, session );
|
||||
}
|
||||
|
||||
int affected = st.executeUpdate();
|
||||
int affected = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st );
|
||||
if ( affected < 0 ) { // todo: should this instead check for exactly one row modified?
|
||||
if (factory.getStatistics().isStatisticsEnabled()) {
|
||||
factory.getStatisticsImplementor().optimisticFailure( lockable.getEntityName() );
|
||||
|
@ -113,7 +113,7 @@ public class PessimisticWriteUpdateLockingStrategy implements LockingStrategy {
|
|||
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
|
|
|
@ -85,7 +85,7 @@ public class SelectLockingStrategy extends AbstractSelectLockingStrategy {
|
|||
);
|
||||
}
|
||||
|
||||
ResultSet rs = st.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
|
||||
try {
|
||||
if ( !rs.next() ) {
|
||||
if ( factory.getStatistics().isStatisticsEnabled() ) {
|
||||
|
@ -96,11 +96,11 @@ public class SelectLockingStrategy extends AbstractSelectLockingStrategy {
|
|||
}
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ public class UpdateLockingStrategy implements LockingStrategy {
|
|||
lockable.getVersionType().nullSafeSet( st, version, offset, session );
|
||||
}
|
||||
|
||||
int affected = st.executeUpdate();
|
||||
int affected = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st );
|
||||
if ( affected < 0 ) {
|
||||
if (factory.getStatistics().isStatisticsEnabled()) {
|
||||
factory.getStatisticsImplementor().optimisticFailure( lockable.getEntityName() );
|
||||
|
@ -116,7 +116,7 @@ public class UpdateLockingStrategy implements LockingStrategy {
|
|||
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
2
hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/AbstractBatchImpl.java
Executable file → Normal file
2
hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/AbstractBatchImpl.java
Executable file → Normal file
|
@ -161,7 +161,7 @@ public abstract class AbstractBatchImpl implements Batch {
|
|||
for ( PreparedStatement statement : getStatements().values() ) {
|
||||
try {
|
||||
statement.clearBatch();
|
||||
statement.close();
|
||||
jdbcCoordinator.release( statement );
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
LOG.unableToReleaseBatchStatement();
|
||||
|
|
|
@ -27,11 +27,10 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.engine.jdbc.batch.spi.BatchKey;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* An implementation of {@link org.hibernate.engine.jdbc.batch.spi.Batch} which does not perform batching. It simply
|
||||
|
@ -43,8 +42,11 @@ public class NonBatchingBatch extends AbstractBatchImpl {
|
|||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, NonBatchingBatch.class.getName() );
|
||||
|
||||
private JdbcCoordinator jdbcCoordinator;
|
||||
|
||||
protected NonBatchingBatch(BatchKey key, JdbcCoordinator jdbcCoordinator) {
|
||||
super( key, jdbcCoordinator );
|
||||
this.jdbcCoordinator = jdbcCoordinator;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,14 +55,9 @@ public class NonBatchingBatch extends AbstractBatchImpl {
|
|||
for ( Map.Entry<String,PreparedStatement> entry : getStatements().entrySet() ) {
|
||||
try {
|
||||
final PreparedStatement statement = entry.getValue();
|
||||
final int rowCount = statement.executeUpdate();
|
||||
final int rowCount = jdbcCoordinator.getResultSetReturn().executeUpdate( statement );
|
||||
getKey().getExpectation().verifyOutcome( rowCount, statement, 0 );
|
||||
try {
|
||||
statement.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
LOG.debug( "Unable to close non-batched batch statement", e );
|
||||
}
|
||||
jdbcCoordinator.release( statement );
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
LOG.debug( "SQLException escaped proxy", e );
|
||||
|
|
|
@ -27,17 +27,25 @@ import java.io.IOException;
|
|||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.TransactionException;
|
||||
import org.hibernate.engine.jdbc.batch.spi.Batch;
|
||||
import org.hibernate.engine.jdbc.batch.spi.BatchBuilder;
|
||||
import org.hibernate.engine.jdbc.batch.spi.BatchKey;
|
||||
import org.hibernate.engine.jdbc.spi.InvalidatableWrapper;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcWrapper;
|
||||
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
||||
import org.hibernate.engine.jdbc.spi.ResultSetReturn;
|
||||
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
|
||||
import org.hibernate.engine.jdbc.spi.StatementPreparer;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -48,6 +56,8 @@ import org.hibernate.engine.transaction.spi.TransactionEnvironment;
|
|||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.jdbc.WorkExecutor;
|
||||
import org.hibernate.jdbc.WorkExecutorVisitable;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.jboss.logging.Logger.Level;
|
||||
|
||||
/**
|
||||
* Standard Hibernate implementation of {@link JdbcCoordinator}
|
||||
|
@ -55,22 +65,34 @@ import org.hibernate.jdbc.WorkExecutorVisitable;
|
|||
* IMPL NOTE : Custom serialization handling!
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public class JdbcCoordinatorImpl implements JdbcCoordinator {
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
|
||||
CoreMessageLogger.class, JdbcCoordinatorImpl.class.getName()
|
||||
);
|
||||
|
||||
private transient TransactionCoordinatorImpl transactionCoordinator;
|
||||
private transient TransactionCoordinator transactionCoordinator;
|
||||
private final transient LogicalConnectionImpl logicalConnection;
|
||||
|
||||
private transient Batch currentBatch;
|
||||
|
||||
private transient long transactionTimeOutInstant = -1;
|
||||
|
||||
private final HashMap<Statement,Set<ResultSet>> xref = new HashMap<Statement,Set<ResultSet>>();
|
||||
private final Set<ResultSet> unassociatedResultSets = new HashSet<ResultSet>();
|
||||
private final SqlExceptionHelper exceptionHelper;
|
||||
|
||||
private Statement lastQuery;
|
||||
|
||||
/**
|
||||
* If true, manually (and temporarily) circumvent aggressive release processing.
|
||||
*/
|
||||
private boolean releasesEnabled = true;
|
||||
|
||||
public JdbcCoordinatorImpl(
|
||||
Connection userSuppliedConnection,
|
||||
TransactionCoordinatorImpl transactionCoordinator) {
|
||||
TransactionCoordinator transactionCoordinator) {
|
||||
this.transactionCoordinator = transactionCoordinator;
|
||||
this.logicalConnection = new LogicalConnectionImpl(
|
||||
userSuppliedConnection,
|
||||
|
@ -78,10 +100,20 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
|
|||
transactionCoordinator.getTransactionContext().getTransactionEnvironment().getJdbcServices(),
|
||||
transactionCoordinator.getTransactionContext().getJdbcConnectionAccess()
|
||||
);
|
||||
this.exceptionHelper = logicalConnection.getJdbcServices().getSqlExceptionHelper();
|
||||
}
|
||||
|
||||
public JdbcCoordinatorImpl(
|
||||
LogicalConnectionImpl logicalConnection,
|
||||
TransactionCoordinator transactionCoordinator) {
|
||||
this.transactionCoordinator = transactionCoordinator;
|
||||
this.logicalConnection = logicalConnection;
|
||||
this.exceptionHelper = logicalConnection.getJdbcServices().getSqlExceptionHelper();
|
||||
}
|
||||
|
||||
private JdbcCoordinatorImpl(LogicalConnectionImpl logicalConnection) {
|
||||
this.logicalConnection = logicalConnection;
|
||||
this.exceptionHelper = logicalConnection.getJdbcServices().getSqlExceptionHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -106,7 +138,7 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
|
|||
return sessionFactory().getServiceRegistry().getService( BatchBuilder.class );
|
||||
}
|
||||
|
||||
private SqlExceptionHelper sqlExceptionHelper() {
|
||||
public SqlExceptionHelper sqlExceptionHelper() {
|
||||
return transactionEnvironment().getJdbcServices().getSqlExceptionHelper();
|
||||
}
|
||||
|
||||
|
@ -116,7 +148,7 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
|
|||
@Override
|
||||
public void flushBeginning() {
|
||||
if ( flushDepth == 0 ) {
|
||||
logicalConnection.disableReleases();
|
||||
releasesEnabled = false;
|
||||
}
|
||||
flushDepth++;
|
||||
}
|
||||
|
@ -128,16 +160,20 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
|
|||
throw new HibernateException( "Mismatched flush handling" );
|
||||
}
|
||||
if ( flushDepth == 0 ) {
|
||||
logicalConnection.enableReleases();
|
||||
releasesEnabled = true;
|
||||
}
|
||||
|
||||
afterStatementExecution();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection close() {
|
||||
LOG.tracev( "Closing JDBC container [{0}]", this );
|
||||
if ( currentBatch != null ) {
|
||||
LOG.closingUnreleasedBatch();
|
||||
currentBatch.release();
|
||||
}
|
||||
cleanup();
|
||||
return logicalConnection.close();
|
||||
}
|
||||
|
||||
|
@ -181,6 +217,16 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
|
|||
return statementPreparer;
|
||||
}
|
||||
|
||||
private transient ResultSetReturn resultSetExtractor;
|
||||
|
||||
@Override
|
||||
public ResultSetReturn getResultSetReturn() {
|
||||
if ( resultSetExtractor == null ) {
|
||||
resultSetExtractor = new ResultSetReturnImpl( this );
|
||||
}
|
||||
return resultSetExtractor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransactionTimeOut(int seconds) {
|
||||
transactionTimeOutInstant = System.currentTimeMillis() + ( seconds * 1000 );
|
||||
|
@ -198,43 +244,61 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
|
|||
return secondsRemaining;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterStatementExecution() {
|
||||
LOG.tracev( "Starting after statement execution processing [{0}]", connectionReleaseMode() );
|
||||
if ( connectionReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT ) {
|
||||
if ( ! releasesEnabled ) {
|
||||
LOG.debug( "Skipping aggressive release due to manual disabling" );
|
||||
return;
|
||||
}
|
||||
if ( hasRegisteredResources() ) {
|
||||
LOG.debug( "Skipping aggressive release due to registered resources" );
|
||||
return;
|
||||
}
|
||||
getLogicalConnection().releaseConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTransaction() {
|
||||
logicalConnection.afterTransaction();
|
||||
transactionTimeOutInstant = -1;
|
||||
if ( connectionReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT ||
|
||||
connectionReleaseMode() == ConnectionReleaseMode.AFTER_TRANSACTION ) {
|
||||
if ( hasRegisteredResources() ) {
|
||||
LOG.forcingContainerResourceCleanup();
|
||||
releaseResources();
|
||||
}
|
||||
getLogicalConnection().aggressiveRelease();
|
||||
}
|
||||
}
|
||||
|
||||
private ConnectionReleaseMode connectionReleaseMode() {
|
||||
return getLogicalConnection().getConnectionReleaseMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T coordinateWork(WorkExecutorVisitable<T> work) {
|
||||
Connection connection = getLogicalConnection().getDistinctConnectionProxy();
|
||||
Connection connection = getLogicalConnection().getConnection();
|
||||
try {
|
||||
T result = work.accept( new WorkExecutor<T>(), connection );
|
||||
getLogicalConnection().afterStatementExecution();
|
||||
afterStatementExecution();
|
||||
return result;
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw sqlExceptionHelper().convert( e, "error executing work" );
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if ( ! connection.isClosed() ) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
catch (SQLException e) {
|
||||
LOG.debug( "Error closing connection proxy", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelLastQuery() {
|
||||
logicalConnection.getResourceRegistry().cancelLastQuery();
|
||||
public boolean isReadyForSerialization() {
|
||||
return getLogicalConnection().isUserSuppliedConnection()
|
||||
? ! getLogicalConnection().isPhysicallyConnected()
|
||||
: ! hasRegisteredResources();
|
||||
}
|
||||
|
||||
|
||||
public void serialize(ObjectOutputStream oos) throws IOException {
|
||||
if ( ! logicalConnection.isReadyForSerialization() ) {
|
||||
if ( ! isReadyForSerialization() ) {
|
||||
throw new HibernateException( "Cannot serialize Session while connected" );
|
||||
}
|
||||
logicalConnection.serialize( oos );
|
||||
|
@ -249,4 +313,222 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
|
|||
public void afterDeserialize(TransactionCoordinatorImpl transactionCoordinator) {
|
||||
this.transactionCoordinator = transactionCoordinator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Statement statement) {
|
||||
LOG.tracev( "Registering statement [{0}]", statement );
|
||||
if ( xref.containsKey( statement ) ) {
|
||||
throw new HibernateException( "statement already registered with JDBCContainer" );
|
||||
}
|
||||
xref.put( statement, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void registerLastQuery(Statement statement) {
|
||||
LOG.tracev( "Registering last query statement [{0}]", statement );
|
||||
if ( statement instanceof JdbcWrapper ) {
|
||||
JdbcWrapper<Statement> wrapper = ( JdbcWrapper<Statement> ) statement;
|
||||
registerLastQuery( wrapper.getWrappedObject() );
|
||||
return;
|
||||
}
|
||||
lastQuery = statement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelLastQuery() {
|
||||
try {
|
||||
if (lastQuery != null) {
|
||||
lastQuery.cancel();
|
||||
}
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
throw exceptionHelper.convert(
|
||||
sqle,
|
||||
"Cannot cancel query"
|
||||
);
|
||||
}
|
||||
finally {
|
||||
lastQuery = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(Statement statement) {
|
||||
LOG.tracev( "Releasing statement [{0}]", statement );
|
||||
Set<ResultSet> resultSets = xref.get( statement );
|
||||
if ( resultSets != null ) {
|
||||
for ( ResultSet resultSet : resultSets ) {
|
||||
close( resultSet );
|
||||
}
|
||||
resultSets.clear();
|
||||
}
|
||||
xref.remove( statement );
|
||||
close( statement );
|
||||
|
||||
afterStatementExecution();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(ResultSet resultSet) {
|
||||
LOG.tracev( "Registering result set [{0}]", resultSet );
|
||||
Statement statement;
|
||||
try {
|
||||
statement = resultSet.getStatement();
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw exceptionHelper.convert( e, "unable to access statement from resultset" );
|
||||
}
|
||||
if ( statement != null ) {
|
||||
if ( LOG.isEnabled( Level.WARN ) && !xref.containsKey( statement ) ) {
|
||||
LOG.unregisteredStatement();
|
||||
}
|
||||
Set<ResultSet> resultSets = xref.get( statement );
|
||||
if ( resultSets == null ) {
|
||||
resultSets = new HashSet<ResultSet>();
|
||||
xref.put( statement, resultSets );
|
||||
}
|
||||
resultSets.add( resultSet );
|
||||
}
|
||||
else {
|
||||
unassociatedResultSets.add( resultSet );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(ResultSet resultSet) {
|
||||
LOG.tracev( "Releasing result set [{0}]", resultSet );
|
||||
Statement statement;
|
||||
try {
|
||||
statement = resultSet.getStatement();
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw exceptionHelper.convert( e, "unable to access statement from resultset" );
|
||||
}
|
||||
if ( statement != null ) {
|
||||
if ( LOG.isEnabled( Level.WARN ) && !xref.containsKey( statement ) ) {
|
||||
LOG.unregisteredStatement();
|
||||
}
|
||||
Set<ResultSet> resultSets = xref.get( statement );
|
||||
if ( resultSets != null ) {
|
||||
resultSets.remove( resultSet );
|
||||
if ( resultSets.isEmpty() ) {
|
||||
xref.remove( statement );
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean removed = unassociatedResultSets.remove( resultSet );
|
||||
if ( !removed ) {
|
||||
LOG.unregisteredResultSetWithoutStatement();
|
||||
}
|
||||
}
|
||||
close( resultSet );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRegisteredResources() {
|
||||
return ! xref.isEmpty() || ! unassociatedResultSets.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseResources() {
|
||||
LOG.tracev( "Releasing JDBC container resources [{0}]", this );
|
||||
cleanup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableReleases() {
|
||||
releasesEnabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableReleases() {
|
||||
releasesEnabled = false;
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
for ( Map.Entry<Statement,Set<ResultSet>> entry : xref.entrySet() ) {
|
||||
if ( entry.getValue() != null ) {
|
||||
closeAll( entry.getValue() );
|
||||
}
|
||||
close( entry.getKey() );
|
||||
}
|
||||
xref.clear();
|
||||
|
||||
closeAll( unassociatedResultSets );
|
||||
}
|
||||
|
||||
protected void closeAll(Set<ResultSet> resultSets) {
|
||||
for ( ResultSet resultSet : resultSets ) {
|
||||
close( resultSet );
|
||||
}
|
||||
resultSets.clear();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
protected void close(Statement statement) {
|
||||
LOG.tracev( "Closing prepared statement [{0}]", statement );
|
||||
|
||||
if ( statement instanceof InvalidatableWrapper ) {
|
||||
InvalidatableWrapper<Statement> wrapper = ( InvalidatableWrapper<Statement> ) statement;
|
||||
close( wrapper.getWrappedObject() );
|
||||
wrapper.invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// if we are unable to "clean" the prepared statement,
|
||||
// we do not close it
|
||||
try {
|
||||
if ( statement.getMaxRows() != 0 ) {
|
||||
statement.setMaxRows( 0 );
|
||||
}
|
||||
if ( statement.getQueryTimeout() != 0 ) {
|
||||
statement.setQueryTimeout( 0 );
|
||||
}
|
||||
}
|
||||
catch( SQLException sqle ) {
|
||||
// there was a problem "cleaning" the prepared statement
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debugf( "Exception clearing maxRows/queryTimeout [%s]", sqle.getMessage() );
|
||||
}
|
||||
return; // EARLY EXIT!!!
|
||||
}
|
||||
statement.close();
|
||||
if ( lastQuery == statement ) {
|
||||
lastQuery = null;
|
||||
}
|
||||
}
|
||||
catch( SQLException e ) {
|
||||
LOG.debugf( "Unable to release JDBC statement [%s]", e.getMessage() );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
// try to handle general errors more elegantly
|
||||
LOG.debugf( "Unable to release JDBC statement [%s]", e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
protected void close(ResultSet resultSet) {
|
||||
LOG.tracev( "Closing result set [{0}]", resultSet );
|
||||
|
||||
if ( resultSet instanceof InvalidatableWrapper ) {
|
||||
InvalidatableWrapper<ResultSet> wrapper = (InvalidatableWrapper<ResultSet>) resultSet;
|
||||
close( wrapper.getWrappedObject() );
|
||||
wrapper.invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
resultSet.close();
|
||||
}
|
||||
catch( SQLException e ) {
|
||||
LOG.debugf( "Unable to release JDBC result set [%s]", e.getMessage() );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
// try to handle general errors more elegantly
|
||||
LOG.debugf( "Unable to release JDBC result set [%s]", e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,274 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.jboss.logging.Logger.Level;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.jdbc.spi.InvalidatableWrapper;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcResourceRegistry;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcWrapper;
|
||||
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
/**
|
||||
* Standard implementation of the {@link org.hibernate.engine.jdbc.spi.JdbcResourceRegistry} contract
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JdbcResourceRegistryImpl implements JdbcResourceRegistry {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, JdbcResourceRegistryImpl.class.getName() );
|
||||
|
||||
private final HashMap<Statement,Set<ResultSet>> xref = new HashMap<Statement,Set<ResultSet>>();
|
||||
private final Set<ResultSet> unassociatedResultSets = new HashSet<ResultSet>();
|
||||
private final SqlExceptionHelper exceptionHelper;
|
||||
|
||||
private Statement lastQuery;
|
||||
|
||||
public JdbcResourceRegistryImpl(SqlExceptionHelper exceptionHelper) {
|
||||
this.exceptionHelper = exceptionHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Statement statement) {
|
||||
LOG.tracev( "Registering statement [{0}]", statement );
|
||||
if ( xref.containsKey( statement ) ) {
|
||||
throw new HibernateException( "statement already registered with JDBCContainer" );
|
||||
}
|
||||
xref.put( statement, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void registerLastQuery(Statement statement) {
|
||||
LOG.tracev( "Registering last query statement [{0}]", statement );
|
||||
if ( statement instanceof JdbcWrapper ) {
|
||||
JdbcWrapper<Statement> wrapper = ( JdbcWrapper<Statement> ) statement;
|
||||
registerLastQuery( wrapper.getWrappedObject() );
|
||||
return;
|
||||
}
|
||||
lastQuery = statement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelLastQuery() {
|
||||
try {
|
||||
if (lastQuery != null) {
|
||||
lastQuery.cancel();
|
||||
}
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
throw exceptionHelper.convert(
|
||||
sqle,
|
||||
"Cannot cancel query"
|
||||
);
|
||||
}
|
||||
finally {
|
||||
lastQuery = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(Statement statement) {
|
||||
LOG.tracev( "Releasing statement [{0}]", statement );
|
||||
Set<ResultSet> resultSets = xref.get( statement );
|
||||
if ( resultSets != null ) {
|
||||
for ( ResultSet resultSet : resultSets ) {
|
||||
close( resultSet );
|
||||
}
|
||||
resultSets.clear();
|
||||
}
|
||||
xref.remove( statement );
|
||||
close( statement );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(ResultSet resultSet) {
|
||||
LOG.tracev( "Registering result set [{0}]", resultSet );
|
||||
Statement statement;
|
||||
try {
|
||||
statement = resultSet.getStatement();
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw exceptionHelper.convert( e, "unable to access statement from resultset" );
|
||||
}
|
||||
if ( statement != null ) {
|
||||
if ( LOG.isEnabled( Level.WARN ) && !xref.containsKey( statement ) ) {
|
||||
LOG.unregisteredStatement();
|
||||
}
|
||||
Set<ResultSet> resultSets = xref.get( statement );
|
||||
if ( resultSets == null ) {
|
||||
resultSets = new HashSet<ResultSet>();
|
||||
xref.put( statement, resultSets );
|
||||
}
|
||||
resultSets.add( resultSet );
|
||||
}
|
||||
else {
|
||||
unassociatedResultSets.add( resultSet );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(ResultSet resultSet) {
|
||||
LOG.tracev( "Releasing result set [{0}]", resultSet );
|
||||
Statement statement;
|
||||
try {
|
||||
statement = resultSet.getStatement();
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw exceptionHelper.convert( e, "unable to access statement from resultset" );
|
||||
}
|
||||
if ( statement != null ) {
|
||||
if ( LOG.isEnabled( Level.WARN ) && !xref.containsKey( statement ) ) {
|
||||
LOG.unregisteredStatement();
|
||||
}
|
||||
Set<ResultSet> resultSets = xref.get( statement );
|
||||
if ( resultSets != null ) {
|
||||
resultSets.remove( resultSet );
|
||||
if ( resultSets.isEmpty() ) {
|
||||
xref.remove( statement );
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean removed = unassociatedResultSets.remove( resultSet );
|
||||
if ( !removed ) {
|
||||
LOG.unregisteredResultSetWithoutStatement();
|
||||
}
|
||||
}
|
||||
close( resultSet );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRegisteredResources() {
|
||||
return ! xref.isEmpty() || ! unassociatedResultSets.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseResources() {
|
||||
LOG.tracev( "Releasing JDBC container resources [{0}]", this );
|
||||
cleanup();
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
for ( Map.Entry<Statement,Set<ResultSet>> entry : xref.entrySet() ) {
|
||||
if ( entry.getValue() != null ) {
|
||||
closeAll( entry.getValue() );
|
||||
}
|
||||
close( entry.getKey() );
|
||||
}
|
||||
xref.clear();
|
||||
|
||||
closeAll( unassociatedResultSets );
|
||||
}
|
||||
|
||||
protected void closeAll(Set<ResultSet> resultSets) {
|
||||
for ( ResultSet resultSet : resultSets ) {
|
||||
close( resultSet );
|
||||
}
|
||||
resultSets.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
LOG.tracev( "Closing JDBC container [{0}]", this );
|
||||
cleanup();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
protected void close(Statement statement) {
|
||||
LOG.tracev( "Closing prepared statement [{0}]", statement );
|
||||
|
||||
if ( statement instanceof InvalidatableWrapper ) {
|
||||
InvalidatableWrapper<Statement> wrapper = ( InvalidatableWrapper<Statement> ) statement;
|
||||
close( wrapper.getWrappedObject() );
|
||||
wrapper.invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// if we are unable to "clean" the prepared statement,
|
||||
// we do not close it
|
||||
try {
|
||||
if ( statement.getMaxRows() != 0 ) {
|
||||
statement.setMaxRows( 0 );
|
||||
}
|
||||
if ( statement.getQueryTimeout() != 0 ) {
|
||||
statement.setQueryTimeout( 0 );
|
||||
}
|
||||
}
|
||||
catch( SQLException sqle ) {
|
||||
// there was a problem "cleaning" the prepared statement
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debugf( "Exception clearing maxRows/queryTimeout [%s]", sqle.getMessage() );
|
||||
}
|
||||
return; // EARLY EXIT!!!
|
||||
}
|
||||
statement.close();
|
||||
if ( lastQuery == statement ) {
|
||||
lastQuery = null;
|
||||
}
|
||||
}
|
||||
catch( SQLException e ) {
|
||||
LOG.debugf( "Unable to release JDBC statement [%s]", e.getMessage() );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
// try to handle general errors more elegantly
|
||||
LOG.debugf( "Unable to release JDBC statement [%s]", e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
protected void close(ResultSet resultSet) {
|
||||
LOG.tracev( "Closing result set [{0}]", resultSet );
|
||||
|
||||
if ( resultSet instanceof InvalidatableWrapper ) {
|
||||
InvalidatableWrapper<ResultSet> wrapper = (InvalidatableWrapper<ResultSet>) resultSet;
|
||||
close( wrapper.getWrappedObject() );
|
||||
wrapper.invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
resultSet.close();
|
||||
}
|
||||
catch( SQLException e ) {
|
||||
LOG.debugf( "Unable to release JDBC result set [%s]", e.getMessage() );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
// try to handle general errors more elegantly
|
||||
LOG.debugf( "Unable to release JDBC result set [%s]", e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,21 +32,18 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.engine.jdbc.internal.proxy.ProxyBuilder;
|
||||
import org.hibernate.engine.jdbc.spi.ConnectionObserver;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcConnectionAccess;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcResourceRegistry;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
||||
import org.hibernate.engine.jdbc.spi.NonDurableConnectionObserver;
|
||||
import org.hibernate.engine.transaction.spi.TransactionContext;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Standard Hibernate {@link org.hibernate.engine.jdbc.spi.LogicalConnection} implementation
|
||||
|
@ -54,22 +51,19 @@ import org.hibernate.internal.util.collections.CollectionHelper;
|
|||
* IMPL NOTE : Custom serialization handling!
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public class LogicalConnectionImpl implements LogicalConnectionImplementor {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, LogicalConnectionImpl.class.getName() );
|
||||
|
||||
private transient Connection physicalConnection;
|
||||
private transient Connection shareableConnectionProxy;
|
||||
|
||||
private final transient ConnectionReleaseMode connectionReleaseMode;
|
||||
private final transient JdbcServices jdbcServices;
|
||||
private final transient JdbcConnectionAccess jdbcConnectionAccess;
|
||||
private final transient JdbcResourceRegistry jdbcResourceRegistry;
|
||||
private final transient List<ConnectionObserver> observers;
|
||||
|
||||
private boolean releasesEnabled = true;
|
||||
|
||||
private final boolean isUserSuppliedConnection;
|
||||
|
||||
private boolean isClosed;
|
||||
|
@ -102,7 +96,6 @@ public class LogicalConnectionImpl implements LogicalConnectionImplementor {
|
|||
);
|
||||
this.jdbcServices = jdbcServices;
|
||||
this.jdbcConnectionAccess = jdbcConnectionAccess;
|
||||
this.jdbcResourceRegistry = new JdbcResourceRegistryImpl( getJdbcServices().getSqlExceptionHelper() );
|
||||
this.observers = observers;
|
||||
|
||||
this.isUserSuppliedConnection = isUserSuppliedConnection;
|
||||
|
@ -131,11 +124,6 @@ public class LogicalConnectionImpl implements LogicalConnectionImplementor {
|
|||
return jdbcServices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcResourceRegistry getResourceRegistry() {
|
||||
return jdbcResourceRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addObserver(ConnectionObserver observer) {
|
||||
observers.add( observer );
|
||||
|
@ -171,30 +159,11 @@ public class LogicalConnectionImpl implements LogicalConnectionImplementor {
|
|||
return physicalConnection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getShareableConnectionProxy() {
|
||||
if ( shareableConnectionProxy == null ) {
|
||||
shareableConnectionProxy = buildConnectionProxy();
|
||||
}
|
||||
return shareableConnectionProxy;
|
||||
}
|
||||
|
||||
private Connection buildConnectionProxy() {
|
||||
return ProxyBuilder.buildConnection( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getDistinctConnectionProxy() {
|
||||
return buildConnectionProxy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection close() {
|
||||
LOG.trace( "Closing logical connection" );
|
||||
Connection c = isUserSuppliedConnection ? physicalConnection : null;
|
||||
try {
|
||||
releaseProxies();
|
||||
jdbcResourceRegistry.close();
|
||||
if ( !isUserSuppliedConnection && physicalConnection != null ) {
|
||||
releaseConnection();
|
||||
}
|
||||
|
@ -212,67 +181,15 @@ public class LogicalConnectionImpl implements LogicalConnectionImplementor {
|
|||
}
|
||||
}
|
||||
|
||||
private void releaseProxies() {
|
||||
if ( shareableConnectionProxy != null ) {
|
||||
try {
|
||||
shareableConnectionProxy.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
LOG.debug( "Error releasing shared connection proxy", e );
|
||||
}
|
||||
}
|
||||
shareableConnectionProxy = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionReleaseMode getConnectionReleaseMode() {
|
||||
return connectionReleaseMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterStatementExecution() {
|
||||
LOG.tracev( "Starting after statement execution processing [{0}]", connectionReleaseMode );
|
||||
if ( connectionReleaseMode == ConnectionReleaseMode.AFTER_STATEMENT ) {
|
||||
if ( ! releasesEnabled ) {
|
||||
LOG.debug( "Skipping aggressive release due to manual disabling" );
|
||||
return;
|
||||
}
|
||||
if ( jdbcResourceRegistry.hasRegisteredResources() ) {
|
||||
LOG.debug( "Skipping aggressive release due to registered resources" );
|
||||
return;
|
||||
}
|
||||
releaseConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTransaction() {
|
||||
if ( connectionReleaseMode == ConnectionReleaseMode.AFTER_STATEMENT ||
|
||||
connectionReleaseMode == ConnectionReleaseMode.AFTER_TRANSACTION ) {
|
||||
if ( jdbcResourceRegistry.hasRegisteredResources() ) {
|
||||
LOG.forcingContainerResourceCleanup();
|
||||
jdbcResourceRegistry.releaseResources();
|
||||
}
|
||||
aggressiveRelease();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableReleases() {
|
||||
LOG.trace( "Disabling releases" );
|
||||
releasesEnabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableReleases() {
|
||||
LOG.trace( "(Re)enabling releases" );
|
||||
releasesEnabled = true;
|
||||
afterStatementExecution();
|
||||
}
|
||||
|
||||
/**
|
||||
* Force aggressive release of the underlying connection.
|
||||
*/
|
||||
@Override
|
||||
public void aggressiveRelease() {
|
||||
if ( isUserSuppliedConnection ) {
|
||||
LOG.debug( "Cannot aggressively release user-supplied connection; skipping" );
|
||||
|
@ -310,7 +227,8 @@ public class LogicalConnectionImpl implements LogicalConnectionImplementor {
|
|||
*
|
||||
* @throws JDBCException Indicates problem closing a connection
|
||||
*/
|
||||
private void releaseConnection() throws JDBCException {
|
||||
@Override
|
||||
public void releaseConnection() throws JDBCException {
|
||||
LOG.debug( "Releasing JDBC connection" );
|
||||
if ( physicalConnection == null ) {
|
||||
return;
|
||||
|
@ -350,9 +268,7 @@ public class LogicalConnectionImpl implements LogicalConnectionImplementor {
|
|||
if ( isClosed ) {
|
||||
throw new IllegalStateException( "cannot manually disconnect because logical connection is already closed" );
|
||||
}
|
||||
releaseProxies();
|
||||
Connection c = physicalConnection;
|
||||
jdbcResourceRegistry.releaseResources();
|
||||
releaseConnection();
|
||||
return c;
|
||||
}
|
||||
|
@ -395,6 +311,11 @@ public class LogicalConnectionImpl implements LogicalConnectionImplementor {
|
|||
throw jdbcServices.getSqlExceptionHelper().convert( e, "could not inspect JDBC autocommit mode" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUserSuppliedConnection() {
|
||||
return isUserSuppliedConnection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyObserversStatementPrepared() {
|
||||
|
@ -403,13 +324,6 @@ public class LogicalConnectionImpl implements LogicalConnectionImplementor {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadyForSerialization() {
|
||||
return isUserSuppliedConnection
|
||||
? ! isPhysicallyConnected()
|
||||
: ! getResourceRegistry().hasRegisteredResources();
|
||||
}
|
||||
|
||||
public void serialize(ObjectOutputStream oos) throws IOException {
|
||||
oos.writeBoolean( isUserSuppliedConnection );
|
||||
oos.writeBoolean( isClosed );
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||
* as indicated by the @authors tag. All rights reserved.
|
||||
* See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.jdbc.spi.ResultSetReturn;
|
||||
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
|
||||
|
||||
/**
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public class ResultSetReturnImpl implements ResultSetReturn {
|
||||
|
||||
private final JdbcCoordinator jdbcCoordinator;
|
||||
|
||||
public ResultSetReturnImpl(JdbcCoordinator jdbcCoordinator) {
|
||||
this.jdbcCoordinator = jdbcCoordinator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet extract(PreparedStatement statement) {
|
||||
// sql logged by StatementPreparerImpl
|
||||
try {
|
||||
ResultSet rs = statement.executeQuery();
|
||||
postExtract( rs );
|
||||
return rs;
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw sqlExceptionHelper().convert( e, "could not extract ResultSet" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet extract(CallableStatement statement) {
|
||||
try {
|
||||
// sql logged by StatementPreparerImpl
|
||||
ResultSet rs = jdbcCoordinator.getLogicalConnection().getJdbcServices()
|
||||
.getDialect().getResultSet( statement );
|
||||
postExtract( rs );
|
||||
return rs;
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw sqlExceptionHelper().convert( e, "could not extract ResultSet" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet extract(Statement statement, String sql) {
|
||||
jdbcCoordinator.getLogicalConnection().getJdbcServices()
|
||||
.getSqlStatementLogger().logStatement( sql );
|
||||
try {
|
||||
ResultSet rs = statement.executeQuery( sql );
|
||||
postExtract( rs );
|
||||
return rs;
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw sqlExceptionHelper().convert( e, "could not extract ResultSet" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet execute(PreparedStatement statement) {
|
||||
// sql logged by StatementPreparerImpl
|
||||
try {
|
||||
if ( !statement.execute() ) {
|
||||
while ( !statement.getMoreResults() && statement.getUpdateCount() != -1 ) {
|
||||
// do nothing until we hit the resultset
|
||||
}
|
||||
}
|
||||
ResultSet rs = statement.getResultSet();
|
||||
postExtract( rs );
|
||||
return rs;
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw sqlExceptionHelper().convert( e, "could not execute statement" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet execute(Statement statement, String sql) {
|
||||
jdbcCoordinator.getLogicalConnection().getJdbcServices()
|
||||
.getSqlStatementLogger().logStatement( sql );
|
||||
try {
|
||||
if ( !statement.execute( sql ) ) {
|
||||
while ( !statement.getMoreResults() && statement.getUpdateCount() != -1 ) {
|
||||
// do nothing until we hit the resultset
|
||||
}
|
||||
}
|
||||
ResultSet rs = statement.getResultSet();
|
||||
postExtract( rs );
|
||||
return rs;
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw sqlExceptionHelper().convert( e, "could not execute statement" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeUpdate( PreparedStatement statement ) {
|
||||
try {
|
||||
return statement.executeUpdate();
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw sqlExceptionHelper().convert( e, "could not execute statement" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeUpdate( Statement statement, String sql ) {
|
||||
jdbcCoordinator.getLogicalConnection().getJdbcServices()
|
||||
.getSqlStatementLogger().logStatement( sql );
|
||||
try {
|
||||
return statement.executeUpdate( sql );
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw sqlExceptionHelper().convert( e, "could not execute statement" );
|
||||
}
|
||||
}
|
||||
|
||||
private final SqlExceptionHelper sqlExceptionHelper() {
|
||||
return jdbcCoordinator.getTransactionCoordinator()
|
||||
.getTransactionContext()
|
||||
.getTransactionEnvironment()
|
||||
.getJdbcServices()
|
||||
.getSqlExceptionHelper();
|
||||
}
|
||||
|
||||
private void postExtract(ResultSet rs) {
|
||||
if ( rs != null ) jdbcCoordinator.register( rs );
|
||||
}
|
||||
|
||||
}
|
|
@ -27,6 +27,7 @@ import java.sql.Connection;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.ScrollMode;
|
||||
|
@ -38,6 +39,7 @@ import org.hibernate.engine.jdbc.spi.StatementPreparer;
|
|||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
class StatementPreparerImpl implements StatementPreparer {
|
||||
private JdbcCoordinatorImpl jdbcCoordinator;
|
||||
|
@ -50,8 +52,8 @@ class StatementPreparerImpl implements StatementPreparer {
|
|||
return jdbcCoordinator.sessionFactory().getSettings();
|
||||
}
|
||||
|
||||
protected final Connection connectionProxy() {
|
||||
return logicalConnection().getShareableConnectionProxy();
|
||||
protected final Connection connection() {
|
||||
return logicalConnection().getConnection();
|
||||
}
|
||||
|
||||
protected final LogicalConnectionImplementor logicalConnection() {
|
||||
|
@ -65,6 +67,18 @@ class StatementPreparerImpl implements StatementPreparer {
|
|||
.getJdbcServices()
|
||||
.getSqlExceptionHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement createStatement() {
|
||||
try {
|
||||
Statement statement = connection().createStatement();
|
||||
jdbcCoordinator.register( statement );
|
||||
return statement;
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw sqlExceptionHelper().convert( e, "could not create statement" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql) {
|
||||
|
@ -82,8 +96,8 @@ class StatementPreparerImpl implements StatementPreparer {
|
|||
@Override
|
||||
protected PreparedStatement doPrepare() throws SQLException {
|
||||
return isCallable
|
||||
? connectionProxy().prepareCall( sql )
|
||||
: connectionProxy().prepareStatement( sql );
|
||||
? connection().prepareCall( sql )
|
||||
: connection().prepareStatement( sql );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -102,7 +116,7 @@ class StatementPreparerImpl implements StatementPreparer {
|
|||
jdbcCoordinator.executeBatch();
|
||||
return new StatementPreparationTemplate( sql ) {
|
||||
public PreparedStatement doPrepare() throws SQLException {
|
||||
return connectionProxy().prepareStatement( sql, autoGeneratedKeys );
|
||||
return connection().prepareStatement( sql, autoGeneratedKeys );
|
||||
}
|
||||
}.prepareStatement();
|
||||
}
|
||||
|
@ -113,7 +127,7 @@ class StatementPreparerImpl implements StatementPreparer {
|
|||
jdbcCoordinator.executeBatch();
|
||||
return new StatementPreparationTemplate( sql ) {
|
||||
public PreparedStatement doPrepare() throws SQLException {
|
||||
return connectionProxy().prepareStatement( sql, columnNames );
|
||||
return connection().prepareStatement( sql, columnNames );
|
||||
}
|
||||
}.prepareStatement();
|
||||
}
|
||||
|
@ -130,26 +144,26 @@ class StatementPreparerImpl implements StatementPreparer {
|
|||
PreparedStatement ps = new QueryStatementPreparationTemplate( sql ) {
|
||||
public PreparedStatement doPrepare() throws SQLException {
|
||||
return isCallable
|
||||
? connectionProxy().prepareCall(
|
||||
? connection().prepareCall(
|
||||
sql, scrollMode.toResultSetType(), ResultSet.CONCUR_READ_ONLY
|
||||
)
|
||||
: connectionProxy().prepareStatement(
|
||||
: connection().prepareStatement(
|
||||
sql, scrollMode.toResultSetType(), ResultSet.CONCUR_READ_ONLY
|
||||
);
|
||||
}
|
||||
}.prepareStatement();
|
||||
logicalConnection().getResourceRegistry().registerLastQuery( ps );
|
||||
jdbcCoordinator.registerLastQuery( ps );
|
||||
return ps;
|
||||
}
|
||||
else {
|
||||
PreparedStatement ps = new QueryStatementPreparationTemplate( sql ) {
|
||||
public PreparedStatement doPrepare() throws SQLException {
|
||||
return isCallable
|
||||
? connectionProxy().prepareCall( sql )
|
||||
: connectionProxy().prepareStatement( sql );
|
||||
? connection().prepareCall( sql )
|
||||
: connection().prepareStatement( sql );
|
||||
}
|
||||
}.prepareStatement();
|
||||
logicalConnection().getResourceRegistry().registerLastQuery( ps );
|
||||
jdbcCoordinator.registerLastQuery( ps );
|
||||
return ps;
|
||||
}
|
||||
}
|
||||
|
@ -163,6 +177,8 @@ class StatementPreparerImpl implements StatementPreparer {
|
|||
|
||||
public PreparedStatement prepareStatement() {
|
||||
try {
|
||||
jdbcCoordinator.getLogicalConnection().getJdbcServices().getSqlStatementLogger().logStatement( sql );
|
||||
|
||||
PreparedStatement preparedStatement = doPrepare();
|
||||
setStatementTimeout( preparedStatement );
|
||||
postProcess( preparedStatement );
|
||||
|
@ -176,6 +192,8 @@ class StatementPreparerImpl implements StatementPreparer {
|
|||
protected abstract PreparedStatement doPrepare() throws SQLException;
|
||||
|
||||
public void postProcess(PreparedStatement preparedStatement) throws SQLException {
|
||||
jdbcCoordinator.register( preparedStatement );
|
||||
logicalConnection().notifyObserversStatementPrepared();
|
||||
}
|
||||
|
||||
private void setStatementTimeout(PreparedStatement preparedStatement) throws SQLException {
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
/**
|
||||
* Basic support for building proxy handlers.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractProxyHandler implements InvocationHandler {
|
||||
private boolean valid = true;
|
||||
private final int hashCode;
|
||||
|
||||
public AbstractProxyHandler(int hashCode) {
|
||||
this.hashCode = hashCode;
|
||||
}
|
||||
|
||||
protected abstract Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable;
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + "[valid=" + valid + "]";
|
||||
}
|
||||
|
||||
public final int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
protected final boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
protected final void invalidate() {
|
||||
valid = false;
|
||||
}
|
||||
|
||||
protected final void errorIfInvalid() {
|
||||
if ( !isValid() ) {
|
||||
throw new HibernateException( "proxy handle is no longer valid" );
|
||||
}
|
||||
}
|
||||
|
||||
public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
String methodName = method.getName();
|
||||
|
||||
// basic Object methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
if ( "toString".equals( methodName ) ) {
|
||||
return this.toString();
|
||||
}
|
||||
if ( "hashCode".equals( methodName ) ) {
|
||||
return this.hashCode();
|
||||
}
|
||||
if ( "equals".equals( methodName ) ) {
|
||||
return this.equals( args[0] );
|
||||
}
|
||||
|
||||
return continueInvocation( proxy, method, args );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.engine.jdbc.spi.JdbcResourceRegistry;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
/**
|
||||
* Basic support for building {@link ResultSet}-based proxy handlers
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractResultSetProxyHandler extends AbstractProxyHandler {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
AbstractResultSetProxyHandler.class.getName());
|
||||
|
||||
private ResultSet resultSet;
|
||||
|
||||
public AbstractResultSetProxyHandler(ResultSet resultSet) {
|
||||
super( resultSet.hashCode() );
|
||||
this.resultSet = resultSet;
|
||||
}
|
||||
|
||||
protected abstract JdbcServices getJdbcServices();
|
||||
|
||||
protected abstract JdbcResourceRegistry getResourceRegistry();
|
||||
|
||||
protected abstract Statement getExposableStatement();
|
||||
|
||||
protected final ResultSet getResultSet() {
|
||||
errorIfInvalid();
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
protected final ResultSet getResultSetWithoutChecks() {
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
final String methodName = method.getName();
|
||||
LOG.tracev( "Handling invocation of ResultSet method [{0}]", methodName );
|
||||
|
||||
// other methods allowed while invalid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
if ( "close".equals( methodName ) ) {
|
||||
explicitClose( ( ResultSet ) proxy );
|
||||
return null;
|
||||
}
|
||||
if ( "invalidate".equals( methodName ) ) {
|
||||
invalidateHandle();
|
||||
return null;
|
||||
}
|
||||
|
||||
errorIfInvalid();
|
||||
|
||||
// handle the JDBC 4 Wrapper#isWrapperFor and Wrapper#unwrap calls
|
||||
// these cause problems to the whole proxy scheme though as we need to return the raw objects
|
||||
if ( "isWrapperFor".equals( methodName ) && args.length == 1 ) {
|
||||
return method.invoke( getResultSetWithoutChecks(), args );
|
||||
}
|
||||
if ( "unwrap".equals( methodName ) && args.length == 1 ) {
|
||||
return method.invoke( getResultSetWithoutChecks(), args );
|
||||
}
|
||||
|
||||
if ( "getWrappedObject".equals( methodName ) ) {
|
||||
return getResultSetWithoutChecks();
|
||||
}
|
||||
|
||||
if ( "getStatement".equals( methodName ) ) {
|
||||
return getExposableStatement();
|
||||
}
|
||||
|
||||
try {
|
||||
return method.invoke( resultSet, args );
|
||||
}
|
||||
catch ( InvocationTargetException e ) {
|
||||
Throwable realException = e.getTargetException();
|
||||
if (SQLException.class.isInstance(realException)) throw getJdbcServices().getSqlExceptionHelper().convert((SQLException)realException,
|
||||
realException.getMessage());
|
||||
throw realException;
|
||||
}
|
||||
}
|
||||
|
||||
private void explicitClose(ResultSet proxy) {
|
||||
if ( isValid() ) {
|
||||
getResourceRegistry().release( proxy );
|
||||
}
|
||||
}
|
||||
|
||||
protected void invalidateHandle() {
|
||||
resultSet = null;
|
||||
invalidate();
|
||||
}
|
||||
}
|
|
@ -1,170 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.engine.jdbc.spi.JdbcResourceRegistry;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
/**
|
||||
* Basic support for building {@link Statement}-based proxy handlers
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractStatementProxyHandler extends AbstractProxyHandler {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
AbstractStatementProxyHandler.class.getName());
|
||||
|
||||
private ConnectionProxyHandler connectionProxyHandler;
|
||||
private Connection connectionProxy;
|
||||
private Statement statement;
|
||||
|
||||
protected AbstractStatementProxyHandler(
|
||||
Statement statement,
|
||||
ConnectionProxyHandler connectionProxyHandler,
|
||||
Connection connectionProxy) {
|
||||
super( statement.hashCode() );
|
||||
this.statement = statement;
|
||||
this.connectionProxyHandler = connectionProxyHandler;
|
||||
this.connectionProxy = connectionProxy;
|
||||
}
|
||||
|
||||
protected ConnectionProxyHandler getConnectionProxy() {
|
||||
errorIfInvalid();
|
||||
return connectionProxyHandler;
|
||||
}
|
||||
|
||||
protected JdbcServices getJdbcServices() {
|
||||
return getConnectionProxy().getJdbcServices();
|
||||
}
|
||||
|
||||
protected JdbcResourceRegistry getResourceRegistry() {
|
||||
return getConnectionProxy().getResourceRegistry();
|
||||
}
|
||||
|
||||
protected Statement getStatement() {
|
||||
errorIfInvalid();
|
||||
return statement;
|
||||
}
|
||||
|
||||
protected Statement getStatementWithoutChecks() {
|
||||
return statement;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
final String methodName = method.getName();
|
||||
LOG.tracev( "Handling invocation of statement method [{0}]", methodName );
|
||||
|
||||
// other methods allowed while invalid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
if ( "close".equals( methodName ) ) {
|
||||
explicitClose( ( Statement ) proxy );
|
||||
return null;
|
||||
}
|
||||
if ( "invalidate".equals( methodName ) ) {
|
||||
invalidateHandle();
|
||||
return null;
|
||||
}
|
||||
|
||||
errorIfInvalid();
|
||||
|
||||
// handle the JDBC 4 Wrapper#isWrapperFor and Wrapper#unwrap calls
|
||||
// these cause problems to the whole proxy scheme though as we need to return the raw objects
|
||||
if ( "isWrapperFor".equals( methodName ) && args.length == 1 ) {
|
||||
return method.invoke( getStatementWithoutChecks(), args );
|
||||
}
|
||||
if ( "unwrap".equals( methodName ) && args.length == 1 ) {
|
||||
return method.invoke( getStatementWithoutChecks(), args );
|
||||
}
|
||||
|
||||
if ( "getWrappedObject".equals( methodName ) ) {
|
||||
return getStatementWithoutChecks();
|
||||
}
|
||||
|
||||
if ( "getConnection".equals( methodName ) ) {
|
||||
return connectionProxy;
|
||||
}
|
||||
|
||||
beginningInvocationHandling( method, args );
|
||||
|
||||
try {
|
||||
Object result = method.invoke( statement, args );
|
||||
result = wrapIfNecessary( result, proxy, method );
|
||||
return result;
|
||||
}
|
||||
catch ( InvocationTargetException e ) {
|
||||
Throwable realException = e.getTargetException();
|
||||
if ( SQLException.class.isInstance( realException ) ) {
|
||||
throw connectionProxyHandler.getJdbcServices().getSqlExceptionHelper()
|
||||
.convert( ( SQLException ) realException, realException.getMessage() );
|
||||
}
|
||||
else {
|
||||
throw realException;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Object wrapIfNecessary(Object result, Object proxy, Method method) {
|
||||
if ( !( ResultSet.class.isAssignableFrom( method.getReturnType() ) ) ) {
|
||||
return result;
|
||||
}
|
||||
|
||||
final ResultSet wrapper;
|
||||
if ( "getGeneratedKeys".equals( method.getName() ) ) {
|
||||
wrapper = ProxyBuilder.buildImplicitResultSet( ( ResultSet ) result, connectionProxyHandler, connectionProxy, ( Statement ) proxy );
|
||||
}
|
||||
else {
|
||||
wrapper = ProxyBuilder.buildResultSet( ( ResultSet ) result, this, ( Statement ) proxy );
|
||||
}
|
||||
getResourceRegistry().register( wrapper );
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
protected void beginningInvocationHandling(Method method, Object[] args) {
|
||||
}
|
||||
|
||||
private void explicitClose(Statement proxy) {
|
||||
if ( isValid() ) {
|
||||
LogicalConnectionImplementor lc = getConnectionProxy().getLogicalConnection();
|
||||
getResourceRegistry().release( proxy );
|
||||
lc.afterStatementExecution();
|
||||
}
|
||||
}
|
||||
|
||||
private void invalidateHandle() {
|
||||
connectionProxyHandler = null;
|
||||
statement = null;
|
||||
invalidate();
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* Invocation handler for {@link Statement} proxies
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BasicStatementProxyHandler extends AbstractStatementProxyHandler {
|
||||
public BasicStatementProxyHandler(
|
||||
Statement statement,
|
||||
ConnectionProxyHandler connectionProxyHandler,
|
||||
Connection connectionProxy) {
|
||||
super( statement, connectionProxyHandler, connectionProxy );
|
||||
}
|
||||
|
||||
protected void beginningInvocationHandling(Method method, Object[] args) {
|
||||
if ( isExecution( method ) ) {
|
||||
getJdbcServices().getSqlStatementLogger().logStatement( ( String ) args[0] );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isExecution(Method method) {
|
||||
String methodName = method.getName();
|
||||
return "execute".equals( methodName )
|
||||
|| "executeQuery".equals( methodName )
|
||||
|| "executeUpdate".equals( methodName );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* Invocation handler for {@link java.sql.CallableStatement} proxies
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class CallableStatementProxyHandler extends PreparedStatementProxyHandler {
|
||||
|
||||
protected CallableStatementProxyHandler(
|
||||
String sql,
|
||||
Statement statement,
|
||||
ConnectionProxyHandler connectionProxyHandler,
|
||||
Connection connectionProxy) {
|
||||
super( sql, statement, connectionProxyHandler, connectionProxy );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
if ( ! "executeQuery".equals( method.getName() ) ) {
|
||||
return super.continueInvocation( proxy, method, args ); // EARLY RETURN!
|
||||
}
|
||||
errorIfInvalid();
|
||||
return executeQuery();
|
||||
}
|
||||
|
||||
private Object executeQuery() throws SQLException {
|
||||
return getConnectionProxy().getJdbcServices().getDialect().getResultSet( ( CallableStatement ) getStatementWithoutChecks() );
|
||||
}
|
||||
}
|
|
@ -1,232 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.engine.jdbc.spi.JdbcResourceRegistry;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
||||
import org.hibernate.engine.jdbc.spi.NonDurableConnectionObserver;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
/**
|
||||
* The {@link InvocationHandler} for intercepting messages to {@link java.sql.Connection} proxies.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ConnectionProxyHandler
|
||||
extends AbstractProxyHandler
|
||||
implements NonDurableConnectionObserver {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
ConnectionProxyHandler.class.getName());
|
||||
|
||||
private LogicalConnectionImplementor logicalConnection;
|
||||
|
||||
public ConnectionProxyHandler(LogicalConnectionImplementor logicalConnection) {
|
||||
super( logicalConnection.hashCode() );
|
||||
this.logicalConnection = logicalConnection;
|
||||
this.logicalConnection.addObserver( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Access to our logical connection.
|
||||
*
|
||||
* @return the logical connection
|
||||
*/
|
||||
protected LogicalConnectionImplementor getLogicalConnection() {
|
||||
errorIfInvalid();
|
||||
return logicalConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reference to physical connection.
|
||||
* <p/>
|
||||
* NOTE : be sure this handler is still valid before calling!
|
||||
*
|
||||
* @return The physical connection
|
||||
*/
|
||||
private Connection extractPhysicalConnection() {
|
||||
return logicalConnection.getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
JdbcResourceRegistry getResourceRegistry() {
|
||||
return logicalConnection.getResourceRegistry();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
final String methodName = method.getName();
|
||||
LOG.tracev( "Handling invocation of connection method [{0}]", methodName );
|
||||
|
||||
// other methods allowed while invalid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
if ( "close".equals( methodName ) ) {
|
||||
explicitClose();
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( "isClosed".equals( methodName ) ) {
|
||||
return ! isValid();
|
||||
}
|
||||
|
||||
errorIfInvalid();
|
||||
|
||||
// handle the JDBC 4 Wrapper#isWrapperFor and Wrapper#unwrap calls
|
||||
// these cause problems to the whole proxy scheme though as we need to return the raw objects
|
||||
if ( "isWrapperFor".equals( methodName ) && args.length == 1 ) {
|
||||
return method.invoke( extractPhysicalConnection(), args );
|
||||
}
|
||||
if ( "unwrap".equals( methodName ) && args.length == 1 ) {
|
||||
return method.invoke( extractPhysicalConnection(), args );
|
||||
}
|
||||
|
||||
if ( "getWrappedObject".equals( methodName ) ) {
|
||||
return extractPhysicalConnection();
|
||||
}
|
||||
|
||||
try {
|
||||
Object result = method.invoke( extractPhysicalConnection(), args );
|
||||
result = postProcess( result, proxy, method, args );
|
||||
|
||||
return result;
|
||||
}
|
||||
catch( InvocationTargetException e ) {
|
||||
Throwable realException = e.getTargetException();
|
||||
if ( SQLException.class.isInstance( realException ) ) {
|
||||
throw logicalConnection.getJdbcServices().getSqlExceptionHelper()
|
||||
.convert( ( SQLException ) realException, realException.getMessage() );
|
||||
}
|
||||
else {
|
||||
throw realException;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Object postProcess(Object result, Object proxy, Method method, Object[] args) throws SQLException {
|
||||
String methodName = method.getName();
|
||||
Object wrapped = result;
|
||||
if ( "createStatement".equals( methodName ) ) {
|
||||
wrapped = ProxyBuilder.buildStatement(
|
||||
(Statement) result,
|
||||
this,
|
||||
( Connection ) proxy
|
||||
);
|
||||
postProcessStatement( ( Statement ) wrapped );
|
||||
}
|
||||
else if ( "prepareStatement".equals( methodName ) ) {
|
||||
wrapped = ProxyBuilder.buildPreparedStatement(
|
||||
( String ) args[0],
|
||||
(PreparedStatement) result,
|
||||
this,
|
||||
( Connection ) proxy
|
||||
);
|
||||
postProcessPreparedStatement( ( Statement ) wrapped );
|
||||
}
|
||||
else if ( "prepareCall".equals( methodName ) ) {
|
||||
wrapped = ProxyBuilder.buildCallableStatement(
|
||||
( String ) args[0],
|
||||
(CallableStatement) result,
|
||||
this,
|
||||
( Connection ) proxy
|
||||
);
|
||||
postProcessPreparedStatement( ( Statement ) wrapped );
|
||||
}
|
||||
else if ( "getMetaData".equals( methodName ) ) {
|
||||
wrapped = ProxyBuilder.buildDatabaseMetaData( (DatabaseMetaData) result, this, ( Connection ) proxy );
|
||||
}
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
private void postProcessStatement(Statement statement) throws SQLException {
|
||||
getResourceRegistry().register( statement );
|
||||
}
|
||||
|
||||
private void postProcessPreparedStatement(Statement statement) throws SQLException {
|
||||
logicalConnection.notifyObserversStatementPrepared();
|
||||
postProcessStatement( statement );
|
||||
}
|
||||
|
||||
private void explicitClose() {
|
||||
if ( isValid() ) {
|
||||
invalidateHandle();
|
||||
}
|
||||
}
|
||||
|
||||
private void invalidateHandle() {
|
||||
LOG.trace( "Invalidating connection handle" );
|
||||
logicalConnection = null;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
// ConnectionObserver ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@Override
|
||||
public void physicalConnectionObtained(Connection connection) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void physicalConnectionReleased() {
|
||||
LOG.logicalConnectionReleasingPhysicalConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logicalConnectionClosed() {
|
||||
LOG.logicalConnectionClosed();
|
||||
invalidateHandle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void statementPrepared() {
|
||||
// N/A
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* The InvocationHandler for intercepting messages to {@link java.sql.DatabaseMetaData} proxies.
|
||||
* <p/>
|
||||
* Mainly we need to intercept the methods defined on {@link java.sql.DatabaseMetaData} which expose
|
||||
* {@link java.sql.ResultSet} instances, which in turn expose {@link java.sql.Statement}
|
||||
* instances, which in turn...
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DatabaseMetaDataProxyHandler extends AbstractProxyHandler {
|
||||
private ConnectionProxyHandler connectionProxyHandler;
|
||||
private Connection connectionProxy;
|
||||
private DatabaseMetaData databaseMetaData;
|
||||
|
||||
public DatabaseMetaDataProxyHandler(DatabaseMetaData databaseMetaData, ConnectionProxyHandler connectionProxyHandler, Connection connectionProxy) {
|
||||
super( databaseMetaData.hashCode() );
|
||||
this.connectionProxyHandler = connectionProxyHandler;
|
||||
this.connectionProxy = connectionProxy;
|
||||
this.databaseMetaData = databaseMetaData;
|
||||
}
|
||||
|
||||
protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
// handle the JDBC 4 Wrapper#isWrapperFor and Wrapper#unwrap calls
|
||||
// these cause problems to the whole proxy scheme though as we need to return the raw objects
|
||||
if ( "isWrapperFor".equals( method.getName() ) && args.length == 1 ) {
|
||||
return method.invoke( databaseMetaData, args );
|
||||
}
|
||||
if ( "unwrap".equals( method.getName() ) && args.length == 1 ) {
|
||||
return method.invoke( databaseMetaData, args );
|
||||
}
|
||||
|
||||
try {
|
||||
boolean exposingResultSet = doesMethodExposeResultSet( method );
|
||||
|
||||
Object result = method.invoke( databaseMetaData, args );
|
||||
|
||||
if ( exposingResultSet ) {
|
||||
result = ProxyBuilder.buildImplicitResultSet( (ResultSet) result, connectionProxyHandler, connectionProxy );
|
||||
connectionProxyHandler.getResourceRegistry().register( ( ResultSet ) result );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch ( InvocationTargetException e ) {
|
||||
Throwable realException = e.getTargetException();
|
||||
if ( SQLException.class.isInstance( realException ) ) {
|
||||
throw connectionProxyHandler.getJdbcServices().getSqlExceptionHelper()
|
||||
.convert( ( SQLException ) realException, realException.getMessage() );
|
||||
}
|
||||
else {
|
||||
throw realException;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean doesMethodExposeResultSet(Method method) {
|
||||
return ResultSet.class.isAssignableFrom( method.getReturnType() );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.engine.jdbc.spi.JdbcResourceRegistry;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
|
||||
/**
|
||||
* Invocation handler for {@link java.sql.ResultSet} proxies obtained from other JDBC object proxies
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ImplicitResultSetProxyHandler extends AbstractResultSetProxyHandler {
|
||||
private ConnectionProxyHandler connectionProxyHandler;
|
||||
private Connection connectionProxy;
|
||||
private Statement sourceStatement;
|
||||
|
||||
public ImplicitResultSetProxyHandler(ResultSet resultSet, ConnectionProxyHandler connectionProxyHandler, Connection connectionProxy) {
|
||||
super( resultSet );
|
||||
this.connectionProxyHandler = connectionProxyHandler;
|
||||
this.connectionProxy = connectionProxy;
|
||||
}
|
||||
|
||||
public ImplicitResultSetProxyHandler(ResultSet resultSet, ConnectionProxyHandler connectionProxyHandler, Connection connectionProxy, Statement sourceStatement) {
|
||||
super( resultSet );
|
||||
this.connectionProxyHandler = connectionProxyHandler;
|
||||
this.connectionProxy = connectionProxy;
|
||||
this.sourceStatement = sourceStatement;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JdbcServices getJdbcServices() {
|
||||
return connectionProxyHandler.getJdbcServices();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JdbcResourceRegistry getResourceRegistry() {
|
||||
return connectionProxyHandler.getResourceRegistry();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement getExposableStatement() {
|
||||
if ( sourceStatement == null ) {
|
||||
try {
|
||||
Statement stmnt = getResultSet().getStatement();
|
||||
if ( stmnt == null ) {
|
||||
return null;
|
||||
}
|
||||
sourceStatement = ProxyBuilder.buildImplicitStatement( stmnt, connectionProxyHandler, connectionProxy );
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
throw getJdbcServices().getSqlExceptionHelper().convert( e, e.getMessage() );
|
||||
}
|
||||
}
|
||||
return sourceStatement;
|
||||
}
|
||||
|
||||
protected void invalidateHandle() {
|
||||
sourceStatement = null;
|
||||
super.invalidateHandle();
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
/**
|
||||
* Invocation handler for {@link java.sql.Statement} proxies obtained from other JDBC object proxies
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ImplicitStatementProxyHandler extends AbstractStatementProxyHandler {
|
||||
protected ImplicitStatementProxyHandler(Statement statement, ConnectionProxyHandler connectionProxyHandler, Connection connectionProxy) {
|
||||
super( statement, connectionProxyHandler, connectionProxy );
|
||||
}
|
||||
|
||||
protected void beginningInvocationHandling(Method method, Object[] args) {
|
||||
// disallow executions...
|
||||
if ( method.getName().startsWith( "execute" ) ) {
|
||||
throw new HibernateException( "execution not allowed on implicit statement object" );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
/**
|
||||
* Indicates a problem defining or instantiating a JDBC proxy class.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JdbcProxyException extends HibernateException {
|
||||
public JdbcProxyException(String message, Throwable root) {
|
||||
super( message, root );
|
||||
}
|
||||
|
||||
public JdbcProxyException(String message) {
|
||||
super( message );
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
/**
|
||||
* Invocation handler for {@link java.sql.PreparedStatement} proxies
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class PreparedStatementProxyHandler extends AbstractStatementProxyHandler {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, PreparedStatementProxyHandler.class.getName() );
|
||||
|
||||
private final String sql;
|
||||
|
||||
protected PreparedStatementProxyHandler(
|
||||
String sql,
|
||||
Statement statement,
|
||||
ConnectionProxyHandler connectionProxyHandler,
|
||||
Connection connectionProxy) {
|
||||
super( statement, connectionProxyHandler, connectionProxy );
|
||||
connectionProxyHandler.getJdbcServices().getSqlStatementLogger().logStatement( sql );
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beginningInvocationHandling(Method method, Object[] args) {
|
||||
if ( isExecution( method ) ) {
|
||||
logExecution();
|
||||
}
|
||||
else {
|
||||
journalPossibleParameterBind( method, args );
|
||||
}
|
||||
}
|
||||
|
||||
private void journalPossibleParameterBind(Method method, Object[] args) {
|
||||
String methodName = method.getName();
|
||||
// todo : is this enough???
|
||||
if ( methodName.startsWith( "set" ) && args != null && args.length >= 2 ) {
|
||||
journalParameterBind( method, args );
|
||||
}
|
||||
}
|
||||
|
||||
private void journalParameterBind(Method method, Object[] args) {
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev( "Binding via {0}: {1}", method.getName(), Arrays.asList( args ) );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isExecution(Method method) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void logExecution() {
|
||||
}
|
||||
}
|
|
@ -1,377 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.engine.jdbc.spi.InvalidatableWrapper;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcWrapper;
|
||||
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
||||
import org.hibernate.internal.util.ValueHolder;
|
||||
|
||||
/**
|
||||
* Centralized builder for proxy instances
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ProxyBuilder {
|
||||
|
||||
// Connection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
public static final Class[] CONNECTION_PROXY_INTERFACES = new Class[] {
|
||||
Connection.class,
|
||||
JdbcWrapper.class
|
||||
};
|
||||
|
||||
private static final ValueHolder<Constructor<Connection>> connectionProxyConstructorValue = new ValueHolder<Constructor<Connection>>(
|
||||
new ValueHolder.DeferredInitializer<Constructor<Connection>>() {
|
||||
@Override
|
||||
public Constructor<Connection> initialize() {
|
||||
try {
|
||||
return locateConnectionProxyClass().getConstructor( InvocationHandler.class );
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new JdbcProxyException( "Could not find proxy constructor in JDK generated Connection proxy class", e );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class<Connection> locateConnectionProxyClass() {
|
||||
return (Class<Connection>) Proxy.getProxyClass(
|
||||
JdbcWrapper.class.getClassLoader(),
|
||||
CONNECTION_PROXY_INTERFACES
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public static Connection buildConnection(LogicalConnectionImplementor logicalConnection) {
|
||||
final ConnectionProxyHandler proxyHandler = new ConnectionProxyHandler( logicalConnection );
|
||||
try {
|
||||
return connectionProxyConstructorValue.getValue().newInstance( proxyHandler );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new JdbcProxyException( "Could not instantiate JDBC Connection proxy", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Statement ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
public static final Class[] STMNT_PROXY_INTERFACES = new Class[] {
|
||||
Statement.class,
|
||||
JdbcWrapper.class,
|
||||
InvalidatableWrapper.class
|
||||
};
|
||||
|
||||
private static final ValueHolder<Constructor<Statement>> statementProxyConstructorValue = new ValueHolder<Constructor<Statement>>(
|
||||
new ValueHolder.DeferredInitializer<Constructor<Statement>>() {
|
||||
@Override
|
||||
public Constructor<Statement> initialize() {
|
||||
try {
|
||||
return locateStatementProxyClass().getConstructor( InvocationHandler.class );
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new JdbcProxyException( "Could not find proxy constructor in JDK generated Statement proxy class", e );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class<Statement> locateStatementProxyClass() {
|
||||
return (Class<Statement>) Proxy.getProxyClass(
|
||||
JdbcWrapper.class.getClassLoader(),
|
||||
STMNT_PROXY_INTERFACES
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public static Statement buildStatement(
|
||||
Statement statement,
|
||||
ConnectionProxyHandler connectionProxyHandler,
|
||||
Connection connectionProxy) {
|
||||
final BasicStatementProxyHandler proxyHandler = new BasicStatementProxyHandler(
|
||||
statement,
|
||||
connectionProxyHandler,
|
||||
connectionProxy
|
||||
);
|
||||
try {
|
||||
return statementProxyConstructorValue.getValue().newInstance( proxyHandler );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new JdbcProxyException( "Could not instantiate JDBC Statement proxy", e );
|
||||
}
|
||||
}
|
||||
|
||||
public static Statement buildImplicitStatement(
|
||||
Statement statement,
|
||||
ConnectionProxyHandler connectionProxyHandler,
|
||||
Connection connectionProxy) {
|
||||
if ( statement == null ) {
|
||||
return null;
|
||||
}
|
||||
final ImplicitStatementProxyHandler proxyHandler = new ImplicitStatementProxyHandler( statement, connectionProxyHandler, connectionProxy );
|
||||
try {
|
||||
return statementProxyConstructorValue.getValue().newInstance( proxyHandler );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new JdbcProxyException( "Could not instantiate JDBC Statement proxy", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// PreparedStatement ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
public static final Class[] PREPARED_STMNT_PROXY_INTERFACES = new Class[] {
|
||||
PreparedStatement.class,
|
||||
JdbcWrapper.class,
|
||||
InvalidatableWrapper.class
|
||||
};
|
||||
|
||||
private static final ValueHolder<Constructor<PreparedStatement>> preparedStatementProxyConstructorValue = new ValueHolder<Constructor<PreparedStatement>>(
|
||||
new ValueHolder.DeferredInitializer<Constructor<PreparedStatement>>() {
|
||||
@Override
|
||||
public Constructor<PreparedStatement> initialize() {
|
||||
try {
|
||||
return locatePreparedStatementProxyClass().getConstructor( InvocationHandler.class );
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new JdbcProxyException( "Could not find proxy constructor in JDK generated Statement proxy class", e );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class<PreparedStatement> locatePreparedStatementProxyClass() {
|
||||
return (Class<PreparedStatement>) Proxy.getProxyClass(
|
||||
JdbcWrapper.class.getClassLoader(),
|
||||
PREPARED_STMNT_PROXY_INTERFACES
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public static PreparedStatement buildPreparedStatement(
|
||||
String sql,
|
||||
Statement statement,
|
||||
ConnectionProxyHandler connectionProxyHandler,
|
||||
Connection connectionProxy) {
|
||||
final PreparedStatementProxyHandler proxyHandler = new PreparedStatementProxyHandler(
|
||||
sql,
|
||||
statement,
|
||||
connectionProxyHandler,
|
||||
connectionProxy
|
||||
);
|
||||
try {
|
||||
return preparedStatementProxyConstructorValue.getValue().newInstance( proxyHandler );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new JdbcProxyException( "Could not instantiate JDBC PreparedStatement proxy", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// CallableStatement ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
public static final Class[] CALLABLE_STMNT_PROXY_INTERFACES = new Class[] {
|
||||
CallableStatement.class,
|
||||
JdbcWrapper.class,
|
||||
InvalidatableWrapper.class
|
||||
};
|
||||
|
||||
private static final ValueHolder<Constructor<CallableStatement>> callableStatementProxyConstructorValue = new ValueHolder<Constructor<CallableStatement>>(
|
||||
new ValueHolder.DeferredInitializer<Constructor<CallableStatement>>() {
|
||||
@Override
|
||||
public Constructor<CallableStatement> initialize() {
|
||||
try {
|
||||
return locateCallableStatementProxyClass().getConstructor( InvocationHandler.class );
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new JdbcProxyException( "Could not find proxy constructor in JDK generated Statement proxy class", e );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class<CallableStatement> locateCallableStatementProxyClass() {
|
||||
return (Class<CallableStatement>) Proxy.getProxyClass(
|
||||
JdbcWrapper.class.getClassLoader(),
|
||||
CALLABLE_STMNT_PROXY_INTERFACES
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public static CallableStatement buildCallableStatement(
|
||||
String sql,
|
||||
CallableStatement statement,
|
||||
ConnectionProxyHandler connectionProxyHandler,
|
||||
Connection connectionProxy) {
|
||||
final CallableStatementProxyHandler proxyHandler = new CallableStatementProxyHandler(
|
||||
sql,
|
||||
statement,
|
||||
connectionProxyHandler,
|
||||
connectionProxy
|
||||
);
|
||||
try {
|
||||
return callableStatementProxyConstructorValue.getValue().newInstance( proxyHandler );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new JdbcProxyException( "Could not instantiate JDBC CallableStatement proxy", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ResultSet ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
public static final Class[] RESULTSET_PROXY_INTERFACES = new Class[] {
|
||||
ResultSet.class,
|
||||
JdbcWrapper.class,
|
||||
InvalidatableWrapper.class
|
||||
};
|
||||
|
||||
private static final ValueHolder<Constructor<ResultSet>> resultSetProxyConstructorValue = new ValueHolder<Constructor<ResultSet>>(
|
||||
new ValueHolder.DeferredInitializer<Constructor<ResultSet>>() {
|
||||
@Override
|
||||
public Constructor<ResultSet> initialize() {
|
||||
try {
|
||||
return locateCallableStatementProxyClass().getConstructor( InvocationHandler.class );
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new JdbcProxyException( "Could not find proxy constructor in JDK generated ResultSet proxy class", e );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class<ResultSet> locateCallableStatementProxyClass() {
|
||||
return (Class<ResultSet>) Proxy.getProxyClass(
|
||||
JdbcWrapper.class.getClassLoader(),
|
||||
RESULTSET_PROXY_INTERFACES
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public static ResultSet buildResultSet(
|
||||
ResultSet resultSet,
|
||||
AbstractStatementProxyHandler statementProxyHandler,
|
||||
Statement statementProxy) {
|
||||
final ResultSetProxyHandler proxyHandler = new ResultSetProxyHandler( resultSet, statementProxyHandler, statementProxy );
|
||||
try {
|
||||
return resultSetProxyConstructorValue.getValue().newInstance( proxyHandler );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new JdbcProxyException( "Could not instantiate JDBC ResultSet proxy", e );
|
||||
}
|
||||
}
|
||||
|
||||
public static ResultSet buildImplicitResultSet(
|
||||
ResultSet resultSet,
|
||||
ConnectionProxyHandler connectionProxyHandler,
|
||||
Connection connectionProxy) {
|
||||
final ImplicitResultSetProxyHandler proxyHandler = new ImplicitResultSetProxyHandler(
|
||||
resultSet,
|
||||
connectionProxyHandler,
|
||||
connectionProxy
|
||||
);
|
||||
try {
|
||||
return resultSetProxyConstructorValue.getValue().newInstance( proxyHandler );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new JdbcProxyException( "Could not instantiate JDBC ResultSet proxy", e );
|
||||
}
|
||||
}
|
||||
|
||||
public static ResultSet buildImplicitResultSet(
|
||||
ResultSet resultSet,
|
||||
ConnectionProxyHandler connectionProxyHandler,
|
||||
Connection connectionProxy,
|
||||
Statement sourceStatement) {
|
||||
final ImplicitResultSetProxyHandler proxyHandler = new ImplicitResultSetProxyHandler(
|
||||
resultSet,
|
||||
connectionProxyHandler,
|
||||
connectionProxy,
|
||||
sourceStatement
|
||||
);
|
||||
try {
|
||||
return resultSetProxyConstructorValue.getValue().newInstance( proxyHandler );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new JdbcProxyException( "Could not instantiate JDBC ResultSet proxy", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// DatabaseMetaData ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
public static final Class[] METADATA_PROXY_INTERFACES = new Class[] {
|
||||
DatabaseMetaData.class,
|
||||
JdbcWrapper.class
|
||||
};
|
||||
|
||||
private static final ValueHolder<Constructor<DatabaseMetaData>> metadataProxyConstructorValue = new ValueHolder<Constructor<DatabaseMetaData>>(
|
||||
new ValueHolder.DeferredInitializer<Constructor<DatabaseMetaData>>() {
|
||||
@Override
|
||||
public Constructor<DatabaseMetaData> initialize() {
|
||||
try {
|
||||
return locateDatabaseMetaDataProxyClass().getConstructor( InvocationHandler.class );
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new JdbcProxyException( "Could not find proxy constructor in JDK generated DatabaseMetaData proxy class", e );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class<DatabaseMetaData> locateDatabaseMetaDataProxyClass() {
|
||||
return (Class<DatabaseMetaData>) Proxy.getProxyClass(
|
||||
JdbcWrapper.class.getClassLoader(),
|
||||
METADATA_PROXY_INTERFACES
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public static DatabaseMetaData buildDatabaseMetaData(
|
||||
DatabaseMetaData metaData,
|
||||
ConnectionProxyHandler connectionProxyHandler,
|
||||
Connection connectionProxy) {
|
||||
final DatabaseMetaDataProxyHandler proxyHandler = new DatabaseMetaDataProxyHandler(
|
||||
metaData,
|
||||
connectionProxyHandler,
|
||||
connectionProxy
|
||||
);
|
||||
try {
|
||||
return metadataProxyConstructorValue.getValue().newInstance( proxyHandler );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new JdbcProxyException( "Could not instantiate JDBC DatabaseMetaData proxy", e );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.internal.proxy;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.engine.jdbc.spi.JdbcResourceRegistry;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
|
||||
/**
|
||||
* Invocation handler for {@link java.sql.ResultSet} proxies
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ResultSetProxyHandler extends AbstractResultSetProxyHandler {
|
||||
private AbstractStatementProxyHandler statementProxyHandler;
|
||||
private Statement statementProxy;
|
||||
|
||||
public ResultSetProxyHandler(
|
||||
ResultSet resultSet,
|
||||
AbstractStatementProxyHandler statementProxyHandler,
|
||||
Statement statementProxy) {
|
||||
super( resultSet );
|
||||
this.statementProxyHandler = statementProxyHandler;
|
||||
this.statementProxy = statementProxy;
|
||||
}
|
||||
|
||||
protected AbstractStatementProxyHandler getStatementProxy() {
|
||||
return statementProxyHandler;
|
||||
}
|
||||
|
||||
protected Statement getExposableStatement() {
|
||||
return statementProxy;
|
||||
}
|
||||
|
||||
protected JdbcServices getJdbcServices() {
|
||||
return getStatementProxy().getJdbcServices();
|
||||
}
|
||||
|
||||
protected JdbcResourceRegistry getResourceRegistry() {
|
||||
return getStatementProxy().getResourceRegistry();
|
||||
}
|
||||
|
||||
protected void invalidateHandle() {
|
||||
statementProxyHandler = null;
|
||||
super.invalidateHandle();
|
||||
}
|
||||
}
|
|
@ -25,6 +25,8 @@ package org.hibernate.engine.jdbc.spi;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.engine.jdbc.batch.spi.Batch;
|
||||
import org.hibernate.engine.jdbc.batch.spi.BatchKey;
|
||||
|
@ -35,6 +37,7 @@ import org.hibernate.jdbc.WorkExecutorVisitable;
|
|||
* Coordinates JDBC-related activities.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public interface JdbcCoordinator extends Serializable {
|
||||
/**
|
||||
|
@ -77,6 +80,13 @@ public interface JdbcCoordinator extends Serializable {
|
|||
*/
|
||||
public StatementPreparer getStatementPreparer();
|
||||
|
||||
/**
|
||||
* Obtain the resultset extractor associated with this JDBC coordinator.
|
||||
*
|
||||
* @return This coordinator's resultset extractor
|
||||
*/
|
||||
public ResultSetReturn getResultSetReturn();
|
||||
|
||||
/**
|
||||
* Callback to let us know that a flush is beginning. We use this fact
|
||||
* to temporarily circumvent aggressive connection releasing until after
|
||||
|
@ -107,6 +117,13 @@ public interface JdbcCoordinator extends Serializable {
|
|||
*/
|
||||
public void afterTransaction();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Perform the requested work handling exceptions, coordinating and handling return processing.
|
||||
*
|
||||
|
@ -137,4 +154,56 @@ public interface JdbcCoordinator extends Serializable {
|
|||
* @throws org.hibernate.TransactionException Indicates the time out period has already been exceeded.
|
||||
*/
|
||||
public int determineRemainingTransactionTimeOutPeriod();
|
||||
/**
|
||||
* Register a JDBC statement.
|
||||
*
|
||||
* @param statement The statement to register.
|
||||
*/
|
||||
public void register(Statement statement);
|
||||
|
||||
/**
|
||||
* Release a previously registered statement.
|
||||
*
|
||||
* @param statement The statement to release.
|
||||
*/
|
||||
public void release(Statement statement);
|
||||
|
||||
/**
|
||||
* Register a JDBC result set.
|
||||
*
|
||||
* @param resultSet The result set to register.
|
||||
*/
|
||||
public void register(ResultSet resultSet);
|
||||
|
||||
/**
|
||||
* Release a previously registered result set.
|
||||
*
|
||||
* @param resultSet The result set to release.
|
||||
*/
|
||||
public void release(ResultSet resultSet);
|
||||
|
||||
/**
|
||||
* Does this registry currently have any registered resources?
|
||||
*
|
||||
* @return True if the registry does have registered resources; false otherwise.
|
||||
*/
|
||||
public boolean hasRegisteredResources();
|
||||
|
||||
/**
|
||||
* Release all registered resources.
|
||||
*/
|
||||
public void releaseResources();
|
||||
|
||||
public void enableReleases();
|
||||
|
||||
public void disableReleases();
|
||||
|
||||
/**
|
||||
* Register a query statement as being able to be cancelled.
|
||||
*
|
||||
* @param statement The cancel-able query statement.
|
||||
*/
|
||||
public void registerLastQuery(Statement statement);
|
||||
|
||||
public boolean isReadyForSerialization();
|
||||
}
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.spi;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* Defines a registry of JDBC resources related to a particular unit of work. The main function of a
|
||||
* JdbcResourceRegistry is to make sure resources get cleaned up. This is accomplished by registering all
|
||||
* JDBC-related resources via the {@link #register(java.sql.Statement)} and {@link #register(java.sql.ResultSet)}
|
||||
* methods. When done with these resources, they should be released by the corollary
|
||||
* {@link #release(java.sql.Statement)} and {@link #release(java.sql.ResultSet)} methods. Any un-released resources
|
||||
* will be released automatically when this registry is closed via {@link #close()}. Additionally,
|
||||
* all registered resources can be released at any time using {@link #releaseResources()}.
|
||||
* <p/>
|
||||
* Additionally, a query can be registered as being able to be cancelled via the {@link #registerLastQuery}
|
||||
* method. Such statements can then be cancelled by calling {@link #cancelLastQuery()}
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface JdbcResourceRegistry extends Serializable {
|
||||
/**
|
||||
* Register a JDBC statement.
|
||||
*
|
||||
* @param statement The statement to register.
|
||||
*/
|
||||
public void register(Statement statement);
|
||||
|
||||
/**
|
||||
* Release a previously registered statement.
|
||||
*
|
||||
* @param statement The statement to release.
|
||||
*/
|
||||
public void release(Statement statement);
|
||||
|
||||
/**
|
||||
* Register a JDBC result set.
|
||||
*
|
||||
* @param resultSet The result set to register.
|
||||
*/
|
||||
public void register(ResultSet resultSet);
|
||||
|
||||
/**
|
||||
* Release a previously registered result set.
|
||||
*
|
||||
* @param resultSet The result set to release.
|
||||
*/
|
||||
public void release(ResultSet resultSet);
|
||||
|
||||
/**
|
||||
* Does this registry currently have any registered resources?
|
||||
*
|
||||
* @return True if the registry does have registered resources; false otherwise.
|
||||
*/
|
||||
public boolean hasRegisteredResources();
|
||||
|
||||
/**
|
||||
* Release all registered resources.
|
||||
*/
|
||||
public void releaseResources();
|
||||
|
||||
/**
|
||||
* Close this registry. Also {@link #releaseResources releases} any registered resources.
|
||||
* <p/>
|
||||
* After execution, the registry is considered unusable.
|
||||
*/
|
||||
public void close();
|
||||
|
||||
/**
|
||||
* Register a query statement as being able to be cancelled.
|
||||
*
|
||||
* @param statement The cancel-able query statement.
|
||||
*/
|
||||
public void registerLastQuery(Statement statement);
|
||||
|
||||
/**
|
||||
* Cancel the last query registered via {@link #registerLastQuery}
|
||||
*/
|
||||
public void cancelLastQuery();
|
||||
}
|
|
@ -55,27 +55,10 @@ public interface LogicalConnection extends Serializable {
|
|||
* connection has either not yet been obtained (non-UserSuppliedConnectionProvider)
|
||||
* or has previously been aggressively released.
|
||||
*
|
||||
* @todo ?? Move this to {@link LogicalConnectionImplementor} in lieu of {@link #getShareableConnectionProxy} and {@link #getDistinctConnectionProxy} ??
|
||||
*
|
||||
* @return The current Connection.
|
||||
*/
|
||||
public Connection getConnection();
|
||||
|
||||
/**
|
||||
* Retrieves the shareable connection proxy.
|
||||
*
|
||||
* @return The shareable connection proxy.
|
||||
*/
|
||||
public Connection getShareableConnectionProxy();
|
||||
|
||||
/**
|
||||
* Retrieves a distinct connection proxy. It is distinct in that it is not shared with others unless the caller
|
||||
* explicitly shares it.
|
||||
*
|
||||
* @return The distinct connection proxy.
|
||||
*/
|
||||
public Connection getDistinctConnectionProxy();
|
||||
|
||||
/**
|
||||
* Release the underlying connection and clean up any other resources associated
|
||||
* with this logical connection.
|
||||
|
@ -85,9 +68,4 @@ public interface LogicalConnection extends Serializable {
|
|||
* @return The application-supplied connection, or {@code null} if Hibernate was managing connection.
|
||||
*/
|
||||
public Connection close();
|
||||
|
||||
/**
|
||||
* Signals the end of current transaction in which this logical connection operated.
|
||||
*/
|
||||
public void afterTransaction();
|
||||
}
|
||||
|
|
|
@ -25,11 +25,13 @@ package org.hibernate.engine.jdbc.spi;
|
|||
import java.sql.Connection;
|
||||
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.JDBCException;
|
||||
|
||||
/**
|
||||
* The "internal" contract for LogicalConnection
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public interface LogicalConnectionImplementor extends LogicalConnection {
|
||||
/**
|
||||
|
@ -39,13 +41,6 @@ public interface LogicalConnectionImplementor extends LogicalConnection {
|
|||
*/
|
||||
public JdbcServices getJdbcServices();
|
||||
|
||||
/**
|
||||
* Obtains the JDBC resource registry associated with this logical connection.
|
||||
*
|
||||
* @return The JDBC resource registry.
|
||||
*/
|
||||
public JdbcResourceRegistry getResourceRegistry();
|
||||
|
||||
/**
|
||||
* Add an observer interested in notification of connection events.
|
||||
*
|
||||
|
@ -67,30 +62,6 @@ public interface LogicalConnectionImplementor extends LogicalConnection {
|
|||
*/
|
||||
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 temporarily) circumvent aggressive release processing.
|
||||
*/
|
||||
public void disableReleases();
|
||||
|
||||
/**
|
||||
* Re-enable aggressive release processing (after a prior {@link #disableReleases()} call.
|
||||
*/
|
||||
public void enableReleases();
|
||||
|
||||
/**
|
||||
* Manually disconnect the underlying JDBC Connection. The assumption here
|
||||
* is that the manager will be reconnected at a later point in time.
|
||||
|
@ -107,10 +78,14 @@ public interface LogicalConnectionImplementor extends LogicalConnection {
|
|||
* with which to reconnect. It is an error to pass a connection in the other strategies.
|
||||
*/
|
||||
public void manualReconnect(Connection suppliedConnection);
|
||||
|
||||
public void aggressiveRelease();
|
||||
|
||||
public void releaseConnection() throws JDBCException;
|
||||
|
||||
public boolean isAutoCommit();
|
||||
|
||||
public boolean isReadyForSerialization();
|
||||
|
||||
public void notifyObserversStatementPrepared();
|
||||
|
||||
public boolean isUserSuppliedConnection();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.engine.jdbc.spi;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* Contract for extracting ResultSets from Statements, executing Statements,
|
||||
* managing Statement/ResultSet resources, and logging statement calls.
|
||||
*
|
||||
* TODO: This could eventually utilize the new Return interface. It would be
|
||||
* great to have a common API shared.
|
||||
*
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public interface ResultSetReturn {
|
||||
|
||||
/**
|
||||
* Extract the ResultSet from the statement.
|
||||
*
|
||||
* @param statement
|
||||
*
|
||||
* @return the ResultSet
|
||||
*/
|
||||
public ResultSet extract( PreparedStatement statement );
|
||||
|
||||
/**
|
||||
* Extract the ResultSet from the statement.
|
||||
*
|
||||
* @param statement
|
||||
*
|
||||
* @return the ResultSet
|
||||
*/
|
||||
public ResultSet extract( CallableStatement statement );
|
||||
|
||||
/**
|
||||
* Extract the ResultSet from the statement.
|
||||
*
|
||||
* @param statement
|
||||
* @param sql
|
||||
*
|
||||
* @return the ResultSet
|
||||
*/
|
||||
public ResultSet extract( Statement statement, String sql );
|
||||
|
||||
/**
|
||||
* Execute the Statement query and, if results in a ResultSet, extract it.
|
||||
*
|
||||
* @param statement
|
||||
*
|
||||
* @return the ResultSet
|
||||
*/
|
||||
public ResultSet execute( PreparedStatement statement );
|
||||
|
||||
/**
|
||||
* Execute the Statement query and, if results in a ResultSet, extract it.
|
||||
*
|
||||
* @param statement
|
||||
* @param sql
|
||||
*
|
||||
* @return the ResultSet
|
||||
*/
|
||||
public ResultSet execute( Statement statement, String sql );
|
||||
|
||||
/**
|
||||
* Execute the Statement queryUpdate.
|
||||
*
|
||||
* @param statement
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public int executeUpdate( PreparedStatement statement );
|
||||
|
||||
/**
|
||||
* Execute the Statement query and, if results in a ResultSet, extract it.
|
||||
*
|
||||
* @param statement
|
||||
* @param sql
|
||||
*
|
||||
* @return the ResultSet
|
||||
*/
|
||||
public int executeUpdate( Statement statement, String sql );
|
||||
}
|
|
@ -24,6 +24,7 @@
|
|||
package org.hibernate.engine.jdbc.spi;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.ScrollMode;
|
||||
|
||||
|
@ -31,8 +32,18 @@ import org.hibernate.ScrollMode;
|
|||
* Contracting for preparing SQL statements
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public interface StatementPreparer {
|
||||
/**
|
||||
* Create a statement.
|
||||
*
|
||||
* @param sql The SQL the statement to be created
|
||||
*
|
||||
* @return the statement
|
||||
*/
|
||||
public Statement createStatement();
|
||||
|
||||
/**
|
||||
* Prepare a statement.
|
||||
*
|
||||
|
|
|
@ -201,11 +201,11 @@ public class NativeSQLQueryPlan implements Serializable {
|
|||
session );
|
||||
col += bindNamedParameters( ps, queryParameters
|
||||
.getNamedParameters(), col, session );
|
||||
result = ps.executeUpdate();
|
||||
result = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
|
||||
}
|
||||
finally {
|
||||
if ( ps != null ) {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,7 +193,7 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
|
|||
// check to see if the connection is in auto-commit mode (no connection means aggressive connection
|
||||
// release outside a JTA transaction context, so MUST be autocommit mode)
|
||||
boolean isAutocommit = getJdbcCoordinator().getLogicalConnection().isAutoCommit();
|
||||
getJdbcCoordinator().getLogicalConnection().afterTransaction();
|
||||
getJdbcCoordinator().afterTransaction();
|
||||
|
||||
if ( isAutocommit ) {
|
||||
for ( TransactionObserver observer : observers ) {
|
||||
|
|
|
@ -64,7 +64,6 @@ public class JdbcIsolationDelegate implements IsolationDelegate {
|
|||
public <T> T delegateWork(WorkExecutorVisitable<T> work, boolean transacted) throws HibernateException {
|
||||
boolean wasAutoCommit = false;
|
||||
try {
|
||||
// todo : should we use a connection proxy here?
|
||||
Connection connection = jdbcConnectionAccess().obtainConnection();
|
||||
try {
|
||||
if ( transacted ) {
|
||||
|
|
|
@ -100,11 +100,11 @@ public class BasicExecutor implements StatementExecutor {
|
|||
}
|
||||
}
|
||||
|
||||
return st.executeUpdate();
|
||||
return session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st );
|
||||
}
|
||||
finally {
|
||||
if ( st != null ) {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,8 +144,8 @@ public class PersistentTableBulkIdStrategy implements MultiTableBulkIdStrategy {
|
|||
}
|
||||
|
||||
try {
|
||||
// TODO: session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().createStatement();
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
for ( Table idTableDefinition : idTableDefinitions ) {
|
||||
if ( cleanUpTables ) {
|
||||
if ( tableCleanUpDdl == null ) {
|
||||
|
@ -156,6 +156,7 @@ public class PersistentTableBulkIdStrategy implements MultiTableBulkIdStrategy {
|
|||
try {
|
||||
final String sql = idTableDefinition.sqlCreateString( jdbcServices.getDialect(), mapping, null, null );
|
||||
jdbcServices.getSqlStatementLogger().logStatement( sql );
|
||||
// TODO: ResultSetExtractor
|
||||
statement.execute( sql );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
|
@ -163,6 +164,8 @@ public class PersistentTableBulkIdStrategy implements MultiTableBulkIdStrategy {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
// session.getTransactionCoordinator().getJdbcCoordinator().release( statement );
|
||||
statement.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
|
@ -191,6 +194,7 @@ public class PersistentTableBulkIdStrategy implements MultiTableBulkIdStrategy {
|
|||
Connection connection = connectionAccess.obtainConnection();
|
||||
|
||||
try {
|
||||
// TODO: session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().createStatement();
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
for ( String cleanupDdl : tableCleanUpDdl ) {
|
||||
|
@ -203,6 +207,8 @@ public class PersistentTableBulkIdStrategy implements MultiTableBulkIdStrategy {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
// session.getTransactionCoordinator().getJdbcCoordinator().release( statement );
|
||||
statement.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
|
@ -267,12 +273,12 @@ public class PersistentTableBulkIdStrategy implements MultiTableBulkIdStrategy {
|
|||
try {
|
||||
ps = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql, false );
|
||||
bindSessionIdentifier( ps, session, 1 );
|
||||
ps.executeUpdate();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
|
||||
}
|
||||
finally {
|
||||
if ( ps != null ) {
|
||||
try {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
// ignore
|
||||
|
|
|
@ -121,11 +121,11 @@ public class TableBasedDeleteHandlerImpl
|
|||
for ( ParameterSpecification parameterSpecification : idSelectParameterSpecifications ) {
|
||||
pos += parameterSpecification.bind( ps, queryParameters, session, pos );
|
||||
}
|
||||
resultCount = ps.executeUpdate();
|
||||
resultCount = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
|
||||
}
|
||||
finally {
|
||||
if ( ps != null ) {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,11 +142,11 @@ public class TableBasedDeleteHandlerImpl
|
|||
.getStatementPreparer()
|
||||
.prepareStatement( delete, false );
|
||||
handleAddedParametersOnDelete( ps, session );
|
||||
ps.executeUpdate();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
|
||||
}
|
||||
finally {
|
||||
if ( ps != null ) {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,11 +141,11 @@ public class TableBasedUpdateHandlerImpl
|
|||
for ( ParameterSpecification parameterSpecification : idSelectParameterSpecifications ) {
|
||||
sum += parameterSpecification.bind( ps, queryParameters, session, sum );
|
||||
}
|
||||
resultCount = ps.executeUpdate();
|
||||
resultCount = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
|
||||
}
|
||||
finally {
|
||||
if ( ps != null ) {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -168,11 +168,11 @@ public class TableBasedUpdateHandlerImpl
|
|||
}
|
||||
handleAddedParametersOnUpdate( ps, session, position );
|
||||
}
|
||||
ps.executeUpdate();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
|
||||
}
|
||||
finally {
|
||||
if ( ps != null ) {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@ import java.sql.SQLWarning;
|
|||
import java.sql.Statement;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.cfg.Mappings;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcConnectionAccess;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
|
@ -42,6 +40,7 @@ import org.hibernate.hql.internal.ast.HqlSqlWalker;
|
|||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.jdbc.AbstractWork;
|
||||
import org.hibernate.persister.entity.Queryable;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -111,11 +110,10 @@ public class TemporaryTableBulkIdStrategy implements MultiTableBulkIdStrategy {
|
|||
final Connection connection = session.getTransactionCoordinator()
|
||||
.getJdbcCoordinator()
|
||||
.getLogicalConnection()
|
||||
.getShareableConnectionProxy();
|
||||
.getConnection();
|
||||
work.execute( connection );
|
||||
session.getTransactionCoordinator()
|
||||
.getJdbcCoordinator()
|
||||
.getLogicalConnection()
|
||||
.afterStatementExecution();
|
||||
}
|
||||
}
|
||||
|
@ -133,11 +131,10 @@ public class TemporaryTableBulkIdStrategy implements MultiTableBulkIdStrategy {
|
|||
final Connection connection = session.getTransactionCoordinator()
|
||||
.getJdbcCoordinator()
|
||||
.getLogicalConnection()
|
||||
.getShareableConnectionProxy();
|
||||
.getConnection();
|
||||
work.execute( connection );
|
||||
session.getTransactionCoordinator()
|
||||
.getJdbcCoordinator()
|
||||
.getLogicalConnection()
|
||||
.afterStatementExecution();
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +144,7 @@ public class TemporaryTableBulkIdStrategy implements MultiTableBulkIdStrategy {
|
|||
try {
|
||||
final String sql = "delete from " + persister.getTemporaryIdTableName();
|
||||
ps = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql, false );
|
||||
ps.executeUpdate();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
|
||||
}
|
||||
catch( Throwable t ) {
|
||||
log.unableToCleanupTemporaryIdTable(t);
|
||||
|
@ -155,7 +152,7 @@ public class TemporaryTableBulkIdStrategy implements MultiTableBulkIdStrategy {
|
|||
finally {
|
||||
if ( ps != null ) {
|
||||
try {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
// ignore
|
||||
|
@ -247,7 +244,6 @@ public class TemporaryTableBulkIdStrategy implements MultiTableBulkIdStrategy {
|
|||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
try {
|
||||
statement = connection.createStatement();
|
||||
statement.executeUpdate( command );
|
||||
}
|
||||
finally {
|
||||
|
|
|
@ -57,20 +57,20 @@ public class GUIDGenerator implements IdentifierGenerator {
|
|||
try {
|
||||
PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
|
||||
try {
|
||||
ResultSet rs = st.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
|
||||
final String result;
|
||||
try {
|
||||
rs.next();
|
||||
result = rs.getString(1);
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
LOG.guidGenerated(result);
|
||||
return result;
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
|
|
|
@ -92,8 +92,8 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
|
|||
.prepareStatement( insertSQL, PreparedStatement.RETURN_GENERATED_KEYS );
|
||||
}
|
||||
|
||||
public Serializable executeAndExtract(PreparedStatement insert) throws SQLException {
|
||||
insert.executeUpdate();
|
||||
public Serializable executeAndExtract(PreparedStatement insert, SessionImplementor session) throws SQLException {
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( insert );
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
rs = insert.getGeneratedKeys();
|
||||
|
@ -105,7 +105,7 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
|
|||
}
|
||||
finally {
|
||||
if ( rs != null ) {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,13 +140,8 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
|
|||
.prepareStatement( insertSQL, PreparedStatement.NO_GENERATED_KEYS );
|
||||
}
|
||||
|
||||
public Serializable executeAndExtract(PreparedStatement insert) throws SQLException {
|
||||
if ( !insert.execute() ) {
|
||||
while ( !insert.getMoreResults() && insert.getUpdateCount() != -1 ) {
|
||||
// do nothing until we hit the rsult set containing the generated id
|
||||
}
|
||||
}
|
||||
ResultSet rs = insert.getResultSet();
|
||||
public Serializable executeAndExtract(PreparedStatement insert, SessionImplementor session) throws SQLException {
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().execute( insert );
|
||||
try {
|
||||
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
||||
rs,
|
||||
|
@ -155,7 +150,7 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
|
|||
);
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ public class IncrementGenerator implements IdentifierGenerator, Configurable {
|
|||
try {
|
||||
PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
|
||||
try {
|
||||
ResultSet rs = st.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
|
||||
try {
|
||||
if (rs.next()) previousValueHolder.initialize(rs, 0L).increment();
|
||||
else previousValueHolder.initialize(1L);
|
||||
|
@ -136,11 +136,11 @@ public class IncrementGenerator implements IdentifierGenerator, Configurable {
|
|||
}
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
|
|
|
@ -119,7 +119,7 @@ public class SequenceGenerator
|
|||
try {
|
||||
PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
|
||||
try {
|
||||
ResultSet rs = st.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
|
||||
try {
|
||||
rs.next();
|
||||
IntegralDataTypeHolder result = buildHolder();
|
||||
|
@ -128,11 +128,11 @@ public class SequenceGenerator
|
|||
return result;
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -107,8 +107,8 @@ public class SequenceIdentityGenerator
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Serializable executeAndExtract(PreparedStatement insert) throws SQLException {
|
||||
insert.executeUpdate();
|
||||
protected Serializable executeAndExtract(PreparedStatement insert, SessionImplementor session) throws SQLException {
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( insert );
|
||||
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
||||
insert.getGeneratedKeys(),
|
||||
getPersister().getRootTableKeyColumnNames()[0],
|
||||
|
|
|
@ -143,7 +143,7 @@ public class TableGenerator implements PersistentIdentifierGenerator, Configurab
|
|||
return generateHolder( session ).makeValue();
|
||||
}
|
||||
|
||||
protected IntegralDataTypeHolder generateHolder(SessionImplementor session) {
|
||||
protected IntegralDataTypeHolder generateHolder(final SessionImplementor session) {
|
||||
final SqlStatementLogger statementLogger = session
|
||||
.getFactory()
|
||||
.getServiceRegistry()
|
||||
|
@ -181,7 +181,7 @@ public class TableGenerator implements PersistentIdentifierGenerator, Configurab
|
|||
}
|
||||
|
||||
statementLogger.logStatement( update, FormatStyle.BASIC.getFormatter() );
|
||||
PreparedStatement ups = connection.prepareStatement(update);
|
||||
PreparedStatement ups = connection.prepareStatement( update );
|
||||
try {
|
||||
value.copy().increment().bind( ups, 1 );
|
||||
value.bind( ups, 2 );
|
||||
|
|
|
@ -95,7 +95,7 @@ public class SequenceStructure implements DatabaseStructure {
|
|||
try {
|
||||
PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
|
||||
try {
|
||||
ResultSet rs = st.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
|
||||
try {
|
||||
rs.next();
|
||||
IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( numberType );
|
||||
|
@ -107,7 +107,7 @@ public class SequenceStructure implements DatabaseStructure {
|
|||
}
|
||||
finally {
|
||||
try {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
// intentionally empty
|
||||
|
@ -115,7 +115,7 @@ public class SequenceStructure implements DatabaseStructure {
|
|||
}
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public abstract class AbstractReturningDelegate implements InsertGeneratedIdenti
|
|||
PreparedStatement insert = prepare( insertSQL, session );
|
||||
try {
|
||||
binder.bindValues( insert );
|
||||
return executeAndExtract( insert );
|
||||
return executeAndExtract( insert, session );
|
||||
}
|
||||
finally {
|
||||
releaseStatement( insert, session );
|
||||
|
@ -76,9 +76,9 @@ public abstract class AbstractReturningDelegate implements InsertGeneratedIdenti
|
|||
|
||||
protected abstract PreparedStatement prepare(String insertSQL, SessionImplementor session) throws SQLException;
|
||||
|
||||
protected abstract Serializable executeAndExtract(PreparedStatement insert) throws SQLException;
|
||||
protected abstract Serializable executeAndExtract(PreparedStatement insert, SessionImplementor session) throws SQLException;
|
||||
|
||||
protected void releaseStatement(PreparedStatement insert, SessionImplementor session) throws SQLException {
|
||||
insert.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( insert );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,10 +58,10 @@ public abstract class AbstractSelectingDelegate implements InsertGeneratedIdenti
|
|||
.prepareStatement( insertSQL, PreparedStatement.NO_GENERATED_KEYS );
|
||||
try {
|
||||
binder.bindValues( insert );
|
||||
insert.executeUpdate();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( insert );
|
||||
}
|
||||
finally {
|
||||
insert.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( insert );
|
||||
}
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
|
@ -82,16 +82,16 @@ public abstract class AbstractSelectingDelegate implements InsertGeneratedIdenti
|
|||
.prepareStatement( selectSQL, false );
|
||||
try {
|
||||
bindParameters( session, idSelect, binder.getEntity() );
|
||||
ResultSet rs = idSelect.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( idSelect );
|
||||
try {
|
||||
return getResult( session, rs, binder.getEntity() );
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
idSelect.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( idSelect );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -115,26 +115,16 @@ public abstract class AbstractScrollableResults implements ScrollableResults {
|
|||
}
|
||||
|
||||
public final void close() throws HibernateException {
|
||||
// not absolutely necessary, but does help with aggressive release
|
||||
//session.getJDBCContext().getConnectionManager().closeQueryStatement( ps, resultSet );
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
try {
|
||||
// not absolutely necessary, but does help with aggressive release
|
||||
//session.getJDBCContext().getConnectionManager().closeQueryStatement( ps, resultSet );
|
||||
ps.close();
|
||||
session.getPersistenceContext().getLoadContexts().cleanup( resultSet );
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
throw session.getFactory().getSQLExceptionHelper().convert(
|
||||
sqle,
|
||||
"could not close results"
|
||||
);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
session.getPersistenceContext().getLoadContexts().cleanup( resultSet );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
// ignore this error for now
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev( "Exception trying to cleanup load context : {0}", ignore.getMessage() );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
// ignore this error for now
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev( "Exception trying to cleanup load context : {0}", ignore.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,28 +83,17 @@ public final class IteratorImpl implements HibernateIterator {
|
|||
|
||||
public void close() throws JDBCException {
|
||||
if (ps!=null) {
|
||||
LOG.debug("Closing iterator");
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
ps = null;
|
||||
rs = null;
|
||||
hasNext = false;
|
||||
try {
|
||||
LOG.debug("Closing iterator");
|
||||
ps.close();
|
||||
ps = null;
|
||||
rs = null;
|
||||
hasNext = false;
|
||||
session.getPersistenceContext().getLoadContexts().cleanup( rs );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
LOG.unableToCloseIterator(e);
|
||||
throw session.getFactory().getSQLExceptionHelper().convert(
|
||||
e,
|
||||
"Unable to close iterator"
|
||||
);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
session.getPersistenceContext().getLoadContexts().cleanup( rs );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
// ignore this error for now
|
||||
LOG.debugf("Exception trying to cleanup load context : %s", ignore.getMessage());
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
// ignore this error for now
|
||||
LOG.debugf("Exception trying to cleanup load context : %s", ignore.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,8 +47,6 @@ import java.util.Set;
|
|||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.CacheMode;
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
|
@ -76,7 +74,6 @@ import org.hibernate.ScrollableResults;
|
|||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionBuilder;
|
||||
import org.hibernate.SessionException;
|
||||
import org.hibernate.engine.spi.SessionOwner;
|
||||
import org.hibernate.SharedSessionBuilder;
|
||||
import org.hibernate.SimpleNaturalIdLoadAccess;
|
||||
import org.hibernate.Transaction;
|
||||
|
@ -101,6 +98,7 @@ import org.hibernate.engine.spi.NonFlushedChanges;
|
|||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionOwner;
|
||||
import org.hibernate.engine.spi.Status;
|
||||
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
|
||||
import org.hibernate.engine.transaction.spi.TransactionCoordinator;
|
||||
|
@ -140,7 +138,6 @@ import org.hibernate.event.spi.ResolveNaturalIdEventListener;
|
|||
import org.hibernate.event.spi.SaveOrUpdateEvent;
|
||||
import org.hibernate.event.spi.SaveOrUpdateEventListener;
|
||||
import org.hibernate.internal.CriteriaImpl.CriterionEntry;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.jdbc.ReturningWork;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.jdbc.WorkExecutor;
|
||||
|
@ -158,6 +155,7 @@ import org.hibernate.stat.SessionStatistics;
|
|||
import org.hibernate.stat.internal.SessionStatisticsImpl;
|
||||
import org.hibernate.type.SerializationException;
|
||||
import org.hibernate.type.Type;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Concrete implementation of a Session.
|
||||
|
@ -545,7 +543,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
|||
|
||||
public Connection connection() throws HibernateException {
|
||||
errorIfClosed();
|
||||
return transactionCoordinator.getJdbcCoordinator().getLogicalConnection().getDistinctConnectionProxy();
|
||||
return transactionCoordinator.getJdbcCoordinator().getLogicalConnection().getConnection();
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
|
@ -562,6 +560,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
|||
public Connection disconnect() throws HibernateException {
|
||||
errorIfClosed();
|
||||
LOG.debug( "Disconnecting session" );
|
||||
transactionCoordinator.getJdbcCoordinator().releaseResources();
|
||||
return transactionCoordinator.getJdbcCoordinator().getLogicalConnection().manualDisconnect();
|
||||
}
|
||||
|
||||
|
@ -2113,7 +2112,7 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
|||
* @throws IOException Indicates a general IO stream exception
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream oos) throws IOException {
|
||||
if ( ! transactionCoordinator.getJdbcCoordinator().getLogicalConnection().isReadyForSerialization() ) {
|
||||
if ( ! transactionCoordinator.getJdbcCoordinator().isReadyForSerialization() ) {
|
||||
throw new IllegalStateException( "Cannot serialize a session while connected" );
|
||||
}
|
||||
|
||||
|
|
|
@ -405,7 +405,7 @@ public class StatelessSessionImpl extends AbstractSessionImpl implements Statele
|
|||
@Override
|
||||
public Connection connection() {
|
||||
errorIfClosed();
|
||||
return transactionCoordinator.getJdbcCoordinator().getLogicalConnection().getDistinctConnectionProxy();
|
||||
return transactionCoordinator.getJdbcCoordinator().getLogicalConnection().getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -910,7 +910,7 @@ public abstract class Loader {
|
|||
return processResultSet( rs, queryParameters, session, returnProxies, forcedResultTransformer, maxRows, afterLoadActions );
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1903,11 +1903,11 @@ public abstract class Loader {
|
|||
LOG.tracev( "Bound [{0}] parameters total", col );
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
throw sqle;
|
||||
}
|
||||
catch ( HibernateException he ) {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
throw he;
|
||||
}
|
||||
|
||||
|
@ -2028,7 +2028,7 @@ public abstract class Loader {
|
|||
throws SQLException, HibernateException {
|
||||
|
||||
try {
|
||||
ResultSet rs = st.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
|
||||
rs = wrapResultSetIfEnabled( rs , session );
|
||||
|
||||
if ( !limitHandler.supportsLimitOffset() || !LimitHelper.useLimit( limitHandler, selection ) ) {
|
||||
|
@ -2041,7 +2041,7 @@ public abstract class Loader {
|
|||
return rs;
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
throw sqle;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -259,7 +259,7 @@ public class DynamicBatchingCollectionInitializerBuilder extends BatchingCollect
|
|||
processResultSet( rs, queryParameters, session, true, null, maxRows, afterLoadActions );
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ public class DynamicBatchingEntityLoaderBuilder extends BatchingEntityLoaderBuil
|
|||
return processResultSet( rs, queryParameters, session, false, null, maxRows, afterLoadActions );
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1164,7 +1164,7 @@ public abstract class AbstractCollectionPersister
|
|||
.addToBatch();
|
||||
}
|
||||
else {
|
||||
expectation.verifyOutcome( st.executeUpdate(), st, -1 );
|
||||
expectation.verifyOutcome( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 );
|
||||
}
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
|
@ -1175,7 +1175,7 @@ public abstract class AbstractCollectionPersister
|
|||
}
|
||||
finally {
|
||||
if ( !useBatch ) {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1263,7 +1263,7 @@ public abstract class AbstractCollectionPersister
|
|||
.addToBatch();
|
||||
}
|
||||
else {
|
||||
expectation.verifyOutcome( st.executeUpdate(), st, -1 );
|
||||
expectation.verifyOutcome( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 );
|
||||
}
|
||||
|
||||
collection.afterRowInsert( this, entry, i );
|
||||
|
@ -1277,7 +1277,7 @@ public abstract class AbstractCollectionPersister
|
|||
}
|
||||
finally {
|
||||
if ( !useBatch ) {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1377,7 +1377,7 @@ public abstract class AbstractCollectionPersister
|
|||
.addToBatch();
|
||||
}
|
||||
else {
|
||||
expectation.verifyOutcome( st.executeUpdate(), st, -1 );
|
||||
expectation.verifyOutcome( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 );
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
@ -1389,7 +1389,7 @@ public abstract class AbstractCollectionPersister
|
|||
}
|
||||
finally {
|
||||
if ( !useBatch ) {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1478,7 +1478,7 @@ public abstract class AbstractCollectionPersister
|
|||
session.getTransactionCoordinator().getJdbcCoordinator().getBatch( insertBatchKey ).addToBatch();
|
||||
}
|
||||
else {
|
||||
expectation.verifyOutcome( st.executeUpdate(), st, -1 );
|
||||
expectation.verifyOutcome( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 );
|
||||
}
|
||||
collection.afterRowInsert( this, entry, i );
|
||||
count++;
|
||||
|
@ -1491,7 +1491,7 @@ public abstract class AbstractCollectionPersister
|
|||
}
|
||||
finally {
|
||||
if ( !useBatch ) {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1795,16 +1795,16 @@ public abstract class AbstractCollectionPersister
|
|||
.prepareStatement( sqlSelectSizeString );
|
||||
try {
|
||||
getKeyType().nullSafeSet( st, key, 1, session );
|
||||
ResultSet rs = st.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
|
||||
try {
|
||||
return rs.next() ? rs.getInt( 1 ) - baseIndex : 0;
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
|
@ -1834,19 +1834,19 @@ public abstract class AbstractCollectionPersister
|
|||
try {
|
||||
getKeyType().nullSafeSet( st, key, 1, session );
|
||||
indexOrElementType.nullSafeSet( st, indexOrElement, keyColumnNames.length + 1, session );
|
||||
ResultSet rs = st.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
|
||||
try {
|
||||
return rs.next();
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
catch ( TransientObjectException e ) {
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
|
@ -1868,7 +1868,7 @@ public abstract class AbstractCollectionPersister
|
|||
try {
|
||||
getKeyType().nullSafeSet( st, key, 1, session );
|
||||
getIndexType().nullSafeSet( st, incrementIndexByBase( index ), keyColumnNames.length + 1, session );
|
||||
ResultSet rs = st.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
|
||||
try {
|
||||
if ( rs.next() ) {
|
||||
return getElementType().nullSafeGet( rs, elementColumnAliases, session, owner );
|
||||
|
@ -1878,11 +1878,11 @@ public abstract class AbstractCollectionPersister
|
|||
}
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
|
|
|
@ -262,7 +262,7 @@ public class BasicCollectionPersister extends AbstractCollectionPersister {
|
|||
.addToBatch();
|
||||
}
|
||||
else {
|
||||
expectation.verifyOutcome( st.executeUpdate(), st, -1 );
|
||||
expectation.verifyOutcome( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 );
|
||||
}
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
|
@ -273,7 +273,7 @@ public class BasicCollectionPersister extends AbstractCollectionPersister {
|
|||
}
|
||||
finally {
|
||||
if ( !useBatch ) {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
count++;
|
||||
|
|
|
@ -235,7 +235,7 @@ public class OneToManyPersister extends AbstractCollectionPersister {
|
|||
.addToBatch();
|
||||
}
|
||||
else {
|
||||
deleteExpectation.verifyOutcome( st.executeUpdate(), st, -1 );
|
||||
deleteExpectation.verifyOutcome( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 );
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ public class OneToManyPersister extends AbstractCollectionPersister {
|
|||
}
|
||||
finally {
|
||||
if ( !useBatch ) {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ public class OneToManyPersister extends AbstractCollectionPersister {
|
|||
session.getTransactionCoordinator().getJdbcCoordinator().getBatch( insertRowBatchKey ).addToBatch();
|
||||
}
|
||||
else {
|
||||
insertExpectation.verifyOutcome( st.executeUpdate(), st, -1 );
|
||||
insertExpectation.verifyOutcome( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 );
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ public class OneToManyPersister extends AbstractCollectionPersister {
|
|||
}
|
||||
finally {
|
||||
if ( !useBatch ) {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1265,7 +1265,7 @@ public abstract class AbstractEntityPersister
|
|||
.getStatementPreparer()
|
||||
.prepareStatement( lazySelect );
|
||||
getIdentifierType().nullSafeSet( ps, id, 1, session );
|
||||
rs = ps.executeQuery();
|
||||
rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( ps );
|
||||
rs.next();
|
||||
}
|
||||
final Object[] snapshot = entry.getLoadedState();
|
||||
|
@ -1278,13 +1278,13 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
finally {
|
||||
if ( rs != null ) {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if ( ps != null ) {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1517,7 +1517,7 @@ public abstract class AbstractEntityPersister
|
|||
try {
|
||||
getIdentifierType().nullSafeSet( ps, id, 1, session );
|
||||
//if ( isVersioned() ) getVersionType().nullSafeSet( ps, version, getIdentifierColumnSpan()+1, session );
|
||||
ResultSet rs = ps.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( ps );
|
||||
try {
|
||||
//if there is no resulting row, return null
|
||||
if ( !rs.next() ) {
|
||||
|
@ -1535,11 +1535,11 @@ public abstract class AbstractEntityPersister
|
|||
return values;
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
|
@ -1577,7 +1577,7 @@ public abstract class AbstractEntityPersister
|
|||
.prepareStatement( generateIdByUniqueKeySelectString( uniquePropertyName ) );
|
||||
try {
|
||||
propertyType.nullSafeSet( ps, key, 1, session );
|
||||
ResultSet rs = ps.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( ps );
|
||||
try {
|
||||
//if there is no resulting row, return null
|
||||
if ( !rs.next() ) {
|
||||
|
@ -1586,11 +1586,11 @@ public abstract class AbstractEntityPersister
|
|||
return (Serializable) getIdentifierType().nullSafeGet( rs, getIdentifierAliases(), session, null );
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
|
@ -1830,13 +1830,13 @@ public abstract class AbstractEntityPersister
|
|||
getVersionType().nullSafeSet( st, nextVersion, 1, session );
|
||||
getIdentifierType().nullSafeSet( st, id, 2, session );
|
||||
getVersionType().nullSafeSet( st, currentVersion, 2 + getIdentifierColumnSpan(), session );
|
||||
int rows = st.executeUpdate();
|
||||
int rows = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st );
|
||||
if ( rows != 1 ) {
|
||||
throw new StaleObjectStateException( getEntityName(), id );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
|
@ -1879,7 +1879,7 @@ public abstract class AbstractEntityPersister
|
|||
.prepareStatement( getVersionSelectString() );
|
||||
try {
|
||||
getIdentifierType().nullSafeSet( st, id, 1, session );
|
||||
ResultSet rs = st.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
|
||||
try {
|
||||
if ( !rs.next() ) {
|
||||
return null;
|
||||
|
@ -1890,11 +1890,11 @@ public abstract class AbstractEntityPersister
|
|||
return getVersionType().nullSafeGet( rs, getVersionColumnName(), session, null );
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
st.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
|
@ -2852,7 +2852,7 @@ public abstract class AbstractEntityPersister
|
|||
.getStatementPreparer()
|
||||
.prepareStatement( sql );
|
||||
rootPersister.getIdentifierType().nullSafeSet( sequentialSelect, id, 1, session );
|
||||
sequentialResultSet = sequentialSelect.executeQuery();
|
||||
sequentialResultSet = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( sequentialSelect );
|
||||
if ( !sequentialResultSet.next() ) {
|
||||
// TODO: Deal with the "optional" attribute in the <join> mapping;
|
||||
// this code assumes that optional defaults to "true" because it
|
||||
|
@ -2909,7 +2909,7 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
|
||||
if ( sequentialResultSet != null ) {
|
||||
sequentialResultSet.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( sequentialResultSet );
|
||||
}
|
||||
|
||||
return values;
|
||||
|
@ -2917,7 +2917,7 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
finally {
|
||||
if ( sequentialSelect != null ) {
|
||||
sequentialSelect.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( sequentialSelect );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3058,7 +3058,7 @@ public abstract class AbstractEntityPersister
|
|||
session.getTransactionCoordinator().getJdbcCoordinator().getBatch( inserBatchKey ).addToBatch();
|
||||
}
|
||||
else {
|
||||
expectation.verifyOutcome( insert.executeUpdate(), insert, -1 );
|
||||
expectation.verifyOutcome( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( insert ), insert, -1 );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3070,7 +3070,7 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
finally {
|
||||
if ( !useBatch ) {
|
||||
insert.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( insert );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3216,7 +3216,7 @@ public abstract class AbstractEntityPersister
|
|||
return true;
|
||||
}
|
||||
else {
|
||||
return check( update.executeUpdate(), id, j, expectation, update );
|
||||
return check( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( update ), id, j, expectation, update );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3228,7 +3228,7 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
finally {
|
||||
if ( !useBatch ) {
|
||||
update.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( update );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3333,7 +3333,7 @@ public abstract class AbstractEntityPersister
|
|||
session.getTransactionCoordinator().getJdbcCoordinator().getBatch( deleteBatchKey ).addToBatch();
|
||||
}
|
||||
else {
|
||||
check( delete.executeUpdate(), id, j, expectation, delete );
|
||||
check( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( delete ), id, j, expectation, delete );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3345,7 +3345,7 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
finally {
|
||||
if ( !useBatch ) {
|
||||
delete.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( delete );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4629,7 +4629,7 @@ public abstract class AbstractEntityPersister
|
|||
.prepareStatement( selectionSQL );
|
||||
try {
|
||||
getIdentifierType().nullSafeSet( ps, id, 1, session );
|
||||
ResultSet rs = ps.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( ps );
|
||||
try {
|
||||
if ( !rs.next() ) {
|
||||
throw new HibernateException(
|
||||
|
@ -4647,12 +4647,12 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
finally {
|
||||
if ( rs != null ) {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
catch( SQLException e ) {
|
||||
|
@ -4729,7 +4729,7 @@ public abstract class AbstractEntityPersister
|
|||
.prepareStatement( sql );
|
||||
try {
|
||||
getIdentifierType().nullSafeSet( ps, id, 1, session );
|
||||
ResultSet rs = ps.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( ps );
|
||||
try {
|
||||
//if there is no resulting row, return null
|
||||
if ( !rs.next() ) {
|
||||
|
@ -4746,11 +4746,11 @@ public abstract class AbstractEntityPersister
|
|||
return snapshot;
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
|
@ -4794,7 +4794,7 @@ public abstract class AbstractEntityPersister
|
|||
positions += type.getColumnSpan( session.getFactory() );
|
||||
}
|
||||
}
|
||||
ResultSet rs = ps.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( ps );
|
||||
try {
|
||||
// if there is no resulting row, return null
|
||||
if ( !rs.next() ) {
|
||||
|
@ -4804,11 +4804,11 @@ public abstract class AbstractEntityPersister
|
|||
return (Serializable) getIdentifierType().hydrate( rs, getIdentifierAliases(), session, null );
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
ps.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
|
|
|
@ -122,7 +122,7 @@ public class DatabaseMetadata {
|
|||
|
||||
}
|
||||
finally {
|
||||
if (rs!=null) rs.close();
|
||||
rs.close();
|
||||
}
|
||||
}
|
||||
catch (SQLException sqlException) {
|
||||
|
@ -153,8 +153,8 @@ public class DatabaseMetadata {
|
|||
}
|
||||
}
|
||||
finally {
|
||||
if (rs!=null) rs.close();
|
||||
if (statement!=null) statement.close();
|
||||
rs.close();
|
||||
statement.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,11 +30,10 @@ import java.sql.SQLException;
|
|||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* <tt>dbtimestamp</tt>: An extension of {@link TimestampType} which
|
||||
|
@ -91,7 +90,7 @@ public class DbTimestampType extends TimestampType {
|
|||
.getJdbcCoordinator()
|
||||
.getStatementPreparer()
|
||||
.prepareStatement( timestampSelectString, false );
|
||||
ResultSet rs = ps.executeQuery();
|
||||
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( ps );
|
||||
rs.next();
|
||||
Timestamp ts = rs.getTimestamp( 1 );
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
|
@ -108,12 +107,7 @@ public class DbTimestampType extends TimestampType {
|
|||
}
|
||||
finally {
|
||||
if ( ps != null ) {
|
||||
try {
|
||||
ps.close();
|
||||
}
|
||||
catch( SQLException sqle ) {
|
||||
LOG.unableToCleanUpPreparedStatement( sqle );
|
||||
}
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +120,7 @@ public class DbTimestampType extends TimestampType {
|
|||
.getStatementPreparer()
|
||||
.prepareStatement( callString, true );
|
||||
cs.registerOutParameter( 1, java.sql.Types.TIMESTAMP );
|
||||
cs.execute();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().execute( cs );
|
||||
Timestamp ts = cs.getTimestamp( 1 );
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev( "Current timestamp retreived from db : {0} (nanos={1}, time={2})", ts, ts.getNanos(), ts.getTime() );
|
||||
|
@ -142,12 +136,7 @@ public class DbTimestampType extends TimestampType {
|
|||
}
|
||||
finally {
|
||||
if ( cs != null ) {
|
||||
try {
|
||||
cs.close();
|
||||
}
|
||||
catch( SQLException sqle ) {
|
||||
LOG.unableToCleanUpCallableStatement( sqle );
|
||||
}
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( cs );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,16 +23,14 @@
|
|||
*/
|
||||
package org.hibernate.id;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.TestingDatabaseInfo;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
@ -50,8 +48,9 @@ import org.hibernate.service.ServiceRegistry;
|
|||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
|
||||
|
@ -127,7 +126,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
|
|||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// initially sequence should be uninitialized
|
||||
assertEquals( 0L, extractSequenceValue( ((Session)session) ) );
|
||||
assertEquals( 0L, extractSequenceValue( (session) ) );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// historically the hilo generators skipped the initial block of values;
|
||||
|
@ -135,44 +134,45 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase {
|
|||
Long generatedValue = (Long) generator.generate( session, null );
|
||||
assertEquals( 1L, generatedValue.longValue() );
|
||||
// which should also perform the first read on the sequence which should set it to its "start with" value (1)
|
||||
assertEquals( 1L, extractSequenceValue( ((Session)session) ) );
|
||||
assertEquals( 1L, extractSequenceValue( (session) ) );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
generatedValue = (Long) generator.generate( session, null );
|
||||
assertEquals( 2L, generatedValue.longValue() );
|
||||
assertEquals( 2L, extractSequenceValue( ((Session)session) ) );
|
||||
assertEquals( 2L, extractSequenceValue( (session) ) );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
generatedValue = (Long) generator.generate( session, null );
|
||||
assertEquals( 3L, generatedValue.longValue() );
|
||||
assertEquals( 3L, extractSequenceValue( ((Session)session) ) );
|
||||
assertEquals( 3L, extractSequenceValue( (session) ) );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
generatedValue = (Long) generator.generate( session, null );
|
||||
assertEquals( 4L, generatedValue.longValue() );
|
||||
assertEquals( 4L, extractSequenceValue( ((Session)session) ) );
|
||||
assertEquals( 4L, extractSequenceValue( (session) ) );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
generatedValue = (Long) generator.generate( session, null );
|
||||
assertEquals( 5L, generatedValue.longValue() );
|
||||
assertEquals( 5L, extractSequenceValue( ((Session)session) ) );
|
||||
assertEquals( 5L, extractSequenceValue( (session) ) );
|
||||
|
||||
((Session)session).getTransaction().commit();
|
||||
((Session)session).close();
|
||||
}
|
||||
|
||||
private long extractSequenceValue(Session session) {
|
||||
private long extractSequenceValue(final SessionImplementor session) {
|
||||
class WorkImpl implements Work {
|
||||
private long value;
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
PreparedStatement query = connection.prepareStatement( "select currval('" + TEST_SEQUENCE + "');" );
|
||||
ResultSet resultSet = query.executeQuery();
|
||||
|
||||
PreparedStatement query = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( "select currval('" + TEST_SEQUENCE + "');" );
|
||||
ResultSet resultSet = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( query );
|
||||
resultSet.next();
|
||||
value = resultSet.getLong( 1 );
|
||||
}
|
||||
}
|
||||
WorkImpl work = new WorkImpl();
|
||||
session.doWork( work );
|
||||
( (Session) session ).doWork( work );
|
||||
return work.value;
|
||||
}
|
||||
}
|
|
@ -23,16 +23,14 @@
|
|||
*/
|
||||
package org.hibernate.id;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.TestingDatabaseInfo;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
@ -42,6 +40,7 @@ import org.hibernate.cfg.ObjectNameNormalizer;
|
|||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.internal.SessionImpl;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.mapping.SimpleAuxiliaryDatabaseObject;
|
||||
|
@ -49,13 +48,14 @@ import org.hibernate.service.ServiceRegistry;
|
|||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
|
||||
* unit test so that we can make sure the value keep being generated in the expected manner
|
||||
*
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation" })
|
||||
|
@ -72,34 +72,26 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
|
|||
Properties properties = new Properties();
|
||||
properties.setProperty( SequenceGenerator.SEQUENCE, TEST_SEQUENCE );
|
||||
properties.setProperty( SequenceHiLoGenerator.MAX_LO, "3" );
|
||||
properties.put(
|
||||
PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
|
||||
new ObjectNameNormalizer() {
|
||||
@Override
|
||||
protected boolean isUseQuotedIdentifiersGlobally() {
|
||||
return false;
|
||||
}
|
||||
properties.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, new ObjectNameNormalizer() {
|
||||
@Override
|
||||
protected boolean isUseQuotedIdentifiersGlobally() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NamingStrategy getNamingStrategy() {
|
||||
return cfg.getNamingStrategy();
|
||||
}
|
||||
}
|
||||
);
|
||||
@Override
|
||||
protected NamingStrategy getNamingStrategy() {
|
||||
return cfg.getNamingStrategy();
|
||||
}
|
||||
} );
|
||||
|
||||
Dialect dialect = new H2Dialect();
|
||||
|
||||
generator = new SequenceHiLoGenerator();
|
||||
generator.configure( StandardBasicTypes.LONG, properties, dialect );
|
||||
|
||||
cfg = TestingDatabaseInfo.buildBaseConfiguration()
|
||||
.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
cfg.addAuxiliaryDatabaseObject(
|
||||
new SimpleAuxiliaryDatabaseObject(
|
||||
generator.sqlCreateStrings( dialect )[0],
|
||||
generator.sqlDropStrings( dialect )[0]
|
||||
)
|
||||
);
|
||||
cfg = TestingDatabaseInfo.buildBaseConfiguration().setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
cfg.addAuxiliaryDatabaseObject( new SimpleAuxiliaryDatabaseObject( generator.sqlCreateStrings( dialect )[0],
|
||||
generator.sqlDropStrings( dialect )[0] ) );
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
|
||||
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
||||
}
|
||||
|
@ -125,7 +117,7 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
|
|||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// historically the hilo generators skipped the initial block of values;
|
||||
// so the first generated id value is maxlo + 1, here be 4
|
||||
// so the first generated id value is maxlo + 1, here be 4
|
||||
Long generatedValue = (Long) generator.generate( session, null );
|
||||
assertEquals( 4L, generatedValue.longValue() );
|
||||
// which should also perform the first read on the sequence which should set it to its "start with" value (1)
|
||||
|
@ -144,8 +136,8 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
|
|||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
generatedValue = (Long) generator.generate( session, null );
|
||||
assertEquals( 7L, generatedValue.longValue() );
|
||||
// unlike the newer strategies, the db value will not get update here. It gets updated on the next invocation
|
||||
// after a clock over
|
||||
// unlike the newer strategies, the db value will not get update here. It gets updated on the next invocation
|
||||
// after a clock over
|
||||
assertEquals( 1L, extractSequenceValue( session ) );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -158,18 +150,19 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
|
|||
session.close();
|
||||
}
|
||||
|
||||
private long extractSequenceValue(Session session) {
|
||||
private long extractSequenceValue(final SessionImplementor session) {
|
||||
class WorkImpl implements Work {
|
||||
private long value;
|
||||
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
PreparedStatement query = connection.prepareStatement( "select currval('" + TEST_SEQUENCE + "');" );
|
||||
ResultSet resultSet = query.executeQuery();
|
||||
PreparedStatement query = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( "select currval('" + TEST_SEQUENCE + "');" );
|
||||
ResultSet resultSet = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( query );
|
||||
resultSet.next();
|
||||
value = resultSet.getLong( 1 );
|
||||
}
|
||||
}
|
||||
WorkImpl work = new WorkImpl();
|
||||
session.doWork( work );
|
||||
( (Session) session ).doWork( work );
|
||||
return work.value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,24 +23,28 @@
|
|||
*/
|
||||
package org.hibernate.sharedSession;
|
||||
|
||||
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
|
||||
import org.hibernate.engine.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.event.spi.*;
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.IrrelevantEntity;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.engine.transaction.spi.TransactionContext;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.hibernate.IrrelevantEntity;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
|
||||
import org.hibernate.engine.transaction.spi.TransactionContext;
|
||||
import org.hibernate.engine.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.event.spi.EventType;
|
||||
import org.hibernate.event.spi.PostInsertEvent;
|
||||
import org.hibernate.event.spi.PostInsertEventListener;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -61,8 +65,6 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
|||
assertFalse(
|
||||
((SessionImplementor) secondSession).getTransactionCoordinator()
|
||||
.getJdbcCoordinator()
|
||||
.getLogicalConnection()
|
||||
.getResourceRegistry()
|
||||
.hasRegisteredResources()
|
||||
);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.junit.Test;
|
|||
import org.hibernate.Session;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.testing.DialectCheck;
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
|
@ -71,9 +72,9 @@ public class BasicOperationsTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
Session s = openSession();
|
||||
|
||||
s.doWork( new ValidateSomeEntityColumns() );
|
||||
s.doWork( new ValidateRowCount( SOME_ENTITY_TABLE_NAME, 0 ) );
|
||||
s.doWork( new ValidateRowCount( SOME_OTHER_ENTITY_TABLE_NAME, 0 ) );
|
||||
s.doWork( new ValidateSomeEntityColumns( (SessionImplementor) s ) );
|
||||
s.doWork( new ValidateRowCount( (SessionImplementor) s, SOME_ENTITY_TABLE_NAME, 0 ) );
|
||||
s.doWork( new ValidateRowCount( (SessionImplementor) s, SOME_OTHER_ENTITY_TABLE_NAME, 0 ) );
|
||||
|
||||
s.beginTransaction();
|
||||
SomeEntity someEntity = new SomeEntity( now );
|
||||
|
@ -85,22 +86,28 @@ public class BasicOperationsTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
s = openSession();
|
||||
|
||||
s.doWork( new ValidateRowCount( SOME_ENTITY_TABLE_NAME, 1 ) );
|
||||
s.doWork( new ValidateRowCount( SOME_OTHER_ENTITY_TABLE_NAME, 1 ) );
|
||||
s.doWork( new ValidateRowCount( (SessionImplementor) s, SOME_ENTITY_TABLE_NAME, 1 ) );
|
||||
s.doWork( new ValidateRowCount( (SessionImplementor) s, SOME_OTHER_ENTITY_TABLE_NAME, 1 ) );
|
||||
|
||||
s.beginTransaction();
|
||||
s.delete( someEntity );
|
||||
s.delete( someOtherEntity );
|
||||
s.getTransaction().commit();
|
||||
|
||||
s.doWork( new ValidateRowCount( SOME_ENTITY_TABLE_NAME, 0 ) );
|
||||
s.doWork( new ValidateRowCount( SOME_OTHER_ENTITY_TABLE_NAME, 0 ) );
|
||||
s.doWork( new ValidateRowCount( (SessionImplementor) s, SOME_ENTITY_TABLE_NAME, 0 ) );
|
||||
s.doWork( new ValidateRowCount( (SessionImplementor) s, SOME_OTHER_ENTITY_TABLE_NAME, 0 ) );
|
||||
|
||||
s.close();
|
||||
}
|
||||
|
||||
// verify all the expected columns are created
|
||||
class ValidateSomeEntityColumns implements Work {
|
||||
private SessionImplementor s;
|
||||
|
||||
public ValidateSomeEntityColumns( SessionImplementor s ) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
// id -> java.util.Date (DATE - becase of explicit TemporalType)
|
||||
validateColumn( connection, "ID", java.sql.Types.DATE );
|
||||
|
@ -122,9 +129,10 @@ public class BasicOperationsTest extends BaseCoreFunctionalTestCase {
|
|||
String columnNamePattern = generateFinalNamePattern( meta, columnName );
|
||||
|
||||
ResultSet columnInfo = meta.getColumns( null, null, tableNamePattern, columnNamePattern );
|
||||
s.getTransactionCoordinator().getJdbcCoordinator().register(columnInfo);
|
||||
assertTrue( columnInfo.next() );
|
||||
int dataType = columnInfo.getInt( "DATA_TYPE" );
|
||||
columnInfo.close();
|
||||
s.getTransactionCoordinator().getJdbcCoordinator().release( columnInfo );
|
||||
assertEquals(
|
||||
columnName,
|
||||
JdbcTypeNameMapper.getTypeName( expectedJdbcTypeCode ),
|
||||
|
@ -147,14 +155,18 @@ public class BasicOperationsTest extends BaseCoreFunctionalTestCase {
|
|||
private final int expectedRowCount;
|
||||
private final String table;
|
||||
|
||||
public ValidateRowCount(String table, int count) {
|
||||
private SessionImplementor s;
|
||||
|
||||
public ValidateRowCount(SessionImplementor s, String table, int count) {
|
||||
this.s = s;
|
||||
this.expectedRowCount = count;
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
Statement st = connection.createStatement();
|
||||
ResultSet result = st.executeQuery( "SELECT COUNT(*) FROM " + table );
|
||||
Statement st = s.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().createStatement();
|
||||
s.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st, "SELECT COUNT(*) FROM " + table );
|
||||
ResultSet result = s.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st, "SELECT COUNT(*) FROM " + table );
|
||||
result.next();
|
||||
int rowCount = result.getInt( 1 );
|
||||
assertEquals( "Unexpected row count", expectedRowCount, rowCount );
|
||||
|
|
|
@ -22,20 +22,20 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.cascade;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Implementation of RefreshTest.
|
||||
|
@ -62,7 +62,7 @@ public class RefreshTest extends BaseCoreFunctionalTestCase {
|
|||
session.flush();
|
||||
|
||||
// behind the session's back, let's modify the statuses
|
||||
updateStatuses( session );
|
||||
updateStatuses( (SessionImplementor)session );
|
||||
|
||||
// Now lets refresh the persistent batch, and see if the refresh cascaded to the jobs collection elements
|
||||
session.refresh( batch );
|
||||
|
@ -77,20 +77,20 @@ public class RefreshTest extends BaseCoreFunctionalTestCase {
|
|||
session.close();
|
||||
}
|
||||
|
||||
private void updateStatuses(Session session) throws Throwable {
|
||||
session.doWork(
|
||||
private void updateStatuses(final SessionImplementor session) throws Throwable {
|
||||
((Session)session).doWork(
|
||||
new Work() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
PreparedStatement stmnt = null;
|
||||
try {
|
||||
stmnt = connection.prepareStatement( "UPDATE T_JOB SET JOB_STATUS = 1" );
|
||||
stmnt.executeUpdate();
|
||||
stmnt = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( "UPDATE T_JOB SET JOB_STATUS = 1" );
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( stmnt );
|
||||
}
|
||||
finally {
|
||||
if ( stmnt != null ) {
|
||||
try {
|
||||
stmnt.close();
|
||||
session.getTransactionCoordinator().getJdbcCoordinator().release( stmnt );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
}
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
*/
|
||||
package org.hibernate.test.collection.list;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
@ -31,10 +35,9 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.collection.internal.PersistentList;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.collection.QueryableCollection;
|
||||
|
@ -42,10 +45,7 @@ import org.hibernate.sql.SimpleSelect;
|
|||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests related to operations on a PersistentList
|
||||
|
@ -83,9 +83,9 @@ public class PersistentListTest extends BaseCoreFunctionalTestCase {
|
|||
session.close();
|
||||
|
||||
// now, make sure the list-index column gotten written...
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
session.doWork(
|
||||
final Session session2 = openSession();
|
||||
session2.beginTransaction();
|
||||
session2.doWork(
|
||||
new Work() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
|
@ -95,9 +95,9 @@ public class PersistentListTest extends BaseCoreFunctionalTestCase {
|
|||
.addColumn( "NAME" )
|
||||
.addColumn( "LIST_INDEX" )
|
||||
.addCondition( "NAME", "<>", "?" );
|
||||
PreparedStatement preparedStatement = connection.prepareStatement( select.toStatementString() );
|
||||
PreparedStatement preparedStatement = ((SessionImplementor)session2).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( select.toStatementString() );
|
||||
preparedStatement.setString( 1, "root" );
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
ResultSet resultSet = ((SessionImplementor)session2).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( preparedStatement );
|
||||
Map<String, Integer> valueMap = new HashMap<String, Integer>();
|
||||
while ( resultSet.next() ) {
|
||||
final String name = resultSet.getString( 1 );
|
||||
|
@ -115,9 +115,9 @@ public class PersistentListTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
}
|
||||
);
|
||||
session.delete( root );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
session2.delete( root );
|
||||
session2.getTransaction().commit();
|
||||
session2.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -26,13 +26,14 @@
|
|||
*/
|
||||
package org.hibernate.test.dialect.functional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -41,13 +42,12 @@ import org.hibernate.LockOptions;
|
|||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.SQLServer2005Dialect;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.exception.LockTimeoutException;
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.hibernate.jdbc.ReturningWork;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -61,13 +61,14 @@ public class SQLServerDialectTest extends BaseCoreFunctionalTestCase {
|
|||
@TestForIssue(jiraKey = "HHH-7198")
|
||||
public void testMaxResultsSqlServerWithCaseSensitiveCollation() throws Exception {
|
||||
|
||||
Session s = openSession();
|
||||
final Session s = openSession();
|
||||
s.beginTransaction();
|
||||
String defaultCollationName = s.doReturningWork( new ReturningWork<String>() {
|
||||
@Override
|
||||
public String execute(Connection connection) throws SQLException {
|
||||
String databaseName = connection.getCatalog();
|
||||
ResultSet rs = connection.createStatement().executeQuery( "SELECT collation_name FROM sys.databases WHERE name = '"+databaseName+ "';" );
|
||||
Statement st = ((SessionImplementor)s).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().createStatement();
|
||||
ResultSet rs = ((SessionImplementor)s).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st, "SELECT collation_name FROM sys.databases WHERE name = '"+databaseName+ "';" );
|
||||
while(rs.next()){
|
||||
return rs.getString( "collation_name" );
|
||||
}
|
||||
|
@ -78,40 +79,44 @@ public class SQLServerDialectTest extends BaseCoreFunctionalTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
String databaseName = s.doReturningWork( new ReturningWork<String>() {
|
||||
Session s2 = openSession();
|
||||
String databaseName = s2.doReturningWork( new ReturningWork<String>() {
|
||||
@Override
|
||||
public String execute(Connection connection) throws SQLException {
|
||||
return connection.getCatalog();
|
||||
}
|
||||
} );
|
||||
s.createSQLQuery( "ALTER DATABASE " + databaseName + " set single_user with rollback immediate" )
|
||||
s2.createSQLQuery( "ALTER DATABASE " + databaseName + " set single_user with rollback immediate" )
|
||||
.executeUpdate();
|
||||
s.createSQLQuery( "ALTER DATABASE " + databaseName + " COLLATE Latin1_General_CS_AS" ).executeUpdate();
|
||||
s.createSQLQuery( "ALTER DATABASE " + databaseName + " set multi_user" ).executeUpdate();
|
||||
s2.createSQLQuery( "ALTER DATABASE " + databaseName + " COLLATE Latin1_General_CS_AS" ).executeUpdate();
|
||||
s2.createSQLQuery( "ALTER DATABASE " + databaseName + " set multi_user" ).executeUpdate();
|
||||
|
||||
Transaction tx = s.beginTransaction();
|
||||
Transaction tx = s2.beginTransaction();
|
||||
|
||||
for ( int i = 1; i <= 20; i++ ) {
|
||||
s.persist( new Product2( i, "Kit" + i ) );
|
||||
s2.persist( new Product2( i, "Kit" + i ) );
|
||||
}
|
||||
s.flush();
|
||||
s.clear();
|
||||
s2.flush();
|
||||
s2.clear();
|
||||
|
||||
List list = s.createQuery( "from Product2 where description like 'Kit%'" )
|
||||
List list = s2.createQuery( "from Product2 where description like 'Kit%'" )
|
||||
.setFirstResult( 2 )
|
||||
.setMaxResults( 2 )
|
||||
.list();
|
||||
assertEquals( 2, list.size() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
s2.close();
|
||||
|
||||
s = openSession();
|
||||
s.createSQLQuery( "ALTER DATABASE " + databaseName + " set single_user with rollback immediate" )
|
||||
s2 = openSession();
|
||||
s2.createSQLQuery( "ALTER DATABASE " + databaseName + " set single_user with rollback immediate" )
|
||||
.executeUpdate();
|
||||
s.createSQLQuery( "ALTER DATABASE " + databaseName + " COLLATE " + defaultCollationName ).executeUpdate();
|
||||
s.createSQLQuery( "ALTER DATABASE " + databaseName + " set multi_user" ).executeUpdate();
|
||||
s.close();
|
||||
s2.createSQLQuery( "ALTER DATABASE " + databaseName + " COLLATE " + defaultCollationName ).executeUpdate();
|
||||
s2.createSQLQuery( "ALTER DATABASE " + databaseName + " set multi_user" ).executeUpdate();
|
||||
s2.close();
|
||||
}
|
||||
|
||||
private void doWork(Session s) {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.Cache71Dialect;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.test.legacy.Blobber;
|
||||
import org.hibernate.test.legacy.Broken;
|
||||
|
@ -648,15 +649,15 @@ public class SQLFunctionsInterSystemsTest extends BaseCoreFunctionalTestCase {
|
|||
java.sql.Timestamp testvalue3 = new java.sql.Timestamp(cal3.getTimeInMillis());
|
||||
testvalue3.setNanos(0);
|
||||
|
||||
Session s = openSession();
|
||||
final Session s = openSession();
|
||||
s.beginTransaction();
|
||||
try {
|
||||
s.doWork(
|
||||
new Work() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
Statement stmt = connection.createStatement();
|
||||
stmt.executeUpdate( "DROP FUNCTION spLock FROM TestInterSystemsFunctionsClass" );
|
||||
Statement stmt = ((SessionImplementor)s).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().createStatement();
|
||||
((SessionImplementor)s).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( stmt, "DROP FUNCTION spLock FROM TestInterSystemsFunctionsClass" );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -672,7 +673,7 @@ public class SQLFunctionsInterSystemsTest extends BaseCoreFunctionalTestCase {
|
|||
new Work() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
Statement stmt = connection.createStatement();
|
||||
Statement stmt = ((SessionImplementor)s).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().createStatement();
|
||||
String create_function = "CREATE FUNCTION SQLUser.TestInterSystemsFunctionsClass_spLock\n" +
|
||||
" ( INOUT pHandle %SQLProcContext, \n" +
|
||||
" ROWID INTEGER \n" +
|
||||
|
@ -684,7 +685,7 @@ public class SQLFunctionsInterSystemsTest extends BaseCoreFunctionalTestCase {
|
|||
" {\n" +
|
||||
" q 0\n" +
|
||||
" }";
|
||||
stmt.executeUpdate(create_function);
|
||||
((SessionImplementor)s).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( stmt, create_function );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -700,70 +701,70 @@ public class SQLFunctionsInterSystemsTest extends BaseCoreFunctionalTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
TestInterSystemsFunctionsClass test = (TestInterSystemsFunctionsClass) s.get(TestInterSystemsFunctionsClass.class, Long.valueOf(10));
|
||||
Session s2 = openSession();
|
||||
s2.beginTransaction();
|
||||
TestInterSystemsFunctionsClass test = (TestInterSystemsFunctionsClass) s2.get(TestInterSystemsFunctionsClass.class, Long.valueOf(10));
|
||||
assertTrue( test.getDate1().equals(testvalue));
|
||||
test = (TestInterSystemsFunctionsClass) s.get(TestInterSystemsFunctionsClass.class, Long.valueOf(10), LockMode.UPGRADE);
|
||||
test = (TestInterSystemsFunctionsClass) s2.get(TestInterSystemsFunctionsClass.class, Long.valueOf(10), LockMode.UPGRADE);
|
||||
assertTrue( test.getDate1().equals(testvalue));
|
||||
Date value = (Date) s.createQuery( "select nvl(o.date,o.dateText) from TestInterSystemsFunctionsClass as o" )
|
||||
Date value = (Date) s2.createQuery( "select nvl(o.date,o.dateText) from TestInterSystemsFunctionsClass as o" )
|
||||
.list()
|
||||
.get(0);
|
||||
assertTrue( value.equals(testvalue));
|
||||
Object nv = s.createQuery( "select nullif(o.dateText,o.dateText) from TestInterSystemsFunctionsClass as o" )
|
||||
Object nv = s2.createQuery( "select nullif(o.dateText,o.dateText) from TestInterSystemsFunctionsClass as o" )
|
||||
.list()
|
||||
.get(0);
|
||||
assertTrue( nv == null);
|
||||
String dateText = (String) s.createQuery(
|
||||
String dateText = (String) s2.createQuery(
|
||||
"select nvl(o.dateText,o.date) from TestInterSystemsFunctionsClass as o"
|
||||
).list()
|
||||
.get(0);
|
||||
assertTrue( dateText.equals("1977-07-03"));
|
||||
value = (Date) s.createQuery( "select ifnull(o.date,o.date1) from TestInterSystemsFunctionsClass as o" )
|
||||
value = (Date) s2.createQuery( "select ifnull(o.date,o.date1) from TestInterSystemsFunctionsClass as o" )
|
||||
.list()
|
||||
.get(0);
|
||||
assertTrue( value.equals(testvalue));
|
||||
value = (Date) s.createQuery( "select ifnull(o.date3,o.date,o.date1) from TestInterSystemsFunctionsClass as o" )
|
||||
value = (Date) s2.createQuery( "select ifnull(o.date3,o.date,o.date1) from TestInterSystemsFunctionsClass as o" )
|
||||
.list()
|
||||
.get(0);
|
||||
assertTrue( value.equals(testvalue));
|
||||
Integer pos = (Integer) s.createQuery(
|
||||
Integer pos = (Integer) s2.createQuery(
|
||||
"select position('07', o.dateText) from TestInterSystemsFunctionsClass as o"
|
||||
).list()
|
||||
.get(0);
|
||||
assertTrue(pos.intValue() == 6);
|
||||
String st = (String) s.createQuery( "select convert(o.date1, SQL_TIME) from TestInterSystemsFunctionsClass as o" )
|
||||
String st = (String) s2.createQuery( "select convert(o.date1, SQL_TIME) from TestInterSystemsFunctionsClass as o" )
|
||||
.list()
|
||||
.get(0);
|
||||
assertTrue( st.equals("00:00:00"));
|
||||
java.sql.Time tm = (java.sql.Time) s.createQuery(
|
||||
java.sql.Time tm = (java.sql.Time) s2.createQuery(
|
||||
"select cast(o.date1, time) from TestInterSystemsFunctionsClass as o"
|
||||
).list()
|
||||
.get(0);
|
||||
assertTrue( tm.toString().equals("00:00:00"));
|
||||
Double diff = (Double) s.createQuery(
|
||||
Double diff = (Double) s2.createQuery(
|
||||
"select timestampdiff(SQL_TSI_FRAC_SECOND, o.date3, o.date1) from TestInterSystemsFunctionsClass as o"
|
||||
).list()
|
||||
.get(0);
|
||||
assertTrue(diff.doubleValue() != 0.0);
|
||||
diff = (Double) s.createQuery(
|
||||
diff = (Double) s2.createQuery(
|
||||
"select timestampdiff(SQL_TSI_MONTH, o.date3, o.date1) from TestInterSystemsFunctionsClass as o"
|
||||
).list()
|
||||
.get(0);
|
||||
assertTrue(diff.doubleValue() == 16.0);
|
||||
diff = (Double) s.createQuery(
|
||||
diff = (Double) s2.createQuery(
|
||||
"select timestampdiff(SQL_TSI_WEEK, o.date3, o.date1) from TestInterSystemsFunctionsClass as o"
|
||||
).list()
|
||||
.get(0);
|
||||
assertTrue(diff.doubleValue() >= 16*4);
|
||||
diff = (Double) s.createQuery(
|
||||
diff = (Double) s2.createQuery(
|
||||
"select timestampdiff(SQL_TSI_YEAR, o.date3, o.date1) from TestInterSystemsFunctionsClass as o"
|
||||
).list()
|
||||
.get(0);
|
||||
assertTrue(diff.doubleValue() == 1.0);
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
s2.getTransaction().commit();
|
||||
s2.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.junit.Test;
|
|||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.dialect.MySQLMyISAMDialect;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.hibernate.jdbc.Work;
|
||||
|
@ -55,7 +56,7 @@ public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
|
|||
comment = "MySQL (MyISAM) does not support FK violation checking"
|
||||
)
|
||||
public void testIntegrityViolation() throws Exception {
|
||||
Session session = openSession();
|
||||
final Session session = openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
session.doWork(
|
||||
|
@ -66,10 +67,10 @@ public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
|
|||
// result in a constraint violation
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
ps = connection.prepareStatement("INSERT INTO T_MEMBERSHIP (user_id, group_id) VALUES (?, ?)");
|
||||
ps = ((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( "INSERT INTO T_MEMBERSHIP (user_id, group_id) VALUES (?, ?)" );
|
||||
ps.setLong(1, 52134241); // Non-existent user_id
|
||||
ps.setLong(2, 5342); // Non-existent group_id
|
||||
ps.executeUpdate();
|
||||
((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
|
||||
|
||||
fail("INSERT should have failed");
|
||||
}
|
||||
|
@ -79,7 +80,7 @@ public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
|
|||
finally {
|
||||
if ( ps != null ) {
|
||||
try {
|
||||
ps.close();
|
||||
((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
// ignore...
|
||||
|
@ -96,7 +97,7 @@ public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testBadGrammar() throws Exception {
|
||||
Session session = openSession();
|
||||
final Session session = openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
session.doWork(
|
||||
|
@ -106,8 +107,8 @@ public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
|
|||
// prepare/execute a query against a non-existent table
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
ps = connection.prepareStatement("SELECT user_id, user_name FROM tbl_no_there");
|
||||
ps.executeQuery();
|
||||
ps = ((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( "SELECT user_id, user_name FROM tbl_no_there" );
|
||||
((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( ps );
|
||||
|
||||
fail("SQL compilation should have failed");
|
||||
}
|
||||
|
@ -117,7 +118,7 @@ public class SQLExceptionConversionTest extends BaseCoreFunctionalTestCase {
|
|||
finally {
|
||||
if ( ps != null ) {
|
||||
try {
|
||||
ps.close();
|
||||
((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
// ignore...
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.junit.Test;
|
|||
|
||||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.jdbc.ReturningWork;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
@ -56,7 +57,7 @@ public class GeneralWorkTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testGeneralUsage() throws Throwable {
|
||||
Session session = openSession();
|
||||
final Session session = openSession();
|
||||
session.beginTransaction();
|
||||
session.doWork(
|
||||
new Work() {
|
||||
|
@ -64,23 +65,24 @@ public class GeneralWorkTest extends BaseCoreFunctionalTestCase {
|
|||
// in this current form, users must handle try/catches themselves for proper resource release
|
||||
Statement statement = null;
|
||||
try {
|
||||
statement = connection.createStatement();
|
||||
statement = ((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().createStatement();
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
resultSet = statement.executeQuery( "select * from T_JDBC_PERSON" );
|
||||
|
||||
resultSet = ((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( statement, "select * from T_JDBC_PERSON" );
|
||||
}
|
||||
finally {
|
||||
releaseQuietly( resultSet );
|
||||
releaseQuietly( ((SessionImplementor)session), resultSet );
|
||||
}
|
||||
try {
|
||||
resultSet = statement.executeQuery( "select * from T_JDBC_BOAT" );
|
||||
((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( statement, "select * from T_JDBC_BOAT" );
|
||||
}
|
||||
finally {
|
||||
releaseQuietly( resultSet );
|
||||
releaseQuietly( ((SessionImplementor)session), resultSet );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
releaseQuietly( statement );
|
||||
releaseQuietly( ((SessionImplementor)session), statement );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +93,7 @@ public class GeneralWorkTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testSQLExceptionThrowing() {
|
||||
Session session = openSession();
|
||||
final Session session = openSession();
|
||||
session.beginTransaction();
|
||||
try {
|
||||
session.doWork(
|
||||
|
@ -99,11 +101,11 @@ public class GeneralWorkTest extends BaseCoreFunctionalTestCase {
|
|||
public void execute(Connection connection) throws SQLException {
|
||||
Statement statement = null;
|
||||
try {
|
||||
statement = connection.createStatement();
|
||||
statement.executeQuery( "select * from non_existent" );
|
||||
statement = ((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().createStatement();
|
||||
((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( statement, "select * from non_existent" );
|
||||
}
|
||||
finally {
|
||||
releaseQuietly( statement );
|
||||
releaseQuietly( ((SessionImplementor)session), statement );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,36 +127,36 @@ public class GeneralWorkTest extends BaseCoreFunctionalTestCase {
|
|||
session.save( p );
|
||||
session.getTransaction().commit();
|
||||
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
long count = session.doReturningWork(
|
||||
final Session session2 = openSession();
|
||||
session2.beginTransaction();
|
||||
long count = session2.doReturningWork(
|
||||
new ReturningWork<Long>() {
|
||||
public Long execute(Connection connection) throws SQLException {
|
||||
// in this current form, users must handle try/catches themselves for proper resource release
|
||||
Statement statement = null;
|
||||
long personCount = 0;
|
||||
try {
|
||||
statement = connection.createStatement();
|
||||
statement = ((SessionImplementor)session2).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().createStatement();
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
resultSet = statement.executeQuery( "select count(*) from T_JDBC_PERSON" );
|
||||
resultSet = ((SessionImplementor)session2).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( statement, "select count(*) from T_JDBC_PERSON" );
|
||||
resultSet.next();
|
||||
personCount = resultSet.getLong( 1 );
|
||||
assertEquals( 1L, personCount );
|
||||
}
|
||||
finally {
|
||||
releaseQuietly( resultSet );
|
||||
releaseQuietly( ((SessionImplementor)session2), resultSet );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
releaseQuietly( statement );
|
||||
releaseQuietly( ((SessionImplementor)session2), statement );
|
||||
}
|
||||
return personCount;
|
||||
}
|
||||
}
|
||||
);
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
session2.getTransaction().commit();
|
||||
session2.close();
|
||||
assertEquals( 1L, count );
|
||||
|
||||
session = openSession();
|
||||
|
@ -164,26 +166,26 @@ public class GeneralWorkTest extends BaseCoreFunctionalTestCase {
|
|||
session.close();
|
||||
}
|
||||
|
||||
private void releaseQuietly(Statement statement) {
|
||||
private void releaseQuietly(SessionImplementor s, Statement statement) {
|
||||
if ( statement == null ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
statement.close();
|
||||
s.getTransactionCoordinator().getJdbcCoordinator().release( statement );
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
private void releaseQuietly(ResultSet resultSet) {
|
||||
private void releaseQuietly(SessionImplementor s, ResultSet resultSet) {
|
||||
if ( resultSet == null ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
resultSet.close();
|
||||
s.getTransactionCoordinator().getJdbcCoordinator().release( resultSet );
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,38 +21,40 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.jdbc.proxies;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.engine.jdbc.internal.LogicalConnectionImpl;
|
||||
import org.hibernate.engine.jdbc.internal.proxy.ProxyBuilder;
|
||||
import org.hibernate.test.common.BasicTestingJdbcServiceImpl;
|
||||
import org.hibernate.test.common.JdbcConnectionAccessImpl;
|
||||
import org.hibernate.test.common.JournalingConnectionObserver;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
package org.hibernate.test.jdbc.internal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl;
|
||||
import org.hibernate.engine.jdbc.internal.LogicalConnectionImpl;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.test.common.BasicTestingJdbcServiceImpl;
|
||||
import org.hibernate.test.common.JdbcConnectionAccessImpl;
|
||||
import org.hibernate.test.common.JournalingConnectionObserver;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class AggressiveReleaseTest extends BaseUnitTestCase {
|
||||
public class AggressiveReleaseTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
private BasicTestingJdbcServiceImpl services = new BasicTestingJdbcServiceImpl();
|
||||
|
||||
@Before
|
||||
public void setUp() throws SQLException {
|
||||
|
||||
@Override
|
||||
protected void prepareTest() throws Exception {
|
||||
services.prepare( true );
|
||||
|
||||
Connection connection = null;
|
||||
|
@ -80,9 +82,9 @@ public class AggressiveReleaseTest extends BaseUnitTestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws SQLException {
|
||||
|
||||
@Override
|
||||
protected void cleanupTest() throws Exception {
|
||||
Connection connection = null;
|
||||
Statement stmnt = null;
|
||||
try {
|
||||
|
@ -109,29 +111,30 @@ public class AggressiveReleaseTest extends BaseUnitTestCase {
|
|||
|
||||
services.release();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBasicRelease() {
|
||||
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl(
|
||||
null,
|
||||
ConnectionReleaseMode.AFTER_STATEMENT,
|
||||
services ,
|
||||
new JdbcConnectionAccessImpl( services.getConnectionProvider() )
|
||||
);
|
||||
Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
|
||||
Session session = openSession();
|
||||
SessionImplementor sessionImpl = (SessionImplementor) session;
|
||||
|
||||
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null,
|
||||
ConnectionReleaseMode.AFTER_STATEMENT, services, new JdbcConnectionAccessImpl(
|
||||
services.getConnectionProvider() ) );
|
||||
JdbcCoordinatorImpl jdbcCoord = new JdbcCoordinatorImpl( logicalConnection,
|
||||
sessionImpl.getTransactionCoordinator() );
|
||||
JournalingConnectionObserver observer = new JournalingConnectionObserver();
|
||||
logicalConnection.addObserver( observer );
|
||||
|
||||
try {
|
||||
PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
PreparedStatement ps = jdbcCoord.getStatementPreparer().prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
ps.setLong( 1, 1 );
|
||||
ps.setString( 2, "name" );
|
||||
ps.execute();
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
jdbcCoord.getResultSetReturn().execute( ps );
|
||||
assertTrue( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 0, observer.getPhysicalConnectionReleasedCount() );
|
||||
ps.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
jdbcCoord.release( ps );
|
||||
assertFalse( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionReleasedCount() );
|
||||
}
|
||||
|
@ -139,122 +142,126 @@ public class AggressiveReleaseTest extends BaseUnitTestCase {
|
|||
fail( "incorrect exception type : sqlexception" );
|
||||
}
|
||||
finally {
|
||||
logicalConnection.close();
|
||||
session.close();
|
||||
}
|
||||
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertFalse( jdbcCoord.hasRegisteredResources() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReleaseCircumventedByHeldResources() {
|
||||
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl(
|
||||
null,
|
||||
ConnectionReleaseMode.AFTER_STATEMENT,
|
||||
services,
|
||||
new JdbcConnectionAccessImpl( services.getConnectionProvider() )
|
||||
);
|
||||
Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
|
||||
Session session = openSession();
|
||||
SessionImplementor sessionImpl = (SessionImplementor) session;
|
||||
|
||||
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null,
|
||||
ConnectionReleaseMode.AFTER_STATEMENT, services, new JdbcConnectionAccessImpl(
|
||||
services.getConnectionProvider() ) );
|
||||
JdbcCoordinatorImpl jdbcCoord = new JdbcCoordinatorImpl( logicalConnection,
|
||||
sessionImpl.getTransactionCoordinator() );
|
||||
JournalingConnectionObserver observer = new JournalingConnectionObserver();
|
||||
logicalConnection.addObserver( observer );
|
||||
|
||||
try {
|
||||
PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
PreparedStatement ps = jdbcCoord.getStatementPreparer().prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
ps.setLong( 1, 1 );
|
||||
ps.setString( 2, "name" );
|
||||
ps.execute();
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
jdbcCoord.getResultSetReturn().execute( ps );
|
||||
assertTrue( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 0, observer.getPhysicalConnectionReleasedCount() );
|
||||
ps.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
jdbcCoord.release( ps );
|
||||
assertFalse( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionReleasedCount() );
|
||||
|
||||
|
||||
// open a result set and hold it open...
|
||||
ps = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
ps.executeQuery();
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
ps = jdbcCoord.getStatementPreparer().prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
jdbcCoord.getResultSetReturn().extract( ps );
|
||||
assertTrue( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 2, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionReleasedCount() );
|
||||
|
||||
|
||||
// open a second result set
|
||||
PreparedStatement ps2 = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
ps2.execute();
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
PreparedStatement ps2 = jdbcCoord.getStatementPreparer().prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
jdbcCoord.getResultSetReturn().execute( ps );
|
||||
assertTrue( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 2, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionReleasedCount() );
|
||||
// and close it...
|
||||
ps2.close();
|
||||
jdbcCoord.release( ps2 );
|
||||
// the release should be circumvented...
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 2, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionReleasedCount() );
|
||||
|
||||
|
||||
// let the close of the logical connection below release all resources (hopefully)...
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
fail( "incorrect exception type : sqlexception" );
|
||||
}
|
||||
finally {
|
||||
logicalConnection.close();
|
||||
jdbcCoord.close();
|
||||
session.close();
|
||||
}
|
||||
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertFalse( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 2, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 2, observer.getPhysicalConnectionReleasedCount() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReleaseCircumventedManually() {
|
||||
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl(
|
||||
null,
|
||||
ConnectionReleaseMode.AFTER_STATEMENT,
|
||||
services,
|
||||
new JdbcConnectionAccessImpl( services.getConnectionProvider() )
|
||||
);
|
||||
Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
|
||||
Session session = openSession();
|
||||
SessionImplementor sessionImpl = (SessionImplementor) session;
|
||||
|
||||
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null,
|
||||
ConnectionReleaseMode.AFTER_STATEMENT, services, new JdbcConnectionAccessImpl(
|
||||
services.getConnectionProvider() ) );
|
||||
JdbcCoordinatorImpl jdbcCoord = new JdbcCoordinatorImpl( logicalConnection,
|
||||
sessionImpl.getTransactionCoordinator() );
|
||||
JournalingConnectionObserver observer = new JournalingConnectionObserver();
|
||||
logicalConnection.addObserver( observer );
|
||||
|
||||
try {
|
||||
PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
PreparedStatement ps = jdbcCoord.getStatementPreparer().prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
ps.setLong( 1, 1 );
|
||||
ps.setString( 2, "name" );
|
||||
ps.execute();
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
jdbcCoord.getResultSetReturn().execute( ps );
|
||||
assertTrue( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 0, observer.getPhysicalConnectionReleasedCount() );
|
||||
ps.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
jdbcCoord.release( ps );
|
||||
assertFalse( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionReleasedCount() );
|
||||
|
||||
|
||||
// disable releases...
|
||||
logicalConnection.disableReleases();
|
||||
|
||||
jdbcCoord.disableReleases();
|
||||
|
||||
// open a result set...
|
||||
ps = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
ps.executeQuery();
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
ps = jdbcCoord.getStatementPreparer().prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
jdbcCoord.getResultSetReturn().extract( ps );
|
||||
assertTrue( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 2, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionReleasedCount() );
|
||||
// and close it...
|
||||
ps.close();
|
||||
jdbcCoord.release( ps );
|
||||
// the release should be circumvented...
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertFalse( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 2, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 1, observer.getPhysicalConnectionReleasedCount() );
|
||||
|
||||
|
||||
// let the close of the logical connection below release all resources (hopefully)...
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
fail( "incorrect exception type : sqlexception" );
|
||||
}
|
||||
finally {
|
||||
logicalConnection.close();
|
||||
jdbcCoord.close();
|
||||
session.close();
|
||||
}
|
||||
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertFalse( jdbcCoord.hasRegisteredResources() );
|
||||
assertEquals( 2, observer.getPhysicalConnectionObtainedCount() );
|
||||
assertEquals( 2, observer.getPhysicalConnectionReleasedCount() );
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.jdbc.internal;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public class BasicConnectionTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Test
|
||||
public void testExceptionHandling() {
|
||||
Session session = openSession();
|
||||
SessionImplementor sessionImpl = (SessionImplementor) session;
|
||||
boolean caught = false;
|
||||
try {
|
||||
PreparedStatement ps = sessionImpl.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer()
|
||||
.prepareStatement( "select count(*) from NON_EXISTENT" );
|
||||
sessionImpl.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().execute( ps );
|
||||
}
|
||||
catch ( JDBCException ok ) {
|
||||
caught = true;
|
||||
}
|
||||
finally {
|
||||
session.close();
|
||||
}
|
||||
|
||||
assertTrue( "The connection did not throw a JDBCException as expected", caught );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicJdbcUsage() throws JDBCException {
|
||||
Session session = openSession();
|
||||
SessionImplementor sessionImpl = (SessionImplementor) session;
|
||||
JdbcCoordinator jdbcCoord = sessionImpl.getTransactionCoordinator().getJdbcCoordinator();
|
||||
|
||||
try {
|
||||
Statement statement = jdbcCoord.getStatementPreparer().createStatement();
|
||||
jdbcCoord.getResultSetReturn().execute( statement, "drop table SANDBOX_JDBC_TST if exists" );
|
||||
jdbcCoord.getResultSetReturn().execute( statement,
|
||||
"create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( jdbcCoord.hasRegisteredResources() );
|
||||
assertTrue( jdbcCoord.getLogicalConnection().isPhysicallyConnected() );
|
||||
jdbcCoord.release( statement );
|
||||
assertFalse( jdbcCoord.hasRegisteredResources() );
|
||||
assertTrue( jdbcCoord.getLogicalConnection().isPhysicallyConnected() ); // after_transaction specified
|
||||
|
||||
PreparedStatement ps = jdbcCoord.getStatementPreparer().prepareStatement(
|
||||
"insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
ps.setLong( 1, 1 );
|
||||
ps.setString( 2, "name" );
|
||||
jdbcCoord.getResultSetReturn().execute( ps );
|
||||
|
||||
ps = jdbcCoord.getStatementPreparer().prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
jdbcCoord.getResultSetReturn().extract( ps );
|
||||
|
||||
assertTrue( jdbcCoord.hasRegisteredResources() );
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
fail( "incorrect exception type : sqlexception" );
|
||||
}
|
||||
finally {
|
||||
session.close();
|
||||
}
|
||||
|
||||
assertFalse( jdbcCoord.hasRegisteredResources() );
|
||||
}
|
||||
}
|
|
@ -21,16 +21,17 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.jdbc.proxies;
|
||||
package org.hibernate.test.jdbc.internal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey;
|
||||
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderImpl;
|
||||
import org.hibernate.engine.jdbc.batch.internal.BatchingBatch;
|
||||
|
@ -40,43 +41,24 @@ import org.hibernate.engine.jdbc.batch.spi.BatchBuilder;
|
|||
import org.hibernate.engine.jdbc.batch.spi.BatchKey;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
||||
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
|
||||
import org.hibernate.engine.transaction.spi.TransactionContext;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.engine.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.engine.transaction.spi.TransactionImplementor;
|
||||
import org.hibernate.jdbc.Expectation;
|
||||
import org.hibernate.jdbc.Expectations;
|
||||
import org.hibernate.service.ServiceRegistryBuilder;
|
||||
import org.hibernate.service.internal.StandardServiceRegistryImpl;
|
||||
import org.hibernate.test.common.JournalingBatchObserver;
|
||||
import org.hibernate.test.common.JournalingTransactionObserver;
|
||||
import org.hibernate.test.common.TransactionContextImpl;
|
||||
import org.hibernate.test.common.TransactionEnvironmentImpl;
|
||||
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public class BatchingTest extends BaseUnitTestCase implements BatchKey {
|
||||
public class BatchingTest extends BaseCoreFunctionalTestCase implements BatchKey {
|
||||
private StandardServiceRegistryImpl serviceRegistry;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
serviceRegistry = (StandardServiceRegistryImpl) new ServiceRegistryBuilder()
|
||||
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
|
||||
.buildServiceRegistry();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
serviceRegistry.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatchedStatementCount() {
|
||||
return 1;
|
||||
|
@ -89,26 +71,24 @@ public class BatchingTest extends BaseUnitTestCase implements BatchKey {
|
|||
|
||||
@Test
|
||||
public void testNonBatchingUsage() throws Exception {
|
||||
final TransactionContext transactionContext = new TransactionContextImpl(
|
||||
new TransactionEnvironmentImpl( serviceRegistry )
|
||||
);
|
||||
|
||||
TransactionCoordinatorImpl transactionCoordinator = new TransactionCoordinatorImpl( null, transactionContext );
|
||||
Session session = openSession();
|
||||
SessionImplementor sessionImpl = (SessionImplementor) session;
|
||||
|
||||
TransactionCoordinator transactionCoordinator = sessionImpl.getTransactionCoordinator();
|
||||
JournalingTransactionObserver observer = new JournalingTransactionObserver();
|
||||
transactionCoordinator.addObserver( observer );
|
||||
|
||||
final JdbcCoordinator jdbcCoordinator = transactionCoordinator.getJdbcCoordinator();
|
||||
LogicalConnectionImplementor logicalConnection = jdbcCoordinator.getLogicalConnection();
|
||||
Connection connection = logicalConnection.getShareableConnectionProxy();
|
||||
|
||||
// set up some tables to use
|
||||
Statement statement = connection.createStatement();
|
||||
statement.execute( "drop table SANDBOX_JDBC_TST if exists" );
|
||||
statement.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
Statement statement = jdbcCoordinator.getStatementPreparer().createStatement();
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "drop table SANDBOX_JDBC_TST if exists" );
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
statement.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
jdbcCoordinator.release( statement );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() ); // after_transaction specified
|
||||
|
||||
// ok, now we can get down to it...
|
||||
|
@ -134,45 +114,45 @@ public class BatchingTest extends BaseUnitTestCase implements BatchKey {
|
|||
insertBatch.addToBatch();
|
||||
assertEquals( 0, batchObserver.getExplicitExecutionCount() );
|
||||
assertEquals( 1, batchObserver.getImplicitExecutionCount() );
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
|
||||
insertBatch.execute();
|
||||
assertEquals( 1, batchObserver.getExplicitExecutionCount() );
|
||||
assertEquals( 1, batchObserver.getImplicitExecutionCount() );
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
|
||||
insertBatch.release();
|
||||
|
||||
txn.commit();
|
||||
logicalConnection.close();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchingUsage() throws Exception {
|
||||
final TransactionContext transactionContext = new TransactionContextImpl( new TransactionEnvironmentImpl( serviceRegistry ) );
|
||||
|
||||
TransactionCoordinatorImpl transactionCoordinator = new TransactionCoordinatorImpl( null, transactionContext );
|
||||
JournalingTransactionObserver transactionObserver = new JournalingTransactionObserver();
|
||||
transactionCoordinator.addObserver( transactionObserver );
|
||||
Session session = openSession();
|
||||
SessionImplementor sessionImpl = (SessionImplementor) session;
|
||||
|
||||
TransactionCoordinator transactionCoordinator = sessionImpl.getTransactionCoordinator();
|
||||
JournalingTransactionObserver observer = new JournalingTransactionObserver();
|
||||
transactionCoordinator.addObserver( observer );
|
||||
|
||||
final JdbcCoordinator jdbcCoordinator = transactionCoordinator.getJdbcCoordinator();
|
||||
LogicalConnectionImplementor logicalConnection = jdbcCoordinator.getLogicalConnection();
|
||||
Connection connection = logicalConnection.getShareableConnectionProxy();
|
||||
|
||||
// set up some tables to use
|
||||
Statement statement = connection.createStatement();
|
||||
statement.execute( "drop table SANDBOX_JDBC_TST if exists" );
|
||||
statement.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
Statement statement = jdbcCoordinator.getStatementPreparer().createStatement();
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "drop table SANDBOX_JDBC_TST if exists" );
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
statement.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
jdbcCoordinator.release( statement );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() ); // after_transaction specified
|
||||
|
||||
// ok, now we can get down to it...
|
||||
TransactionImplementor txn = transactionCoordinator.getTransaction(); // same as Session#getTransaction
|
||||
txn.begin();
|
||||
assertEquals( 1, transactionObserver.getBegins() );
|
||||
assertEquals( 1, observer.getBegins() );
|
||||
|
||||
final BatchBuilder batchBuilder = new BatchBuilderImpl( 2 );
|
||||
final BatchKey batchKey = new BasicBatchKey( "this", Expectations.BASIC );
|
||||
|
@ -192,7 +172,7 @@ public class BatchingTest extends BaseUnitTestCase implements BatchKey {
|
|||
insertBatch.addToBatch();
|
||||
assertEquals( 0, batchObserver.getExplicitExecutionCount() );
|
||||
assertEquals( 0, batchObserver.getImplicitExecutionCount() );
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
|
||||
PreparedStatement insert2 = insertBatch.getBatchStatement( insertSql, false );
|
||||
assertSame( insert, insert2 );
|
||||
|
@ -204,17 +184,17 @@ public class BatchingTest extends BaseUnitTestCase implements BatchKey {
|
|||
insertBatch.addToBatch();
|
||||
assertEquals( 0, batchObserver.getExplicitExecutionCount() );
|
||||
assertEquals( 1, batchObserver.getImplicitExecutionCount() );
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
|
||||
insertBatch.execute();
|
||||
assertEquals( 1, batchObserver.getExplicitExecutionCount() );
|
||||
assertEquals( 1, batchObserver.getImplicitExecutionCount() );
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
|
||||
insertBatch.release();
|
||||
|
||||
txn.commit();
|
||||
logicalConnection.close();
|
||||
session.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,155 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* 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, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY 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
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.jdbc.proxies;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.engine.jdbc.internal.LogicalConnectionImpl;
|
||||
import org.hibernate.engine.jdbc.internal.proxy.ProxyBuilder;
|
||||
import org.hibernate.test.common.BasicTestingJdbcServiceImpl;
|
||||
import org.hibernate.test.common.JdbcConnectionAccessImpl;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BasicConnectionProxyTest extends BaseUnitTestCase {
|
||||
private BasicTestingJdbcServiceImpl services = new BasicTestingJdbcServiceImpl();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
services.prepare( false );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
services.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDatabaseMetaDataHandling() throws Throwable {
|
||||
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl(
|
||||
null,
|
||||
ConnectionReleaseMode.AFTER_TRANSACTION,
|
||||
services,
|
||||
new JdbcConnectionAccessImpl( services.getConnectionProvider() )
|
||||
);
|
||||
Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
|
||||
try {
|
||||
DatabaseMetaData metaData = proxiedConnection.getMetaData();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
ResultSet rs1 = metaData.getCatalogs();
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
rs1.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
metaData.getCatalogs();
|
||||
metaData.getSchemas();
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
fail( "incorrect exception type : sqlexception" );
|
||||
}
|
||||
finally {
|
||||
logicalConnection.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptionHandling() {
|
||||
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl(
|
||||
null,
|
||||
ConnectionReleaseMode.AFTER_TRANSACTION,
|
||||
services,
|
||||
new JdbcConnectionAccessImpl( services.getConnectionProvider() )
|
||||
);
|
||||
Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
|
||||
try {
|
||||
proxiedConnection.prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery();
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
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,
|
||||
new JdbcConnectionAccessImpl( services.getConnectionProvider() )
|
||||
);
|
||||
Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
|
||||
|
||||
try {
|
||||
Statement statement = proxiedConnection.createStatement();
|
||||
statement.execute( "drop table SANDBOX_JDBC_TST if exists" );
|
||||
statement.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
statement.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() ); // after_transaction specified
|
||||
|
||||
PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
ps.setLong( 1, 1 );
|
||||
ps.setString( 2, "name" );
|
||||
ps.execute();
|
||||
|
||||
ps = proxiedConnection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
ps.executeQuery();
|
||||
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
}
|
||||
catch ( SQLException e ) {
|
||||
fail( "incorrect exception type : sqlexception" );
|
||||
}
|
||||
finally {
|
||||
logicalConnection.close();
|
||||
}
|
||||
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
}
|
||||
}
|
|
@ -23,23 +23,24 @@
|
|||
*/
|
||||
package org.hibernate.test.join;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.jdbc.AbstractWork;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
|
@ -140,14 +141,7 @@ public class JoinTest extends BaseCoreFunctionalTestCase {
|
|||
s.clear();
|
||||
|
||||
// Remove the optional row from the join table and requery the User obj
|
||||
s.doWork(
|
||||
new AbstractWork() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
connection.prepareStatement("delete from t_user").execute();
|
||||
}
|
||||
}
|
||||
);
|
||||
doWork(s);
|
||||
s.clear();
|
||||
|
||||
jesus = (User) s.get( Person.class, new Long( jesus.getId() ) );
|
||||
|
@ -161,6 +155,18 @@ public class JoinTest extends BaseCoreFunctionalTestCase {
|
|||
s.close();
|
||||
}
|
||||
|
||||
private void doWork(final Session s) {
|
||||
s.doWork(
|
||||
new AbstractWork() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
PreparedStatement ps = connection.prepareStatement( "delete from t_user" );
|
||||
ps.execute();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomColumnReadAndWrite() {
|
||||
Session s = openSession();
|
||||
|
|
|
@ -23,9 +23,17 @@
|
|||
*/
|
||||
package org.hibernate.test.legacy;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Time;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -42,13 +50,6 @@ import java.util.TimeZone;
|
|||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.testing.*;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.FlushMode;
|
||||
|
@ -62,6 +63,7 @@ import org.hibernate.QueryException;
|
|||
import org.hibernate.ScrollableResults;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
|
||||
import org.hibernate.criterion.Example;
|
||||
import org.hibernate.criterion.MatchMode;
|
||||
import org.hibernate.criterion.Order;
|
||||
|
@ -83,6 +85,8 @@ import org.hibernate.dialect.SybaseASE15Dialect;
|
|||
import org.hibernate.dialect.SybaseDialect;
|
||||
import org.hibernate.dialect.TimesTenDialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.internal.util.SerializationHelper;
|
||||
import org.hibernate.internal.util.collections.JoinedIterator;
|
||||
import org.hibernate.jdbc.AbstractReturningWork;
|
||||
|
@ -92,15 +96,11 @@ import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
|
|||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FooBarTest extends LegacyTestCase {
|
||||
private static final Logger log = Logger.getLogger( FooBarTest.class );
|
||||
|
@ -2092,29 +2092,29 @@ public class FooBarTest extends LegacyTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
baz = (Baz) s.load( Baz.class, baz.getCode() );
|
||||
final Session s2 = openSession();
|
||||
s2.beginTransaction();
|
||||
baz = (Baz) s2.load( Baz.class, baz.getCode() );
|
||||
assertTrue( baz.getFooArray().length == 1 );
|
||||
assertTrue( s.createQuery( "from Baz baz join baz.fooArray foo" ).list().size()==1 );
|
||||
assertTrue( s.createQuery( "from Foo foo" ).list().size()==2 );
|
||||
assertTrue( s.createFilter( baz.getFooArray(), "" ).list().size() == 1 );
|
||||
assertTrue( s2.createQuery( "from Baz baz join baz.fooArray foo" ).list().size()==1 );
|
||||
assertTrue( s2.createQuery( "from Foo foo" ).list().size()==2 );
|
||||
assertTrue( s2.createFilter( baz.getFooArray(), "" ).list().size() == 1 );
|
||||
//assertTrue( s.delete("from java.lang.Object o")==9 );
|
||||
doDelete( s, "from Foo foo" );
|
||||
doDelete( s2, "from Foo foo" );
|
||||
final String bazid = baz.getCode();
|
||||
s.delete( baz );
|
||||
int rows = s.doReturningWork(
|
||||
s2.delete( baz );
|
||||
int rows = s2.doReturningWork(
|
||||
new AbstractReturningWork<Integer>() {
|
||||
@Override
|
||||
public Integer execute(Connection connection) throws SQLException {
|
||||
return connection.createStatement()
|
||||
.executeUpdate( "delete from FOO_ARRAY where id_='" + bazid + "' and i>=8" );
|
||||
Statement st = connection.createStatement();
|
||||
return st.executeUpdate( "delete from FOO_ARRAY where id_='" + bazid + "' and i>=8" );
|
||||
}
|
||||
}
|
||||
);
|
||||
assertTrue( rows == 1 );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
s2.getTransaction().commit();
|
||||
s2.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2656,45 +2656,46 @@ public class FooBarTest extends LegacyTestCase {
|
|||
assertTrue( baz.getCascadingBars().size()==1 );
|
||||
txn.commit();
|
||||
|
||||
s2 = (Session) SerializationHelper.deserialize( SerializationHelper.serialize(s) );
|
||||
final Session s3 = (Session) SerializationHelper.deserialize( SerializationHelper.serialize(s) );
|
||||
s.close();
|
||||
|
||||
txn2 = s2.beginTransaction();
|
||||
baz = (Baz) s2.load(Baz.class, baz.getCode());
|
||||
assertEquals( 3, ((Long) s2.createQuery( "select count(*) from Bar" ).iterate().next()).longValue() );
|
||||
s2.delete(baz);
|
||||
s2.delete( baz.getTopGlarchez().get( Character.valueOf('G') ) );
|
||||
s2.delete( baz.getTopGlarchez().get( Character.valueOf('H') ) );
|
||||
int rows = s2.doReturningWork(
|
||||
txn2 = s3.beginTransaction();
|
||||
baz = (Baz) s3.load(Baz.class, baz.getCode());
|
||||
assertEquals( 3, ((Long) s3.createQuery( "select count(*) from Bar" ).iterate().next()).longValue() );
|
||||
s3.delete(baz);
|
||||
s3.delete( baz.getTopGlarchez().get( Character.valueOf('G') ) );
|
||||
s3.delete( baz.getTopGlarchez().get( Character.valueOf('H') ) );
|
||||
int rows = s3.doReturningWork(
|
||||
new AbstractReturningWork<Integer>() {
|
||||
@Override
|
||||
public Integer execute(Connection connection) throws SQLException {
|
||||
final String sql = "update " + getDialect().openQuote() + "glarchez" + getDialect().closeQuote() + " set baz_map_id=null where baz_map_index='a'";
|
||||
return connection.createStatement().executeUpdate( sql );
|
||||
Statement st = connection.createStatement();
|
||||
return st.executeUpdate( sql );
|
||||
}
|
||||
}
|
||||
);
|
||||
assertTrue(rows==1);
|
||||
assertEquals( 2, doDelete( s2, "from Bar bar" ) );
|
||||
assertEquals( 2, doDelete( s3, "from Bar bar" ) );
|
||||
FooProxy[] arr = baz.getFooArray();
|
||||
assertTrue( "new array of objects", arr.length==4 && arr[1].getKey().equals( foo.getKey() ) );
|
||||
for ( int i=1; i<arr.length; i++ ) {
|
||||
if ( arr[i]!=null) s2.delete(arr[i]);
|
||||
if ( arr[i]!=null) s3.delete(arr[i]);
|
||||
}
|
||||
|
||||
s2.load( Qux.class, new Long(666) ); //nonexistent
|
||||
s3.load( Qux.class, new Long(666) ); //nonexistent
|
||||
|
||||
assertEquals( 1, doDelete( s2, "from Glarch g" ) );
|
||||
assertEquals( 1, doDelete( s3, "from Glarch g" ) );
|
||||
txn2.commit();
|
||||
|
||||
s2.disconnect();
|
||||
s3.disconnect();
|
||||
|
||||
Session s3 = (Session) SerializationHelper.deserialize( SerializationHelper.serialize( s2 ) );
|
||||
s2.close();
|
||||
//s3.reconnect();
|
||||
assertTrue( s3.load( Qux.class, new Long(666) )!=null ); //nonexistent
|
||||
//s3.disconnect();
|
||||
Session s4 = (Session) SerializationHelper.deserialize( SerializationHelper.serialize( s3 ) );
|
||||
s3.close();
|
||||
//s3.reconnect();
|
||||
assertTrue( s4.load( Qux.class, new Long(666) )!=null ); //nonexistent
|
||||
//s3.disconnect();
|
||||
s4.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -4219,26 +4220,27 @@ public class FooBarTest extends LegacyTestCase {
|
|||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.load( im, im.getId() );
|
||||
final Session s2 = openSession();
|
||||
s2.beginTransaction();
|
||||
s2.load( im, im.getId() );
|
||||
assertEquals(
|
||||
"cached object identity",
|
||||
im,
|
||||
s.createQuery( "from Immutable im where im = ?" ).setParameter(
|
||||
0, im, s.getTypeHelper().entity( Immutable.class )
|
||||
s2.createQuery( "from Immutable im where im = ?" ).setParameter(
|
||||
0, im, s2.getTypeHelper().entity( Immutable.class )
|
||||
).uniqueResult()
|
||||
);
|
||||
s.doWork(
|
||||
s2.doWork(
|
||||
new AbstractWork() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
connection.createStatement().executeUpdate("delete from immut");
|
||||
Statement st = connection.createStatement();
|
||||
st.executeUpdate( "delete from immut" );
|
||||
}
|
||||
}
|
||||
);
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
s2.getTransaction().commit();
|
||||
s2.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -4270,7 +4272,7 @@ public class FooBarTest extends LegacyTestCase {
|
|||
|
||||
@Test
|
||||
public void testRefresh() throws Exception {
|
||||
Session s = openSession();
|
||||
final Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Foo foo = new Foo();
|
||||
s.save( foo );
|
||||
|
@ -4280,7 +4282,8 @@ public class FooBarTest extends LegacyTestCase {
|
|||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
final String sql = "update " + getDialect().openQuote() + "foos" + getDialect().closeQuote() + " set long_ = -3";
|
||||
connection.createStatement().executeUpdate( sql );
|
||||
Statement st = connection.createStatement();
|
||||
st.executeUpdate( sql );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
//$Id: MultiTableTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
|
||||
package org.hibernate.test.legacy;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
|
@ -11,8 +16,6 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.LockMode;
|
||||
|
@ -20,11 +23,9 @@ import org.hibernate.Session;
|
|||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.jdbc.Work;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class MultiTableTest extends LegacyTestCase {
|
||||
|
@ -127,48 +128,49 @@ public class MultiTableTest extends LegacyTestCase {
|
|||
|
||||
sessionFactory().evict(SubMulti.class);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.doWork(
|
||||
final Session s2 = openSession();
|
||||
s2.beginTransaction();
|
||||
s2.doWork(
|
||||
new Work() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
final String sql = "select * from leafsubsubclass sm, nonleafsubclass m, rootclass s " +
|
||||
"where sm.sid=m.sid and sm.sid=s.id1_ and sm.sid=1";
|
||||
connection.createStatement().executeQuery( sql ).next();
|
||||
Statement st = ((SessionImplementor)s2).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().createStatement();
|
||||
((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st, sql ).next();
|
||||
}
|
||||
}
|
||||
);
|
||||
assertTrue(
|
||||
s.createQuery(
|
||||
s2.createQuery(
|
||||
"select s from SubMulti as sm join sm.children as s where s.amount>-1 and s.name is null"
|
||||
).list().size()==2 );
|
||||
s.createQuery( "select c from SubMulti sm join sm.children c" ).list();
|
||||
assertTrue( s.createQuery( "select elements(sm.children) from SubMulti as sm" ).list().size()==2 );
|
||||
s2.createQuery( "select c from SubMulti sm join sm.children c" ).list();
|
||||
assertTrue( s2.createQuery( "select elements(sm.children) from SubMulti as sm" ).list().size()==2 );
|
||||
assertTrue(
|
||||
s.createQuery(
|
||||
s2.createQuery(
|
||||
"select distinct sm from SubMulti as sm join sm.children as s where s.amount>-1 and s.name is null"
|
||||
).list().size()==1 );
|
||||
sm = (SubMulti) s.load(SubMulti.class, id);
|
||||
sm = (SubMulti) s2.load(SubMulti.class, id);
|
||||
assertTrue( sm.getChildren().size()==2 );
|
||||
assertEquals(
|
||||
s.createFilter( sm.getMoreChildren(), "select count(*) where this.amount>-1 and this.name is null" ).list().get(0),
|
||||
s2.createFilter( sm.getMoreChildren(), "select count(*) where this.amount>-1 and this.name is null" ).list().get(0),
|
||||
new Long(2)
|
||||
);
|
||||
assertEquals( "FOO", sm.getDerived() );
|
||||
assertSame(
|
||||
s.createQuery( "select distinct s from SubMulti s where s.moreChildren[1].amount < 1.0" ).iterate().next(),
|
||||
s2.createQuery( "select distinct s from SubMulti s where s.moreChildren[1].amount < 1.0" ).iterate().next(),
|
||||
sm
|
||||
);
|
||||
assertTrue( sm.getMoreChildren().size()==2 );
|
||||
s.delete(sm);
|
||||
s2.delete(sm);
|
||||
Iterator iter = sm.getChildren().iterator();
|
||||
while ( iter.hasNext() ) {
|
||||
s.delete( iter.next() );
|
||||
s2.delete( iter.next() );
|
||||
}
|
||||
s.flush();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
s2.flush();
|
||||
s2.getTransaction().commit();
|
||||
s2.close();
|
||||
|
||||
}
|
||||
|
||||
|
|
11
hibernate-core/src/test/java/org/hibernate/test/rowid/RowIdTest.java
Executable file → Normal file
11
hibernate-core/src/test/java/org/hibernate/test/rowid/RowIdTest.java
Executable file → Normal file
|
@ -33,6 +33,7 @@ import org.junit.Test;
|
|||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.Oracle9iDialect;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
@ -56,19 +57,19 @@ public class RowIdTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
public void afterSessionFactoryBuilt() {
|
||||
super.afterSessionFactoryBuilt();
|
||||
Session session = sessionFactory().openSession();
|
||||
final Session session = sessionFactory().openSession();
|
||||
session.doWork(
|
||||
new Work() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
Statement st = connection.createStatement();
|
||||
Statement st = ((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().createStatement();
|
||||
try {
|
||||
st.execute( "drop table Point");
|
||||
((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().execute( st, "drop table Point");
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
}
|
||||
st.execute("create table Point (\"x\" number(19,2) not null, \"y\" number(19,2) not null, description varchar2(255) )");
|
||||
st.close();
|
||||
((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().execute( st, "create table Point (\"x\" number(19,2) not null, \"y\" number(19,2) not null, description varchar2(255) )");
|
||||
((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().release( st );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
*/
|
||||
package org.hibernate.test.sql.autodiscovery;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
@ -30,15 +32,13 @@ import java.sql.ResultSetMetaData;
|
|||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -121,13 +121,14 @@ public class AutoDiscoveryTest extends BaseCoreFunctionalTestCase {
|
|||
@Test
|
||||
public void testDialectGetColumnAliasExtractor() throws Exception {
|
||||
Session session = openSession();
|
||||
final SessionImplementor sessionImplementor = (SessionImplementor) session;
|
||||
session.beginTransaction();
|
||||
session.doWork(
|
||||
new Work() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
PreparedStatement ps = connection.prepareStatement( QUERY_STRING );
|
||||
ResultSet rs = ps.executeQuery();
|
||||
PreparedStatement ps = sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( QUERY_STRING );
|
||||
ResultSet rs = sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( ps );
|
||||
try {
|
||||
ResultSetMetaData metadata = rs.getMetaData();
|
||||
String column1Alias = getDialect().getColumnAliasExtractor().extractColumnAlias( metadata, 1 );
|
||||
|
@ -135,8 +136,8 @@ public class AutoDiscoveryTest extends BaseCoreFunctionalTestCase {
|
|||
Assert.assertFalse( "bad dialect.getColumnAliasExtractor impl", column1Alias.equals( column2Alias ) );
|
||||
}
|
||||
finally {
|
||||
rs.close();
|
||||
ps.close();
|
||||
sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().release( rs );
|
||||
sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().release( ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,16 +23,17 @@
|
|||
*/
|
||||
package org.hibernate.test.transaction.jdbc;
|
||||
|
||||
import java.sql.Connection;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
||||
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
|
||||
import org.hibernate.engine.transaction.spi.TransactionContext;
|
||||
|
@ -44,11 +45,9 @@ import org.hibernate.test.common.TransactionContextImpl;
|
|||
import org.hibernate.test.common.TransactionEnvironmentImpl;
|
||||
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -81,49 +80,45 @@ public class TestExpectedUsage extends BaseUnitTestCase {
|
|||
JournalingTransactionObserver observer = new JournalingTransactionObserver();
|
||||
transactionCoordinator.addObserver( observer );
|
||||
|
||||
LogicalConnectionImplementor logicalConnection = transactionCoordinator.getJdbcCoordinator().getLogicalConnection();
|
||||
Connection connection = logicalConnection.getShareableConnectionProxy();
|
||||
JdbcCoordinator jdbcCoordinator = transactionCoordinator.getJdbcCoordinator();
|
||||
LogicalConnectionImplementor logicalConnection = jdbcCoordinator.getLogicalConnection();
|
||||
|
||||
// set up some tables to use
|
||||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
statement.execute( "drop table SANDBOX_JDBC_TST if exists" );
|
||||
statement.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
statement.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() ); // after_transaction specified
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
fail( "incorrect exception type : SQLException" );
|
||||
}
|
||||
Statement statement = jdbcCoordinator.getStatementPreparer().createStatement();
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "drop table SANDBOX_JDBC_TST if exists" );
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
jdbcCoordinator.release( statement );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() ); // after_transaction specified
|
||||
|
||||
// ok, now we can get down to it...
|
||||
TransactionImplementor txn = transactionCoordinator.getTransaction(); // same as Session#getTransaction
|
||||
txn.begin();
|
||||
assertEquals( 1, observer.getBegins() );
|
||||
try {
|
||||
PreparedStatement ps = connection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
PreparedStatement ps = jdbcCoordinator.getStatementPreparer().prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
ps.setLong( 1, 1 );
|
||||
ps.setString( 2, "name" );
|
||||
ps.execute();
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
ps.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
jdbcCoordinator.getResultSetReturn().execute( ps );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
jdbcCoordinator.release( ps );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
|
||||
ps = connection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
ps.executeQuery();
|
||||
connection.prepareStatement( "delete from SANDBOX_JDBC_TST" ).execute();
|
||||
ps = jdbcCoordinator.getStatementPreparer().prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
jdbcCoordinator.getResultSetReturn().extract( ps );
|
||||
ps = jdbcCoordinator.getStatementPreparer().prepareStatement( "delete from SANDBOX_JDBC_TST" );
|
||||
jdbcCoordinator.getResultSetReturn().execute( ps );
|
||||
// lets forget to close these...
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
|
||||
// and commit the transaction...
|
||||
txn.commit();
|
||||
|
||||
// we should now have:
|
||||
// 1) no resources because of after_transaction release mode
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
// 2) non-physically connected logical connection, again because of after_transaction release mode
|
||||
assertFalse( logicalConnection.isPhysicallyConnected() );
|
||||
// 3) transaction observer callbacks
|
||||
|
|
|
@ -23,18 +23,19 @@
|
|||
*/
|
||||
package org.hibernate.test.transaction.jta;
|
||||
|
||||
import java.sql.Connection;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
||||
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
|
||||
import org.hibernate.engine.transaction.internal.jta.JtaTransactionFactory;
|
||||
|
@ -49,11 +50,9 @@ import org.hibernate.test.common.TransactionEnvironmentImpl;
|
|||
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Testing transaction handling when the JTA transaction facade is the driver.
|
||||
|
@ -88,23 +87,18 @@ public class BasicDrivingTest extends BaseUnitTestCase {
|
|||
JournalingTransactionObserver observer = new JournalingTransactionObserver();
|
||||
transactionCoordinator.addObserver( observer );
|
||||
|
||||
LogicalConnectionImplementor logicalConnection = transactionCoordinator.getJdbcCoordinator().getLogicalConnection();
|
||||
Connection connection = logicalConnection.getShareableConnectionProxy();
|
||||
JdbcCoordinator jdbcCoordinator = transactionCoordinator.getJdbcCoordinator();
|
||||
LogicalConnectionImplementor logicalConnection = jdbcCoordinator.getLogicalConnection();
|
||||
|
||||
// set up some tables to use
|
||||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
statement.execute( "drop table SANDBOX_JDBC_TST if exists" );
|
||||
statement.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
statement.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertFalse( logicalConnection.isPhysicallyConnected() ); // after_statement specified
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
fail( "incorrect exception type : SQLException" );
|
||||
}
|
||||
Statement statement = jdbcCoordinator.getStatementPreparer().createStatement();
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "drop table SANDBOX_JDBC_TST if exists" );
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
jdbcCoordinator.release( statement );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertFalse( logicalConnection.isPhysicallyConnected() ); // after_statement specified
|
||||
|
||||
// ok, now we can get down to it...
|
||||
TransactionImplementor txn = transactionCoordinator.getTransaction(); // same as Session#getTransaction
|
||||
|
@ -112,19 +106,20 @@ public class BasicDrivingTest extends BaseUnitTestCase {
|
|||
assertEquals( 1, observer.getBegins() );
|
||||
assertTrue( txn.isInitiator() );
|
||||
try {
|
||||
PreparedStatement ps = connection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
PreparedStatement ps = jdbcCoordinator.getStatementPreparer().prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
ps.setLong( 1, 1 );
|
||||
ps.setString( 2, "name" );
|
||||
ps.execute();
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
ps.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
jdbcCoordinator.getResultSetReturn().execute( ps );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
jdbcCoordinator.release( ps );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
|
||||
ps = connection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
ps.executeQuery();
|
||||
connection.prepareStatement( "delete from SANDBOX_JDBC_TST" ).execute();
|
||||
ps = jdbcCoordinator.getStatementPreparer().prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
jdbcCoordinator.getResultSetReturn().extract( ps );
|
||||
ps = jdbcCoordinator.getStatementPreparer().prepareStatement( "delete from SANDBOX_JDBC_TST" );
|
||||
jdbcCoordinator.getResultSetReturn().execute( ps );
|
||||
// lets forget to close these...
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
|
||||
// and commit the transaction...
|
||||
|
@ -132,7 +127,7 @@ public class BasicDrivingTest extends BaseUnitTestCase {
|
|||
|
||||
// we should now have:
|
||||
// 1) no resources because of after_transaction release mode
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
// 2) non-physically connected logical connection, again because of after_transaction release mode
|
||||
assertFalse( logicalConnection.isPhysicallyConnected() );
|
||||
// 3) transaction observer callbacks
|
||||
|
|
|
@ -23,21 +23,23 @@
|
|||
*/
|
||||
package org.hibernate.test.transaction.jta;
|
||||
|
||||
import java.sql.Connection;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.jdbc.spi.LogicalConnectionImplementor;
|
||||
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
|
||||
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
|
||||
|
@ -52,11 +54,9 @@ import org.hibernate.test.common.TransactionEnvironmentImpl;
|
|||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Testing transaction facade handling when the transaction is being driven by something other than the facade.
|
||||
|
@ -97,23 +97,18 @@ public class ManagedDrivingTest extends BaseUnitTestCase {
|
|||
final JournalingTransactionObserver transactionObserver = new JournalingTransactionObserver();
|
||||
transactionCoordinator.addObserver( transactionObserver );
|
||||
|
||||
final LogicalConnectionImplementor logicalConnection = transactionCoordinator.getJdbcCoordinator().getLogicalConnection();
|
||||
Connection connection = logicalConnection.getShareableConnectionProxy();
|
||||
JdbcCoordinator jdbcCoordinator = transactionCoordinator.getJdbcCoordinator();
|
||||
LogicalConnectionImplementor logicalConnection = jdbcCoordinator.getLogicalConnection();
|
||||
|
||||
// set up some tables to use
|
||||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
statement.execute( "drop table SANDBOX_JDBC_TST if exists" );
|
||||
statement.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
statement.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertFalse( logicalConnection.isPhysicallyConnected() ); // after_statement specified
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
fail( "incorrect exception type : SQLException" );
|
||||
}
|
||||
Statement statement = jdbcCoordinator.getStatementPreparer().createStatement();
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "drop table SANDBOX_JDBC_TST if exists" );
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
jdbcCoordinator.release( statement );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertFalse( logicalConnection.isPhysicallyConnected() ); // after_statement specified
|
||||
|
||||
JtaPlatform instance = serviceRegistry.getService( JtaPlatform.class );
|
||||
TransactionManager transactionManager = instance.retrieveTransactionManager();
|
||||
|
@ -126,34 +121,34 @@ public class ManagedDrivingTest extends BaseUnitTestCase {
|
|||
txn.begin();
|
||||
assertEquals( 1, transactionObserver.getBegins() );
|
||||
assertFalse( txn.isInitiator() );
|
||||
connection = logicalConnection.getShareableConnectionProxy();
|
||||
try {
|
||||
PreparedStatement ps = connection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
PreparedStatement ps = jdbcCoordinator.getStatementPreparer().prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
|
||||
ps.setLong( 1, 1 );
|
||||
ps.setString( 2, "name" );
|
||||
ps.execute();
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
ps.close();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
jdbcCoordinator.getResultSetReturn().execute( ps );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
jdbcCoordinator.release( ps );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
|
||||
ps = connection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
ps.executeQuery();
|
||||
connection.prepareStatement( "delete from SANDBOX_JDBC_TST" ).execute();
|
||||
ps = jdbcCoordinator.getStatementPreparer().prepareStatement( "select * from SANDBOX_JDBC_TST" );
|
||||
jdbcCoordinator.getResultSetReturn().extract( ps );
|
||||
ps = jdbcCoordinator.getStatementPreparer().prepareStatement( "delete from SANDBOX_JDBC_TST" );
|
||||
jdbcCoordinator.getResultSetReturn().execute( ps );
|
||||
// lets forget to close these...
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
|
||||
// and commit the transaction...
|
||||
txn.commit();
|
||||
|
||||
// since txn is not a driver, nothing should have changed...
|
||||
assertTrue( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
assertEquals( 0, transactionObserver.getBeforeCompletions() );
|
||||
assertEquals( 0, transactionObserver.getAfterCompletions() );
|
||||
|
||||
transactionManager.commit();
|
||||
assertFalse( logicalConnection.getResourceRegistry().hasRegisteredResources() );
|
||||
assertFalse( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertFalse( logicalConnection.isPhysicallyConnected() );
|
||||
assertEquals( 1, transactionObserver.getBeforeCompletions() );
|
||||
assertEquals( 1, transactionObserver.getAfterCompletions() );
|
||||
|
|
|
@ -23,20 +23,20 @@
|
|||
*/
|
||||
package org.hibernate.test.typeparameters;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test for parameterizable types.
|
||||
|
@ -67,13 +67,22 @@ public class TypeParameterTest extends BaseCoreFunctionalTestCase {
|
|||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
||||
doWork(id, s);
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
deleteData();
|
||||
}
|
||||
|
||||
private void doWork(final Integer id, final Session s) {
|
||||
s.doWork(
|
||||
new Work() {
|
||||
@Override
|
||||
public void execute(Connection connection) throws SQLException {
|
||||
PreparedStatement statement = connection.prepareStatement("SELECT * FROM STRANGE_TYPED_OBJECT WHERE ID=?");
|
||||
PreparedStatement statement = ((SessionImplementor)s).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( "SELECT * FROM STRANGE_TYPED_OBJECT WHERE ID=?" );
|
||||
statement.setInt(1, id.intValue());
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
ResultSet resultSet = ((SessionImplementor)s).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( statement );
|
||||
|
||||
assertTrue("A row should have been returned", resultSet.next());
|
||||
assertTrue("Default value should have been mapped to null", resultSet.getObject("VALUE_ONE") == null);
|
||||
|
@ -83,11 +92,6 @@ public class TypeParameterTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
deleteData();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.hibernate.envers.strategy;
|
||||
|
||||
import static org.hibernate.envers.entities.mapper.relation.query.QueryConstants.MIDDLE_ENTITY_ALIAS;
|
||||
import static org.hibernate.envers.entities.mapper.relation.query.QueryConstants.REVISION_PARAMETER;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
@ -10,8 +13,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
|
@ -32,15 +33,12 @@ import org.hibernate.event.spi.AutoFlushEventListener;
|
|||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.event.spi.EventType;
|
||||
import org.hibernate.jdbc.ReturningWork;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.persister.entity.Queryable;
|
||||
import org.hibernate.persister.entity.UnionSubclassEntityPersister;
|
||||
import org.hibernate.property.Getter;
|
||||
import org.hibernate.sql.Update;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
import static org.hibernate.envers.entities.mapper.relation.query.QueryConstants.MIDDLE_ENTITY_ALIAS;
|
||||
import static org.hibernate.envers.entities.mapper.relation.query.QueryConstants.REVISION_PARAMETER;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Audit strategy which persists and retrieves audit information using a validity algorithm, based on the
|
||||
|
@ -162,7 +160,7 @@ public class ValidityAuditStrategy implements AuditStrategy {
|
|||
new ReturningWork<Integer>() {
|
||||
@Override
|
||||
public Integer execute(Connection connection) throws SQLException {
|
||||
PreparedStatement preparedStatement = connection.prepareStatement( updateSql );
|
||||
PreparedStatement preparedStatement = sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( updateSql );
|
||||
|
||||
try {
|
||||
int index = 1;
|
||||
|
@ -197,15 +195,10 @@ public class ValidityAuditStrategy implements AuditStrategy {
|
|||
// where REVEND is null
|
||||
// nothing to bind....
|
||||
|
||||
return preparedStatement.executeUpdate();
|
||||
return sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( preparedStatement );
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
log.debug( "Could not release prepared statement : " + e.getMessage() );
|
||||
}
|
||||
sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().release( preparedStatement );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue