Hi Nicholas

Thanks a lot for the details!

I tried most of what you said in your mail. However, I need to inject my own 
connection, transaction, and command objects as I'd be using the same 
connection for some legacy transactions as well. The CustomDaoSession that I 
created do have all methods to control a transaction, but it doesn't allow you 
to inject a Connection object for example.

On further analysis, I feel that I need to have my own implementation of 
ISqlMapper coz this is what IBatis internally uses for getting a new Connection 
for example. Now, my problem is that I don't know what's the best way to inject 
it in. Possible ways:

1. it would have been best if I could have extended the existing SqlMapper and 
overridden some properties like Connection and Transaction (again these are not 
virtual!!).

2. Use façade pattern, and create a wrapper around the existing SqlMap object 
passed to the custom session :-(

Is there any other approach that saves me re-writing a whole bunch of code?

Thanks for your time,
Gul


-----Original Message-----
From: Nicholas L. Piasecki [mailto:[EMAIL PROTECTED]
Sent: Friday, September 26, 2008 12:01 PM
To: [email protected]
Subject: RE: External transaction management

We use our own session handler, at least, which we did to inject some extra
information using SET CONTEXT_INFO at the start of a transaction.

The short version: Make your config file point to a custom session handler.
Make a custom session handler to return your custom session.

The long version:

First, in our DaoConfig.xml file, we tell iBATIS that we want to use our own
session handler in Foo.Bar.DLL:

<!-- Let's use our own DAO session handler for database auditing purposes
-->
<daoSessionHandlers>
        <handler id="UndiesDaoSessionHandler"
implementation="Foo.Bar.SkiviezSqlMapDaoSessionHandler, Foo.Bar" />
</daoSessionHandlers>

SkiviezSqlMapDaoSessionHandler.cs implements the IDaoSessionHandler
interface, returning our SkiviezSqlMapDaoSession class. For the Configure()
method, I just copied the code from the same method in
SqlMapDaoSessionHandler.cs in the iBATIS source. (Why aren't these methods
virtual?!)

SkiviezSqlMapDaoSession.cs inherits from SqlMapDaoSession. By overriding the
methods here (like BeginTransaction(), etc.), we can control all aspects of
the transactions that iBATIS uses with the data source.

Hope this helps.

V/R,
Nicholas Piasecki

Software Developer
Skiviez, Inc.
[EMAIL PROTECTED]
804-550-9406

From: Gulsharan Goraya [mailto:[EMAIL PROTECTED]
Sent: Friday, September 26, 2008 12:25 PM
To: '[email protected]'
Subject: External transaction management

Hi All

I am trying to integrate IBatis.Net with one of our legacy applications.
Now, the problem is that I need to do it one domain object at a time. So,
for that I need to integrate our current transaction management system with
IBatis.

I tried using a custom DaoSessionHandler. However, it's still using the
datasource as defined in Dao.config. Could someone highlight as to what all
IBatis classes/interfaces I need override/implement in order to make IBatis
use my custom transaction, session, command, datasource etc.

Really looking forward to you guys for some help.

Thanks,
Gul




Reply via email to