Exemple #1
0
        /// <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);
        }
Exemple #2
0
 /// <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}");
 }
Exemple #3
0
 /// <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;
 }
Exemple #4
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}");
 }
Exemple #5
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);
     }
 }
Exemple #6
0
 /// <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 };
     }
 }
Exemple #7
0
        /// <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);
        }
Exemple #8
0
        /// <summary>
        /// Create time dimension mapping with transcoding
        /// </summary>
        /// <param name="mapping">
        ///     The mapping entity<see cref="MappingEntity"/> of the Time Dimension component
        /// </param>
        /// <param name="databaseType">
        ///     The dissemination database vendor. Is needed to generate the correct SQL query where conditions
        /// </param>
        /// <param name="timeTranscoding">
        /// The Mapping Store <c>TIME_TRANSCODING</c> object
        /// </param>
        /// <exception cref="TranscodingException">
        /// Incomplete/Invalid mapping or expression
        /// </exception>
        /// <returns>
        /// An Time Dimension Transcoding object<see cref="ITimeDimension"/>
        /// </returns>
        private static ITimeDimensionMapping CreateTranscodedTimeDimensionMapping(MappingEntity mapping, string databaseType, TimeTranscodingEntity timeTranscoding)
        {
            ITimeDimensionMapping timeDimensionTranscoding;
            TimeExpressionEntity  expr = TimeExpressionEntity.CreateExpression(timeTranscoding);

            if (!expr.IsDateTime)
            {
                if (!expr.OneColumnMapping)
                {
                    timeDimensionTranscoding = new TimeDimension2Column(mapping, expr, databaseType);
                }
                else
                {
                    if (expr.YearLength != 4)
                    {
                        throw new TranscodingException(ErrorMessages.TimeDimensionYearNo4Digits);
                    }

                    if (expr.Freq != TimeFormatEnumType.Year)
                    {
                        if (expr.PeriodLength <= 0 && expr.YearStart > expr.PeriodStart)
                        {
                            throw new TranscodingException(ErrorMessages.TimeDimensionVariableLenPeriodNotFirst);
                        }

                        if (((expr.YearStart + expr.YearLength) > expr.PeriodStart && expr.YearStart < expr.PeriodStart)
                            ||
                            ((expr.PeriodStart + expr.PeriodLength) > expr.YearStart &&
                             expr.YearStart > expr.PeriodStart) || expr.PeriodStart == expr.YearStart)
                        {
                            throw new TranscodingException(ErrorMessages.TimeDimensionYearPeriodOverlap);
                        }
                    }

                    timeDimensionTranscoding = new TimeDimension1Column(mapping, expr, databaseType);
                }
            }
            else
            {
                timeDimensionTranscoding = new TimeDimensionDateType(mapping, expr, databaseType);
            }

            return(timeDimensionTranscoding);
        }
Exemple #9
0
        /// <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);
        }
Exemple #10
0
        /// <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);
        }