示例#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);
        }
        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);
        }
 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;
 }
        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);
                }
            }
        }
        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);
        }
        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));
             }
         }
     }
 }
        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);
            }
        }
 public string GetObjectFolder(MetadataClass cls, DataId id) => Path.Combine(Path.Combine(this.DefaultFolder, cls.IdentName), id.ToString());
 internal void RemoveObjectFromCache(DataId id) => this.FObjects.Remove(id);
 internal void DequeueObjectFromUpdate(DataId id) => this.FObjectsToUpdate.Remove(id);
 internal bool IsObjectCached(DataId id) => this.FObjects.ContainsKey(id);
 internal DataObject GetCachedObject(DataId id) => this.FObjects[id];
        internal DataObject EnsureCacheItem(DataId id)
        {
            DataObject dataObject;

            return(id.IsEmpty ? this.NullObject : (this.FObjects.TryGetValue(id, out dataObject) ? dataObject : this.NewCacheItem(id, (ObjectSessionState)0)));
        }
 internal void Init(DataStorage storage, DataId id, ObjectSessionState state)
 {
     this.FStorage      = storage;
     this.FId           = id;
     this.FSessionState = state;
 }
 internal void SetNewId(DataId id) => this.FId = id;
示例#20
0
 public DataId(DataId id) => this.FValue = id.FValue;
 public DataObject QueryObject(string loadPlan, DataId id) => this.QueryObject(this.CreatePlanFromString(loadPlan), id);