ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From I L <iss...@hotmail.com>
Subject RE: Using Connection.commit() in place of SqlMapSession.commitTransaction(). "commitRequired" Benefit
Date Wed, 08 Apr 2009 07:29:21 GMT

To be safe, I created a commit wrapper that goes out and sets the forceCommit flag to true,
then calls commitTransaction(). I didn't feel comfortable about calling connection.commit()
directly. This allows me to selectively choose when I want to force a commit or have ibatis
check the isCommitRequired flag. My only worry left is if an instance of TransactionConfig
shared by other transactions and if so, will  changing its value effect the other transactions
as well? Or is TransactionConfig cloned for each transaction. I wouldn't mind if the other
transactions temporarily forced a commit while this one finished up but I am just curious.

    public void forceCommitWork(){
            if(sqlMapSession instanceof SqlMapSessionImpl){
                SqlMapExecutorDelegate sqlMapExecutorDelegate = ((SqlMapSessionImpl) sqlMapSession).getDelegate();
                TransactionManager transManager = sqlMapExecutorDelegate.getTxManager();
                TransactionConfig config = transManager.getConfig();
                //remember the original force commit setting
                boolean originalForceCommitSetting = config.isForceCommit();
                //temporarly change it to true
                //revert the force commit setting
                throw new TechnicalException("Expected sqlMapSession to be an instanceof SqlMapSessionImpl");
        }catch(SQLException se){
            throw new TechnicalException(se.getMessage());

From: isster@hotmail.com
To: user-java@ibatis.apache.org
Subject: Using Connection.commit() in place of SqlMapSession.commitTransaction(). "commitRequired"
Date: Wed, 8 Apr 2009 01:19:31 +0000

Hi guys,

This is a two part question.

1) Is there a significant performance pickup if you use commitRequired="false". As you know
this attribute is set to false by default. I couldn't find any information on the benefit
of keeping that field false.

2) I would like to run an sql update query using a Statement object. Its for throw away install
scripts that I do not want the sql to be in the xml files.

So if I run an sql update query using a Statement object with commitRequired="false", the
expected behavior of sqlMapSession.commitTransaction() would be to do nothing because ibatis
didn't detect the update. So what I ended up doing is the following code snippet:


  Connection connection = sqlMapSession.getCurrentConnection();
  Statement stmt = connection.createStatement()

  stmt.executeUpdate("UPDATE item SET type="NA");
  connection.commit(); //did not use sqlMapSession.commitTransaction()

Note how I used the connection's commit() instead of commitTransaction(). Is this ok? Am I
bypassing something that could be dangerous? From my testing, it shows that everything is

Thank you in advance.


Rediscover HotmailĀ®: Get quick friend updates right in your inbox. 
View raw message