Framework Professional Edition Package


org.mbs.services.transaction.file
Class FileTransactionResource

java.lang.Object
  extended by org.mbs.services.transaction.file.FileTransactionResource
All Implemented Interfaces:
TransactionResource

public abstract class FileTransactionResource
extends java.lang.Object
implements TransactionResource

The FileTransactionResource is an utility class, that is used by resources that deals with files. Before performing a file operation, the caller should mark the file with the correct operation. The marked files will be correctly restored on rollback. However, this requires that the extending class calls the mark() method before any file operation, and calls the super commit() and rollback() methods. Notice, that this implementation is not thread-safe and if the developer performs operation though different threads, should also synchronize the calls.

Author:
Valentin Valchev

Field Summary
static int FILE_CREATE
          Marks the file is newly (or will be) created.
static int FILE_CREATE_TEMP
          Marks that a newly temporary file is/will be created.
static int FILE_MODIFY
          Marks the file as being modified, this takes a snapshot of the file, that is restored on rollback.
static int FILE_REMOVE
          Not only marks the file as removed, but also deletes it.
static java.lang.String FILE_TRANSACTION_PROP
          Use this system property to replace the default FileTransaction implementation.
protected  TransactionManager transactionManager
          This is the transaction manager instance.
 
Constructor Summary
FileTransactionResource()
           
 
Method Summary
 void commit(TransactionContext transaction)
          Commit all the changes associated with the given transaction.
protected  void mark(int operation, java.io.File file)
          Marks a file, that operation is being performed on it.
protected  FileTransaction newFileTransaction()
          Override this method in order to use different implementation of FileTransaciton.
 void rollback(TransactionContext transaction)
          Undo all the changes made to this subsystem that are associated with the given transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.mbs.services.transaction.TransactionResource
prepare
 

Field Detail

FILE_TRANSACTION_PROP

public static final java.lang.String FILE_TRANSACTION_PROP
Use this system property to replace the default FileTransaction implementation. The name of the property is "mbs.transactions.file.impl.class".

See Also:
Constant Field Values

FILE_REMOVE

public static final int FILE_REMOVE
Not only marks the file as removed, but also deletes it. On rollback, the previous content of the file will be restored.

See Also:
Constant Field Values

FILE_CREATE

public static final int FILE_CREATE
Marks the file is newly (or will be) created. On rollback, the file will be deleted.

See Also:
Constant Field Values

FILE_CREATE_TEMP

public static final int FILE_CREATE_TEMP
Marks that a newly temporary file is/will be created. The temporary files are deleted on commit and rollback.

See Also:
Constant Field Values

FILE_MODIFY

public static final int FILE_MODIFY
Marks the file as being modified, this takes a snapshot of the file, that is restored on rollback.

See Also:
Constant Field Values

transactionManager

protected TransactionManager transactionManager
This is the transaction manager instance. DON'T FORGET to initialize it or the service will not work correctly.

Constructor Detail

FileTransactionResource

public FileTransactionResource()
Method Detail

commit

public void commit(TransactionContext transaction)
Description copied from interface: TransactionResource
Commit all the changes associated with the given transaction.

Specified by:
commit in interface TransactionResource
See Also:
TransactionResource.commit(org.mbs.services.transaction.TransactionContext)

rollback

public void rollback(TransactionContext transaction)
Description copied from interface: TransactionResource
Undo all the changes made to this subsystem that are associated with the given transaction. The method may be called on another thread than the one associated with the transaction object.

Specified by:
rollback in interface TransactionResource
Parameters:
transaction - The associated transaction.
See Also:
TransactionResource.rollback(org.mbs.services.transaction.TransactionContext)

mark

protected void mark(int operation,
                    java.io.File file)
             throws java.io.IOException
Marks a file, that operation is being performed on it.

Parameters:
operation - the operation that will be performed on the file.
file - the file itself.
Throws:
java.io.IOException - on I/O error

newFileTransaction

protected FileTransaction newFileTransaction()
Override this method in order to use different implementation of FileTransaciton. This method by default will try to use reflection to instantiate the FileTransaction implementation, if the FILE_TRANSACTION_PROP system property is set. Otherwise the default FileTransactionPlain implementation is used.

Returns:
the implementation of the FileTransaction proxy.

Framework Professional Edition Package


Copyright © 1999-2007 ProSyst Software GmbH. All Rights Reserved