下面列出了怎么用org.hibernate.resource.jdbc.spi.StatementInspector的API类实例代码及写法,或者点击链接到github查看源代码。
public JdbcSessionContextImpl(SharedSessionContractImplementor session, StatementInspector statementInspector) {
this.sessionFactory = session.getFactory();
this.statementInspector = statementInspector;
this.connectionHandlingMode = settings().getPhysicalConnectionHandlingMode();
this.serviceRegistry = sessionFactory.getServiceRegistry();
this.jdbcObserver = new JdbcObserverImpl( session );
if ( this.statementInspector == null ) {
throw new IllegalArgumentException( "StatementInspector cannot be null" );
}
}
private StatementInspector interpret(StatementInspector statementInspector) {
if ( statementInspector == null ) {
// If there is no StatementInspector specified, map to the call
// to the (deprecated) Interceptor #onPrepareStatement method
return (StatementInspector) interceptor::onPrepareStatement;
}
return statementInspector;
}
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException {
if ( log.isTraceEnabled() ) {
log.trace( "Deserializing " + getClass().getSimpleName() );
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Step 1 :: read back non-transient state...
ois.defaultReadObject();
sessionEventsManager = new SessionEventListenerManagerImpl();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Step 2 :: read back transient state...
// -- see above
factory = SessionFactoryImpl.deserialize( ois );
jdbcSessionContext = new JdbcSessionContextImpl( this, (StatementInspector) ois.readObject() );
jdbcCoordinator = JdbcCoordinatorImpl.deserialize( ois, this );
cacheTransactionSync = factory.getCache().getRegionFactory().createTransactionContext( this );
transactionCoordinator = factory.getServiceRegistry()
.getService( TransactionCoordinatorBuilder.class )
.buildTransactionCoordinator( jdbcCoordinator, this );
entityNameResolver = new CoordinatingEntityNameResolver( factory, interceptor );
exceptionConverter = new ExceptionConverterImpl( this );
}
@Override
public StatementInspector getStatementInspector() {
return statementInspector;
}
@Override
public StatementInspector getStatementInspector() {
return statementInspector;
}
@Override
public StatementInspector getStatementInspector() {
return null;
}
public AbstractSharedSessionContract(SessionFactoryImpl factory, SessionCreationOptions options) {
this.factory = factory;
this.cacheTransactionSync = factory.getCache().getRegionFactory().createTransactionContext( this );
this.flushMode = options.getInitialSessionFlushMode();
this.tenantIdentifier = options.getTenantIdentifier();
if ( MultiTenancyStrategy.NONE == factory.getSettings().getMultiTenancyStrategy() ) {
if ( tenantIdentifier != null ) {
throw new HibernateException( "SessionFactory was not configured for multi-tenancy" );
}
}
else {
if ( tenantIdentifier == null ) {
throw new HibernateException( "SessionFactory configured for multi-tenancy, but no tenant identifier specified" );
}
}
this.interceptor = interpret( options.getInterceptor() );
this.jdbcTimeZone = options.getJdbcTimeZone();
final StatementInspector statementInspector = interpret( options.getStatementInspector() );
this.jdbcSessionContext = new JdbcSessionContextImpl( this, statementInspector );
this.entityNameResolver = new CoordinatingEntityNameResolver( factory, interceptor );
if ( options instanceof SharedSessionCreationOptions && ( (SharedSessionCreationOptions) options ).isTransactionCoordinatorShared() ) {
if ( options.getConnection() != null ) {
throw new SessionException( "Cannot simultaneously share transaction context and specify connection" );
}
this.isTransactionCoordinatorShared = true;
final SharedSessionCreationOptions sharedOptions = (SharedSessionCreationOptions) options;
this.transactionCoordinator = sharedOptions.getTransactionCoordinator();
this.jdbcCoordinator = sharedOptions.getJdbcCoordinator();
// todo : "wrap" the transaction to no-op cmmit/rollback attempts?
this.currentHibernateTransaction = sharedOptions.getTransaction();
if ( sharedOptions.shouldAutoJoinTransactions() ) {
log.debug(
"Session creation specified 'autoJoinTransactions', which is invalid in conjunction " +
"with sharing JDBC connection between sessions; ignoring"
);
autoJoinTransactions = false;
}
if ( sharedOptions.getPhysicalConnectionHandlingMode() != this.jdbcCoordinator.getLogicalConnection().getConnectionHandlingMode() ) {
log.debug(
"Session creation specified 'PhysicalConnectionHandlingMode which is invalid in conjunction " +
"with sharing JDBC connection between sessions; ignoring"
);
}
addSharedSessionTransactionObserver( transactionCoordinator );
}
else {
this.isTransactionCoordinatorShared = false;
this.autoJoinTransactions = options.shouldAutoJoinTransactions();
this.jdbcCoordinator = new JdbcCoordinatorImpl( options.getConnection(), this );
this.transactionCoordinator = factory.getServiceRegistry()
.getService( TransactionCoordinatorBuilder.class )
.buildTransactionCoordinator( jdbcCoordinator, this );
}
exceptionConverter = new ExceptionConverterImpl( this );
}
@Override
public StatementInspector getStatementInspector() {
return delegate.getStatementInspector();
}
@Override
public T applyStatementInspector(StatementInspector statementInspector) {
delegate.applyStatementInspector( statementInspector );
return getThis();
}
@Override
public StatementInspector getStatementInspector() {
return statementInspector;
}
public void applyStatementInspector(StatementInspector statementInspector) {
this.statementInspector = statementInspector;
}
@Override
public SessionFactoryBuilder applyStatementInspector(StatementInspector statementInspector) {
this.optionsBuilder.applyStatementInspector( statementInspector );
return this;
}
/**
* Names a StatementInspector to be applied to the SessionFactory, which in turn means it will be used by all
* Sessions unless one is explicitly specified in {@link org.hibernate.SessionBuilder#statementInspector}
*
* @param statementInspector The StatementInspector
*
* @return {@code this}, for method chaining
*
* @see org.hibernate.cfg.AvailableSettings#STATEMENT_INSPECTOR
*/
SessionFactoryBuilder applyStatementInspector(StatementInspector statementInspector);
StatementInspector getStatementInspector();
StatementInspector getStatementInspector();