Пример #1
0
        private void AddJoin(QualifiedJoinType joinType, List <RbacSelectColumn> columns)
        {
            for (int c = 0; c < columns.Count; c += 2)
            {
                RbacJoin ajoin = new RbacJoin();
                ajoin.JoinType = (RbacJoinTypes)Enum.Parse(typeof(RbacJoinTypes), joinType.ToString(), true);

                ajoin.FromTableName   = columns[c].Table.Name;
                ajoin.FromTableAlias  = columns[c].Table.Alias;
                ajoin.FromTableColumn = columns[c].Name;

                ajoin.WithTableName   = columns[c + 1].Table.Name;
                ajoin.WithTableAlias  = columns[c + 1].Table.Alias;
                ajoin.WithTableColumn = columns[c + 1].Name;

                if (string.IsNullOrEmpty(ajoin.FromTableName))
                {
                    RbacTable table = Context.User.Role.CrudPermissions.Find(ajoin.FromTableAlias);
                    ajoin.FromTableName = table.Name;
                }
                if (string.IsNullOrEmpty(ajoin.WithTableName))
                {
                    RbacTable table = Context.User.Role.CrudPermissions.Find(ajoin.FromTableAlias);
                    ajoin.WithTableName = table.Name;
                }
                JoinClauses.Add(ajoin);
            }
        }
Пример #2
0
        public static RbacJoin AddNewJoin(SqlQueryParser sqlQueryParser, string fromTableName, string fromTableColumn,
                                          string withTableName, string withTableColumn)
        {
            //RbacJoin joinClause = existingJoins.Where(jc => jc.WithTableName.Equals(withTableName).SingleOrDefault();
            RbacJoin join = sqlQueryParser.JoinClauses.JoinExists(withTableName, fromTableName);

            if (join == null)
            {
                string fromTableNameAlias = sqlQueryParser.GetTableNameOrAlias(fromTableName);
                aliasNumber++;
                string withTableAlias = "t" + aliasNumber;
                join = new RbacJoin(fromTableName, fromTableNameAlias, withTableName, withTableAlias);
                join.FromTableColumn = fromTableColumn;
                join.WithTableColumn = withTableColumn;

                join.JoinClause = string.Format(" {0} join [{1}] [{2}] on [{2}].{3} = [{4}].{5} ", join.JoinType.ToString().ToLower(),
                                                withTableName, withTableAlias, withTableColumn, fromTableNameAlias, fromTableColumn);

                sqlQueryParser.JoinClauses.Add(join);
                return(join);
            }
            else
            {
                return(join);
            }
        }
Пример #3
0
        private void AddRelationalJoins(RbacRelation relation, List <RbacCondition> conditions)
        {
            //was relation already referred in the query?
            RbacTable relationTable = TablesReferred.Find(relation.WithTable);

            if (relationTable == null)
            {
                //NO:
                //Is there already join with that table?
                RbacJoin join = JoinClauses.JoinExists(relation.WithTable, relation.SelfName);
                if (join == null)
                {
                    //add new join, at the end of operation we will stringify sequentially
                    join = RbacJoin.AddNewJoin(this,
                                               relation.SelfName, relation.SelfColumnName,
                                               relation.WithTable, relation.WithColumn);
                }

                //add into referred table as 'ReferencedOnly'
                relationTable = new RbacTable(string.Empty, relation.WithTable, false);
                relationTable.Conditions.AddRange(conditions);
                relationTable.ReferencedOnly = true;
                relationTable.TempAlias      = join.WithTableAlias;
                TablesReferred.Add(relationTable);
            }
            //add condition
            ApplyCondition(relationTable);
        }