예제 #1
0
        public void FetchInternalEntityIdIntoChangeBuffer(DriverChangeBuffer changeBuffer, RequestExecutionContext context)
        {
            if (changeBuffer.InternalEntityId == null)
            {
                changeBuffer.InternalEntityId = new byte[context.DriverOutputBuffer.InternalEntityId.Length];
            }

            ReadPrimaryKey(changeBuffer);
        }
 public void FetchInternalEntityIdIntoChangeBuffer(DriverChangeBuffer changeBuffer,
     RequestExecutionContext context)
 {
     changeBuffer.InternalEntityId = context.DriverOutputBuffer.InternalEntityId;
 }
예제 #3
0
        /// <summary>
        /// Ctr.
        /// </summary>
        public RamDriverChangeset(RamDriver driver, DriverChangeBuffer changeBuffer, bool isBulk, DocumentDataContainer documentContainer, ColumnDataBase[] columnStores)
        {
            if (driver == null)
            {
                throw new ArgumentNullException("driver");
            }

            if (changeBuffer == null)
            {
                throw new ArgumentNullException("changeBuffer");
            }

            if (documentContainer == null)
            {
                throw new ArgumentNullException("documentContainer");
            }

            Driver = driver;
            ChangeBuffer = changeBuffer;
            IsBulk = isBulk;
            ColumnStores = columnStores;
            DocumentContainer = documentContainer;
        }
예제 #4
0
        private void UpdateAtPosition(RamDriverChangeset changesetRec, DriverChangeBuffer change, int docIndex)
        {
            var changeData = change.Data;
            for (var ordinal = 0; ordinal < change.Fields.Length; ordinal++)
            {
                var colStore = changesetRec.ColumnStores[ordinal];

                if (BitVector.Get(changeData.NotNulls, ordinal))
                {
                    colStore.NotNulls.SafeSet(docIndex);
                    var indexInArray = changeData.GetIndexInArray(ordinal);
                    colStore.AssignFromDriverRow(docIndex, changeData, indexInArray);
                }
                else
                {
                    colStore.NotNulls.SafeClear(docIndex);
                }
            }
        }
예제 #5
0
        public long CreateChangeset(DriverChangeBuffer changeBuffer, bool isBulk)
        {
            CheckInitialized();

            if (changeBuffer == null)
            {
                throw new ArgumentNullException("changeBuffer");
            }

            var key = Interlocked.Increment(ref m_lastChangesetHandle);

            ColumnDataBase[] columnStores = null;
            var documentContainer = m_dataContainer.RequireDocumentContainer(changeBuffer.TargetEntity);
            if (changeBuffer.Fields != null && changeBuffer.Fields.Length > 0)
            {
                columnStores = new ColumnDataBase[changeBuffer.Fields.Length];
                for (var i = 0; i < changeBuffer.Fields.Length; i++)
                {
                    var field = changeBuffer.Fields[i];
                    columnStores[i] = documentContainer.RequireColumnStore(field.FieldId);
                }
            }

            var changesetRec = new RamDriverChangeset(this, changeBuffer, isBulk, documentContainer, columnStores);

            documentContainer.StructureLock.EnterReadLock();
            try
            {
                if (!m_changesets.TryAdd(key, changesetRec))
                {
                    throw new Exception("Internal error");
                }
                return key;
            }
            catch
            {
                documentContainer.StructureLock.ExitReadLock();
                throw;
            }
        }
 public void FetchInternalEntityIdIntoChangeBuffer(DriverChangeBuffer changeBuffer, RequestExecutionContext context)
 {
     // reference copy is safe because storage driver is responsible for copying this value
     // when it reads the change buffer
     changeBuffer.InternalEntityId = context.DriverOutputBuffer.InternalEntityId;
 }
예제 #7
0
        private void ReadPrimaryKey(DriverChangeBuffer changeBuffer)
        {
            if (!BitVector.Get(changeBuffer.Data.NotNulls, 0))
            {
                throw new Exception("Primary key value may not be null");
            }

            var indexInArray = changeBuffer.Data.FieldArrayIndexes[0];
            var internalEntityId = changeBuffer.InternalEntityId;

            switch (m_pkFieldType)
            {
                case DriverRowData.DataTypeRepresentation.ByteArray:
                    {
                        var value = changeBuffer.Data.BinaryData[indexInArray];
                        if (value.Length == 0 || value.Length > byte.MaxValue)
                        {
                            throw new Exception("Primary key length must be within 1 to 255 bytes");
                        }

                        Buffer.BlockCopy(value.Data, 0, internalEntityId, 1, value.Length - 1);
                        internalEntityId[0] = (byte)(value.Length - 1);
                    }
                    break;
                case DriverRowData.DataTypeRepresentation.String:
                    {
                        var value = changeBuffer.Data.StringData[indexInArray];
                        if (value.Length == 0 || value.Length > byte.MaxValue)
                        {
                            throw new Exception("Primary key length must be within 1 to 255 characters");
                        }

                        var bytelen = Encoding.UTF8.GetByteCount(value);
                        if (bytelen == 0 || bytelen > byte.MaxValue)
                        {
                            throw new Exception("UTF conversion must produce from 1 to 255 bytes");
                        }
                        internalEntityId[0] = (byte)Encoding.UTF8.GetBytes(value, 0, value.Length, internalEntityId, 1);
                    }
                    break;
                case DriverRowData.DataTypeRepresentation.Value8Bytes:
                    {
                        var value = changeBuffer.Data.ValueData8Bytes[indexInArray].AsUInt64;
                        var pos = 1;
                        while (value > 0)
                        {
                            internalEntityId[pos] = (byte)value;
                            value >>= 8;
                            pos++;
                        }
                        internalEntityId[0] = (byte)(pos - 1);
                    }
                    break;
                case DriverRowData.DataTypeRepresentation.Value16Bytes:
                    {
                        var value = (UInt64)changeBuffer.Data.ValueData16Bytes[indexInArray].Lo;
                        var pos = 1;
                        while (value > 0)
                        {
                            internalEntityId[pos] = (byte)value;
                            value >>= 8;
                            pos++;
                        }
                        value = (UInt64)changeBuffer.Data.ValueData16Bytes[indexInArray].Hi;
                        while (value > 0)
                        {
                            internalEntityId[pos] = (byte)value;
                            value >>= 8;
                            pos++;
                        }
                        internalEntityId[0] = (byte)(pos - 1);
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }