PDA

View Full Version : Implementing transaction around files storing service



plissken
Jan 26th, 2010, 02:58 AM
Hi,
I'd like to implement a service to store files on mass storage. Let's see some code sample as follow:


class Something implements StoreBean {
// bla bla bla some attributes
private String path;
// getters and setters of course bla bla bla
}

interface StoreBean {
public String getPath();
}


What is a idea ? Shortly... service implementing declarative transactions should save 'Something' object to database, save some file indicated by 'path' attribute on disk, and ... if db transaction fails, some transactionmanager should delete file from disk. I need some advices, what is a best solution to above scenario ??

Regards

Tom

eran_ha
Jan 28th, 2010, 01:35 AM
Apache Commons Transactions has some implementation for that, which I used in the past for a Transactional-In-Mem-Data-Structure. Not sure about the project state, but I see it moved from sandbox to the main projects :D

See http://commons.apache.org/transaction/

I'm sure there are also many more ready to use open source projects out there that can save you the trouble of having to reinvent the wheel...

nitin_verma
Feb 11th, 2012, 12:03 PM
Hi,

Using XA transactions you can combine operations across multiple resources in a single global transaction. This would guarantee that either all of the operations commit or none of them commit. You need to configure your database's data-source to enable XA with database. As file-systems do not support XA, you can use XADisk (http://xadisk.java.net/) to perform the file operations inside XA transactions.

Hope that helps.

Thanks,
Nitin