rdf-hamster-repo 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/AUTHORS +1 -0
- data/README.md +62 -0
- data/UNLICENSE +24 -0
- data/VERSION +1 -0
- data/etc/doap.ttl +29 -0
- data/lib/rdf/hamster_repo.rb +437 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f9a06151808cb3e8163fb27a8f378e9b507c99c784761ac3dfc6bcd9efc42306
|
4
|
+
data.tar.gz: b3353ac4627e79194ed360cf022d51a98f1d0c96062527cee36d653e2eb8dabc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe7606f4c71c852706b6a97a2e8632ca32921768280dda101e946c44c010d04cc438bc8436865f22dc698f6608f9369cff98b8fa4f38ed6569ee0a85ac9f9d15
|
7
|
+
data.tar.gz: e27972369c6fb37e6d616329266dd09c69740d8bc5bfe508c5b3b7dca04df6723d73c40f9191d78a3839970afa57372d191387badcad7fe1a6819ca823c423db
|
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* Gregg Kellogg <gregg@greggkellogg.net>
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# RDF::HamsterRepo
|
2
|
+
An RDF repository implementation using an in-memory Hamster Hash.
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/rdf-hamster-repo.png)](https://badge.fury.io/rb/rdf-hamster-repo)
|
5
|
+
[![Build Status](https://github.com/ruby-rdf/rdf-hamster-repo/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/rdf-hamster-repo/actions?query=workflow%3ACI)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf-hamster-repo/badge.svg?branch=develop)](https://coveralls.io/github/ruby-rdf/rdf-hamster-repo?branch=develop)
|
7
|
+
[![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)
|
8
|
+
|
9
|
+
## Description
|
10
|
+
|
11
|
+
An in-memory implementation of RDF::Repository using an efficient, immutable, and thread-safe Hash.
|
12
|
+
|
13
|
+
## Examples
|
14
|
+
|
15
|
+
require 'rdf/hamster_repo'
|
16
|
+
require 'rdf/nquads'
|
17
|
+
repo = RDF::HamsterRepo.load("https://ruby-rdf.github.com/rdf/etc/doap.nq")
|
18
|
+
|
19
|
+
## Dependencies
|
20
|
+
|
21
|
+
* [Ruby](https://ruby-lang.org/) (>= 2.6)
|
22
|
+
* [RDF.rb][] (~> 3.2)
|
23
|
+
* [Hamster][] (~> 3.0)
|
24
|
+
|
25
|
+
## Mailing List
|
26
|
+
|
27
|
+
* <https://lists.w3.org/Archives/Public/public-rdf-ruby/>
|
28
|
+
|
29
|
+
## Author
|
30
|
+
|
31
|
+
* [Gregg Kellogg](https://github.com/gkellogg) - <https://greggkellogg.net/>
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration.
|
35
|
+
|
36
|
+
* Do your best to adhere to the existing coding conventions and idioms.
|
37
|
+
* Don't use hard tabs, and don't leave trailing whitespace on any line.
|
38
|
+
Before committing, run `git diff --check` to make sure of this.
|
39
|
+
* Do document every method you add using [YARD][] annotations. Read the
|
40
|
+
[tutorial][YARD-GS] or just look at the existing code for examples.
|
41
|
+
* Don't touch the `.gemspec` or `VERSION` files. If you need to change them,
|
42
|
+
do so on your private branch only.
|
43
|
+
* Do feel free to add yourself to the `CREDITS` file and the
|
44
|
+
corresponding list in the the `README`. Alphabetical order applies.
|
45
|
+
* Don't touch the `AUTHORS` file. If your contributions are significant
|
46
|
+
enough, be assured we will eventually add you in there.
|
47
|
+
* Do note that in order for us to merge any non-trivial changes (as a rule
|
48
|
+
of thumb, additions larger than about 15 lines of code), we need an
|
49
|
+
explicit [public domain dedication][PDD] on record from you,
|
50
|
+
which you will be asked to agree to on the first commit to a repo within the organization.
|
51
|
+
Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization.
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
This is free and unencumbered public domain software. For more information,
|
56
|
+
see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
57
|
+
|
58
|
+
[RDF.rb]: https://ruby-rdf.github.com/
|
59
|
+
[YARD]: https://yardoc.org/
|
60
|
+
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
|
61
|
+
[PDD]: https://unlicense.org/#unlicensing-contributions
|
62
|
+
[Hamster]: https://github.com/hamstergem/hamster
|
data/UNLICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <https://unlicense.org>
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.0
|
data/etc/doap.ttl
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
@base <https://rubygems.org/gems/rdf-hamster-repo> .
|
2
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
3
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
4
|
+
@prefix dc: <http://purl.org/dc/terms/> .
|
5
|
+
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
|
6
|
+
@prefix doap: <http://usefulinc.com/ns/doap#> .
|
7
|
+
@prefix ex: <http://example.org/> .
|
8
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
9
|
+
|
10
|
+
<> a doap:Project ;
|
11
|
+
doap:name "RDF::HamsterRepo" ;
|
12
|
+
doap:homepage <https://github.com/ruby-rdf/rdf-hamster-repo> ;
|
13
|
+
doap:license <https://unlicense.org/1.0/> ;
|
14
|
+
doap:shortdesc "An RDF repository implementation using an in-memory Hamster Hash."@en ;
|
15
|
+
doap:description "An in-memory implementation of RDF::Repository using an efficient, immutable, and thread-safe Hash."@en ;
|
16
|
+
doap:created "2021-12-28"^^xsd:date;
|
17
|
+
doap:programming-language "Ruby" ;
|
18
|
+
doap:implements <http://www.w3.org/TR/rdf11-concepts/> ;
|
19
|
+
doap:category <http://dbpedia.org/resource/Resource_Description_Framework>,
|
20
|
+
<http://dbpedia.org/resource/Ruby_(programming_language)> ;
|
21
|
+
doap:download-page <> ;
|
22
|
+
doap:mailing-list <https://lists.w3.org/Archives/Public/public-rdf-ruby/> ;
|
23
|
+
doap:bug-database <https://github.com/ruby-rdf/rdf-hamster-repo/issues> ;
|
24
|
+
doap:blog <https://greggkellogg.net/> ;
|
25
|
+
doap:developer <https://greggkellogg.net/foaf#me> ;
|
26
|
+
doap:maintainer <https://greggkellogg.net/foaf#me> ;
|
27
|
+
doap:documenter <https://greggkellogg.net/foaf#me> ;
|
28
|
+
foaf:maker <https://greggkellogg.net/foaf#me> ;
|
29
|
+
dc:creator <https://greggkellogg.net/foaf#me> .
|
@@ -0,0 +1,437 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
require 'hamster'
|
3
|
+
|
4
|
+
module RDF
|
5
|
+
##
|
6
|
+
# Sub-class of RDF::Repository with order-preserving properties.
|
7
|
+
class HamsterRepo < RDF::Repository
|
8
|
+
DEFAULT_GRAPH = false
|
9
|
+
|
10
|
+
##
|
11
|
+
# @private
|
12
|
+
def self.extend_object(obj)
|
13
|
+
obj.instance_variable_set(:@data, obj.options.delete(:data) ||
|
14
|
+
Hamster::Hash.new)
|
15
|
+
obj.instance_variable_set(:@tx_class,
|
16
|
+
obj.options.delete(:transaction_class) ||
|
17
|
+
SerializedTransaction)
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Initializes this repository instance.
|
23
|
+
#
|
24
|
+
# @param [URI, #to_s] uri (nil)
|
25
|
+
# @param [String, #to_s] title (nil)
|
26
|
+
# @param [Hash{Symbol => Object}] options
|
27
|
+
# @option options [Boolean] :with_graph_name (true)
|
28
|
+
# Indicates that the repository supports named graphs, otherwise,
|
29
|
+
# only the default graph is supported.
|
30
|
+
# @option options [Boolean] :with_validity (true)
|
31
|
+
# Indicates that the repository supports named validation.
|
32
|
+
# @option options [Boolean] :transaction_class (SerializedTransaction)
|
33
|
+
# Specifies the RDF::Transaction implementation to use in this Repository.
|
34
|
+
# @yield [repository]
|
35
|
+
# @yieldparam [Repository] repository
|
36
|
+
def initialize(uri: nil, title: nil, **options, &block)
|
37
|
+
@data = options.delete(:data) || Hamster::Hash.new
|
38
|
+
super do
|
39
|
+
if block_given?
|
40
|
+
case block.arity
|
41
|
+
when 1 then block.call(self)
|
42
|
+
else instance_eval(&block)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Returns `true` if this respository supports the given `feature`.
|
50
|
+
#
|
51
|
+
# This repository supports list_terms.
|
52
|
+
def supports?(feature)
|
53
|
+
case feature.to_sym
|
54
|
+
when :atomic_write then true
|
55
|
+
when :rdfstar then true
|
56
|
+
when :snapshots then true
|
57
|
+
else super
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Creates a query from the statements in this repository, turning blank nodes into non-distinguished variables. This can be used to determine if this repository is logically a subset of another repository.
|
63
|
+
#
|
64
|
+
# @return [RDF::Query]
|
65
|
+
def to_query
|
66
|
+
RDF::Query.new do |query|
|
67
|
+
each do |statement|
|
68
|
+
query.pattern RDF::Query::Pattern.from(statement, ndvars: true)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# @private
|
75
|
+
# @see RDF::Countable#count
|
76
|
+
def count
|
77
|
+
count = 0
|
78
|
+
@data.each do |_, ss|
|
79
|
+
ss.each do |_, ps|
|
80
|
+
ps.each { |_, os| count += os.size }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
count
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# @overload graph?
|
88
|
+
# Returns `false` to indicate that this is not a graph.
|
89
|
+
#
|
90
|
+
# @return [Boolean]
|
91
|
+
# @overload graph?(name)
|
92
|
+
# Returns `true` if `self` contains the given RDF graph_name.
|
93
|
+
#
|
94
|
+
# @param [RDF::Resource, false] graph_name
|
95
|
+
# Use value `false` to query for the default graph_name
|
96
|
+
# @return [Boolean]
|
97
|
+
def graph?(*args)
|
98
|
+
case args.length
|
99
|
+
when 0 then false
|
100
|
+
when 1 then @data.key?(args.first)
|
101
|
+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
alias_method :has_graph?, :graph?
|
105
|
+
|
106
|
+
##
|
107
|
+
# @private
|
108
|
+
# @see RDF::Enumerable#each_graph
|
109
|
+
def graph_names(options = nil, &block)
|
110
|
+
@data.keys.reject { |g| g == DEFAULT_GRAPH }.to_a
|
111
|
+
end
|
112
|
+
|
113
|
+
##
|
114
|
+
# @private
|
115
|
+
# @see RDF::Enumerable#each_graph
|
116
|
+
def each_graph(&block)
|
117
|
+
if block_given?
|
118
|
+
@data.each_key do |gn|
|
119
|
+
yield RDF::Graph.new(graph_name: (gn == DEFAULT_GRAPH ? nil : gn), data: self)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
enum_graph
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# @overload statement?
|
127
|
+
# Returns `false` indicating this is not an RDF::Statemenet.
|
128
|
+
# @return [Boolean]
|
129
|
+
# @see RDF::Value#statement?
|
130
|
+
# @overload statement?(statement)
|
131
|
+
# @private
|
132
|
+
# @see RDF::Enumerable#statement?
|
133
|
+
def statement?(*args)
|
134
|
+
case args.length
|
135
|
+
when 0 then false
|
136
|
+
when 1 then args.first && statement_in?(@data, args.first)
|
137
|
+
else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
alias_method :has_statement?, :statement?
|
141
|
+
|
142
|
+
##
|
143
|
+
# @private
|
144
|
+
# @see RDF::Enumerable#each_statement
|
145
|
+
def each_statement(&block)
|
146
|
+
if block_given?
|
147
|
+
@data.each do |g, ss|
|
148
|
+
ss.each do |s, ps|
|
149
|
+
ps.each do |p, os|
|
150
|
+
os.each do |o, object_options|
|
151
|
+
yield RDF::Statement.new(s, p, o, object_options.merge(graph_name: g.equal?(DEFAULT_GRAPH) ? nil : g))
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
enum_statement
|
158
|
+
end
|
159
|
+
alias_method :each, :each_statement
|
160
|
+
|
161
|
+
##
|
162
|
+
# @see Mutable#apply_changeset
|
163
|
+
def apply_changeset(changeset)
|
164
|
+
data = @data
|
165
|
+
changeset.deletes.each do |del|
|
166
|
+
if del.constant?
|
167
|
+
data = delete_from(data, del)
|
168
|
+
else
|
169
|
+
# we need this condition to handle wildcard statements
|
170
|
+
query_pattern(del) { |stmt| data = delete_from(data, stmt) }
|
171
|
+
end
|
172
|
+
end
|
173
|
+
changeset.inserts.each { |ins| data = insert_to(data, ins) }
|
174
|
+
@data = data
|
175
|
+
end
|
176
|
+
|
177
|
+
##
|
178
|
+
# @see RDF::Dataset#isolation_level
|
179
|
+
def isolation_level
|
180
|
+
:serializable
|
181
|
+
end
|
182
|
+
|
183
|
+
##
|
184
|
+
# A readable & queryable snapshot of the repository for isolated reads.
|
185
|
+
#
|
186
|
+
# @return [Dataset] an immutable Dataset containing a current snapshot of
|
187
|
+
# the Repository contents.
|
188
|
+
#
|
189
|
+
# @see Mutable#snapshot
|
190
|
+
def snapshot
|
191
|
+
self.class.new(data: @data).freeze
|
192
|
+
end
|
193
|
+
|
194
|
+
protected
|
195
|
+
|
196
|
+
##
|
197
|
+
# Match elements with `eql?`, not `==`
|
198
|
+
#
|
199
|
+
# `graph_name` of `false` matches default graph. Unbound variable matches
|
200
|
+
# non-false graph name.
|
201
|
+
#
|
202
|
+
# Matches terms which are native lists.
|
203
|
+
#
|
204
|
+
# @private
|
205
|
+
# @see RDF::Queryable#query_pattern
|
206
|
+
def query_pattern(pattern, **options, &block)
|
207
|
+
snapshot = @data
|
208
|
+
if block_given?
|
209
|
+
graph_name = pattern.graph_name
|
210
|
+
subject = pattern.subject
|
211
|
+
predicate = pattern.predicate
|
212
|
+
object = pattern.object
|
213
|
+
|
214
|
+
cs = snapshot.has_key?(graph_name) ? { graph_name => snapshot[graph_name] } : snapshot
|
215
|
+
|
216
|
+
cs.each do |c, ss|
|
217
|
+
next unless graph_name.nil? ||
|
218
|
+
graph_name == DEFAULT_GRAPH && !c ||
|
219
|
+
graph_name.eql?(c)
|
220
|
+
|
221
|
+
ss = if subject.nil? || subject.is_a?(RDF::Query::Variable)
|
222
|
+
ss
|
223
|
+
elsif subject.is_a?(RDF::Query::Pattern)
|
224
|
+
# Match subjects which are statements matching this pattern
|
225
|
+
ss.keys.select {|s| s.statement? && subject.eql?(s)}.inject({}) do |memo, st|
|
226
|
+
memo.merge(st => ss[st])
|
227
|
+
end
|
228
|
+
elsif ss.has_key?(subject)
|
229
|
+
{ subject => ss[subject] }
|
230
|
+
else
|
231
|
+
[]
|
232
|
+
end
|
233
|
+
ss.each do |s, ps|
|
234
|
+
ps = if predicate.nil? || predicate.is_a?(RDF::Query::Variable)
|
235
|
+
ps
|
236
|
+
elsif ps.has_key?(predicate)
|
237
|
+
{ predicate => ps[predicate] }
|
238
|
+
else
|
239
|
+
[]
|
240
|
+
end
|
241
|
+
ps.each do |p, os|
|
242
|
+
os.each do |o, object_options|
|
243
|
+
next unless object.nil? || object.eql?(o)
|
244
|
+
yield RDF::Statement.new(s, p, o, object_options.merge(graph_name: c.equal?(DEFAULT_GRAPH) ? nil : c))
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
else
|
250
|
+
enum_for(:query_pattern, pattern, **options)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
##
|
255
|
+
# @private
|
256
|
+
# @see RDF::Mutable#insert
|
257
|
+
def insert_statement(statement)
|
258
|
+
@data = insert_to(@data, statement)
|
259
|
+
end
|
260
|
+
|
261
|
+
##
|
262
|
+
# @private
|
263
|
+
# @see RDF::Mutable#delete
|
264
|
+
def delete_statement(statement)
|
265
|
+
@data = delete_from(@data, statement)
|
266
|
+
end
|
267
|
+
|
268
|
+
##
|
269
|
+
# @private
|
270
|
+
# @see RDF::Mutable#clear
|
271
|
+
def clear_statements
|
272
|
+
@data = @data.clear
|
273
|
+
end
|
274
|
+
|
275
|
+
##
|
276
|
+
# @private
|
277
|
+
# @return [Hash]
|
278
|
+
def data
|
279
|
+
@data
|
280
|
+
end
|
281
|
+
|
282
|
+
##
|
283
|
+
# @private
|
284
|
+
# @return [Hash]
|
285
|
+
def data=(hash)
|
286
|
+
@data = hash
|
287
|
+
end
|
288
|
+
|
289
|
+
private
|
290
|
+
|
291
|
+
##
|
292
|
+
# @private
|
293
|
+
# @see #statement?
|
294
|
+
def statement_in?(data, statement)
|
295
|
+
s, p, o, g = statement.to_quad
|
296
|
+
g ||= DEFAULT_GRAPH
|
297
|
+
|
298
|
+
data.key?(g) &&
|
299
|
+
data[g].key?(s) &&
|
300
|
+
data[g][s].key?(p) &&
|
301
|
+
data[g][s][p].key?(o)
|
302
|
+
end
|
303
|
+
alias_method :has_statement_in?, :statement_in?
|
304
|
+
|
305
|
+
##
|
306
|
+
# @private
|
307
|
+
# @return [Hash] a new, updated hash
|
308
|
+
def insert_to(data, statement)
|
309
|
+
raise ArgumentError, "Statement #{statement.inspect} is incomplete" if statement.incomplete?
|
310
|
+
|
311
|
+
unless statement_in?(data, statement)
|
312
|
+
s, p, o, c = statement.to_quad
|
313
|
+
c ||= DEFAULT_GRAPH
|
314
|
+
|
315
|
+
return data.put(c) do |subs|
|
316
|
+
(subs || Hamster::Hash.new).put(s) do |preds|
|
317
|
+
(preds || Hamster::Hash.new).put(p) do |objs|
|
318
|
+
(objs || Hamster::Hash.new).put(o, statement.options)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
data
|
324
|
+
end
|
325
|
+
|
326
|
+
##
|
327
|
+
# @private
|
328
|
+
# @return [Hash] a new, updated hash
|
329
|
+
def delete_from(data, statement)
|
330
|
+
if has_statement_in?(data, statement)
|
331
|
+
s, p, o, g = statement.to_quad
|
332
|
+
g = DEFAULT_GRAPH unless supports?(:graph_name)
|
333
|
+
g ||= DEFAULT_GRAPH
|
334
|
+
|
335
|
+
os = data[g][s][p].delete(o)
|
336
|
+
ps = os.empty? ? data[g][s].delete(p) : data[g][s].put(p, os)
|
337
|
+
ss = ps.empty? ? data[g].delete(s) : data[g].put(s, ps)
|
338
|
+
return ss.empty? ? data.delete(g) : data.put(g, ss)
|
339
|
+
end
|
340
|
+
data
|
341
|
+
end
|
342
|
+
|
343
|
+
##
|
344
|
+
# A transaction for the Hamster-based `RDF::Repository::Implementation`
|
345
|
+
# with full serializability.
|
346
|
+
#
|
347
|
+
# @todo refactor me!
|
348
|
+
# @see RDF::Transaction
|
349
|
+
class SerializedTransaction < Transaction
|
350
|
+
##
|
351
|
+
# @see Transaction#initialize
|
352
|
+
def initialize(*args, **options, &block)
|
353
|
+
super(*args, **options, &block)
|
354
|
+
@base_snapshot = @snapshot
|
355
|
+
end
|
356
|
+
|
357
|
+
##
|
358
|
+
# Inserts the statement to the transaction's working snapshot.
|
359
|
+
#
|
360
|
+
# @see Transaction#insert_statement
|
361
|
+
def insert_statement(statement)
|
362
|
+
@snapshot = @snapshot.class
|
363
|
+
.new(data: @snapshot.send(:insert_to,
|
364
|
+
@snapshot.send(:data),
|
365
|
+
process_statement(statement)))
|
366
|
+
end
|
367
|
+
|
368
|
+
##
|
369
|
+
# Deletes the statement from the transaction's working snapshot.
|
370
|
+
#
|
371
|
+
# @see Transaction#insert_statement
|
372
|
+
def delete_statement(statement)
|
373
|
+
@snapshot = @snapshot.class
|
374
|
+
.new(data: @snapshot.send(:delete_from,
|
375
|
+
@snapshot.send(:data),
|
376
|
+
process_statement(statement)))
|
377
|
+
end
|
378
|
+
|
379
|
+
##
|
380
|
+
# @see RDF::Dataset#isolation_level
|
381
|
+
def isolation_level
|
382
|
+
:serializable
|
383
|
+
end
|
384
|
+
|
385
|
+
##
|
386
|
+
# @note this is a simple object equality check.
|
387
|
+
#
|
388
|
+
# @see RDF::Transaction#mutated?
|
389
|
+
def mutated?
|
390
|
+
!@snapshot.send(:data).equal?(repository.send(:data))
|
391
|
+
end
|
392
|
+
|
393
|
+
##
|
394
|
+
# Replaces repository data with the transaction's snapshot in a safely
|
395
|
+
# serializable fashion.
|
396
|
+
#
|
397
|
+
# @note this transaction uses a pessimistic merge strategy which
|
398
|
+
# fails the transaction if any data has changed in the repository
|
399
|
+
# since transaction start time. However, the specific guarantee is
|
400
|
+
# softer: multiple concurrent conflicting transactions will not
|
401
|
+
# succeed. We may choose to implement a less pessimistic merge
|
402
|
+
# strategy as a non-breaking change.
|
403
|
+
#
|
404
|
+
# @raise [TransactionError] when the transaction can't be merged.
|
405
|
+
# @see Transaction#execute
|
406
|
+
def execute
|
407
|
+
raise TransactionError, 'Cannot execute a rolled back transaction. ' \
|
408
|
+
'Open a new one instead.' if instance_variable_defined?(:@rolledback) && @rolledback
|
409
|
+
|
410
|
+
raise TransactionError, 'Error merging transaction. Repository' \
|
411
|
+
'has changed during transaction time.' unless
|
412
|
+
repository.send(:data).equal? @base_snapshot.send(:data)
|
413
|
+
|
414
|
+
repository.send(:data=, @snapshot.send(:data))
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
module VERSION
|
419
|
+
VERSION_FILE = File.expand_path("../../../VERSION", __FILE__)
|
420
|
+
MAJOR, MINOR, TINY, EXTRA = File.read(VERSION_FILE).chop.split(".")
|
421
|
+
|
422
|
+
STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
|
423
|
+
|
424
|
+
##
|
425
|
+
# @return [String]
|
426
|
+
def self.to_s() STRING end
|
427
|
+
|
428
|
+
##
|
429
|
+
# @return [String]
|
430
|
+
def self.to_str() STRING end
|
431
|
+
|
432
|
+
##
|
433
|
+
# @return [Array(Integer, Integer, Integer)]
|
434
|
+
def self.to_a() STRING.split(".") end
|
435
|
+
end
|
436
|
+
end
|
437
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rdf-hamster-repo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gregg Kellogg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rdf
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hamster
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdf-spec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
83
|
+
description: An in-memory implementation of RDF::Repository using an efficient, immutable,
|
84
|
+
and thread-safe Hash.
|
85
|
+
email: public-rdf-ruby@w3.org
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- AUTHORS
|
91
|
+
- README.md
|
92
|
+
- UNLICENSE
|
93
|
+
- VERSION
|
94
|
+
- etc/doap.ttl
|
95
|
+
- lib/rdf/hamster_repo.rb
|
96
|
+
homepage: https://github.com/ruby-rdf/rdf-hamster-repo
|
97
|
+
licenses:
|
98
|
+
- Unlicense
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '2.6'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubygems_version: 3.3.3
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: An RDF repository implementation using an in-memory Hamster Hash.
|
119
|
+
test_files: []
|