| Class | SemanticRecord::TransactionFactory |
| In: |
lib/semantic_record/transaction_factory.rb
|
| Parent: | REXML::Document |
Builds a transaction document for updates in the store
adds an add-statement to the transaction document
# File lib/semantic_record/transaction_factory.rb, line 51
51: def add_add_statement(s, p, o)
52: add_state = build_element( ADD_STATEMENT )
53: #--
54: # TODO move adding of multiple elements to support/helper
55: #++
56: construct_triples(s,p,o).each do |triple|
57: # add_remove_statement(triple['s'],triple['p'],triple['o'])
58: build_triple(triple['s'],triple['p'],triple['o']).each do |resource|
59: add_state.add(resource)
60: end
61: end
62: self.root.add(add_state)
63: end
adds an remove-statement to the transaction document
# File lib/semantic_record/transaction_factory.rb, line 27
27: def add_remove_statement(s, p, o)
28: remove = build_element( REMOVE_STATEMENT )
29: #--
30: # TODO move adding of multiple elements to support/helper
31: #++
32: construct_triples(s,p,o).each do |triple|
33: # add_remove_statement(triple['s'],triple['p'],triple['o'])
34: build_triple(triple['s'],triple['p'],triple['o']).each do |resource|
35: remove.add(resource)
36: end
37: end
38:
39:
40: # build_triple(s,p,o).each do |resource|
41: # remove.add(resource)
42: # end
43:
44: self.root.add(remove)
45: end
Add a Node calles transaction to the document
# File lib/semantic_record/transaction_factory.rb, line 19
19: def add_transaction_statement
20: self.add( build_element( TRANSACTION_STATEMENT ) )
21: end
if theirs an update the old triple has to be deleted and the new values added to the store
# File lib/semantic_record/transaction_factory.rb, line 66
66: def add_update_statement(s, p, o, new_object)
67: #--
68: # TODO modify for applying changes that effect more than the object
69: #++
70: #construct_triples(s,p,o).each do |triple|
71: add_remove_statement(s, p, o)
72: #end
73: #construct_triples(s,p,new_object).each do |triple|
74: add_add_statement(s, p, new_object)
75: #end
76:
77: #raise self.to_s.inspect
78: end
If the value of an object ist a literal build a literal-node
# File lib/semantic_record/transaction_factory.rb, line 126
126: def build_literal_element(value)
127: #--
128: # TODO make me pretty
129: #++
130: b = build_element( LITERAL_STATEMENT )
131: b.text=(value)
132: return b
133: end
creates a triple that could be added to the transaction document
# File lib/semantic_record/transaction_factory.rb, line 93
93: def build_triple(s, p, o)
94: returning [] do |triple|
95: #raise s.inspect
96:
97: # ugly!!! first should not called directly
98: [s,p,o].each do |resource|
99: #--
100: # FIXME if handling of properties ever changes (resource.type == URI)
101: #++
102:
103:
104: if resource =~ /http:\/\//
105: triple << build_uri_element(resource)
106: elsif resource.nil?
107: triple << build_element( NULL )
108: else
109: triple << build_literal_element(resource)
110: end
111: end
112: end
113: end
If the value of a object is uri then build a uri-node
# File lib/semantic_record/transaction_factory.rb, line 116
116: def build_uri_element(value)
117: #--
118: # TODO make me pretty
119: #++
120: b = build_element( URI_STATEMENT )
121: b.text=(value)
122: return b
123: end