Пример #1
0
 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());
 }
Пример #2
0
 /// <summary>Adds a write action to the transaction</summary>
 /// <param name="writeAction">The write action to be added</param>
 /// <param name="persistWriteAcion">To indicate if write action must be persisted</param>
 public virtual void AddWriteAction(NeoDatis.Odb.Core.Transaction.IWriteAction writeAction
                                    , bool persistWriteAcion)
 {
     if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
     {
         NeoDatis.Tool.DLogger.Info("Adding WA in Transaction of session " + session.GetId
                                        ());
     }
     if (writeAction.IsEmpty())
     {
         return;
     }
     CheckRollback();
     if (!hasBeenPersisted && persistWriteAcion)
     {
         Persist();
     }
     if (persistWriteAcion)
     {
         writeAction.Persist(fsi, numberOfWriteActions + 1);
     }
     // Only adds the writeaction to the list if the transaction keeps all in
     // memory
     if (hasAllWriteActionsInMemory)
     {
         writeActions.Add(writeAction);
     }
     numberOfWriteActions++;
     if (hasAllWriteActionsInMemory && numberOfWriteActions > NeoDatis.Odb.OdbConfiguration
         .GetMaxNumberOfWriteObjectPerTransaction())
     {
         hasAllWriteActionsInMemory = false;
         System.Collections.IEnumerator iterator = writeActions.GetEnumerator();
         NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction wa = null;
         while (iterator.MoveNext())
         {
             wa = (NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction)iterator.Current;
             wa.Clear();
         }
         writeActions.Clear();
         if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
         {
             NeoDatis.Tool.DLogger.Info("Number of objects has exceeded the max number " + numberOfWriteActions
                                        + "/" + NeoDatis.Odb.OdbConfiguration.GetMaxNumberOfWriteObjectPerTransaction()
                                        + ": switching to persistent transaction managment");
         }
     }
 }
Пример #3
0
        public virtual void Test3()
        {
            NeoDatis.Odb.Core.Layers.Layer3.Engine.IByteArrayConverter byteArrayConverter = NeoDatis.Odb.OdbConfiguration
                                                                                            .GetCoreProvider().GetByteArrayConverter();
            int size = 1000;

            NeoDatis.Odb.Core.Transaction.ISession session = new NeoDatis.Odb.Core.Mock.MockSession
                                                                 (NeoDatis.Odb.Test.ODBTest.Directory + "test2.neodatis");
            NeoDatis.Odb.Core.Layers.Layer3.Engine.IFileSystemInterface fsi = new NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.LocalFileSystemInterface
                                                                                  ("test", session, new NeoDatis.Odb.Core.Layers.Layer3.IOFileParameter(NeoDatis.Odb.Test.ODBTest
                                                                                                                                                        .Directory + "test2.neodatis", true, null, null), false, NeoDatis.Odb.OdbConfiguration
                                                                                  .GetDefaultBufferSizeForData());
            NeoDatis.Odb.Impl.Core.Transaction.DefaultTransaction transaction = new NeoDatis.Odb.Impl.Core.Transaction.DefaultTransaction
                                                                                    (session, fsi);
            transaction.SetArchiveLog(true);
            for (int i = 0; i < size; i++)
            {
                // 155 : to avoid protected zone
                transaction.ManageWriteAction(300 + i * 4 * 2, byteArrayConverter.IntToByteArray(
                                                  i));
            }
            NeoDatis.Odb.Core.Transaction.IWriteAction wa1 = (NeoDatis.Odb.Core.Transaction.IWriteAction
                                                              )transaction.GetWriteActions()[size - 2];
            byte[] bytes = wa1.GetBytes(0);
            transaction.Commit();
            long start = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();

            NeoDatis.Odb.Impl.Core.Transaction.DefaultTransaction transaction2 = NeoDatis.Odb.Impl.Core.Transaction.DefaultTransaction
                                                                                 .Read(NeoDatis.Odb.Test.ODBTest.Directory + transaction.GetName());
            long t = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs() - start;

            NeoDatis.Odb.Core.Transaction.IWriteAction wa2 = (NeoDatis.Odb.Core.Transaction.IWriteAction
                                                              )transaction2.GetWriteActions()[size - 2];
            AssertEquals(NeoDatis.Tool.DisplayUtility.ByteArrayToString(bytes), NeoDatis.Tool.DisplayUtility
                         .ByteArrayToString(wa2.GetBytes(0)));
            AssertEquals(wa1.GetPosition(), wa2.GetPosition());
            transaction2.Rollback();
            fsi.Close();
            DeleteBase("test2.neodatis");
            DeleteBase(transaction.GetName());
        }
Пример #4
0
 public virtual void ManageWriteAction(long position, byte[] bytes)
 {
     if (this.currentWritePositionInWA == position)
     {
         if (currentWriteAction == null)
         {
             currentWriteAction = provider.GetWriteAction(position, null);
         }
         currentWriteAction.AddBytes(bytes);
         this.currentWritePositionInWA += bytes.Length;
     }
     else
     {
         if (currentWriteAction != null)
         {
             AddWriteAction(currentWriteAction);
         }
         this.currentWriteAction       = provider.GetWriteAction(position, bytes);
         this.currentWritePositionInWA = position + bytes.Length;
     }
 }
Пример #5
0
 /// <summary>Set the write position (position in main database file).</summary>
 /// <remarks>
 /// 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.
 /// </remarks>
 /// <param name="position"></param>
 public virtual void SetWritePosition(long position)
 {
     if (position != this.currentWritePositionInWA)
     {
         this.currentWritePositionInWA = position;
         if (currentWriteAction != null)
         {
             AddWriteAction(currentWriteAction);
         }
         this.currentWriteAction = new NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction
                                       (position);
     }
     else
     {
         if (currentWriteAction == null)
         {
             this.currentWriteAction = new NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction
                                           (position);
             this.currentWritePositionInWA = position;
         }
     }
 }
Пример #6
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="System.TypeLoadException"></exception>
        public virtual void LoadWriteActionsBackwards(string filename, bool apply)
        {
            int executedWriteAction = 0;

            if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
            {
                NeoDatis.Tool.DLogger.Debug("Load write actions of " + filename);
            }
            NeoDatis.Odb.Core.Transaction.IWriteAction wa = null;
            try
            {
                CheckFileAccess(false, filename);
                fsi.UseBuffer(true);
                fsi.SetReadPosition(0);
                isCommited       = fsi.ReadByte() == 1;
                creationDateTime = fsi.ReadLong();
                System.Collections.Generic.IDictionary <long, long> writtenPositions = null;
                if (apply)
                {
                    writtenPositions = new NeoDatis.Tool.Wrappers.Map.OdbHashMap <long, long>();
                }
                long position = System.Convert.ToInt64(-1);
                int  i        = numberOfWriteActions;
                long previousWriteActionPosition = fsi.GetLength();
                while (i > 0)
                {
                    // Sets the position 8 bytes backwards
                    fsi.SetReadPosition(previousWriteActionPosition - NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType
                                        .Long.GetSize());
                    // And then the read a long, this will be the previous write
                    // action position
                    previousWriteActionPosition = fsi.ReadLong();
                    // Then sets the read position to read the write action
                    fsi.SetReadPosition(previousWriteActionPosition);
                    wa = NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction.Read(fsi, i + 1);
                    if (apply)
                    {
                        position = wa.GetPosition();
                        if (writtenPositions[position] != null)
                        {
                            // It has already been written something more recent at
                            // this position, do not write again
                            i--;
                            continue;
                        }
                        wa.ApplyTo(fsiToApplyWriteActions, i + 1);
                        writtenPositions.Add(position, position);
                        executedWriteAction++;
                    }
                    else
                    {
                        AddWriteAction(wa, false);
                    }
                    i--;
                }
                if (apply)
                {
                    fsiToApplyWriteActions.Flush();
                    if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
                    {
                        NeoDatis.Tool.DLogger.Debug("Total Write actions : " + i + " / position cache = "
                                                    + writtenPositions.Count);
                    }
                    NeoDatis.Tool.DLogger.Info("Total write actions = " + numberOfWriteActions + " : executed = "
                                               + executedWriteAction);
                    writtenPositions.Clear();
                    writtenPositions = null;
                }
            }
            finally
            {
            }
        }
Пример #7
0
 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();
 }
Пример #8
0
 /// <summary>Adds a write action to the transaction</summary>
 /// <param name="writeAction">The write action to be added</param>
 public virtual void AddWriteAction(NeoDatis.Odb.Core.Transaction.IWriteAction writeAction
                                    )
 {
     AddWriteAction(writeAction, true);
 }
		public virtual void ManageWriteAction(long position, byte[] bytes)
		{
			if (this.currentWritePositionInWA == position)
			{
				if (currentWriteAction == null)
				{
					currentWriteAction = provider.GetWriteAction(position, null);
				}
				currentWriteAction.AddBytes(bytes);
				this.currentWritePositionInWA += bytes.Length;
			}
			else
			{
				if (currentWriteAction != null)
				{
					AddWriteAction(currentWriteAction);
				}
				this.currentWriteAction = provider.GetWriteAction(position, bytes);
				this.currentWritePositionInWA = position + bytes.Length;
			}
		}
		/// <summary>Set the write position (position in main database file).</summary>
		/// <remarks>
		/// 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.
		/// </remarks>
		/// <param name="position"></param>
		public virtual void SetWritePosition(long position)
		{
			if (position != this.currentWritePositionInWA)
			{
				this.currentWritePositionInWA = position;
				if (currentWriteAction != null)
				{
					AddWriteAction(currentWriteAction);
				}
				this.currentWriteAction = new NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction
					(position);
			}
			else
			{
				if (currentWriteAction == null)
				{
					this.currentWriteAction = new NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction
						(position);
					this.currentWritePositionInWA = position;
				}
			}
		}
		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();
		}