Generally, the answer is YES. SqlMapper stores the Session (the IBatisNet abstraction of connection/transaction) variable in the context of a thread and the context is not shared between threads. See the ISessionStore interface and its implementation classes for more detals.
yours smartkid 2009/1/30 MaaKut <ma...@pochta.ru> > > I've got one more question concerning transactions and thead-safety. > Say, I have Thread #1 running code like this: > > ISqlMapper sqlMapper = ... // Get a singleton instance of ISqlMapper > sqlMapper.BeginTransaction(); > try > { > sqlMapper.Update(entity1); > sqlMapper.Delete(entity2); > // and something else goes here > sqlMapper.CommitTransaction(); > } > catch > { > sqlMapper.RollbackTransaction(); > throw; > } > > While this one is running try-block, Thread #2 also gets the same > ISqlMapper > instance and, e.g., tries to insert an entity. Will this insertion > participate in transaction started by Thread #1 or SqlMapper is smart > enough > to distinguish these two? > Also, I might rewrite Thread #1 code like this: > > ISqlMapper sqlMapper = ... // Get a singleton instance of ISqlMapper > using (ISqlMapSession session = sqlMapper.BeginTransaction()) > { > sqlMapper.Update(entity1); > sqlMapper.Delete(entity2); > // and something else goes here > session.Complete(); > } > > In this case I conttol transaction via ISqlMapSession instance which seems > to be created for this particular thread only, but still I can't find part > of the doc which says that yes, code like this is thread-safe. > -- > View this message in context: > http://www.nabble.com/Caching-and-thread-safety-tp21680257p21742034.html > Sent from the iBATIS - User - Cs mailing list archive at Nabble.com. > >