rygel-tracker-years.vala \
rygel-tracker-search-container.vala \
rygel-tracker-query.vala \
+ rygel-tracker-selection-query.vala \
rygel-tracker-query-triplet.vala \
rygel-tracker-query-triplets.vala \
rygel-tracker-item-factory.vala \
var last_variable = variables[num_keys - 1];
selected.add ("DISTINCT " + last_variable);
- var query = new TrackerQuery (selected,
- mandatory,
- null,
- null,
- last_variable);
+ var query = new TrackerSelectionQuery (selected,
+ mandatory,
+ null,
+ null,
+ last_variable);
string[,] values;
try {
/**
* Represents Tracker SPARQL query
*/
-public class Rygel.TrackerQuery {
+public abstract class Rygel.TrackerQuery {
public TrackerQueryTriplets mandatory;
public TrackerQueryTriplets optional;
- public ArrayList<string> variables;
- public ArrayList<string> filters;
-
- public string order_by;
- public int offset;
- public int max_count;
-
- public TrackerQuery (ArrayList<string> variables,
- TrackerQueryTriplets mandatory,
- TrackerQueryTriplets? optional,
- ArrayList<string>? filters,
- string? order_by = null,
- int offset = 0,
- int max_count = -1) {
- this.variables = variables;
+ public TrackerQuery (TrackerQueryTriplets mandatory,
+ TrackerQueryTriplets? optional) {
this.mandatory = mandatory;
if (optional != null) {
} else {
this.optional = new TrackerQueryTriplets ();
}
-
- if (filters != null) {
- this.filters = filters;
- } else {
- this.filters = new ArrayList<string> ();
- }
-
- this.order_by = order_by;
-
- this.offset = offset;
- this.max_count = max_count;
- }
-
- public TrackerQuery.clone (TrackerQuery query) {
- this (this.copy_str_list (query.variables),
- new TrackerQueryTriplets.clone (query.mandatory),
- new TrackerQueryTriplets.clone (query.optional),
- this.copy_str_list (query.filters),
- query.order_by,
- query.offset,
- query.max_count);
}
public async string[,] execute (TrackerResourcesIface resources)
return yield resources.sparql_query (str);
}
- public string to_string () {
- string query = "SELECT";
-
- foreach (var variable in this.variables) {
- query += " " + variable;
- }
-
- query += " WHERE { " +
- this.serialize_triplets (this.mandatory) +
- " . " +
- this.serialize_triplets (this.optional);
-
- if (this.filters.size > 0) {
- query += " FILTER (";
- for (var i = 0; i < this.filters.size; i++) {
- query += this.filters[i];
-
- if (i < this.filters.size - 1) {
- query += " && ";
- }
- }
- query += ")";
- }
-
- query += " }";
-
- if (this.order_by != null) {
- query += " ORDER BY " + order_by;
- }
-
- query += " OFFSET " + this.offset.to_string ();
-
- if (this.max_count != -1) {
- query += " LIMIT " + this.max_count.to_string ();
- }
-
- return query;
+ // Deriving classes should override this method and complete it by
+ // adding the first part of the query
+ public virtual string to_string () {
+ return this.serialize_triplets (this.mandatory) +
+ " . " +
+ this.serialize_triplets (this.optional);
}
private string serialize_triplets (TrackerQueryTriplets triplets) {
return str;
}
-
- private ArrayList<string> copy_str_list (Gee.List<string> str_list) {
- var copy = new ArrayList<string> ();
-
- copy.add_all (str_list);
-
- return copy;
- }
}
private const string MODIFIED_PREDICATE = "nfo:fileLastModified";
private const string MODIFIED_VARIABLE = "?modified";
- public TrackerQuery query;
+ public TrackerSelectionQuery query;
public TrackerItemFactory item_factory;
private TrackerResourcesIface resources;
}
}
- this.query = new TrackerQuery (variables,
- our_mandatory,
- optional,
- filters,
- MODIFIED_VARIABLE);
+ this.query = new TrackerSelectionQuery (variables,
+ our_mandatory,
+ optional,
+ filters,
+ MODIFIED_VARIABLE);
try {
this.create_proxies ();
private async void get_children_count () {
try {
- var query = new TrackerQuery.clone (this.query);
+ var query = new TrackerSelectionQuery.clone (this.query);
query.variables = new ArrayList<string> ();
query.variables.add ("COUNT(" + ITEM_VARIABLE + ") AS x");
}
}
- private TrackerQuery? create_query (SearchExpression expression,
- int offset,
- int max_count) {
+ private TrackerSelectionQuery? create_query (SearchExpression expression,
+ int offset,
+ int max_count) {
if (expression == null || !(expression is RelationalExpression)) {
return null;
}
var rel_expression = expression as RelationalExpression;
- var query = new TrackerQuery.clone (this.query);
+ var query = new TrackerSelectionQuery.clone (this.query);
if (rel_expression.operand1 == "@id") {
var filter = create_filter_for_id (rel_expression);
--- /dev/null
+/*
+ * Copyright (C) 20010 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali <zeenix@gmail.com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using Gee;
+
+/**
+ * Represents Tracker SPARQL Selection query
+ */
+public class Rygel.TrackerSelectionQuery : Rygel.TrackerQuery {
+ public ArrayList<string> variables;
+ public ArrayList<string> filters;
+
+ public string order_by;
+ public int offset;
+ public int max_count;
+
+ public TrackerSelectionQuery (ArrayList<string> variables,
+ TrackerQueryTriplets mandatory,
+ TrackerQueryTriplets? optional,
+ ArrayList<string>? filters,
+ string? order_by = null,
+ int offset = 0,
+ int max_count = -1) {
+ base (mandatory, optional);
+
+ if (filters != null) {
+ this.filters = filters;
+ } else {
+ this.filters = new ArrayList<string> ();
+ }
+
+ this.variables = variables;
+ this.order_by = order_by;
+ this.offset = offset;
+ this.max_count = max_count;
+ }
+
+ public TrackerSelectionQuery.clone (TrackerSelectionQuery query) {
+ this (this.copy_str_list (query.variables),
+ new TrackerQueryTriplets.clone (query.mandatory),
+ new TrackerQueryTriplets.clone (query.optional),
+ this.copy_str_list (query.filters),
+ query.order_by,
+ query.offset,
+ query.max_count);
+ }
+
+ public override string to_string () {
+ var query = "SELECT ";
+
+ foreach (var variable in this.variables) {
+ query += " " + variable;
+ }
+
+ query += " WHERE { " + base.to_string ();
+
+ if (this.filters.size > 0) {
+ query += " FILTER (";
+ for (var i = 0; i < this.filters.size; i++) {
+ query += this.filters[i];
+
+ if (i < this.filters.size - 1) {
+ query += " && ";
+ }
+ }
+ query += ")";
+ }
+
+ query += " }";
+
+ if (this.order_by != null) {
+ query += " ORDER BY " + order_by;
+ }
+
+ query += " OFFSET " + this.offset.to_string ();
+
+ if (this.max_count != -1) {
+ query += " LIMIT " + this.max_count.to_string ();
+ }
+
+ return query;
+ }
+
+ private ArrayList<string> copy_str_list (Gee.List<string> str_list) {
+ var copy = new ArrayList<string> ();
+
+ copy.add_all (str_list);
+
+ return copy;
+ }
+}
}
private void on_got_chunk (Message msg, Buffer chunk) {
-
this.write_chunk.begin (chunk);
}