[tracker/blank] SPARQL: Fix URI generation for inserted blank nodes
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/blank] SPARQL: Fix URI generation for inserted blank nodes
- Date: Wed, 25 Nov 2009 08:49:29 +0000 (UTC)
commit d0cb4af994043de50ba00baac1308a3cf32fa63c
Author: Jürg Billeter <j bitron ch>
Date: Wed Nov 25 09:49:03 2009 +0100
SPARQL: Fix URI generation for inserted blank nodes
src/libtracker-data/tracker-sparql-query.vala | 44 +++++++++++++-----------
1 files changed, 24 insertions(+), 20 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 99b25c2..3915577 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -290,6 +290,21 @@ public class Tracker.SparqlQuery : Object {
this.update_extensions = true;
}
+ string get_uuid_for_name (uchar[] base_uuid, string name) {
+ var checksum = new Checksum (ChecksumType.SHA1);
+ // base UUID, unique per file
+ checksum.update (base_uuid, 16);
+
+ // node ID
+ checksum.update ((uchar[]) name, -1);
+
+ string sha1 = checksum.get_string ();
+
+ // generate name based uuid
+ return "urn:uuid:%.8s-%.4s-%.4s-%.4s-%.12s".printf (
+ sha1, sha1.offset (8), sha1.offset (12), sha1.offset (16), sha1.offset (20));
+ }
+
string generate_bnodeid (string? user_bnodeid) {
// user_bnodeid is NULL for anonymous nodes
if (user_bnodeid == null) {
@@ -304,28 +319,17 @@ public class Tracker.SparqlQuery : Object {
}
}
- var checksum = new Checksum (ChecksumType.SHA1);
- // base UUID, unique per file
- checksum.update (base_uuid, 16);
-
- while (uri == null) {
- // node ID
- checksum.update ((uchar[]) user_bnodeid, -1);
+ uri = get_uuid_for_name (base_uuid, user_bnodeid);
- string sha1 = checksum.get_string ();
-
- // generate name based uuid
- uri = "urn:uuid:%.8s-%.4s-%.4s-%.4s-%.12s".printf (
- sha1, sha1.offset (8), sha1.offset (12), sha1.offset (16), sha1.offset (20));
-
- if (blank_nodes != null) {
- if (Data.query_resource_id (uri) > 0) {
- blank_nodes.insert (user_bnodeid, uri);
- } else {
- // uri collision
- uri = null;
- }
+ if (blank_nodes != null) {
+ while (Data.query_resource_id (uri) > 0) {
+ // uri collision, generate new UUID
+ uchar[] new_base_uuid = new uchar[16];
+ uuid_generate (new_base_uuid);
+ uri = get_uuid_for_name (new_base_uuid, user_bnodeid);
}
+
+ blank_nodes.insert (user_bnodeid, uri);
}
return uri;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]