Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/rdf/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,18 @@ def initialize(uri: nil, title: nil, **options, &block)
##
# Returns `true` if this respository supports the given `feature`.
#
# Supported features include those from {RDF::Enumerable#supports?} along with the following:
# * `:transactions` supports atomic transactions
# * `:snapshots` supports creation of immutable snapshots of current contents via #snapshot.
# Supported features include those from {RDF::Enumerable#supports?} along
# with the following:
# * `:atomic_write` supports atomic write in transaction scopes
# * `:snapshots` supports creation of immutable snapshots of current
# contents via #snapshot.
# @see RDF::Enumerable#supports?
def supports?(feature)
case feature.to_sym
when :graph_name then @options[:with_graph_name]
when :inference then false # forward-chaining inference
when :validity then @options.fetch(:with_validity, true)
when :transactions then false
when :atomic_write then false
when :snapshots then false
else false
end
Expand Down Expand Up @@ -272,7 +274,7 @@ def supports?(feature)
when :graph_name then @options[:with_graph_name]
when :inference then false # forward-chaining inference
when :validity then @options.fetch(:with_validity, true)
when :transactions then true
when :atomic_write then true
when :snapshots then true
else false
end
Expand Down
10 changes: 7 additions & 3 deletions lib/rdf/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module RDF
#
# Repository implementations may provide support for transactional updates
# by providing an atomic implementation of {Mutable#apply_changeset} and
# responding to `#supports?(:transactions)` with `true`.
# responding to `#supports?(:atomic_write)` with `true`.
#
# We carefully distinguish between read-only and read/write transactions,
# in order to enable repository implementations to take out the
Expand All @@ -18,7 +18,7 @@ module RDF
# transaction's scope. In case repository implementations should be unable
# to provide full ACID guarantees for transactions, that must be clearly
# indicated in their documentation. If update atomicity is not provided,
# `#supports?(:transactions)` must respond `false`.
# `#supports?(:atomic_write)` must respond `false`.
#
# @example Executing a read-only transaction
# repository = RDF::Repository.new
Expand Down Expand Up @@ -145,7 +145,11 @@ def initialize(repository, mutable: false, **options, &block)
repository.supports?(:snapshots) ? repository.snapshot : repository
@options = options.dup
@mutable = mutable


raise TransactionError,
'Tried to open a mutable transaction on an immutable repository' if
@mutable && !@repository.mutable?

@changes = RDF::Changeset.new

if block_given?
Expand Down
4 changes: 4 additions & 0 deletions spec/model_graph_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@
it_behaves_like 'an RDF::Queryable'
end

context 'transactions' do
it { require 'pry'; binding.pry }
end

context "Examples" do
let(:graph) {described_class.new}

Expand Down