active-orient 0.6 → 0.42

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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/Gemfile +4 -10
  4. data/Guardfile +4 -12
  5. data/README.md +198 -261
  6. data/VERSION +1 -1
  7. data/active-orient-0.4.gem +0 -0
  8. data/active-orient-0.41.gem +0 -0
  9. data/active-orient.gemspec +5 -6
  10. data/config/boot.rb +0 -84
  11. data/config/connect.yml +4 -8
  12. data/examples/books.rb +39 -86
  13. data/examples/streets.rb +84 -85
  14. data/lib/active-orient.rb +9 -57
  15. data/lib/base.rb +145 -172
  16. data/lib/base_properties.rb +44 -40
  17. data/lib/model.rb +468 -0
  18. data/lib/orient.rb +60 -114
  19. data/lib/query.rb +73 -71
  20. data/lib/rest.rb +1059 -0
  21. data/lib/support.rb +319 -386
  22. data/test.rb +4 -0
  23. data/usecase.md +91 -0
  24. metadata +20 -65
  25. data/bin/active-orient-console +0 -38
  26. data/config/config.yml +0 -10
  27. data/create_project +0 -19
  28. data/examples/test_commands.rb +0 -92
  29. data/examples/test_commands_2.rb +0 -54
  30. data/examples/test_commands_3.rb +0 -48
  31. data/examples/test_commands_4.rb +0 -28
  32. data/examples/time_graph.md +0 -162
  33. data/gratefuldeadconcerts.md +0 -94
  34. data/lib/class_utils.rb +0 -300
  35. data/lib/database_utils.rb +0 -106
  36. data/lib/init.rb +0 -45
  37. data/lib/java-api.rb +0 -437
  38. data/lib/jdbc.rb +0 -211
  39. data/lib/model/edge.rb +0 -55
  40. data/lib/model/model.rb +0 -91
  41. data/lib/model/the_class.rb +0 -500
  42. data/lib/model/the_record.rb +0 -322
  43. data/lib/model/vertex.rb +0 -136
  44. data/lib/orientdb_private.rb +0 -48
  45. data/lib/other.rb +0 -330
  46. data/lib/rest/change.rb +0 -137
  47. data/lib/rest/create.rb +0 -488
  48. data/lib/rest/delete.rb +0 -134
  49. data/lib/rest/operations.rb +0 -160
  50. data/lib/rest/read.rb +0 -150
  51. data/lib/rest/rest.rb +0 -112
  52. data/lib/rest_disabled.rb +0 -24
  53. data/linkmap.md +0 -75
  54. data/namespace.md +0 -111
  55. data/old_lib_functions/two_general_class.rb +0 -139
  56. data/rails.md +0 -125
  57. data/rails/activeorient.rb +0 -53
  58. data/rails/config.yml +0 -10
  59. data/rails/connect.yml +0 -17
  60. data/usecase_oo.md +0 -61
@@ -1,48 +0,0 @@
1
- module OrientDbPrivate
2
- private
3
-
4
- def translate_property_hash field, type: nil, linked_class: nil, **args
5
- type = type.presence || args[:propertyType].presence || args[:property_type]
6
- linked_class = linked_class.presence || args[:linkedClass] || args[:other_class]
7
- if type.present?
8
- if linked_class.nil?
9
- {field => {propertyType: type.to_s.upcase}}
10
- else
11
- {field => {propertyType: type.to_s.upcase, linkedClass: classname(linked_class)}}
12
- end
13
- end
14
- end
15
-
16
- def property_uri this_classname
17
- if block_given?
18
- "property/#{@database}/#{this_classname}/" << yield
19
- else
20
- "property/#{@database}/#{this_classname}"
21
- end
22
- end
23
-
24
- def self.simple_uri *names
25
- names.each do |name|
26
- m_name = ("#{name.to_s}_uri").to_sym
27
- define_method(m_name) do |&b|
28
- if b
29
- "#{name.to_s}/#{@database}/#{b.call}"
30
- else
31
- "#{name.to_s}/#{@database}"
32
- end # branch
33
- end
34
- end
35
- end
36
-
37
- def self.sql_uri *names
38
- names.each do |name|
39
- define_method(("#{name.to_s}_sql_uri").to_sym) do
40
- "#{name.to_s}/#{@database}/sql/"
41
- end
42
- end
43
- end
44
-
45
- simple_uri :database, :document, :class, :batch, :function
46
- sql_uri :command, :query
47
-
48
- end
@@ -1,330 +0,0 @@
1
- # Class create to manage to_orient and from_orient
2
-
3
- class Array
4
- def to_orient
5
- map( &:to_orient) # .join(',')
6
- end
7
-
8
- def from_orient
9
- map &:from_orient
10
- end
11
-
12
- def method_missing(method, *key)
13
- #if method == :to_int
14
- # return self.first
15
- #else
16
-
17
- unless method == :to_hash || method == :to_str #|| method == :to_int
18
- return self.map{|x| x.public_send(method, *key)}
19
- # end
20
- end
21
- end
22
- # used to enable
23
- # def abc *key
24
- # where key is a Range, an comma separated List or an item
25
- # aimed to support #compose_where
26
- def analyse
27
- if first.is_a?(Range)
28
- first
29
- elsif size ==1
30
- first
31
- else
32
- self
33
- end
34
-
35
- end
36
- end
37
-
38
- #class RecordList
39
- # def from_orient
40
- # map &:from_orient
41
- # end
42
- #end
43
- if RUBY_PLATFORM == 'java'
44
-
45
- ## JavaMath:.BigDecimal does not premit mathematical operations
46
- ## We convert it to RubyBigDecimal to represent it (if present in the DB) and upon loading from the DB
47
-
48
- class Java::JavaMath::BigDecimal
49
- def to_f
50
- BigDecimal.new self.to_s
51
- end
52
-
53
- def from_orient
54
- BigDecimal.new self.to_s
55
- end
56
-
57
- end
58
- class Java::ComOrientechnologiesOrientCoreDbRecordRidbag::ORidBag
59
- def from_orient
60
- to_a.from_orient
61
- end
62
- end
63
-
64
- class Java::ComOrientechnologiesOrientCoreDbRecord::OTrackedList
65
- # class RecordList
66
- # Basisklasse
67
- # Java::ComOrientechnologiesOrientCoreDbRecord::ORecordLazyList
68
- # Methode get(Index): gibt das Dokument (Java::ComOrientechnologiesOrientCoreRecordImpl::ODocument) zurück
69
- ## base = ActiveOrient::Model::Base.first
70
- ## base.document.first_list
71
- # => #<OrientDB::RecordList:[#21:0, #22:0, #23:0, #24:0, #21:1, #22:1, #23:1, #24:1, #21:2, #22:2]>
72
- ## base.first_list.get(3)
73
- # => <OrientDB::Document:first_list:#24:0 second_list:#<OrientDB::RecordList:[#27:17, #28:17, #25:18, #26:18, #27:18, #28:18, #25:19, #26:19, #27:19, #28:19]> label:3>
74
- ## base.first_list[3]
75
- # => #<ActiveOrient::Model::FirstList:0x18df26a1 (...)
76
- ## base.first_list[3].second_list[5]
77
- # => #<ActiveOrient::Model::SecondList: (...)
78
- ## base.first_list.get(3).second_list.get(5)
79
- # => <OrientDB::Document:second_list:#28:18 label:5>
80
- #
81
- def from_orient
82
- map &:from_orient
83
- self
84
- end
85
- def to_orient
86
- self
87
- end
88
-
89
- #def add value
90
- # puts "ASDSD"
91
- #end
92
- #
93
- def to_a
94
- super.map &:from_orient
95
- end
96
- def first
97
- super.from_orient
98
- end
99
- def last
100
- super.from_orient
101
- end
102
- def [] val
103
- super.from_orient
104
-
105
- end
106
-
107
- def << value
108
- #put "I will perform the insert"
109
- value = value.document if value.is_a?( ActiveOrient::Model ) && value.document.present?
110
- add value
111
- #save
112
-
113
- end
114
- end
115
-
116
- class Java::ComOrientechnologiesOrientCoreDbRecord::OTrackedMap
117
- def from_orient
118
-
119
- # puts self.inspect
120
- # puts self.keys.inspect
121
- HashWithIndifferentAccess.new(self)
122
- # Kernel.exit
123
- # map &:from_orient
124
- # to_a.from_orient
125
- end
126
-
127
- end
128
- class Java::JavaUtil::Date
129
- def from_orient
130
- Date.new(year+1900, month+1, date )
131
- end
132
- def to_orient
133
- self
134
- end
135
- end
136
-
137
-
138
- end
139
-
140
- class Symbol
141
- def from_orient
142
- self
143
- end
144
- def to_a
145
- [ self ]
146
- end
147
- end
148
- class FalseClass
149
- def from_orient
150
- self
151
- end
152
-
153
- def to_orient
154
- self
155
- end
156
- end
157
-
158
- class Hash #WithIndifferentAccess
159
- def from_orient
160
- substitute_hash = HashWithIndifferentAccess.new
161
- #keys.each{|k| puts self[k].inspect}
162
- keys.each{|k| substitute_hash[k] = self[k].from_orient}
163
- substitute_hash
164
- end
165
-
166
- def to_orient
167
- #puts "here hash"
168
- substitute_hash = Hash.new
169
- keys.each{|k| substitute_hash[k] = self[k].to_orient}
170
- substitute_hash
171
- end
172
-
173
- def nested_under_indifferent_access
174
- HashWithIndifferentAccess.new self
175
- end
176
- end
177
-
178
- class Date
179
- def to_orient
180
- if RUBY_PLATFORM == 'java'
181
- java.util.Date.new( year-1900, month-1, day , 0, 0 , 0 ) ## Jahr 0 => 1900
182
- else
183
- self
184
- end
185
- end
186
- def from_orient
187
- self
188
- end
189
- end
190
- ##module OrientDB
191
- #class Document
192
- # def from_orient
193
- # ActiveOrient::Model.autoload_object rid
194
- # end
195
- #end
196
- #end
197
- class NilClass
198
- def to_orient
199
- self
200
- end
201
- def from_orient
202
- nil
203
- end
204
-
205
- end
206
-
207
- class Numeric
208
- def from_orient
209
- self
210
- end
211
-
212
- def to_orient
213
- self
214
- end
215
-
216
- def to_or
217
- "#{self.to_s}"
218
- end
219
-
220
- def to_a
221
- [ self ]
222
- end
223
- end
224
-
225
- class String
226
- def capitalize_first_letter
227
- self.sub(/^(.)/) { $1.capitalize }
228
- end
229
-
230
- def where **args
231
- if rid?
232
- from_orient.where **args
233
- end
234
- end
235
-
236
- def from_orient
237
- if rid?
238
- ActiveOrient::Model.autoload_object self
239
- elsif
240
- self =~ /^:.*:$/
241
- self[1..-2].to_sym
242
- else
243
- self
244
- end
245
- end
246
- # alias :reload! from_orient
247
- # String#ToOrient: if the string contains "#xx:yy" omit quotes
248
- def to_orient
249
- if rid?
250
- if self[0] == "#"
251
- self
252
- else
253
- "#"+self
254
- end
255
- else
256
- self # return the sting (not the quoted string. this is to_or)
257
- end
258
- #self.gsub /%/, '(percent)'
259
- # quote
260
- end
261
-
262
- # a rid is either #nn:nn and nn:nn
263
- def rid?
264
- self =~ /\A[#]{,1}[0-9]{1,}:[0-9]{1,}\z/
265
- end
266
-
267
- # return a valid rid or nil
268
- def rid
269
- rid? ? self : nil
270
- end
271
-
272
- def to_classname
273
- if self[0] == '$'
274
- self[1..-1]
275
- else
276
- self
277
- end
278
- end
279
-
280
- def to_or
281
- quote
282
- end
283
-
284
- def to_a
285
- [ self ]
286
- end
287
-
288
- def quote
289
- str = self.dup
290
- if str[0, 1] == "'" && str[-1, 1] == "'"
291
- self
292
- else
293
- last_pos = 0
294
- while (pos = str.index("'", last_pos))
295
- str.insert(pos, "\\") if pos > 0 && str[pos - 1, 1] != "\\"
296
- last_pos = pos + 1
297
- end
298
- "'#{str}'"
299
- end
300
- end
301
-
302
-
303
- end
304
-
305
- class Symbol
306
- def to_orient
307
- ":"+self.to_s+":"
308
- end
309
- ## there is no "from_orient" as symbols are stored as strings
310
- end
311
-
312
- class Time
313
- def from_orient
314
- self
315
- end
316
-
317
- def to_orient
318
- self
319
- end
320
- end
321
-
322
- class TrueClass
323
- def from_orient
324
- self
325
- end
326
-
327
- def to_orient
328
- self
329
- end
330
- end
@@ -1,137 +0,0 @@
1
- module RestChange
2
-
3
- ############### DATABASE ####################
4
-
5
- # Changes the working-database to {name}
6
-
7
- def change_database name
8
- @classes = []
9
- @database = name
10
- ActiveOrient.database = name
11
- end
12
-
13
- ############# OBJECTS #################
14
-
15
- =begin
16
- Convient update of the dataset by calling sql-patch
17
-
18
- The argument record can be specified as ActiveOrient::Model-instance or as rid-string( #0:0 )
19
-
20
- called from ModelRecord#update
21
-
22
- if the update was successful, the updated ActiveOrient::Model-record is returned.
23
- =end
24
-
25
- def update record, attributes , version=0 # :nodoc:
26
- r = if record.is_a?(String) && record.rid?
27
- ActiveOrient::Model.autoload record
28
- else
29
- record
30
- end
31
- return(false) unless r.is_a?(ActiveOrient::Model)
32
- version = r.version if version.zero?
33
- result = patch_record(r.rid) do
34
- attributes.merge({'@version' => version, '@class' => r.class.ref_name })
35
- end
36
- # returns a new instance of ActiveOrient::Model and updates any reference on rid
37
- # if the patch is not successfull no string is returned and thus no record is fetched
38
- # puts JSON.parse(result) if result.is_a?(String)
39
- ActiveOrient::Model.orientdb_class(name: r.class.ref_name, superclass: :find_ME ).new(JSON.parse(result)) if result.is_a?(String)
40
- end
41
-
42
-
43
- =begin
44
- Example:
45
- ORD.update_documents classname, set: {:symbol => 'TWR'}, where: {con_id: 340}
46
-
47
- Replaces the symbol to TWR in each record where the con_id is 340
48
-
49
- Both set and where take multiple attributes
50
-
51
- Returns the JSON-Response.
52
- =end
53
-
54
- def update_records o_class, set:{}, where: {}, remove: nil
55
- logger.progname = 'RestChange#UpdateRecords'
56
- url = if set.present?
57
- "UPDATE #{classname(o_class)} SET #{generate_sql_list(set)} #{compose_where(where)}"
58
- elsif remove.present?
59
- "UPDATE #{classname(o_class)} remove #{remove} #{compose_where(where)}"
60
- end
61
- r = @res[URI.encode("/command/#{ActiveOrient.database}/sql/" << url)].post ''
62
- count_of_updated_records = (JSON.parse( r))['result'].first['value']
63
- ## remove all records of the class from cache
64
- ActiveOrient::Base.display_rid.delete_if{|x,y| y.is_a? o_class } if count_of_updated_records > 0 && o_class.is_a?(Class)
65
- count_of_updated_records # return_value
66
- rescue Exception => e
67
- logger.error{e.message}
68
- nil
69
-
70
-
71
- end
72
-
73
- # Lazy Updating of the given Record.
74
-
75
- def patch_record rid # :nodoc: (used by Model#update )
76
- logger.progname = 'RestChange#PatchRecord'
77
- content = yield
78
- if content.is_a? Hash
79
- begin
80
- @res["/document/#{ActiveOrient.database}/#{rid}"].patch content.to_orient.to_json
81
- rescue Exception => e
82
- logger.error{e.message}
83
- end
84
- else
85
- logger.error{"FAILED: The Block must provide an Hash with properties to be updated"}
86
- end
87
- end
88
- alias patch_document patch_record
89
-
90
-
91
- #### EXPERIMENTAL ##########
92
-
93
- =begin
94
- Used to add restriction or other properties to the Property of a Class.
95
- See http://orientdb.com/docs/2.1/SQL-Alter-Property.html
96
- =end
97
-
98
- def alter_property o_class, property:, attribute: "DEFAULT", alteration: # :nodoc: because untested
99
- logger.progname = 'RestChange#AlterProperty'
100
- begin
101
- attribute.to_s! unless attribute.is_a? String
102
- attribute.capitalize_first_letter
103
- case attribute
104
- when "LINKEDCLASS", "LINKEDTYPE", "NAME", "REGEX", "TYPE", "REGEX", "COLLATE", "CUSTOM"
105
- unless alteration.is_a? String
106
- logger.error{"#{alteration} should be a String."}
107
- return 0
108
- end
109
- when "MIN", "MAX"
110
- unless alteration.is_a? Integer
111
- logger.error{"#{alteration} should be an Integer."}
112
- return 0
113
- end
114
- when "MANDATORY", "NOTNULL", "READONLY"
115
- unless alteration.is_a? TrueClass or alteration.is_a? FalseClass
116
- logger.error{"#{alteration} should be an Integer."}
117
- return 0
118
- end
119
- when "DEFAULT"
120
- else
121
- logger.error{"Wrong attribute."}
122
- return 0
123
- end
124
-
125
- name_class = classname(o_class)
126
- execute name_class, transaction: false do # To execute commands
127
- [{ type: "cmd",
128
- language: 'sql',
129
- command: "ALTER PROPERTY #{name_class}.#{property} #{attribute} #{alteration}"}]
130
- end
131
- rescue Exception => e
132
- logger.error{e.message}
133
- end
134
- end
135
-
136
-
137
- end