public DefaultTransaction(NeoDatis.Odb.Core.Transaction.ISession session, NeoDatis.Odb.Core.Layers.Layer3.Engine.IFileSystemInterface fsiToApplyTransaction) { this.fsiToApplyWriteActions = fsiToApplyTransaction; Init(session); readOnlyMode = false; }
private void CheckFileAccess(bool canWrite, string fileName) { lock (this) { if (fsi == null) { NeoDatis.Odb.Core.Layers.Layer3.IBaseIdentification p = null; // to unable direct junit test of FileSystemInterface if (fsiToApplyWriteActions == null) { p = new NeoDatis.Odb.Core.Layers.Layer3.IOFileParameter(fileName, canWrite, null, null); } else { p = GetParameters(canWrite); } // To enable unit test if (session != null) { isLocal = session.GetStorageEngine().IsLocal(); } fsi = new NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.LocalFileSystemInterface("transaction" , session, p, false, NeoDatis.Odb.OdbConfiguration.GetDefaultBufferSizeForTransaction ()); } } }
public virtual void TestSize() { DeleteBase("writing.neodatis"); DeleteBase("writing"); DeleteBase("reserving.neodatis"); DeleteBase("reserving"); NeoDatis.Odb.Core.Layers.Layer3.IStorageEngine engine1 = NeoDatis.Odb.OdbConfiguration .GetCoreProvider().GetClientStorageEngine(new NeoDatis.Odb.Core.Layers.Layer3.IOFileParameter (NeoDatis.Odb.Test.ODBTest.Directory + "writing.neodatis", true, null, null)); NeoDatis.Odb.Core.Layers.Layer3.IStorageEngine engine2 = NeoDatis.Odb.OdbConfiguration .GetCoreProvider().GetClientStorageEngine(new NeoDatis.Odb.Core.Layers.Layer3.IOFileParameter (NeoDatis.Odb.Test.ODBTest.Directory + "reserving.neodatis", true, null, null)); NeoDatis.Odb.Core.Layers.Layer3.Engine.IFileSystemInterface writingFsi = engine1. GetObjectWriter().GetFsi(); NeoDatis.Odb.Core.Layers.Layer3.Engine.IFileSystemInterface reservingFsi = engine2 .GetObjectWriter().GetFsi(); AssertEquals(writingFsi.GetLength(), reservingFsi.GetLength()); Write(writingFsi, false); Write(reservingFsi, true); AssertEquals(writingFsi.GetLength(), reservingFsi.GetLength()); engine1.Commit(); engine1.Close(); engine2.Commit(); engine2.Close(); DeleteBase("writing.neodatis"); DeleteBase("reserving.neodatis"); }
public override void SetFileSystemInterfaceToApplyTransaction(NeoDatis.Odb.Core.Layers.Layer3.Engine.IFileSystemInterface fsi) { fsiToApplyTransaction = fsi; if (transaction != null) { transaction.SetFsiToApplyWriteActions(fsiToApplyTransaction); } }
public virtual void Test2B() { if (!isLocal) { return; } NeoDatis.Odb.Core.Layers.Layer3.Engine.IByteArrayConverter byteArrayConverter = NeoDatis.Odb.OdbConfiguration .GetCoreProvider().GetByteArrayConverter(); DeleteBase("test78.neodatis"); // 155 : to avoid protected zone NeoDatis.Odb.Core.Transaction.IWriteAction wa1 = new NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction (300 + 1, byteArrayConverter.IntToByteArray(1), "size"); NeoDatis.Odb.Core.Transaction.IWriteAction wa2 = new NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction (300 + 15, byteArrayConverter.StringToByteArray(" 1 - ol√° chico! - 1", true, -1 , true), "name"); NeoDatis.Odb.Core.Transaction.IWriteAction wa3 = new NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction (300 + 1, byteArrayConverter.IntToByteArray(2), "size"); NeoDatis.Odb.Core.Transaction.IWriteAction wa4 = new NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction (300 + 15, byteArrayConverter.StringToByteArray(" 2 - ol√° chico! - 2", true, -1 , true), "name"); NeoDatis.Odb.Core.Layers.Layer3.IStorageEngine se = NeoDatis.Odb.OdbConfiguration .GetCoreProvider().GetClientStorageEngine(new NeoDatis.Odb.Core.Layers.Layer3.IOFileParameter (NeoDatis.Odb.Test.ODBTest.Directory + "test78.neodatis", true, null, null)); // se.close(); NeoDatis.Odb.Core.Layers.Layer3.Engine.IFileSystemInterface fsi = se.GetObjectWriter ().GetFsi(); // new FileSystemInterface(null,se.getSession(),new // IOFileParameter("test.neodatis",true),false,Configuration.getDefaultBufferSizeForData()); NeoDatis.Odb.Core.Transaction.ITransaction transaction = se.GetSession(true).GetTransaction (); transaction.SetArchiveLog(true); transaction.ManageWriteAction(wa1.GetPosition(), wa1.GetBytes(0)); transaction.ManageWriteAction(wa2.GetPosition(), wa2.GetBytes(0)); transaction.ManageWriteAction(wa3.GetPosition(), wa3.GetBytes(0)); transaction.ManageWriteAction(wa4.GetPosition(), wa4.GetBytes(0)); // transaction.getFsi().flush(); NeoDatis.Odb.Core.Transaction.IWriteAction wat1 = (NeoDatis.Odb.Core.Transaction.IWriteAction )((NeoDatis.Odb.Impl.Core.Transaction.DefaultTransaction)transaction).GetWriteActions ()[2]; byte[] bytes = wat1.GetBytes(0); transaction.Commit(); NeoDatis.Odb.Impl.Core.Transaction.DefaultTransaction transaction2 = NeoDatis.Odb.Impl.Core.Transaction.DefaultTransaction .Read(NeoDatis.Odb.Test.ODBTest.Directory + transaction.GetName()); NeoDatis.Odb.Core.Transaction.IWriteAction wat2 = (NeoDatis.Odb.Core.Transaction.IWriteAction )transaction2.GetWriteActions()[2]; AssertEquals(NeoDatis.Tool.DisplayUtility.ByteArrayToString(bytes), NeoDatis.Tool.DisplayUtility .ByteArrayToString(wat2.GetBytes(0))); AssertEquals(wat1.GetPosition(), wat2.GetPosition()); transaction2.Rollback(); fsi.Close(); DeleteBase("test78.neodatis"); DeleteBase(transaction.GetName()); }
public virtual void ApplyTo(NeoDatis.Odb.Core.Layers.Layer3.Engine.IFileSystemInterface fsi, int index) { if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId)) { NeoDatis.Tool.DLogger.Debug("Applying WriteAction #" + index + " : " + ToString() ); } fsi.SetWritePosition(position, false); for (int i = 0; i < listOfBytes.Count; i++) { fsi.WriteBytes(GetBytes(i), false, "WriteAction"); } }
public virtual void Persist(NeoDatis.Odb.Core.Layers.Layer3.Engine.IFileSystemInterface fsi, int index) { long currentPosition = fsi.GetPosition(); if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId)) { } // DLogger.debug("# Writing WriteAction #" + index + " at " + // currentPosition+" : " + toString()); int sizeOfLong = NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType.Long.GetSize(); int sizeOfInt = NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType.Integer.GetSize(); // build the full byte array to write once byte[] bytes = new byte[sizeOfLong + sizeOfInt + size]; byte[] bytesOfPosition = byteArrayConverter.LongToByteArray(position); byte[] bytesOfSize = byteArrayConverter.IntToByteArray(size); for (int i = 0; i < sizeOfLong; i++) { bytes[i] = bytesOfPosition[i]; } int offset = sizeOfLong; for (int i = 0; i < sizeOfInt; i++) { bytes[offset] = bytesOfSize[i]; offset++; } for (int i = 0; i < listOfBytes.Count; i++) { byte[] tmp = listOfBytes[i]; System.Array.Copy(tmp, 0, bytes, offset, tmp.Length); offset += tmp.Length; } fsi.WriteBytes(bytes, false, "Transaction"); int fixedSize = sizeOfLong + sizeOfInt; long positionAfterWrite = fsi.GetPosition(); long writeSize = positionAfterWrite - currentPosition; if (writeSize != size + fixedSize) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.DifferentSizeInWriteAction .AddParameter(size).AddParameter(writeSize)); } }
public static NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction Read(NeoDatis.Odb.Core.Layers.Layer3.Engine.IFileSystemInterface fsi, int index) { try { long position = fsi.ReadLong(); int size = fsi.ReadInt(); byte[] bytes = fsi.ReadBytes(size); NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction writeAction = new NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction (position, bytes); if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId)) { NeoDatis.Tool.DLogger.Debug("Loading Write Action # " + index + " at " + fsi.GetPosition () + " => " + writeAction.ToString()); } return(writeAction); } catch (NeoDatis.Odb.ODBRuntimeException e) { NeoDatis.Tool.DLogger.Error("error reading write action " + index + " at position " + fsi.GetPosition()); throw; } }
/// <summary> /// The init2 method is the two phase init implementation The /// FileSystemInterface depends on the session creation which is done by /// subclasses after the ObjectWriter constructor So we can not execute the /// buildFSI in the constructor as it would result in a non initialized /// object reference (the session) /// </summary> public virtual void Init2() { this.fsi = BuildFSI(); }
/// <summary>Reset the transaction</summary> public virtual void Reset() { Clear(); Init(session); fsi = null; }
public override void SetFileSystemInterfaceToApplyTransaction(NeoDatis.Odb.Core.Layers.Layer3.Engine.IFileSystemInterface fsi) { }
public virtual void Close() { objectReader = null; if (idManager != null) { idManager.Clear(); idManager = null; } storageEngine = null; fsi.Close(); fsi = null; }
/// <exception cref="System.IO.IOException"></exception> public virtual void Write(NeoDatis.Odb.Core.Layers.Layer3.Engine.IFileSystemInterface fsi, bool writeInTransaction) { fsi.WriteInt(1, writeInTransaction, "1"); }
public virtual void SetFsiToApplyWriteActions(NeoDatis.Odb.Core.Layers.Layer3.Engine.IFileSystemInterface fsi) { this.fsiToApplyWriteActions = fsi; }
public virtual void Commit() { if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId)) { NeoDatis.Tool.DLogger.Info("Commiting " + numberOfWriteActions + " write actions - In Memory : " + hasAllWriteActionsInMemory + " - sid=" + session.GetId()); } // Check if database has been rollbacked CheckRollback(); // call the commit listeners ManageCommitListenersBefore(); if (currentWriteAction != null && !currentWriteAction.IsEmpty()) { AddWriteAction(currentWriteAction); currentWriteAction = null; } if (fsi == null && numberOfWriteActions != 0) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.TransactionAlreadyCommitedOrRollbacked ); } if (numberOfWriteActions == 0 || readOnlyMode) { // FIXME call commitMetaModel in realOnlyMode? CommitMetaModel(); // Nothing to do if (fsi != null) { fsi.Close(); fsi = null; } if (session != null) { session.GetCache().ClearOnCommit(); } return; } // Marks the transaction as committed SetCommited(true); // Apply the write actions the main database file ApplyTo(); // Commit Meta Model changes CommitMetaModel(); if (archiveLog) { fsi.SetWritePositionNoVerification(0, false); fsi.WriteByte((byte)2, false); fsi.GetIo().EnableAutomaticDelete(false); fsi.Close(); fsi = null; } else { fsi.Close(); Delete(); fsi = null; } if (session != null) { session.GetCache().ClearOnCommit(); } ManageCommitListenersAfter(); }