HHH-13523 StatementPreparerImpl should not need to retrieve the JDBCService as often

This commit is contained in:
Andrea Boriero 2019-07-29 22:19:05 +01:00 committed by Sanne Grinovero
parent 99398753c6
commit 16ca846143
2 changed files with 19 additions and 27 deletions

View File

@ -61,18 +61,12 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
private transient LogicalConnectionImplementor logicalConnection;
private transient JdbcSessionOwner owner;
private transient JdbcServices jdbcServices;
private transient Batch currentBatch;
private transient long transactionTimeOutInstant = -1;
/**
* This is a marker value to insert instead of null values for when a Statement gets registered in xref
* but has no associated ResultSets registered. This is useful to efficiently check against duplicate
* registration but you'll have to check against instance equality rather than null before attempting
* to add elements to this set.
*/
private static final Set<ResultSet> EMPTY_RESULTSET = Collections.emptySet();
private final HashMap<Statement,Set<ResultSet>> xref = new HashMap<>();
private final Set<ResultSet> unassociatedResultSets = new HashSet<>();
private transient SqlExceptionHelper exceptionHelper;
@ -110,9 +104,10 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
);
}
this.owner = owner;
this.exceptionHelper = owner.getJdbcSessionContext()
this.jdbcServices = owner.getJdbcSessionContext()
.getServiceRegistry()
.getService( JdbcServices.class )
.getService( JdbcServices.class );
this.exceptionHelper = jdbcServices
.getSqlExceptionHelper();
}
@ -123,9 +118,10 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
this.logicalConnection = logicalConnection;
this.isUserSuppliedConnection = isUserSuppliedConnection;
this.owner = owner;
this.exceptionHelper = owner.getJdbcSessionContext()
this.jdbcServices = owner.getJdbcSessionContext()
.getServiceRegistry()
.getService( JdbcServices.class )
.getService( JdbcServices.class );
this.exceptionHelper = jdbcServices
.getSqlExceptionHelper();
}
@ -227,7 +223,7 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
@Override
public StatementPreparer getStatementPreparer() {
if ( statementPreparer == null ) {
statementPreparer = new StatementPreparerImpl( this );
statementPreparer = new StatementPreparerImpl( this, jdbcServices );
}
return statementPreparer;
}

View File

@ -18,6 +18,7 @@ import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.engine.jdbc.spi.StatementPreparer;
import org.hibernate.resource.jdbc.spi.JdbcObserver;
import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor;
/**
@ -28,15 +29,17 @@ import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor;
* @author Brett Meyer
*/
class StatementPreparerImpl implements StatementPreparer {
private JdbcCoordinatorImpl jdbcCoordinator;
private final JdbcCoordinatorImpl jdbcCoordinator;
private final JdbcServices jdbcServices;
/**
* Construct a StatementPreparerImpl
*
* @param jdbcCoordinator The JdbcCoordinatorImpl
*/
StatementPreparerImpl(JdbcCoordinatorImpl jdbcCoordinator) {
StatementPreparerImpl(JdbcCoordinatorImpl jdbcCoordinator, JdbcServices jdbcServices) {
this.jdbcCoordinator = jdbcCoordinator;
this.jdbcServices = jdbcServices;
}
protected final SessionFactoryOptions settings() {
@ -52,7 +55,7 @@ class StatementPreparerImpl implements StatementPreparer {
}
protected final SqlExceptionHelper sqlExceptionHelper() {
return getJdbcService().getSqlExceptionHelper();
return jdbcServices.getSqlExceptionHelper();
}
@Override
@ -164,16 +167,17 @@ class StatementPreparerImpl implements StatementPreparer {
public PreparedStatement prepareStatement() {
try {
getJdbcService().getSqlStatementLogger().logStatement( sql );
jdbcServices.getSqlStatementLogger().logStatement( sql );
final PreparedStatement preparedStatement;
final JdbcObserver observer = jdbcCoordinator.getJdbcSessionOwner().getJdbcSessionContext().getObserver();
try {
jdbcCoordinator.getJdbcSessionOwner().getJdbcSessionContext().getObserver().jdbcPrepareStatementStart();
observer.jdbcPrepareStatementStart();
preparedStatement = doPrepare();
setStatementTimeout( preparedStatement );
}
finally {
jdbcCoordinator.getJdbcSessionOwner().getJdbcSessionContext().getObserver().jdbcPrepareStatementEnd();
observer.jdbcPrepareStatementEnd();
}
postProcess( preparedStatement );
return preparedStatement;
@ -198,14 +202,6 @@ class StatementPreparerImpl implements StatementPreparer {
}
}
private JdbcServices getJdbcService() {
return jdbcCoordinator
.getJdbcSessionOwner()
.getJdbcSessionContext()
.getServiceRegistry()
.getService( JdbcServices.class );
}
private abstract class QueryStatementPreparationTemplate extends StatementPreparationTemplate {
protected QueryStatementPreparationTemplate(String sql) {
super( sql );