ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Meadors" <lmead...@apache.org>
Subject Re: reusing prepared statement
Date Thu, 15 Feb 2007 16:45:14 GMT
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.
>
>

Mime
View raw message