[tracker/wip/carlosg/portal: 117/141] libtracker-data: Refactor find_graph() function



commit a0f34980c2adc5c900485957535b314079d9f9c8
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jan 23 18:07:19 2020 +0100

    libtracker-data: Refactor find_graph() function
    
    Since we'll be adding policy from TrackerSparql on top, wrap the
    TrackerDataManager function to find IDs for graphs.

 src/libtracker-data/tracker-sparql.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 7bde4e287..8d4fe9511 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -775,6 +775,13 @@ tracker_sparql_add_union_graph_subquery_for_class (TrackerSparql *sparql,
        tracker_sparql_swap_builder (sparql, old);
 }
 
+static gint
+tracker_sparql_find_graph (TrackerSparql *sparql,
+                           const gchar   *name)
+{
+       return tracker_data_manager_find_graph (sparql->data_manager, name);
+}
+
 static void
 _prepend_path_element (TrackerSparql      *sparql,
                        TrackerPathElement *path_elem)
@@ -808,7 +815,7 @@ _prepend_path_element (TrackerSparql      *sparql,
                        table_name = g_strdup_printf ("\"%s\".\"%s\"", graph,
                                                      tracker_property_get_table_name 
(path_elem->data.property));
                        graph_column = g_strdup_printf ("%d",
-                                                       tracker_data_manager_find_graph 
(sparql->data_manager, graph));
+                                                       tracker_sparql_find_graph (sparql, graph));
                }
 
                _append_string_printf (sparql,
@@ -908,7 +915,7 @@ _prepend_path_element (TrackerSparql      *sparql,
                        graph = tracker_token_get_idstring (&sparql->current_state.graph);
                        _append_string_printf (sparql,
                                               "AND graph = %d",
-                                              tracker_data_manager_find_graph (sparql->data_manager, graph));
+                                              tracker_sparql_find_graph (sparql, graph));
                }
 
                _append_string (sparql, ") ");
@@ -1479,7 +1486,7 @@ _add_quad (TrackerSparql  *sparql,
                                return FALSE;
                        }
 
-                       if (!graph_db || !tracker_data_manager_find_graph (sparql->data_manager, graph_db))
+                       if (!graph_db || !tracker_sparql_find_graph (sparql, graph_db))
                                tracker_sparql_add_union_graph_subquery_for_class (sparql, subject_type);
 
                        is_rdf_type = TRUE;
@@ -1538,14 +1545,14 @@ _add_quad (TrackerSparql  *sparql,
                                        }
 
                                        if (domain_index) {
-                                               if (!graph_db || !tracker_data_manager_find_graph 
(sparql->data_manager, graph_db))
+                                               if (!graph_db || !tracker_sparql_find_graph (sparql, 
graph_db))
                                                        tracker_sparql_add_union_graph_subquery_for_class 
(sparql, domain_index);
                                                db_table = tracker_class_get_name (domain_index);
                                        }
                                }
                        }
 
-                       if (!graph_db || !tracker_data_manager_find_graph (sparql->data_manager, graph_db))
+                       if (!graph_db || !tracker_sparql_find_graph (sparql, graph_db))
                                tracker_sparql_add_union_graph_subquery (sparql, property);
 
                        /* We can never share the table with multiple triples for
@@ -2167,7 +2174,7 @@ _end_triples_block (TrackerSparql  *sparql,
                        _append_string_printf (sparql, "\"%s\" ", table->sql_db_tablename);
                } else {
                        if (table->graph &&
-                           tracker_data_manager_find_graph (sparql->data_manager, table->graph)) {
+                           tracker_sparql_find_graph (sparql, table->graph)) {
                                _append_string_printf (sparql, "\"%s\".\"%s\" ",
                                                       table->graph,
                                                       table->sql_db_tablename);
@@ -3629,7 +3636,7 @@ translate_Clear (TrackerSparql  *sparql,
        } else {
                graph = tracker_token_get_idstring (&sparql->current_state.graph);
 
-               if (tracker_data_manager_find_graph (sparql->data_manager, graph) == 0)
+               if (tracker_sparql_find_graph (sparql, graph) == 0)
                        _raise (UNKNOWN_GRAPH, "Unknown graph", graph);
 
                graphs = g_list_prepend (graphs, (gpointer) graph);
@@ -3717,7 +3724,7 @@ translate_Create (TrackerSparql  *sparql,
 
        graph_name = tracker_token_get_idstring (&sparql->current_state.graph);
 
-       if (tracker_data_manager_find_graph (sparql->data_manager, graph_name) != 0) {
+       if (tracker_sparql_find_graph (sparql, graph_name) != 0) {
                inner_error = g_error_new (TRACKER_SPARQL_ERROR,
                                           TRACKER_SPARQL_ERROR_CONSTRAINT,
                                           "Graph '%s' already exists",
@@ -3766,7 +3773,7 @@ translate_Add (TrackerSparql  *sparql,
        }
 
        if (source &&
-           !tracker_data_manager_find_graph (sparql->data_manager, source)) {
+           !tracker_sparql_find_graph (sparql, source)) {
                g_set_error (&inner_error, TRACKER_SPARQL_ERROR,
                             TRACKER_SPARQL_ERROR_UNKNOWN_GRAPH,
                             "Unknown graph '%s'", source);
@@ -3774,7 +3781,7 @@ translate_Add (TrackerSparql  *sparql,
        }
 
        if (destination &&
-           !tracker_data_manager_find_graph (sparql->data_manager, destination)) {
+           !tracker_sparql_find_graph (sparql, destination)) {
                if (!tracker_data_manager_create_graph (sparql->data_manager,
                                                        destination, &inner_error))
                        goto error;
@@ -3828,7 +3835,7 @@ translate_Move (TrackerSparql  *sparql,
        }
 
        if (source &&
-           !tracker_data_manager_find_graph (sparql->data_manager, source)) {
+           !tracker_sparql_find_graph (sparql, source)) {
                g_set_error (&inner_error, TRACKER_SPARQL_ERROR,
                             TRACKER_SPARQL_ERROR_UNKNOWN_GRAPH,
                             "Unknown graph '%s'", source);
@@ -3836,7 +3843,7 @@ translate_Move (TrackerSparql  *sparql,
        }
 
        if (destination &&
-           !tracker_data_manager_find_graph (sparql->data_manager, destination)) {
+           !tracker_sparql_find_graph (sparql, destination)) {
                if (!tracker_data_manager_create_graph (sparql->data_manager,
                                                        destination, &inner_error))
                        goto error;
@@ -3902,7 +3909,7 @@ translate_Copy (TrackerSparql  *sparql,
        }
 
        if (source &&
-           !tracker_data_manager_find_graph (sparql->data_manager, source)) {
+           !tracker_sparql_find_graph (sparql, source)) {
                g_set_error (&inner_error, TRACKER_SPARQL_ERROR,
                             TRACKER_SPARQL_ERROR_UNKNOWN_GRAPH,
                             "Unknown graph '%s'", source);
@@ -3910,7 +3917,7 @@ translate_Copy (TrackerSparql  *sparql,
        }
 
        if (destination &&
-           !tracker_data_manager_find_graph (sparql->data_manager, destination)) {
+           !tracker_sparql_find_graph (sparql, destination)) {
                if (!tracker_data_manager_create_graph (sparql->data_manager,
                                                        destination, &inner_error))
                        goto error;


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