0

I've been using Spring framework and MySQL database in my project and I have problems to manage change both into database and files system. Until now I managed, for each transaction, only one operation for database and file so I developed them manually with try- catch but now I have some method with several operations. For example I should:

  1. Rename a lot of files in different folders and rename even archive files (unzip-rename-zip)
  2. Change some database fields

If one of the above activities fails then I have to rollback all the operations, so give to the files the original name and restore database values. I read about Apache commons-transactions but there isn't a useful documentation, is it a good choise for my requirements? Reading this article I thought to create a FileResourceManager singleton and call start and id from the other classes. But does it manage my unzip-rename-zip procedure? Otherwise I have to create a backup of folders and replace all in case of error. Thanks

luca
  • 3,248
  • 10
  • 66
  • 145
  • While individual transactions on most filesystems are transactional (a rename either succeeds or not, and consistency is guaranteed in case of power failure), multiple changes cannot be done as a transaction like you can do for databases. Some filesystems may support transactions, but it is uncommon (so no standard API). It is something left to databases. – john16384 Mar 27 '17 at 11:33
  • so is it impossible to create a rollback for both file system and database? – luca Mar 30 '17 at 10:10
  • Most filesystems don't support transactions like this, so yes, it is not possible since one of the components does not support it at all. You'd have to build something on top of a filesystem that cleans up the changes in case of a rollback. I'm not aware of any framework that supports this out of the box. – john16384 Mar 30 '17 at 12:00

0 Answers0