コード例 #1
0
ファイル: BaseGenOsqlHelper.cs プロジェクト: leonchen09/poc
        private int GetParentTableInexInJoinClause(DSRelationRow whereRelation, DSRelationRow tableRelation)
        {
            // or relation
            DSRelationRow relation = whereRelation;

            if (relation != null)
            {
                relation = relation.Clone();
                if (tableRelation != null)
                {
                    relation.OrRow(tableRelation);
                }
            }

            // check index
            for (int i = 0; i < relation.Data.Count; i++)
            {
                long num   = relation.Data[i];
                int  index = i * 64;
                do
                {
                    int bit = (int)num % 2;
                    if (bit == 1)
                    {
                        return(index);
                    }

                    index++;
                    num = num >> 1; //ShiftRight(num, 1);
                }while (num > 0);
            }

            return(-1);
        }
コード例 #2
0
ファイル: BaseGenOsqlHelper.cs プロジェクト: leonchen09/poc
        protected void GenWhereClause(ref GenOsqlParamInfo paramInfo)
        {
            if (paramInfo.WhereClauses == null)
            {
                paramInfo.WhereClauses = new List <string>();
            }
            if (paramInfo.JWhereClauses == null)
            {
                paramInfo.JWhereClauses = new List <string>();
            }
            if (paramInfo.DomainInfo.DSDomainData.WhereClause.DSJoins == null ||
                paramInfo.DomainInfo.DSDomainData.WhereClause.DSJoins.Count == 0)
            {
                paramInfo.WhereClauses.Add(paramInfo.DomainInfo.DSDomainData.WhereClause.Clause);
                paramInfo.JWhereClauses.Add(paramInfo.DomainInfo.DSDomainData.WhereClause.JavaClause);
            }
            else
            {
                paramInfo.DSWhereClauseRelationRow = null;
                string whereClause  = string.Empty;
                string jWhereClause = string.Empty;
                string logicType    = string.Empty;
                bool   hasRootJoin  = false;
                foreach (DSJoin dsJoin in paramInfo.DomainInfo.DSDomainData.WhereClause.DSJoins)
                {
                    string usedTables = BitHelper.ToBinaryFormat(dsJoin.Tables.Data, true);
                    usedTables = BaseMarkupUtilities.ReverseString(usedTables);
                    bool isUseDSJoin = true;

                    #region check use or no
                    for (int index = 0; index < usedTables.Length; index++)
                    {
                        if (usedTables[index] == '1')
                        {
                            if (!paramInfo.SelectedTableIndexes.Contains(index))
                            {
                                isUseDSJoin = false;
                                break;
                            }
                        }
                    }
                    if (!isUseDSJoin)
                    {
                        continue;
                    }
                    #endregion

                    #region build where clause
                    if ("and".Equals(dsJoin.LogicType, StringComparison.OrdinalIgnoreCase) ||
                        "or".Equals(dsJoin.LogicType, StringComparison.OrdinalIgnoreCase))
                    {
                        if (!hasRootJoin)
                        {
                            whereClause  = dsJoin.LogicType + " " + dsJoin.Condition + " " + whereClause;
                            jWhereClause = dsJoin.LogicType + " " + dsJoin.JavaCondition + " " + jWhereClause;
                        }
                        else
                        {
                            whereClause  = whereClause + " " + dsJoin.LogicType + " " + dsJoin.Condition;
                            jWhereClause = jWhereClause + " " + dsJoin.LogicType + " " + dsJoin.JavaCondition;
                        }
                        logicType = dsJoin.LogicType;
                    }
                    else
                    {
                        whereClause  = dsJoin.Condition + " " + whereClause;
                        jWhereClause = dsJoin.JavaCondition + " " + jWhereClause;
                        hasRootJoin  = true;
                    }
                    #endregion

                    #region mark used for gen from clause
                    if (paramInfo.DSWhereClauseRelationRow == null)
                    {
                        paramInfo.DSWhereClauseRelationRow = dsJoin.Tables.Clone();
                    }
                    else
                    {
                        paramInfo.DSWhereClauseRelationRow.OrRow(dsJoin.Tables);
                    }
                    #endregion
                }

                if (!hasRootJoin && !string.IsNullOrWhiteSpace(logicType))
                {
                    whereClause  = whereClause.Substring(logicType.Length);
                    jWhereClause = jWhereClause.Substring(logicType.Length);
                }
                paramInfo.WhereClauses.Add(whereClause);
                paramInfo.JWhereClauses.Add(jWhereClause);
                if (paramInfo.DSWhereClauseRelationRow == null)
                {
                    DSRelationRow templateRow = paramInfo.DomainInfo.DSDomainData.WhereClause.DSJoins[0].Tables;
                    paramInfo.DSWhereClauseRelationRow = templateRow.Clone();
                    for (int index = 0; index < paramInfo.DSWhereClauseRelationRow.Data.Count; index++)
                    {
                        paramInfo.DSWhereClauseRelationRow.Data[index] = paramInfo.DSWhereClauseRelationRow.Data[index] & 0;
                    }
                    foreach (int tableIndex in paramInfo.SelectedTableIndexes)
                    {
                        int index = (tableIndex / 64) + (tableIndex % 64 != 0 ? 1 : 0);
                        index--;
                        if (index >= 0 && index < paramInfo.DSWhereClauseRelationRow.Data.Count)
                        {
                            int position = tableIndex % 64;
                            paramInfo.DSWhereClauseRelationRow.Data[index] =
                                paramInfo.DSWhereClauseRelationRow.TurnOnBit(paramInfo.DSWhereClauseRelationRow.Data[index], position);
                        }
                    }
                }
            }
        }