예제 #1
0
        /// <summary>
        /// Process the docs and convert them to entities.
        /// </summary>
        /// <param name="rows"></param>
        /// <returns></returns>
        internal EntitiesProcessResult Process(
            JToken[] rows, OdmViewProcessingOptions processingOptions)
        {
            PreProcessInfo preProcess = PreProcess(rows);

            return(PostProcess(preProcess, processingOptions));
        }
예제 #2
0
        internal void FillProxy(
            EntityDefinition entityDef,
            object proxy, JToken doc, string id, PreProcessInfo preProcess,
            OdmViewProcessingOptions processingOptions, bool emptyProxy)
        {
            foreach (EntityPropertyDefinition propDef in entityDef.Properties)
            {
                propDef.Read(proxy, doc, id, preProcess, processingOptions, emptyProxy, context);
            }

            //foreach (PropertyInfo prop in GetPropertiesOf(proxy)) {
            //  if (emptyProxy && IsSimpleType(prop)) {
            //    ReadValueType(proxy, prop, doc);
            //  }
            //  else if (emptyProxy && IsArray(prop)) {
            //    ReadArray(proxy, prop, doc);
            //  }
            //  else if (IsCollection(prop)) {
            //    CreateReferenceProxies(proxy, prop, doc, id, preProcess, processingOptions, emptyProxy);
            //  }
            //  else if (IsToOneReference(prop)) {
            //    DebugWriteLine("The property {0}.{1} is entity reference which is supported yet",
            //        prop.DeclaringType.Name, prop.Name, prop.PropertyType.Name);
            //  }
            //  else {
            //    DebugWriteLine("The property {0}.{1} is of type {2} which is not supported yet",
            //        prop.DeclaringType.Name, prop.Name, prop.PropertyType.Name);
            //  }
            //}
        }
예제 #3
0
        private EntitiesProcessResult ExecuteView(CouchViewOptions viewOptions)
        {
            JToken[] rows = couchDBContext.ClientAdaper.GetViewRows(viewName, viewOptions);
            var      processingOptions = new OdmViewProcessingOptions(assoicateCollectionsToLoad);

            EntitiesProcessResult processResult = couchDBContext.Process(rows, processingOptions);

            return(processResult);
        }
예제 #4
0
        /// <summary>
        /// Process document rows.
        /// </summary>
        /// <param name="rows"></param>
        /// <returns></returns>
        internal EntitiesProcessResult Process(
            JToken[] rows, OdmViewProcessingOptions processingOptions)
        {
            EntitiesProcessResult result = IdentityMap.Process(rows, processingOptions);

            DocumentManager.Add(result.NewEntities);

            return(result);
        }
예제 #5
0
        /// <summary>
        /// Create proxy from the specified document and entity type.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="entityType"></param>
        /// <returns></returns>
        public object CreateProxy(
            JToken doc, Type entityType, string id, PreProcessInfo preProcess,
            OdmViewProcessingOptions processingOptions, bool emptyProxy)
        {
            EntityDefinition entityDef = context.Mapping.GetEntityDefinition(entityType);
            object           proxy     = entityDef.CreateInstance();

            FillProxy(entityDef, proxy, doc, id, preProcess, processingOptions, emptyProxy);
            return(proxy);
        }
예제 #6
0
        private object Deserialize(
            JToken doc, PreProcessInfo preProcess, OdmViewProcessingOptions processingOptions)
        {
            Type   entityType = GetDocEntityType(doc);
            string entityId   = GetDocId(doc);

            object entity = context.Serializer.CreateProxy(doc, entityType, entityId, preProcess, processingOptions, emptyProxy: true);

            return(entity);
        }
예제 #7
0
        internal void ReFillProxy(
            object entity,
            JToken doc,
            string id,
            PreProcessInfo preProcess,
            OdmViewProcessingOptions processingOptions)
        {
            EntityDefinition entityDef = context.Mapping.GetEntityDefinition(entity.GetType());

            FillProxy(entityDef, entity, doc, id, preProcess, processingOptions, false);
        }
예제 #8
0
        private EntitiesProcessResult PostProcess(
            PreProcessInfo preProcess, OdmViewProcessingOptions processingOptions)
        {
            var resultBuilder = new EntitiesProcessResultBuilder();

            foreach (PreProcessEntityInfo preProcessRow in preProcess.Rows)
            {
                JToken row = preProcessRow.Row;
                JToken doc = row[CouchDBFieldsConst.ResultRowDoc];
                if (doc == null)
                {
                    throw new Exception("doc field was not found");
                }

                string id    = preProcessRow.Id;
                string rev   = doc.Value <string>(CouchDBFieldsConst.DocRev);
                var    idrev = new IdRev(id, rev);

                object entity;
                if (idToEntity.TryGetValue(id, out entity))
                {
                    // PATCH: This line reload exist entities and should be remove in the future.
                    // The reason it is here is because when loading main entity with associated entity
                    // with many-to-many relations between them the related entity's assoication will
                    // be partially loaded and when updating the association of the related entity
                    // only part of the data will be avilable. This patch solve the problem
                    // but it will introduce inconsistensis and also cost in performance.
                    context.Serializer.ReFillProxy(entity, doc, id, preProcess, processingOptions);

                    // Reuse exist entity.
                    resultBuilder.AddExist(entity, idrev, doc, preProcessRow.Key);
                }
                else
                {
                    // Found new entity
                    entity = Deserialize(doc, preProcess, processingOptions);

                    idToEntity.Add(id, entity);
                    entityToId.Add(entity, id);

                    resultBuilder.AddNew(entity, idrev, doc, preProcessRow.Key);
                }
            }

            return(resultBuilder.BuildResult());
        }