/// <summary> /// Initializes a new instance of the <see cref="TimeDimensionDateType"/> class. /// Builds a TimeDimensionDateType /// </summary> /// <param name="mapping"> /// The mapping of TimeDimension component /// </param> /// <param name="expression"> /// The expression that is used in this mapping /// </param> /// <param name="databaseType"> /// The dissemination database type /// </param> public TimeDimensionDateType(MappingEntity mapping, TimeExpressionEntity expression, string databaseType) : base(mapping, expression, databaseType) { string provider = DatabaseType.GetProviderName(databaseType); string cast = DatabaseType.DatabaseSettings[provider].DateCast; /* if (databaseType.Equals(DatabaseType.Mappings.Oracle.Name, StringComparison.OrdinalIgnoreCase) || databaseType.Equals(DatabaseType.Mappings.MySql.Name, StringComparison.OrdinalIgnoreCase)) { cast = "DATE"; } */ var dateColumnSysId = expression.DateColumnSysId; string columnName = GetColumnName(mapping, dateColumnSysId); this._startWhereFormat = string.Format( CultureInfo.InvariantCulture, "({0}>= {2}'{1}')", columnName, "{0}", cast); this._endWhereFormat = string.Format( CultureInfo.InvariantCulture, "({0}<= {2}'{1}')", columnName, "{0}", cast); this._resultParsingMap.Add(typeof(DateTime), x => (DateTime)x); this._resultParsingMap.Add(typeof(long), x => new DateTime((long)x)); this._resultParsingMap.Add( typeof(string), x => { DateTime time; return DateTime.TryParse((string)x, CultureInfo.InvariantCulture, DateTimeStyles.None, out time) ? DateTime.MinValue : time; }); this._fieldOrdinals = new TimeTranscodingFieldOrdinal(mapping, this.Expression); }
/// <summary> /// Initializes a new instance of the <see cref="TimeDimensionConstant"/> class. /// Initialize an new instance of the TimeDimensionMapping based class /// </summary> /// <param name="mapping"> /// The time dimension mapping /// </param> /// <param name="expression"> /// It is not used in this implementation /// </param> /// <param name="databaseType"> /// The dissemination database vendor from DB_CONNECTION.DB_TYPE at Mapping Store database. It is used to determine the substring command to use /// </param> /// <exception cref="TranscodingException"> /// It is not used in this implementation /// </exception> public TimeDimensionConstant(MappingEntity mapping, TimeExpressionEntity expression, string databaseType) : base(mapping, expression, databaseType) { this._fromWhere = string.Format( CultureInfo.InvariantCulture, " ( '{0}' >= '{1}' )", mapping.Constant, "{0}"); this._toWhere = string.Format(CultureInfo.InvariantCulture, " ( '{0}' <= '{1}' )", mapping.Constant, "{0}"); this._equalsWhere = string.Format( CultureInfo.InvariantCulture, " ( '{0}' = '{1}' )", mapping.Constant, "{0}"); }
/// <summary> /// Initializes a new instance of the <see cref="TimeDimension1To1"/> class. /// Initialize an new instance of the TimeDimensionMapping based class /// </summary> /// <param name="mapping"> /// The time dimension mapping /// </param> /// <param name="expression"> /// It is not used in this implementation /// </param> /// <param name="databaseType"> /// The dissemination database vendor from DB_CONNECTION.DB_TYPE at Mapping Store database. It is used to determine the substring command to use /// </param> /// <exception cref="TranscodingException"> /// It is not used in this implementation /// </exception> public TimeDimension1To1(MappingEntity mapping, TimeExpressionEntity expression, string databaseType) : base(mapping, expression, databaseType) { this._fromWhere = string.Format( CultureInfo.InvariantCulture, " ( {0} >= '{1}' )", mapping.Columns[0].Name, "{0}"); this._toWhere = string.Format( CultureInfo.InvariantCulture, " ( {0} <= '{1}' )", mapping.Columns[0].Name, "{0}"); this._equalsWhere = string.Format( CultureInfo.InvariantCulture, " ( {0} = '{1}' )", mapping.Columns[0].Name, "{0}"); }
/// <summary> /// Initializes a new instance of the <see cref="TimeDimensionMapping"/> class. /// Initialize an new instance of the TimeDimensionMapping based class /// </summary> /// <param name="mapping"> /// The time dimension mapping /// </param> /// <param name="expression"> /// The TRANSCODING.EXPRESSION contents /// </param> /// <param name="databaseType"> /// The dissemination database vendor from DB_CONNECTION.DB_TYPE at Mapping Store database. It is used to determine the substring command to use /// </param> /// <exception cref="TranscodingException"> /// Occurs when transcoding cannot performed due to incorrect mapping store data /// </exception> protected TimeDimensionMapping(MappingEntity mapping, TimeExpressionEntity expression, string databaseType) { this.Mapping = mapping; this.Component = mapping.Components[0]; this._expression = expression; this.SetDbType(databaseType); if (expression != null) { this._periodicity = PeriodicityFactory.Create(expression.Freq); } }
/// <summary> /// Initializes a new instance of the <see cref="TimeTranscodingFieldOrdinal"/> class. /// Initializes a new instance of the <see cref="T:System.Object"/> class. /// </summary> /// <param name="mapping"> /// The mapping. /// </param> /// <param name="expression"> /// The expression. /// </param> public TimeTranscodingFieldOrdinal(MappingEntity mapping, TimeExpressionEntity expression) { this._yearColumn = new NameOrdinal(GetColumnName(mapping, expression.YearColumnSysId)); this._periodColumn = new NameOrdinal(GetColumnName(mapping, expression.PeriodColumnSysId)); this._dateColumn = new NameOrdinal(GetColumnName(mapping, expression.DateColumnSysId)); if (this._yearColumn.IsSet) { this._nameOrdinals = this._periodColumn.IsSet ? new[] { this._yearColumn, this._periodColumn } : new[] { this._yearColumn }; } else { this._nameOrdinals = new[] { this._dateColumn }; } }
/// <summary> /// Initializes a new instance of the <see cref="TimeDimension1Column"/> class. /// </summary> /// <param name="mapping"> /// The time dimension mapping /// </param> /// <param name="expression"> /// The TRANSCODING.EXPRESSION contents /// </param> /// <param name="databaseType"> /// The dissemination database vendor from DB_CONNECTION.DB_TYPE at Mapping Store database. It is used to determine the substring command to use /// </param> /// <exception cref="TranscodingException"> /// Occurs when transcoding cannot performed due to incorrect mapping store data /// </exception> public TimeDimension1Column(MappingEntity mapping, TimeExpressionEntity expression, string databaseType) : base(mapping, expression, databaseType) { this._periodLocalCode = new CodeCollection(); string yearPeriodColumn = GetColumnName(mapping, expression.YearColumnSysId); string yearOnlyStart = this.CreateSubStringClause(yearPeriodColumn, expression.YearStart + 1, expression.YearLength, ">="); string yearOnlyEnd = this.CreateSubStringClause(yearPeriodColumn, expression.YearStart + 1, expression.YearLength, "<="); string whereFormat = this.CreateSubStringClause(yearPeriodColumn, expression.PeriodStart + 1, expression.PeriodLength, "="); string yearOnlyWhereFormat = this.CreateSubStringClause(yearPeriodColumn, expression.YearStart + 1, expression.YearLength, "="); this._whereBuilder = new TimeTranscodingWhereBuilder(this.Periodicity, this.Expression, whereFormat, yearOnlyEnd, yearOnlyStart, yearOnlyWhereFormat); this._fieldOrdinals = new TimeTranscodingFieldOrdinal(mapping, this.Expression); }
/// <summary> /// Create an <see cref="TimeExpressionEntity"/> instance from the specified <paramref name="timeTranscoding"/> /// </summary> /// <param name="timeTranscoding"> /// The Mapping store Time Transcoding /// </param> /// <returns> /// An <see cref="TimeExpressionEntity"/> /// </returns> public static TimeExpressionEntity CreateExpression(TimeTranscodingEntity timeTranscoding) { var expr = new TimeExpressionEntity(); Match match = TimeExpressionRegex.Match(timeTranscoding.Expression); expr.Freq = TimeFormat.GetTimeFormatFromCodeId(timeTranscoding.FrequencyValue).EnumType; expr.IsDateTime = match.Groups["datetime"].Value.Equals("1"); expr.TranscodingRules = timeTranscoding.TranscodingRules; if (!expr.IsDateTime) { expr.YearStart = Convert.ToInt32(match.Groups["year_start"].Value, CultureInfo.InvariantCulture); expr.YearLength = Convert.ToInt32(match.Groups["year_len"].Value, CultureInfo.InvariantCulture); if (expr.YearLength == 0) { expr.YearLength = 4; } expr.YearColumnSysId = timeTranscoding.YearColumnId; expr.PeriodStart = 0; expr.PeriodLength = 0; expr.PeriodColumnSysId = 0; if (expr.Freq != TimeFormatEnumType.Year) { expr.PeriodColumnSysId = timeTranscoding.PeriodColumnId; expr.PeriodStart = Convert.ToInt32(match.Groups["period_start"].Value, CultureInfo.InvariantCulture); expr.PeriodLength = Convert.ToInt32(match.Groups["period_len"].Value, CultureInfo.InvariantCulture); expr.OneColumnMapping = expr.YearColumnSysId == expr.PeriodColumnSysId; } else { expr.OneColumnMapping = true; } } else { expr.DateColumnSysId = timeTranscoding.DateColumnId; } return(expr); }
/// <summary> /// Initializes a new instance of the <see cref="TimeDimension2Column"/> class. /// </summary> /// <param name="mapping"> /// The time dimension mapping /// </param> /// <param name="expression"> /// The TRANSCODING.EXPRESSION contents /// </param> /// <param name="databaseType"> /// The dissemination database vendor from DB_CONNECTION.DB_TYPE at Mapping Store database. It is used to determine the substring command to use /// </param> /// <exception cref="TranscodingException"> /// Occurs when transcoding cannot performed due to incorrect mapping store data /// </exception> public TimeDimension2Column(MappingEntity mapping, TimeExpressionEntity expression, string databaseType) : base(mapping, expression, databaseType) { string yearOnlyWhereFormat; string yearOnlyStart; string yearOnlyEnd; string whereFormat; this._periodLocalCode = new CodeCollection(); string yearColumn = GetColumnName(mapping, expression.YearColumnSysId); string periodColumn = GetColumnName(mapping, expression.PeriodColumnSysId); string periodClause = expression.PeriodLength == 0 ? string.Format(FormatProvider, "( {0} = '{1}' )", periodColumn, "{0}") : this.CreateSubStringClause(periodColumn, expression.PeriodStart + 1, expression.PeriodLength, "="); if (expression.YearLength == 0) { yearOnlyStart = string.Format(FormatProvider, " ( {0} >= '{1}' )", yearColumn, "{0}"); yearOnlyEnd = string.Format(FormatProvider, " ( {0} <= '{1}' )", yearColumn, "{0}"); yearOnlyWhereFormat = string.Format(FormatProvider, "( {0} = '{1}' )", yearColumn, "{0}"); // whereFormat = String.Format(FormatProvider,"({0} = '{1}' and {2} )",yearColumn, "{0}",periodClause); whereFormat = periodClause; } else { yearOnlyStart = this.CreateSubStringClause(yearColumn, expression.YearStart + 1, expression.YearLength, ">="); yearOnlyEnd = this.CreateSubStringClause(yearColumn, expression.YearStart + 1, expression.YearLength, "<="); whereFormat = periodClause; yearOnlyWhereFormat = this.CreateSubStringClause(yearColumn, expression.YearStart + 1, expression.YearLength, "="); } this._whereBuilder = new TimeTranscodingWhereBuilder(this.Periodicity, this.Expression, whereFormat, yearOnlyEnd, yearOnlyStart, yearOnlyWhereFormat); this._fieldOrdinals = new TimeTranscodingFieldOrdinal(mapping, this.Expression); }
/// <summary> /// Create an <see cref="TimeExpressionEntity"/> instance from the specified <paramref name="timeTranscoding"/> /// </summary> /// <param name="timeTranscoding"> /// The Mapping store Time Transcoding /// </param> /// <returns> /// An <see cref="TimeExpressionEntity"/> /// </returns> public static TimeExpressionEntity CreateExpression(TimeTranscodingEntity timeTranscoding) { var expr = new TimeExpressionEntity(); Match match = TimeExpressionRegex.Match(timeTranscoding.Expression); expr.Freq = TimeFormat.GetTimeFormatFromCodeId(timeTranscoding.FrequencyValue).EnumType; expr.IsDateTime = match.Groups["datetime"].Value.Equals("1"); expr.TranscodingRules = timeTranscoding.TranscodingRules; if (!expr.IsDateTime) { expr.YearStart = Convert.ToInt32(match.Groups["year_start"].Value, CultureInfo.InvariantCulture); expr.YearLength = Convert.ToInt32(match.Groups["year_len"].Value, CultureInfo.InvariantCulture); if (expr.YearLength == 0) { expr.YearLength = 4; } expr.YearColumnSysId = timeTranscoding.YearColumnId; expr.PeriodStart = 0; expr.PeriodLength = 0; expr.PeriodColumnSysId = 0; if (expr.Freq != TimeFormatEnumType.Year) { expr.PeriodColumnSysId = timeTranscoding.PeriodColumnId; expr.PeriodStart = Convert.ToInt32(match.Groups["period_start"].Value, CultureInfo.InvariantCulture); expr.PeriodLength = Convert.ToInt32(match.Groups["period_len"].Value, CultureInfo.InvariantCulture); expr.OneColumnMapping = expr.YearColumnSysId == expr.PeriodColumnSysId; } else { expr.OneColumnMapping = true; } } else { expr.DateColumnSysId = timeTranscoding.DateColumnId; } return expr; }
/// <summary> /// Initializes a new instance of the <see cref="TimeTranscodingWhereBuilder"/> class. /// </summary> /// <param name="periodicity"> /// The periodicity. /// </param> /// <param name="expressionEntity"> /// The expression Entity. /// </param> /// <param name="whereFormat"> /// The where Format. /// </param> /// <param name="yearOnlyEnd"> /// The year Only End. /// </param> /// <param name="yearOnlyStart"> /// The year Only Start. /// </param> /// <param name="yearOnlyWhereFormat"> /// The year Only Where Format. /// </param> public TimeTranscodingWhereBuilder(IPeriodicity periodicity, TimeExpressionEntity expressionEntity, string whereFormat, string yearOnlyEnd, string yearOnlyStart, string yearOnlyWhereFormat) { this._periodicity = periodicity; this._expressionEntity = expressionEntity; this._whereFormat = whereFormat; this._yearOnlyEnd = yearOnlyEnd; this._yearOnlyStart = yearOnlyStart; this._yearOnlyWhereFormat = yearOnlyWhereFormat; }
/// <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; }