internal MetadataClass(ApplicationMetadata metadata, string name, int index) { this.Metadata = metadata; this.Name = name; this.Index = index; string str = name.Replace('/', '.'); this.QTypeName = "InMeta." + str; this.IdentName = name.Replace('/', '_'); int length = str.LastIndexOf("."); if (length >= 0) { this.TypeNamespace = str.Substring(0, length); this.TypeName = str.Substring(length + 1, str.Length - length - 1); } else { this.TypeNamespace = string.Empty; this.TypeName = str; } this.Properties = new MetadataPropertyList(); this.AllProperties = new MetadataPropertyList(); this.Associations = new MetadataAssociationList(); this.Owners = new MetadataAssociationList(); this.Childs = new MetadataChildRefList(this); this.ObjectViews = new MetadataObjectViewList(this); this.ExternalRefs = new MetadataAssociationRefList(); }
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); }
internal override object GetValue() { object obj = base.GetValue(); if (obj != null) { return(obj); } MetadataAssociationRefList refs = this.Metadata.Association.Refs; return(this.Metadata.Association.Selector == null ? (object)this.Session[refs[0].RefClass].NullObject : (object)this.Session.UntypedNullObject); }
public SqlUtils.NavigationStep EnsureRootStep(string path) { SqlUtils.NavigationStep navigationStep1 = !string.IsNullOrEmpty(path) ? this.FindRootStep(path) : throw new ArgumentNullException(nameof(path)); if (navigationStep1 != null) { return(navigationStep1); } string predecessorPath; string identifier; MetadataClass refClass1; bool isExternalRef; SqlUtils.Navigation.ParseLastPartOfPath(this.Class.Metadata.Classes, path, out predecessorPath, out identifier, out refClass1, out isExternalRef); SqlUtils.NavigationStep predecessor = !string.IsNullOrEmpty(predecessorPath) ? this.EnsureRootStep(predecessorPath) : (SqlUtils.NavigationStep)null; MetadataClass refClass2 = predecessor != null ? predecessor.TargetClass : this.Class; SqlUtils.NavigationStep navigationStep2; if (isExternalRef) { MetadataProperty metadataProperty = refClass1.Properties.Need(identifier); if (!metadataProperty.IsLink) { throw new Exception(string.Format("Свойство \"{0}.{1}\" не является отношением.", (object)refClass1.Name, (object)identifier)); } navigationStep2 = (SqlUtils.NavigationStep) new SqlUtils.ExternalAssociationNavigationStep(this, predecessor, path, metadataProperty.Association.Refs.Need(refClass2)); } else { MetadataProperty property; MetadataChildRef childRef; refClass2.NeedMember(identifier, out property, out childRef); if (property != null) { if (!property.IsLink) { throw new DataException(string.Format("\"{0}\" не является ассоциацией или дочерним объектом.", (object)identifier)); } MetadataAssociationRefList refs = property.Association.Refs; if (refClass1 == null && refs.Count != 1) { throw new DataException(string.Format("\"{0}\" является ассоциацией с вариантами связи. В тексте запроса такое поле следует указывать в форме \"имя-свойства:имя-связанного-класса\" (например, \"Subject:Person\").", (object)identifier)); } navigationStep2 = (SqlUtils.NavigationStep) new SqlUtils.AssociationNavigationStep(this, predecessor, path, refClass1 == null ? refs[0] : refs.Need(refClass1)); } else { navigationStep2 = (SqlUtils.NavigationStep) new SqlUtils.ChildNavigationStep(this, predecessor, path, childRef); } } navigationStep2.TargetAlias = this.CreateUniqueAlias(navigationStep2.TargetClass.DataTable); this.RootSteps.Add(navigationStep2); return(navigationStep2); }
protected internal DataProperty CreatePropertyInstance( MetadataProperty propertyMetadata) { switch (propertyMetadata.Purpose) { case MetadataPropertyPurpose.Data: DataType dataType = propertyMetadata.DataType & DataType.BaseMask; switch (dataType) { case DataType.Boolean: return((DataProperty) new BooleanProperty(this, propertyMetadata)); case DataType.Integer: return((DataProperty) new IntegerProperty(this, propertyMetadata)); case DataType.Float: return((DataProperty) new DoubleProperty(this, propertyMetadata)); case DataType.Currency: return((DataProperty) new CurrencyProperty(this, propertyMetadata)); case DataType.DateTime: return((DataProperty) new DateTimeProperty(this, propertyMetadata)); case DataType.String: return((DataProperty) new StringProperty(this, propertyMetadata)); case DataType.Memo: return((DataProperty) new StringProperty(this, propertyMetadata)); case DataType.Binary: return((DataProperty) new BinaryProperty(this, propertyMetadata)); default: throw new DataException(string.Format("Некорректный тип данных {0} свойства {1} объекта {2}", (object)dataType, (object)propertyMetadata.Name, (object)this.FStorage.Class.Name)); } case MetadataPropertyPurpose.Association: case MetadataPropertyPurpose.Aggregation: MetadataAssociationRefList refs = propertyMetadata.Association.Refs; return(propertyMetadata.Association.Selector == null ? (DataProperty)this.Session[refs[0].RefClass].CreateLinkPropertyInstance(this, propertyMetadata) : (DataProperty) new LinkProperty(this, propertyMetadata)); default: throw new System.Data.DataException("Попытка создания объекта доступа к свойству ID."); } }
internal override int SaveValueToDb(ref object value, ref object exValue) { if (!this.IsAssigned) { throw new DataException("Попытка записать в БД неприсвоенное значение."); } MetadataAssociationRefList refs = this.Metadata.Association.Refs; DataObject dataObject = (DataObject)base.GetValue(); if (dataObject != null && !dataObject.IsNull) { value = (object)dataObject.Id.ToString(); if (this.Metadata.Association.Selector != null) { exValue = InDbUtils.Convert((object)refs.Need(dataObject.Class).SelectorValue, this.Metadata.Association.Selector.DataType); } } return(this.Metadata.Association.Selector != null ? 2 : 1); }
internal MetadataAssociation(MetadataProperty property) { this.Property = property; this.Property.SetAssociation(this); this.Refs = new MetadataAssociationRefList(); }