Ejemplo n.º 1
0
        /// <summary>
        /// Compose OR group node with specified child nodes
        /// </summary>
        /// <param name="nodes">child nodes</param>
        /// <returns>QueryGroupNode of OR type</returns>
        public static QGroupNode Or(params QNode[] nodes)
        {
            var orGrp = new QGroupNode(QGroupType.Or);

            orGrp._Nodes.AddRange(nodes);
            return(orGrp);
        }
Ejemplo n.º 2
0
        protected virtual string BuildGroup(QGroupNode node)
        {
            // do not render empty group
            if (node.Nodes == null || node.Nodes.Count == 0)
            {
                return(null);
            }

            // if group contains only one node ignore group rendering logic
            if (node.Nodes.Count == 1)
            {
                return(BuildExpression(node.Nodes[0]));
            }

            var subNodes = new List <string>();

            foreach (QNode childNode in node.Nodes)
            {
                string childNodeExpression = BuildExpression(childNode);
                if (childNodeExpression != null)
                {
                    subNodes.Add("(" + childNodeExpression + ")");
                }
            }

            return(String.Join(
                       " " + node.GroupType.ToString() + " ",
                       subNodes.ToArray()));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Compose AND group node with specified child nodes
        /// </summary>
        /// <param name="nodes">child nodes</param>
        /// <returns>QueryGroupNode of AND type</returns>
        public static QGroupNode And(params QNode[] nodes)
        {
            var andGrp = new QGroupNode(QGroupType.And);

            andGrp._Nodes.AddRange(nodes);
            return(andGrp);
        }
Ejemplo n.º 4
0
 internal static QNode MapQValue(QNode qNode, Func <IQueryValue, IQueryValue> mapFunc)
 {
     if (qNode is QGroupNode)
     {
         var group = new QGroupNode((QGroupNode)qNode);
         for (int i = 0; i < group.Nodes.Count; i++)
         {
             group.Nodes[i] = MapQValue(group.Nodes[i], mapFunc);
         }
         return(group);
     }
     if (qNode is QConditionNode)
     {
         var origCndNode = (QConditionNode)qNode;
         var cndNode     = new QConditionNode(origCndNode.Name,
                                              mapFunc(origCndNode.LValue),
                                              origCndNode.Condition,
                                              mapFunc(origCndNode.RValue));
         return(cndNode);
     }
     if (qNode is QNegationNode)
     {
         var negNode = new QNegationNode((QNegationNode)qNode);
         for (int i = 0; i < negNode.Nodes.Count; i++)
         {
             negNode.Nodes[i] = MapQValue(negNode.Nodes[i], mapFunc);
         }
         return(negNode);
     }
     return(qNode);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// AND operator
        /// </summary>
        public static QGroupNode operator &(QNode node1, QNode node2)
        {
            QGroupNode res = new QGroupNode(QGroupType.And);

            res.Nodes.Add(node1);
            res.Nodes.Add(node2);
            return(res);
        }
Ejemplo n.º 6
0
        Query GetPkQuery()
        {
            var q      = new Query(new QTable(TableName, null));
            var grpAnd = QGroupNode.And();

            q.Condition = grpAnd;
            foreach (var pkCol in RS.PrimaryKey)
            {
                grpAnd.Nodes.Add((QField)pkCol.Name == new QVar(pkCol.Name).Set(null));
            }
            return(q);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// OR operator
        /// </summary>
        public static QGroupNode operator |(QGroupNode node1, QNode node2)
        {
            if (node1.GroupType == QGroupType.Or)
            {
                node1.Nodes.Add(node2);
                return(node1);
            }
            QGroupNode res = new QGroupNode(QGroupType.Or);

            res.Nodes.Add(node1);
            res.Nodes.Add(node2);
            return(res);
        }
Ejemplo n.º 8
0
        Query GetQueryByKey(object pocoModel)
        {
            var schema = DataMapper.Instance.GetSchema(pocoModel.GetType());

            if (schema.Key.Length == 0)
            {
                throw new ArgumentException("Specified object doesn't have properties annotated with KeyAttribute.");
            }
            var q        = new Query(schema.TableName);
            var andGroup = QGroupNode.And();

            q.Condition = andGroup;
            for (int i = 0; i < schema.Key.Length; i++)
            {
                var keyCol = schema.Key[i];
                if (keyCol.GetVal != null)
                {
                    andGroup.Nodes.Add((QField)keyCol.ColumnName == new QConst(keyCol.GetVal(pocoModel)));
                }
            }
            return(q);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the QueryGroupNode that copies specified QueryGroupNode
 /// </summary>
 /// <param name="likeGroup">QueryGroupNode to copy from</param>
 public QGroupNode(QGroupNode likeGroup)
     : this(likeGroup.GroupType)
 {
     Name = likeGroup.Name;
     _Nodes.AddRange(likeGroup.Nodes);
 }