You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Shawn Smiley <ss...@yahoo.com> on 2006/01/10 22:28:33 UTC

Best way to handle large transactions?

 I have a data import routine that needs to do approximately 500 or so inserts/updates across 6 tables in a SQL Server database within a single transaction (all succeed or all fail).

What is the best way to handle this in iBatis?

This is an ASP.net 1.1 application and I have a 1:1 mapping between iBatis DAL objects and tables in the database.

Related to the above, are there any good examples out there on how to properly do transactions with iBatis?


Roughly what I have for code (not currently using a transaction) is something like this (psudocode):
Visit TargetVisit = Visit.Find(1234);
TargetVisit.Status = VisitStatuses.Completed;
TargetVisit.Save();

foreach (collection of students){
    Student AStudent = Student.Find(someid);
    AStudent.Active = true;
    AStudent.Save();
    foreach (collection of data) {
        TopicSection ts = new TopicSection();
        ts.Property1 = "some value";
        ts.Property2 = "some value";
        ts.Save();

        ... This continues down 3 more tables...
    }
}


Thanks for any suggestions on the best way to put this into a single transaction.

-Shawn


		
---------------------------------
Yahoo! Photos – Showcase holiday pictures in hardcover
 Photo Books. You design it and we’ll bind it!

Re: Best way to handle large transactions?

Posted by Ron Grabowski <ro...@yahoo.com>.
IBatisNet.DataMapper.Mapper.Instance().BeginTransaction();
try
{
foreach (collection of students){
    Student AStudent = Student.Find(someid);
    AStudent.Active = true;
    AStudent.Save();
    foreach (collection of data) {
       TopicSection ts = new TopicSection();
       ts.Property1 = "some value";
       ts.Property2 = "some value";
       ts.Save();
    }
}
IBatisNet.DataMapper.Mapper.Instance().CommitTransaction();
}
catch
{
IBatisNet.DataMapper.Mapper.Instance().RollBackTransaction();
throw;
}

----- Original Message ----
From: Shawn Smiley <ss...@yahoo.com>
To: iBatis Users <us...@ibatis.apache.org>
Sent: Tuesday, January 10, 2006 4:28:33 PM
Subject: Best way to handle large transactions?


 I have a data import routine that needs to do approximately 500 or so inserts/updates across 6 tables in a SQL Server database within a single transaction (all succeed or all fail).

What is the best way to handle this in iBatis?

This is an ASP.net 1.1 application and I have a 1:1 mapping between iBatis DAL objects and tables in the database.

Related to the above, are there any good examples out there on how to properly do transactions with iBatis?


Roughly what I have for code (not currently using a transaction) is something like this (psudocode):
Visit TargetVisit = Visit.Find(1234);
TargetVisit.Status = VisitStatuses.Completed;
TargetVisit.Save();

foreach (collection of students){
    Student AStudent = Student.Find(someid);
    AStudent.Active = true;
    AStudent.Save();
    foreach (collection of data) {
       TopicSection ts = new TopicSection();
       ts.Property1 = "some value";
       ts.Property2 = "some value";
       ts.Save();

       ... This continues down 3 more tables...
    }
}


Thanks for any suggestions on the best way to put this into a single transaction.

-Shawn



Yahoo! Photos Showcase holiday pictures in hardcover
Photo Books. You design it and well bind it!