|
@@ -12,9 +12,15 @@ LSR_desc_new_multi (LSUP_Graph *const *data, LSR_Desc **rsrc_p)
|
|
|
|
|
|
// Default context graph.
|
|
// Default context graph.
|
|
rsrc->main_data = LSUP_graph_new (
|
|
rsrc->main_data = LSUP_graph_new (
|
|
- LSUP_default_ctx, LSUP_STORE_HTABLE, NULL, NULL, 0);
|
|
|
|
|
|
+ NULL, LSUP_term_copy (LSUP_default_ctx), NULL);
|
|
|
|
+ log_debug (
|
|
|
|
+ "Main data graph: %s",
|
|
|
|
+ LSUP_graph_uri(rsrc->main_data)->data);
|
|
|
|
|
|
- LSUP_GraphIterator *lu_it, *add_it, *admin_add_it = NULL;
|
|
|
|
|
|
+ LSUP_GraphIterator
|
|
|
|
+ *lu_it, // Lookup iterator.
|
|
|
|
+ *add_it, // Main graph add iterator.
|
|
|
|
+ *admin_add_it = NULL; // Admin graph add iterator.
|
|
|
|
|
|
LSUP_Term *dest_s, *dest_p, *dest_o;
|
|
LSUP_Term *dest_s, *dest_p, *dest_o;
|
|
LSUP_Triple src_spo_s, dest_spo_s;
|
|
LSUP_Triple src_spo_s, dest_spo_s;
|
|
@@ -35,7 +41,7 @@ LSR_desc_new_multi (LSUP_Graph *const *data, LSR_Desc **rsrc_p)
|
|
|
|
|
|
// Loop over input graphs.
|
|
// Loop over input graphs.
|
|
for (size_t i = 0; i < ct; i++) {
|
|
for (size_t i = 0; i < ct; i++) {
|
|
- LSUP_Term *gr_uri = LSUP_term_copy (LSUP_graph_uri (data[i]));
|
|
|
|
|
|
+ LSUP_Term *gr_uri = LSUP_graph_uri (data[i]);
|
|
|
|
|
|
LSUP_Term *rel_uri = LSUP_iriref_relative (rsrc_uri, gr_uri);
|
|
LSUP_Term *rel_uri = LSUP_iriref_relative (rsrc_uri, gr_uri);
|
|
if (strstr (rel_uri->data, "#__") == rel_uri->data) {
|
|
if (strstr (rel_uri->data, "#__") == rel_uri->data) {
|
|
@@ -46,7 +52,11 @@ LSR_desc_new_multi (LSUP_Graph *const *data, LSR_Desc **rsrc_p)
|
|
if (rc < 0) goto finally;
|
|
if (rc < 0) goto finally;
|
|
|
|
|
|
rsrc->user_data[i] = LSUP_graph_new (
|
|
rsrc->user_data[i] = LSUP_graph_new (
|
|
- gr_uri, LSUP_STORE_HTABLE, NULL, NULL, 0);
|
|
|
|
|
|
+ NULL, LSUP_term_copy (gr_uri), NULL);
|
|
|
|
+ log_debug (
|
|
|
|
+ "User data graph (@%p): %s",
|
|
|
|
+ LSUP_graph_uri(rsrc->user_data[i]),
|
|
|
|
+ LSUP_graph_uri(rsrc->user_data[i])->data);
|
|
|
|
|
|
add_it = LSUP_graph_add_init (rsrc->user_data[i]);
|
|
add_it = LSUP_graph_add_init (rsrc->user_data[i]);
|
|
lu_it = LSUP_graph_lookup (rsrc->user_data[i], NULL, NULL, NULL, NULL);
|
|
lu_it = LSUP_graph_lookup (rsrc->user_data[i], NULL, NULL, NULL, NULL);
|
|
@@ -76,24 +86,24 @@ LSR_desc_new_multi (LSUP_Graph *const *data, LSR_Desc **rsrc_p)
|
|
LSUP_rc tmp_rc;
|
|
LSUP_rc tmp_rc;
|
|
// Check subject.
|
|
// Check subject.
|
|
if (LSR_IS_RSRC_IRI (dest_s)) {
|
|
if (LSR_IS_RSRC_IRI (dest_s)) {
|
|
- uuid_parse (dest_s->data + strlen (LSR_RSRC_PFX), id_tmp);
|
|
|
|
|
|
+ uuid_parse (dest_s->data + strlen (LSR_RSRC_NS), id_tmp);
|
|
tmp_rc = LSR_desc_get (id_tmp, NULL);
|
|
tmp_rc = LSR_desc_get (id_tmp, NULL);
|
|
if (tmp_rc != LSUP_OK) {
|
|
if (tmp_rc != LSUP_OK) {
|
|
log_error (
|
|
log_error (
|
|
"Referenced subject does not exist: %s",
|
|
"Referenced subject does not exist: %s",
|
|
- dest_s->data + strlen (LSR_RSRC_PFX));
|
|
|
|
|
|
+ dest_s->data + strlen (LSR_RSRC_NS));
|
|
rc = LSUP_VALUE_ERR;
|
|
rc = LSUP_VALUE_ERR;
|
|
goto finally;
|
|
goto finally;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Check object.
|
|
// Check object.
|
|
if (LSR_IS_RSRC_IRI (dest_o)) {
|
|
if (LSR_IS_RSRC_IRI (dest_o)) {
|
|
- uuid_parse (dest_o->data + strlen (LSR_RSRC_PFX), id_tmp);
|
|
|
|
|
|
+ uuid_parse (dest_o->data + strlen (LSR_RSRC_NS), id_tmp);
|
|
tmp_rc = LSR_desc_get (id_tmp, NULL);
|
|
tmp_rc = LSR_desc_get (id_tmp, NULL);
|
|
if (tmp_rc != LSUP_OK) {
|
|
if (tmp_rc != LSUP_OK) {
|
|
log_error (
|
|
log_error (
|
|
"Referenced object does not exist: %s",
|
|
"Referenced object does not exist: %s",
|
|
- dest_o->data + strlen (LSR_RSRC_PFX));
|
|
|
|
|
|
+ dest_o->data + strlen (LSR_RSRC_NS));
|
|
rc = LSUP_VALUE_ERR;
|
|
rc = LSUP_VALUE_ERR;
|
|
goto finally;
|
|
goto finally;
|
|
}
|
|
}
|
|
@@ -152,8 +162,11 @@ loop_end:
|
|
/* BEGIN adding managed (admin) data. */
|
|
/* BEGIN adding managed (admin) data. */
|
|
|
|
|
|
LSUP_Term *gr_uri = LSR_id_to_urn (rsrc->id, "__admin");
|
|
LSUP_Term *gr_uri = LSR_id_to_urn (rsrc->id, "__admin");
|
|
- rsrc->admin_data = LSUP_graph_new (
|
|
|
|
- gr_uri, LSUP_STORE_HTABLE, NULL, NULL, 0);
|
|
|
|
|
|
+ rsrc->admin_data = LSUP_graph_new (NULL, gr_uri, NULL);
|
|
|
|
+ log_debug (
|
|
|
|
+ "Admin data graph (@%p): %s",
|
|
|
|
+ LSUP_graph_uri(rsrc->admin_data),
|
|
|
|
+ LSUP_graph_uri(rsrc->admin_data)->data);
|
|
|
|
|
|
admin_add_it = LSUP_graph_add_init (rsrc->admin_data);
|
|
admin_add_it = LSUP_graph_add_init (rsrc->admin_data);
|
|
dest_s = LSUP_iriref_new("", NULL); // Relative to resource URI.
|
|
dest_s = LSUP_iriref_new("", NULL); // Relative to resource URI.
|
|
@@ -252,12 +265,15 @@ LSR_desc_store (const LSR_Desc *rsrc)
|
|
{
|
|
{
|
|
// TODO Make atomic. Needs to implement transactions in backend.
|
|
// TODO Make atomic. Needs to implement transactions in backend.
|
|
LSR_Desc *old_rsrc;
|
|
LSR_Desc *old_rsrc;
|
|
- LSUP_rc rc = LSR_desc_get (rsrc->id, &old_rsrc);
|
|
|
|
- if (UNLIKELY (rc < 0)) return rc;
|
|
|
|
|
|
+ PRCCK (LSR_desc_get (rsrc->id, &old_rsrc));
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ * BEGIN txn
|
|
|
|
+ */
|
|
|
|
+ void *txn;
|
|
|
|
+ LSUP_store_begin (LSR_store, 0, &txn);
|
|
// Remove all existing user graphs.
|
|
// Remove all existing user graphs.
|
|
if (old_rsrc) {
|
|
if (old_rsrc) {
|
|
- LSUP_Term *main_data_urn = LSUP_graph_uri (old_rsrc->main_data);
|
|
|
|
// TODO Handle managed preds and types.
|
|
// TODO Handle managed preds and types.
|
|
// TODO Handle conflict between disjoint managed types.
|
|
// TODO Handle conflict between disjoint managed types.
|
|
// TODO Retain created and created_by.
|
|
// TODO Retain created and created_by.
|
|
@@ -265,32 +281,79 @@ LSR_desc_store (const LSR_Desc *rsrc)
|
|
LSUP_Term *gr_uri = LSUP_graph_uri (old_rsrc->user_data[i]);
|
|
LSUP_Term *gr_uri = LSUP_graph_uri (old_rsrc->user_data[i]);
|
|
size_t ct;
|
|
size_t ct;
|
|
// Remove triples from user graph.
|
|
// Remove triples from user graph.
|
|
- LSUP_graph_remove (old_rsrc->user_data[i], NULL, NULL, NULL, &ct);
|
|
|
|
- log_debug ( "Removed %lu triples from graph %s", ct, gr_uri->data);
|
|
|
|
|
|
+ PCHECK (LSUP_graph_remove_txn (
|
|
|
|
+ txn, old_rsrc->user_data[i],
|
|
|
|
+ NULL, NULL, NULL, &ct), fail);
|
|
|
|
+ log_debug ("Removed %lu triples from graph %s", ct, gr_uri->data);
|
|
|
|
|
|
// Remove user graph metadata.
|
|
// Remove user graph metadata.
|
|
- LSUP_graph_remove (old_rsrc->main_data, gr_uri, NULL, NULL, NULL);
|
|
|
|
- LSUP_graph_remove (old_rsrc->main_data, NULL, NULL, gr_uri, NULL);
|
|
|
|
|
|
+ PCHECK (LSUP_graph_remove_txn (
|
|
|
|
+ txn, old_rsrc->main_data, gr_uri,
|
|
|
|
+ NULL, NULL, NULL), fail);
|
|
|
|
+ PCHECK (LSUP_graph_remove_txn (
|
|
|
|
+ txn, old_rsrc->main_data,
|
|
|
|
+ NULL, NULL, gr_uri, NULL), fail);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ LSUP_Graph *tmp_gr;
|
|
// Add new triples.
|
|
// Add new triples.
|
|
|
|
+ LSUP_rc rc = LSUP_NOACTION;
|
|
for (size_t i = 0; rsrc->user_data[i] != NULL; i++) {
|
|
for (size_t i = 0; rsrc->user_data[i] != NULL; i++) {
|
|
- LSUP_Term *gr_uri = LSUP_graph_uri (rsrc->user_data[i]);
|
|
|
|
-
|
|
|
|
- LSUP_graph_store (rsrc->user_data[i], NULL, NULL);
|
|
|
|
|
|
+ tmp_gr = LSUP_graph_new (
|
|
|
|
+ LSR_store,
|
|
|
|
+ LSUP_term_copy (LSUP_graph_uri (rsrc->user_data[i])), NULL);
|
|
|
|
+ if (UNLIKELY (!tmp_gr)) {
|
|
|
|
+ rc = LSUP_MEM_ERR;
|
|
|
|
+ goto fail;
|
|
|
|
+ }
|
|
|
|
+ PCHECK (LSUP_graph_copy_contents_txn (
|
|
|
|
+ txn, rsrc->user_data[i], tmp_gr), fail);
|
|
|
|
+ LSUP_graph_free (tmp_gr);
|
|
}
|
|
}
|
|
|
|
|
|
// Update admin data.
|
|
// Update admin data.
|
|
- LSUP_graph_store (rsrc->admin_data, NULL, NULL);
|
|
|
|
|
|
+ tmp_gr = LSUP_graph_new (
|
|
|
|
+ LSR_store,
|
|
|
|
+ LSUP_term_copy (LSUP_graph_uri (rsrc->admin_data)), NULL);
|
|
|
|
+ if (UNLIKELY (!tmp_gr)) {
|
|
|
|
+ rc = LSUP_MEM_ERR;
|
|
|
|
+ goto fail;
|
|
|
|
+ }
|
|
|
|
+ PCHECK (LSUP_graph_copy_contents_txn (
|
|
|
|
+ txn, rsrc->admin_data, tmp_gr), fail);
|
|
|
|
+ LSUP_graph_free (tmp_gr);
|
|
|
|
+
|
|
// Update graph metadata.
|
|
// Update graph metadata.
|
|
- LSUP_graph_store (rsrc->main_data, NULL, NULL);
|
|
|
|
|
|
+ tmp_gr = LSUP_graph_new (
|
|
|
|
+ LSR_store,
|
|
|
|
+ LSUP_term_copy (LSUP_graph_uri (rsrc->main_data)), NULL);
|
|
|
|
+ if (UNLIKELY (!tmp_gr)) {
|
|
|
|
+ rc = LSUP_MEM_ERR;
|
|
|
|
+ goto fail;
|
|
|
|
+ }
|
|
|
|
+ PCHECK (LSUP_graph_copy_contents_txn (
|
|
|
|
+ txn, rsrc->main_data, tmp_gr), fail);
|
|
|
|
+ LSUP_graph_free (tmp_gr);
|
|
|
|
+
|
|
|
|
+ PCHECK (LSUP_store_commit (LSR_store, txn), fail);
|
|
|
|
+ /*
|
|
|
|
+ * END txn
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ return LSUP_OK;
|
|
|
|
+
|
|
|
|
+fail:
|
|
|
|
+ LSUP_store_abort (LSR_store, txn);
|
|
|
|
+
|
|
|
|
+ return rc;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
LSUP_rc
|
|
LSUP_rc
|
|
LSUP_desc_update (LSR_id id, LSUP_Term **remove, LSUP_Triple *add)
|
|
LSUP_desc_update (LSR_id id, LSUP_Term **remove, LSUP_Triple *add)
|
|
{
|
|
{
|
|
|
|
+ return LSUP_OK;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -300,39 +363,38 @@ LSR_desc_get (const uuid_t id, LSR_Desc **rsrc_p)
|
|
LSUP_rc rc = LSUP_OK;
|
|
LSUP_rc rc = LSUP_OK;
|
|
|
|
|
|
LSUP_Graph *main_gr = LSUP_graph_new (
|
|
LSUP_Graph *main_gr = LSUP_graph_new (
|
|
- LSUP_default_ctx, LSR_DEFAULT_BACKEND, NULL, NULL, 0);
|
|
|
|
-
|
|
|
|
- LSUP_Term
|
|
|
|
- *s = LSR_id_to_urn (id, NULL),
|
|
|
|
- *p = LSUP_iriref_new ("rdf:type", LSUP_default_nsm),
|
|
|
|
- *o = LSUP_iriref_new ("lsup:Resource", LSUP_default_nsm);
|
|
|
|
|
|
+ LSR_store, LSUP_term_copy (LSUP_default_ctx), NULL);
|
|
|
|
+ if (!main_gr) return LSUP_DB_ERR;
|
|
|
|
|
|
- LSUP_Triple *spo = LSUP_triple_new (s, p, o);
|
|
|
|
- LSUP_triple_free (spo);
|
|
|
|
|
|
+ LSUP_Triple *spo = LSUP_triple_new (
|
|
|
|
+ LSR_id_to_urn (id, NULL),
|
|
|
|
+ LSUP_iriref_new ("rdf:type", LSUP_default_nsm),
|
|
|
|
+ LSUP_iriref_new ("lsup:Resource", LSUP_default_nsm)
|
|
|
|
+ );
|
|
|
|
|
|
if (!LSUP_graph_contains (main_gr, spo)) {
|
|
if (!LSUP_graph_contains (main_gr, spo)) {
|
|
rc = LSUP_NORESULT;
|
|
rc = LSUP_NORESULT;
|
|
goto finally;
|
|
goto finally;
|
|
}
|
|
}
|
|
|
|
|
|
- LSUP_term_free (o);
|
|
|
|
- o = LSUP_iriref_new ("lsup:DescriptiveResource", LSUP_default_nsm);
|
|
|
|
- spo = LSUP_triple_new (s, p, o);
|
|
|
|
|
|
+ LSUP_term_free (spo->o);
|
|
|
|
+ spo->o = LSUP_iriref_new ("lsup:DescriptiveResource", LSUP_default_nsm);
|
|
if (!LSUP_graph_contains (main_gr, spo)) {
|
|
if (!LSUP_graph_contains (main_gr, spo)) {
|
|
- log_error ("%s is not a descriptive resource.", o->data);
|
|
|
|
|
|
+ log_error ("%s is not a descriptive resource.", spo->o->data);
|
|
rc = LSUP_NORESULT;
|
|
rc = LSUP_NORESULT;
|
|
goto finally;
|
|
goto finally;
|
|
}
|
|
}
|
|
|
|
|
|
- LSUP_term_free (p);
|
|
|
|
- p = LSUP_iriref_new ("foaf:primaryTopic", LSUP_default_nsm);
|
|
|
|
|
|
+ LSUP_term_free (spo->p);
|
|
|
|
+ spo->p = LSUP_iriref_new ("foaf:primaryTopic", LSUP_default_nsm);
|
|
size_t ct = 0, i = 0;
|
|
size_t ct = 0, i = 0;
|
|
|
|
|
|
// Find all graphs making up the resource.
|
|
// Find all graphs making up the resource.
|
|
- LSUP_GraphIterator *it = LSUP_graph_lookup (main_gr, NULL, p, s, &ct);
|
|
|
|
|
|
+ LSUP_GraphIterator *it = LSUP_graph_lookup (
|
|
|
|
+ main_gr, NULL, spo->p, spo->s, &ct);
|
|
LSUP_Graph **data = calloc (sizeof (*data), ct + 1);
|
|
LSUP_Graph **data = calloc (sizeof (*data), ct + 1);
|
|
while (LSUP_graph_iter_next (it, &spo)) {
|
|
while (LSUP_graph_iter_next (it, &spo)) {
|
|
- data[i] = LSUP_graph_new (spo->s, LSR_DEFAULT_BACKEND, NULL, NULL, 0);
|
|
|
|
|
|
+ data[i] = LSUP_graph_new (LSR_store, LSUP_term_copy (spo->s), NULL);
|
|
if (! data[i++]) break; // Last slot remains NULL (sentinel).
|
|
if (! data[i++]) break; // Last slot remains NULL (sentinel).
|
|
}
|
|
}
|
|
LSUP_graph_iter_free (it);
|
|
LSUP_graph_iter_free (it);
|
|
@@ -345,9 +407,6 @@ LSR_desc_get (const uuid_t id, LSR_Desc **rsrc_p)
|
|
|
|
|
|
finally:
|
|
finally:
|
|
LSUP_triple_free (spo);
|
|
LSUP_triple_free (spo);
|
|
- LSUP_term_free (s);
|
|
|
|
- LSUP_term_free (p);
|
|
|
|
- LSUP_term_free (o);
|
|
|
|
LSUP_graph_free (main_gr);
|
|
LSUP_graph_free (main_gr);
|
|
|
|
|
|
return rc;
|
|
return rc;
|
|
@@ -357,29 +416,10 @@ finally:
|
|
LSUP_Graph *
|
|
LSUP_Graph *
|
|
LSR_desc_metadata (const LSR_Desc *rsrc)
|
|
LSR_desc_metadata (const LSR_Desc *rsrc)
|
|
{
|
|
{
|
|
- uuid_t uuid;
|
|
|
|
- char
|
|
|
|
- *rsrc_uri_str = LSUP_graph_uri (rsrc->admin_data)->data,
|
|
|
|
- *frag = "#metadata-",
|
|
|
|
- uuid_str [UUID_STR_LEN],
|
|
|
|
- id_str [8],
|
|
|
|
- *uri_str = malloc (
|
|
|
|
- strlen (frag) + strlen (rsrc_uri_str) + sizeof (id_str));
|
|
|
|
- if (UNLIKELY (!uri_str)) return NULL;
|
|
|
|
-
|
|
|
|
- uuid_generate_random (uuid);
|
|
|
|
- uuid_unparse_lower (uuid, uuid_str);
|
|
|
|
- strncpy (id_str, uuid_str, sizeof (id_str) - 1);
|
|
|
|
-
|
|
|
|
- sprintf (uri_str, "%s%s%s", rsrc_uri_str, frag, id_str);
|
|
|
|
-
|
|
|
|
- LSUP_Graph *res = LSUP_graph_copy (rsrc->admin_data);
|
|
|
|
- if (LIKELY (res))
|
|
|
|
- LSUP_graph_set_uri (res, LSUP_iriref_new (uri_str, NULL));
|
|
|
|
-
|
|
|
|
- free (uri_str);
|
|
|
|
- free (rsrc_uri_str);
|
|
|
|
- free (uuid);
|
|
|
|
|
|
+ LSUP_Graph *res = LSUP_graph_new (
|
|
|
|
+ LSR_store, LSUP_term_copy (LSUP_graph_uri (rsrc->admin_data)),
|
|
|
|
+ NULL);
|
|
|
|
+ LSUP_graph_copy_contents (rsrc->admin_data, res);
|
|
|
|
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
@@ -388,39 +428,20 @@ LSR_desc_metadata (const LSR_Desc *rsrc)
|
|
LSUP_Graph **
|
|
LSUP_Graph **
|
|
LSR_desc_user_data (const LSR_Desc *rsrc)
|
|
LSR_desc_user_data (const LSR_Desc *rsrc)
|
|
{
|
|
{
|
|
- uuid_t uuid;
|
|
|
|
- char
|
|
|
|
- *rsrc_uri_str = LSUP_graph_uri (rsrc->admin_data)->data,
|
|
|
|
- *frag = "#metadata-",
|
|
|
|
- uuid_str [UUID_STR_LEN],
|
|
|
|
- id_str [8],
|
|
|
|
- *uri_str = malloc (
|
|
|
|
- strlen (frag) + strlen (rsrc_uri_str) + sizeof (id_str));
|
|
|
|
- if (UNLIKELY (!uri_str)) return NULL;
|
|
|
|
-
|
|
|
|
size_t ct = 0;
|
|
size_t ct = 0;
|
|
- while (rsrc->user_data[ct]) ct ++;
|
|
|
|
- LSUP_Graph **res = malloc (sizeof *res * (ct + 1));
|
|
|
|
|
|
+ while (rsrc->user_data[ct++]);
|
|
|
|
+ LSUP_Graph **res = malloc (sizeof (*res) * (ct + 1));
|
|
if (UNLIKELY (!res)) return NULL;
|
|
if (UNLIKELY (!res)) return NULL;
|
|
|
|
|
|
for (size_t i = 0; i < ct; i++) {
|
|
for (size_t i = 0; i < ct; i++) {
|
|
- uuid_generate_random (uuid);
|
|
|
|
- uuid_unparse_lower (uuid, uuid_str);
|
|
|
|
- strncpy (id_str, uuid_str, sizeof (id_str) - 1);
|
|
|
|
-
|
|
|
|
- sprintf (uri_str, "%s%s%s", rsrc_uri_str, frag, id_str);
|
|
|
|
-
|
|
|
|
- res[i] = LSUP_graph_copy (rsrc->user_data[i]);
|
|
|
|
- if (LIKELY (res))
|
|
|
|
- LSUP_graph_set_uri (res[i], LSUP_iriref_new (uri_str, NULL));
|
|
|
|
|
|
+ res[i] = LSUP_graph_new (
|
|
|
|
+ LSR_store,
|
|
|
|
+ LSUP_term_copy (LSUP_graph_uri (rsrc->user_data[i])), NULL);
|
|
|
|
+ LSUP_graph_copy_contents (rsrc->user_data[i], res[i]);
|
|
}
|
|
}
|
|
|
|
|
|
res[ct] = NULL;
|
|
res[ct] = NULL;
|
|
|
|
|
|
- free (uri_str);
|
|
|
|
- free (rsrc_uri_str);
|
|
|
|
- free (uuid);
|
|
|
|
-
|
|
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -438,51 +459,3 @@ void LSR_desc_free (LSR_Desc *rsrc)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-LSUP_rc
|
|
|
|
-LSR_desc_store (const LSR_Desc *rsrc)
|
|
|
|
-{
|
|
|
|
- // TODO Make atomic. Needs to implement transactions in backend.
|
|
|
|
- LSR_Desc *old_rsrc;
|
|
|
|
- LSUP_rc rc = LSR_desc_get (rsrc->id, &old_rsrc);
|
|
|
|
- if (UNLIKELY (rc < 0)) return rc;
|
|
|
|
-
|
|
|
|
- // Remove all existing user graphs.
|
|
|
|
- if (rc == LSUP_OK) {
|
|
|
|
- //LSUP_Term *main_data_urn = LSUP_graph_uri (old_rsrc->main_data);
|
|
|
|
- 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.
|
|
|
|
- LSUP_graph_remove (old_rsrc->user_data[i], NULL, NULL, NULL, &ct);
|
|
|
|
- log_debug ( "Removed %lu triples from graph %s", ct, gr_uri->data);
|
|
|
|
-
|
|
|
|
- // Remove user graph metadata.
|
|
|
|
- LSUP_graph_remove (old_rsrc->main_data, gr_uri, NULL, NULL, NULL);
|
|
|
|
- LSUP_graph_remove (old_rsrc->main_data, NULL, NULL, gr_uri, NULL);
|
|
|
|
- }
|
|
|
|
- } else rc = LSUP_OK;
|
|
|
|
-
|
|
|
|
- // Add new triples.
|
|
|
|
- for (size_t i = 0; rsrc->user_data[i] != NULL; i++) {
|
|
|
|
- //LSUP_Term *gr_uri = LSUP_graph_uri (rsrc->user_data[i]);
|
|
|
|
-
|
|
|
|
- log_trace ("Storing data graph #%lu", i);
|
|
|
|
- LSUP_graph_store (rsrc->user_data[i], NULL, NULL);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Update admin data.
|
|
|
|
- LSUP_graph_store (rsrc->admin_data, NULL, NULL);
|
|
|
|
- // Update graph metadata.
|
|
|
|
- LSUP_graph_store (rsrc->main_data, NULL, NULL);
|
|
|
|
-
|
|
|
|
- return rc;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-LSUP_rc
|
|
|
|
-LSUP_desc_update (LSR_id id, LSUP_Term **remove, LSUP_Triple *add)
|
|
|
|
-{
|
|
|
|
- LSUP_rc rc = LSUP_OK;
|
|
|
|
-
|
|
|
|
- return rc;
|
|
|
|
-}
|
|
|