/// <summary> /// Gets the component map ids. /// </summary> /// <param name="state"> /// The state. /// </param> /// <param name="dsdReference"> /// The DSD reference. /// </param> /// <returns> /// The component id to primary key value dictionary /// </returns> public static IDictionary<string, long> GetComponentMapIds(DbTransactionState state, IStructureReference dsdReference) { IDictionary<string, long> map = new Dictionary<string, long>(StringComparer.Ordinal); var idParameter = state.Database.CreateInParameter("p_id", DbType.AnsiString, dsdReference.MaintainableId); var agencyParameter = state.Database.CreateInParameter("p_agency", DbType.AnsiString, dsdReference.AgencyId); var versionParameter = state.Database.CreateInParameter("p_version", DbType.AnsiString, dsdReference.Version); var queryFormat = dsdReference.MaintainableStructureEnumType.EnumType == SdmxStructureEnumType.Dsd ? "select c.COMP_ID, c.ID from COMPONENT c inner join ARTEFACT_VIEW a on a.ART_ID = c.DSD_ID where a.ID = {0} and a.AGENCY = {1} and a.VERSION = {2}" : "select c.COMP_ID, c.ID from COMPONENT c inner join DATAFLOW d on d.DSD_ID = c.DSD_ID inner join ARTEFACT_VIEW a on a.ART_ID = d.DF_ID where a.ID = {0} and a.AGENCY = {1} and a.VERSION = {2}"; using (var command = state.Database.GetSqlStringCommandFormat(queryFormat, idParameter, agencyParameter, versionParameter)) using (var reader = state.Database.ExecuteReader(command)) { var sysIdOrdinal = reader.GetOrdinal("COMP_ID"); var idOrdinal = reader.GetOrdinal("ID"); while (reader.Read()) { map.Add(reader.GetString(idOrdinal), reader.GetInt64(sysIdOrdinal)); } } return map; }
/// <summary> /// Insert a record with the values from <paramref name="annotations"/> to <paramref name="annotationProcedureBase"/> /// for an artifact with the specified /// <paramref name="annotatablePrimaryKey"/> /// </summary> /// <param name="state"> /// The mapping store connection and transaction state /// </param> /// <param name="annotatablePrimaryKey"> /// The artifact primary key. /// </param> /// <param name="annotationProcedureBase"> /// The annotation procedure base. /// </param> /// <param name="annotations"> /// The annotations. /// </param> public void Insert(DbTransactionState state, long annotatablePrimaryKey, AnnotationProcedureBase annotationProcedureBase, IList<IAnnotation> annotations) { this._decorated.Insert( state, annotatablePrimaryKey, annotationProcedureBase, annotations.Where(annotation => !string.Equals(annotation.Title, AnnotationConstant.CodeTimeDimensionTitle)).ToArray()); }
/// <summary> /// Deletes annotations for annotatoble with the specified <paramref name="annotableSysId"/> and the specified <paramref name="type"/> /// </summary> /// <param name="state">The state.</param> /// <param name="annotableSysId">The annotable system identifier.</param> /// <param name="type">The type.</param> /// <param name="structureType">Type of the structure.</param> /// <returns>The number of annotations deleted.</returns> public int DeleteByType(DbTransactionState state, long annotableSysId, string type, SdmxStructureType structureType) { var annotationRelationTable = this._annotationRelationInfoBuilder.Build(structureType); var query = string.Format( CultureInfo.InvariantCulture, "DELETE FROM ANNOTATION WHERE ANN_ID IN (SELECT DISTINCT ANN_ID FROM {0} WHERE {1} = {{0}} AND TYPE={{1}})", annotationRelationTable.Table, annotationRelationTable.PrimaryKey); return state.Database.ExecuteNonQueryFormat(query, this._mappingStoreDatabase.CreateInParameter("p_id", DbType.Int64, annotableSysId), this._mappingStoreDatabase.CreateInParameter("p_type", DbType.String, type)); }
/// <summary> /// Insert a record with the values from <paramref name="annotations" /> to <paramref name="annotationProcedureBase" /> for an artifact with the specified /// <paramref name="annotatablePrimaryKey" /> /// </summary> /// <param name="state">The mapping store connection and transaction state</param> /// <param name="annotatablePrimaryKey">The artifact primary key.</param> /// <param name="annotationProcedureBase">The annotation procedure base.</param> /// <param name="annotations">The annotations.</param> public void Insert(DbTransactionState state, long annotatablePrimaryKey, AnnotationProcedureBase annotationProcedureBase, IList<IAnnotation> annotations) { var count = annotations.Count; if (count == 0) { return; } var sysIdToAnnotation = new KeyValuePair<long, IAnnotation>[count]; using (var command = annotationProcedureBase.CreateCommandWithDefaults(state)) { annotationProcedureBase.CreateParentIdParameter(command, annotatablePrimaryKey); var outputParameter = annotationProcedureBase.CreateOutputParameter(command); for (int i = 0; i < count; i++) { var annotation = annotations[i]; annotationProcedureBase.CreateIdParameter(command, annotation.Id); annotationProcedureBase.CreateTitleParameter(command, annotation.Title); annotationProcedureBase.CreateTypeParameter(command, annotation.Type); annotationProcedureBase.CreateUriParameter(command, annotation.Uri != null ? annotation.Uri.ToString() : null); command.ExecuteNonQuery(); if (annotation.Text.Count > 0) { sysIdToAnnotation[i] = new KeyValuePair<long, IAnnotation>((long)outputParameter.Value, annotation); } } } using (var command = this._annotationText.CreateCommandWithDefaults(state)) { for (int i = 0; i < sysIdToAnnotation.Length; i++) { var keyValuePair = sysIdToAnnotation[i]; if (!keyValuePair.IsDefault()) { this._annotationText.CreateAnnIdParameter(command).Value = keyValuePair.Key; foreach (var textTypeWrapper in keyValuePair.Value.Text) { this._annotationText.CreateLanguageParameter(command).Value = GetLanguage(textTypeWrapper); this._annotationText.CreateTextParameter(command).Value = textTypeWrapper.Value; command.ExecuteNonQuery(); } } } } }
/// <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> /// Returns the <c>ITEM.ITEM_ID</c> value from Mapping Store for <paramref name="artefactId"/> /// </summary> /// <param name="state"> /// The state. /// </param> /// <param name="sdmxStructure"> /// The SDMX Structure. /// </param> /// <param name="artefactId"> /// The artefact primary key. <c>ARTEFACT.ART_ID</c>. /// </param> /// <returns> /// The <c>ITEM.ITEM_ID</c> value from Mapping Store for <paramref name="artefactId"/> /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="state"/> is null /// </exception> /// <exception cref="ArgumentException"> /// At <paramref name="sdmxStructure"/>, unsupported structure /// </exception> public static ItemStatusCollection GetId(DbTransactionState state, SdmxStructureEnumType sdmxStructure, long artefactId) { if (state == null) { throw new ArgumentNullException("state"); } var tableInfo = _tableInfoBuilder.Build(sdmxStructure); if (tableInfo == null) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.ExceptionUnsupportedStructureReferenceFormat1, sdmxStructure), "sdmxStructure"); } var itemIdQueryBuilder = new ItemIdQueryBuilder(state.Database); var query = itemIdQueryBuilder.Build(tableInfo); return new ItemStatusCollection(state.Connection.Query<ItemStatus>( query, new { id = artefactId }, state.Transaction, false)); }
/// <summary> /// Creates a new instance of a <see cref="DbCommand"/> for the stored procedure with the specified <paramref name="state"/> /// </summary> /// <param name="stored"> /// The stored. /// </param> /// <param name="state"> /// The state. /// </param> /// <returns> /// a new instance of a <see cref="DbCommand"/> for the stored procedure with the specified <paramref name="state"/> /// </returns> /// <remarks> /// It sets the following <see cref="DbCommand"/> properties <see cref="DbCommand.Connection"/> , <see cref="DbCommand.Transaction"/> , <see cref="DbCommand.CommandType"/> and <see cref="DbCommand.CommandText"/> /// </remarks> public static DbCommand CreateCommandWithDefaults(this IProcedure stored, DbTransactionState state) { return stored.CreateCommandWithDefaults(state.Database); }
/// <summary> /// Creates a new instance of a <see cref="DbCommand"/> for the stored procedure with the specified <paramref name="state"/> /// </summary> /// <param name="stored"> /// The stored. /// </param> /// <param name="state"> /// The state. /// </param> /// <returns> /// a new instance of a <see cref="DbCommand"/> for the stored procedure with the specified <paramref name="state"/> /// </returns> /// <remarks> /// It sets the following <see cref="DbCommand"/> properties <see cref="DbCommand.Connection"/> , <see cref="DbCommand.Transaction"/> , <see cref="DbCommand.CommandType"/> and <see cref="DbCommand.CommandText"/> /// </remarks> public static DbCommand CreateCommand(this IProcedure stored, DbTransactionState state) { return stored.CreateCommand(state.Connection, state.Transaction); }
/// <summary> /// Returns a <see cref="TextFormatTypesQueryEngine" /> instance for the specified <paramref name="state" /> /// </summary> /// <param name="state">The mapping store database</param> /// <returns> /// The <see cref="TextFormatTypesQueryEngine" />. /// </returns> public static TextFormatTypesQueryEngine GetTextFormatQuery(DbTransactionState state) { return _databaseMap.GetOrAdd(state.Database, settings => new TextFormatTypesQueryEngine(state)); }
/// <summary> /// Gets the CodeList status. /// </summary> /// <param name="state"> /// The state. /// </param> /// <param name="reference"> /// The reference. /// </param> /// <param name="itemScheme"> /// The item scheme. /// </param> /// <returns> /// The <see cref="ItemSchemeFinalStatus"/>. /// </returns> public ItemSchemeFinalStatus GetReferenceStatus(DbTransactionState state, IStructureReference reference, StructureCache itemScheme) { ItemSchemeFinalStatus codelistStatus = itemScheme.GetStructure(state, reference); this.ValidateFinalStatus(codelistStatus.FinalStatus, reference); return codelistStatus; }