org.neodatis.odb.impl.core.transaction
Class DefaultTransaction

java.lang.Object
  extended by org.neodatis.odb.impl.core.transaction.DefaultTransaction
All Implemented Interfaces:
ITransaction

public class DefaultTransaction
extends java.lang.Object
implements ITransaction

 The transaction class is used to guarantee ACID behavior. It keep tracks of all session
 operations. It uses the WriteAction class to store all changes that can not be written to the file
 before the commit.
 The transaction is held by The Session class and manage commits and rollbacks.
 
 All WriteActions are written in a transaction file to be sure to be able to commit and in case 
 of very big transaction where all WriteActions can not be stored in memory.
 

Author:
osmadja

Field Summary
 IWriteAction currentWriteAction
          The same write action is reused for successive writes
 long currentWritePositionInWA
          The position of the next write for WriteAction
 IFileSystemInterface fsi
          A file interface to the transaction file - used to read/write the file
static java.lang.String LOG_ID
          the log module name
 int numberOfWriteActions
          The number of write actions
 ISession session
          The transaction session
 
Constructor Summary
DefaultTransaction(ISession session)
          The main constructor
DefaultTransaction(ISession session, IFileSystemInterface fsiToApplyTransaction)
           
DefaultTransaction(ISession session, java.lang.String overrideTransactionName)
           
 
Method Summary
 void addWriteAction(IWriteAction writeAction)
          Adds a write action to the transaction
 void addWriteAction(IWriteAction writeAction, boolean persistWriteAcion)
          Adds a write action to the transaction
 ClassInfo buildClassInfoForCommit(ClassInfo classInfo)
          Shift all unconnected infos to connected (committed) infos
 void clear()
          clear the transaction
 void commit()
          Execute the commit process of the transaction
protected  void commitMetaModel()
          Used to commit meta model : classes This is useful when running in client server mode TODO Check this
protected  void delete()
          deletes the transaction file
 long getCreationDateTime()
           
 IFileSystemInterface getFsi()
           
 java.lang.String getName()
           
 int getNumberOfWriteActions()
           
(package private)  IBaseIdentification getParameters(boolean canWrite)
           
 IOdbList<IWriteAction> getWriteActions()
           
 void init(ISession session)
           
 boolean isArchiveLog()
           
 boolean isCommited()
           
 void loadWriteActions(boolean apply)
           
 void loadWriteActions(java.lang.String filename, boolean apply)
           
 void loadWriteActionsBackwards(java.lang.String filename, boolean apply)
           
 void manageWriteAction(long position, byte[] bytes)
          The public method to add a write action to the transaction.
protected  void persist()
           
static DefaultTransaction read(java.lang.String fileName)
           
 void reset()
          Reset the transaction
 void rollback()
           
 void setArchiveLog(boolean archiveLog)
           
 void setFsiToApplyWriteActions(IFileSystemInterface fsi)
           
 void setWritePosition(long position)
          Set the write position (position in main database file).
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG_ID

public static final java.lang.String LOG_ID
the log module name

See Also:
Constant Field Values

currentWriteAction

public IWriteAction currentWriteAction
The same write action is reused for successive writes


currentWritePositionInWA

public long currentWritePositionInWA
The position of the next write for WriteAction


numberOfWriteActions

public int numberOfWriteActions
The number of write actions


fsi

public IFileSystemInterface fsi
A file interface to the transaction file - used to read/write the file


session

public ISession session
The transaction session

Constructor Detail

DefaultTransaction

public DefaultTransaction(ISession session)
                   throws java.io.IOException
The main constructor

Parameters:
session - The transaction session
Throws:
java.io.IOException

DefaultTransaction

public DefaultTransaction(ISession session,
                          java.lang.String overrideTransactionName)
                   throws java.io.IOException
Throws:
java.io.IOException

DefaultTransaction

public DefaultTransaction(ISession session,
                          IFileSystemInterface fsiToApplyTransaction)
Method Detail

init

public void init(ISession session)

clear

public void clear()
Description copied from interface: ITransaction
clear the transaction

Specified by:
clear in interface ITransaction

reset

public void reset()
Reset the transaction

Specified by:
reset in interface ITransaction

addWriteAction

public void addWriteAction(IWriteAction writeAction)
Adds a write action to the transaction

Parameters:
writeAction - The write action to be added

addWriteAction

public void addWriteAction(IWriteAction writeAction,
                           boolean persistWriteAcion)
Adds a write action to the transaction

Parameters:
writeAction - The write action to be added
persistWriteAcion - To indicate if write action must be persisted

getName

public java.lang.String getName()
Specified by:
getName in interface ITransaction

getParameters

IBaseIdentification getParameters(boolean canWrite)

persist

protected void persist()

getWriteActions

public IOdbList<IWriteAction> getWriteActions()

getCreationDateTime

public long getCreationDateTime()

isCommited

public boolean isCommited()
Specified by:
isCommited in interface ITransaction

rollback

public void rollback()
Specified by:
rollback in interface ITransaction

commit

public void commit()
Description copied from interface: ITransaction
Execute the commit process of the transaction

Specified by:
commit in interface ITransaction

commitMetaModel

protected void commitMetaModel()
Used to commit meta model : classes This is useful when running in client server mode TODO Check this


buildClassInfoForCommit

public ClassInfo buildClassInfoForCommit(ClassInfo classInfo)
Shift all unconnected infos to connected (committed) infos

Parameters:
classInfo -
Returns:
The updated class info

read

public static DefaultTransaction read(java.lang.String fileName)
                               throws java.io.IOException,
                                      java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

loadWriteActions

public void loadWriteActions(boolean apply)

loadWriteActions

public void loadWriteActions(java.lang.String filename,
                             boolean apply)

loadWriteActionsBackwards

public void loadWriteActionsBackwards(java.lang.String filename,
                                      boolean apply)
                               throws java.io.IOException,
                                      java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

delete

protected void delete()
deletes the transaction file

Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setFsiToApplyWriteActions

public void setFsiToApplyWriteActions(IFileSystemInterface fsi)
Specified by:
setFsiToApplyWriteActions in interface ITransaction

isArchiveLog

public boolean isArchiveLog()
Specified by:
isArchiveLog in interface ITransaction
Returns:
Returns the archiveLog.

setArchiveLog

public void setArchiveLog(boolean archiveLog)
Specified by:
setArchiveLog in interface ITransaction
Parameters:
archiveLog - The archiveLog to set.

getNumberOfWriteActions

public int getNumberOfWriteActions()
Specified by:
getNumberOfWriteActions in interface ITransaction
Returns:
Returns the numberOfWriteActions.

getFsi

public IFileSystemInterface getFsi()
                            throws java.io.IOException
Throws:
java.io.IOException

setWritePosition

public void setWritePosition(long position)
Set the write position (position in main database file). This is used to know if the next write can be appended to the previous one (in the same current Write Action) or not.

Specified by:
setWritePosition in interface ITransaction
Parameters:
position -

manageWriteAction

public void manageWriteAction(long position,
                              byte[] bytes)
Description copied from interface: ITransaction
The public method to add a write action to the transaction. If first checks if the new write action action can be appended to the current write action. It is done by checking the currentWritePositioninWA. If yes (position==currentPositioninWA, just append the WA. If not, adds the current one to the transaction and creates a new one (as current)

Specified by:
manageWriteAction in interface ITransaction