ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thibaut Fagart <thibaut.fag...@hsbc.fr>
Subject Re: [JDBC type = ARRAY / Java type = ?] reusing prepared statement
Date Mon, 19 Feb 2007 10:08:49 GMT

I'm still trying to reuse prepared statements and from looking at the source
code of IBatis 2.3, it seems you need a SessionScope for it to work (It
seems the session scope holds the prepared statement cache).

I can't find anywhere in the code where a SessionScope is instanciated, how
do I achieve that ?



Thibaut Fagart wrote:
> 
> 
> Is there some documentation/specification/mails that describe the
> conditions where statement cacheing is used by IBatis ?
> 
> Are you saying that IBatis does not allow prepared statements to be reused
> across invocations of a given query (in the same thread/transaction) ? I
> hoped it was what that settings flag was for :(
> 
> 
> 
> Larry Meadors-2 wrote:
>> 
>> Without a batch, that is the correct behavior, yes.
>> 
>> Maybe [ot], but if you are using Oracle, it does this for you in the
>> database.
>> 
>> Larry
>> 
>> 
>> On 2/15/07, Thibaut Fagart <thibaut.fagart@hsbc.fr> wrote:
>>>
>>> Hi,
>>>
>>> I'm currently trying to have IBatis reuse prepared statements for
>>> subsequent
>>> calls, but I don't believe It works.
>>>
>>> Here is my Test class
>>>
>>>
>>> > public class TestPatrimonyWithSpringAndIBatis extends
>>> > AbstractTransactionalDataSourceSpringContextTests {
>>> >       private CustomerPatrimonyDAO dao;
>>> >
>>> >       protected String[] getConfigLocations() {
>>> >               return new String[] {
>>> > "classpath:com/hsbc/hbfr/ccf/referentiels/ibatis/spring.xml" };
>>> >       }
>>> >       public void setCustomerPatrimonyDao(CustomerPatrimonyDAO dao) {
>>> this.dao
>>> > = dao; }
>>> >       public void setCustomerPatrimonyService(PatrimonySISV
>>> patrimonyService) {
>>> > this.patrimonyService = patrimonyService; }
>>> >
>>> >       public void testService() throws CustomerNotFoundException {
>>> >               CustomerIdVO idVO = new CustomerIdVO();
>>> >               // set request params, omitted
>>> >               CustomerPatrimonyVO vo =
>>> patrimonyService.findPatrimony(idVO);
>>> >               assertNotNull(vo);
>>> >       }
>>> >
>>> >       public void testDo2FindsConsecutively() {
>>> >               testCustomerDAOWithNoCustomer();
>>> >               testCustomerDAOWithNoCustomer();
>>> >       }
>>> >       public void testCustomerDAOWithNoCustomer() {
>>> >               CustomerIdVO idVO = new CustomerIdVO();
>>> >               // set request params, omitted
>>> >
>>> >               CustomerPatrimonyVO vo = dao.findPatrimony(new
>>> CustomerIdVO());
>>> >               assertNull("vo should be null", vo);
>>> >       }
>>> > }
>>> >
>>>
>>> where the dao is just
>>>
>>>
>>>
>>> > public class CustomerPatrimonyDAO  extends SqlMapClientTemplate {
>>> >       public CustomerPatrimonyVO findPatrimony(CustomerIdVO
>>> customerId) {
>>> >               return (CustomerPatrimonyVO)
>>> queryForObject("getPatrimonyByCustomerId",
>>> > customerId);
>>> >       }
>>> > }
>>> >
>>>
>>> I included <settings statementCachingEnabled="true"/> in my sqlMapConfig
>>>
>>> I activated ibatis logs using log4j and here is what i get
>>>
>>>
>>>
>>> >
>>> com.hsbc.hbfr.ccf.referentiels.ibatis.TestPatrimonyWithSpringAndIBatis;INFO;main;2007-02-15
>>> > 17:28:05,208;Began transaction (1): transaction manager
>>> >
>>> [org.springframework.jdbc.datasource.DataSourceTransactionManager@48ea8086];
>>> > default rollback = true
>>> > java.sql.Connection;DEBUG;main;2007-02-15 17:28:05,268;{conn-100000}
>>> > Connection
>>> > java.sql.Connection;DEBUG;main;2007-02-15 17:28:05,288;{conn-100000}
>>> > Preparing Statement:   // OMITTED
>>> > java.sql.PreparedStatement;DEBUG;main;2007-02-15
>>> > 17:28:05,889;{pstm-100001} Executing Statement:   // OMITTED
>>> > java.sql.PreparedStatement;DEBUG;main;2007-02-15
>>> > 17:28:05,969;{pstm-100001} Parameters: [null, null, 0, 0]
>>> > java.sql.PreparedStatement;DEBUG;main;2007-02-15
>>> > 17:28:05,969;{pstm-100001} Types: [null, null, java.lang.Integer,
>>> > java.lang.Integer]
>>> > java.sql.ResultSet;DEBUG;main;2007-02-15 17:28:06,279;{rset-100002}
>>> > ResultSet
>>> > java.sql.Connection;DEBUG;main;2007-02-15 17:28:06,399;{conn-100003}
>>> > Connection
>>> > java.sql.Connection;DEBUG;main;2007-02-15 17:28:06,409;{conn-100003}
>>> > Preparing Statement:   // OMITTED
>>> > java.sql.PreparedStatement;DEBUG;main;2007-02-15
>>> > 17:28:06,510;{pstm-100004} Executing Statement:   // OMITTED
>>> > java.sql.PreparedStatement;DEBUG;main;2007-02-15
>>> > 17:28:06,590;{pstm-100004} Parameters: [null, null, 0, 0]
>>> > java.sql.PreparedStatement;DEBUG;main;2007-02-15
>>> > 17:28:06,590;{pstm-100004} Types: [null, null, java.lang.Integer,
>>> > java.lang.Integer]
>>> > java.sql.ResultSet;DEBUG;main;2007-02-15 17:28:06,620;{rset-100005}
>>> > ResultSet
>>> >
>>> com.hsbc.hbfr.ccf.referentiels.ibatis.TestPatrimonyWithSpringAndIBatis;INFO;main;2007-02-15
>>> > 17:28:06,650;Rolled back transaction after test execution
>>> >
>>>
>>> It seems to obtain a new connection and preparing a new statement for
>>> each
>>> call to the DAO, is it what is expected ?
>>> --
>>> View this message in context:
>>> http://www.nabble.com/reusing-prepared-statement-tf3234702.html#a8988671
>>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>>
>>>
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/reusing-prepared-statement-tf3234702.html#a9039749
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Mime
View raw message