|
@@ -129,8 +129,8 @@ LSUP_rc
|
|
|
LSR_desc_store (const LSR_Desc *rsrc)
|
|
|
{
|
|
|
LSR_Desc *old_rsrc;
|
|
|
- LSUP_rc rc = LSR_desc_get (rsrc->id, &old_rsrc);
|
|
|
- PRCCK (rc);
|
|
|
+ LSUP_rc get_rc = LSR_desc_get (rsrc->id, &old_rsrc);
|
|
|
+ PRCCK (get_rc);
|
|
|
|
|
|
/*
|
|
|
* BEGIN txn
|
|
@@ -138,12 +138,11 @@ LSR_desc_store (const LSR_Desc *rsrc)
|
|
|
void *txn;
|
|
|
LSUP_store_begin (LSR_store, 0, &txn);
|
|
|
// Remove all existing user graphs.
|
|
|
- if (rc == LSUP_OK) {
|
|
|
- // TODO Handle managed preds and types.
|
|
|
- // TODO Handle conflict between disjoint managed types.
|
|
|
- // TODO Retain created and created_by.
|
|
|
+ if (get_rc == LSUP_OK) {
|
|
|
for (size_t i = 0; old_rsrc->user_data[i] != NULL; i++) {
|
|
|
+
|
|
|
LSUP_Term *gr_uri = LSUP_graph_uri (old_rsrc->user_data[i]);
|
|
|
+
|
|
|
size_t ct;
|
|
|
// Remove triples from user graph.
|
|
|
PCHECK (LSUP_graph_remove_txn (
|
|
@@ -158,12 +157,14 @@ LSR_desc_store (const LSR_Desc *rsrc)
|
|
|
PCHECK (LSUP_graph_remove_txn (
|
|
|
txn, old_rsrc->main_data,
|
|
|
NULL, NULL, gr_uri, NULL), fail);
|
|
|
+
|
|
|
+ LSUP_term_free (gr_uri);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
LSUP_Graph *tmp_gr;
|
|
|
// Add new triples.
|
|
|
- rc = LSUP_NOACTION;
|
|
|
+ LSUP_rc rc = LSUP_NOACTION;
|
|
|
for (size_t i = 0; rsrc->user_data[i] != NULL; i++) {
|
|
|
tmp_gr = LSUP_graph_new (
|
|
|
LSR_store, LSUP_graph_uri (rsrc->user_data[i]), NULL);
|
|
@@ -212,13 +213,6 @@ fail:
|
|
|
}
|
|
|
|
|
|
|
|
|
-LSUP_rc
|
|
|
-LSUP_desc_update (LSR_id id, LSUP_Term **remove, LSUP_Triple *add)
|
|
|
-{
|
|
|
- return LSUP_OK;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
LSUP_rc
|
|
|
LSR_desc_get (const uuid_t id, LSR_Desc **rsrc_p)
|
|
|
{
|
|
@@ -307,27 +301,50 @@ LSR_desc_user_data (const LSR_Desc *rsrc)
|
|
|
|
|
|
LSUP_rc
|
|
|
LSR_desc_update (
|
|
|
- LSR_Desc *rsrc, LSUP_Graph *const *rm_data,
|
|
|
+ LSR_Desc *rsrc, LSUP_Term *const rm_data[][4],
|
|
|
LSUP_Graph *const *add_data)
|
|
|
{
|
|
|
LSUP_rc rc = LSUP_NOACTION;
|
|
|
LSUP_Term *rsrc_uri = LSR_id_to_urn (rsrc->id, NULL);
|
|
|
|
|
|
- size_t ct;
|
|
|
+ size_t ct = 0;
|
|
|
|
|
|
/*
|
|
|
* REMOVE user data.
|
|
|
*/
|
|
|
|
|
|
if (rm_data) {
|
|
|
- // Count graphs to be removed.
|
|
|
- ct = 0;
|
|
|
- while (add_data[ct]) ct++;
|
|
|
- for (size_t i = 0; i < ct; i++) {
|
|
|
- LSUP_Term *gr_uri = LSUP_graph_uri (rm_data[i]);
|
|
|
- // TODO remove ops.
|
|
|
+ size_t ct_loop;
|
|
|
+ for (size_t i = 0; rm_data[i] != NULL; i++) {
|
|
|
+ LSUP_Buffer
|
|
|
+ *ss = NULL,
|
|
|
+ *sp = NULL,
|
|
|
+ *so = NULL,
|
|
|
+ *sc = NULL;
|
|
|
+
|
|
|
+ if (rm_data[i][1])
|
|
|
+ ss = LSUP_term_serialize (rm_data[i][1]);
|
|
|
+ if (rm_data[i][2])
|
|
|
+ sp = LSUP_term_serialize (rm_data[i][2]);
|
|
|
+ if (rm_data[i][3])
|
|
|
+ so = LSUP_term_serialize (rm_data[i][3]);
|
|
|
+ if (rm_data[i][0])
|
|
|
+ sc = LSUP_term_serialize (rm_data[i][0]);
|
|
|
+
|
|
|
+ LSR_store->sif->remove_fn (
|
|
|
+ LSR_store->data, ss, sp, so, sc, NULL, &ct_loop);
|
|
|
+
|
|
|
+ LSUP_buffer_free (ss);
|
|
|
+ LSUP_buffer_free (sp);
|
|
|
+ LSUP_buffer_free (so);
|
|
|
+ LSUP_buffer_free (sc);
|
|
|
+
|
|
|
+ log_debug (
|
|
|
+ "Removed %lu triples for %s",
|
|
|
+ ct_loop, rm_data[i][0]->data);
|
|
|
+
|
|
|
+ ct += ct_loop;
|
|
|
// TODO if graph is empty after removal, remove it.
|
|
|
- LSUP_term_free (gr_uri);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -335,7 +352,7 @@ LSR_desc_update (
|
|
|
* ADD user data.
|
|
|
*/
|
|
|
|
|
|
- // Count graphs inserted and allocate space.
|
|
|
+ // Count graphs to be inserted and allocate space.
|
|
|
ct = 0;
|
|
|
while (add_data[ct]) ct++;
|
|
|
rsrc->user_data = calloc (sizeof (*rsrc->user_data), ct + 1);
|
|
@@ -370,7 +387,7 @@ LSR_desc_update (
|
|
|
add_it = LSUP_graph_add_init (rsrc->user_data[i]);
|
|
|
lu_it = LSUP_graph_lookup (rsrc->user_data[i], NULL, NULL, NULL, NULL);
|
|
|
|
|
|
- // Loop over graph triples.
|
|
|
+ // Loop over source graph triples.
|
|
|
LSUP_Term *dest_s, *dest_p, *dest_o;
|
|
|
LSUP_Triple *src_spo;
|
|
|
while (LSUP_graph_iter_next (lu_it, &src_spo) == LSUP_OK) {
|
|
@@ -382,7 +399,7 @@ LSR_desc_update (
|
|
|
LSUP_triple_init (spo, dest_s, dest_p, dest_o);
|
|
|
|
|
|
// if the pred is managed, ignore the triple and send a warning.
|
|
|
- if (hashmap_get(LSR_managed_preds, spo->p)) {
|
|
|
+ if (hashmap_get (LSR_managed_preds, spo->p)) {
|
|
|
log_warn (
|
|
|
"Predicate %s is managed. Skipping triple.",
|
|
|
dest_p->data);
|