orientdb4r 0.2.8 → 0.2.9

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.
data/changelog.txt CHANGED
@@ -3,7 +3,13 @@
3
3
  - 'rest-client' replaced by 'excon' for HTTP communication with Keep-Alive
4
4
  - introduced support for distributed server
5
5
 
6
- 0.2.8 /07/07/xx
6
+
7
+ 0.2.9 /07/07/18
8
+ - introduced class Rid
9
+ - added feature Client#delete_database
10
+
11
+
12
+ 0.2.8 /07/07/16
7
13
  - changed and stabilized exception handling
8
14
  - added feature Client#create_class(:properties)
9
15
 
data/fstudy/design_v1.dia CHANGED
Binary file
@@ -3,7 +3,7 @@ require 'study_case'
3
3
  # This class tests performance on a simple flat class.
4
4
  class FlatClassPerf < FStudy::Case
5
5
 
6
- # def db; 'perf'; end
6
+ def db; 'perf'; end
7
7
 
8
8
  def drop
9
9
  client.drop_class 'User'
@@ -35,8 +35,18 @@ class FlatClassPerf < FStudy::Case
35
35
  end
36
36
  end
37
37
 
38
- def count
39
- puts client.query 'SELECT count(*) FROM User'
38
+ def product
39
+ 1.upto(500000) do |i|
40
+ Orientdb4r::logger.info "...done: #{i}" if 0 == (i % 100000)
41
+ name = dg.word
42
+ type = (rand(3) == 0) ? 'a' : 'b'
43
+ begin
44
+ client.command "insert into product cluster #{type} (name,type) values ('#{name}','#{type}')"
45
+ # client.command "insert into product_simple (name,type) values ('#{name}','#{type}')"
46
+ rescue Exception => e
47
+ Orientdb4r::logger.error e
48
+ end
49
+ end
40
50
  end
41
51
 
42
52
  end
@@ -190,7 +190,7 @@ class TechnicalFeasibility < FStudy::Case
190
190
  types = [:login, :logout, :likeit, :rated, :saw, :commented]
191
191
  limit = users.size * user_coef
192
192
  1.upto(limit) do |i|
193
- puts "... #{i}" if 0 == i % 100000
193
+ puts "... #{i} #{Time.now - start}" if 0 == i % 100000
194
194
  type = rand(types.size)
195
195
  activity = { '@class' => 'Activity', :type => type, :stamp => (Time.now.to_i - rand(3600*23*30)) }
196
196
  # random distribution of Users (1) & the same communities as user
@@ -201,7 +201,12 @@ class TechnicalFeasibility < FStudy::Case
201
201
  content = (types[type] == :login or types[type] == :logout) ? nil : contents[rand(contents.size)]
202
202
  activity[content['@class'].downcase] = content[:rid] unless content.nil?
203
203
 
204
- client.create_document(activity)
204
+ begin
205
+ client.create_document(activity)
206
+ rescue Exception => e
207
+ Orientdb4r::logger.error "problem storing index=#{i}, user=#{user.inspect}"
208
+ Orientdb4r::logger.error e
209
+ end
205
210
  end
206
211
  puts "Created Activities: #{limit}, time = #{Time.now - start} [s]"
207
212
  end
@@ -84,6 +84,13 @@ module Orientdb4r
84
84
  end
85
85
 
86
86
 
87
+ ###
88
+ # Drops a database.
89
+ # Requires additional authentication to the server.
90
+ def delete_database(options)
91
+ raise NotImplementedError, 'this should be overridden by concrete client'
92
+ end
93
+
87
94
  # ---------------------------------------------------------------------- SQL
88
95
 
89
96
  ###
@@ -103,7 +103,7 @@ module Orientdb4r
103
103
  def create_database(options) #:nodoc:
104
104
  options_pattern = {
105
105
  :database => :mandatory, :type => 'memory',
106
- :user => :optional, :password => :optional, :ssl => false
106
+ :user => :optional, :password => :optional
107
107
  }
108
108
  verify_and_sanitize_options(options, options_pattern)
109
109
 
@@ -141,6 +141,22 @@ module Orientdb4r
141
141
  end
142
142
 
143
143
 
144
+ def delete_database(options) #:nodoc:
145
+ options_pattern = {
146
+ :database => :mandatory, :user => :optional, :password => :optional
147
+ }
148
+ verify_and_sanitize_options(options, options_pattern)
149
+
150
+ u = options.include?(:user) ? options[:user] : user
151
+ p = options.include?(:password) ? options[:password] : password
152
+
153
+ # uses one-off request because of additional authentication to the server
154
+ response = a_node.oo_request :method => :delete, :user => u, :password => p, \
155
+ :uri => "database/#{options[:database]}"
156
+ process_response(response)
157
+ end
158
+
159
+
144
160
  # ---------------------------------------------------------------------- SQL
145
161
 
146
162
  def query(sql, options=nil) #:nodoc:
@@ -212,24 +228,20 @@ module Orientdb4r
212
228
 
213
229
  # ----------------------------------------------------------------- DOCUMENT
214
230
 
215
- def create_document(doc)
231
+ def create_document(doc) #:nodoc:
216
232
  response = a_node.request(:method => :post, :uri => "document/#{@database}", \
217
233
  :content_type => 'application/json', :data => doc.to_json)
218
- rid = process_response(response) do
234
+ srid = process_response(response) do
219
235
  raise DataError, 'validation problem' if response.body =~ /OValidationException/
220
236
  end
221
237
 
222
- raise ArgumentError, "invalid RID format, RID=#{rid}" unless rid =~ /^#[0-9]+:[0-9]+/
223
- rid
238
+ Rid.new srid
224
239
  end
225
240
 
226
241
 
227
242
  def get_document(rid) #:nodoc:
228
- raise ArgumentError, 'blank RID' if blank? rid
229
- # remove the '#' prefix
230
- rid = rid[1..-1] if rid.start_with? '#'
231
-
232
- response = a_node.request(:method => :get, :uri => "document/#{@database}/#{rid}")
243
+ rid = Rid.new(rid) unless rid.is_a? Rid
244
+ response = a_node.request(:method => :get, :uri => "document/#{@database}/#{rid.unprefixed}")
233
245
  rslt = process_response(response) do
234
246
  raise NotFoundError, 'record not found' if response.body =~ /ORecordNotFoundException/
235
247
  raise NotFoundError, 'record not found' if response.body =~ /Record with id .* was not found/ # why after delete?
@@ -245,10 +257,10 @@ module Orientdb4r
245
257
  raise ArgumentError, 'document has no RID' if doc.doc_rid.nil?
246
258
  raise ArgumentError, 'document has no version' if doc.doc_version.nil?
247
259
 
248
- rid = doc.delete '@rid'
249
- rid = rid[1..-1] if rid.start_with? '#'
260
+ rid = doc.doc_rid
261
+ doc.delete '@rid' # will be not updated
250
262
 
251
- response = a_node.request(:method => :put, :uri => "document/#{@database}/#{rid}", \
263
+ response = a_node.request(:method => :put, :uri => "document/#{@database}/#{rid.unprefixed}", \
252
264
  :content_type => 'application/json', :data => doc.to_json)
253
265
  process_response(response) do
254
266
  raise DataError, 'concurrent modification' if response.body =~ /OConcurrentModificationException/
@@ -259,11 +271,9 @@ module Orientdb4r
259
271
 
260
272
 
261
273
  def delete_document(rid) #:nodoc:
262
- raise ArgumentError, 'blank RID' if blank? rid
263
- # remove the '#' prefix
264
- rid = rid[1..-1] if rid.start_with? '#'
274
+ rid = Rid.new(rid) unless rid.is_a? Rid
265
275
 
266
- response = a_node.request(:method => :delete, :uri => "document/#{@database}/#{rid}")
276
+ response = a_node.request(:method => :delete, :uri => "document/#{@database}/#{rid.unprefixed}")
267
277
  process_response(response) do
268
278
  raise NotFoundError, 'record not found' if response.body =~ /ORecordNotFoundException/
269
279
  end
@@ -126,7 +126,8 @@ module Orientdb4r
126
126
  ###
127
127
  # Gets the document ID.
128
128
  def doc_rid
129
- self['@rid']
129
+ @mixedin_rid = Rid.new(self['@rid']) if @mixedin_rid.nil?
130
+ @mixedin_rid
130
131
  end
131
132
 
132
133
  ###
@@ -0,0 +1,50 @@
1
+ module Orientdb4r
2
+
3
+ ###
4
+ # This class represents encapsulation of RecordID.
5
+ class Rid
6
+ include Utils
7
+
8
+ # Format validation regexp.
9
+ RID_REGEXP_PATTERN = /^#?\d+:\d+$/
10
+
11
+ attr_reader :cluster_id, :document_id
12
+
13
+ ###
14
+ # Constructor.
15
+ def initialize(rid)
16
+ raise ArgumentError, 'RID cannot be blank' if blank? rid
17
+ raise ArgumentError, 'RID is not String' unless rid.is_a? String
18
+ raise ArgumentError, "bad RID format, rid=#{rid}" unless rid =~ RID_REGEXP_PATTERN
19
+
20
+ rid = rid[1..-1] if rid.start_with? '#'
21
+ ids = rid.split ':'
22
+ self.cluster_id = ids[0].to_i
23
+ self.document_id = ids[1].to_i
24
+ end
25
+
26
+ def cluster_id=(cid)
27
+ @cluster_id = cid.to_i
28
+ end
29
+
30
+ def document_id=(did)
31
+ @document_id = did.to_i
32
+ end
33
+
34
+ def to_s
35
+ "##{cluster_id}:#{document_id}"
36
+ end
37
+
38
+ ###
39
+ # Gets RID's string representation with no prefix.
40
+ def unprefixed
41
+ "#{cluster_id}:#{document_id}"
42
+ end
43
+
44
+ def ==(another_rid) #:nodoc:
45
+ self.cluster_id == another_rid.cluster_id and self.document_id == another_rid.document_id
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -2,6 +2,7 @@ module Orientdb4r
2
2
 
3
3
  # Version history.
4
4
  VERSION_HISTORY = [
5
+ ['0.2.9', '2012-07-18', "Added feature Client#delete_database, New class Rid"],
5
6
  ['0.2.8', '2012-07-16', "New exception handling, added feature Client#create_class(:properties)"],
6
7
  ['0.2.7', '2012-07-07', "Added method Client#class_exists?"],
7
8
  ['0.2.6', '2012-07-03', "BF #8, BF #6"],
data/lib/orientdb4r.rb CHANGED
@@ -11,6 +11,7 @@ module Orientdb4r
11
11
  autoload :Utils, 'orientdb4r/utils'
12
12
  autoload :Client, 'orientdb4r/client'
13
13
  autoload :RestClient, 'orientdb4r/rest/client'
14
+ autoload :Rid, 'orientdb4r/rid'
14
15
  autoload :HashExtension, 'orientdb4r/rest/model'
15
16
  autoload :OClass, 'orientdb4r/rest/model'
16
17
  autoload :ChainedError, 'orientdb4r/chained_error'
@@ -76,14 +76,16 @@ class TestDatabase < Test::Unit::TestCase
76
76
 
77
77
  ###
78
78
  # CREATE DATABASE
79
- # Temporary disabled because of unknown way how to drop a new created datatabse.
79
+ # Temporary disabled because of dependency to password of 'root' account
80
80
  def xtest_create_database
81
- @client.create_database :database => 'UniT', :user => 'root', :password => 'root'
81
+ assert_nothing_thrown do
82
+ @client.create_database :database => 'UniT', :user => 'root', :password => 'root'
83
+ end
82
84
  assert_nothing_thrown do
83
85
  @client.get_database :database => 'UniT', :user => 'admin', :password => 'admin'
84
86
  end
85
87
  # creating an existing DB
86
- assert_raise Orientdb4r::OrientdbError do
88
+ assert_raise Orientdb4r::ServerError do
87
89
  @client.create_database :database => 'UniT', :user => 'root', :password => 'root'
88
90
  end
89
91
  # insufficient rights
@@ -93,8 +95,10 @@ class TestDatabase < Test::Unit::TestCase
93
95
 
94
96
  # By convention 3 users are always created by default every time you create a new database.
95
97
  # Default users are: admin, reader, writer
96
- @client.connect :database => 'UniT', :user => 'admin', :password => 'admin'
97
- #@client.command "DROP DATABASE UniT" : NOT WORKING now
98
+ assert_nothing_thrown do
99
+ @client.connect :database => 'UniT', :user => 'admin', :password => 'admin'
100
+ end
101
+ @client.delete_database({:database => 'UniT', :user => 'root', :password => 'root'})
98
102
  end
99
103
 
100
104
 
@@ -126,6 +130,27 @@ class TestDatabase < Test::Unit::TestCase
126
130
  end
127
131
 
128
132
 
133
+ ###
134
+ # DELETE DATABASE
135
+ # Temporary disabled because of dependency to password of 'root' account
136
+ def xtest_delete_database
137
+ @client.create_database :database => 'UniT', :user => 'root', :password => 'root'
138
+
139
+ # deleting non-existing DB
140
+ assert_raise Orientdb4r::ServerError do
141
+ @client.delete_database :database => 'UniT1', :user => 'root', :password => 'root'
142
+ end
143
+ # insufficient rights
144
+ assert_raise Orientdb4r::OrientdbError do
145
+ @client.delete_database :database => 'UniT', :user => 'admin', :password => 'admin'
146
+ end
147
+
148
+ assert_nothing_thrown do
149
+ @client.delete_database({:database => 'UniT', :user => 'root', :password => 'root'})
150
+ end
151
+ end
152
+
153
+
129
154
  ###
130
155
  # SERVER info
131
156
  # Temporary disabled because of dependency to password of 'root' account
data/test/test_dmo.rb CHANGED
@@ -77,6 +77,7 @@ class TestDmo < Test::Unit::TestCase
77
77
  assert_instance_of Array, entries
78
78
  assert_equal 20, entries.size # 20 is default limit
79
79
  entries.each { |doc| assert doc.kind_of? Orientdb4r::DocumentMetadata }
80
+ entries.each { |doc| assert_instance_of Orientdb4r::Rid, doc.doc_rid }
80
81
  # limit
81
82
  assert_equal 5, @client.query("SELECT FROM #{CLASS} LIMIT 5").size
82
83
  entries = @client.query "SELECT FROM #{CLASS}", :limit => 100
@@ -32,7 +32,7 @@ class TestDocumentCrud < Test::Unit::TestCase
32
32
  def test_create_document
33
33
  assert_nothing_thrown do @client.create_document( { '@class' => CLASS, 'prop1' => 99, 'prop2' => 'ipsum lorem' }); end
34
34
  rid = @client.create_document({ '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
35
- assert rid =~ /#[0-9]+:[0-9]+$/
35
+ assert_instance_of Orientdb4r::Rid, rid
36
36
 
37
37
  # no effect if a define the version
38
38
  assert_nothing_thrown do
@@ -86,10 +86,10 @@ class TestDocumentCrud < Test::Unit::TestCase
86
86
  assert doc.kind_of? Orientdb4r::DocumentMetadata
87
87
 
88
88
  # not existing RID
89
- rid1 = rid.sub(/[0-9]+$/, (rid.split(':')[1].to_i + 1).to_s) # '#6:0' > '#6:1' or '#6:11' > '#6:12'
89
+ rid1 = Orientdb4r::Rid.new("#{rid.cluster_id}:#{rid.document_id + 1}") # '#6:0' > '#6:1' or '#6:11' > '#6:12'
90
90
  assert_raise Orientdb4r::NotFoundError do @client.get_document rid1; end
91
91
  # bad RID format
92
- assert_raise Orientdb4r::ServerError do @client.get_document('xx'); end
92
+ assert_raise ArgumentError do @client.get_document('xx'); end
93
93
  end
94
94
 
95
95
  ###
@@ -146,7 +146,7 @@ class TestDocumentCrud < Test::Unit::TestCase
146
146
  # not existing RID
147
147
  assert_raise Orientdb4r::NotFoundError do @client.delete_document '#4:1111'; end
148
148
  # bad RID format
149
- assert_raise Orientdb4r::ServerError do @client.delete_document 'xx'; end
149
+ assert_raise ArgumentError do @client.delete_document 'xx'; end
150
150
  end
151
151
 
152
152
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orientdb4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
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-07-16 00:00:00.000000000 Z
12
+ date: 2012-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -59,6 +59,7 @@ files:
59
59
  - lib/orientdb4r/rest/model.rb
60
60
  - lib/orientdb4r/rest/node.rb
61
61
  - lib/orientdb4r/rest/restclient_node.rb
62
+ - lib/orientdb4r/rid.rb
62
63
  - lib/orientdb4r/utils.rb
63
64
  - lib/orientdb4r/version.rb
64
65
  - orientdb4r.gemspec