LOGGER.debug(() ->"SqlSession ["+ session +"] was not registered for synchronization because DataSource is not transactional"); }else{ thrownewTransientDataAccessResourceException("SqlSessionFactory must be using a SpringManagedTransactionFactory in order to use Spring transaction synchronization"); }...
--配置事物,事物管理器--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="datasource" /> </bean> <!--启动事物管理器注解--> <tx:annotation-driven transaction-manager="transactionManager" /> <!--datasource...
在看到 getResource() 方法,核心源码如下: @NullablepublicstaticObjectgetResource(Object key){ObjectactualKey=TransactionSynchronizationUtils.unwrapResourceIfNecessary(key);Objectvalue=doGetResource(actualKey);if(value !=null&& logger.isTraceEnabled()) { logger.trace("Retrieved value ["+ value +"] for ...
直接分析默认使用的openSession()无参的方法,在DefaultSqlSessionFactory#openSession中,可以看到其调用的是openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit)这个方法: private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, b...
(this,transaction); } elseif(ExecutorType.REUSE == executorType) { executor = new ReuseExecutor(this,transaction); } else { executor = newSimpleExecutor(this, transaction); } if (cacheEnabled) { executor = new CachingExecutor(executor); } executor =(Executor) interceptorChain.pluginAll(...
* Gets an SqlSession from Spring Transaction Manager or creates a new one if needed. * Tries to get a SqlSession out of current transaction. If there is not any, it creates a new one. * Then, it synchronizes the SqlSession with the transaction if Spring TX is active and ...
ExecutorType.SIMPLE:executorType;Executorexecutor;if(ExecutorType.BATCH==executorType){executor=newBatchExecutor(this,transaction);}elseif(ExecutorType.REUSE==executorType){executor=newReuseExecutor(this,transaction);}else{executor=newSimpleExecutor(this,transaction);}if(cacheEnabled){executor=newCaching...
(this, transaction); } else if (ExecutorType.REUSE == executorType) { executor = new ReuseExecutor(this, transaction); } else { executor = new SimpleExecutor(this, transaction); } if (cacheEnabled) { executor = new CachingExecutor(executor); } executor = (Executor) interceptorChain.plugin...
executor = new SimpleExecutor(this, transaction); } // 是否开启缓存 if (cacheEnabled) { executor = new CachingExecutor(executor, autoCommit); } executor = (Executor) interceptorChain.pluginAll(executor); return executor; } 可以看出,如果不开启cache的话,创建的Executor只是3中基础类型之一: ...
executor = new SimpleExecutor(this, transaction); } if (cacheEnabled) { executor = new CachingExecutor(executor); } executor = (Executor) interceptorChain.pluginAll(executor); return executor; } 注:最后interceptorChain.pluginAll()中执行层层动态代理,最后在可以在调用真正的Executor前可以修改插件代码,...