Hi
Here's my situation.
We have an app (Tomcat 5.5.9A, Spring 2.0.5 (commons dbcp), MySQL 5.1?, iBatis 2.3.0.667 ) with AOP declarative transaction control - Here's the xml:
DAOs
Services:Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <!-- ========================= PERSISTENCE DEFINITIONS ========================= --> <beans> <!-- DataSource Beans - These are grbbed from tomcat using jndi lookups --> <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" scope="singleton" abstract="false" lazy-init="default" autowire="default" dependency-check="default"> <property name="jndiName" value="java:comp/env/jdbc/newDBIssues" /> </bean> <!-- IBatis Map configuration --> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation" value="WEB-INF/sqlmap-context.xml"/> <property name="dataSource" ref="dataSource"/> </bean> <bean id="creditSqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation" value="WEB-INF/credit-sqlmap-context.xml"/> <property name="dataSource" ref="creditDataSource"/> </bean> <!-- DAOs here --> <bean id="ProspectusFieldDAO" class="com.globalfilings.domain.dao.ProspectusFieldDAOImpl"> <property name="sqlMapClient" ref="sqlMapClient"/> <property name="fieldCache" ref="fieldCache"/> </bean> </beans>
I've removed some of the beans from the xml for clarity.Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <!-- Transaction Managers --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- Services beans --> <bean id="issuesServices" class="com.globalfilings.services.IssuesServices"> <property name="prospectusFieldDAO" ref="ProspectusFieldDAO"/> </bean> <!-- AOP Enables transaction options --> <!-- the transactional advice (i.e. what 'happens'; see the <aop:advisor/> bean below) --> <tx:advice id="issuesTxAdvice" transaction-manager="txManager"> <!-- the transactional semantics... --> <tx:attributes> <!-- all methods starting with 'select' are read-only --> <tx:method name="select*" read-only="true" propagation="REQUIRED"/> <tx:method name="get*" read-only="true" propagation="REQUIRED"/> <tx:method name="savePagePosition" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="revert*" propagation="REQUIRED" /> <!-- other methods use the default transaction settings (see below) --> <tx:method name="*" /> </tx:attributes> </tx:advice> <!-- ensure that the above transactional advice runs for any execution of an operation defined by the service interfaces --> <aop:config> <aop:pointcut id="issuesServiceOperation" expression="execution(* com.globalfilings.services.IIssuesServices.*(..))" /> <aop:advisor advice-ref="issuesTxAdvice" pointcut-ref="issuesServiceOperation" /> </aop:config> <aop:config> <aop:pointcut id="userServiceOperation" expression="execution(* com.globalfilings.services.IUserServices.*(..))" /> <aop:advisor advice-ref="creditTxAdvice" pointcut-ref="userServiceOperation" /> </aop:config> </beans>
Here's the problem - in the course of a request there is an interceptor that look up some values using a method of ProspectusFieldDAOImpl - Here it is:
This pulls stuff out of the cache as expected but it doesn't save much time (2-10ms per lookup). I put debug onto Transaction Manager and it is still pulling connections from the pool and doing full transaction management even though it doesn't run the select - here's a snippet of the log when the cache works:Code:public ProspectusField selectByPrimaryKey(Integer id) { ProspectusField record = null; //Look in the cache first Element cacheResult = null; cacheResult = fieldCache.get(id); if(cacheResult==null){ //No cache so go to the db ProspectusField key = new ProspectusField(); key.setId(id); record = (ProspectusField) getSqlMapClientTemplate().queryForObject("wf_Prospectus_Fields2.abatorgenerated_selectByPrimaryKey", key); //check to see if we have valid field if(record!=null){ //Yes so stick it on the cache fieldCache.put(new Element(id, record)); } }else{ record = (ProspectusField)cacheResult.getValue(); } return record; }
I suppose this means that all is working just as designed but is there any way I can stop the Transaction doing it's stuff? The log snippet details just one of the lookups but the interceptor could make up to 20 which may add 2 seconds to the processing.Code:2007-08-16 11:46:15,781 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Using transaction object [org.springframework.jdbc.datasource.DataSourceTransactionManager$DataSourceTransactionObject@8b915d]> 2007-08-16 11:46:15,781 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [com.globalfilings.services.IIssuesServices.getFieldbyId]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly> 2007-08-16 11:46:15,812 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [org.apache.tomcat.dbcp.dbcp.PoolableConnection@8777c] for JDBC transaction> 2007-08-16 11:46:15,812 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Switching JDBC Connection [org.apache.tomcat.dbcp.dbcp.PoolableConnection@8777c] to manual commit> 2007-08-16 11:46:15,843 INFO [com.globalfilings.services.IssuesServices] - <Returning field 370 took 0ms> 2007-08-16 11:46:15,843 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Triggering beforeCommit synchronization> 2007-08-16 11:46:15,843 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Triggering beforeCompletion synchronization> 2007-08-16 11:46:15,843 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit> 2007-08-16 11:46:15,843 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [org.apache.tomcat.dbcp.dbcp.PoolableConnection@8777c]> 2007-08-16 11:46:15,859 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Triggering afterCommit synchronization> 2007-08-16 11:46:15,874 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Triggering afterCompletion synchronization> 2007-08-16 11:46:15,906 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [org.apache.tomcat.dbcp.dbcp.PoolableConnection@8777c] after transaction>
Any ideas?
Thanks
Charlie


Reply With Quote
