fr.dyade.aaa.util
Class AbstractTransaction

java.lang.Object
  extended by fr.dyade.aaa.util.AbstractTransaction
All Implemented Interfaces:
Transaction
Direct Known Subclasses:
ATransaction, DBTransaction, NGTransaction, NTransaction

public abstract class AbstractTransaction
extends java.lang.Object
implements Transaction

The AbstractTransaction class implements the common part of the Transaction Transaction interface. A transaction implementation only needs to define several methods: saveInLog, loadByteArray, delete and commit.

See Also:
Transaction

Nested Class Summary
 class AbstractTransaction.Context
           
 
Field Summary
protected  java.io.File dir
           
protected static org.objectweb.util.monolog.api.Logger logmon
           
protected static byte[] OOS_STREAM_HEADER
          The OOS_STREAM_HEADER allows to reset an ObjectOutputStream built on top of a ByteArrayOutputStream.
protected  java.lang.ThreadLocal perThreadContext
          ThreadLocal variable used to get the log to associate state with each thread.
protected  int phase
           
protected  long startTime
           
 
Fields inherited from interface fr.dyade.aaa.util.Transaction
COMMIT, FINALIZE, FREE, GARBAGE, INIT, Kb, Mb, PhaseInfo, ROLLBACK, RUN
 
Constructor Summary
AbstractTransaction()
           
 
Method Summary
 void begin()
          Start a transaction validation, the validation phase needs 3 phases: begin, commit and release.
 void create(java.io.Serializable obj, java.lang.String name)
          Register the state of a newly created object in the current transaction.
 void create(java.io.Serializable obj, java.lang.String dirName, java.lang.String name)
          Register the state of a newly created object in the current transaction.
 void createByteArray(byte[] buf, java.lang.String name)
          Register a new byte array in the current transaction.
 void createByteArray(byte[] buf, java.lang.String dirName, java.lang.String name)
          Register a new byte array in the current transaction.
 void delete(java.lang.String name)
          Deletes the specified object.
 int getPhase()
          Returns the transaction state.
 java.lang.String getPhaseInfo()
          Returns a string representation of the transaction state.
 long getStartTime()
          Returns the starting time.
 void init(java.lang.String path)
          Initializes the atomic storage component.
abstract  void initRepository()
           
 java.lang.Object load(java.lang.String name)
          Load the specified object.
 java.lang.Object load(java.lang.String dirName, java.lang.String name)
          Load the specified object.
 byte[] loadByteArray(java.lang.String name)
          Load the specified byte array.
 void release()
          Release the mutual exclusion.
 void save(java.io.Serializable obj, java.lang.String name)
          Register the modified state of an object in the current transaction.
 void save(java.io.Serializable obj, java.lang.String dirName, java.lang.String name)
          Register the modified state of an object in the current transaction.
 void save(java.io.Serializable obj, java.lang.String dirName, java.lang.String name, boolean first)
          Register the state of an object in the current transaction.
 void saveByteArray(byte[] buf, java.lang.String name)
          Register a modified byte array in the current transaction.
 void saveByteArray(byte[] buf, java.lang.String dirName, java.lang.String name)
          Register a modified byte array in the current transaction.
 void saveByteArray(byte[] buf, java.lang.String dirName, java.lang.String name, boolean copy, boolean first)
          Register a modified byte array in the current transaction.
protected abstract  void saveInLog(byte[] buf, java.lang.String dirName, java.lang.String name, java.util.Hashtable log, boolean copy, boolean first)
          Register the specified object in transaction log.
protected abstract  void setPhase(int newPhase)
          Changes the transaction state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface fr.dyade.aaa.util.Transaction
close, commit, delete, getList, isPersistent, loadByteArray, stop
 

Field Detail

logmon

protected static org.objectweb.util.monolog.api.Logger logmon

startTime

protected long startTime

phase

protected int phase

dir

protected java.io.File dir

perThreadContext

protected java.lang.ThreadLocal perThreadContext
ThreadLocal variable used to get the log to associate state with each thread. The log contains all operations do by the current thread since the last commit. On commit, its content is added to current log (clog, memory + disk), then it is freed.


OOS_STREAM_HEADER

protected static final byte[] OOS_STREAM_HEADER
The OOS_STREAM_HEADER allows to reset an ObjectOutputStream built on top of a ByteArrayOutputStream.

Constructor Detail

AbstractTransaction

public AbstractTransaction()
Method Detail

getStartTime

public long getStartTime()
Returns the starting time.

Returns:
The starting time.

getPhase

public final int getPhase()
Returns the transaction state.

Specified by:
getPhase in interface Transaction
Returns:
the transaction state.
See Also:
Transaction.getPhase()

getPhaseInfo

public final java.lang.String getPhaseInfo()
Returns a string representation of the transaction state.

Specified by:
getPhaseInfo in interface Transaction
Returns:
the string representation of the transaction state.
See Also:
Transaction.getPhaseInfo()

setPhase

protected abstract void setPhase(int newPhase)
                          throws java.io.IOException
Changes the transaction state.

Parameters:
newPhase - the new transaction state.
Throws:
java.io.IOException

initRepository

public abstract void initRepository()
                             throws java.io.IOException
Throws:
java.io.IOException

init

public final void init(java.lang.String path)
                throws java.io.IOException
Description copied from interface: Transaction
Initializes the atomic storage component.

Specified by:
init in interface Transaction
Throws:
java.io.IOException

begin

public final void begin()
                 throws java.io.IOException
Start a transaction validation, the validation phase needs 3 phases: begin, commit and release. The begin ensure the mutual exclusion of the current transaction.

Specified by:
begin in interface Transaction
Throws:
java.io.IOException
See Also:
Transaction.begin()

create

public final void create(java.io.Serializable obj,
                         java.lang.String name)
                  throws java.io.IOException
Register the state of a newly created object in the current transaction.

Specified by:
create in interface Transaction
Parameters:
obj - the object to store.
name - the name of the object.
Throws:
java.io.IOException
See Also:
Transaction.create(java.io.Serializable, java.lang.String)

create

public final void create(java.io.Serializable obj,
                         java.lang.String dirName,
                         java.lang.String name)
                  throws java.io.IOException
Register the state of a newly created object in the current transaction.

Specified by:
create in interface Transaction
Parameters:
obj - the object to store.
dirName - the directory name of the object.
name - the name of the object.
Throws:
java.io.IOException
See Also:
Transaction.create(java.io.Serializable, java.lang.String, java.lang.String)

save

public final void save(java.io.Serializable obj,
                       java.lang.String name)
                throws java.io.IOException
Register the modified state of an object in the current transaction.

Specified by:
save in interface Transaction
Parameters:
obj - the object to store.
name - the name of the object.
Throws:
java.io.IOException
See Also:
Transaction.save(java.io.Serializable, java.lang.String)

save

public final void save(java.io.Serializable obj,
                       java.lang.String dirName,
                       java.lang.String name)
                throws java.io.IOException
Register the modified state of an object in the current transaction.

Specified by:
save in interface Transaction
Parameters:
obj - the object to store.
dirName - the directory name of the object.
name - the name of the object.
Throws:
java.io.IOException
See Also:
Transaction.save(java.io.Serializable, java.lang.String, java.lang.String)

save

public final void save(java.io.Serializable obj,
                       java.lang.String dirName,
                       java.lang.String name,
                       boolean first)
                throws java.io.IOException
Register the state of an object in the current transaction.

Specified by:
save in interface Transaction
Parameters:
obj - the object to store.
dirName - the directory name of the object.
name - the name of the object.
first - the object is a new one.
Throws:
java.io.IOException
See Also:
Transaction.save(java.io.Serializable, java.lang.String, java.lang.String, boolean)

createByteArray

public final void createByteArray(byte[] buf,
                                  java.lang.String name)
                           throws java.io.IOException
Register a new byte array in the current transaction.

Specified by:
createByteArray in interface Transaction
Parameters:
buf - the byte array to store.
name - the name of the object.
Throws:
java.io.IOException
See Also:
Transaction.createByteArray(byte[], java.lang.String)

createByteArray

public final void createByteArray(byte[] buf,
                                  java.lang.String dirName,
                                  java.lang.String name)
                           throws java.io.IOException
Register a new byte array in the current transaction.

Specified by:
createByteArray in interface Transaction
Parameters:
buf - the byte array to store.
dirName - the directory name of the object.
name - the name of the object.
Throws:
java.io.IOException
See Also:
Transaction.createByteArray(byte[], java.lang.String, java.lang.String)

saveByteArray

public final void saveByteArray(byte[] buf,
                                java.lang.String name)
                         throws java.io.IOException
Register a modified byte array in the current transaction.

Specified by:
saveByteArray in interface Transaction
Parameters:
buf - the byte array to store.
name - the name of the object.
Throws:
java.io.IOException
See Also:
Transaction.saveByteArray(byte[], java.lang.String)

saveByteArray

public final void saveByteArray(byte[] buf,
                                java.lang.String dirName,
                                java.lang.String name)
                         throws java.io.IOException
Register a modified byte array in the current transaction.

Specified by:
saveByteArray in interface Transaction
Parameters:
buf - the byte array to store.
dirName - the directory name of the object.
name - the name of the object.
Throws:
java.io.IOException
See Also:
Transaction.saveByteArray(byte[], java.lang.String, java.lang.String)

saveByteArray

public final void saveByteArray(byte[] buf,
                                java.lang.String dirName,
                                java.lang.String name,
                                boolean copy,
                                boolean first)
                         throws java.io.IOException
Register a modified byte array in the current transaction.

Specified by:
saveByteArray in interface Transaction
Parameters:
buf - the byte array to store.
dirName - the directory name of the object.
name - the name of the object.
copy - the byte array can be modified, copy it.
first - the object is a new one.
Throws:
java.io.IOException
See Also:
Transaction.saveByteArray(byte[], java.lang.String, java.lang.String, boolean, boolean)

saveInLog

protected abstract void saveInLog(byte[] buf,
                                  java.lang.String dirName,
                                  java.lang.String name,
                                  java.util.Hashtable log,
                                  boolean copy,
                                  boolean first)
                           throws java.io.IOException
Register the specified object in transaction log.

Parameters:
buf - the byte array containing the state of the object.
dirName - the directory name of the object.
name - the name of the object.
log - the log to use.
copy - the byte array can be modified, copy it.
first - the object is a new one.
Throws:
java.io.IOException

load

public final java.lang.Object load(java.lang.String name)
                            throws java.io.IOException,
                                   java.lang.ClassNotFoundException
Load the specified object.

Specified by:
load in interface Transaction
Parameters:
name - the name of the object.
Returns:
the loaded object.
Throws:
java.io.IOException
java.lang.ClassNotFoundException
See Also:
Transaction.load(java.lang.String)

load

public final java.lang.Object load(java.lang.String dirName,
                                   java.lang.String name)
                            throws java.io.IOException,
                                   java.lang.ClassNotFoundException
Load the specified object.

Specified by:
load in interface Transaction
Parameters:
dirName - the directory name of the object.
name - the name of the object.
Returns:
the loaded object.
Throws:
java.io.IOException
java.lang.ClassNotFoundException
See Also:
Transaction.load(java.lang.String, java.lang.String)

loadByteArray

public final byte[] loadByteArray(java.lang.String name)
                           throws java.io.IOException
Load the specified byte array.

Specified by:
loadByteArray in interface Transaction
Parameters:
name - the name of the object.
Returns:
the loaded byte array.
Throws:
java.io.IOException
See Also:
Transaction.loadByteArray(java.lang.String)

delete

public final void delete(java.lang.String name)
Deletes the specified object.

Specified by:
delete in interface Transaction
Parameters:
name - the name of the object.
See Also:
Transaction.delete(java.lang.String)

release

public void release()
             throws java.io.IOException
Release the mutual exclusion.

Specified by:
release in interface Transaction
Throws:
java.io.IOException
See Also:
Transaction.release()


Copyright © 2011 ScalAgent D.T.. All Rights Reserved.