orientdb-binary 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 822de4e7fe6c71ba013c1a5ff83d47359fc29bf9
4
+ data.tar.gz: 20409e9c8397250249a51a4f94da04613d094846
5
+ SHA512:
6
+ metadata.gz: b3593c9e0a8f34d3777de2a1f8bdf916c48cf5667168de66482c2f8df689f1e3345d28978760962f6fbfa0eb78936824357492108c09632a5fb70c0d477e4c88
7
+ data.tar.gz: 7df96f629462b46a538f68e7fd93ff0cc19e2d6beccbf5b925587f3a8f345e9b1af6d2e65a52e8e80311de01c473f39af9ccf85f6ceb040d8d7e613213585491
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ coverage/*
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in orientdb_binary.gemspec
4
+
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Michal Ostrowski
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Orientdb Binary
2
+
3
+ OrientDB Network Binary library for Ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'orientdb-binary'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install orientdb-binary
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/espresse/orientdb-binary/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,64 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => [:test]
3
+
4
+
5
+ task :build do
6
+ system "gem build orientdb-binary.gemspec"
7
+ end
8
+
9
+ task :release => :build do
10
+ system "gem push orientdb-binary-#{OrientdbBinary::VERSION}"
11
+ end
12
+
13
+ task :install do
14
+ system "gem install orientdb-binary-#{OrientdbBinary::Version}"
15
+ end
16
+
17
+ test_tasks = ['test:all']
18
+ desc "Run all tests"
19
+ task :test => test_tasks
20
+
21
+ namespace :test do
22
+ desc "Run server tests"
23
+ task :server do
24
+ $: << 'lib'
25
+
26
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
27
+ require_relative 'lib/orientdb_binary'
28
+ require 'test/test_helper'
29
+
30
+ Dir['./test/server/**/test_*.rb'].each { |test| require test }
31
+ end
32
+ end
33
+
34
+ namespace :test do
35
+ desc "Run database tests"
36
+ task :database do
37
+ $: << 'lib'
38
+
39
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
40
+ require_relative 'lib/orientdb_binary'
41
+ require 'test/test_helper'
42
+
43
+ Dir['./test/database/**/test_*.rb'].each { |test| require test }
44
+ end
45
+ end
46
+
47
+ namespace :test do
48
+ desc "Run all tests and check coverage"
49
+ task :all do
50
+ $: << 'lib'
51
+ require 'simplecov'
52
+
53
+ SimpleCov.start do
54
+ add_filter "test"
55
+ command_name 'Mintest'
56
+ end
57
+
58
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
59
+ require_relative 'lib/orientdb_binary'
60
+ require 'test/test_helper'
61
+
62
+ Dir['./test/**/test_*.rb'].each { |test| require test }
63
+ end
64
+ end
@@ -0,0 +1,25 @@
1
+ require 'socket'
2
+ require 'bindata'
3
+ require 'set'
4
+ require 'bigdecimal'
5
+ require 'date'
6
+
7
+ require "orientdb_binary/config"
8
+
9
+ require 'orientdb_binary/parser/deserializer'
10
+ require 'orientdb_binary/parser/serializer'
11
+
12
+ require 'orientdb_binary/operation_types'
13
+ require 'orientdb_binary/protocols/base'
14
+ require 'orientdb_binary/protocols/bindata_primitives'
15
+ require 'orientdb_binary/protocols/errors'
16
+
17
+ require 'orientdb_binary/connection'
18
+ require 'orientdb_binary/base'
19
+
20
+ require 'orientdb_binary/server'
21
+ require 'orientdb_binary/database'
22
+
23
+ module OrientdbBinary
24
+
25
+ end
@@ -0,0 +1,40 @@
1
+ module OrientdbBinary
2
+ class OrientdbBase
3
+ attr_accessor :socket, :protocol, :session
4
+
5
+ def initialize(options)
6
+ defaults = {
7
+ host: 'localhost',
8
+ port: 2424
9
+ }
10
+
11
+ @options = defaults.merge(options)
12
+
13
+ @server_connection = OrientdbBinary::Connection.new(@options)
14
+ @socket = @server_connection.socket
15
+ @connected = false
16
+ @session = OrientdbBinary::OperationTypes::NEW_SESSION
17
+ end
18
+
19
+ def connected?
20
+ @connected
21
+ end
22
+
23
+ def disconnect
24
+ close
25
+ @server_connection.close()
26
+ end
27
+
28
+ def close
29
+ @session = OrientdbBinary::OperationTypes::NEW_SESSION
30
+ @connected = false
31
+ end
32
+
33
+ private
34
+
35
+ def params (args={})
36
+ args.merge(session: session)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ module OrientdbBinary
2
+ VERSION = "0.6.0"
3
+ NAME = "OrientDB Binary Protocol Ruby Client"
4
+ PROTOCOL_VERSION = 20
5
+ end
@@ -0,0 +1,17 @@
1
+ module OrientdbBinary
2
+ class Connection
3
+
4
+ attr_accessor :socket, :protocol
5
+
6
+ def initialize(options)
7
+ @socket = TCPSocket.open(options[:host], options[:port])
8
+ @protocol = BinData::Int16be.read(socket)
9
+ end
10
+
11
+ def close
12
+ socket.close
13
+ @protocol = nil
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ require 'orientdb_binary/database_operations/base_operations'
2
+ require 'orientdb_binary/database_operations/data_segment'
3
+ require 'orientdb_binary/database_operations/data_cluster'
4
+ require 'orientdb_binary/database_operations/record'
5
+ require 'orientdb_binary/database_operations/query'
6
+ require 'orientdb_binary/database_operations/transaction'
7
+
8
+ module OrientdbBinary
9
+ class Database < OrientdbBinary::OrientdbBase
10
+ include OrientdbBinary::DatabaseOperations::BaseOperations
11
+ include OrientdbBinary::DatabaseOperations::DataSegment
12
+ include OrientdbBinary::DatabaseOperations::DataCluster
13
+ include OrientdbBinary::DatabaseOperations::Record
14
+ include OrientdbBinary::DatabaseOperations::Query
15
+ include OrientdbBinary::DatabaseOperations::Transaction
16
+
17
+ attr_accessor :clusters
18
+
19
+ def self.connect(options)
20
+ Database.new(options)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,70 @@
1
+ require 'orientdb_binary/protocols/db_close'
2
+ require 'orientdb_binary/protocols/db_open'
3
+ require 'orientdb_binary/protocols/db_reload'
4
+ require 'orientdb_binary/protocols/db_size'
5
+ require 'orientdb_binary/protocols/db_list'
6
+
7
+ module OrientdbBinary
8
+ module DatabaseOperations
9
+ module BaseOperations
10
+
11
+ # Open database connection.
12
+ # Params:
13
+ # db: string -> database name
14
+ # user: username for accessing database
15
+ # password: user's pasword for database access
16
+ # storage: string -> memory, local, plocal; plocal is used by default
17
+ # Usage:
18
+ # db = OrientdbBinary::Database.open(db: "test", storage: 'plocal', user: 'admin', password: 'admin')
19
+ #
20
+ def open(args)
21
+ @db_params = {
22
+ db: args[:db],
23
+ storage: args[:storage]
24
+ }
25
+
26
+ defaults = {
27
+ storage: 'plocal'
28
+ }
29
+
30
+
31
+ connection = OrientdbBinary::Protocols::DbOpen.new(defaults.merge(args)).process(socket)
32
+
33
+ @session = connection[:session]
34
+ @connected = true if @session >= 0
35
+ @clusters = connection[:clusters]
36
+ connection
37
+ end
38
+
39
+ # Close databse connection
40
+ # No params are accepted
41
+ # Usage:
42
+ # db.close()
43
+ #
44
+ def close
45
+ OrientdbBinary::Protocols::DbClose.new(params).process(socket)
46
+ super
47
+ end
48
+
49
+ # Reload database. Information about clusters are updated
50
+ # No params are accepted
51
+ # Usage
52
+ # db.reload()
53
+ #
54
+ def reload
55
+ answer = OrientdbBinary::Protocols::DbReload.new(params).process(socket)
56
+ @clusters = answer[:clusters]
57
+ answer
58
+ end
59
+
60
+ # Return size of the database
61
+ # No params are accepted
62
+ # Usage:
63
+ # db.size()
64
+ #
65
+ def size
66
+ OrientdbBinary::Protocols::DbSize.new(params).process(socket)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,116 @@
1
+ require 'orientdb_binary/protocols/datacluster_add'
2
+ require 'orientdb_binary/protocols/datacluster_drop'
3
+ require 'orientdb_binary/protocols/datacluster_count'
4
+ require 'orientdb_binary/protocols/datacluster_datarange'
5
+ require 'orientdb_binary/protocols/datacluster_lh_cluster_is_used'
6
+
7
+ module OrientdbBinary
8
+ module DatabaseOperations
9
+ module DataCluster
10
+
11
+ # Add datacluster.
12
+ # name: string
13
+ # optional parameters:
14
+ # cluster_type: string (PHYSICAL or MEMORY), for memory databases it should be 'MEMORY', for local/plocal it can be either 'MEMORY or 'PHYSICAL'
15
+ # datasegment_name: string (should exists, 'default' is used by default)
16
+ # location: string
17
+ # cluster_id: string, should be -1 for new clusters
18
+ #
19
+ # Usage:
20
+ # db.add_datacluster(name: "posts") # uses default datasegment
21
+ # If needed datasegment should be created before
22
+ # db.add_datasegment(name: "posts")
23
+ # db.add_datacluster(name: "posts", datasegment_name: "posts")
24
+ #
25
+ def add_datacluster(args)
26
+ types = {
27
+ local: 'PHYSICAL',
28
+ plocal: 'PHYSICAL',
29
+ memory: 'MEMORY'
30
+ }
31
+
32
+ defaults = {
33
+ cluster_type: types[@db_params[:storage].to_sym],
34
+ datasegment_name: "default",
35
+ location: args[:name] + "_datacluster",
36
+ cluster_id: -1
37
+ }
38
+
39
+ options = defaults.merge(args)
40
+
41
+ OrientdbBinary::Protocols::DataclusterAdd.new(params(options)).process(socket)
42
+ end
43
+
44
+ # Find cluster by its parameter
45
+ # Usage:
46
+ # db.find_datacluster_by(name: 'default')
47
+ # db.find_datacluster_by(id: 1)
48
+ # Only first cluster is returned!
49
+ #
50
+ def find_datacluster_by(arg)
51
+ key = arg.keys.first
52
+ val = arg[key]
53
+ @clusters.select {|cluster| cluster["#{key}".to_sym] == val}.first
54
+ end
55
+
56
+ # Drops datacluster
57
+ # cluster_id: int
58
+ # or
59
+ # cluster_name: string
60
+ # Usage:
61
+ # db.drop_datacluster(cluster_id: 7)
62
+ # db.drop_datacluster(cluster_name: 'posts')
63
+ #
64
+ def drop_datacluster(args)
65
+ if args[:cluster_name] and not args[:cluster_id]
66
+ if cluster=find_datacluster_by(cluster_name: args[:cluster_name])
67
+ args[:cluster_id] = cluster[:cluster_id]
68
+ end
69
+ end
70
+ OrientdbBinary::Protocols::DataclusterDrop.new(params(args)).process(socket)
71
+ end
72
+
73
+ # cluster_ids: array of ids
74
+ # or
75
+ # cluster_names: array of names
76
+ # Usage:
77
+ # db.count_datacluster(cluster_ids: [0,1,2,3])
78
+ # db.count_datacluster(cluster_names: ['default', 'posts'])
79
+ #
80
+ def count_datacluster(args)
81
+ if args[:cluster_names] and not args[:cluster_ids]
82
+ args[:cluster_ids] = args[:cluster_names].map do |name|
83
+ cluster = find_datacluster_by(cluster_name: name)
84
+ cluster[:cluster_id] if cluster
85
+ end
86
+ end
87
+ args[:cluster_ids] = args[:cluster_ids].delete_if {|cluster| !cluster}
88
+ args[:cluster_count] = args[:cluster_ids].length
89
+
90
+ OrientdbBinary::Protocols::DataclusterCount.new(params(args)).process(socket)
91
+ end
92
+
93
+ # cluster_id: int
94
+ # or
95
+ # cluster_name: string
96
+ # Usage:
97
+ # db.datarange_datacluster(cluster_id: 7)
98
+ # db.datarange_datacluster(cluster_name: 'posts')
99
+ #
100
+ def datarange_datacluster(args)
101
+ if args[:cluster_name] and not args[:cluster_id]
102
+ if cluster=find_datacluster_by(cluster_name: args[:cluster_name])
103
+ args[:cluster_id] = cluster[:cluster_id]
104
+ end
105
+ end
106
+ OrientdbBinary::Protocols::DataclusterDatarange.new(params(args)).process(socket)
107
+ end
108
+
109
+ # it looks like it's not supported (?)
110
+ def datacluster_lh_cluster_is_used()
111
+ # OrientdbBinary::Protocols::DataclusterLhClusterIsUsed.new(session: session).process(socket)
112
+ return nil
113
+ end
114
+ end
115
+ end
116
+ end