Example #1
0
        protected string GenSelectClauseForUSC(InternalBookmarkItem ibmItem, ref GenOsqlParamInfo paramInfo)
        {
            //1.Find USC bookmark in the list Conditions to get actual USC.
            //2.Build SQl
            string sqlClause = string.Empty;
            string itemName  = BaseMarkupUtilities.GetOriginalBizName(ibmItem.Key, ibmItem.BizName);

            if (paramInfo.UscItems == null || paramInfo.UscItems.Count <= 0 || ibmItem.Key.EndsWith(BaseProntoMarkup.KeyEndIf))
            {
                return(sqlClause);
            }

            USCItem uscItem = null;

            if (paramInfo.UscItems.Keys.Contains(itemName))
            {
                uscItem = paramInfo.UscItems[itemName];
            }

            //
            Dictionary <string, DSTreeView> lowerFields = new Dictionary <string, DSTreeView>();

            foreach (string key in paramInfo.DomainInfo.Fields.Keys)
            {
                lowerFields.Add(key.ToLower(), paramInfo.DomainInfo.Fields[key]);
            }

            //Validate and Build SQl
            if (uscItem != null)
            {
                List <Token>       lstTokens       = new List <Token>();
                string             error           = string.Empty;
                ExpressionProvider expressProvider = new ExpressionProvider();
                expressProvider.DoTokenize(uscItem.SQLExpression, ref lstTokens, ref error);

                foreach (Token token in lstTokens)
                {
                    string key = string.Empty;
                    if (token.Name.Contains("[") && token.Name.Contains("]"))
                    {
                        key = token.Name.Substring(1, token.Name.Length - 2).ToLower();
                        if (lowerFields.ContainsKey(key))
                        {
                            token.Name = lowerFields[key].TechName;

                            if (paramInfo.DSRelationRow == null)
                            {
                                paramInfo.DSRelationRow = lowerFields[key].Relation.Clone();
                            }
                            else
                            {
                                paramInfo.DSRelationRow.OrRow(lowerFields[key].Relation);
                            }
                        }
                    }
                    sqlClause += token.Name + " ";
                }
            }
            return(sqlClause.Trim());
        }
Example #2
0
        private bool ProcessUSCTag(InternalBookmarkItem ibmItem, DSIconType dataTagType, string itemName,
                                   ref GenOsqlParamInfo paramInfo, ref Dictionary <string, bool> dataTagChecker)
        {
            if (dataTagType == DSIconType.USC)
            {
                GetTableIndexForUSC(ibmItem, ref paramInfo);
                USCItem usc            = paramInfo.UscItems[itemName];
                string  orderFieldName = usc.BaseOnField;

                if (!string.IsNullOrWhiteSpace(orderFieldName) && !dataTagChecker.ContainsKey(orderFieldName))
                {
                    InternalBookmarkItem exist = (from c in paramInfo.IbmDomain.InternalBookmarkItems
                                                  where (c.TableIndex == usc.TableIndex) && (string.Equals(c.ItemType, DSIconType.Field.ToString()))
                                                  select c).FirstOrDefault();
                    //If existed one data field in selected tag, shouldnot include data field in udf
                    if (exist == null || string.IsNullOrEmpty(exist.BizName))
                    {
                        InternalBookmarkItem bm = AddUdfFields(orderFieldName, ref paramInfo);
                        dataTagChecker.Add(BaseMarkupUtilities.GetOriginalBizName(bm.Key, bm.BizName), true);
                    }
                    else
                    {
                        dataTagChecker.Add(itemName, true);
                        paramInfo.AddDataTags(ibmItem, true);
                    }
                }

                return(true);
            }

            return(false);
        }
Example #3
0
        private bool ProcessStartForeachTag(string ibmItemKey, string ibmItemBizName,
                                            ref GenOsqlParamInfo paramInfo, ref Dictionary <string, bool> dataTagChecker)
        {
            if (ibmItemKey.Contains(BaseProntoMarkup.KeyStartForeach)) // update for add sort item in for-each
            {
                Dictionary <string, OrderByType> sorteds = BaseMarkupUtilities.GetOldOrderBy(ibmItemBizName, false);
                if (sorteds.Count > 0) // has sort in for-each
                {
                    foreach (string orderBizName in sorteds.Keys)
                    {
                        string sortBizName = paramInfo.DomainInfo.GetUdfSortedBizName(orderBizName);
                        if (sortBizName != orderBizName) // has order by bizname
                        {
                            if (dataTagChecker.ContainsKey(sortBizName))
                            {
                                continue;
                            }

                            InternalBookmarkItem bm = AddUdfFields(sortBizName, ref paramInfo);
                            dataTagChecker.Add(BaseMarkupUtilities.GetOriginalBizName(bm.Key, bm.BizName), true);
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
Example #4
0
        private void GenSelectClauseForField(InternalBookmarkItem bmItem, ref GenOsqlParamInfo paramInfo)
        {
            string     itemName = BaseMarkupUtilities.GetOriginalBizName(bmItem.Key, bmItem.BizName);
            DSTreeView item     = paramInfo.DomainInfo.GetField(itemName);
            DSIconType type     = (DSIconType)Enum.Parse(typeof(DSIconType), bmItem.ItemType);

            double     i         = Math.Log((double)bmItem.TableIndex, (double)2);
            DSOnClause table     = paramInfo.DomainInfo.DSDomainData.OnClauses.Items[bmItem.TableIndex];
            string     tableName = table.Alias;

            paramInfo.PutSelectedTable(tableName, false);
            paramInfo.SelectedTableIndexes.Add(item.TableIndex);

            UpdateSelectedColumns(ref paramInfo, tableName, itemName);
            InternalBookmarkItem existedItem = paramInfo.DataTagFields.FirstOrDefault(a => a.TableIndex == item.TableIndex && a.DSIconType == DSIconType.Field);
            bool isImageTrunc = bmItem.IsTruncImage();

            if (isImageTrunc && existedItem != null && existedItem.BizName == bmItem.BizName && !paramInfo.TablesHasField.Contains(item.TableIndex))
            { // this table has only image that is chunked then we need to add one default column
                GenSelectClauseItem(DSIconType.Field, item.TechName,
                                    string.Empty, Guid.NewGuid().ToString(), false, true, ref paramInfo);
                paramInfo.TablesHasField.Add(item.TableIndex);
                paramInfo.HasImage = true;
            }
            GenSelectClauseItem(type, bmItem.TechName, item.JavaClause, itemName, bmItem.IsTruncImage(), true, ref paramInfo);

            if (!string.IsNullOrEmpty(item.RenderXYOrder))
            {
                List <string> renderParam = item.RenderXYOrder.Split(';').ToList <string>();
                for (int j = 0; j < renderParam.Count; j++)
                {
                    AddItemToListJParameters((renderParam[j] == "1") ? FrameworkConstants.RenderArgumentX : FrameworkConstants.RenderArgumentY,
                                             ref paramInfo, OracleQueryConstants.DicSelectClauseParamName);
                }
            }

            #region Build Extra field
            if (existedItem == null && !string.IsNullOrEmpty(item.OrginalField) && !paramInfo.TablesHasField.Contains(item.TableIndex))
            {
                GenSelectClauseItem(DSIconType.Field, item.OrginalField, string.Empty, Guid.NewGuid().ToString(), false, true, ref paramInfo);
                paramInfo.TablesHasField.Add(item.TableIndex);
                return;
            }
            #endregion
        }
Example #5
0
        /// <summary>
        /// get list of data tag fields, data tag others and renderxy
        /// </summary>
        /// <param name="paramInfo"></param>
        protected void AnalyzeDataTag(ref GenOsqlParamInfo paramInfo)
        {
            paramInfo.RenderXY = 0;
            paramInfo.UpdateUSCItemsDictionary();

            int itemIndex = 0;
            Dictionary <string, bool> dataTagChecker = new Dictionary <string, bool>();

            while (itemIndex < paramInfo.IbmDomain.InternalBookmarkItems.Count)
            {
                InternalBookmarkItem ibmItem = paramInfo.IbmDomain.InternalBookmarkItems[itemIndex];
                DSIconType           type    = ibmItem.DSIconType;
                string     itemName          = BaseMarkupUtilities.GetOriginalBizName(ibmItem.Key, ibmItem.BizName);
                DSTreeView dsObject          = paramInfo.DomainInfo.GetField(itemName);

                if (dsObject != null)
                {
                    paramInfo.RenderXY = paramInfo.RenderXY | CheckRenderXY(dsObject.RenderXYOrder);
                }
                else
                {
                    paramInfo.RenderXY = paramInfo.RenderXY | CheckRenderXY("0");
                }

                itemIndex++;
                if (ProcessEndForeachIfTag(ref paramInfo, ibmItem.Key, itemName, dataTagChecker))
                {
                    continue;
                }

                if (ProcessStartForeachTag(ibmItem.Key, ibmItem.BizName, ref paramInfo, ref dataTagChecker))
                {
                    continue;
                }

                if (ProcessUSCTag(ibmItem, type, itemName, ref paramInfo, ref dataTagChecker))
                {
                    continue;
                }

                ProcessSelectTag(ibmItem, type, itemName, ref paramInfo, ref dataTagChecker);
            }
        }
Example #6
0
        private int GetTableIndexForUSC(InternalBookmarkItem ibmItem, ref GenOsqlParamInfo paramInfo)
        {
            if (paramInfo.UscItems == null || paramInfo.UscItems.Count <= 0)
            {
                return(-1);
            }
            string  itemName = BaseMarkupUtilities.GetOriginalBizName(ibmItem.Key, ibmItem.BizName);
            USCItem item     = paramInfo.UscItems[itemName];
            int     maxIndex = -1;

            if (item.Fields.Count > 0)
            {
                foreach (USCItem subField in item.Fields)
                {
                    if (paramInfo.DomainInfo.Fields.Keys.Contains(subField.BusinessName))
                    {
                        if (maxIndex < paramInfo.DomainInfo.Fields[subField.BusinessName].TableIndex)
                        {
                            maxIndex         = paramInfo.DomainInfo.Fields[subField.BusinessName].TableIndex;
                            item.BaseOnField = string.IsNullOrWhiteSpace(paramInfo.DomainInfo.Fields[subField.BusinessName].OrginalField) ?
                                               paramInfo.DomainInfo.Fields[subField.BusinessName].Text : paramInfo.DomainInfo.Fields[subField.BusinessName].OrginalField;
                        }
                    }
                }
            }
            ibmItem.TableIndex = maxIndex;
            item.TableIndex    = maxIndex;

            //Update to Relation
            DSOnClause table     = paramInfo.DomainInfo.DSDomainData.OnClauses.Items[maxIndex];
            string     tableName = table.Alias;

            if (!paramInfo.DomainInfo.Relations.MapInfos.ContainsKey(itemName))
            {
                paramInfo.DomainInfo.Relations.MapInfos.Add(itemName, new Mapping(itemName, tableName, itemName));
            }
            else
            {
                paramInfo.DomainInfo.Relations.MapInfos[itemName].TableName = tableName;
            }

            return(maxIndex);
        }
Example #7
0
        private void GenSelectClauseForFields(ref GenOsqlParamInfo paramInfo)
        {
            paramInfo.HasImage = false;
            paramInfo.HasField = false;
            if (paramInfo.DataTagFields != null && paramInfo.DataTagFields.Count > 0)
            {
                paramInfo.OrderDataTagFieldsByTableIndex();
                List <List <InternalBookmarkItem> > paths = GetPaths(ref paramInfo, paramInfo.DataTagFields, paramInfo.DomainInfo.DSDomainData);
                foreach (List <InternalBookmarkItem> path in paths)
                {
                    if (path.Count <= 0)
                    {
                        continue;
                    }

                    paramInfo.OsqlStringBuilder = new OsqlStringBuilder();
                    paramInfo.OsqlStringBuilder.AppendLine(OracleQueryConstants.SelectClause);
                    paramInfo.DSRelationRow = null;
                    // add paramater for watermark at start of query for osql & jsql
                    paramInfo.OsqlStringBuilder.Osql.AppendLine(string.Format(OracleQueryConstants.SQLSystemInfo,
                                                                              ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwWatermark,
                                                                              ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwWatermark) + OracleQueryConstants.SQLComma);
                    paramInfo.OsqlStringBuilder.JOsql.AppendLine(string.Format(OracleQueryConstants.JSQLSystemInfo,
                                                                               ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwWatermark) + OracleQueryConstants.SQLComma);
                    paramInfo.OsqlStringBuilder.SelectedColumns = string.Empty;
                    paramInfo.CurrentTableName = string.Empty;
                    paramInfo.PutSelectedTable(string.Empty, true);
                    paramInfo.SelectedTableIndexes = new List <int>();
                    foreach (InternalBookmarkItem item in path)
                    {
                        DSIconType type = item.DSIconType;
                        if (type == DSIconType.Field)
                        {
                            paramInfo.HasField = true;
                        }

                        if (type == DSIconType.USC)
                        {
                            string sqlUSC      = GenSelectClauseForUSC(item, ref paramInfo);
                            string itemBizName = BaseMarkupUtilities.GetOriginalBizName(item.Key, item.BizName);
                            GenSelectClauseItem(type, sqlUSC, string.Empty, itemBizName, false, true, ref paramInfo);

                            string tableName = paramInfo.SelectedTables[0][0];
                            UpdateSelectedColumns(ref paramInfo, tableName, itemBizName);
                        }
                        else
                        {
                            if (item.Relation != null)
                            {
                                if (paramInfo.DSRelationRow == null)
                                {
                                    paramInfo.DSRelationRow = item.Relation.Clone();
                                }
                                else
                                {
                                    paramInfo.DSRelationRow.OrRow(item.Relation);
                                }
                            }

                            GenSelectClauseForField(item, ref paramInfo);
                        }

                        if (item != null && item.DataType != null &&
                            (item.DataType.Name == SQLTypeName.BINARY || item.DataType.Name == SQLTypeName.VARBINARY))
                        {
                            paramInfo.HasImage = true;
                        }
                    }
                    UpdateOsqlXmlItem(ref paramInfo);
                }
            }
        }