Esempio n. 1
0
        public DocumentDataContainer RequireDocumentContainer(int docType)
        {
            DocumentDataContainer docStore;

            if (m_documentDataContainers.TryGetValue(docType, out docStore))
            {
                return(docStore);
            }

            var doclock = m_documentDataContainerLocks[docType];

            lock (doclock)
            {
                if (!m_documentDataContainers.TryGetValue(docType, out docStore))
                {
                    docStore = new DocumentDataContainer(
                        m_dataContainerDescriptor,
                        m_dataContainerDescriptor.RequireDocumentType(docType),
                        m_memoryPool,
                        m_tracer);
                    if (!string.IsNullOrEmpty(m_storageRoot))
                    {
                        var stats = ReadStatsFromStore(m_storageRoot);
                        docStore.ReadDataFromStore(GetDocRootPath(m_storageRoot, m_dataContainerDescriptor.RequireDocumentType(docType)), stats.TryGetDocumentCount(docType));
                    }

                    m_documentDataContainers.Add(docType, docStore);
                }

                return(docStore);
            }
        }
Esempio n. 2
0
        private void ParseBulkRequest(DataRequestBulk requestBulk, ParsedRequest parsedRequest)
        {
            switch (requestBulk.DbStatementType)
            {
            case StatementType.Insert:
            case StatementType.Update:
                parsedRequest.StatementType = requestBulk.DbStatementType;
                break;

            default:
                throw new ArgumentOutOfRangeException("requestBulk", requestBulk.DbStatementType, "Invalid bulk statement type");
            }

            parsedRequest.TargetEntity = m_containerDescriptor.RequireDocumentType(
                m_containerDescriptor.RequireDocumentTypeName(requestBulk.EntityName));

            if (string.IsNullOrEmpty(parsedRequest.TargetEntity.PrimaryKeyFieldName))
            {
                throw new Exception("Target entity does not have a primary key, cannot perform bulk operations on it");
            }

            parsedRequest.TargetEntityPkField = m_containerDescriptor.RequireField(
                parsedRequest.TargetEntity.DocumentType, parsedRequest.TargetEntity.PrimaryKeyFieldName);

            // we always expect value of primary key into driver row data for bulk requests at first position
            parsedRequest.OrdinalOfPrimaryKey = 0;

            if (0 != StringComparer.OrdinalIgnoreCase.Compare(requestBulk.FieldNames[0], parsedRequest.TargetEntityPkField.Name))
            {
                throw new Exception("First field in bulk request input schema on this entity must be the primary key field");
            }

            for (var ordinal = 0; ordinal < requestBulk.FieldNames.Length; ordinal++)
            {
                var fieldName = requestBulk.FieldNames[ordinal];
                var field     = m_containerDescriptor.RequireField(parsedRequest.TargetEntity.DocumentType, fieldName);

                if (ordinal != 0 && ReferenceEquals(parsedRequest.TargetEntityPkField, field))
                {
                    throw new Exception("Primary key field may only be used in first position");
                }

                if (parsedRequest.Modify.ModifiedFields.Contains(field))
                {
                    throw new CompilationException("A field can be assigned only once: " + field.Name, null);
                }

                parsedRequest.BulkInput.BulkInputFields.Add(field);
                parsedRequest.Modify.ModifiedFields.Add(field);
                parsedRequest.Modify.InsertUpdateSetClauses.Add(null);
            }
        }