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, #manage_transaction, #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

#as, #compose_where, #generate_sql_list, #where, #while_s

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



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

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 }
			# setup connection pool
			# database-settings: client.channel.maxPool = 100
			ActiveOrient.db_pool ||= Pond.new( :maximum_size => 25, :timeout => 50) {  get_resource }
#			ActiveOrient.db_pool.collection = :stack
  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
			Thread.abort_on_exception = true
end

Instance Method Details

#connectObject

Used to connect to the database



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rest/rest.rb', line 93

def connect 
	first_tentative = true
	begin
		database =  ActiveOrient.database
		logger.progname = 'OrientDB#Connect'
		r = ActiveOrient.db_pool.checkout do | conn |
			r = conn["/connect/#{database}"].get
		end
		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

thread safe method to allocate a resource



82
83
84
85
86
87
# File 'lib/rest/rest.rb', line 82

def get_resource
			logger.debug {"ALLOCATING NEW RESOURCE --> #{ ActiveOrient.db_pool.size }" }
   = [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