org.neodatis.odb.impl.core.transaction
Class DefaultTransaction
- java.lang.Object
-
- 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.
-
-
Field Summary
Fields Modifier and Type Field and Description IWriteActioncurrentWriteActionThe same write action is reused for successive writeslongcurrentWritePositionInWAThe position of the next write for WriteActionIFileSystemInterfacefsiA file interface to the transaction file - used to read/write the filestatic java.lang.StringLOG_IDthe log module nameintnumberOfWriteActionsThe number of write actionsISessionsessionThe transaction session
-
Constructor Summary
Constructors Constructor and Description DefaultTransaction(ISession session)The main constructorDefaultTransaction(ISession session, IFileSystemInterface fsiToApplyTransaction)DefaultTransaction(ISession session, java.lang.String overrideTransactionName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddWriteAction(IWriteAction writeAction)Adds a write action to the transactionvoidaddWriteAction(IWriteAction writeAction, boolean persistWriteAcion)Adds a write action to the transactionClassInfobuildClassInfoForCommit(ClassInfo classInfo)Shift all unconnected infos to connected (committed) infosvoidclear()clear the transactionvoidcommit()Execute the commit process of the transactionlonggetCreationDateTime()IFileSystemInterfacegetFsi()java.lang.StringgetName()intgetNumberOfWriteActions()IOdbList<IWriteAction>getWriteActions()voidinit(ISession session)booleanisArchiveLog()booleanisCommited()voidloadWriteActions(boolean apply)voidloadWriteActions(java.lang.String filename, boolean apply)voidloadWriteActionsBackwards(java.lang.String filename, boolean apply)voidmanageWriteAction(long position, byte[] bytes)The public method to add a write action to the transaction.static DefaultTransactionread(java.lang.String fileName)voidreset()Reset the transactionvoidrollback()voidsetArchiveLog(boolean archiveLog)voidsetFsiToApplyWriteActions(IFileSystemInterface fsi)voidsetWritePosition(long position)Set the write position (position in main database file).java.lang.StringtoString()
-
-
-
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:ITransactionclear the transaction- Specified by:
clearin interfaceITransaction
-
reset
public void reset()
Reset the transaction- Specified by:
resetin interfaceITransaction
-
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 addedpersistWriteAcion- To indicate if write action must be persisted
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceITransaction
-
getWriteActions
public IOdbList<IWriteAction> getWriteActions()
-
getCreationDateTime
public long getCreationDateTime()
-
isCommited
public boolean isCommited()
- Specified by:
isCommitedin interfaceITransaction
-
rollback
public void rollback()
- Specified by:
rollbackin interfaceITransaction
-
commit
public void commit()
Description copied from interface:ITransactionExecute the commit process of the transaction- Specified by:
commitin interfaceITransaction
-
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.IOExceptionjava.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.IOExceptionjava.lang.ClassNotFoundException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
setFsiToApplyWriteActions
public void setFsiToApplyWriteActions(IFileSystemInterface fsi)
- Specified by:
setFsiToApplyWriteActionsin interfaceITransaction
-
isArchiveLog
public boolean isArchiveLog()
- Specified by:
isArchiveLogin interfaceITransaction- Returns:
- Returns the archiveLog.
-
setArchiveLog
public void setArchiveLog(boolean archiveLog)
- Specified by:
setArchiveLogin interfaceITransaction- Parameters:
archiveLog- The archiveLog to set.
-
getNumberOfWriteActions
public int getNumberOfWriteActions()
- Specified by:
getNumberOfWriteActionsin interfaceITransaction- 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:
setWritePositionin interfaceITransaction- Parameters:
position-
-
manageWriteAction
public void manageWriteAction(long position, byte[] bytes)Description copied from interface:ITransactionThe 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:
manageWriteActionin interfaceITransaction
-
-
DataMelt 3.0 © DataMelt by jWork.ORG