lib/rest/operations.rb in active-orient-0.5 vs lib/rest/operations.rb in active-orient-0.6

- old
+ new

@@ -22,36 +22,42 @@ query.projection << 'COUNT (*)' result = get_records raw: true, query: query result.first['COUNT'] rescue 0 # return_value end - - def manipulate_relation record, method, array, items # :nodoc: # - execute_array = Array.new - method = method.to_s.upcase - - add_2_execute_array = -> (it) do - command = "UPDATE ##{record.rid} #{method} #{array} = #{it.to_orient } " #updating}" - command.gsub!(/\"/,"") if it.is_a? Array - #puts "COMMAND:: #{command}" - execute_array << {type: "cmd", language: "sql", command: command} - end - - items.each{|x| add_2_execute_array[x] } - r= execute{ execute_array } - - if r.present? - case method - when 'ADD' - items.each{|x| record.attributes[array] << x} - when 'REMOVE' - items.map{|x| record.attributes[array].delete x.is_a?(ActiveOrient::Model) ? x.rid : x} - else - end - record.increment_version - end - end +## historic method +# def manipulate_relation record, method, array, items # :nodoc: # +# execute_array = Array.new +# method = method.to_s.upcase +# +# add_2_execute_array = -> (it) do +# command = "UPDATE ##{record.rid} #{method} #{array} = #{it.to_or } " #updating}" +# command.gsub!(/\"/,"") if it.is_a? Array +# puts "COMMAND:: #{command}" +# execute_array << {type: "cmd", language: "sql", command: command} +# end +# +# items.to_a.each{|x| add_2_execute_array[x] } +## puts "******************" +## puts record.inspect +## puts "-----" +## puts execute_array.join('\n') +# r= execute{ execute_array } +# puts record.inspect +# puts r.inspect +## puts "******************" +# if r.present? +# case method +# when 'ADD' +# items.each{|x| record.attributes[array] << x} +# when 'REMOVE' +# items.map{|x| record.attributes[array].delete x} +# else +# end +# record.increment_version +# end +# end =begin Executes a list of commands and returns the result-array (if present) (External use) @@ -88,10 +94,11 @@ =end def execute transaction: true, tolerated_error_code: nil, process_error: true, raw: nil # Set up for classes batch = {transaction: transaction, operations: yield} logger.progname= "Execute" +# puts "batch: #{batch[:operations]}" unless batch[:operations].blank? batch[:operations] = {:type=>"cmd", :language=>"sql", :command=> batch[:operations]} if batch[:operations].is_a? String batch[:operations] = [batch[:operations]] unless batch[:operations].is_a? Array batch[:operations].compact! # transaction is true only for multible statements @@ -120,13 +127,16 @@ # logger.error{e.message.to_s} else raise end end + rescue Errno::EADDRNOTAVAIL => e + sleep(2) + retry end if response.present? && response.code == 200 if response.body['result'].present? - result= JSON.parse(response.body)['result'] + result=JSON.parse(response.body)['result'] return result if raw.present? result.map do |x| if x.is_a? Hash if x.has_key?('@class') ActiveOrient::Model.orientdb_class(name: x['@class'], superclass: :find_ME ).new x