/// <summary> /// Retrieve the <see cref="IDataStructureMutableObject"/> from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="versionConstraints"> /// The version query type. /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <returns> /// The <see cref="ISet{IDataStructureMutableObject}"/>. /// </returns> public override ISet <ICategorisationMutableObject> Retrieve( IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, VersionQueryType versionConstraints, IList <IMaintainableRefObject> allowedDataflows) { var sqlInfo = versionConstraints == VersionQueryType.Latest ? this.SqlQueryInfoForLatest : this.SqlQueryInfoForAll; var categorisations = this.GetCategorisations(maintainableRef, ComplexStructureQueryDetailEnumType.Full, sqlInfo, allowedDataflows); NormalizeDetailLevel(detail, categorisations); return(categorisations); }
/// <summary> /// Returns the categorisations. /// </summary> /// <param name="maintainableRef"> /// The maintainable ref. /// </param> /// <param name="detail"> /// The detail. /// </param> /// <param name="sqlInfo"> /// The SQL info. /// </param> /// <param name="allowedDataflows"> /// The allowed dataflows. /// </param> /// <returns> /// The <see cref="ISet{ICategorisationMutableObject}"/>. /// </returns> private ISet <ICategorisationMutableObject> GetCategorisations( IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, SqlQueryInfo sqlInfo, IList <IMaintainableRefObject> allowedDataflows) { var artefactSqlQuery = new ArtefactSqlQuery(sqlInfo, maintainableRef); var dataflowCache = new Dictionary <long, IStructureReference>(); var categoryCache = new Dictionary <long, IStructureReference>(); this.RetrieveArtefactReference(dataflowCache, allowedDataflows); this.RetrieveCategoryReference(categoryCache); return(this.RetrieveArtefacts(artefactSqlQuery, detail, null, (o, l) => RetrieveReferences(o, l, l1 => GetReference(l1, dataflowCache), l1 => GetReference(l1, categoryCache)))); }
/// <summary> /// Retrieve the set of <see cref="IMaintainableMutableObject"/> from Mapping Store that references /// <paramref name="referencedStructure"/> /// . /// </summary> /// <param name="referencedStructure"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. This is the referenced structure. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="referencedStructure"/> is null. /// </exception> /// <returns> /// The <see cref="ISet{IMaintainableMutableObject}"/>. /// </returns> public override ISet <ICategorisationMutableObject> RetrieveFromReferenced( IStructureReference referencedStructure, ComplexStructureQueryDetailEnumType detail, IList <IMaintainableRefObject> allowedDataflows) { if (referencedStructure == null) { throw new ArgumentNullException("referencedStructure"); } var dataflowCache = new Dictionary <long, IStructureReference>(); var categoryCache = new Dictionary <long, IStructureReference>(); this.RetrieveArtefactReference(dataflowCache, allowedDataflows); this.RetrieveCategoryReference(categoryCache); var retrieveFromReferencedInternal = this.RetrieveFromReferencedInternal(referencedStructure, ComplexStructureQueryDetailEnumType.Full, null, (o, l) => RetrieveReferences(o, l, l1 => GetReference(l1, dataflowCache), l1 => GetReference(l1, categoryCache))); NormalizeDetailLevel(detail, retrieveFromReferencedInternal); return(retrieveFromReferencedInternal); }
/// <summary> /// Handles the detail level. /// </summary> /// <param name="detail">The detail.</param> /// <param name="retrieveDetails">The retrieve details.</param> /// <param name="artefactPkPairs">The artefact - primary key pairs.</param> /// <returns>The artefacts.</returns> private ISet <T> HandleDetailLevel(ComplexStructureQueryDetailEnumType detail, Func <T, long, T> retrieveDetails, IEnumerable <KeyValuePair <T, long> > artefactPkPairs) { ISet <T> artefacts = new HashSet <T>(); foreach (var artefactPkPair in artefactPkPairs) { var artefact = artefactPkPair.Key; var sysId = artefactPkPair.Value; switch (detail) { case ComplexStructureQueryDetailEnumType.MatchedItems: break; case ComplexStructureQueryDetailEnumType.CascadedMatchedItems: break; case ComplexStructureQueryDetailEnumType.Null: case ComplexStructureQueryDetailEnumType.Full: artefact = retrieveDetails(artefact, sysId); break; case ComplexStructureQueryDetailEnumType.CompleteStub: case ComplexStructureQueryDetailEnumType.Stub: artefact.ExternalReference = SdmxObjectUtil.CreateTertiary(true); artefact.Stub = true; artefact.StructureURL = DefaultUri; break; } if (!artefact.IsDefault()) { artefacts.Add(artefact); if (detail != ComplexStructureQueryDetailEnumType.Stub) { this._maintainableAnnotationRetrieverEngine.RetrieveAnnotations(sysId, artefact); } } } return(artefacts); }
/// <summary> /// Normalizes the detail level. /// </summary> /// <param name="detail">The detail.</param> /// <param name="categorisations">The categorisations.</param> private static void NormalizeDetailLevel(ComplexStructureQueryDetailEnumType detail, IEnumerable <ICategorisationMutableObject> categorisations) { foreach (var categorisation in categorisations) { switch (detail) { case ComplexStructureQueryDetailEnumType.CompleteStub: categorisation.ExternalReference = SdmxObjectUtil.CreateTertiary(true); categorisation.Stub = true; categorisation.StructureURL = DefaultUri; categorisation.CategoryReference = null; categorisation.StructureReference = null; break; case ComplexStructureQueryDetailEnumType.Stub: categorisation.Descriptions.Clear(); goto case ComplexStructureQueryDetailEnumType.CompleteStub; } } }
/// <summary> /// Read the localized string from <paramref name="dataReader"/> /// </summary> /// <param name="item"> /// The <see cref="INameableMutableObject"/> . /// </param> /// <param name="typeIdx"> /// The <c>LOCALISED_STRING.TYPE</c> ordinal /// </param> /// <param name="txtIdx"> /// The <c>LOCALISED_STRING.TEXT</c> ordinal /// </param> /// <param name="langIdx"> /// The <c>LOCALISED_STRING.LANGUAGE</c> ordinal /// </param> /// <param name="dataReader"> /// The MASTORE DB <see cref="IDataReader"/> /// </param> /// <param name="detail">The Structure Query Detail</param> protected static void ReadLocalisedString(INameableMutableObject item, int typeIdx, int txtIdx, int langIdx, IDataRecord dataReader, ComplexStructureQueryDetailEnumType detail = ComplexStructureQueryDetailEnumType.Full) { //// TODO support SDMX-ML Query detail CompleteStub versus Stub when Common API supports it. //// When it is stub then only name should be returned. //// When it is complete stub both name and description. //// Now we use StructureQueryDetail which is for REST queries only. //// According to the http://sdmx.org/wp-content/uploads/2012/05/SDMX_2_1-SECTION_07_WebServicesGuidelines_May2012.pdf //// page 10, footnotes 10-12 REST AllStubs == SDMX-ML Query Stub so in that case we skip description var value = DataReaderHelper.GetString(dataReader, txtIdx); var locale = DataReaderHelper.GetString(dataReader, langIdx); string type = DataReaderHelper.GetString(dataReader, typeIdx); var textType = new TextTypeWrapperMutableCore { Locale = locale, Value = value }; switch (type) { case LocalisedStringType.Name: item.Names.Add(textType); break; case LocalisedStringType.Desc: if (detail != ComplexStructureQueryDetailEnumType.Stub) { item.Descriptions.Add(textType); } break; default: _log.WarnFormat(CultureInfo.InvariantCulture, "Unknown type at LOCALISATION.TYPE : '{0}', Locale: '{1}', Text:'{2}'", type, locale, value); if (item.Names.Count == 0) { item.AddName(null, !string.IsNullOrWhiteSpace(value) ? value : item.Id); } break; } }
/// <summary> /// Retrieve the common <see cref="IMaintainableMutableObject"/> information from Mapping Store ARTEFACT table. This method does not retrieve the Names and Description /// </summary> /// <param name="sqlQuery"> /// The SQL Query for artefacts /// </param> /// <param name="detail"> /// The structure query detail /// </param> /// <param name="commandBuilder"> /// The command Builder. /// </param> /// <param name="retrieveDetails"> /// The method to retrieve details of the artefacts /// </param> /// <param name="extraFields"> /// The extra Fields. /// </param> /// <returns> /// A dictionary with key the primary key in Mapping Store /// </returns> protected ISet <T> RetrieveArtefacts(ArtefactSqlQuery sqlQuery, ComplexStructureQueryDetailEnumType detail, Func <ArtefactSqlQuery, DbCommand> commandBuilder = null, Func <T, long, T> retrieveDetails = null, Action <T, IDataReader> extraFields = null) { commandBuilder = commandBuilder ?? this.CommandBuilder.Build; retrieveDetails = retrieveDetails ?? this.RetrieveDetails; var artefactPkPairs = new List <KeyValuePair <T, long> >(); using (DbCommand command = commandBuilder(sqlQuery)) { _log.InfoFormat(CultureInfo.InvariantCulture, "Executing Query: '{0}' with '{1}'", command.CommandText, sqlQuery.MaintainableRef); using (IDataReader dataReader = this._mappingStoreDb.ExecuteReader(command)) { int sysIdIdx = dataReader.GetOrdinal("SYSID"); int idIdx = dataReader.GetOrdinal("ID"); int version1Idx = dataReader.GetOrdinal("VERSION"); int agencyIdx = dataReader.GetOrdinal("AGENCY"); int validFromIdx = dataReader.GetOrdinal("VALID_FROM"); int validToIdx = dataReader.GetOrdinal("VALID_TO"); int isFinalIdx = dataReader.GetOrdinal("IS_FINAL"); int txtIdx = dataReader.GetOrdinal("TEXT"); int langIdx = dataReader.GetOrdinal("LANGUAGE"); int typeIdx = dataReader.GetOrdinal("TYPE"); var artefactMap = new Dictionary <long, T>(); while (dataReader.Read()) { long sysId = DataReaderHelper.GetInt64(dataReader, sysIdIdx); T artefact; if (!artefactMap.TryGetValue(sysId, out artefact)) { artefact = this.CreateArtefact(); artefact.FinalStructure = DataReaderHelper.GetTristate(dataReader, isFinalIdx); artefact.EndDate = DataReaderHelper.GetStringDate(dataReader, validToIdx); artefact.StartDate = DataReaderHelper.GetStringDate(dataReader, validFromIdx); artefact.Version = DataReaderHelper.GetString(dataReader, version1Idx); artefact.AgencyId = DataReaderHelper.GetString(dataReader, agencyIdx); artefact.Id = DataReaderHelper.GetString(dataReader, idIdx); this.HandleArtefactExtraFields(artefact, dataReader); if (extraFields != null) { extraFields(artefact, dataReader); } artefactPkPairs.Add(new KeyValuePair <T, long>(artefact, sysId)); artefactMap.Add(sysId, artefact); } if (!artefact.IsDefault()) { ReadLocalisedString(artefact, typeIdx, txtIdx, langIdx, dataReader, detail); } } } } if (artefactPkPairs.Count < 1) { _log.InfoFormat(CultureInfo.InvariantCulture, "No artefacts retrieved for : '{0}'", sqlQuery.MaintainableRef); return(new HashSet <T>()); } return(HandleDetailLevel(detail, retrieveDetails, artefactPkPairs)); }
/// <summary> /// Retrieve the <see cref="IMaintainableMutableObject"/> with the latest version group by ID and AGENCY from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <returns> /// The <see cref="IMaintainableMutableObject"/>. /// </returns> public abstract T RetrieveLatest(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail);
/// <summary> /// Read the localized string from <paramref name="dataReader"/> /// </summary> /// <param name="item"> /// The <see cref="INameableMutableObject"/> . /// </param> /// <param name="typeIdx"> /// The <c>LOCALISED_STRING.TYPE</c> ordinal /// </param> /// <param name="txtIdx"> /// The <c>LOCALISED_STRING.TEXT</c> ordinal /// </param> /// <param name="langIdx"> /// The <c>LOCALISED_STRING.LANGUAGE</c> ordinal /// </param> /// <param name="dataReader"> /// The MASTORE DB <see cref="IDataReader"/> /// </param> /// <param name="detail">The Structure Query Detail</param> protected static void ReadLocalisedString(INameableMutableObject item, int typeIdx, int txtIdx, int langIdx, IDataRecord dataReader, ComplexStructureQueryDetailEnumType detail = ComplexStructureQueryDetailEnumType.Full) { //// TODO support SDMX-ML Query detail CompleteStub versus Stub when Common API supports it. //// When it is stub then only name should be returned. //// When it is complete stub both name and description. //// Now we use StructureQueryDetail which is for REST queries only. //// According to the http://sdmx.org/wp-content/uploads/2012/05/SDMX_2_1-SECTION_07_WebServicesGuidelines_May2012.pdf //// page 10, footnotes 10-12 REST AllStubs == SDMX-ML Query Stub so in that case we skip description var value = DataReaderHelper.GetString(dataReader, txtIdx); var locale = DataReaderHelper.GetString(dataReader, langIdx); string type = DataReaderHelper.GetString(dataReader, typeIdx); var textType = new TextTypeWrapperMutableCore { Locale = locale, Value = value }; switch (type) { case LocalisedStringType.Name: item.Names.Add(textType); break; case LocalisedStringType.Desc: if (detail != ComplexStructureQueryDetailEnumType.Stub) { item.Descriptions.Add(textType); } break; default: _log.WarnFormat(CultureInfo.InvariantCulture, "Unknown type at LOCALISATION.TYPE : '{0}', Locale: '{1}', Text:'{2}'", type, locale, value); if (item.Names.Count == 0) { item.AddName(null, !string.IsNullOrWhiteSpace(value) ? value : item.Id); } break; } }
/// <summary> /// /// </summary> /// <param name="maintainableRef"></param> /// <param name="detail"></param> /// <param name="versionConstraints"></param> /// <returns></returns> public override ISet <IContentConstraintMutableObject> Retrieve(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, VersionQueryType versionConstraints) { var sqlInfo = versionConstraints == VersionQueryType.Latest ? this.SqlQueryInfoForLatest : this.SqlQueryInfoForAll; return(this.GetConstraintMutableObjects(maintainableRef, detail, sqlInfo)); }
/// <summary> /// Retrieve the <see cref="ICodelistMutableObject"/> from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="dataflowRef"> /// The dataflow Ref. /// </param> /// <param name="conceptId"> /// The concept Id. /// </param> /// <param name="isTranscoded"> /// The is Transcoded. /// </param> /// <param name="allowedDataflows">The allowed dataflows.</param> /// <returns> /// The <see cref="ISet{ICodelistMutableObject}"/>. /// </returns> public ISet<ICodelistMutableObject> Retrieve(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, IMaintainableRefObject dataflowRef, string conceptId, bool isTranscoded, IList<IMaintainableRefObject> allowedDataflows) { var sqlQuery = new ArtefactSqlQuery(this.SqlQueryInfoForAll, maintainableRef); return this.RetrieveArtefacts(sqlQuery, detail, retrieveDetails: (o, l) => this.FillCodes(o, l, dataflowRef, conceptId, isTranscoded, allowedDataflows)); }
/// <summary> /// Retrieve the <see cref="IStructureSetMutableObject"/> with the latest version group by ID and AGENCY from Mapping /// Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <returns> /// The <see cref="IStructureSetMutableObject"/>. /// </returns> public override IStructureSetMutableObject RetrieveLatest(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail) { ISet <IStructureSetMutableObject> mutableObjects = this.GetStructureSetMutableObjects(maintainableRef, detail, this.SqlQueryInfoForLatest); return(mutableObjects.GetOneOrNothing()); }
/// <summary> /// Retrieve the <see cref="ICodelistMutableObject"/> from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="dataflowRef"> /// The dataflow Ref. /// </param> /// <param name="conceptId"> /// The concept Id. /// </param> /// <param name="isTranscoded"> /// The is Transcoded. /// </param> /// <param name="allowedDataflows">The allowed dataflows.</param> /// <returns> /// The <see cref="ISet{ICodelistMutableObject}"/>. /// </returns> public ISet <ICodelistMutableObject> Retrieve(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, IMaintainableRefObject dataflowRef, string conceptId, bool isTranscoded, IList <IMaintainableRefObject> allowedDataflows) { var sqlQuery = new ArtefactSqlQuery(this.SqlQueryInfoForAll, maintainableRef); return(this.RetrieveArtefacts(sqlQuery, detail, retrieveDetails: (o, l) => this.FillCodes(o, l, dataflowRef, conceptId, isTranscoded, allowedDataflows))); }
/// <summary> /// Retrieve the <see cref="IDataflowMutableObject"/> from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="versionConstraints"> /// The version query type /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <returns> /// The <see cref="ISet{IDataflowMutableObject}"/>. /// </returns> public override ISet <IDataflowMutableObject> Retrieve(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, VersionQueryType versionConstraints, IList <IMaintainableRefObject> allowedDataflows) { var dataflowMutableObjects = new HashSet <IDataflowMutableObject>(); var sqlQueryInfo = versionConstraints == VersionQueryType.Latest ? this._sqlQueryInfoLatest : this._sqlQueryInfo; var artefactSqlQuery = new ArtefactSqlQuery(sqlQueryInfo, maintainableRef); // do a security check. return(!SecurityHelper.Contains(allowedDataflows, maintainableRef) ? dataflowMutableObjects : this.RetrieveArtefacts(artefactSqlQuery, detail, query => this._artefactCommandBuilder.Build(query, allowedDataflows))); }
/// <summary> /// Retrieve the <see cref="IMaintainableMutableObject"/> from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="versionConstraints"> /// The version criteria /// </param> /// <returns> /// The <see cref="ISet{IMaintainableMutableObject}"/>. /// </returns> public override ISet <IDataflowMutableObject> Retrieve(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, VersionQueryType versionConstraints) { return(this.Retrieve(maintainableRef, detail, versionConstraints, null)); }
/// <summary> /// Retrieve the <see cref="ICategorisationMutableObject"/> with the latest version group by ID and AGENCY from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <returns> /// The <see cref="ISet{ICategorisationMutableObject}"/>. /// </returns> public override ICategorisationMutableObject RetrieveLatest(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, IList <IMaintainableRefObject> allowedDataflows) { ISet <ICategorisationMutableObject> mutableObjects = this.Retrieve(maintainableRef, detail, VersionQueryType.Latest, allowedDataflows); ////return mutableObjects.GetOneOrNothing(); //// HACK This needs to be fixed after including proper categorisation support return(mutableObjects.FirstOrDefault()); }
/// <summary> /// Retrieve the <see cref="IMaintainableMutableObject"/> from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="versionConstraints"> /// The version types. /// </param> /// <returns> /// The <see cref="ISet{IMaintainableMutableObject}"/>. /// </returns> public override ISet <TMaintaible> Retrieve(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, VersionQueryType versionConstraints) { var sqlInfo = versionConstraints == VersionQueryType.Latest ? this.SqlQueryInfoForLatest : this.SqlQueryInfoForAll; var sqlQuery = new ArtefactSqlQuery(sqlInfo, maintainableRef); return(this.RetrieveItemScheme(detail, sqlQuery)); }
/// <summary> /// Retrieve the <see cref="IMaintainableMutableObject"/> with the latest version group by ID and AGENCY from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <returns> /// The <see cref="ISet{IMaintainableMutableObject}"/>. /// </returns> public override TMaintaible RetrieveLatest(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail) { var sqlQuery = new ArtefactSqlQuery(this.SqlQueryInfoForLatest, maintainableRef); var mutableObjects = this.RetrieveItemScheme(detail, sqlQuery); switch (mutableObjects.Count) { case 0: return(default(TMaintaible)); case 1: return(mutableObjects.First()); default: throw new ArgumentException(ErrorMessages.MoreThanOneArtefact, "maintainableRef"); } }
/// <summary> /// Retrieve the set of <see cref="IMaintainableMutableObject"/> from Mapping Store that references /// <paramref name="referencedStructure"/> /// . /// </summary> /// <param name="referencedStructure"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. This is the referenced structure. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="commandBuilder"> /// The command Builder. /// </param> /// <param name="retrieveDetails">The method that retrieves the details of the artefact.</param> /// <returns> /// The <see cref="ISet{IMaintainableMutableObject}"/>. /// </returns> protected ISet <T> RetrieveFromReferencedInternal(IStructureReference referencedStructure, ComplexStructureQueryDetailEnumType detail, Func <ArtefactSqlQuery, DbCommand> commandBuilder, Func <T, long, T> retrieveDetails) { if (referencedStructure == null) { throw new ArgumentNullException("referencedStructure"); } string innerJoin = this.GetReferencedFromInnerJoins(referencedStructure.MaintainableStructureEnumType.EnumType); ISet <T> mutableObjects; if (innerJoin != null) { SqlQueryInfo sqlQueryInfo = this._artefactParentsSqlBuilder.Build(innerJoin); var artefactSqlQuery = new ArtefactSqlQuery(sqlQueryInfo, referencedStructure.MaintainableReference); mutableObjects = this.RetrieveArtefacts(artefactSqlQuery, detail, commandBuilder, retrieveDetails); } else { mutableObjects = new HashSet <T>(); } return(mutableObjects); }
/// <summary> /// Retrieve the set of <see cref="IMaintainableMutableObject"/> from Mapping Store that references /// <paramref name="referencedStructure"/> /// . /// </summary> /// <param name="referencedStructure"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. This is the referenced structure. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <returns> /// The <see cref="ISet{IMaintainableMutableObject}"/>. /// </returns> public override ISet <IDataflowMutableObject> RetrieveFromReferenced(IStructureReference referencedStructure, ComplexStructureQueryDetailEnumType detail, IList <IMaintainableRefObject> allowedDataflows) { return(this.RetrieveFromReferencedInternal(referencedStructure, detail, query => this._artefactCommandBuilder.Build(query, allowedDataflows), this.RetrieveDetails)); }
/// <summary> /// The retrieve item scheme. /// </summary> /// <param name="detail"> /// The detail. /// </param> /// <param name="sqlQuery"> /// The SQL query. /// </param> /// <returns> /// The <see cref="ISet{IItemSchemeObject}"/>. /// </returns> private ISet <TMaintaible> RetrieveItemScheme(ComplexStructureQueryDetailEnumType detail, ArtefactSqlQuery sqlQuery) { return(this.RetrieveArtefacts(sqlQuery, detail)); }
/// <summary> /// Retrieve the <see cref="IMaintainableMutableObject"/> with the latest version group by ID and AGENCY from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <returns> /// The <see cref="IMaintainableMutableObject"/>. /// </returns> public override IDataflowMutableObject RetrieveLatest(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail) { return(this.RetrieveLatest(maintainableRef, detail, null)); }
/// <summary> /// Retrieve the <see cref="ICodelistMutableObject"/> from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="subset"> /// The subset. /// </param> /// <returns> /// The <see cref="ISet{ICodelistMutableObject}"/>. /// </returns> public ISet <ICodelistMutableObject> Retrieve(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, IList <string> subset) { var sqlQuery = new ArtefactSqlQuery(this.SqlQueryInfoForAll, maintainableRef); Func <ICodelistMutableObject, long, ICodelistMutableObject> hashMethod = (itemSchemeBean, parentSysId) => this.FillCodesHash(itemSchemeBean, parentSysId, subset); Func <ICodelistMutableObject, long, ICodelistMutableObject> whereInMethod = (itemSchemeBean, parentSysId) => this.FillCodes(itemSchemeBean, parentSysId, subset); Func <ICodelistMutableObject, long, ICodelistMutableObject> selected = whereInMethod; switch (this.MappingStoreDb.ProviderName) { case MappingStoreDefaultConstants.SqlServerProvider: // SQL server performs very bad with 'IN' selected = hashMethod; break; case MappingStoreDefaultConstants.MySqlProvider: if (subset.Count > 2000) { selected = hashMethod; } break; case MappingStoreDefaultConstants.OracleProvider: case MappingStoreDefaultConstants.OracleProviderOdp: if (subset.Count > 4000) { selected = hashMethod; } break; default: if (subset.Count > 1000) { selected = hashMethod; } break; } return(this.RetrieveArtefacts(sqlQuery, detail, retrieveDetails: selected)); }
/// <summary> /// Retrieve the <see cref="IDataflowMutableObject"/> with the latest version group by ID and AGENCY from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <returns> /// The <see cref="ISet{IDataflowMutableObject}"/>. /// </returns> public override IDataflowMutableObject RetrieveLatest(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, IList <IMaintainableRefObject> allowedDataflows) { var dataflowMutableObjects = new HashSet <IDataflowMutableObject>(); var artefactSqlQuery = new ArtefactSqlQuery(this._sqlQueryInfoLatest, maintainableRef); // do a security check. var dataflows = !SecurityHelper.Contains(allowedDataflows, maintainableRef) ? dataflowMutableObjects : this.RetrieveArtefacts(artefactSqlQuery, detail, query => this._artefactCommandBuilder.Build(query, allowedDataflows)); return(dataflows.GetOneOrNothing()); }
/// <summary> /// Retrieve the <see cref="IMaintainableMutableObject"/> from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="versionConstraints">A value indicating the version criteria.</param> /// <returns> /// The <see cref="ISet{IMaintainableMutableObject}"/>. /// </returns> public abstract ISet <T> Retrieve(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, VersionQueryType versionConstraints);
/// <summary> /// Retrieve the set of <see cref="IMaintainableMutableObject"/> from Mapping Store that references /// <paramref name="referencedStructure"/> /// . /// </summary> /// <param name="referencedStructure"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. This is the referenced structure. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="referencedStructure"/> is null. /// </exception> /// <returns> /// The <see cref="ISet{IMaintainableMutableObject}"/>. /// </returns> public override ISet <IDataflowMutableObject> RetrieveFromReferenced(IStructureReference referencedStructure, ComplexStructureQueryDetailEnumType detail) { return(this.RetrieveFromReferenced(referencedStructure, detail, null)); }
/// <summary> /// Retrieve the set of <see cref="IMaintainableMutableObject"/> from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="versionConstraints"> /// A value indicating the version criteria. /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <returns> /// The <see cref="ISet{IMaintainableMutableObject}"/>. /// </returns> public virtual ISet <T> Retrieve(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, VersionQueryType versionConstraints, IList <IMaintainableRefObject> allowedDataflows) { return(this.Retrieve(maintainableRef, detail, versionConstraints)); }
/// <summary> /// Retrieve the set of <see cref="IMaintainableMutableObject"/> from Mapping Store that references /// <paramref name="referencedStructure"/> /// . /// </summary> /// <param name="referencedStructure"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. This is the referenced structure. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="referencedStructure"/> is null. /// </exception> /// <returns> /// The <see cref="ISet{IMaintainableMutableObject}"/>. /// </returns> public virtual ISet <T> RetrieveFromReferenced(IStructureReference referencedStructure, ComplexStructureQueryDetailEnumType detail) { return(this.RetrieveFromReferencedInternal(referencedStructure, detail, query => this.CommandBuilder.Build(query), this.RetrieveDetails)); }
/// <summary> /// Retrieve the set of <see cref="IMaintainableMutableObject"/> from Mapping Store that references /// <paramref name="referencedStructure"/> /// . /// </summary> /// <param name="referencedStructure"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. This is the referenced structure. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <returns> /// The <see cref="ISet{IMaintainableMutableObject}"/>. /// </returns> public virtual ISet <T> RetrieveFromReferenced(IStructureReference referencedStructure, ComplexStructureQueryDetailEnumType detail, IList <IMaintainableRefObject> allowedDataflows) { return(this.RetrieveFromReferenced(referencedStructure, detail)); }
/// <summary> /// /// </summary> /// <param name="maintainableRef"></param> /// <param name="detail"></param> /// <param name="queryInfo"></param> /// <returns></returns> private ISet <IContentConstraintMutableObject> GetConstraintMutableObjects(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, SqlQueryInfo queryInfo) { var artefactSqlQuery = new ArtefactSqlQuery(queryInfo, maintainableRef); return(this.RetrieveArtefacts(artefactSqlQuery, detail)); }
/// <summary> /// Retrieve the <see cref="IMaintainableMutableObject"/> with the latest version group by ID and AGENCY from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <returns> /// The <see cref="IMaintainableMutableObject"/>. /// </returns> public virtual T RetrieveLatest(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, IList <IMaintainableRefObject> allowedDataflows) { return(this.RetrieveLatest(maintainableRef, detail)); }
/// <summary> /// /// </summary> /// <param name="maintainableRef"></param> /// <param name="detail"></param> /// <returns></returns> public override IContentConstraintMutableObject RetrieveLatest(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail) { ISet <IContentConstraintMutableObject> mutableObjects = this.GetConstraintMutableObjects(maintainableRef, detail, this.SqlQueryInfoForLatest); if (mutableObjects.Count > 0) { foreach (IContentConstraintMutableObject cons in mutableObjects) { return(cons); } } return(null); }
/// <summary> /// Retrieve the <see cref="ICodelistMutableObject"/> from Mapping Store. /// </summary> /// <param name="maintainableRef"> /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION. /// </param> /// <param name="detail"> /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not. /// </param> /// <param name="subset"> /// The subset. /// </param> /// <returns> /// The <see cref="ISet{ICodelistMutableObject}"/>. /// </returns> public ISet<ICodelistMutableObject> Retrieve(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, IList<string> subset) { var sqlQuery = new ArtefactSqlQuery(this.SqlQueryInfoForAll, maintainableRef); Func<ICodelistMutableObject, long, ICodelistMutableObject> hashMethod = (itemSchemeBean, parentSysId) => this.FillCodesHash(itemSchemeBean, parentSysId, subset); Func<ICodelistMutableObject, long, ICodelistMutableObject> whereInMethod = (itemSchemeBean, parentSysId) => this.FillCodes(itemSchemeBean, parentSysId, subset); Func<ICodelistMutableObject, long, ICodelistMutableObject> selected = whereInMethod; switch (this.MappingStoreDb.ProviderName) { case MappingStoreDefaultConstants.SqlServerProvider: // SQL server performs very bad with 'IN' selected = hashMethod; break; case MappingStoreDefaultConstants.MySqlProvider: if (subset.Count > 2000) { selected = hashMethod; } break; case MappingStoreDefaultConstants.OracleProvider: case MappingStoreDefaultConstants.OracleProviderOdp: if (subset.Count > 4000) { selected = hashMethod; } break; default: if (subset.Count > 1000) { selected = hashMethod; } break; } return this.RetrieveArtefacts(sqlQuery, detail, retrieveDetails: selected); }