orientdb-binary 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile +5 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +64 -0
  7. data/lib/orientdb_binary.rb +25 -0
  8. data/lib/orientdb_binary/base.rb +40 -0
  9. data/lib/orientdb_binary/config.rb +5 -0
  10. data/lib/orientdb_binary/connection.rb +17 -0
  11. data/lib/orientdb_binary/database.rb +24 -0
  12. data/lib/orientdb_binary/database_operations/base_operations.rb +70 -0
  13. data/lib/orientdb_binary/database_operations/data_cluster.rb +116 -0
  14. data/lib/orientdb_binary/database_operations/data_segment.rb +31 -0
  15. data/lib/orientdb_binary/database_operations/query.rb +58 -0
  16. data/lib/orientdb_binary/database_operations/record.rb +105 -0
  17. data/lib/orientdb_binary/database_operations/transaction.rb +8 -0
  18. data/lib/orientdb_binary/operation_types.rb +51 -0
  19. data/lib/orientdb_binary/parser/deserializer.rb +161 -0
  20. data/lib/orientdb_binary/parser/serializer.rb +83 -0
  21. data/lib/orientdb_binary/protocols/base.rb +42 -0
  22. data/lib/orientdb_binary/protocols/bindata_primitives.rb +46 -0
  23. data/lib/orientdb_binary/protocols/command.rb +166 -0
  24. data/lib/orientdb_binary/protocols/config_get.rb +22 -0
  25. data/lib/orientdb_binary/protocols/config_list.rb +24 -0
  26. data/lib/orientdb_binary/protocols/config_set.rb +22 -0
  27. data/lib/orientdb_binary/protocols/connect.rb +26 -0
  28. data/lib/orientdb_binary/protocols/datacluster_add.rb +26 -0
  29. data/lib/orientdb_binary/protocols/datacluster_count.rb +26 -0
  30. data/lib/orientdb_binary/protocols/datacluster_datarange.rb +23 -0
  31. data/lib/orientdb_binary/protocols/datacluster_drop.rb +22 -0
  32. data/lib/orientdb_binary/protocols/datacluster_lh_cluster_is_used.rb +20 -0
  33. data/lib/orientdb_binary/protocols/datasegment_add.rb +24 -0
  34. data/lib/orientdb_binary/protocols/datasegment_drop.rb +23 -0
  35. data/lib/orientdb_binary/protocols/db_close.rb +16 -0
  36. data/lib/orientdb_binary/protocols/db_countrecords.rb +20 -0
  37. data/lib/orientdb_binary/protocols/db_create.rb +23 -0
  38. data/lib/orientdb_binary/protocols/db_drop.rb +22 -0
  39. data/lib/orientdb_binary/protocols/db_exist.rb +23 -0
  40. data/lib/orientdb_binary/protocols/db_freeze.rb +21 -0
  41. data/lib/orientdb_binary/protocols/db_list.rb +26 -0
  42. data/lib/orientdb_binary/protocols/db_open.rb +43 -0
  43. data/lib/orientdb_binary/protocols/db_release.rb +21 -0
  44. data/lib/orientdb_binary/protocols/db_reload.rb +26 -0
  45. data/lib/orientdb_binary/protocols/db_size.rb +20 -0
  46. data/lib/orientdb_binary/protocols/errors.rb +28 -0
  47. data/lib/orientdb_binary/protocols/record_create.rb +35 -0
  48. data/lib/orientdb_binary/protocols/record_delete.rb +25 -0
  49. data/lib/orientdb_binary/protocols/record_load.rb +65 -0
  50. data/lib/orientdb_binary/protocols/record_update.rb +27 -0
  51. data/lib/orientdb_binary/protocols/shutdown.rb +21 -0
  52. data/lib/orientdb_binary/server.rb +71 -0
  53. data/orientdb-binary.gemspec +26 -0
  54. data/test/database/test_database.rb +193 -0
  55. data/test/database/test_deserializer.rb +140 -0
  56. data/test/database/test_serializer.rb +55 -0
  57. data/test/server/test_server.rb +73 -0
  58. data/test/test_helper.rb +9 -0
  59. metadata +162 -0
@@ -0,0 +1,42 @@
1
+ module OrientdbBinary
2
+ module Protocols
3
+
4
+ module Base
5
+
6
+ def process(socket)
7
+ write(socket)
8
+
9
+ status = BinData::Int8.read(socket).to_i
10
+ errors = process_errors(socket, status)
11
+ unless errors
12
+ constantize("#{self.class.to_s}Answer").read(socket)
13
+ else
14
+ return {exceptions: errors[:exceptions][0..-2]}
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def process_errors(socket, status)
21
+ if status == 1
22
+ errors = OrientdbBinary::Protocols::Errors.read(socket)
23
+ return errors
24
+ end
25
+ return nil
26
+ end
27
+
28
+ # this might go to String (as a refinment?)
29
+ def constantize(name)
30
+ names = name.split('::')
31
+ names.shift if names.empty? || names.first.empty?
32
+
33
+ constant = Object
34
+ names.each do |name|
35
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
36
+ end
37
+ constant
38
+
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,46 @@
1
+ module OrientdbBinary
2
+ module BinDataPrimitives
3
+ class ProtocolString < BinData::Primitive
4
+ endian :big
5
+
6
+ int32 :len, value: -> { data.length }
7
+ string :data, read_length: :len
8
+
9
+ def get
10
+ data
11
+ end
12
+
13
+ def set(v)
14
+ self.data = v
15
+ end
16
+ end
17
+
18
+ class RecordType < BinData::Primitive
19
+ endian :big
20
+
21
+ int8 :type
22
+
23
+ def get
24
+ type.chr
25
+ end
26
+
27
+ def set(v)
28
+ self.type = v.ord
29
+ end
30
+ end
31
+
32
+ class RecordObject < BinData::Primitive
33
+ endian :big
34
+
35
+ protocol_string :content
36
+
37
+ def get
38
+ self.content = OrientdbBinary::Parser::Deserializer.new.deserialize_document(self.content)
39
+ end
40
+
41
+ def set(v)
42
+ self.content = v
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,166 @@
1
+ module OrientdbBinary
2
+ module Protocols
3
+
4
+ # class SqlCommandPayload < BinData::Record
5
+ # endian :big
6
+
7
+ # protocol_string :text
8
+ # int32 :non_text_limit
9
+ # protocol_string :fetchplan
10
+ # protocol_string :serialized_params, value: "params:[name:\"admin\"]"
11
+ # end
12
+
13
+ # class SqlCommandPayload < BinData::Record
14
+ # endian :big
15
+
16
+ # protocol_string :class_name
17
+ # protocol_string :text
18
+ # int32 :non_text_limit, value: -1
19
+ # protocol_string :fetchplan, value: '*:-1'
20
+ # protocol_string :serialized_params
21
+ # # int8 :with_params, value: 1
22
+ # # int8 :composite_key_params_present, value: 0
23
+ # end
24
+ class Recordd < BinData::Primitive
25
+ endian :big
26
+
27
+ array :records do
28
+ int16 :marker
29
+ int8 :record_type
30
+ int16 :cluster_id
31
+ int64 :position
32
+ int32 :version
33
+ protocol_string :record_content
34
+ end
35
+ end
36
+
37
+ class SqlCommandPayload < BinData::Record
38
+ endian :big
39
+
40
+ protocol_string :class_name
41
+ protocol_string :text
42
+ int32 :non_text_limit, value: -1
43
+ protocol_string :fetch_plan, initial_value: '*:0'
44
+ protocol_string :serialized_params
45
+ end
46
+
47
+ class CommandAnswer < BinData::Record
48
+ endian :big
49
+
50
+ int32 :session
51
+ int8 :synch_result_type
52
+
53
+ int32 :collection_size, onlyif: -> {synch_result_type == 108}
54
+ array :collection, initial_length: :collection_size, onlyif: -> {synch_result_type == 108} do
55
+ int16 :marker
56
+ int8 :record_type
57
+ int16 :cluster_id
58
+ int64 :position
59
+ int32 :version
60
+ protocol_string :record_content
61
+ end
62
+
63
+ int16 :marker, onlyif: -> {synch_result_type == 114}
64
+ int8 :record_type, onlyif: -> {synch_result_type == 114}
65
+ int16 :cluster_id, onlyif: -> {synch_result_type == 114}
66
+ int64 :position, onlyif: -> {synch_result_type == 114}
67
+ int32 :version, onlyif: -> {synch_result_type == 114}
68
+ protocol_string :record_content, onlyif: -> {synch_result_type == 114 or synch_result_type == 97}
69
+
70
+ array :prefetched_records, read_until: -> {element.payload_status == 0} do
71
+ int8 :payload_status
72
+ int16 :marker, onlyif: -> {payload_status > 0}
73
+ int8 :record_type, onlyif: -> {payload_status > 0}
74
+ int16 :cluster_id, onlyif: -> {payload_status > 0}
75
+ int64 :position, onlyif: -> {payload_status > 0}
76
+ int32 :version, onlyif: -> {payload_status > 0}
77
+ protocol_string :record_content, onlyif: -> {payload_status > 0}
78
+ end
79
+
80
+ end
81
+
82
+
83
+ # class SqlCommandPayload < BinData::Record
84
+ # endian :big
85
+
86
+ # protocol_string :class_name, value: 'com.orientechnologies.orient.core.sql.OCommandSQL'
87
+ # protocol_string :text, value: 'SELECT FROM OUser WHERE name = :name'
88
+ # # protocol_string :fetchplan, value: '*:1'
89
+ # int8 :with_params, value: 1
90
+ # protocol_string :serialized_params, value: 'params:{"name":"admin"}'
91
+ # int8 :composite_key_params_present, value: 0
92
+ # end
93
+
94
+ class ScriptCommandPayload < BinData::Record
95
+ endian :big
96
+
97
+ protocol_string :language
98
+ protocol_string :text
99
+ int32 :non_text_limit
100
+ protocol_string :fetchplan
101
+ int32 :serialized_params, value: 0
102
+ end
103
+
104
+ class Command < BinData::Record
105
+ include OrientdbBinary::Protocols::Base
106
+
107
+ endian :big
108
+
109
+ int8 :operation, value: OrientdbBinary::OperationTypes::REQUEST_COMMAND
110
+ int32 :session
111
+
112
+ bit8 :mode
113
+ protocol_string :command_payload
114
+ end
115
+
116
+ # class CommandAnswer < BinData::Record
117
+ # endian :big
118
+
119
+ # int32 :session
120
+ # int8 :synch_result_type
121
+ # int32 :collection_size
122
+ # array :collection, initial_length: :collection_size do
123
+ # int16 :marker
124
+ # int8 :record_type
125
+ # int16 :cluster_id
126
+ # int64 :position
127
+ # int32 :version
128
+ # record_content :record_content
129
+ # end
130
+ # end
131
+ end
132
+ end
133
+
134
+
135
+ # if ($this->mode == OrientDB::COMMAND_QUERY || $this->mode == OrientDB::COMMAND_SELECT_SYNC || $this->mode == OrientDB::COMMAND_SELECT_GREMLIN) {
136
+ # $this->addByte(self::MODE_SYNC);
137
+ # } else {
138
+ # $this->addByte(self::MODE_ASYNC);
139
+ # }
140
+ # if ($this->mode == OrientDB::COMMAND_SELECT_ASYNC) {
141
+ # $objName = 'com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery';
142
+ # } elseif ($this->mode == OrientDB::COMMAND_SELECT_SYNC) {
143
+ # $objName = 'com.orientechnologies.orient.core.sql.query.OSQLSynchQuery';
144
+ # } elseif ($this->mode == OrientDB::COMMAND_SELECT_GREMLIN) {
145
+ # $objName = 'com.orientechnologies.orient.graph.gremlin.OCommandGremlin';
146
+ # } else {
147
+ # $objName = 'com.orientechnologies.orient.core.sql.OCommandSQL';
148
+ # }
149
+ # $buff = '';
150
+ # // Java query object name serialization
151
+ # $buff .= pack('N', strlen($objName));
152
+ # $buff .= $objName;
153
+ # // Query text serialization in TEXT mode
154
+ # $buff .= pack('N', strlen($this->query));
155
+ # $buff .= $this->query;
156
+ # if ($this->mode == OrientDB::COMMAND_SELECT_ASYNC || $this->mode == OrientDB::COMMAND_SELECT_SYNC || $this->mode == OrientDB::COMMAND_SELECT_GREMLIN) {
157
+ # // Limit set to -1 to ignore and use TEXT MODE
158
+ # $buff .= pack('N', -1);
159
+ # // Add a fetchplan
160
+ # $buff .= pack('N', strlen($this->fetchPlan));
161
+ # $buff .= $this->fetchPlan;
162
+ # }
163
+ # // Params serialization, we have 0 params
164
+ # $buff .= pack('N', 0);
165
+ # // Now query object serialization complete, add it to command bytes
166
+ # $this->addString($buff);
@@ -0,0 +1,22 @@
1
+ module OrientdbBinary
2
+ module Protocols
3
+
4
+ class ConfigGet < BinData::Record
5
+ include OrientdbBinary::Protocols::Base
6
+
7
+ endian :big
8
+
9
+ int8 :operation, value: OrientdbBinary::OperationTypes::REQUEST_CONFIG_GET
10
+ int32 :session
11
+
12
+ protocol_string :option_key
13
+ end
14
+
15
+ class ConfigGetAnswer < BinData::Record
16
+ endian :big
17
+
18
+ int32 :session
19
+ protocol_string :option_value
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ module OrientdbBinary
2
+ module Protocols
3
+
4
+ class ConfigList < BinData::Record
5
+ include OrientdbBinary::Protocols::Base
6
+
7
+ endian :big
8
+
9
+ int8 :operation, value: OrientdbBinary::OperationTypes::REQUEST_CONFIG_LIST
10
+ int32 :session
11
+ end
12
+
13
+ class ConfigListAnswer < BinData::Record
14
+ endian :big
15
+
16
+ int32 :session
17
+ int16 :config_count
18
+ array :config_list, initial_length: :config_count do
19
+ protocol_string :option_key
20
+ protocol_string :option_value
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ module OrientdbBinary
2
+ module Protocols
3
+
4
+ class ConfigSet < BinData::Record
5
+ include OrientdbBinary::Protocols::Base
6
+
7
+ endian :big
8
+
9
+ int8 :operation, value: OrientdbBinary::OperationTypes::REQUEST_CONFIG_SET
10
+ int32 :session
11
+
12
+ protocol_string :option_key
13
+ protocol_string :option_value
14
+ end
15
+
16
+ class ConfigSetAnswer < BinData::Record
17
+ endian :big
18
+
19
+ int32 :session
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ module OrientdbBinary
2
+ module Protocols
3
+ class Connect < BinData::Record
4
+ include OrientdbBinary::Protocols::Base
5
+
6
+ endian :big
7
+
8
+ int8 :operation, value: OrientdbBinary::OperationTypes::REQUEST_CONNECT
9
+ int32 :session, value: OrientdbBinary::OperationTypes::NEW_SESSION
10
+
11
+ protocol_string :driver, value: OrientdbBinary::NAME
12
+ protocol_string :driver_version, value: OrientdbBinary::VERSION
13
+ int16 :protocol, value: OrientdbBinary::PROTOCOL_VERSION
14
+ protocol_string :client_id, value: "#{OrientdbBinary::NAME} #{OrientdbBinary::VERSION}, protocol v#{OrientdbBinary::PROTOCOL_VERSION}"
15
+ protocol_string :user
16
+ protocol_string :password
17
+ end
18
+
19
+ class ConnectAnswer < BinData::Record
20
+ endian :big
21
+
22
+ skip length: 4
23
+ int32 :session
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module OrientdbBinary
2
+ module Protocols
3
+
4
+ class DataclusterAdd < BinData::Record
5
+ include OrientdbBinary::Protocols::Base
6
+
7
+ endian :big
8
+
9
+ int8 :operation, value: OrientdbBinary::OperationTypes::REQUEST_DATACLUSTER_ADD
10
+ int32 :session
11
+
12
+ protocol_string :cluster_type
13
+ protocol_string :name
14
+ protocol_string :location
15
+ protocol_string :datasegment_name
16
+ int16 :cluster_id, initial_value: -1
17
+ end
18
+
19
+ class DataclusterAddAnswer < BinData::Record
20
+ endian :big
21
+
22
+ int32 :session
23
+ int16 :cluster_id
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module OrientdbBinary
2
+ module Protocols
3
+
4
+ class DataclusterCount < BinData::Record
5
+ include OrientdbBinary::Protocols::Base
6
+
7
+ endian :big
8
+
9
+ int8 :operation, value: OrientdbBinary::OperationTypes::REQUEST_DATACLUSTER_COUNT
10
+ int32 :session
11
+
12
+ int16 :cluster_count
13
+ array :cluster_ids, initial_length: :cluster_count do
14
+ int16 :cluster_number
15
+ end
16
+ int8 :count_tombstones
17
+ end
18
+
19
+ class DataclusterCountAnswer < BinData::Record
20
+ endian :big
21
+
22
+ int32 :session
23
+ int64 :records_in_clusters
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ module OrientdbBinary
2
+ module Protocols
3
+
4
+ class DataclusterDatarange < BinData::Record
5
+ include OrientdbBinary::Protocols::Base
6
+
7
+ endian :big
8
+
9
+ int8 :operation, value: OrientdbBinary::OperationTypes::REQUEST_DATACLUSTER_DATARANGE
10
+ int32 :session
11
+
12
+ int16 :cluster_id
13
+ end
14
+
15
+ class DataclusterDatarangeAnswer < BinData::Record
16
+ endian :big
17
+
18
+ int32 :session
19
+ int64 :record_id_begin
20
+ int64 :record_id_end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ module OrientdbBinary
2
+ module Protocols
3
+
4
+ class DataclusterDrop < BinData::Record
5
+ include OrientdbBinary::Protocols::Base
6
+
7
+ endian :big
8
+
9
+ int8 :operation, value: OrientdbBinary::OperationTypes::REQUEST_DATACLUSTER_DROP
10
+ int32 :session
11
+
12
+ int16 :cluster_id
13
+ end
14
+
15
+ class DataclusterDropAnswer < BinData::Record
16
+ endian :big
17
+
18
+ int32 :session
19
+ bit4 :succeed
20
+ end
21
+ end
22
+ end