/// <summary> /// Build where clauses in the form of : (year and (periodA or periodB or ... ) and write them /// to a specified StringBuilder /// </summary> /// <param name="ret">The StringBuilder to write the output</param> /// <param name="yearStr">The year string</param> /// <param name="firstPeriod">The first period</param> /// <param name="lastPeriod">The last period</param> /// <param name="periodicity">The periodicity.</param> /// <param name="timeExpressionEntity">The time expression entity.</param> /// <returns> /// The position of the last clause inside the StringBuilder /// </returns> private int BuildPeriodWhere(StringBuilder ret, string yearStr, int firstPeriod, int lastPeriod, IPeriodicity periodicity, TimeExpressionEntity timeExpressionEntity) { var queryCode = new CodeCollection(); ret.Append("( "); ret.AppendFormat(this._yearOnlyWhereFormat, yearStr); int lastClause = ret.Length; ret.Append(" and "); ret.Append("( "); for (int x = firstPeriod; x <= lastPeriod; x++) { string periodStr = x.ToString(periodicity.Format, _formatProvider); queryCode.Clear(); queryCode.Add(periodStr); string periodCode = timeExpressionEntity.TranscodingRules.GetLocalCodes(queryCode)[0][0]; ret.AppendFormat(CultureInfo.InvariantCulture, this._whereFormat, periodCode); lastClause = ret.Length; ret.Append(" or "); } ret.Length = lastClause; ret.Append(") "); ret.Append(") "); lastClause = ret.Length; ret.Append(" or "); return(lastClause); }
/// <summary> /// Maps the column of the mapping to the component of this ComponentMapping1to1T object /// and transcodes it. /// </summary> /// <param name="reader"> /// The DataReader for retrieving the values of the column. /// </param> /// <returns> /// The value of the component or null if no transcoding rule for the column values is found /// </returns> public string MapComponent(IDataReader reader) { var resultCodes = new CodeCollection(); this.BuildOrdinals(reader); var column = this.ColumnOrdinals[0]; string columnValue = DataReaderHelper.GetString(reader, column.Value); resultCodes.Add(columnValue); Collection <string> transcodedCodes = this.Mapping.Transcoding.TranscodingRules.GetDsdCodes(resultCodes); string ret = null; if (transcodedCodes != null && transcodedCodes.Count > 0) { ret = transcodedCodes[0]; } return(ret); }
/// <summary> /// Retrieve TimeDimension transcoding, if <paramref name="timeDimensionMapping"/> is null /// </summary> /// <param name="mappingStoreDb"> /// The mapping store DB. /// </param> /// <param name="timeDimensionMapping"> /// The time dimension mapping. /// </param> private static void RetrieveTimeDimensionTranscoding( Database mappingStoreDb, MappingEntity timeDimensionMapping) { if (timeDimensionMapping == null) { return; } RetrieveTimeTranscoding(mappingStoreDb, timeDimensionMapping); TimeTranscodingCollection timeTranscodingCollection = timeDimensionMapping.Transcoding.TimeTranscodingCollection; if (timeTranscodingCollection.Count == 1 && TimeFormat.GetTimeFormatFromCodeId(timeTranscodingCollection[0].FrequencyValue).EnumType == TimeFormatEnumType.Year) { return; } var codelists = PeriodCodelist.PeriodCodelistIdMap; IDictionary<string, TimeTranscodingEntity> transcodingMap = new Dictionary<string, TimeTranscodingEntity>(StringComparer.Ordinal); foreach (var periodObject in codelists) { if (timeTranscodingCollection.Contains(periodObject.Key)) { var timeTranscodingEntity = timeTranscodingCollection[periodObject.Key]; if (timeTranscodingEntity.PeriodColumnId > 0) { var timeDimensionRules = new TranscodingRulesEntity(); timeDimensionRules.AddColumn(timeTranscodingEntity.PeriodColumnId, 0); timeDimensionRules.AddComponent(timeDimensionMapping.Components[0].SysId, 0); timeTranscodingEntity.TranscodingRules = timeDimensionRules; transcodingMap.Add(periodObject.Value.Id, timeTranscodingEntity); } } } DbParameter parameter = mappingStoreDb.CreateInParameter(ParameterNameConstants.TranscodingId, DbType.Int64, timeDimensionMapping.Transcoding.SysId); using (DbCommand command = mappingStoreDb.GetSqlStringCommandFormat(MappingStoreSqlStatements.TranscodingRulesTimeDimension, parameter)) using (IDataReader dataReader = mappingStoreDb.ExecuteReader(command)) { int dsdcodeIdx = dataReader.GetOrdinal("DSDCODE"); int localcodeIdx = dataReader.GetOrdinal("LOCALCODE"); int codelistId = dataReader.GetOrdinal("CODELIST_ID"); while (dataReader.Read()) { var periodCodelist = DataReaderHelper.GetString(dataReader, codelistId); TimeTranscodingEntity timeTranscodingEntity; if (transcodingMap.TryGetValue(periodCodelist, out timeTranscodingEntity)) { var timeDimensionRules = timeTranscodingEntity.TranscodingRules; var dsdperiod = new CodeCollection(); var localperiod = new CodeCollection(); dsdperiod.Add(DataReaderHelper.GetString(dataReader, dsdcodeIdx)); localperiod.Add(DataReaderHelper.GetString(dataReader, localcodeIdx)); timeDimensionRules.Add(localperiod, dsdperiod); } } } }
/// <summary> /// Maps the column of the mapping to the component of this ComponentMapping1to1T object /// and transcodes it. /// </summary> /// <param name="reader"> /// The DataReader for retrieving the values of the column. /// </param> /// <returns> /// The value of the component or null if no transcoding rule for the column values is found /// </returns> public string MapComponent(IDataReader reader) { var resultCodes = new CodeCollection(); this.BuildOrdinals(reader); var column = this.ColumnOrdinals[0]; string columnValue = DataReaderHelper.GetString(reader, column.Value); resultCodes.Add(columnValue); Collection<string> transcodedCodes = this.Mapping.Transcoding.TranscodingRules.GetDsdCodes(resultCodes); string ret = null; if (transcodedCodes != null && transcodedCodes.Count > 0) { ret = transcodedCodes[0]; } return ret; }
/// <summary> /// Build where clauses in the form of : (year and (periodA or periodB or ... ) and write them /// to a specified StringBuilder /// </summary> /// <param name="ret">The StringBuilder to write the output</param> /// <param name="yearStr">The year string</param> /// <param name="firstPeriod">The first period</param> /// <param name="lastPeriod">The last period</param> /// <param name="periodicity">The periodicity.</param> /// <param name="timeExpressionEntity">The time expression entity.</param> /// <returns> /// The position of the last clause inside the StringBuilder /// </returns> private int BuildPeriodWhere(StringBuilder ret, string yearStr, int firstPeriod, int lastPeriod, IPeriodicity periodicity, TimeExpressionEntity timeExpressionEntity) { var queryCode = new CodeCollection(); ret.Append("( "); ret.AppendFormat(this._yearOnlyWhereFormat, yearStr); int lastClause = ret.Length; ret.Append(" and "); ret.Append("( "); for (int x = firstPeriod; x <= lastPeriod; x++) { string periodStr = x.ToString(periodicity.Format, _formatProvider); queryCode.Clear(); queryCode.Add(periodStr); string periodCode = timeExpressionEntity.TranscodingRules.GetLocalCodes(queryCode)[0][0]; ret.AppendFormat(CultureInfo.InvariantCulture, this._whereFormat, periodCode); lastClause = ret.Length; ret.Append(" or "); } ret.Length = lastClause; ret.Append(") "); ret.Append(") "); lastClause = ret.Length; ret.Append(" or "); return lastClause; }