Class: ActiveOrient::OrientDB

Overview

OrientDB points to an OrientDB-Database. The communication is based on the OrientDB-REST-API.

Its usually initialised through ActiveOrient::Init.connect

Instance Method Summary collapse

Methods included from RestDelete

#delete_class, #delete_database, #delete_property, #delete_record, #delete_records

Methods included from RestOperations

#_execute, #call_function, #count, #execute, #read_transaction

Methods included from RestChange

#alter_property, #change_database, #patch_record, #update, #update_records

Methods included from RestCreate

#create_database, #create_index, #create_properties, #create_property, #create_record, #upsert

Methods included from RestRead

#get_class_properties, #get_classes, #get_databases, #get_record, #get_records, #print_class_properties

Methods included from ClassUtils

#allocate_class_in_ruby, #classname, #create_class, #create_edge_class, #create_vertex_class, #delete_edge

Methods included from DatabaseUtils

#class_hierarchy, #database_classes, #get_db_superclass, #preallocate_classes, #system_classes

Methods included from OrientSupport::Logging

included

Methods included from OrientSupport::Support

#compose_where, #generate_sql_list

Constructor Details

#initialize(database: nil, preallocate: true, model_dir: nil, **defaults) ⇒ OrientDB

OrientDB is conventionally initialized.

The first call initialises database-name and -classes, server-adress and user-credentials.

Subsequent initialisations are made to initialise namespaced database classes, ie.

ORD = ActiveOrient.init.connect database: 'temp' server: 'localhost', port: 2480, user: root, password: root module HC; end ActiveOrient::Init.define_namespace { HC } ActiveOrient::OrientDB.new preallocate: true


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rest/rest.rb', line 58

def initialize database: nil, preallocate: true, model_dir: nil, **defaults
  ActiveOrient.database ||= database || 'temp'
  ActiveOrient.database_classes ||=   Hash.new

			ActiveOrient.default_server ||= { :server => defaults[:server] || 'localhost' ,
																:port   => defaults[:port] ||= 2480,
																:user   => defaults[:user].to_s ,
																:password => defaults[:password].to_s }

  @res = get_resource 
  connect() 
  database_classes # initialize @classes-array and ActiveOrient.database_classes 
			ActiveOrient::Base.logger =  logger
  ActiveOrient::Model.orientdb = self 
  ActiveOrient::Model.db = self 
  ActiveOrient::Model.keep_models_without_file ||= nil
  preallocate_classes( model_dir )  if preallocate

end

Instance Method Details

#connectObject

Used to connect to the database


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rest/rest.rb', line 86

def connect
  first_tentative = true
  begin
database =  ActiveOrient.database
    logger.progname = 'OrientDB#Connect'
    r = @res["/connect/#{database}"].get
    if r.code == 204
     logger.info{"Connected to database #{database}"}
     true
   else
     logger.error{"Connection to database #{database} could NOT be established"}
     nil
   end
  rescue RestClient::Unauthorized => e
    if first_tentative
     logger.info{"Database #{database} NOT present --> creating"}
     first_tentative = false
     create_database database: database
     retry
    else
     Kernel.exit
    end
  end
end

#get_resourceObject


78
79
80
81
82
# File 'lib/rest/rest.rb', line 78

def get_resource
   = [ActiveOrient.default_server[:user] , ActiveOrient.default_server[:password]]
  server_adress = "http://#{ActiveOrient.default_server[:server]}:#{ActiveOrient.default_server[:port]}"
  RestClient::Resource.new(server_adress, *)
end