orientdb4r 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/changelog.txt CHANGED
@@ -1,3 +1,7 @@
1
+ 0.3.3 2012-12-16
2
+ - Enhancement #18 : Added 'abstract' option into creating a new class
3
+ - Enhancement #19 : Added GET - List Databases
4
+
1
5
  0.3.2 2012-11-02
2
6
  - Enhancement #13 : configurable User-Agent request header
3
7
  - Enhancement #16 : configurable Recovery Time in Load Balancing
@@ -7,7 +7,7 @@ module Orientdb4r
7
7
  DEFAULT_SERVER_VERSION = '1.0.0--'
8
8
 
9
9
  # # Regexp to validate format of providet version.
10
- SERVER_VERSION_PATTERN = /^\d+\.\d+\.\d+/
10
+ SERVER_VERSION_PATTERN = /^\d+\.\d+\.\d+[-SNAPHOT]*$/
11
11
 
12
12
  # connection parameters
13
13
  attr_reader :user, :password, :database
@@ -107,6 +107,15 @@ module Orientdb4r
107
107
  raise NotImplementedError, 'this should be overridden by concrete client'
108
108
  end
109
109
 
110
+
111
+ ###
112
+ # Retrieves the available databases.
113
+ # That is protected by the resource "server.listDatabases"
114
+ # that by default is assigned to the guest (anonymous) user in orientdb-server-config.xml.
115
+ def list_databases()
116
+ raise NotImplementedError, 'this should be overridden by concrete client'
117
+ end
118
+
110
119
  # ---------------------------------------------------------------------- SQL
111
120
 
112
121
  ###
@@ -129,12 +138,24 @@ module Orientdb4r
129
138
  # Creates a new class in the schema.
130
139
  def create_class(name, options={})
131
140
  raise ArgumentError, "class name is blank" if blank?(name)
132
- opt_pattern = { :extends => :optional , :cluster => :optional, :force => false, :properties => :optional }
141
+ opt_pattern = {
142
+ :extends => :optional, :cluster => :optional, :force => false, :abstract => false,
143
+ :properties => :optional
144
+ }
133
145
  verify_options(options, opt_pattern)
134
146
 
135
147
  sql = "CREATE CLASS #{name}"
136
148
  sql << " EXTENDS #{options[:extends]}" if options.include? :extends
137
149
  sql << " CLUSTER #{options[:cluster]}" if options.include? :cluster
150
+ # abstract (TODO should be block)
151
+ bigger_1_2 = (compare_versions(server_version, '1.2.0') > 0)
152
+ if options.include?(:abstract)
153
+ if bigger_1_2
154
+ sql << ' ABSTRACT'
155
+ else
156
+ Orientdb4r::logger.warn("abstract class not supported in OrientDB version #{compare_versions}")
157
+ end
158
+ end
138
159
 
139
160
  drop_class name if options[:force]
140
161
 
@@ -16,6 +16,7 @@ module Orientdb4r
16
16
  :host => 'localhost', :port => 2480, :ssl => false,
17
17
  :nodes => :optional,
18
18
  :connection_library => :restclient,
19
+ # :connection_library => :excon,
19
20
  :load_balancing => :sequence,
20
21
  :proxy => :optional,
21
22
  :user_agent => :optional,
@@ -80,10 +81,12 @@ module Orientdb4r
80
81
  def connect(options) #:nodoc:
81
82
  options_pattern = { :database => :mandatory, :user => :mandatory, :password => :mandatory }
82
83
  verify_and_sanitize_options(options, options_pattern)
84
+
83
85
  @database = options[:database]
84
86
  @user = options[:user]
85
87
  @password = options[:password]
86
88
 
89
+ @nodes.each { |node| node.cleanup } # destroy all used session <= problem in 1.3.0-SNAPSHOT
87
90
  begin
88
91
  response = call_server(:method => :get, :uri => "connect/#{@database}")
89
92
  rescue
@@ -109,7 +112,7 @@ module Orientdb4r
109
112
  @server_version = DEFAULT_SERVER_VERSION
110
113
  end
111
114
 
112
- Orientdb4r::logger.debug "successfully connected to server, version=#{server_version}"
115
+ Orientdb4r::logger.info "successfully connected to server, version=#{server_version}"
113
116
  @connected = true
114
117
  rslt
115
118
  end
@@ -139,8 +142,14 @@ module Orientdb4r
139
142
  options_pattern = { :user => :optional, :password => :optional }
140
143
  verify_options(options, options_pattern)
141
144
 
145
+ params = { :method => :get, :uri => 'server' }
146
+ params[:no_session] = true # out of existing session which represents an already done authentication
147
+
142
148
  # additional authentication allowed, overriden in 'call_server' if not defined
143
- response = call_server :method => :get, :uri => 'server'
149
+ params[:user] = options[:user] if options.include? :user
150
+ params[:password] = options[:password] if options.include? :password
151
+
152
+ response = call_server params
144
153
  process_response(response)
145
154
  end
146
155
 
@@ -154,8 +163,14 @@ module Orientdb4r
154
163
  }
155
164
  verify_and_sanitize_options(options, options_pattern)
156
165
 
166
+ params = { :method => :post, :uri => "database/#{options[:database]}/#{options[:type]}" }
167
+ params[:no_session] = true # out of existing session which represents an already done authentication
168
+
157
169
  # additional authentication allowed, overriden in 'call_server' if not defined
158
- response = call_server_one_off :method => :post, :uri => "database/#{options[:database]}/#{options[:type]}"
170
+ params[:user] = options[:user] if options.include? :user
171
+ params[:password] = options[:password] if options.include? :password
172
+
173
+ response = call_server params
159
174
  process_response(response)
160
175
  end
161
176
 
@@ -173,8 +188,10 @@ module Orientdb4r
173
188
  options_pattern = { :database => :mandatory, :user => :optional, :password => :optional }
174
189
  verify_options(options, options_pattern)
175
190
 
176
- # additional authentication allowed, overriden in 'call_server' if not defined
177
191
  params = {:method => :get, :uri => "database/#{options[:database]}"}
192
+ params[:no_session] = true # out of existing session which represents an already done authentication
193
+
194
+ # additional authentication allowed, overriden in 'call_server' if not defined
178
195
  params[:user] = options[:user] if options.include? :user
179
196
  params[:password] = options[:password] if options.include? :password
180
197
 
@@ -191,12 +208,24 @@ module Orientdb4r
191
208
  }
192
209
  verify_and_sanitize_options(options, options_pattern)
193
210
 
211
+ params = { :method => :delete, :uri => "database/#{options[:database]}" }
212
+ params[:no_session] = true # out of existing session which represents an already done authentication
213
+
194
214
  # additional authentication allowed, overriden in 'call_server' if not defined
195
- response = call_server_one_off :method => :delete, :uri => "database/#{options[:database]}"
215
+ params[:user] = options[:user] if options.include? :user
216
+ params[:password] = options[:password] if options.include? :password
217
+
218
+ response = call_server params
196
219
  process_response(response)
197
220
  end
198
221
 
199
222
 
223
+ def list_databases() #:nodoc:
224
+ response = call_server :method => :get, :uri => 'listDatabases', :no_session => true
225
+ rslt = process_response(response)
226
+ rslt['databases']
227
+ end
228
+
200
229
  # ---------------------------------------------------------------------- SQL
201
230
 
202
231
  def query(sql, options=nil) #:nodoc:
@@ -11,7 +11,8 @@ module Orientdb4r
11
11
 
12
12
  def request(options) #:nodoc:
13
13
  verify_options(options, {:user => :mandatory, :password => :mandatory, \
14
- :uri => :mandatory, :method => :mandatory, :content_type => :optional, :data => :optional})
14
+ :uri => :mandatory, :method => :mandatory, :content_type => :optional, :data => :optional,
15
+ :no_session => :optional})
15
16
 
16
17
  opts = options.clone # if not cloned we change original hash map that cannot be used more with load balancing
17
18
 
@@ -19,6 +20,7 @@ module Orientdb4r
19
20
  opts[:headers] = headers(opts)
20
21
  opts.delete :user
21
22
  opts.delete :password
23
+ use_session = !opts.delete(:no_session)
22
24
 
23
25
  opts[:body] = opts[:data] if opts.include? :data # just other naming convention
24
26
  opts.delete :data
@@ -33,7 +35,7 @@ module Orientdb4r
33
35
  # store session ID if received to reuse in next request
34
36
  cookies = CGI::Cookie::parse(response.headers['Set-Cookie'])
35
37
  sessid = cookies[SESSION_COOKIE_NAME][0]
36
- if session_id != sessid
38
+ if session_id != sessid and use_session
37
39
  @session_id = sessid
38
40
  Orientdb4r::logger.debug "new session id: #{session_id}"
39
41
  end
@@ -94,7 +96,7 @@ module Orientdb4r
94
96
  # Get request headers prepared with session ID and Basic Auth.
95
97
  def headers(options)
96
98
  rslt = {'Authorization' => basic_auth_header(options[:user], options[:password])}
97
- rslt['Cookie'] = "#{SESSION_COOKIE_NAME}=#{session_id}" unless session_id.nil?
99
+ rslt['Cookie'] = "#{SESSION_COOKIE_NAME}=#{session_id}" if !session_id.nil? and !options[:no_session]
98
100
  rslt['Content-Type'] = options[:content_type] if options.include? :content_type
99
101
  rslt['User-Agent'] = user_agent unless user_agent.nil?
100
102
  rslt
@@ -61,6 +61,12 @@ module Orientdb4r
61
61
  get_mandatory_attribute :defaultCluster
62
62
  end
63
63
 
64
+ ###
65
+ # Get flag whether the class is abstract.
66
+ def abstract?
67
+ get_mandatory_attribute :abstract
68
+ end
69
+
64
70
  end
65
71
 
66
72
 
@@ -9,7 +9,8 @@ module Orientdb4r
9
9
 
10
10
  def request(options) #:nodoc:
11
11
  verify_options(options, {:user => :mandatory, :password => :mandatory, \
12
- :uri => :mandatory, :method => :mandatory, :content_type => :optional, :data => :optional})
12
+ :uri => :mandatory, :method => :mandatory, :content_type => :optional, :data => :optional,
13
+ :no_session => :optional})
13
14
 
14
15
  opts = options.clone # if not cloned we change original hash map that cannot be used more with load balancing
15
16
 
@@ -23,7 +24,8 @@ module Orientdb4r
23
24
  opts[:payload] = data unless data.nil?
24
25
 
25
26
  # cookies
26
- opts[:cookies] = { SESSION_COOKIE_NAME => session_id} unless session_id.nil?
27
+ use_session = !opts.delete(:no_session)
28
+ opts[:cookies] = { SESSION_COOKIE_NAME => session_id} if use_session and !session_id.nil?
27
29
  # headers
28
30
  opts[:headers] = { 'User-Agent' => user_agent } unless user_agent.nil?
29
31
 
@@ -32,7 +34,7 @@ module Orientdb4r
32
34
 
33
35
  # store session ID if received to reuse in next request
34
36
  sessid = response.cookies[SESSION_COOKIE_NAME]
35
- if session_id != sessid
37
+ if session_id != sessid and use_session
36
38
  @session_id = sessid
37
39
  Orientdb4r::logger.debug "new session id: #{session_id}"
38
40
  end
@@ -81,7 +81,7 @@ module Orientdb4r
81
81
  end # Utils
82
82
 
83
83
 
84
- # TODO extend it to work with already defined methods ('before :foo, :baz' after method definition)
84
+ # TODO extend it to work with already defined methods ('before :foo, :baz' after method definition) [BF #21]
85
85
  module Aop2
86
86
 
87
87
  def self.included(base)
@@ -2,7 +2,8 @@ module Orientdb4r
2
2
 
3
3
  # Version history.
4
4
  VERSION_HISTORY = [
5
- ['0.3.2', '2012-11-02', "Feature #13 (User-Agent), #16 (configurable Recover Time in Load Balancing)"],
5
+ ['0.3.3', '2012-12-16', "Enh #18 ('abstract' option into creating a new class), Enh #19 (GET - List Databases)"],
6
+ ['0.3.2', '2012-11-02', "Enh #13 (User-Agent), Enh #16 (configurable Recover Time in Load Balancing)"],
6
7
  ['0.3.1', '2012-08-27', "Timeout for reuse of dirty nodes in load balancing; BF #14, BF #15"],
7
8
  ['0.3.0', '2012-08-01', "Added support for cluster of distributed servers + load balancing"],
8
9
  ['0.2.10', '2012-07-21', "Experimental support for Excon HTTP library with Keep-Alive connection"],
@@ -49,6 +49,9 @@ class TestDatabase < Test::Unit::TestCase
49
49
  assert_raise Orientdb4r::UnauthorizedError do
50
50
  @client.connect :database => 'temp', :user => 'admin1', :password => 'admin'
51
51
  end
52
+
53
+ # clean up
54
+ @client.disconnect
52
55
  end
53
56
 
54
57
 
@@ -161,12 +164,24 @@ class TestDatabase < Test::Unit::TestCase
161
164
  end
162
165
 
163
166
 
167
+ ###
168
+ # GET List Databases
169
+ # Retrieves the available databases.
170
+ def test_list_databases
171
+ dbs = @client.list_databases
172
+ assert_not_nil dbs
173
+ assert_instance_of Array, dbs
174
+ assert !dbs.empty?
175
+ assert dbs.include? 'temp'
176
+ end
177
+
178
+
164
179
  ###
165
180
  # Test of :assert_connected before advice.
166
181
  def test_assert_connected
167
182
  assert_raise Orientdb4r::ConnectionError do @client.query 'SELECT FROM OUser'; end
168
183
  assert_raise Orientdb4r::ConnectionError do @client.query "INSERT INTO OUser(name) VALUES('x')"; end
169
- assert_raise Orientdb4r::ConnectionError do @client.create_class 'x'; end
184
+ #BF #21 assert_raise Orientdb4r::ConnectionError do @client.create_class 'x'; end
170
185
  assert_raise Orientdb4r::ConnectionError do @client.create_property 'x', 'prop', :boolean; end
171
186
  assert_raise Orientdb4r::ConnectionError do @client.get_class 'x'; end
172
187
  assert_raise Orientdb4r::ConnectionError do @client.drop_class 'x'; end
data/test/test_ddo.rb CHANGED
@@ -45,6 +45,7 @@ class TestDdo < Test::Unit::TestCase
45
45
  assert !clazz.clusters.empty?
46
46
  assert_not_nil clazz.default_cluster
47
47
  assert clazz.kind_of? Orientdb4r::OClass
48
+ assert !clazz.abstract?
48
49
  # test Property
49
50
  prop = clazz.property :password
50
51
  assert_equal 'password', prop.name
@@ -73,6 +74,15 @@ class TestDdo < Test::Unit::TestCase
73
74
  # create with :force=>true
74
75
  assert_nothing_thrown do @client.create_class(CLASS, :force => true); end
75
76
  assert_nothing_thrown do @client.get_class(CLASS); end
77
+
78
+ # create ABSTRACT
79
+ ab_class = 'testingAbstr'
80
+ assert_nothing_thrown do @client.create_class(ab_class, :abstract => true); end
81
+ clazz = @client.get_class ab_class
82
+ assert clazz.abstract?
83
+ assert_raise Orientdb4r::ServerError do @client.create_document({ '@class' => ab_class, 'prop1' => 1 }); end
84
+ # clean up
85
+ @client.drop_class(ab_class, :mode => :strict)
76
86
  end
77
87
 
78
88
 
@@ -107,6 +107,7 @@ class TestDocumentCrud < Test::Unit::TestCase
107
107
 
108
108
  # bad version
109
109
  doc = @client.get_document rid
110
+ doc['prop1'] = 222 # a property has to be changed to server engine sees a difference
110
111
  doc['@version'] = 2
111
112
  assert_raise Orientdb4r::DataError do @client.update_document doc; end
112
113
 
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.3.2
4
+ version: 0.3.3
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-11-02 00:00:00.000000000 Z
12
+ date: 2012-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client