/// <summary>
        /// Sets the group by clause.
        /// </summary>
        private void SetGroupByClause()
        {
            int    iIndex     = -1;
            string nameFormat = m_DataObjectBroker.ConnectionInfo.NameFormat();

            GroupBy = string.Empty;

            foreach (GroupCriterion groupCriterion in base.GroupCriteriaList)
            {
                string persistentTypeName = AppInfo.GetTableName(groupCriterion.Type);
                //string persistentTypeName = ((TableAttribute[])groupCriterion.Type.GetCustomAttributes(typeof(TableAttribute), false))[0].TableName;
                iIndex++;

                if (iIndex > 0)
                {
                    GroupBy += ", ";
                }

                GroupBy += string.Format(nameFormat, persistentTypeName) + ".";

                if (groupCriterion.OriginalPropertyName != "ObjectKey")
                {
                    GroupBy += string.Format(nameFormat, groupCriterion.OriginalPropertyName);
                }
                else
                {
                    GroupBy += string.Format(nameFormat, persistentTypeName + "Key");
                }
            }

            if (GroupBy.Length > 0)
            {
                GroupBy = " GROUP BY " + GroupBy;
            }
        }
        /// <summary>
        /// Gets the column list.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <returns></returns>
        public string GetColumnList(System.Type objectType)
        {
            int    index            = -1;
            string returnColumnList = String.Empty;

            foreach (GroupCriterion groupCriterion in base.GroupCriteriaList)
            {
                string persistentTypeName = AppInfo.GetTableName(groupCriterion.Type);
                //string persistentTypeName = ((TableAttribute[])groupCriterion.Type.GetCustomAttributes(typeof(TableAttribute), false))[0].TableName;

                if (groupCriterion.Type != objectType)
                {
                    index++;
                    if (index > 0)
                    {
                        returnColumnList += ", ";
                    }

                    returnColumnList += persistentTypeName + ".";

                    if (groupCriterion.OriginalPropertyName != "ObjectKey")
                    {
                        returnColumnList += groupCriterion.OriginalPropertyName;
                    }
                    else
                    {
                        returnColumnList += persistentTypeName + "Key";
                    }
                }
            }
            return(returnColumnList);
        }
        public string GetXmlColumnList()
        {
            int           index = -1;
            StringBuilder str   = new StringBuilder();

            foreach (OrderCriterion orderCriterion in base.OrderCriteriaList)
            {
                string persistentTypeName = AppInfo.GetTableName(orderCriterion.Type);
                //string persistentTypeName = ((TableAttribute[])orderCriterion.Type.GetCustomAttributes(typeof(TableAttribute), false))[0].TableName;

                if (orderCriterion.DataType != null)
                {
                    index++;
                    if (index > 0)
                    {
                        str.Append(",");
                    }

                    char[]   delimiterChars = { '.' };
                    string[] xmlColumn      = orderCriterion.OriginalPropertyName.Split(delimiterChars);

                    str.AppendFormat("{0}.{1}.value('(/{2}{3})[1]', '{4}') {5}",
                                     persistentTypeName,
                                     xmlColumn[0],
                                     orderCriterion.XmlPath,
                                     xmlColumn[1],
                                     GetDataType(orderCriterion),
                                     orderCriterion.OriginalPropertyName);
                }
            }

            return(str.ToString());
        }
Exemple #4
0
        /// <summary>
        /// Columns the alias.
        /// </summary>
        /// <param name="selectionCriterion">The selectionCriterion.</param>
        /// <returns></returns>
        private string ColumnAlias(SelectionCriterion selectionCriterion)
        {
            string str = string.Empty;

            if ((selectionCriterion == null) || (selectionCriterion.Property == null))
            {
                throw new NullReferenceException("SelectionCriterion cannot be null!");
            }
            if (selectionCriterion.DataType == null)
            {
                str = selectionCriterion.PropertyAlias;
            }
            else
            {
                char[]   delimiterChars     = { '.' };
                string[] xmlColumn          = selectionCriterion.OriginalPropertyName.Split(delimiterChars);
                string   persistentTypeName = AppInfo.GetTableName(selectionCriterion.Type);
                str = m_DataObjectBroker.ConnectionInfo.GetColumnAlias(persistentTypeName, xmlColumn, selectionCriterion.XmlPath, GetDataType(selectionCriterion), selectionCriterion);
            }
            return(str);
        }
Exemple #5
0
        /// <summary>
        /// Selections the clause.
        /// </summary>
        /// <param name="selectionCriterion">The selectionCriterion.</param>
        /// <returns></returns>
        private string SelectionClause(SelectionCriterion selectionCriterion, bool forParameters)
        {
            string result = string.Empty;

            if (selectionCriterion.Expression == Expression.None)
            {
                if (selectionCriterion == null)
                {
                    throw new NullReferenceException("SelectionCriterion cannot be null!");
                }
                if (!m_Types.Contains(selectionCriterion.Type))
                {
                    m_Types.Add(selectionCriterion.Type);
                }
                selectionCriterion.PropertyAlias = AppInfo.GetTableName(selectionCriterion.Type) + ".";
                if (selectionCriterion.OriginalPropertyName != "ObjectKey")
                {
                    selectionCriterion.PropertyAlias += selectionCriterion.OriginalPropertyName;
                }
                else
                {
                    selectionCriterion.PropertyAlias += AppInfo.GetTableName(selectionCriterion.Type) + "Key";
                }
                string expression = string.Empty;
                if (m_PreviousSelectionCriterion != null && m_PreviousSelectionCriterion.Expression == Expression.Begin)
                {
                    expression = "(";
                }
                if (forParameters)
                {
                    object value = selectionCriterion.Value;
                    if (selectionCriterion.ComparisonMethod == ComparisonMethod.In || selectionCriterion.ComparisonMethod == ComparisonMethod.NotIn)
                    {
                        if (value != null)
                        {
                            object   obj   = value;
                            Array    array = obj as Array;
                            object[] objs  = new object[array.Length];
                            int      i     = 0;
                            foreach (var item in array)
                            {
                                objs[i++] = item;
                            }
                            value = objs;
                        }
                        else
                        {
                            throw new InvalidOperationException("ComparisonMethod.In/ComparisonMethod.NotIn cannot have a null object value");
                        }
                    }
                    string text = ComparisonTextForParameters(m_DataObjectBroker, selectionCriterion.ComparisonMethod, ref value, m_Parameters.Count);
                    if (value != null)
                    {
                        if (selectionCriterion.ComparisonMethod != ComparisonMethod.In && selectionCriterion.ComparisonMethod != ComparisonMethod.NotIn)
                        {
                            m_Parameters.Add(value);
                        }
                        else
                        {
                            for (int i = 0; i < ((object[])value).Length; i++)
                            {
                                m_Parameters.Add(((object[])value)[i]);
                            }
                        }
                    }
                    result = OperandText(selectionCriterion.OperandType) + " " + expression + ColumnAlias(selectionCriterion) + " " + text + " ";
                }
                else
                {
                    result = OperandText(selectionCriterion.OperandType) + " " + expression +
                             ColumnAlias(selectionCriterion) + " " +
                             ComparisonText(m_DataObjectBroker, selectionCriterion.ComparisonMethod, selectionCriterion.Value, selectionCriterion.Property.PropertyType) + " ";
                }
            }
            else if (selectionCriterion.Expression == Expression.Begin)
            {
                result = string.Empty;
            }
            else if (selectionCriterion.Expression == Expression.End)
            {
                result = ") ";
            }
            else
            {
                throw new ApplicationException("Could not generate where clause!");
            }
            m_PreviousSelectionCriterion = selectionCriterion;
            return(result);
        }
        /// <summary>
        /// Sets the order by clause.
        /// </summary>
        private void SetOrderByClause()
        {
            int index = -1;

            OrderBy = string.Empty;

            foreach (OrderCriterion orderCriterion in base.OrderCriteriaList)
            {
                string persistentTypeName = AppInfo.GetTableName(orderCriterion.Type);

                index++;

                if (index > 0)
                {
                    OrderBy += ", ";
                }

                if (orderCriterion.OriginalPropertyName != "ObjectKey")
                {
                    if (orderCriterion.XmlPath == string.Empty)
                    {
                        string pTypeName = PersistentTypeName != null && !String.Empty.Equals(PersistentTypeName) ? PersistentTypeName : persistentTypeName;
                        string field     = string.Format("{0}." + "{1}", pTypeName, orderCriterion.OriginalPropertyName);

                        if (orderCriterion.AggregateFunction == AggregateFunction.None)
                        {
                            OrderBy += field;
                        }
                        else
                        {
                            OrderBy += string.Format("{0}({1})", orderCriterion.AggregateFunction, field);
                        }
                    }
                    else
                    {
                        char[]   delimiterChars = { '.' };
                        string[] xmlColumn      = orderCriterion.OriginalPropertyName.Split(delimiterChars);
                        OrderBy += m_DataObjectBroker.ConnectionInfo.GetXmlOrder(persistentTypeName, xmlColumn, orderCriterion.XmlPath, GetDataType(orderCriterion));
                    }
                }
                else
                {
                    string field = persistentTypeName + "." + persistentTypeName + "Key";

                    if (orderCriterion.AggregateFunction == AggregateFunction.None)
                    {
                        OrderBy += field;
                    }
                    else
                    {
                        OrderBy += string.Format("{0}({1})", orderCriterion.AggregateFunction, field);
                    }
                }

                OrderBy += " ";

                if (m_Reverse)
                {
                    if (orderCriterion.SortOrder.ToUpper().Equals("ASC"))
                    {
                        orderCriterion.SortOrder = "DESC";
                    }
                    else
                    {
                        orderCriterion.SortOrder = "ASC";
                    }
                }

                OrderBy += orderCriterion.SortOrder;
            }

            if (OrderBy.Length > 0)
            {
                OrderBy = "ORDER BY " + OrderBy;
            }
        }