Hi,
I just wanted to know if anyone new how to make an object transactional. For example if I wanted to write a sequence of three strings to a file and if any of them failed the whole lot would be rolled back.
e.g.
UserTransaction tx = getUserTransaction();
try{
tx.begin();
MyTransFileWriter mtf = new MyTransFileWriter();
mtf.insert(s1);
mtf.insert(s2);
mtf.insert(s3);
tx.commit();
}catch(Exception e){
tx.rollback();
}
Any resources on this would be appreciated.
Cheers
Ben
-
Building Transactional Classes (2 messages)
- Posted by: ben storey
- Posted on: March 14 2006 13:01 EST
Threaded Messages (2)
- Building Transactional Classes by Majid Kalkatechi on March 15 2006 02:01 EST
- Building Transactional Classes by Gideon Low on March 15 2006 11:28 EST
-
Building Transactional Classes[ Go to top ]
- Posted by: Majid Kalkatechi
- Posted on: March 15 2006 02:01 EST
- in response to ben storey
To put Three String in a file, if your Strings are smaller than the Stream's BufferSize, then changes will affect after calling the close method of the Stream. Otherwise you can read the file after writing your Strings and if you found some of them has failed, then you can remove others from the file. -
Building Transactional Classes[ Go to top ]
- Posted by: Gideon Low
- Posted on: March 15 2006 11:28 EST
- in response to ben storey
Ben,
Have you considered using a Distributed Caching product in your architecture? Products such as GemFire give you:
1. Transactional Semantics accross multiple updates into the cache. These could easily be the String objects in your example below.
2. Fast file persistence or redundant memory-copies (or both), including the handling of rollbacks if some component of the transaction fails.
Finally, if you ever want to switch the persistence method from a file to a database, you would simply implement a CacheWriter callback with the necessary logic and without the need for any changes the business logic code.
Cheers,
Gideon
GemFire-The Enterprise Data Fabric
http://www.gemstone.com