active-orient 0.42 → 0.79

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/Gemfile +13 -5
  4. data/Guardfile +12 -4
  5. data/README.md +67 -280
  6. data/VERSION +1 -1
  7. data/active-orient.gemspec +6 -5
  8. data/bin/active-orient-0.6.gem +0 -0
  9. data/bin/active-orient-console +85 -0
  10. data/config/boot.rb +72 -1
  11. data/config/config.yml +10 -0
  12. data/config/connect.yml +9 -4
  13. data/examples/books.rb +92 -40
  14. data/examples/streets.rb +89 -85
  15. data/examples/test_commands.rb +97 -0
  16. data/examples/test_commands_2.rb +59 -0
  17. data/examples/test_commands_3.rb +55 -0
  18. data/examples/test_commands_4.rb +33 -0
  19. data/examples/time_graph.md +162 -0
  20. data/lib/active-orient.rb +75 -9
  21. data/lib/base.rb +238 -169
  22. data/lib/base_properties.rb +68 -60
  23. data/lib/class_utils.rb +226 -0
  24. data/lib/database_utils.rb +98 -0
  25. data/lib/init.rb +79 -0
  26. data/lib/java-api.rb +442 -0
  27. data/lib/jdbc.rb +211 -0
  28. data/lib/model/custom.rb +26 -0
  29. data/lib/model/edge.rb +70 -0
  30. data/lib/model/model.rb +134 -0
  31. data/lib/model/the_class.rb +607 -0
  32. data/lib/model/the_record.rb +266 -0
  33. data/lib/model/vertex.rb +236 -0
  34. data/lib/orientdb_private.rb +48 -0
  35. data/lib/other.rb +371 -0
  36. data/lib/railtie.rb +68 -0
  37. data/lib/rest/change.rb +147 -0
  38. data/lib/rest/create.rb +279 -0
  39. data/lib/rest/delete.rb +134 -0
  40. data/lib/rest/operations.rb +211 -0
  41. data/lib/rest/read.rb +171 -0
  42. data/lib/rest/rest.rb +112 -0
  43. data/lib/rest_disabled.rb +24 -0
  44. data/lib/support/logging.rb +38 -0
  45. data/lib/support/orient.rb +196 -0
  46. data/lib/support/orientquery.rb +469 -0
  47. data/rails.md +154 -0
  48. data/rails/activeorient.rb +32 -0
  49. data/rails/config.yml +10 -0
  50. data/rails/connect.yml +17 -0
  51. metadata +65 -24
  52. data/active-orient-0.4.gem +0 -0
  53. data/active-orient-0.41.gem +0 -0
  54. data/lib/model.rb +0 -468
  55. data/lib/orient.rb +0 -98
  56. data/lib/query.rb +0 -88
  57. data/lib/rest.rb +0 -1059
  58. data/lib/support.rb +0 -372
  59. data/test.rb +0 -4
  60. data/usecase.md +0 -91
@@ -1,372 +0,0 @@
1
- class String
2
- def to_classname
3
- if self[0] =='$'
4
- self[1..-1]
5
- else
6
- self.camelize
7
- end
8
- end
9
- def to_orient
10
- self.gsub /%/, '(percent)'
11
-
12
- end
13
- def rid?
14
- self =~ /\A[#]{,1}[0-9]{1,}:[0-9]{1,}\z/
15
- end
16
- def from_orient
17
- if rid?
18
- ActiveOrient::Model.autoload_object self
19
- else
20
- self
21
- end
22
- end
23
- ## this enables the universal use of an rid-string as pseudonym for a ActiveOrient::Model
24
- alias :reload! from_orient
25
- end
26
- class NilClass
27
- def to_orient
28
- self
29
- end
30
- end
31
- class Symbol
32
- def to_orient
33
- self.to_s.to_orient
34
- end
35
- def from_orient
36
- self
37
- end
38
- end
39
-
40
- class Numeric
41
- def from_orient
42
- self
43
- end
44
- def to_orient
45
- self
46
- end
47
- end
48
-
49
- class Time
50
- def from_orient
51
- self
52
- end
53
- def to_orient
54
- self
55
- end
56
- end
57
- class Date
58
- def from_orient
59
- self
60
- end
61
- def to_orient
62
- self
63
- end
64
- end
65
-
66
- class TrueClass
67
- def from_orient
68
- self
69
- end
70
- def to_orient
71
- self
72
- end
73
- end
74
- class FalseClass
75
- def from_orient
76
- self
77
- end
78
- def to_orient
79
- self
80
- end
81
- end
82
-
83
- class Array
84
- def to_orient
85
- map &:to_orient
86
- end
87
- def from_orient
88
- map &:from_orient
89
- end
90
- end
91
- class Hash #WithIndifferentAccess
92
- def from_orient
93
- substitute_hash = HashWithIndifferentAccess.new
94
- keys.each{ |k| puts self[k].inspect }
95
- keys.each{| k | substitute_hash[k] = self[k].from_orient }
96
- substitute_hash
97
-
98
- end
99
- def to_orient
100
- substitute_hash = Hash.new
101
- keys.each{| k | substitute_hash[k] = self[k].to_orient }
102
- substitute_hash
103
-
104
- end
105
-
106
- def nested_under_indifferent_access
107
- HashWithIndifferentAccess.new self
108
- end
109
- end
110
-
111
-
112
- module OrientSupport
113
-
114
- module Support
115
- =begin
116
- supports
117
-
118
- where: 'string'
119
- where: { property: 'value', property: value, ... }
120
- where: ['string, { property: value, ... }, ... ]
121
-
122
-
123
- Used by update and select
124
- =end
125
-
126
- def compose_where *arg
127
- arg=arg.flatten
128
- return "" if arg.blank? || arg.size == 1 && arg.first.blank?
129
- "where " + arg.map do |issue|
130
- case issue
131
- when String
132
- issue
133
- when Hash
134
- generate_sql_list issue
135
- end
136
- end.join( ' and ' )
137
- end
138
- def generate_sql_list attributes={}
139
- attributes.map do | key, value |
140
- case value
141
- when Numeric
142
- key.to_s << " = " << value.to_s
143
- else # String, Symbol, Date, Time, Trueclass, Falseclass ...
144
- key.to_s << ' = ' << "\'#{ value }\'"
145
- end
146
- end.join( ' and ' )
147
- end
148
- end # module
149
-
150
-
151
- class OrientQuery
152
-
153
- include Support
154
-
155
- def initialize **args
156
- @projection = []
157
- @misc = []
158
- @let = []
159
- @where = []
160
- @order = []
161
- @kind = 'select'
162
- args.each do | k,v|
163
- case k
164
- when :projection
165
- @projection << v
166
- when :let
167
- @let << v
168
- when :order
169
- @order << v
170
- when :where
171
- @where << v
172
- when :kind
173
- @kind = v
174
- else
175
- self.send k, v
176
- end
177
- end
178
- end
179
-
180
- def method_missing method, *arg, &b
181
- @misc << method.to_s << " " << arg.map(&:to_s).join(' ')
182
- end
183
-
184
- def misc
185
- @misc.join(' ') unless @misc.empty?
186
- end
187
-
188
- def subquery
189
- nil
190
- end
191
- =begin
192
- Output the compiled query
193
- parmeter: destination (rest, batch )
194
- If the query is submitted via the REST-Interface (as get-command), the limit parameter is extracted.
195
- =end
196
- def compose( destination: :batch )
197
- if destination == :rest
198
- [ @kind, projection_s, from, let_s, where_s , subquery, misc, order_s , group_by, unwind, skip ].compact.join(' ')
199
- else
200
- [ @kind, projection_s, from, let_s, where_s , subquery, misc, order_s , group_by, limit, unwind, skip ].compact.join(' ')
201
- end
202
- end
203
- alias :to_s :compose
204
- =begin
205
- from can either be a Databaseclass to operate on or a Subquery providing data to query further
206
- =end
207
- def from arg=nil
208
- if arg.present?
209
- @database = case arg
210
- when Class
211
- arg.new.classname
212
- when ActiveOrient::Model
213
- classname
214
- when String
215
- arg
216
- when Symbol
217
- arg
218
- when OrientQuery
219
- ' ( '+ arg.to_s + ' ) '
220
- end
221
- compose # return the complete query
222
- else # read from
223
- "from " << @database.to_s unless @database.nil?
224
- end
225
- end
226
- alias :from= :from
227
- def database_class= arg
228
- @database = arg if @database.present?
229
- if @from.is_a? OrientQuery
230
- @from.database_class= arg
231
- end
232
- end
233
- def database_class
234
- if @database.present?
235
- @database
236
- elsif @from.is_a? OrientQuery
237
- @from.database_class
238
- else
239
- nil
240
- end
241
- end
242
-
243
-
244
- =begin
245
- Call where without a parameter to request the saved where-string
246
-
247
- to create the where-part of the query a string, a hash or an Array is supported
248
-
249
- where: "r > 9" --> where r > 9
250
- where: {a: 9, b: 's'} --> where a = 9 and b = 's'
251
- where:[{ a: 2} , 'b > 3',{ c: 'ufz' }] --> where a = 2 and b > 3 and c = 'ufz'
252
- =end
253
- attr_accessor :where
254
- def where_s
255
- compose_where @where
256
- end
257
-
258
-
259
- attr_accessor :let
260
- def let_s
261
- unless @let.empty?
262
- "let " << @let.map do |s|
263
- case s
264
- when Hash
265
- s.map{ |x,y| "$#{x} = ( #{y} )"}.join( ', ')
266
- when Array
267
- s.join(', ')
268
- else
269
- s
270
- end
271
- end.join(', ')
272
- end
273
- end
274
-
275
- def distinct d
276
- @projection << case d
277
- when String, Symbol
278
- "distinct( #{d.to_s} )"
279
- when Array
280
- "distinct( #{d.first} ) as #{d.last}"
281
- when Hash
282
- "distinct( #{d.first.first} ) as #{d.first.last}"
283
- else
284
- ""
285
- end
286
- compose # return the hole query
287
- end
288
- alias :distinct= :distinct
289
-
290
- attr_accessor :projection
291
- def projection_s
292
-
293
- @projection.map do | s |
294
- case s
295
- when Hash
296
- s.map{ |x,y| "#{x} as #{y}"}.join( ', ')
297
- when Array
298
- s.join(', ')
299
- else
300
- s
301
- end
302
- end.join( ', ' )
303
-
304
- end
305
-
306
-
307
- # def where= w
308
-
309
- # end
310
- # select_string = ("select " + select_string + distinct_string + ' from ' + class_name(o_class) ).squeeze(' ')
311
- # where_string = compose_where( where )
312
-
313
- def limit l=nil
314
- @limit = "limit #{l.to_s}" if l.present?
315
- # only a string is allowed
316
- @limit # return_value
317
- end
318
- alias :limit= :limit
319
- =begin :nodoc
320
- The Rest-Interface needs to separate the limit-value.
321
- This Method extracts the number, usage in REST::get_documents
322
-
323
- =end
324
- def get_limit
325
- @limit.nil? ? -1 : @limit.split(' ').last.to_i
326
- end
327
- def group_by g=nil
328
- @group = "group by #{g.to_s}" if g.present?
329
- # only a string is allowed
330
- @group # return_value
331
- end
332
- def unwind u=nil
333
- @unwind = "unwind #{u.to_s}" if u.present?
334
- # only a string is allowed
335
- @unwind # return_value
336
- end
337
-
338
- def skip n=nil
339
- @skip= n if n.present?
340
- "skip #{@skip}" if @skip.present?
341
- end
342
-
343
- attr_accessor :order
344
-
345
- def order_s
346
- unless @order.empty?
347
- # the [@order] is nessesary to enable query.order= "..." oder query.order= { a: :b }
348
- "order by " << [@order].flatten.map do | o |
349
- case o
350
- when Hash
351
- o.map{ |x,y| "#{x} #{y}" }.join( " " )
352
- else
353
- o.to_s
354
- end # case
355
- end.join(', ')
356
- else
357
- ''
358
- end
359
- end
360
- # misc_string = if skip > 0 && limit > 0
361
- # " skip: #{skip} "
362
- # else
363
- # ""
364
- # end
365
- # #
366
- #
367
- # def compose
368
- #
369
- # end
370
-
371
- end
372
- end # module
data/test.rb DELETED
@@ -1,4 +0,0 @@
1
- $:.unshift File.expand_path('.')
2
- require 'config/boot'
3
-
4
-
data/usecase.md DELETED
@@ -1,91 +0,0 @@
1
- ## Usecase
2
- Below some typical features are summarized by example
3
-
4
- Start a irb-session and initialize ActiveOrient
5
- ```ruby
6
- topo@gamma:~/new_hctw$ irb
7
- 2.2.1 :001 > require './config/boot'
8
- Using development-environment
9
- -------------------- initialize -------------------- => true
10
- 2.2.1 :002 > ActiveOrient::Model.orientdb = ror = ActiveOrient::OrientDB.new
11
- => #<ActiveOrient::OrientDB:0x000000046f1a90 @res=#<RestClient::Resource:0x000000046c0af8 @url="http://localhost:2480", @block=nil, @options={:user=>"hctw", :password=>"**"}>, @database="hc_database", @classes=[]>
12
- ```
13
- #### Object Mapping
14
- Lets create a class, put some content in it and perform basic oo-steps.
15
-
16
- Attributes(Properties) do not have to be formaly declared. However it is nessessary to introduce them properly. This is done with the »attributes«-Argument during the initialisation step or via
17
- »update«
18
-
19
- ``` ruby
20
- A = r.create_class 'my_a_class'
21
- => ActiveOrient::Model::Myaclass
22
- a = A.new_document attributes: { test: 45}
23
- a.update set: { a_array: aa= [ 1,4,'r', :r ] ,
24
- a_hash: { :a => 'b', b: 2 } }
25
- a.to_human
26
- => <Myaclass: a_array: [1, 4, "r", :r] a_hash: {:a=>"b", :b=>2} test: 45>
27
-
28
- ```
29
- Then the attibutes/properties can be handled as normal ruby objects ie.
30
-
31
- ``` ruby
32
- a.a_array << "a new element"
33
- a.a_hash[ :a_new_element ] = "value of the new element"
34
- a.test += 3
35
- a.test = 567
36
- a.update
37
- ```
38
- Objects are synchronized with the database with »update«. To revert changes, a »reload!« method is available.
39
-
40
- #### Contracts-Example
41
- Assume a Database, which is defined as
42
- ```
43
- create class Industries
44
- create class Categories
45
- create class SubCategories
46
- create class OpenInterest ABSTRACT
47
- create class Stocks extends Contracts
48
- create class Futures extends Contracts
49
- create class Options extends Contracts
50
- create class Forexes extends Contracts
51
- create property Industries.categories linkset
52
- create property Categories.subcategories linkset
53
- create property Categories.industry link
54
- create property SubCategories.category link
55
- create property SubCategories.contracts linkset
56
-
57
- create property Contracts.subcategory link
58
- create property Contracts.details link
59
- create property OpenInterest.contracts linkset
60
-
61
- ```
62
- This defines some conventional relations:
63
-
64
- OpenInterest -> Contracts <- Subcategory <- Category <- Industry
65
-
66
- with some oo-Behavior
67
- ```ruby
68
- 2.2.1 :003 > ror.class_hierachie base_class: 'Contracts'
69
- => ["Forexes", "Futures", "Options", "Stocks"]
70
- ```
71
-
72
- then the following ORM-behavior is implemented:
73
- ```ruby
74
- topo@gamma:~/new_hctw$ irb
75
- 2.2.1 :001 > require './config/boot'
76
- Using development-environment
77
- -------------------- initialize -------------------- => true
78
- 2.2.1 :002 > ActiveOrient::Model.orientdb = ror = ActiveOrient::OrientDB.new
79
- => #<ActiveOrient::OrientDB:0x000000046f1a90 @res=#<RestClient::Resource:0x000000046c0af8 @url="http://localhost:2480", @block=nil, @options={:user=>"hctw", :password=>"**"}>, @database="hc_database", @classes=[]>
80
- 2.2.1 :003 > OpenInterest = ror.open_class 'Openinterest'
81
- => ActiveOrient::Model::Openinterest
82
- 2.2.1 :004 > first_open_interest = OpenInterest.first
83
- => #<ActiveOrient::Model::Openinterest:0x0000000443ede8 @metadata={"type"=>"d", "class"=>"Openinterest", "version"=>5, "fieldTypes"=>"fetch_date=t,contracts=z", "cluster"=>13, "record"=>0}, @attributes={"fetch_date"=>"2015-06-02 00:00:00", "contracts"=>["#21:36", "#21:35", "#21:34", "#21:33", "#21:32", "#21:31", "#21:30", "#21:29", "#21:28", "#21:27", "#21:26", "#21:25", "#21:24", "#21:23", "#21:22", "#21:21", "#21:51", "#21:49", "#21:50", "#21:47", "#21:48", "#21:45", "#21:46", "#21:43", "#21:44", "#21:41", "#21:42", "#21:39", "#21:40", "#21:37", "#21:38", "#21:4", "#21:3", "#21:0", "#21:17", "#21:18", "#21:19", "#21:20", "#21:13", "#21:14", "#21:15", "#21:16", "#21:9", "#21:10", "#21:11", "#21:12", "#21:5", "#21:6", "#21:7", "#21:8"], "created_at"=>2015-07-01 15:27:41 +0200, "updated_at"=>2015-07-01 15:27:41 +0200}>
84
- 2.2.1 :005 > first_open_interest.contracts.first.subcategory.category.industry
85
- => #<ActiveOrient::Model::Industries:0x00000004af88f0 @metadata={"type"=>"d", "class"=>"Industries", "version"=>8, "fieldTypes"=>"categories=n", "cluster"=>17, "record"=>1}, @attributes={"categories"=>["#15:13", "#15:4", "#15:1"], "name"=>"Basic Materials", "created_at"=>2015-07-01 15:27:58 +0200, "updated_at"=>2015-07-01 15:27:58 +0200}>
86
-
87
- 2.2.1 :006 > first_open_interest.contracts.first.subcategory.category.industry.name
88
- => "Basic Materials"
89
- ```
90
-
91
-