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: Operations, PayloadStatuses, RecordTypes, Statuses, SyncModes, VersionControl

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



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/orient_db_client/protocols/protocol7.rb', line 74

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

	serialized_command = NetworkMessage.new { |m|
		m.add :string,		options[:query_class_name]
		m.add :string,		command
		m.add :integer,		options[:non_text_limit] || options[:limit]
		m.add :integer,		0
	}.pack

	socket.write NetworkMessage.new { |m|
		m.add :byte, 		Operations::COMMAND
		m.add :integer, 	session
		m.add :byte, 		options[:async] ? 'a' : 's'
		m.add :string,		serialized_command
	}.pack

	read_response(socket)

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

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



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/orient_db_client/protocols/protocol7.rb', line 109

def self.connect(socket, options = {})
	socket.write NetworkMessage.new { |m|
		m.add :byte, 		Operations::CONNECT
		m.add :integer, 	NEW_SESSION
		m.add :string, 		DRIVER_NAME
		m.add :string, 		DRIVER_VERSION
		m.add :short,		self.version
		m.add :integer,		0
		m.add :string, 		options[:user]
		m.add :string, 		options[:password]
	}.pack

	read_response(socket)

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

.count(socket, session, cluster_name) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/orient_db_client/protocols/protocol7.rb', line 127

def self.count(socket, session, cluster_name)
	socket.write NetworkMessage.new { |m|
		m.add :byte, 		Operations::COUNT
		m.add :integer, 	session
		m.add :string, 		cluster_name
	}.pack

	read_response(socket)

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

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



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/orient_db_client/protocols/protocol7.rb', line 140

def self.datacluster_add(socket, session, type, options)
	socket.write NetworkMessage.new { |m|
		type = type.downcase.to_sym if type.is_a?(String)
		type_string = type.to_s.upcase

		m.add :byte, 	Operations::DATACLUSTER_ADD
		m.add :integer,	session
		m.add :string,	type_string

		case type
			when :physical
				m.add :string,	options[:name]
				m.add :string,	options[:file_name]
				m.add :integer,	options[:initial_size] || -1
			when :logical
				m.add :integer,	options[:physical_cluster_container_id]
			when :memory
				m.add :string,	options[:name]
		end
	}.pack

	read_response(socket)

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

.datacluster_datarange(socket, session, cluster_id) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/orient_db_client/protocols/protocol7.rb', line 167

def self.datacluster_datarange(socket, session, cluster_id)
	socket.write NetworkMessage.new { |m|
		m.add :byte, 	Operations::DATACLUSTER_DATARANGE
		m.add :integer,	session
		m.add :short,	cluster_id
	}.pack

	read_response(socket)

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

.datacluster_remove(socket, session, cluster_id) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/orient_db_client/protocols/protocol7.rb', line 180

def self.datacluster_remove(socket, session, cluster_id)
	socket.write NetworkMessage.new { |m|
		m.add :byte, 	Operations::DATACLUSTER_REMOVE
		m.add :integer,	session
		m.add :short,	cluster_id
	}.pack

	read_response(socket)

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

.db_close(socket, session = NEW_SESSION) ⇒ Object



193
194
195
196
197
198
199
200
# File 'lib/orient_db_client/protocols/protocol7.rb', line 193

def self.db_close(socket, session = NEW_SESSION)
	socket.write NetworkMessage.new { |m|
		m.add :byte,	Operations::DB_CLOSE
		m.add :integer,	session
	}.pack

	return socket.closed?
end

.db_countrecords(socket, session) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
# File 'lib/orient_db_client/protocols/protocol7.rb', line 202

def self.db_countrecords(socket, session)
	socket.write NetworkMessage.new { |m|
		m.add :byte,	Operations::DB_COUNTRECORDS
		m.add :integer, session
	}.pack

	read_response(socket)

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

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



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/orient_db_client/protocols/protocol7.rb', line 214

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

	socket.write make_db_create_message(session, database, options).pack

	read_response(socket)

	{ :session => read_integer(socket) }
end

.db_delete(socket, session, database) ⇒ Object



230
231
232
233
234
235
236
237
238
239
240
# File 'lib/orient_db_client/protocols/protocol7.rb', line 230

def self.db_delete(socket, session, database)
	socket.write NetworkMessage.new { |m|
		m.add :byte, 	Operations::DB_DELETE
		m.add :integer,	session
		m.add :string,	database
	}.pack

	read_response(socket)

	{ :session => read_integer(socket) }
end

.db_exist(socket, session, database) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/orient_db_client/protocols/protocol7.rb', line 242

def self.db_exist(socket, session, database)
	socket.write NetworkMessage.new { |m|
		m.add :byte, 	Operations::DB_EXIST
		m.add :integer,	session
		m.add :string,	database
	}.pack

	read_response(socket)

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

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



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/orient_db_client/protocols/protocol7.rb', line 255

def self.db_open(socket, database, options = {})
	socket.write NetworkMessage.new { |m|
		m.add :byte,	Operations::DB_OPEN
		m.add :integer,	NEW_SESSION
		m.add :string, 	DRIVER_NAME
		m.add :string, 	DRIVER_VERSION
		m.add :short,	self.version
		m.add :integer,	0
		m.add :string,	database
		m.add :string, 	options[:user]
		m.add :string,	options[:password]
	}.pack

	read_response(socket)

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

.db_reload(socket, session) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
# File 'lib/orient_db_client/protocols/protocol7.rb', line 274

def self.db_reload(socket, session)
	socket.write NetworkMessage.new { |m|
		m.add :byte,	Operations::DB_RELOAD
		m.add :integer,	session
	}.pack

	read_response(socket)

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

.db_size(socket, session) ⇒ Object



286
287
288
289
290
291
292
293
294
295
296
# File 'lib/orient_db_client/protocols/protocol7.rb', line 286

def self.db_size(socket, session)
	socket.write NetworkMessage.new { |m|
		m.add :byte,	Operations::DB_SIZE
		m.add :integer,	session
	}.pack

	read_response(socket)

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

.deserializerObject



371
372
373
# File 'lib/orient_db_client/protocols/protocol7.rb', line 371

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

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



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/orient_db_client/protocols/protocol7.rb', line 298

def self.record_create(socket, session, cluster_id, record)
	socket.write NetworkMessage.new { |m|
		m.add :byte,	Operations::RECORD_CREATE
		m.add :integer,	session
		m.add :short,	cluster_id
		m.add :string,	serializer.serialize(record)
		m.add :byte,	RecordTypes::DOCUMENT
		m.add :byte,	SyncModes::SYNC
	}.pack

	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



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/orient_db_client/protocols/protocol7.rb', line 314

def self.record_delete(socket, session, cluster_id, cluster_position, version)
	socket.write NetworkMessage.new { |m|
		m.add :byte,	Operations::RECORD_DELETE
		m.add :integer,	session
		m.add :short,	cluster_id
		m.add :long,	cluster_position
		m.add :integer,	version
		m.add :byte,	SyncModes::SYNC
	}.pack

	read_response(socket)

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

.record_load(socket, session, rid) ⇒ Object



330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/orient_db_client/protocols/protocol7.rb', line 330

def self.record_load(socket, session, rid)
	socket.write NetworkMessage.new { |m|
		m.add :byte,	Operations::RECORD_LOAD
		m.add :integer,	session
		m.add :short,	rid.cluster_id
		m.add :long,	rid.cluster_position
		m.add :string,	""
	}.pack

	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



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/orient_db_client/protocols/protocol7.rb', line 345

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

	socket.write NetworkMessage.new { |m|
		m.add :byte,	Operations::RECORD_UPDATE
		m.add :integer,	session
		m.add :short,	cluster_id
		m.add :long,	cluster_position
		m.add :string,	serializer.serialize(record)
		m.add :integer,	version
		m.add :byte,	RecordTypes::DOCUMENT
		m.add :byte,	SyncModes::SYNC
	}.pack

	read_response(socket)

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

.serializerObject



375
376
377
# File 'lib/orient_db_client/protocols/protocol7.rb', line 375

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

.versionObject



379
380
381
# File 'lib/orient_db_client/protocols/protocol7.rb', line 379

def self.version
	self::VERSION
end