lib/rest/change.rb in active-orient-0.79 vs lib/rest/change.rb in active-orient-0.80

- old
+ new

@@ -29,10 +29,11 @@ =end def update record, attributes , version=0 r = ActiveOrient::Model.autoload_object record.rid return(false) unless r.is_a?(ActiveOrient::Model) + raise "Cannot update the record, version-information missing. please reload ! " if version.nil? version = r.version if version.zero? result = patch_record(r.rid) do attributes.merge({'@version' => version, '@class' => r.class.ref_name }) end # returns a new instance of ActiveOrient::Model and updates any reference on rid @@ -80,24 +81,31 @@ # Lazy Updating of the given Record. # internal using while updating records def patch_record rid # :nodoc: (used by #update ) logger.progname = 'RestChange#PatchRecord' content = yield - if content.is_a? Hash - begin - @res["/document/#{ActiveOrient.database}/#{rid}"].patch content.to_orient.to_json - rescue RestClient::InternalServerError => e - sentence= JSON.parse( e.response)['errors'].last['content'] - logger.error{sentence} - logger.error{ e.backtrace.map {|l| " #{l}\n"}.join } - logger.error{e.message.to_s} - end - else - logger.error{"PATCH FAILED: The Block must provide an Hash with properties to be updated"} - end - end - alias patch_document patch_record + if content.is_a? Hash + begin + ActiveOrient.db_pool.checkout do | conn | + conn["/document/#{ActiveOrient.database}/#{rid}"].patch content.to_orient.to_json + end + rescue RestClient::Conflict => e # (409) + # most probably the server is busy. we wait for a second print an Error-Message and retry + sleep(1) + logger.error{ "RestClient::Error(409): Server is signaling a conflict ... retrying" } + retry + rescue RestClient::InternalServerError => e + sentence= JSON.parse( e.response)['errors'].last['content'] + logger.error{sentence} + logger.error{ e.backtrace.map {|l| " #{l}\n"}.join } + logger.error{e.message.to_s} + end + else + logger.error{"PATCH FAILED: The Block must provide an Hash with properties to be updated"} + end + end + alias patch_document patch_record #### EXPERIMENTAL ########## =begin @@ -130,15 +138,10 @@ else logger.error{"Wrong attribute."} return 0 end - name_class = classname(o_class) - execute name_class, transaction: false do # To execute commands - [{ type: "cmd", - language: 'sql', - command: "ALTER PROPERTY #{name_class}.#{property} #{attribute} #{alteration}"}] - end + execute { "ALTER PROPERTY #{class_name(o_class)}.#{property} #{attribute} #{alteration}"} rescue Exception => e logger.error{e.message} end end