/// <summary> /// Gets the structure. /// </summary> /// <param name="state">The state.</param> /// <param name="reference">The reference.</param> /// <returns>The <see cref="ItemStatusCollection"/></returns> public ItemSchemeFinalStatus GetStructure(DbTransactionState state, IStructureReference reference) { ItemSchemeFinalStatus returnObjet; if (!this._dictionary.TryGetValue(reference, out returnObjet)) { var artefactFinalStatus = ArtefactBaseEngine.GetFinalStatus(state, reference); ItemStatusCollection collection = null; if (artefactFinalStatus != null && artefactFinalStatus.IsFinal && reference.HasChildReference()) { switch (reference.TargetReference.EnumType) { case SdmxStructureEnumType.Component: case SdmxStructureEnumType.Dimension: case SdmxStructureEnumType.TimeDimension: case SdmxStructureEnumType.MeasureDimension: case SdmxStructureEnumType.DataAttribute: case SdmxStructureEnumType.PrimaryMeasure: case SdmxStructureEnumType.CrossSectionalMeasure: var map = GetComponentMapIds(state, reference); collection = new ItemStatusCollection(map.Select(pair => new ItemStatus(pair.Key, pair.Value))); break; default: collection = GetId(state, reference.TargetReference.EnumType, artefactFinalStatus.PrimaryKey); break; } } returnObjet = new ItemSchemeFinalStatus(artefactFinalStatus ?? ArtefactFinalStatus.Empty, collection); } return(returnObjet); }
/// <summary> /// Insert the specified <paramref name="items"/> to the mapping store with <paramref name="state"/> /// </summary> /// <param name="state"> /// The MAPPING STORE connection and transaction state /// </param> /// <param name="items"> /// The items. /// </param> /// <param name="parentArtefact"> /// The primary key of the parent artefact. /// </param> /// <returns> /// The <see cref="IEnumerable{Long}"/>. /// </returns> public ItemStatusCollection Insert(DbTransactionState state, IEnumerable <IComponent> items, long parentArtefact) { var components = items as IComponent[] ?? items.ToArray(); if (components.Length == 0) { return(new ItemStatusCollection()); } var cache = new StructureCache(); var returnValues = new ItemStatusCollection(); var dsd = components[0].MaintainableParent as IDataStructureObject; if (dsd == null) { throw new ArgumentException(Resources.ExceptionCannotDetermineParent, "items"); } foreach (var component in components) { returnValues.Add(new ItemStatus(component.Id, Insert(state, component, cache, parentArtefact))); } return(returnValues); }
/// <summary> /// Insert the specified <paramref name="maintainable"/> to the mapping store with <paramref name="state"/> /// </summary> /// <param name="state"> /// The MAPPING STORE connection and transaction state /// </param> /// <param name="maintainable"> /// The maintainable. /// </param> /// <returns> /// The <see cref="ArtefactImportStatus"/>. /// </returns> public override ArtefactImportStatus Insert(DbTransactionState state, IDataStructureObject maintainable) { _log.DebugFormat(CultureInfo.InvariantCulture, "Importing artefact {0}", maintainable.Urn); var artefactStoredProcedure = _artefactStoredProcedure; var artefactStatus = this.InsertArtefactInternal(state, maintainable, artefactStoredProcedure); ItemStatusCollection groups = this._groupImport.Insert(state, maintainable.Groups, artefactStatus.PrimaryKeyValue); ItemStatusCollection components = this._componentImport.Insert(state, maintainable.GetAllComponents(), artefactStatus.PrimaryKeyValue); InsertDimensionGroup(state, maintainable, groups, components); InsertAttributeGroup(state, maintainable, groups, components); InsertAttributeDimensions(state, maintainable, components); InsertAttributeAttachmentMeasures(state, maintainable, components); this.InsertAsDataflow(state, maintainable, artefactStatus); return(artefactStatus); }
/// <summary> /// Insert the specified <paramref name="items"/> to the mapping store with <paramref name="state"/> /// </summary> /// <param name="state"> /// The MAPPING STORE connection and transaction state /// </param> /// <param name="items"> /// The items. /// </param> /// <param name="parentArtefact"> /// The primary key of the parent artefact. /// </param> /// <returns> /// The <see cref="IEnumerable{Long}"/>. /// </returns> public ItemStatusCollection Insert(DbTransactionState state, IEnumerable <IGroup> items, long parentArtefact) { var storedProcedure = _insertDsdGroup; var annotations = new List <Tuple <long, IGroup> >(); var groupIds = new ItemStatusCollection(); using (DbCommand command = storedProcedure.CreateCommand(state)) { DbParameter dsdParameter = storedProcedure.CreateDsdIdParameter(command); DbParameter idParameter = storedProcedure.CreateIdParameter(command); DbParameter outputParameter = storedProcedure.CreateOutputParameter(command); foreach (var group in items) { idParameter.Value = group.Id; dsdParameter.Value = parentArtefact; command.ExecuteNonQuery(); var id = (long)outputParameter.Value; groupIds.Add(new ItemStatus(group.Id, id)); if (group.Annotations.Count > 0) { annotations.Add(new Tuple <long, IGroup>(id, group)); } } } foreach (var annotation in annotations) { IAnnotableObject annotableObject = annotation.Item2; _annotationInsertEngine.Insert(state, annotation.Item1, _insertGroupAnnotation, annotableObject.Annotations); } return(groupIds); }
/// <summary> /// Gets the structure. /// </summary> /// <param name="state">The state.</param> /// <param name="reference">The reference.</param> /// <returns>The <see cref="ItemStatusCollection"/></returns> public ItemSchemeFinalStatus GetStructure(DbTransactionState state, IStructureReference reference) { ItemSchemeFinalStatus returnObjet; if (!this._dictionary.TryGetValue(reference, out returnObjet)) { var artefactFinalStatus = ArtefactBaseEngine.GetFinalStatus(state, reference); ItemStatusCollection collection = null; if (artefactFinalStatus != null && artefactFinalStatus.IsFinal && reference.HasChildReference()) { switch (reference.TargetReference.EnumType) { case SdmxStructureEnumType.Component: case SdmxStructureEnumType.Dimension: case SdmxStructureEnumType.TimeDimension: case SdmxStructureEnumType.MeasureDimension: case SdmxStructureEnumType.DataAttribute: case SdmxStructureEnumType.PrimaryMeasure: case SdmxStructureEnumType.CrossSectionalMeasure: var map = GetComponentMapIds(state, reference); collection = new ItemStatusCollection(map.Select(pair => new ItemStatus(pair.Key, pair.Value))); break; default: collection = GetId(state, reference.TargetReference.EnumType, artefactFinalStatus.PrimaryKey); break; } } returnObjet = new ItemSchemeFinalStatus(artefactFinalStatus ?? ArtefactFinalStatus.Empty, collection); } return returnObjet; }
/// <summary> /// Initializes a new instance of the <see cref="ItemSchemeFinalStatus"/> class. /// </summary> /// <param name="finalStatus"> /// The final Status. /// </param> /// <param name="itemIdMap"> /// The item Id Map. /// </param> public ItemSchemeFinalStatus(ArtefactFinalStatus finalStatus, ItemStatusCollection itemIdMap) { this.ItemIdMap = itemIdMap; this.FinalStatus = finalStatus; }
/// <summary> /// Initializes a new instance of the <see cref="ItemSchemeFinalStatus"/> class. /// </summary> /// <param name="finalStatus"> /// The final Status. /// </param> /// <param name="itemIdMap"> /// The item Id Map. /// </param> public ItemSchemeFinalStatus(ArtefactFinalStatus finalStatus, ItemStatusCollection itemIdMap) { this.ItemIdMap = itemIdMap; this.FinalStatus = finalStatus; }
/// <summary> /// Insert attribute group. /// </summary> /// <param name="state"> /// The state. /// </param> /// <param name="dsd"> /// The DSD. /// </param> /// <param name="groups"> /// The groups. /// </param> /// <param name="components"> /// The components. /// </param> private static void InsertAttributeGroup(DbTransactionState state, IDataStructureObject dsd, ItemStatusCollection groups, ItemStatusCollection components) { var parameterList = new List <DbParameter[]>(); foreach (var attributeObject in dsd.GroupAttributes) { ItemStatus dsdGroupStatus; if (attributeObject.AttachmentGroup != null && groups.TryGetValue(attributeObject.AttachmentGroup, out dsdGroupStatus)) { ItemStatus attributeStatus; if (components.TryGetValue(attributeObject.Id, out attributeStatus)) { var parameters = new DbParameter[2]; parameters[0] = state.Database.CreateInParameter(IdParameter, DbType.Int64, attributeStatus.SysID); parameters[1] = state.Database.CreateInParameter(GroupIdParameter, DbType.Int64, dsdGroupStatus.SysID); parameterList.Add(parameters); } } } state.ExecuteNonQueryFormat("insert into ATT_GROUP (COMP_ID, GR_ID) VALUES ({0}, {1})", parameterList); }
/// <summary> /// Inserts the attribute attachment measures. (SDMX V2.0 only) /// </summary> /// <param name="state">The state.</param> /// <param name="dsd">The DSD.</param> /// <param name="components">The components.</param> private static void InsertAttributeAttachmentMeasures(DbTransactionState state, IDataStructureObject dsd, ItemStatusCollection components) { var cross = dsd as ICrossSectionalDataStructureObject; if (cross == null) { // it is not a SDXM v2.0 cross sectional DSD therefor there are no Measure dimensions or CrossSectional measures. return; } var parameterList = new List <DbParameter[]>(); foreach (var attributeObject in cross.Attributes) { ItemStatus attributeStatus; if (components.TryGetValue(attributeObject.Id, out attributeStatus)) { foreach (var crossSectionalMeasure in cross.GetAttachmentMeasures(attributeObject)) { ItemStatus measureStatus; if (components.TryGetValue(crossSectionalMeasure.Id, out measureStatus)) { var parameters = new DbParameter[2]; parameters[0] = state.Database.CreateInParameter(IdParameter, DbType.Int64, attributeStatus.SysID); parameters[1] = state.Database.CreateInParameter("measureId", DbType.Int64, measureStatus.SysID); parameterList.Add(parameters); } } } } state.ExecuteNonQueryFormat("insert into ATT_MEASURE (ATT_COMP_ID, MEASURE_COMP_ID) VALUES ({0}, {1})", parameterList); }
/// <summary> /// Insert attribute group. /// </summary> /// <param name="state"> /// The state. /// </param> /// <param name="dsd"> /// The DSD. /// </param> /// <param name="components"> /// The components. /// </param> private static void InsertAttributeDimensions(DbTransactionState state, IDataStructureObject dsd, ItemStatusCollection components) { var parameterList = new List <DbParameter[]>(); foreach (var attributeObject in dsd.DimensionGroupAttributes) { ItemStatus attributeStatus; if (components.TryGetValue(attributeObject.Id, out attributeStatus)) { foreach (var dimensionReference in attributeObject.DimensionReferences) { ItemStatus dimensionStatus; if (components.TryGetValue(dimensionReference, out dimensionStatus)) { var parameters = new DbParameter[2]; parameters[0] = state.Database.CreateInParameter(IdParameter, DbType.Int64, attributeStatus.SysID); parameters[1] = state.Database.CreateInParameter(GroupIdParameter, DbType.Int64, dimensionStatus.SysID); parameterList.Add(parameters); } } } } state.ExecuteNonQueryFormat("insert into ATTR_DIMS (ATTR_ID, DIM_ID) VALUES ({0}, {1})", parameterList); }
/// <summary> /// Insert dimension group. /// </summary> /// <param name="state"> /// The state. /// </param> /// <param name="dsd"> /// The DSD. /// </param> /// <param name="groups"> /// The groups. /// </param> /// <param name="components"> /// The components. /// </param> private static void InsertDimensionGroup(DbTransactionState state, IDataStructureObject dsd, ItemStatusCollection groups, ItemStatusCollection components) { var parameterList = new List <DbParameter[]>(); foreach (var dsdGroup in dsd.Groups) { ItemStatus dsdGroupStatus; if (groups.TryGetValue(dsdGroup.Id, out dsdGroupStatus)) { foreach (var dimensionRef in dsdGroup.DimensionRefs) { ItemStatus dimensionStatus; if (components.TryGetValue(dimensionRef, out dimensionStatus)) { var parameters = new DbParameter[2]; parameters[0] = state.Database.CreateInParameter(IdParameter, DbType.Int64, dimensionStatus.SysID); parameters[1] = state.Database.CreateInParameter(GroupIdParameter, DbType.Int64, dsdGroupStatus.SysID); parameterList.Add(parameters); } } } } state.ExecuteNonQueryFormat("insert into DIM_GROUP (COMP_ID, GR_ID) VALUES ({0}, {1})", parameterList); }