Coordinated save in database and disk in java
In my task I need to save file on disk and update info about in database. Exception can happen when saving file and when updating info in database. Do exist some ready open source solutions for it or it need write from scratch? Thanks.
There's XADisk which provides transactional access to file systems. From their web site:
XADisk (pronounced 'x-a-disk') enables transactional access to existing file systems by providing APIs to perform file/directory operations. With simple steps, it can be deployed over any JVM and can then start serving all kinds of Java/JavaEE application running anywhere.
In Java, enterprise transactions management is ruled by the JTA spec wich is used in Java EE.
JTA allows to create several TransactionManager with differents implementations (one for database, one for file) and make them work together to define a cross-transaction I think this could be a way for you to do what you want
Look at this blog post for more information about Spring and transactions usage
The file system isn't directly supported by Java EE, but you could implement/ search for a resource adapter for the file system.