tracker r2287 - in trunk: . data/dbus src/libtracker src/tracker-utils src/trackerd



Author: mottela
Date: Wed Oct  1 12:27:37 2008
New Revision: 2287
URL: http://svn.gnome.org/viewvc/tracker?rev=2287&view=rev

Log:
Added GetUniqueValuesWithCountAndSum back to the metadata dbus API

Modified:
   trunk/ChangeLog
   trunk/data/dbus/tracker-metadata.xml
   trunk/src/libtracker/tracker.c
   trunk/src/libtracker/tracker.h
   trunk/src/tracker-utils/tracker-unique.c
   trunk/src/trackerd/tracker-metadata.c
   trunk/src/trackerd/tracker-metadata.h

Modified: trunk/data/dbus/tracker-metadata.xml
==============================================================================
--- trunk/data/dbus/tracker-metadata.xml	(original)
+++ trunk/data/dbus/tracker-metadata.xml	Wed Oct  1 12:27:37 2008
@@ -106,5 +106,18 @@
       <arg type="aas" name="result" direction="out" />
     </method>
 
+    <method name="GetUniqueValuesWithCountAndSum">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="s" name="service" direction="in" />
+      <arg type="as" name="meta_types" direction="in" />
+      <arg type="s" name="query" direction="in" />
+      <arg type="s" name="count_field" direction="in" />
+      <arg type="s" name="sum_field" direction="in" />
+      <arg type="b" name="descending" direction="in" />
+      <arg type="i" name="offset" direction="in" />
+      <arg type="i" name="max_hits" direction="in" />
+      <arg type="aas" name="result" direction="out" />
+    </method>
+
   </interface>
 </node>

Modified: trunk/src/libtracker/tracker.c
==============================================================================
--- trunk/src/libtracker/tracker.c	(original)
+++ trunk/src/libtracker/tracker.c	Wed Oct  1 12:27:37 2008
@@ -579,6 +579,19 @@
 	return table;
 }
 
+GPtrArray *
+tracker_metadata_get_unique_values_with_count_and_sum (TrackerClient *client, ServiceType service, char **meta_types, char *query, char *count, char *sum, gboolean descending, int offset, int max_hits, GError **error)
+{
+	GPtrArray *table;
+	char *service_str = tracker_service_types[service];
+
+	if (!org_freedesktop_Tracker_Metadata_get_unique_values_with_count_and_sum (client->proxy_metadata, service_str, (const char **)meta_types, query, count, sum, descending, offset, max_hits, &table, &*error)) {
+		return NULL;
+	}
+
+	return table;
+}
+
 
 GPtrArray *
 tracker_keywords_get_list (TrackerClient *client, ServiceType service, GError **error)
@@ -1214,6 +1227,21 @@
 
 }
 
+void
+tracker_metadata_get_unique_values_with_count_and_sum_async (TrackerClient *client, ServiceType service, char **meta_types, const char *query, char *count, char *sum, gboolean descending, int offset, int max_hits, TrackerGPtrArrayReply callback, gpointer user_data)
+{
+
+	GPtrArrayCallBackStruct *callback_struct;
+	char *service_str = tracker_service_types[service];
+
+	callback_struct = g_new (GPtrArrayCallBackStruct, 1);
+	callback_struct->callback = callback;
+	callback_struct->data = user_data;
+
+	client->last_pending_call = org_freedesktop_Tracker_Metadata_get_unique_values_with_count_and_sum_async (client->proxy_metadata, service_str, (const char **) meta_types, query, count, sum, descending, offset, max_hits, tracker_GPtrArray_reply, callback_struct);
+
+}
+
 
 void
 tracker_keywords_get_list_async (TrackerClient *client, ServiceType service, TrackerGPtrArrayReply callback, gpointer user_data)

Modified: trunk/src/libtracker/tracker.h
==============================================================================
--- trunk/src/libtracker/tracker.h	(original)
+++ trunk/src/libtracker/tracker.h	Wed Oct  1 12:27:37 2008
@@ -131,7 +131,9 @@
 GPtrArray *		tracker_metadata_get_unique_values		(TrackerClient *client, ServiceType service, char **meta_types, char *query, gboolean descending, int offset, int max_hits, GError **error);
 int		tracker_metadata_get_sum			(TrackerClient *client, ServiceType service, char *field, char *query, GError **error);
 int		tracker_metadata_get_count			(TrackerClient *client, ServiceType service, char *field, char *query, GError **error);
-GPtrArray *		tracker_metadata_get_unique_values_with_count	(TrackerClient *client, ServiceType service, char **meta_types, char *query, char *count, gboolean descending, int offset, int max_hits, GError **error);
+GPtrArray *	tracker_metadata_get_unique_values_with_count	(TrackerClient *client, ServiceType service, char **meta_types, char *query, char *count, gboolean descending, int offset, int max_hits, GError **error);
+GPtrArray *	tracker_metadata_get_unique_values_with_count_and_sum   (TrackerClient *client, ServiceType service, char **meta_types, char *query, char *count, char *sum, gboolean descending, int offset, int max_hits, GError **error);
+
 
 GPtrArray *	tracker_keywords_get_list			(TrackerClient *client, ServiceType service, GError **error);
 char **		tracker_keywords_get				(TrackerClient *client, ServiceType service, const char *id, GError **error);
@@ -194,6 +196,7 @@
 void		tracker_metadata_get_sum_async				(TrackerClient *client, ServiceType service, char *field, char *query, TrackerIntReply callback, gpointer user_data);
 void		tracker_metadata_get_count_async			(TrackerClient *client, ServiceType service, char *field, char *query, TrackerIntReply callback, gpointer user_data);
 void		tracker_metadata_get_unique_values_with_count_async	(TrackerClient *client, ServiceType service, char **meta_types, const char *query, char *count, gboolean descending, int offset, int max_hits, TrackerGPtrArrayReply callback, gpointer user_data);
+void	   tracker_metadata_get_unique_values_with_count_and_sum_async	(TrackerClient *client, ServiceType service, char **meta_types, const char *query, char *count, char *sum, gboolean descending, int offset, int max_hits, TrackerGPtrArrayReply callback, gpointer user_data);
 
 void		tracker_keywords_get_list_async				(TrackerClient *client, ServiceType service, TrackerGPtrArrayReply callback, gpointer user_data);
 void		tracker_keywords_get_async				(TrackerClient *client, ServiceType service, const char *id, TrackerArrayReply callback, gpointer user_data);

Modified: trunk/src/tracker-utils/tracker-unique.c
==============================================================================
--- trunk/src/tracker-utils/tracker-unique.c	(original)
+++ trunk/src/tracker-utils/tracker-unique.c	Wed Oct  1 12:27:37 2008
@@ -38,7 +38,7 @@
 static gchar	     *service;
 static gchar	     *path;
 static gchar	     *count;
-static gchar	     *sum;
+static gchar         *sum;
 static gboolean       descending;
 
 static GOptionEntry   entries[] = {
@@ -189,15 +189,16 @@
 		}
 	}
 
-	array = tracker_metadata_get_unique_values_with_count (client,
-							       type,
-							       fields,
-							       buffer,
-							       count,
-							       descending,
-							       0,
-							       512,
-							       &error);
+	array = tracker_metadata_get_unique_values_with_count_and_sum (client,
+								       type,
+								       fields,
+								       buffer,
+								       count,
+								       sum,
+								       descending,
+								       0,
+								       512,
+								       &error);
 	g_free (buffer);
 
 	if (error) {

Modified: trunk/src/trackerd/tracker-metadata.c
==============================================================================
--- trunk/src/trackerd/tracker-metadata.c	(original)
+++ trunk/src/trackerd/tracker-metadata.c	Wed Oct  1 12:27:37 2008
@@ -512,6 +512,12 @@
 	tracker_dbus_request_success (request_id);
 }
 
+static gboolean
+is_data_type_numeric (TrackerFieldType type) {
+	return (type == TRACKER_FIELD_TYPE_INTEGER
+		|| type == TRACKER_FIELD_TYPE_DOUBLE);
+}
+
 void
 tracker_metadata_get_unique_values (TrackerMetadata	   *object,
 				    const gchar		   *service_type,
@@ -863,12 +869,245 @@
 	return;
 }
 
-static gboolean
-is_data_type_numeric (TrackerFieldType type) {
-	return (type == TRACKER_FIELD_TYPE_INTEGER
-		|| type == TRACKER_FIELD_TYPE_DOUBLE);
-}
+void
+tracker_metadata_get_unique_values_with_count_and_sum (TrackerMetadata	      *object,
+						       const gchar	      *service_type,
+						       gchar		     **fields,
+						       const gchar	      *query_condition,
+						       const gchar	      *count_field,
+						       const gchar            *sum_field,
+						       gboolean		       order_desc,
+						       gint		       offset,
+						       gint		       max_hits,
+						       DBusGMethodInvocation  *context,
+						       GError		     **error)
+{
+	TrackerDBInterface *iface;
+	TrackerDBResultSet *result_set = NULL;
+	guint		    request_id;
+
+	GPtrArray	   *values = NULL;
+	GSList		   *field_list = NULL;
+	gchar		   *str_offset, *str_limit;
+
+	GString		   *sql_select;
+	GString		   *sql_from;
+	GString		   *sql_where;
+	GString		   *sql_order;
+	GString		   *sql_group;
+	gchar		   *sql;
+
+	char		   *rdf_where;
+	char		   *rdf_from;
+	GError		   *actual_error = NULL;
+
+	guint		    i;
+
+	request_id = tracker_dbus_get_next_request_id ();
+
+	tracker_dbus_async_return_if_fail (service_type != NULL, context);
+	tracker_dbus_async_return_if_fail (fields != NULL, context);
+	tracker_dbus_async_return_if_fail (query_condition != NULL, context);
+
+	tracker_dbus_request_new (request_id,
+				  "DBus request to get unique values with count and sum, "
+				  "service type:'%s', query '%s'"
+				  "count field :'%s'",
+				  "sum field :'%s'",
+				  service_type,
+				  query_condition,
+				  count_field,
+				  sum_field);
+
+	if (!tracker_ontology_service_is_valid (service_type)) {
+		tracker_dbus_request_failed (request_id,
+					     &actual_error,
+					     "Service_Type '%s' is invalid or has not been implemented yet",
+					     service_type);
+		dbus_g_method_return_error (context, actual_error);
+		g_error_free (actual_error);
+		return;
+	}
+
+	iface = tracker_db_manager_get_db_interface_by_service (service_type);
+
+	sql_select = g_string_new ("SELECT DISTINCT ");
+	sql_from   = g_string_new ("\nFROM Services S ");
+	sql_where  = g_string_new ("\nWHERE ");
+	sql_order  = g_string_new ("\nORDER BY ");
+	sql_group  = g_string_new ("\nGROUP BY ");
+
+
+	for (i=0;i<g_strv_length(fields);i++) {
+		TrackerFieldData   *def = NULL;
+		def = tracker_metadata_add_metadata_field (iface, service_type, &field_list, fields[i], FALSE, TRUE);
+
+		if (!def) {
+			g_string_free (sql_select, TRUE);
+			g_string_free (sql_from, TRUE);
+			g_string_free (sql_where, TRUE);
+			g_string_free (sql_order, TRUE);
+			g_string_free (sql_group, TRUE);
+
+			tracker_dbus_request_failed (request_id,
+						     &actual_error,
+						     "Invalid or non-existant metadata type '%s' specified",
+						     fields[i]);
+			dbus_g_method_return_error (context, actual_error);
+			g_error_free (actual_error);
+			return;
+		}
+
+		if (i) {
+			g_string_append_printf (sql_select, ",");
+			g_string_append_printf (sql_order, ",");
+			g_string_append_printf (sql_group, ",");
+		}
+
+		g_string_append_printf (sql_select, "%s", tracker_field_data_get_select_field (def));
+		g_string_append_printf (sql_order, " %s %s",
+					tracker_field_data_get_select_field (def),
+					order_desc ? "DESC" : "ASC" );
+		g_string_append_printf (sql_group, "%s", tracker_field_data_get_select_field (def));
+
+	}
+
+	if (count_field && !(tracker_is_empty_string (count_field))) {
+		TrackerFieldData   *def = NULL;
+
+		def = tracker_metadata_add_metadata_field (iface, service_type, &field_list, count_field, FALSE, TRUE);
+
+		if (!def) {
+			g_string_free (sql_select, TRUE);
+			g_string_free (sql_from, TRUE);
+			g_string_free (sql_where, TRUE);
+			g_string_free (sql_order, TRUE);
+			g_string_free (sql_group, TRUE);
+
+			tracker_dbus_request_failed (request_id,
+						     &actual_error,
+						     "Invalid or non-existant metadata type '%s' specified",
+						     count_field);
+			dbus_g_method_return_error (context, actual_error);
+			g_error_free (actual_error);
+			return;
+		}
+
+		g_string_append_printf (sql_select, ", COUNT (DISTINCT %s)", tracker_field_data_get_select_field (def));
+	}
+
+	if (sum_field && !(tracker_is_empty_string (sum_field))) {
+		TrackerFieldData   *def = NULL;
+		TrackerFieldType    data_type;
+
+		def = tracker_metadata_add_metadata_field (iface, service_type, &field_list, sum_field, FALSE, TRUE);
+
+		if (!def) {
+			g_string_free (sql_select, TRUE);
+			g_string_free (sql_from, TRUE);
+			g_string_free (sql_where, TRUE);
+			g_string_free (sql_order, TRUE);
+			g_string_free (sql_group, TRUE);
+
+			tracker_dbus_request_failed (request_id,
+						     &actual_error,
+						     "Invalid or non-existant metadata type '%s' specified",
+						     sum_field);
+			dbus_g_method_return_error (context, actual_error);
+			g_error_free (actual_error);
+			return;
+		}
+
+		data_type = tracker_field_data_get_data_type (def);
+		if (!is_data_type_numeric (data_type)) {
+			g_string_free (sql_select, TRUE);
+			g_string_free (sql_from, TRUE);
+			g_string_free (sql_where, TRUE);
+			g_string_free (sql_order, TRUE);
+			g_string_free (sql_group, TRUE);
+
+			tracker_dbus_request_failed (request_id,
+						     &actual_error,
+						     "Cannot sum '%s': this metadata type is not numeric",
+						     sum_field);
+			dbus_g_method_return_error (context, actual_error);
+			g_error_free (actual_error);
+			return;
+		}
+
+		g_string_append_printf (sql_select, ", SUM (%s)", tracker_field_data_get_select_field (def));
+	}
+
+	tracker_rdf_filter_to_sql (iface, query_condition, service_type,
+				   &field_list, &rdf_from, &rdf_where, &actual_error);
+
+	if (actual_error) {
+
+		g_string_free (sql_select, TRUE);
+		g_string_free (sql_from, TRUE);
+		g_string_free (sql_where, TRUE);
+		g_string_free (sql_order, TRUE);
+		g_string_free (sql_group, TRUE);
+
+
+		tracker_dbus_request_failed (request_id,
+					     &actual_error,
+					     NULL);
+
+		dbus_g_method_return_error (context, actual_error);
+		g_error_free (actual_error);
+		return;
+	}
+
+	g_string_append_printf (sql_from, " %s ", rdf_from);
+	g_string_append_printf (sql_where, " %s ", rdf_where);
+
+	g_free (rdf_from);
+	g_free (rdf_where);
+
+	str_offset = tracker_gint_to_string (offset);
+	str_limit = tracker_gint_to_string (metadata_sanity_check_max_hits (max_hits));
+
+	g_string_append_printf (sql_order, " LIMIT %s,%s", str_offset, str_limit);
+
+	sql = g_strconcat (sql_select->str, " ",
+			   sql_from->str, " ",
+			   sql_where->str, " ",
+			   sql_group->str, " ",
+			   sql_order->str, NULL);
 
+	g_free (str_offset);
+	g_free (str_limit);
+
+	g_string_free (sql_select, TRUE);
+	g_string_free (sql_from, TRUE);
+	g_string_free (sql_where, TRUE);
+	g_string_free (sql_order, TRUE);
+	g_string_free (sql_group, TRUE);
+
+	g_slist_foreach (field_list, (GFunc) g_object_unref, NULL);
+	g_slist_free (field_list);
+
+	g_message ("Unique values query executed:\n%s", sql);
+
+	result_set =  tracker_db_interface_execute_query (iface, NULL, sql);
+
+	g_free (sql);
+
+	values = tracker_dbus_query_result_to_ptr_array (result_set);
+
+	dbus_g_method_return (context, values);
+
+	tracker_dbus_results_ptr_array_free (&values);
+
+	if (result_set) {
+		g_object_unref (result_set);
+	}
+
+	tracker_dbus_request_success (request_id);
+
+	return;
+}
 
 void
 tracker_metadata_get_sum (TrackerMetadata	 *object,
@@ -926,28 +1165,27 @@
 
 	def = tracker_metadata_add_metadata_field (iface, service_type, &fields, field, FALSE, TRUE);
 
-	data_type = tracker_field_data_get_data_type (def);
-	if (!is_data_type_numeric (data_type)) {
+	if (!def) {
 		g_string_free (sql_select, TRUE);
 		g_string_free (sql_from, TRUE);
 		g_string_free (sql_where, TRUE);
 		tracker_dbus_request_failed (request_id,
 					     &actual_error,
-					     "Cannot sum '%s': this metadata type is not numeric",
+					     "Invalid or non-existant metadata type '%s' specified",
 					     field);
 		dbus_g_method_return_error (context, actual_error);
 		g_error_free (actual_error);
 		return;
 	}
 
-
-	if (!def) {
+	data_type = tracker_field_data_get_data_type (def);
+	if (!is_data_type_numeric (data_type)) {
 		g_string_free (sql_select, TRUE);
 		g_string_free (sql_from, TRUE);
 		g_string_free (sql_where, TRUE);
 		tracker_dbus_request_failed (request_id,
 					     &actual_error,
-					     "Invalid or non-existant metadata type '%s' specified",
+					     "Cannot sum '%s': this metadata type is not numeric",
 					     field);
 		dbus_g_method_return_error (context, actual_error);
 		g_error_free (actual_error);

Modified: trunk/src/trackerd/tracker-metadata.h
==============================================================================
--- trunk/src/trackerd/tracker-metadata.h	(original)
+++ trunk/src/trackerd/tracker-metadata.h	Wed Oct  1 12:27:37 2008
@@ -103,16 +103,28 @@
 							  DBusGMethodInvocation  *context,
 							  GError		**error);
 
-void		 tracker_metadata_get_unique_values_with_count (TrackerMetadata        *object,
-								const gchar	       *service_type,
-								gchar		      **fields,
-								const gchar	       *query_condition,
-								const gchar	       *count,
-								gboolean		order_desc,
-								gint			offset,
-								gint			max_hits,
-								DBusGMethodInvocation  *context,
-								GError		      **error);
+void	   tracker_metadata_get_unique_values_with_count (TrackerMetadata          *object,
+							  const gchar	           *service_type,
+							  gchar		          **fields,
+							  const gchar	           *query_condition,
+							  const gchar	           *count,
+							  gboolean	            order_desc,
+							  gint			    offset,
+							  gint			    max_hits,
+							  DBusGMethodInvocation    *context,
+							  GError		  **error);
+
+void tracker_metadata_get_unique_values_with_count_and_sum (TrackerMetadata        *object,
+							    const gchar	           *service_type,
+							    gchar		  **fields,
+							    const gchar	           *query_condition,
+							    const gchar	           *count,
+							    const gchar            *sum,
+							    gboolean		    order_desc,
+							    gint		    offset,
+							    gint		    max_hits,
+							    DBusGMethodInvocation  *context,
+							    GError		  **error);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]