예제 #1
0
        protected override void SetRootPagingStatments(TempTableNode root, QueryExpand queryExpand)
        {
            Query query = queryExpand.Query;

            root.TempTableName = GetTempTableName();
            PagingClauseCollection clauses = GeneratePagingClauseCollection(query, out DbParameter[] dbParameters);
            List <string>          list    = new List <string>
            {
                string.Format("CREATE GLOBAL TEMPORARY TABLE {0} ON COMMIT PRESERVE ROWS AS", root.TempTableName),
                clauses.Select,
                clauses.From,
                string.Join(" ", clauses.LeftJoins),
                clauses.Where ?? string.Empty,
                clauses.OrderBy ?? string.Empty
            };

            list.AddRange(clauses.Clauses);

            string sql = string.Join(" ", list);

            root.BeforeExecuteStatments.Add(new SQLStatment(sql, dbParameters));

            //
            string fetchSql = string.Format("SELECT * FROM {0}", root.TempTableName);

            root.FetchTableStatment = new SQLStatment(fetchSql);
        }
        protected override void SetRootSelectStatments(TempTableNode root, QueryExpand queryExpand)
        {
            Query query = queryExpand.Query;

            root.TempTableName = GetTempTableName();
            SelectClauseCollection clauses = GenerateSelectClauseCollection(query, out DbParameter[] dbParameters);
            List <string>          list    = new List <string>
            {
                clauses.Select,
                "INTO " + root.TempTableName,
                clauses.From,
                string.Join(" ", clauses.LeftJoins),
                clauses.Where ?? string.Empty,
                //clauses.OrderBy ?? string.Empty
            };

            string sql = string.Join(" ", list);

            root.BeforeExecuteStatments.Add(new SQLStatment(sql, dbParameters));

            //
            string fetchSql = string.Format("SELECT * FROM {0}", root.TempTableName);

            if (query.Orderby != null)
            {
                IEnumerable <string> orderby = query.Orderby.Orders.Select(order => order.Property + ((order is DescendingOrder) ? " DESC" : " ASC"));
                fetchSql += " ORDER BY " + string.Join(",", orderby);
            }
            root.FetchTableStatment = new SQLStatment(fetchSql);
        }
예제 #3
0
        // expand
        public T Find(string entity, string[] key, string select, Expand[] expands, out XElement xsd)
        {
            string filter = GetFilter(entity, key);

            Query       query       = new Query(entity, select, filter, null, Schema, new ParameterCollection());
            QueryExpand queryExpand = new QueryExpand(query, expands);
            ResultNode  resultNode  = Database.GetCollection(queryExpand);

            xsd = DataConverter.GenerateEntityXsd(resultNode, Schema);
            return(DataConverter.Convert(resultNode).FirstOrDefault());
        }
예제 #4
0
        // expand
        protected IEnumerable <T> GetPagingCollection(string entity, string select, string filter, string orderby, long skip, long top, Expand[] expands, object parameterValues)
        {
            ParameterCollection parameterCollection = new ParameterCollection();
            Query       query       = new Query(entity, select, filter, orderby, skip, top, Schema, parameterCollection);
            QueryExpand queryExpand = new QueryExpand(query, expands);

            SetParameterValues(parameterCollection, parameterValues);

            ResultNode resultNode = Database.GetCollection(queryExpand);

            return(DataConverter.Convert(resultNode));
        }
예제 #5
0
        // expand
        protected IEnumerable <T> GetCollection(string entity, string select, string filter, string orderby, Expand[] expands, object parameterValues, out XElement xsd)
        {
            ParameterCollection parameterCollection = new ParameterCollection();
            Query       query       = new Query(entity, select, filter, orderby, Schema, parameterCollection);
            QueryExpand queryExpand = new QueryExpand(query, expands);

            SetParameterValues(parameterCollection, parameterValues);

            ResultNode resultNode = Database.GetCollection(queryExpand);

            xsd = DataConverter.GenerateCollectionXsd(resultNode, Schema);
            return(DataConverter.Convert(resultNode));
        }
예제 #6
0
        public override ResultNode GetCollection(QueryExpand queryExpand)
        {
            TempTableNode root = BuildTempTableTree(queryExpand);

            Database.Connection.Open();
            try
            {
                Execute(root);
            }
            finally
            {
                Database.Connection.Close();
            }

            return(root.ToResultNode());
        }
예제 #7
0
        protected TempTableNode BuildTempTableTree(QueryExpand queryExpand)
        {
            Query query = queryExpand.Query;

            XElement entitySchema = query.Schema.GetEntitySchema(query.Entity);
            string   name         = entitySchema.Attribute(SchemaVocab.Collection).Value;

            string[] select = new string[query.Select.Properties.Length];
            query.Select.Properties.CopyTo(select, 0);
            Order[]       orderby = GetOrders(query);
            TempTableNode root    = new CollectionTempNode(name, select, orderby, query.Entity)
            {
                Path = name
            };

            //
            Dictionary <ExpandNode, TempTableNode> childrenDict = CreateChildren(queryExpand.Nodes, root, out IEnumerable <string> relatedPropertiesForSelect);

            query.Select.Properties = query.Select.Properties.Union(relatedPropertiesForSelect).ToArray();
            query.Properties.UnionFieldProperties(relatedPropertiesForSelect);

            //
            if (query.Top != 0 || query.Skip != 0)
            {
                SetRootPagingStatments(root, queryExpand);
            }
            else
            {
                SetRootSelectStatments(root, queryExpand);
            }

            //
            foreach (KeyValuePair <ExpandNode, TempTableNode> pair in childrenDict)
            {
                pair.Value.ParentTempTableName = root.TempTableName;
                Compose(pair.Key, pair.Value);
            }

            return(root);
        }
예제 #8
0
 protected abstract void SetRootPagingStatments(TempTableNode root, QueryExpand queryExpand);
예제 #9
0
 public abstract ResultNode GetCollection(QueryExpand queryExpand);
예제 #10
0
 public override ResultNode GetCollection(QueryExpand queryExpand)
 {
     _tableNames = queryExpand.Schema.Elements(SchemaVocab.Entity).Select(x => x.Attribute(SchemaVocab.Table).Value);
     return(base.GetCollection(queryExpand));
 }