/// <summary> /// Initializes a new instance of the <see cref="DsdRetrievalEngine"/> class. /// Initializes a new instance of the <see cref="DataflowRetrievalEngine"/> class. /// </summary> /// <param name="mappingStoreDb"> /// The mapping store DB. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mappingStoreDb"/> is null. /// </exception> public DsdRetrievalEngine(Database mappingStoreDb) : base(mappingStoreDb) { var sqlQueryBuilder = new ReferencedSqlQueryBuilder(this.MappingStoreDb, null); this._attributeGroupQueryInfo = sqlQueryBuilder.Build(DsdConstant.AttributeAttachmentGroupQueryFormat); this._attributeMeasureQueryInfo = sqlQueryBuilder.Build(DsdConstant.AttributeAttachmentMeasureQueryFormat); this._groupQueryInfo = sqlQueryBuilder.Build(DsdConstant.GroupQueryFormat); this._attributeDimensionRefsInfo = sqlQueryBuilder.Build(DsdConstant.AttributeDimensionFormat); this._componentQueryInfo = sqlQueryBuilder.Build(DsdConstant.ComponentQueryFormat); this._componentQueryInfo.OrderBy = DsdConstant.ComponentOrderBy; this._commandBuilder = new ItemCommandBuilder(this.MappingStoreDb); this._componentAnnotationRetrieverEngine = new IdentifiableAnnotationRetrieverEngine( mappingStoreDb, new ItemTableInfo(SdmxStructureEnumType.Component) { ForeignKey = "DSD_ID", PrimaryKey = "COMP_ID", Table = "COMPONENT" }); this._groupAnnotationRetrieverEngine = new IdentifiableAnnotationRetrieverEngine( mappingStoreDb, new ItemTableInfo(SdmxStructureEnumType.Group) { ForeignKey = "DSD_ID", PrimaryKey = "GR_ID", Table = "DSD_GROUP" }); }
/// <summary> /// Initializes a new instance of the <see cref="CodeListRetrievalEngine" /> class. /// </summary> /// <param name="mappingStoreDb">The mapping store DB.</param> /// <param name="itemOrderBy">The item order by.</param> /// <exception cref="ArgumentNullException"><paramref name="mappingStoreDb" /> is null</exception> public CodeListRetrievalEngine(Database mappingStoreDb, string itemOrderBy = CodeListConstant.ItemOrderBy) : base(mappingStoreDb) { var itemSqlQueryBuilder = new ItemSqlQueryBuilder(mappingStoreDb, itemOrderBy); this._itemSqlQueryInfo = itemSqlQueryBuilder.Build(CodeListConstant.ItemTableInfo); }
/// <summary> /// Initializes a new instance of the <see cref="DataflowRetrievalEngine"/> class. /// </summary> /// <param name="mappingStoreDb"> /// The mapping store DB. /// </param> /// <param name="filter"> /// The filter. (Optional defaults to <see cref="DataflowFilter.Production"/> /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mappingStoreDb"/> is null. /// </exception> public DataflowRetrievalEngine(Database mappingStoreDb, DataflowFilter filter = DataflowFilter.Production) : base(mappingStoreDb) { this._artefactCommandBuilder = new DataflowCommandBuilder(mappingStoreDb, filter); var sqlQueryBuilder = new ReferencedSqlQueryBuilder(this.MappingStoreDb, null); this._keyFamilyRefQuery = sqlQueryBuilder.Build(DataflowConstant.KeyFamilyRefQueryFormat); this._keyFamilyRefCommandBuilder = new ItemCommandBuilder(this.MappingStoreDb); ArtefactSqlBuilder dataflowBuilder; ArtefactSqlBuilder latestBuilder; switch (filter) { case DataflowFilter.Any: dataflowBuilder = new ArtefactSqlBuilder(); latestBuilder = new ArtefactSqlBuilder(null, VersionQueryType.Latest); break; case DataflowFilter.Production: dataflowBuilder = new ArtefactSqlBuilder(null, VersionQueryType.All, DataflowConstant.ProductionWhereLatestClause); latestBuilder = new ArtefactSqlBuilder(null, VersionQueryType.Latest, DataflowConstant.ProductionWhereLatestClause); break; default: throw new ArgumentOutOfRangeException("filter"); } this._sqlQueryInfo = dataflowBuilder.Build(DataflowConstant.TableInfo); this._sqlQueryInfoLatest = latestBuilder.Build(DataflowConstant.TableInfo); }
/// <summary> /// Retrieve the <see cref="IHierarchicalCodelistMutableObject"/> 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="IHierarchicalCodelistMutableObject"/>. /// </returns> public override IHierarchicalCodelistMutableObject RetrieveLatest(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail) { SqlQueryInfo queryInfo = this.SqlQueryInfoForLatest; ISet <IHierarchicalCodelistMutableObject> mutableObjects = this.HierarchicalCodelistMutableObjects(maintainableRef, detail, queryInfo); return(mutableObjects.GetOneOrNothing()); }
public virtual int InsertAndGetIdentity(DbManager db, object obj) { SqlQueryInfo query = GetSqlQueryInfo(db, obj.GetType(), "InsertAndGetIdentity"); return(db .SetCommand(query.QueryText, query.GetParameters(db, obj)) .ExecuteScalar <int>()); }
/// <summary> /// Builds an <see cref="SqlQueryInfo"/> from the specified <paramref name="innerJoins"/> /// </summary> /// <param name="innerJoins"> /// An Object to build the output object from /// </param> /// <returns> /// an <see cref="SqlQueryInfo"/> build from the specified <paramref name="innerJoins"/> /// </returns> public SqlQueryInfo Build(string innerJoins) { string queryFormat = string.Format(CultureInfo.InvariantCulture, SqlQueryFormat, innerJoins, this._tableInfo.ExtraFields); var queryInfo = new SqlQueryInfo { QueryFormat = queryFormat, OrderBy = OrderBy, WhereStatus = WhereState.Nothing }; return(queryInfo); }
/// <summary> /// Метод выполняет добавление записи и возвращает идентификатор новой записи. /// </summary> /// <typeparam name="TID">Тип идентификатора.</typeparam> /// <param name="db">Экземпляр менеджера базы данных, производного от <see cref="BLToolkit.Data.DbManager">DbManager</see>.</param> /// <param name="obj">Экземпляр объекта, для которого будет добавлена новая запись.</param> /// <returns></returns> public virtual TID InsertAndGetIdentity <TID>(DbManager db, object obj) where TID : struct { SqlQueryInfo query = GetSqlQueryInfo(db, obj.GetType(), "InsertAndGetIdentity"); return(db .SetCommand(query.QueryText, query.GetParameters(db, obj)) .ExecuteScalar <TID>()); }
/// <summary> /// Builds an <see cref="SqlQueryInfo"/> from the specified <paramref name="tableInfo"/> /// </summary> /// <param name="tableInfo"> /// An Object to build the output object from /// </param> /// <returns> /// an <see cref="SqlQueryInfo"/> build from the specified <paramref name="tableInfo"/> /// </returns> public SqlQueryInfo Build(TableInfo tableInfo) { string queryFormat = string.Format(CultureInfo.InvariantCulture, this._queryFormat, tableInfo.PrimaryKey, tableInfo.Table, tableInfo.ExtraFields, this._latestConstraint); var queryInfo = new SqlQueryInfo { QueryFormat = queryFormat, OrderBy = this._orderBy, WhereStatus = this._whereStatus }; return(queryInfo); }
/// <summary> /// Initializes a new instance of the <see cref="ItemSchemeRetrieverEngine{TMaintaible,TItem}"/> class. /// </summary> /// <param name="mappingStoreDb"> /// The mapping store DB. /// </param> /// <param name="orderBy"> /// The order By. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mappingStoreDb"/> is null /// </exception> protected ItemSchemeRetrieverEngine(Database mappingStoreDb, string orderBy = null) : base(mappingStoreDb, orderBy) { this._itemCommandBuilder = new ItemCommandBuilder(mappingStoreDb); var itemTableInfoBuilder = new ItemTableInfoBuilder(); TableInfo tableInfo = new TableInfoBuilder().Build(typeof(TMaintaible)); var itemTableInfo = itemTableInfoBuilder.Build(tableInfo.StructureType); var itemSqlQueryBuilder = new ItemSqlQueryBuilder(mappingStoreDb, null); this._itemSqlQueryInfo = itemSqlQueryBuilder.Build(itemTableInfo); this._identifiableAnnotationRetrieverEngine = new IdentifiableAnnotationRetrieverEngine(mappingStoreDb, itemTableInfo); }
protected override SqlQueryInfo CreateSqlText(DbManager db, Type type, string actionName) { switch (actionName) { case "InsertAndGetIdentity": SqlQueryInfo qi = CreateInsertSqlText(db, type, -1); qi.QueryText += "\nSELECT Cast(SCOPE_IDENTITY() as int)"; return(qi); default: return(base.CreateSqlText(db, type, actionName)); } }
/// <summary> /// Initializes a new instance of the <see cref="MaintainableAnnotationRetrieverEngine"/> class. /// </summary> /// <param name="mappingStoreDb">The mapping store database.</param> /// <param name="tableInfo">The table information.</param> /// <exception cref="System.ArgumentNullException"><paramref name="tableInfo"/> is null -or- <paramref name="mappingStoreDb"/> is null.</exception> public MaintainableAnnotationRetrieverEngine(Database mappingStoreDb, TableInfo tableInfo) { if (mappingStoreDb == null) { throw new ArgumentNullException("mappingStoreDb"); } if (tableInfo == null) { throw new ArgumentNullException("tableInfo"); } this._mappingStoreDb = mappingStoreDb; ISqlQueryInfoBuilder <TableInfo> annotationQueryBuilder = new AnnotationQueryBuilder(); this._annotationSqlQueryInfo = annotationQueryBuilder.Build(tableInfo); this._annotationCommandBuilder = new AnnotationCommandBuilder(this._mappingStoreDb); }
/// <summary> /// Initializes a new instance of the <see cref="ArtefactRetrieverEngine{T}"/> class. /// </summary> /// <param name="mappingStoreDb"> /// The mapping store DB. /// </param> /// <param name="orderBy"> /// The order By. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mappingStoreDb"/> is null. /// </exception> protected ArtefactRetrieverEngine(Database mappingStoreDb, string orderBy = null) { if (mappingStoreDb == null) { throw new ArgumentNullException("mappingStoreDb"); } this._mappingStoreDb = mappingStoreDb; this._artefactCommandBuilder = new ArtefactCommandBuilder(this._mappingStoreDb); var tableInfoBuilder = new TableInfoBuilder(); var tableInfo = tableInfoBuilder.Build(typeof(T)); if (tableInfo != null) { var latestArtefactSqlBuilder = new ArtefactSqlBuilder(orderBy, VersionQueryType.Latest); var artefactSqlBuilder = new ArtefactSqlBuilder(orderBy); this._sqlQueryInfo = artefactSqlBuilder.Build(tableInfo); this._sqlQueryInfoLatest = latestArtefactSqlBuilder.Build(tableInfo); this._artefactParentsSqlBuilder = new ArtefactParentsSqlBuilder(tableInfo); this._maintainableAnnotationRetrieverEngine = new MaintainableAnnotationRetrieverEngine(mappingStoreDb, tableInfo); } }
/// <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> /// Initializes a new instance of the <see cref="HierarchicalCodeListRetrievealEngine"/> class. /// </summary> /// <param name="mappingStoreDb"> /// The mapping store DB. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mappingStoreDb"/> is null. /// </exception> public HierarchicalCodeListRetrievealEngine(Database mappingStoreDb) : base(mappingStoreDb) { var sqlQueryBuilder = new ReferencedSqlQueryBuilder(this.MappingStoreDb, null); this._hierarchyQueryInfo = sqlQueryBuilder.Build(HclConstant.HierarchyQueryFormat); this._codelistRefQueryInfo = sqlQueryBuilder.Build(HclConstant.CodelistRefQueryFormat); this._codeRefQueryInfo = sqlQueryBuilder.Build(HclConstant.CodeRefQueryFormat); this._levelQueryInfo = sqlQueryBuilder.Build(HclConstant.LevelQueryFormat); this._itemCommandBuilder = new ItemCommandBuilder(this.MappingStoreDb); this._hierarchalCodeAnnotationRetrieverEngine = new IdentifiableAnnotationRetrieverEngine(mappingStoreDb, new ItemTableInfo(SdmxStructureEnumType.HierarchicalCode) { ForeignKey = "H_ID", PrimaryKey = "HCODE_ID", Table = "HCL_CODE" }); this._levelAnnotationRetrieverEngine = new IdentifiableAnnotationRetrieverEngine(mappingStoreDb, new ItemTableInfo(SdmxStructureEnumType.HierarchicalCode) { ForeignKey = "H_ID", PrimaryKey = "LEVEL_ID", Table = "HLEVEL" }); this._hierarchyAnnotationRetrieverEngine = new IdentifiableAnnotationRetrieverEngine(mappingStoreDb, new ItemTableInfo(SdmxStructureEnumType.HierarchicalCode) { ForeignKey = "HCL_ID", PrimaryKey = "H_ID", Table = "HIERARCHY" }); }
/// <summary> /// Initializes a new instance of the <see cref="ItemSqlQuery"/> class. /// </summary> /// <param name="queryInfo"> /// The query Info. /// </param> /// <param name="parentSysId"> /// The parent ItemScheme parent Id. /// </param> public ItemSqlQuery(SqlQueryInfo queryInfo, long parentSysId) : base(queryInfo) { this.ParentSysId = parentSysId; }
/// <summary> /// Initializes a new instance of the <see cref="ItemSqlQuery"/> class. /// </summary> /// <param name="queryInfo"> /// The query Info. /// </param> /// <param name="parentSysId"> /// The parent ItemScheme parent Id. /// </param> public ItemSqlQuery(SqlQueryInfo queryInfo, long parentSysId) : base(queryInfo) { this.ParentSysId = parentSysId; }
/// <summary> /// Retrieve the <see cref="IHierarchicalCodelistMutableObject"/> 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="queryInfo"> /// The query Info. /// </param> /// <returns> /// The <see cref="ISet{IHierarchicalCodelistMutableObject}"/>. /// </returns> private ISet <IHierarchicalCodelistMutableObject> HierarchicalCodelistMutableObjects(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, SqlQueryInfo queryInfo) { var artefactSqlQuery = new ArtefactSqlQuery(queryInfo, maintainableRef); return(this.RetrieveArtefacts(artefactSqlQuery, detail)); }
/// <summary> /// Initializes a new instance of the <see cref="ReferenceSqlQuery"/> class. /// </summary> /// <param name="queryInfo"> /// The query Info. /// </param> public ReferenceSqlQuery(SqlQueryInfo queryInfo) : base(queryInfo) { }
/// <summary> /// Initializes a new instance of the <see cref="ReferenceSqlQuery"/> class. /// </summary> /// <param name="queryInfo"> /// The query Info. /// </param> public ReferenceSqlQuery(SqlQueryInfo queryInfo) : base(queryInfo) { }
/// <summary> /// Initializes a new instance of the <see cref="AgencySchemeRetrievalEngine"/> class. /// </summary> /// <param name="mappingStoreDb"> /// The mapping store DB. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mappingStoreDb"/> is null /// </exception> public AgencySchemeRetrievalEngine(Database mappingStoreDb) : base(mappingStoreDb) { this._itemSqlQueryBuilder = new ItemSqlQueryBuilder(mappingStoreDb, AgencySchemeConstant.ItemOrderBy); this._itemSqlQueryInfo = this._itemSqlQueryBuilder.Build(AgencySchemeConstant.ItemTableInfo); }
/// <summary> /// Initializes a new instance of the <see cref="OrganisationUnitSchemeRetrievalEngine"/> class. /// </summary> /// <param name="mappingStoreDb"> /// The mapping store DB. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mappingStoreDb"/> is null /// </exception> public OrganisationUnitSchemeRetrievalEngine(Database mappingStoreDb) : base(mappingStoreDb) { this._itemSqlQueryBuilder = new ItemSqlQueryBuilder(mappingStoreDb, OrganisationUnitSchemeConstant.ItemOrderBy); this._itemSqlQueryInfo = this._itemSqlQueryBuilder.Build(OrganisationUnitSchemeConstant.ItemTableInfo); }
/// <summary> /// Initializes a new instance of the <see cref="CategorySchemeRetrievalEngine"/> class. /// </summary> /// <param name="mappingStoreDb"> /// The mapping store DB. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="mappingStoreDb"/> is null /// </exception> public CategorySchemeRetrievalEngine(Database mappingStoreDb) : base(mappingStoreDb, null) { this._itemSqlQueryBuilder = new ItemSqlQueryBuilder(mappingStoreDb, null); this._itemSqlQueryInfo = this._itemSqlQueryBuilder.Build(CategorySchemeConstant.ItemTableInfo); }
/// <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> /// Initializes a new instance of the <see cref="SqlQueryBase"/> class. /// </summary> /// <param name="queryInfo"> /// The query Info. /// </param> protected SqlQueryBase(SqlQueryInfo queryInfo) { this._queryInfo = queryInfo; }
/// <summary> /// Initializes a new instance of the <see cref="SqlQueryBase" /> class. /// </summary> /// <param name="queryInfo">The query Info.</param> /// <param name="primaryKeyValue">The primary key value.</param> public PrimaryKeySqlQuery(SqlQueryInfo queryInfo, long primaryKeyValue) : base(queryInfo) { this._primaryKeyValue = primaryKeyValue; }
/// <summary> /// Initializes a new instance of the <see cref="SqlQueryBase"/> class. /// </summary> /// <param name="queryInfo"> /// The query Info. /// </param> protected SqlQueryBase(SqlQueryInfo queryInfo) { this._queryInfo = queryInfo; }
/// <summary> /// Initializes a new instance of the <see cref="SqlQueryBase" /> class. /// </summary> /// <param name="queryInfo">The query Info.</param> /// <param name="primaryKeyValue">The primary key value.</param> public PrimaryKeySqlQuery(SqlQueryInfo queryInfo, long primaryKeyValue) : base(queryInfo) { this._primaryKeyValue = primaryKeyValue; }
/// <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)))); }