lib/rest/create.rb
Creates a Record in the Database and returns this as ActiveOrient::Model-Instance

Creates a Record with the attributes provided in the attributes-hash e.g.
   create_record @classname, attributes: {con_id: 343, symbol: 'EWTZ'}

Puts the database-response into the cache by default


Creates a Record in the Database and returns this as ActiveOrient::Model-Instance
Creates a Record with the attributes provided in the attributes-hash e.g.
create_record @classname, attributes: {con_id: 343, symbol: 'EWTZ'}

Puts the database-response into the cache by default
Creates a Record in the Database and returns this as ActiveOrient :: Model - Instance Creates a Record with the attributes provided in the attributes - hash e . g . create_record @classname attributes : { con_id : 343 symbol : ' EWTZ ' } Puts the database - response into the cache by default
def create_record o_class, attributes: {}, cache: true    
    logger.progname = 'RestCreate#CreateRecord'
    attributes = yield if attributes.empty? && block_given?
    post_argument = {'@class' => classname(o_class)}.merge(attributes.to_orient)
    begin
      response = @res["/document/#{ActiveOrient.database}"].post post_argument.to_json
      data = JSON.parse(response.body)
      the_object = ActiveOrient::Model.orientdb_class(name: data['@class']).new data 
      if cache 
	  ActiveOrient::Base.store_rid( the_object ) 
      else
	the_object
      end
    rescue RestClient::InternalServerError => e
      sentence=  JSON.parse( e.response)['errors'].last['content']
      if sentence =~ /found duplicated key/
	rid = sentence.split("#").last
	logger.info{ "found duplicated Key --> loaded #{rid} instead of creating "}
	get_record rid
      else
	response = JSON.parse(e.response)['errors'].pop
	logger.error{response['content'].split(':')[1..-1].join(':')}
	logger.error{"No Object allocated"}
	nil 
       end
    rescue Errno::EADDRNOTAVAIL => e
      sleep(2)
      retry
    end
  end
def create_record o_class , attributes : { } , cache : true logger . progname = 'RestCreate#CreateRecord' attributes = yield if attributes . empty? && block_given? post_argument = { '@class' => classname ( o_class ) } . merge ( attributes . to_orient ) begin response = @res [ "/document/#{ActiveOrient.database}" ] . post post_argument . to_json data = JSON . parse ( response . body ) the_object = ActiveOrient :: Model . orientdb_class ( name : data [ '@class' ] ) . new data if cache ActiveOrient :: Base . store_rid ( the_object ) else the_object end rescue RestClient :: InternalServerError => e sentence = JSON . parse ( e . response ) [ 'errors' ] . last [ 'content' ] if sentence =~ / found duplicated key / rid = sentence . split ( "#" ) . last logger . info { "found duplicated Key --> loaded #{rid} instead of creating " } get_record rid else response = JSON . parse ( e . response ) [ 'errors' ] . pop logger . error { response [ 'content' ] . split ( ':' ) [ 1 .. - 1 ] . join ( ':' ) } logger . error { "No Object allocated" } nil end rescue Errno :: EADDRNOTAVAIL => e sleep ( 2 ) retry end end
Creates a Record in the Database and returns this as ActiveOrient::Model-Instance
Creates a Record with the attributes provided in the attributes-hash e.g.
Creates a Record in the Database and returns this as ActiveOrient :: Model - Instance Creates a Record with the attributes provided in the attributes - hash e . g .
# use Model#create instead # @class must not quoted! Quote only attributes(strings) ## return_value #      puts sentence.to_s ## reading database content -- maybe update attributes? # return_value
o_class
<not_specific>
attributes
<not_specific>
cache
<not_specific>