예제 #1
0
        internal override void LoadValueFromDb(object value, object exValue, LoadContext loadContext)
        {
            DataId              id                  = new DataId((string)DataProperty.EscapeFromDBNull(value));
            DataObject          dataObject          = (DataObject)null;
            DataObjectChildList dataObjectChildList = (DataObjectChildList)null;

            if (!id.IsEmpty)
            {
                MetadataAssociationRefList refs = this.Metadata.Association.Refs;
                MetadataAssociationRef     metadataAssociationRef = this.Metadata.Association.Selector == null ? refs[0] : refs.FindBySelectorValue(exValue);
                if (metadataAssociationRef == null)
                {
                    throw new DataException(string.Format("Нарушение целостности данных.\n{0}\nОшибка: Невозможно определить класс связанного объекта по значению селектора '{1}'.\n", (object)this.SystemView, exValue));
                }
                dataObject = this.Session[metadataAssociationRef.RefClass].EnsureCacheItem(id);
                if (dataObject.IsNull)
                {
                    dataObject = (DataObject)null;
                }
                else if (this.Metadata.IsAggregation)
                {
                    dataObjectChildList = dataObject.GetChilds(metadataAssociationRef.OwnerChildRef);
                    if ((loadContext & LoadContext.FetchAllObjects) != (LoadContext)0)
                    {
                        dataObjectChildList.SetCompleted(true);
                    }
                }
            }
            base.SetValue((object)dataObject);
            dataObjectChildList?.AttachChild(this.Object, true);
        }
예제 #2
0
        public DataObject GetObject(DataId id)
        {
            DataObject dataObject1 = this.EnsureCacheItem(id);

            if (dataObject1.IsUnknown)
            {
                DataSession masterSession = this.Session.MasterSession;
                if (masterSession != null)
                {
                    DataObject dataObject2 = masterSession[dataObject1.Class][id];
                    dataObject1.ClearSessionState();
                    if (dataObject2.IsError | dataObject2.IsDeleted)
                    {
                        dataObject1.IncludeSessionState(ObjectSessionState.Error);
                    }
                    else
                    {
                        dataObject1.IncludeSessionState(ObjectSessionState.Existing);
                    }
                }
                else
                {
                    dataObject1.LoadNotAssignedProperties();
                }
            }
            return(dataObject1);
        }
예제 #3
0
 public DataObject this[DataId id]
 {
     get
     {
         DataObject dataObject = this.GetObject(id);
         return(!dataObject.SessionStateContainsAny(ObjectSessionState.Error) ? dataObject : throw new DataException(string.Format("Объект {0}[{1}] не существует.", (object)this.Class.Name, (object)id)));
     }
 }
예제 #4
0
 internal void Add(DataId id)
 {
     if (this.LoadedObjects.ContainsKey((object)id))
     {
         return;
     }
     this.FIds[(object)id] = (object)null;
 }
예제 #5
0
        public DataObject QueryObject(LoadPlan loadPlan, DataId id)
        {
            DataObjectList listInstance = this.CreateListInstance();

            this.Session.LoadData(loadPlan, listInstance, new DataId[1]
            {
                id
            }, (string)null);
            return(listInstance.Count != 0 ? listInstance[0] : this.Session[loadPlan.Class].NullObject);
        }
예제 #6
0
        internal override void Load(InDbDatabase db, DataObjectList dstObjs)
        {
            int count = this.FIds.Count;

            if (count == 0)
            {
                return;
            }
            DataId[] dataIdArray = new DataId[count];
            this.FIds.Keys.CopyTo((Array)dataIdArray, 0);
            this.FIds.Clear();
            StringBuilder stringBuilder = new StringBuilder(this.SelectSql);

            stringBuilder.Append(" WHERE [").Append(this.InProperty.DataField).Append("] IN ('");
            int length = stringBuilder.Length;
            int index1 = 0;

            while (index1 < count)
            {
                stringBuilder.Length = length;
                for (int index2 = 0; index1 < count && index2 < 100; ++index2)
                {
                    if (index2 > 0)
                    {
                        stringBuilder.Append("','");
                    }
                    stringBuilder.Append(dataIdArray[index1].ToString());
                    ++index1;
                }
                stringBuilder.Append("')");
                InDbCommand command = db.CreateCommand(stringBuilder.ToString());
                IDataReader reader  = command.ExecuteReader();
                try
                {
                    this.Load(reader, dstObjs, (LoadContext)0);
                }
                finally
                {
                    reader.Dispose();
                    command.Dispose();
                }
            }
            if (!this.InProperty.IsId)
            {
                return;
            }
            for (int index2 = 0; index2 < count; ++index2)
            {
                DataId id = dataIdArray[index2];
                if (!this.LoadedObjects.ContainsKey((object)id))
                {
                    this.FStorage.EnsureCacheItem(id).SetSessionState(ObjectSessionState.Error);
                }
            }
        }
예제 #7
0
        private DataObject NewCacheItem(DataId id, ObjectSessionState sessionState)
        {
            DataObject objectInstance = this.CreateObjectInstance();

            objectInstance.Init(this, id, sessionState);
            if (id.IsEmpty)
            {
                this.Session.EnqueueIdGeneration(objectInstance);
            }
            else
            {
                this.FObjects.Add(id, objectInstance);
            }
            return(objectInstance);
        }
예제 #8
0
        public DataId ConvertId(DataId sourceId)
        {
            int localGroupId;
            int number;

            if (this.FGroupConverters.Count > 0 && sourceId.TryExtractParts(out localGroupId, out number))
            {
                for (int index = 0; index < this.FGroupConverters.Count; ++index)
                {
                    IdConverter.GroupConverter fgroupConverter = this.FGroupConverters[index];
                    if (fgroupConverter.SourceLocalId == localGroupId)
                    {
                        return(new DataId(fgroupConverter.DestinationLocalId, number));
                    }
                }
            }
            return(sourceId);
        }
예제 #9
0
        public DataObject AddExisting(DataId id)
        {
            DataObject objectInstance;

            if (!this.FObjects.TryGetValue(id, out objectInstance))
            {
                objectInstance = this.CreateObjectInstance();
                this.FObjects.Add(id, objectInstance);
                objectInstance.Init(this, id, ObjectSessionState.New);
                this.FObjectsToUpdate[id] = objectInstance;
            }
            else if (objectInstance.IsError)
            {
                objectInstance.Init(this, id, ObjectSessionState.New);
                this.FObjectsToUpdate[id] = objectInstance;
            }
            return(objectInstance);
        }
예제 #10
0
 internal void Load(IDataReader reader, DataObjectList dstObjs, LoadContext loadContext)
 {
     object[] values = new object[reader.FieldCount];
     while (reader.Read())
     {
         reader.GetValues(values);
         DataId id = new DataId((string)values[0]);
         if (this.LoadedObjects[(object)id] == null)
         {
             DataObject dataObject = this.FStorage.EnsureCacheItem(id);
             if (!dataObject.IsDeleted)
             {
                 int index = 0;
                 int num   = 1;
                 for (; index < this.ObjectLoader.Count; ++index)
                 {
                     ObjectPartLoader objectPartLoader = this.ObjectLoader[index];
                     object           obj     = objectPartLoader.FieldName != null ? values[num++] : (object)null;
                     object           exValue = objectPartLoader.ExFieldName != null ? values[num++] : (object)null;
                     objectPartLoader.Load(dataObject, obj, exValue, loadContext);
                 }
                 dstObjs?.Add((object)dataObject);
             }
             this.LoadedObjects.Add((object)dataObject.Id, (object)dataObject);
             dataObject.IncludeSessionState(ObjectSessionState.Existing);
         }
     }
     if (loadContext != LoadContext.FetchAllObjects)
     {
         return;
     }
     for (int index1 = 0; index1 < this.ObjectLoader.Count; ++index1)
     {
         if (this.ObjectLoader[index1] is LinkPropertyLoader linkPropertyLoader && linkPropertyLoader.Association.Property.IsAggregation)
         {
             for (int index2 = 0; index2 < linkPropertyLoader.RefLoaders.Length; ++index2)
             {
                 MetadataClass cls = linkPropertyLoader.RefLoaders[index2].Class;
                 this.FStorage.Session[cls].CompleteChildLists(cls.Childs.Need(this.Class));
             }
         }
     }
 }
예제 #11
0
        internal void Commit()
        {
            DataId id = this.Id;

            if (this.FAttachments != null)
            {
                this.FAttachments.Commit();
            }
            if (this.IsDeleted)
            {
                this.Storage.RemoveObjectFromCache(id);
                this.SetSessionState(ObjectSessionState.Error);
            }
            else
            {
                if (this.IsNew)
                {
                    this.ExcludeSessionState(ObjectSessionState.New);
                    this.IncludeSessionState(ObjectSessionState.Existing);
                }
                if (this.IsPropertiesModified)
                {
                    foreach (DataProperty fproperty in this.FProperties)
                    {
                        fproperty?.Commit();
                    }
                    this.ExcludeSessionState(ObjectSessionState.PropertiesModified);
                }
                if (!this.IsChildsModified)
                {
                    return;
                }
                foreach (DataObjectChildList fchild in this.FChilds)
                {
                    fchild?.Commit();
                }
                this.ExcludeSessionState(ObjectSessionState.ChildsModified);
            }
        }
예제 #12
0
 internal void SetNewId(DataId id) => this.FId = id;
예제 #13
0
 internal void Init(DataStorage storage, DataId id, ObjectSessionState state)
 {
     this.FStorage      = storage;
     this.FId           = id;
     this.FSessionState = state;
 }
예제 #14
0
 internal DataObject GetCachedObject(DataId id) => this.FObjects[id];
 public string GetObjectFolder(MetadataClass cls, DataId id) => Path.Combine(Path.Combine(this.DefaultFolder, cls.IdentName), id.ToString());
예제 #16
0
        internal DataObject EnsureCacheItem(DataId id)
        {
            DataObject dataObject;

            return(id.IsEmpty ? this.NullObject : (this.FObjects.TryGetValue(id, out dataObject) ? dataObject : this.NewCacheItem(id, (ObjectSessionState)0)));
        }
예제 #17
0
 internal void RemoveObjectFromCache(DataId id) => this.FObjects.Remove(id);
예제 #18
0
 internal void DequeueObjectFromUpdate(DataId id) => this.FObjectsToUpdate.Remove(id);
예제 #19
0
 internal bool IsObjectCached(DataId id) => this.FObjects.ContainsKey(id);
예제 #20
0
 public DataId(DataId id) => this.FValue = id.FValue;
예제 #21
0
 public DataObject QueryObject(string loadPlan, DataId id) => this.QueryObject(this.CreatePlanFromString(loadPlan), id);