Esempio n. 1
0
        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));
            }
        }
Esempio n. 2
0
 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;
     }
 }