orient_db_client 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/orient_db_client/connection.rb +9 -5
- data/lib/orient_db_client/database_session.rb +11 -11
- data/lib/orient_db_client/protocols/protocol7.rb +16 -5
- data/lib/orient_db_client/protocols/protocol9.rb +10 -1
- data/lib/orient_db_client/serializers/serializer7.rb +1 -5
- data/lib/orient_db_client/version.rb +1 -1
- data/lib/orient_db_client.rb +2 -1
- data/test/integration/database_session_9_test.rb +2 -2
- data/test/integration/database_session_test.rb +18 -22
- data/test/unit/serializers/serializer7_test.rb +1 -2
- metadata +2 -8
@@ -36,17 +36,13 @@ module OrientDbClient
|
|
36
36
|
when 'java.lang.IndexOutOfBoundsException', 'java.lang.IllegalArgumentException'
|
37
37
|
result = false
|
38
38
|
else
|
39
|
-
|
39
|
+
raise err
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
result
|
44
44
|
end
|
45
45
|
|
46
|
-
def command(session, text, options = {})
|
47
|
-
@protocol.command(@socket, session, text, options)
|
48
|
-
end
|
49
|
-
|
50
46
|
def count(session, cluster_name)
|
51
47
|
@protocol.count(@socket, session, cluster_name)
|
52
48
|
end
|
@@ -123,6 +119,14 @@ module OrientDbClient
|
|
123
119
|
@sessions[session] = DatabaseSession.new(message_content[:session], self, message_content[:clusters])
|
124
120
|
end
|
125
121
|
|
122
|
+
def query(session, text, options = {})
|
123
|
+
options[:query_class_name] = :query
|
124
|
+
|
125
|
+
result = @protocol.command(@socket, session, text, options)
|
126
|
+
|
127
|
+
result[:message_content]
|
128
|
+
end
|
129
|
+
|
126
130
|
def reload(session)
|
127
131
|
result = @protocol.db_reload(@socket, session)
|
128
132
|
clusters = result[:message_content][:clusters]
|
@@ -18,10 +18,6 @@ module OrientDbClient
|
|
18
18
|
@connection.cluster_exists?(@id, cluster_id)
|
19
19
|
end
|
20
20
|
|
21
|
-
def command(text, options = {})
|
22
|
-
@connection.command(@id, text, options)
|
23
|
-
end
|
24
|
-
|
25
21
|
def count(cluster_name)
|
26
22
|
@connection.count(@id, cluster_name)
|
27
23
|
end
|
@@ -45,12 +41,12 @@ module OrientDbClient
|
|
45
41
|
end
|
46
42
|
|
47
43
|
def delete_record(rid_or_cluster_id, cluster_position_or_version, version = nil)
|
48
|
-
if rid_or_cluster_id.is_a?(
|
49
|
-
rid = OrientDbClient::Rid.new(rid_or_cluster_id, cluster_position)
|
50
|
-
version = version
|
51
|
-
else
|
44
|
+
if rid_or_cluster_id.is_a?(OrientDbClient::Rid)
|
52
45
|
rid = rid_or_cluster_id
|
53
|
-
version = cluster_position_or_version
|
46
|
+
version = cluster_position_or_version.to_i
|
47
|
+
else
|
48
|
+
rid = OrientDbClient::Rid.new(rid_or_cluster_id.to_i, cluster_position_or_version.to_i)
|
49
|
+
version = version
|
54
50
|
end
|
55
51
|
|
56
52
|
@connection.delete_record(@id, rid, version)
|
@@ -76,13 +72,17 @@ module OrientDbClient
|
|
76
72
|
@connection.load_record(@id, rid_or_cluster_id)[:message_content]
|
77
73
|
end
|
78
74
|
|
75
|
+
def query(text, options = {})
|
76
|
+
@connection.query(@id, text, options)
|
77
|
+
end
|
78
|
+
|
79
79
|
def reload
|
80
80
|
@connection.reload(@id)
|
81
81
|
end
|
82
82
|
|
83
|
-
def update_record(record, rid_or_cluster_id, cluster_position_or_version, version =
|
83
|
+
def update_record(record, rid_or_cluster_id, cluster_position_or_version, version = :none)
|
84
84
|
if rid_or_cluster_id.is_a?(Fixnum)
|
85
|
-
rid = OrientDbClient::Rid.new(rid_or_cluster_id,
|
85
|
+
rid = OrientDbClient::Rid.new(rid_or_cluster_id, cluster_position_or_version)
|
86
86
|
version = version
|
87
87
|
else
|
88
88
|
rid = rid_or_cluster_id
|
@@ -66,15 +66,26 @@ module OrientDbClient
|
|
66
66
|
DRIVER_NAME = 'OrientDB Ruby Client'.freeze
|
67
67
|
DRIVER_VERSION = OrientDbClient::VERSION
|
68
68
|
|
69
|
+
COMMAND_CLASS = 'com.orientechnologies.orient.core.sql.OCommandSQL'.freeze
|
70
|
+
QUERY_CLASS = 'com.orientechnologies.orient.core.sql.query.OSQLSynchQuery'.freeze
|
71
|
+
|
69
72
|
NEW_SESSION = -1
|
70
73
|
|
71
74
|
def self.command(socket, session, command, options = {})
|
72
75
|
options = {
|
73
76
|
:async => false, # Async mode is not supported yet
|
74
|
-
:query_class_name =>
|
77
|
+
:query_class_name => QUERY_CLASS,
|
75
78
|
:limit => -1
|
76
79
|
}.merge(options);
|
77
80
|
|
81
|
+
if options[:query_class_name].is_a?(Symbol)
|
82
|
+
options[:query_class_name] = case options[:query_class_name]
|
83
|
+
when :query then QUERY_CLASS
|
84
|
+
when :command then COMMAND_CLASS
|
85
|
+
else raise "Unsupported command class: #{options[:query_class_name]}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
78
89
|
serialized_command = NetworkMessage.new { |m|
|
79
90
|
m.add :string, options[:query_class_name]
|
80
91
|
m.add :string, command
|
@@ -408,7 +419,7 @@ module OrientDbClient
|
|
408
419
|
:record_version => read_integer(socket),
|
409
420
|
:bytes => read_string(socket) })
|
410
421
|
else
|
411
|
-
|
422
|
+
raise "Unsupported record format: #{record[:format]}"
|
412
423
|
end
|
413
424
|
end
|
414
425
|
|
@@ -424,7 +435,7 @@ module OrientDbClient
|
|
424
435
|
result.concat collection
|
425
436
|
break
|
426
437
|
else
|
427
|
-
|
438
|
+
raise "Unsupported payload status: #{status}"
|
428
439
|
end
|
429
440
|
end
|
430
441
|
|
@@ -519,10 +530,10 @@ module OrientDbClient
|
|
519
530
|
result = result || record
|
520
531
|
result[:document] = deserializer.deserialize(record[:bytes])[:document]
|
521
532
|
else
|
522
|
-
|
533
|
+
raise "Unsupported record type: #{record[:record_type]}"
|
523
534
|
end
|
524
535
|
else
|
525
|
-
|
536
|
+
raise "Unsupported payload status: #{status}"
|
526
537
|
end
|
527
538
|
end
|
528
539
|
|
@@ -8,9 +8,18 @@ module OrientDbClient
|
|
8
8
|
|
9
9
|
def self.command(socket, session, command, options = {})
|
10
10
|
options[:query_class_name].tap do |qcn|
|
11
|
+
if qcn.is_a?(Symbol)
|
12
|
+
qcn = case qcn
|
13
|
+
when :query then 'q'
|
14
|
+
when :command then 'c'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
11
18
|
if qcn.nil? || qcn == 'com.orientechnologies.orient.core.sql.query.OSQLSynchQuery'
|
12
|
-
|
19
|
+
qcn = 'q'
|
13
20
|
end
|
21
|
+
|
22
|
+
options[:query_class_name] = qcn
|
14
23
|
end
|
15
24
|
|
16
25
|
super socket, session, command, options
|
@@ -172,11 +172,7 @@ module OrientDbClient
|
|
172
172
|
if value.is_a?(OrientDbClient::Rid)
|
173
173
|
serialize_rid(value)
|
174
174
|
elsif value.is_a?(String)
|
175
|
-
|
176
|
-
serialize_binary(value)
|
177
|
-
else
|
178
|
-
serialize_string(value)
|
179
|
-
end
|
175
|
+
serialize_string(value)
|
180
176
|
elsif value.is_a?(Fixnum)
|
181
177
|
serialize_integer(value)
|
182
178
|
elsif value.is_a?(TrueClass)
|
data/lib/orient_db_client.rb
CHANGED
@@ -26,8 +26,8 @@ class TestDatabaseSession < MiniTest::Unit::TestCase
|
|
26
26
|
refute @connection.closed?
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
result = @session.
|
29
|
+
def test_query
|
30
|
+
result = @session.query("SELECT FROM OUser")
|
31
31
|
|
32
32
|
assert_equal @session.id, result[:session]
|
33
33
|
|
@@ -52,30 +52,26 @@ class TestDatabaseSession < MiniTest::Unit::TestCase
|
|
52
52
|
refute @session.cluster_exists?("OTest")
|
53
53
|
end
|
54
54
|
|
55
|
-
def
|
56
|
-
result = @session.
|
55
|
+
def test_query
|
56
|
+
result = @session.query("SELECT FROM OUser")
|
57
57
|
|
58
|
-
assert_equal
|
58
|
+
assert_equal 3, result.length
|
59
|
+
|
60
|
+
result[0].tap do |record|
|
61
|
+
assert_equal 0, record[:format]
|
62
|
+
assert_equal 4, record[:cluster_id]
|
63
|
+
assert_equal 0, record[:cluster_position]
|
64
|
+
|
65
|
+
record[:document].tap do |doc|
|
66
|
+
assert_equal 'admin', doc['name']
|
67
|
+
assert_equal 'ACTIVE', doc['status']
|
68
|
+
|
69
|
+
doc['roles'].tap do |roles|
|
70
|
+
assert roles.is_a?(Array), "expected Array, but got #{roles.class}"
|
59
71
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
content[0].tap do |record|
|
64
|
-
assert_equal 0, record[:format]
|
65
|
-
assert_equal 4, record[:cluster_id]
|
66
|
-
assert_equal 0, record[:cluster_position]
|
67
|
-
|
68
|
-
record[:document].tap do |doc|
|
69
|
-
assert_equal 'admin', doc['name']
|
70
|
-
assert_equal 'ACTIVE', doc['status']
|
71
|
-
|
72
|
-
doc['roles'].tap do |roles|
|
73
|
-
assert roles.is_a?(Array), "expected Array, but got #{roles.class}"
|
74
|
-
|
75
|
-
assert roles[0].is_a?(OrientDbClient::Rid)
|
76
|
-
assert_equal 3, roles[0].cluster_id
|
77
|
-
assert_equal 0, roles[0].cluster_position
|
78
|
-
end
|
72
|
+
assert roles[0].is_a?(OrientDbClient::Rid)
|
73
|
+
assert_equal 3, roles[0].cluster_id
|
74
|
+
assert_equal 0, roles[0].cluster_position
|
79
75
|
end
|
80
76
|
end
|
81
77
|
end
|
@@ -28,7 +28,6 @@ class TestSerializer7 < MiniTest::Unit::TestCase
|
|
28
28
|
'time' => :time
|
29
29
|
},
|
30
30
|
:document => {
|
31
|
-
'implicit_binary' => "Binary data".encode("ASCII-8BIT"),
|
32
31
|
'implicit_boolean_true' => true,
|
33
32
|
'implicit_boolean_false' => false,
|
34
33
|
'implicit_collection' => [ 3, 7, 14 ],
|
@@ -63,7 +62,7 @@ class TestSerializer7 < MiniTest::Unit::TestCase
|
|
63
62
|
}
|
64
63
|
}
|
65
64
|
|
66
|
-
expected_result = %Q{OClass@
|
65
|
+
expected_result = %Q{OClass@implicit_boolean_true:true,implicit_boolean_false:false,implicit_collection:[3,7,14],implicit_date:1333425600a,implicit_document:(sym_key:\"embedded doc string\"),implicit_double:6.6236d,implicit_integer:15,implicit_long:7345723467317884556l,implicit_map:{\"key1\":\"value1\",\"key2\":\"value2\"},implicit_time:1296279468t,implicit_string:\"a string\",buffer:_RXhwbGljaXQgYmluYXJ5IGRhdGE=_,true:true,false:false,byte:97b,array:[\"Test\",\"Test3\",6,2,#5:1],date_from_time:1339560000a,date_from_string:1339560000a,doc:(integer:735),float:5.6234f,double:2.67234235d,bignum:1l,bigdec:6.2724522625234c,map:{\"key1\":\"Value 1\",\"key_2\":\"Value 2\",\"key_3\":6234},rid:#3:2,short:5s,time:1327417259t,implicit_embedded_documents:[(null_rid:#),(short:16134s)]}
|
67
66
|
|
68
67
|
result = @serializer.serialize(record)
|
69
68
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orient_db_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -123,18 +123,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
-
segments:
|
127
|
-
- 0
|
128
|
-
hash: -4489046239481477100
|
129
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
127
|
none: false
|
131
128
|
requirements:
|
132
129
|
- - ! '>='
|
133
130
|
- !ruby/object:Gem::Version
|
134
131
|
version: '0'
|
135
|
-
segments:
|
136
|
-
- 0
|
137
|
-
hash: -4489046239481477100
|
138
132
|
requirements: []
|
139
133
|
rubyforge_project: orient_db_client
|
140
134
|
rubygems_version: 1.8.21
|