views:

260

answers:

5

I store file’s attributes (size, update time…) in database. So the problem is how to manage transaction for database and file.

In jee environment, JTA is just able to manage database transaction. In case, updating database is successful but file operation fails, should I write file-rollback method for this? Moreover, file operation in EJB container violates EJB spec.

What’s your opinion? Thank!

+1  A: 

manually. You'll probably need to write compensatory transactions for this.

Ryan Fernandes
A: 

That means I should backup the original files for rollback function before modifying files...

卢声远 Shengyuan Lu
This doesn't look like an answer to your own question. Either edit your question, or comment the answers directly. (Answers with similar vote count are displayed in random order, it's not a forum thread)
ewernli
A: 

Maybe have a look at commons-transaction for transactional file access. Refer to:

In any case, you'll have to write files outside the EJB container or to interact with a JCA connector as pointed out by @ewernli.

Pascal Thivent
+1  A: 

Access to external resources such as a file system should ideally go through a JCA connector. Though there are several posts around discussing this, I never found a ready-to-use JCA connector for transactional access to the file system, so I started to write one:

Regarding other projects:

Note that as soon as you have more than one transactional participant, the app. server really need to use distributed transaction and things get more complicated. You must not underestimate this complexity (e.g. database have another timeout mechanism for distributed transaction).

Another lightweight approach to consider is to use a SFSB that writes on the file system. If you implement SessionSynchronization interface, you get beforeCompletion and afterCompletion callbacks. The later indicates whether the transaction was committed or rolled back and you do cleanup if necessary. You can then implement a transactional behavior.

ewernli
+1  A: 

Hello,

Recently, I have been working on a project that can hopefully match the requirement posted

above. This project, called XADisk, is hosted on an open source community (java.net) as

https://xadisk.dev.java.net/.

Thanks, Nitin.

Nitin Verma
+1 I had never heard of this one. That's good to know.
ewernli