Пример #1
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");
         }
     }
 }
Пример #2
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();
 }