ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mitchell, Steven C" <Steven.Mitch...@umb.com>
Subject Transaction Best Practices
Date Fri, 30 Sep 2005 20:43:20 GMT
I've used iBatis on many projects now.  My latest project has run out of
Oracle connections a couple of time during testing, which has me
concerned. There did not appear to be any kind of looping going on.  I
found only one Controller method that called multiple methods that used
the same DAO.  I changed the parent method to get the DAO and pass it
into the two child methods.  

 

Now, I'm wondering if I am using Transactions as they were indented.
I've only used Transaction on updates.  Should I use them on reads to
make sure everything gets cleaned up.  Here is an example of what I do:

 

// NO TRANSACTION FOR QUERIES

 

public static Company getCompany( Integer companyId )

    throws IVRPasswordException

    { 

        try

        {

            final DaoManager daoManager =  DaoHelper.getDaoManager();

            final CompanyDao companyDao = ( CompanyDao )
daoManager.getDao( CompanyDao.class );

            return companyDao.getCompany( companyId );

        }

        catch ( Exception e )

        {

            throw new IVRPasswordException( e );

        }

    }

 

// TRANSACTION FOR ALL UPDATES/INSERTS/DELTES

 

public static void updateCompany( Company company ) throws
IVRPasswordException

    {

        DaoManager daoManager = null;

        try

        {

            daoManager = DaoHelper.getDaoManager();

            daoManager.startTransaction();

            final CompanyDao companyDao = (CompanyDao)
daoManager.getDao( CompanyDao.class );

            companyDao.updateCompany( company );

            daoManager.commitTransaction();            

        }

        catch ( Exception e )

        {

            throw new IVRPasswordException( e );

        }

        finally

        {

            if ( daoManager != null )

            {

                daoManager.endTransaction();

            }

        }

    }

 

Thoughts?

 

Steve Mitchell
Group Leader for Java Development
UMB Bank, n.a.



 


Mime
View raw message