Class: E

Inherits:
ActiveOrient::Model show all
Defined in:
lib/model/edge.rb

Constant Summary

Constants included from OrientDB

OrientDB::DocumentDatabase, OrientDB::DocumentDatabasePool, OrientDB::DocumentDatabasePooled, OrientDB::GraphDatabase, OrientDB::IndexType, OrientDB::OClassImpl, OrientDB::OTraverse, OrientDB::PropertyImpl, OrientDB::RemoteStorage, OrientDB::SQLCommand, OrientDB::SQLSynchQuery, OrientDB::Schema, OrientDB::SchemaProxy, OrientDB::SchemaType, OrientDB::ServerAdmin, OrientDB::User, OrientDB::UsingJava

Instance Attribute Summary

Attributes inherited from ActiveOrient::Model

#metadata

Attributes inherited from ActiveOrient::Base

#metadata

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveOrient::Model

_to_partial_path, autoload_object, delete_class, #document, #persisted?, #to_ary, to_or, use_or_allocate

Methods included from ModelClass

#add_edge_link, #all, #alter_property, #classname, #count, #create, #create_class, #create_index, #create_properties, #create_property, #custom_where, #delete_property, #delete_record, #delete_records, #first, #get, #get_records, #indexes, #last, #link_list, #match, #namespace_prefix, #naming_convention, #orientdb_class, #print_properties, #properties, #query_database, #require_model_file, #update_all, #upsert, #where

Methods included from OrientSupport::Support

#compose_where, #generate_sql_list

Methods included from CustomClass

#like

Methods included from ActiveOrient::BaseProperties

#==, #content_attributes, #default_attributes, #embedded, #set_attribute_defaults, #update_missing

Methods inherited from ActiveOrient::Base

#[], #[]=, attr_accessible, attr_protected, #attributes, #attributes=, belongs_to, display_rid, exclude_the_following_properties, get_rid, has_many, has_one, #included_links, #initialize, #my_metadata, remove_rid, reset_rid_store, serialize, store_rid, #to_model, #update_attribute

Constructor Details

This class inherits a constructor from ActiveOrient::Base

Class Method Details

.create(from:, to:, set: {}, transaction: false, update_cache: false, **attributes) ⇒ Object

Instantiate a new Edge between two Vertices

Properties can be placed using the :set-directive or simply by adding key: value- parameter-pairs

if the creation of an edged is not possible, due to constrains (uniq_index), the already
connecting edge is returned

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/model/edge.rb', line 25

def create from:, to: , set: {}, transaction:  false, update_cache: false, **attributes
return nil if from.blank? || to.blank?
set.merge!(attributes) 
content =  set.empty? ? "" : "content #{set.to_orient.to_json}" 
statement = "CREATE EDGE #{ref_name} from #{from.to_or} to #{to.to_or} #{content}"
transaction = true if [:fire, :complete, :run].include?(transaction)
ir= db.execute( transaction: transaction, process_error: false ){ statement  }
if update_cache
	from.reload! # get last version 
	to.is_a?(Array)? to.each( &:reload! )  : to.reload!
end
to.is_a?(Array)  ? ir : ir.first   # return the plain edge, if only one is created
	rescue RestClient::InternalServerError => e
sentence=  JSON.parse( e.response)['errors'].last['content']
if sentence =~ /found duplicated key/
	ref_rid =  sentence.split.last.expand  # return expanded rid
else
	raise
end
	rescue ArgumentError => e
logger.error{ "wrong parameters  #{keyword_arguments} \n\t\t required: from: , to: , attributes:\n\t\t Edge is NOT created"}
end

.delete(where:) ⇒ Object

Fires a “delete edge” command to the database.

The where statement can be empty ( “” or {}“), then all edges are removed

The rid-cache is resetted

to_do: Implement :all=> true directive

     support from: , to: syntax

:call-seq:
delete where:

62
63
64
65
66
67
# File 'lib/model/edge.rb', line 62

def delete where:  

  db.execute { "delete edge #{ref_name} #{db.compose_where(where)}" }
  reset_rid_store

end

.uniq_indexObject

Establish constrains on Edges

After applying this method Edges are uniq!

Creates individual indices for child-classes if applied to the class itself.


11
12
13
14
15
# File 'lib/model/edge.rb', line 11

def  uniq_index
  create_property  :in,  type: :link, linked_class: :V
  create_property  :out, type: :link, linked_class: :V
  create_index "#{ref_name}_idx", on: [ :in, :out ]
end

Instance Method Details

#deleteObject

Deletes the actual ActiveOrient::Model-Edge-Object


78
79
80
# File 'lib/model/edge.rb', line 78

def delete
	db.execute{ "delete edge #{ref_name} #{rrid}" }
end

#to_humanObject


81
82
83
84
# File 'lib/model/edge.rb', line 81

def to_human
	displayed_attributes =  content_attributes.reject{|k,_| [:in, :out].include?(k) }
	"<#{self.class.to_s.demodulize}[#{rrid}] -i-> ##{ attributes[:in].rid} #{displayed_attributes.to_human} -o-> #{out.rrid}>"
end