Package org.xwiki.store
Class FileDeleteTransactionRunnable
- java.lang.Object
-
- org.xwiki.store.TransactionRunnable<R>
-
- org.xwiki.store.ProvidingTransactionRunnable<T,T>
-
- org.xwiki.store.StartableTransactionRunnable<TransactionRunnable>
-
- org.xwiki.store.FileDeleteTransactionRunnable
-
public class FileDeleteTransactionRunnable extends StartableTransactionRunnable<TransactionRunnable>
A TransactionRunnable for deleting 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: e57fe7e5a1eee5d6734ee4ede2c2070407b0e98a $
-
-
Constructor Summary
Constructors Constructor Description FileDeleteTransactionRunnable(File toDelete, File backupFile, ReadWriteLock lock)The Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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, onCommit, preRun, rollback, run, runIn
-
-
-
-
Constructor Detail
-
FileDeleteTransactionRunnable
public FileDeleteTransactionRunnable(File toDelete, File backupFile, ReadWriteLock lock)
The Constructor.- Parameters:
toDelete- the file to delete.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 toDelete 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.
-
-
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.onPreRun()
-
onRun
protected void onRun() throws IOException- Overrides:
onRunin classTransactionRunnable<TransactionRunnable>- Throws:
IOException
-
onRollback
protected void onRollback()
There are a few possibilities. If preRun() has not completed then there may be an old backup from a previous delete, anyway if preRun() has not completed then we know there is nothing to rollback. Otherwise:
- There is a backup file but no main file, it has been renamed, rename it back to the main location.
- There is a main file and no backup. Nothing has probably happened, do nothing to rollback.
- There are neither backup nor main files, this means we tried to delete a file which didn't exist to begin with.
- There are both main and backup files. AAAAAaaa what do we do?! Throw an exception which will be reported.
- Overrides:
onRollbackin classTransactionRunnable<TransactionRunnable>- See Also:
TransactionRunnable.onRollback()
-
onComplete
protected void onComplete() throws IOExceptionOnce this is called, there is no going back. Remove backup file and unlock the lock.
- Overrides:
onCompletein classTransactionRunnable<TransactionRunnable>- Throws:
IOException- See Also:
TransactionRunnable.onComplete()
-
-