Package org.xwiki.store
Class FileSaveTransactionRunnable
- java.lang.Object
-
- org.xwiki.store.TransactionRunnable<R>
-
- org.xwiki.store.ProvidingTransactionRunnable<T,T>
-
- org.xwiki.store.StartableTransactionRunnable<TransactionRunnable>
-
- org.xwiki.store.FileSaveTransactionRunnable
-
public class FileSaveTransactionRunnable extends StartableTransactionRunnable<TransactionRunnable>
A TransactionRunnable for saving a file safely. The operation can be rolled back even after the onCommit() function is called. It is only final when the onComplete function is called.- Since:
- 3.0M2
- Version:
- $Id: a1874a06e50243651cbbe8cb6f0dac32bdd85e88 $
-
-
Constructor Summary
Constructors Constructor Description FileSaveTransactionRunnable(File toSave, File tempFile, File backupFile, ReadWriteLock lock, FileSerializer serializer)The Constructor.FileSaveTransactionRunnable(File toSave, File tempFile, File backupFile, ReadWriteLock lock, StreamProvider provider)The Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidonCommit()protected voidonComplete()protected voidonPreRun()protected voidonRollback()protected voidonRun()-
Methods inherited from class org.xwiki.store.StartableTransactionRunnable
start
-
Methods inherited from class org.xwiki.store.ProvidingTransactionRunnable
asProvider, getProvidedContext
-
Methods inherited from class org.xwiki.store.TransactionRunnable
commit, complete, getContext, preRun, rollback, run, runIn
-
-
-
-
Constructor Detail
-
FileSaveTransactionRunnable
public FileSaveTransactionRunnable(File toSave, File tempFile, File backupFile, ReadWriteLock lock, StreamProvider provider)
The Constructor.- Parameters:
toSave- the file to put the content in.tempFile- a temporary file, this should not contain anything important as it will be deleted and must not be altered while the operation is running. This will contain the data until onCommit when it is renamed to the toSave file.backupFile- a temporary file, this should not contain anything important as it will be deleted and must not be altered while the operation is running. This will contain whatever was in the toSave file prior, just in case onRollback must be called.lock- a ReadWriteLock whose writeLock will be locked as the beginning of the process and unlocked when complete.provider- a StreamProvider to get the data to put into the file.
-
FileSaveTransactionRunnable
public FileSaveTransactionRunnable(File toSave, File tempFile, File backupFile, ReadWriteLock lock, FileSerializer serializer)
The Constructor.- Parameters:
toSave- the file to put the content in.tempFile- a temporary file, this should not contain anything important as it will be deleted and must not be altered while the operation is running. This will contain the data until onCommit when it is renamed to the toSave file.backupFile- a temporary file, this should not contain anything important as it will be deleted and must not be altered while the operation is running. This will contain whatever was in the toSave file prior, just in case onRollback must be called.lock- a ReadWriteLock whose writeLock will be locked as the beginning of the process and unlocked when complete.serializer- a FileSerializer in charge to serializing what need to be serialize to the file.- Since:
- 9.0RC1
-
-
Method Detail
-
onPreRun
protected void onPreRun() throws IOExceptionObtain the lock and make sure the temporary and backup files are deleted.
- Overrides:
onPreRunin classTransactionRunnable<TransactionRunnable>- Throws:
IOException- See Also:
TransactionRunnable.preRun()
-
onRun
protected void onRun() throws ExceptionWrite the data from the provider to the temporary file.
- Overrides:
onRunin classTransactionRunnable<TransactionRunnable>- Throws:
Exception- See Also:
TransactionRunnable.run()
-
onCommit
protected void onCommit()
Move whatever is in the main file location into backup and move the temp file into the main location.
- Overrides:
onCommitin classTransactionRunnable<TransactionRunnable>- See Also:
TransactionRunnable.onCommit()
-
onRollback
protected void onRollback()
- Overrides:
onRollbackin classTransactionRunnable<TransactionRunnable>
-
onComplete
protected void onComplete() throws IOExceptionOnce this is called, there is no going back. Remove temporary and backup files and unlock the lock.
- Overrides:
onCompletein classTransactionRunnable<TransactionRunnable>- Throws:
IOException- See Also:
TransactionRunnable.onComplete()
-
-