+// A structure for storing queries
+
+function QueryExt(query, parent_query, main_query) {
+
+ /* Constructor */
+ if (typeof query == "undefined")
+ throw "Must pass a query in QueryExt constructor";
+ this.query = query
+ this.parent_query = (typeof parent_query == "undefined") ? false : parent_query
+ this.main_query = (typeof main_query == "undefined") ? false : main_query
+
+ // How to link to an update query ? they both have the same UUID !!
+
+}
+
+function QueryStore() {
+
+ var main_queries = {};
+ var analyzed_queries = {};
+
+ /* Insertion */
+
+ this.insert = function(query)
+ {
+ if (query.analyzed_query == null) {
+ query.analyze_subqueries();
+ }
+
+ query_ext = QueryExt(query, null, null)
+ manifold.query_store.main_queries[query.query_uuid] = query_ext;
+
+ // We also need to insert all queries and subqueries from the analyzed_query
+ query.iter_subqueries(function(sq, data, parent_query) {
+ parent_query_ext = this.find_analyzed_query_ext(parent_query.query_uuid);
+ sq_ext = QueryExt(sq, parent_query_ext, query_ext)
+ this.analyzed_queries[sq.query_uuid] = sq_ext;
+ });
+ }
+
+ /* Searching */
+
+ this.find_query_ext = function(query_uuid)
+ {
+ return this.main_queries[query_uuid];
+ }
+
+ this.find_query = function(query_uuid)
+ {
+ return this.find_query_ext(query_uuid).query;
+ }
+
+ this.find_analyzed_query_ext = function(query_uuid)
+ {
+ return this.analyzed_queries[query_uuid];
+ }
+
+ this.find_analyzed_query = function(query_uuid)
+ {
+ return this.find_analyzed_query_ext(query_uuid).query;
+ }
+}
+