|
@@ -64,6 +64,42 @@ LSUP_graph_new (LSUP_Store *store, LSUP_Term *uri, LSUP_NSMap *nsm)
|
|
|
}
|
|
|
|
|
|
|
|
|
+LSUP_Graph *
|
|
|
+LSUP_graph_get_txn (void *txn, LSUP_Store *store, LSUP_Term *uri, size_t *ct)
|
|
|
+{
|
|
|
+ LSUP_Buffer *sc = LSUP_term_serialize (uri);
|
|
|
+ void *it = store->sif->lookup_fn (
|
|
|
+ store->data, NULL, NULL, NULL, sc, NULL, NULL);
|
|
|
+
|
|
|
+ LSUP_Graph *gr = LSUP_graph_new (NULL, uri, NULL);
|
|
|
+ LSUP_BufferTriple *sspo = BTRP_DUMMY;
|
|
|
+ void *add_it = LSUP_graph_add_init_txn (txn, gr);
|
|
|
+
|
|
|
+ size_t _ct = 0;
|
|
|
+ while (store->sif->lu_next_fn (it, sspo, NULL) == LSUP_OK) {
|
|
|
+ // TODO This is inefficient, it's deserializing a buffer triple that
|
|
|
+ // will be re-serialized by LSUP_graph_add_iter.
|
|
|
+ LSUP_Triple *spo = LSUP_triple_new_from_btriple (sspo);
|
|
|
+ LSUP_graph_add_iter (add_it, spo);
|
|
|
+ LSUP_triple_free (spo);
|
|
|
+ _ct++;
|
|
|
+ }
|
|
|
+ LSUP_graph_add_done (add_it);
|
|
|
+ store->sif->lu_free_fn(it);
|
|
|
+ LSUP_buffer_free (sc);
|
|
|
+ LSUP_btriple_free_shallow (sspo);
|
|
|
+
|
|
|
+ // Do not create a new graph if no results were found.
|
|
|
+ if (_ct == 0) {
|
|
|
+ LSUP_graph_free (gr);
|
|
|
+ gr = NULL;
|
|
|
+ }
|
|
|
+ if (ct) *ct = _ct;
|
|
|
+
|
|
|
+ return gr;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
LSUP_rc
|
|
|
LSUP_graph_bool_op_txn (
|
|
|
void *txn, const LSUP_bool_op op,
|
|
@@ -212,7 +248,17 @@ LSUP_graph_set_namespace (LSUP_Graph *gr, LSUP_NSMap *nsm)
|
|
|
|
|
|
size_t
|
|
|
LSUP_graph_size (const LSUP_Graph *gr)
|
|
|
-{ return gr->store->sif->size_fn (gr->store->data); }
|
|
|
+{
|
|
|
+ size_t ct = 0;
|
|
|
+ LSUP_Buffer *sc = LSUP_term_serialize (gr->uri);
|
|
|
+ void *it = gr->store->sif->lookup_fn (
|
|
|
+ gr->store->data, NULL, NULL, NULL, sc, NULL, &ct);
|
|
|
+ gr->store->sif->lu_free_fn (it);
|
|
|
+
|
|
|
+ LSUP_buffer_free (sc);
|
|
|
+
|
|
|
+ return ct;
|
|
|
+}
|
|
|
|
|
|
|
|
|
bool
|
|
@@ -330,15 +376,13 @@ LSUP_graph_remove_txn (
|
|
|
const LSUP_Term *s, const LSUP_Term *p, const LSUP_Term *o,
|
|
|
size_t *ct)
|
|
|
{
|
|
|
- LSUP_rc rc;
|
|
|
-
|
|
|
LSUP_Buffer
|
|
|
*ss = LSUP_term_serialize (s),
|
|
|
*sp = LSUP_term_serialize (p),
|
|
|
*so = LSUP_term_serialize (o),
|
|
|
*sc = LSUP_term_serialize (gr->uri);
|
|
|
|
|
|
- rc = gr->store->sif->remove_fn (
|
|
|
+ LSUP_rc rc = gr->store->sif->remove_fn (
|
|
|
gr->store->data, ss, sp, so, sc, txn, ct);
|
|
|
|
|
|
LSUP_buffer_free (ss);
|
|
@@ -677,12 +721,11 @@ inline LSUP_rc
|
|
|
graph_iter_alloc_buffers (LSUP_GraphIterator *it)
|
|
|
{
|
|
|
if (it->graph->store->sif->features & LSUP_STORE_COW) {
|
|
|
+ // Copy-on-wite store.
|
|
|
it->sspo = BTRP_DUMMY;
|
|
|
- CALLOC_GUARD (it->sspo->s, LSUP_MEM_ERR);
|
|
|
- CALLOC_GUARD (it->sspo->p, LSUP_MEM_ERR);
|
|
|
- CALLOC_GUARD (it->sspo->o, LSUP_MEM_ERR);
|
|
|
+ if (it->sspo == NULL) return LSUP_MEM_ERR;
|
|
|
} else {
|
|
|
- // TODO copy-on-retrieval stores. None yet.
|
|
|
+ // TODO copy-on-retrieval store. No implementations yet.
|
|
|
}
|
|
|
|
|
|
return LSUP_OK;
|