Class: OrientDbClient::Protocols::Protocol7

Inherits:
Object
  • Object
show all
Defined in:
lib/orient_db_client/protocols/protocol7.rb

Direct Known Subclasses

Protocol9

Defined Under Namespace

Modules: Commands, Operations, PayloadStatuses, RecordTypes, Statuses, SyncModes, VersionControl Classes: ProtocolString, QueryMessage

Constant Summary collapse

VERSION =
7
DRIVER_NAME =
'OrientDB Ruby Client'.freeze
DRIVER_VERSION =
OrientDbClient::VERSION
COMMAND_CLASS =
'com.orientechnologies.orient.core.sql.OCommandSQL'.freeze
QUERY_CLASS =
'com.orientechnologies.orient.core.sql.query.OSQLSynchQuery'.freeze
NEW_SESSION =
-1

Class Method Summary collapse

Class Method Details

.command(socket, session, command, options = {}) ⇒ Object



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/orient_db_client/protocols/protocol7.rb', line 297

def self.command(socket, session, command, options = {})
	options = {
		:async =>				false,	# Async mode is not supported yet
		:query_class_name => QUERY_CLASS,
		:limit =>				-1
	}.merge(options);

	if options[:query_class_name].is_a?(Symbol)
		options[:query_class_name] = case options[:query_class_name]
			when :query then QUERY_CLASS
			when :command then COMMAND_CLASS
			else raise "Unsupported command class: #{options[:query_class_name]}"
		end
	end

	query = QueryMessage.new :query_class_name => options[:query_class_name],
													 :text => command,
													 :non_text_limit => options[:non_text_limit] || options[:limit]

	command = Commands::Command.new :session => session,
																	:mode => options[:async] ? 'a'.ord : 's'.ord,
																	:command_serialized => query.to_binary_s

	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content 	=> read_command(socket) }
end

.connect(socket, options = {}) ⇒ Object



328
329
330
331
332
333
334
335
336
337
338
# File 'lib/orient_db_client/protocols/protocol7.rb', line 328

def self.connect(socket, options = {})
	command = Commands::Connect.new :version => self.version,
																	:user => options[:user],
																	:password => options[:password]
	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content 	=> read_connect(socket) }
end

.count(socket, session, cluster_name) ⇒ Object



340
341
342
343
344
345
346
347
348
349
350
# File 'lib/orient_db_client/protocols/protocol7.rb', line 340

def self.count(socket, session, cluster_name)
	command = Commands::Count.new :session => session,
																	:cluster_name => cluster_name

	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content 	=> read_count(socket) }
end

.datacluster_add(socket, session, type, options) ⇒ Object



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/orient_db_client/protocols/protocol7.rb', line 352

def self.datacluster_add(socket, session, type, options)
	type = type.downcase.to_sym if type.is_a?(String)

	case type
	when :physical
		command = Commands::DataclusterAddPhysical.new :session => session,
																									 :name => options[:name],
																									 :file_name => options[:file_name],
																									 :initial_size => options[:initial_size] || -1
	when :logical
		command = Commands::DataclusterAddLogical.new :session => session,
																									:physical_cluster_container_id => options[:physical_cluster_container_id]
	when :memory
		command = Commands::DataclusterAddMemory.new :session => session,
																								 :name => options[:name]
	end

	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content 	=> read_datacluster_add(socket) }
end

.datacluster_datarange(socket, session, cluster_id) ⇒ Object



377
378
379
380
381
382
383
384
385
386
387
# File 'lib/orient_db_client/protocols/protocol7.rb', line 377

def self.datacluster_datarange(socket, session, cluster_id)
	command = Commands::DataclusterDatarange.new :session => session,
																							 :cluster_id => cluster_id

	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content 	=> read_datacluster_datarange(socket) }
end

.datacluster_remove(socket, session, cluster_id) ⇒ Object



389
390
391
392
393
394
395
396
397
398
# File 'lib/orient_db_client/protocols/protocol7.rb', line 389

def self.datacluster_remove(socket, session, cluster_id)
	command = Commands::DataclusterRemove.new :session => session,
																							 :cluster_id => cluster_id
	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content 	=> read_datacluster_remove(socket) }
end

.db_close(socket, session = NEW_SESSION) ⇒ Object



400
401
402
403
404
405
# File 'lib/orient_db_client/protocols/protocol7.rb', line 400

def self.db_close(socket, session = NEW_SESSION)
	command = Commands::DbClose.new :session => session
	command.write(socket)

	return socket.closed?
end

.db_countrecords(socket, session) ⇒ Object



407
408
409
410
411
412
413
414
415
# File 'lib/orient_db_client/protocols/protocol7.rb', line 407

def self.db_countrecords(socket, session)
	command = Commands::DbCountRecords.new :session => session
	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content 	=> read_db_countrecords(socket) }
end

.db_create(socket, session, database, options = {}) ⇒ Object



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# File 'lib/orient_db_client/protocols/protocol7.rb', line 417

def self.db_create(socket, session, database, options = {})
     if options.is_a?(String) || options.is_a?(Symbol)
         options = { :storage_type => options }
     end

     options = { :storage_type => 'local' }.merge(options)

     options[:storage_type] = options[:storage_type].to_s

	make_db_create_command(session, database, options).write(socket)

	read_response(socket)

	{ :session => read_integer(socket) }
end

.db_delete(socket, session, database) ⇒ Object



433
434
435
436
437
438
439
440
441
# File 'lib/orient_db_client/protocols/protocol7.rb', line 433

def self.db_delete(socket, session, database)
	command = Commands::DbDelete.new :session => session,
																				 :database => database
	command.write(socket)

	read_response(socket)

	{ :session => read_integer(socket) }
end

.db_exist(socket, session, database) ⇒ Object



443
444
445
446
447
448
449
450
451
452
# File 'lib/orient_db_client/protocols/protocol7.rb', line 443

def self.db_exist(socket, session, database)
	command = Commands::DbExist.new :session => session,
																	 :database => database
	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content 	=> read_db_exist(socket) }
end

.db_open(socket, database, options = {}) ⇒ Object



454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/orient_db_client/protocols/protocol7.rb', line 454

def self.db_open(socket, database, options = {})
	command = Commands::DbOpen.new :version => self.version,
																 :database => database,
																 :user => options[:user],
																 :password => options[:password]
	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content 	=> read_db_open(socket)	}
end

.db_reload(socket, session) ⇒ Object



467
468
469
470
471
472
473
474
475
# File 'lib/orient_db_client/protocols/protocol7.rb', line 467

def self.db_reload(socket, session)
	command = Commands::DbReload.new :session => session
	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content 	=> read_db_reload(socket)	}
end

.db_size(socket, session) ⇒ Object



477
478
479
480
481
482
483
484
485
# File 'lib/orient_db_client/protocols/protocol7.rb', line 477

def self.db_size(socket, session)
	command = Commands::DbSize.new :session => session
	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content 	=> read_db_size(socket) }
end

.deserializerObject



546
547
548
# File 'lib/orient_db_client/protocols/protocol7.rb', line 546

def self.deserializer
	return OrientDbClient::Deserializers::Deserializer7.new
end

.record_create(socket, session, cluster_id, record) ⇒ Object



487
488
489
490
491
492
493
494
495
496
497
# File 'lib/orient_db_client/protocols/protocol7.rb', line 487

def self.record_create(socket, session, cluster_id, record)
	command = Commands::RecordCreate.new :session => session,
																			 :cluster_id => cluster_id,
																			 :record_content => serializer.serialize(record)
	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content	=> read_record_create(socket).merge({ :cluster_id => cluster_id }) }
end

.record_delete(socket, session, cluster_id, cluster_position, version) ⇒ Object



499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/orient_db_client/protocols/protocol7.rb', line 499

def self.record_delete(socket, session, cluster_id, cluster_position, version)
	command = Commands::RecordDelete.new :session => session,
																			 :cluster_id => cluster_id,
																			 :cluster_position => cluster_position,
																			 :record_version => version
	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content	=> read_record_delete(socket) }
end

.record_load(socket, session, rid) ⇒ Object



512
513
514
515
516
517
518
519
520
521
522
# File 'lib/orient_db_client/protocols/protocol7.rb', line 512

def self.record_load(socket, session, rid)
	command = Commands::RecordLoad.new :session => session,
																		 :cluster_id => rid.cluster_id,
																		 :cluster_position => rid.cluster_position
	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content 	=> read_record_load(socket) }
end

.record_update(socket, session, cluster_id, cluster_position, record, version = VersionControl::NONE) ⇒ Object



524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/orient_db_client/protocols/protocol7.rb', line 524

def self.record_update(socket, session, cluster_id, cluster_position, record, version = VersionControl::NONE)
	if version.is_a?(Symbol)
		version = case version
			when :none then VersionControl::NONE
			when :incremental then VersionControl::INCREMENTAL
			else VersionControl::NONE
		end
	end

	command = Commands::RecordUpdate.new :session => session,
																		 :cluster_id => cluster_id,
																		 :cluster_position => cluster_position,
																		 :record_content => serializer.serialize(record),
																		 :record_version => version
	command.write(socket)

	read_response(socket)

	{ :session 			=> read_integer(socket),
	  :message_content	=> read_record_update(socket) }
end

.serializerObject



550
551
552
# File 'lib/orient_db_client/protocols/protocol7.rb', line 550

def self.serializer
	return OrientDbClient::Serializers::Serializer7.new
end

.versionObject



554
555
556
# File 'lib/orient_db_client/protocols/protocol7.rb', line 554

def self.version
	self::VERSION
end