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); }
// 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()); }
// 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)); }
// 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)); }
public override ResultNode GetCollection(QueryExpand queryExpand) { TempTableNode root = BuildTempTableTree(queryExpand); Database.Connection.Open(); try { Execute(root); } finally { Database.Connection.Close(); } return(root.ToResultNode()); }
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); }
protected abstract void SetRootPagingStatments(TempTableNode root, QueryExpand queryExpand);
public abstract ResultNode GetCollection(QueryExpand queryExpand);
public override ResultNode GetCollection(QueryExpand queryExpand) { _tableNames = queryExpand.Schema.Elements(SchemaVocab.Entity).Select(x => x.Attribute(SchemaVocab.Table).Value); return(base.GetCollection(queryExpand)); }