Class IndirectFileCreateFileTransaction

java.lang.Object
de.uplanet.util.transaction.AbstractTwoPhaseIOTransaction
de.uplanet.util.transaction.IndirectFileCreateFileTransaction
All Implemented Interfaces:
ITwoPhaseIOTransaction, ITwoPhaseTransaction

public final class IndirectFileCreateFileTransaction extends AbstractTwoPhaseIOTransaction
The IO operation not done before commit is called by the transaction manager Transaction object for creating a new file. On rollback and commit the given source file will always deleted.
  • Constructor Details

    • IndirectFileCreateFileTransaction

      public IndirectFileCreateFileTransaction(File p_fileDst, File p_fileSrc, boolean p_bOverwriteExisting) throws IOException
      Parameters:
      p_fileDst - The destination file.
      p_fileSrc - The file used for create (must be a temporary file, because it will always be deleted after rollback or commit).
      p_bOverwriteExisting - true if an existing file should be overwritten, or false otherwise.
      Throws:
      IOException - If p_fileDst or p_fileSrc is not a file.
  • Method Details

    • commit

      public void commit()
      Description copied from interface: ITwoPhaseTransaction
      Commit the transaction.
      Specified by:
      commit in interface ITwoPhaseTransaction
    • rollback

      public boolean rollback()
      Try to rollback the file transaction.
      Specified by:
      rollback in interface ITwoPhaseTransaction
      Returns:
      true if the rollback was successful, or false otherwise. In the latter case ITwoPhaseTransaction.getLastError() may give additional information about why the rollback failed, and a backup file may exist then.
    • requestCommit

      public boolean requestCommit()
      Description copied from interface: ITwoPhaseTransaction
      Request a file system transaction.

      When this method returns true it has sucessfully moved the source file to it's new location, and has successfully created a backup copy of the destination file, if it existed before.

      Specified by:
      requestCommit in interface ITwoPhaseTransaction
    • getDestinationFile

      public final File getDestinationFile()
      Get the destination file.
      Returns:
      The value p_fileDst that was passed to the contructor.
    • getSourceFile

      public final File getSourceFile()
      Get the source file.
      Returns:
      The value p_fileSrc that was passed to the contructor.
    • hasBackup

      public final boolean hasBackup()
      Returns:
      true if the transaction has left a backup file, or false otherwise (e.g. if the destination file did not exist before the transaction).
    • getBackup

      public final File getBackup()
      Returns:
      The backup file that was left by the transaction, or null if none was created (e.g. if the destination file did not exist before the transaction).
    • getLastError

      public final Throwable getLastError()
      Returns:
      The last exception that was caugth during the transaction, or null if no error occurred;
    • toString

      public String toString()
      Overrides:
      toString in class Object