Class | Foxen::TransactionFactory |
In: |
lib/semantic_record/foxen.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/foxen.rb, line 48 48: def add_add_statement(s, p, o) 49: add_state = build_element( ADD_STATEMENT ) 50: #-- 51: # TODO move adding of multiple elements to support/helper 52: #++ 53: build_triple(s,p,o).each do |resource| 54: add_state.add(resource) 55: end 56: self.root.add(add_state) 57: end
adds an remove-statement to the transaction document
# File lib/semantic_record/foxen.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: build_triple(s,p,o).each do |resource| 33: remove.add(resource) 34: end 35: 36: 37: # build_triple(s,p,o).each do |resource| 38: # remove.add(resource) 39: # end 40: 41: self.root.add(remove) 42: end
Add a Node calles transaction to the document
# File lib/semantic_record/foxen.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/foxen.rb, line 60 60: def add_update_statement(s, p, o, new_object) 61: #-- 62: # TODO modify for applying changes that effect more than the object 63: #++ 64: #construct_triples(s,p,o).each do |triple| 65: add_remove_statement(s, p, o) 66: #end 67: #construct_triples(s,p,new_object).each do |triple| 68: add_add_statement(s, p, new_object) 69: #end 70: 71: #raise self.to_s.inspect 72: end
If the value of an object ist a literal build a literal-node
# File lib/semantic_record/foxen.rb, line 120 120: def build_literal_element(value) 121: #-- 122: # TODO make me pretty 123: #++ 124: b = build_element( LITERAL_STATEMENT ) 125: b.text=(value) 126: return b 127: end
creates a triple that could be added to the transaction document
# File lib/semantic_record/foxen.rb, line 87 87: def build_triple(s, p, o) 88: returning [] do |triple| 89: #raise s.inspect 90: 91: # ugly!!! first should not called directly 92: [s,p,o].each do |resource| 93: #-- 94: # FIXME if handling of properties ever changes (resource.type == URI) 95: #++ 96: 97: 98: if resource =~ /http:\/\// 99: triple << build_uri_element(resource) 100: elsif resource.nil? 101: triple << build_element( NULL ) 102: else 103: triple << build_literal_element(resource) 104: end 105: end 106: end 107: end
If the value of a object is uri then build a uri-node
# File lib/semantic_record/foxen.rb, line 110 110: def build_uri_element(value) 111: #-- 112: # TODO make me pretty 113: #++ 114: b = build_element( URI_STATEMENT ) 115: b.text=(value) 116: return b 117: end