active-orient 0.4 → 0.5

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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +8 -3
  4. data/Guardfile +12 -4
  5. data/README.md +221 -201
  6. data/VERSION +1 -1
  7. data/active-orient.gemspec +3 -2
  8. data/bin/active-orient-console +35 -0
  9. data/config/boot.rb +84 -16
  10. data/config/config.yml +10 -0
  11. data/config/connect.yml +6 -2
  12. data/create_project +19 -0
  13. data/examples/books.rb +86 -39
  14. data/examples/createTime.rb +91 -0
  15. data/examples/streets.rb +85 -84
  16. data/examples/test_commands.rb +92 -0
  17. data/examples/test_commands_2.rb +54 -0
  18. data/examples/test_commands_3.rb +48 -0
  19. data/examples/test_commands_4.rb +28 -0
  20. data/examples/time_graph/Gemfile +21 -0
  21. data/examples/time_graph/Guardfile +26 -0
  22. data/examples/time_graph/README.md +129 -0
  23. data/examples/time_graph/bin/active-orient-console +35 -0
  24. data/examples/time_graph/config/boot.rb +119 -0
  25. data/examples/time_graph/config/config.yml +8 -0
  26. data/examples/time_graph/config/connect.yml +17 -0
  27. data/examples/time_graph/config/init_db.rb +59 -0
  28. data/examples/time_graph/createTime.rb +51 -0
  29. data/examples/time_graph/lib/createTime.rb +82 -0
  30. data/examples/time_graph/model/day_of.rb +3 -0
  31. data/examples/time_graph/model/e.rb +6 -0
  32. data/examples/time_graph/model/edge.rb +53 -0
  33. data/examples/time_graph/model/monat.rb +19 -0
  34. data/examples/time_graph/model/stunde.rb +16 -0
  35. data/examples/time_graph/model/tag.rb +29 -0
  36. data/examples/time_graph/model/time_base.rb +6 -0
  37. data/examples/time_graph/model/time_of.rb +4 -0
  38. data/examples/time_graph/model/v.rb +3 -0
  39. data/examples/time_graph/model/vertex.rb +32 -0
  40. data/examples/time_graph/spec/lib/create_time_spec.rb +50 -0
  41. data/examples/time_graph/spec/rest_helper.rb +37 -0
  42. data/examples/time_graph/spec/spec_helper.rb +46 -0
  43. data/lib/active-orient.rb +56 -6
  44. data/lib/base.rb +149 -147
  45. data/lib/base_properties.rb +40 -41
  46. data/lib/class_utils.rb +301 -0
  47. data/lib/database_utils.rb +97 -0
  48. data/lib/init.rb +35 -0
  49. data/lib/java-api.rb +437 -0
  50. data/lib/jdbc.rb +211 -0
  51. data/lib/model/edge.rb +53 -0
  52. data/lib/model/model.rb +77 -0
  53. data/lib/model/the_class.rb +480 -0
  54. data/lib/model/the_record.rb +310 -0
  55. data/lib/model/vertex.rb +32 -0
  56. data/lib/orient.rb +113 -50
  57. data/lib/orientdb_private.rb +48 -0
  58. data/lib/other.rb +280 -0
  59. data/lib/query.rb +71 -73
  60. data/lib/rest/change.rb +124 -0
  61. data/lib/rest/create.rb +474 -0
  62. data/lib/rest/delete.rb +133 -0
  63. data/lib/rest/operations.rb +150 -0
  64. data/lib/rest/read.rb +150 -0
  65. data/lib/rest/rest.rb +111 -0
  66. data/lib/rest_disabled.rb +24 -0
  67. data/lib/support.rb +387 -296
  68. data/old_lib_functions/two_general_class.rb +139 -0
  69. data/usecase.md +49 -36
  70. data/usecase_oo.md +59 -0
  71. metadata +73 -9
  72. data/lib/model.rb +0 -461
  73. data/lib/rest.rb +0 -1036
  74. data/test.rb +0 -4
@@ -0,0 +1,48 @@
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
@@ -0,0 +1,280 @@
1
+ # Class create to manage to_orient and from_orient
2
+
3
+ class Array
4
+ def to_orient
5
+ map &:to_orient
6
+ end
7
+
8
+ def from_orient
9
+ map &:from_orient
10
+ end
11
+
12
+ def method_missing(method)
13
+ unless method == :to_hash || method == :to_str
14
+ return self.map{|x| x.public_send(method)}
15
+ end
16
+ end
17
+ end
18
+
19
+ #class RecordList
20
+ # def from_orient
21
+ # map &:from_orient
22
+ # end
23
+ #end
24
+ if RUBY_PLATFORM == 'java'
25
+ class Java::ComOrientechnologiesOrientCoreDbRecordRidbag::ORidBag
26
+ def from_orient
27
+ to_a.from_orient
28
+ end
29
+ end
30
+
31
+ class Java::ComOrientechnologiesOrientCoreDbRecord::OTrackedList
32
+ # class RecordList
33
+ # Basisklasse
34
+ # Java::ComOrientechnologiesOrientCoreDbRecord::ORecordLazyList
35
+ # Methode get(Index): gibt das Dokument (Java::ComOrientechnologiesOrientCoreRecordImpl::ODocument) zurück
36
+ ## base = ActiveOrient::Model::Base.first
37
+ ## base.document.first_list
38
+ # => #<OrientDB::RecordList:[#21:0, #22:0, #23:0, #24:0, #21:1, #22:1, #23:1, #24:1, #21:2, #22:2]>
39
+ ## base.first_list.get(3)
40
+ # => <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>
41
+ ## base.first_list[3]
42
+ # => #<ActiveOrient::Model::FirstList:0x18df26a1 (...)
43
+ ## base.first_list[3].second_list[5]
44
+ # => #<ActiveOrient::Model::SecondList: (...)
45
+ ## base.first_list.get(3).second_list.get(5)
46
+ # => <OrientDB::Document:second_list:#28:18 label:5>
47
+ #
48
+ def from_orient
49
+ map &:from_orient
50
+ self
51
+ end
52
+ def to_orient
53
+ self
54
+ end
55
+
56
+ #def add value
57
+ # puts "ASDSD"
58
+ #end
59
+ #
60
+ def to_a
61
+ super.map &:from_orient
62
+ end
63
+ def first
64
+ super.from_orient
65
+ end
66
+ def last
67
+ super.from_orient
68
+ end
69
+ def [] val
70
+ super.from_orient
71
+
72
+ end
73
+
74
+ def << value
75
+ #put "I will perform the insert"
76
+ value = value.document if value.is_a?( ActiveOrient::Model ) && value.document.present?
77
+ add value
78
+ #save
79
+
80
+ end
81
+ end
82
+
83
+ class Java::ComOrientechnologiesOrientCoreDbRecord::OTrackedMap
84
+ def from_orient
85
+
86
+ # puts self.inspect
87
+ # puts self.keys.inspect
88
+ HashWithIndifferentAccess.new(self)
89
+ # Kernel.exit
90
+ # map &:from_orient
91
+ # to_a.from_orient
92
+ end
93
+
94
+ end
95
+ class Java::JavaUtil::Date
96
+ def from_orient
97
+ Date.new(year+1900, month+1, date )
98
+ end
99
+ def to_orient
100
+ self
101
+ end
102
+ end
103
+
104
+
105
+ end
106
+
107
+ class Symbol
108
+ def from_orient
109
+ self
110
+ end
111
+ end
112
+ class FalseClass
113
+ def from_orient
114
+ self
115
+ end
116
+
117
+ def to_orient
118
+ self
119
+ end
120
+ end
121
+
122
+ class Hash #WithIndifferentAccess
123
+ def from_orient
124
+ substitute_hash = HashWithIndifferentAccess.new
125
+ #keys.each{|k| puts self[k].inspect}
126
+ keys.each{|k| substitute_hash[k] = self[k].from_orient}
127
+ substitute_hash
128
+ end
129
+
130
+ def to_orient
131
+ #puts "here hash"
132
+ substitute_hash = Hash.new
133
+ keys.each{|k| substitute_hash[k] = self[k].to_orient}
134
+ substitute_hash
135
+ end
136
+
137
+ def nested_under_indifferent_access
138
+ HashWithIndifferentAccess.new self
139
+ end
140
+ end
141
+
142
+ class Date
143
+ def to_orient
144
+ if RUBY_PLATFORM == 'java'
145
+ java.util.Date.new( year-1900, month-1, day , 0, 0 , 0 ) ## Jahr 0 => 1900
146
+ else
147
+ self
148
+ end
149
+ end
150
+ def from_orient
151
+ self
152
+ end
153
+ end
154
+ ##module OrientDB
155
+ #class Document
156
+ # def from_orient
157
+ # ActiveOrient::Model.autoload_object rid
158
+ # end
159
+ #end
160
+ #end
161
+ class NilClass
162
+ def to_orient
163
+ self
164
+ end
165
+ def from_orient
166
+ nil
167
+ end
168
+ end
169
+
170
+ class Numeric
171
+ def from_orient
172
+ self
173
+ end
174
+
175
+ def to_orient
176
+ self
177
+ end
178
+
179
+ def to_or
180
+ "#{self.to_s}"
181
+ end
182
+ end
183
+
184
+ class String
185
+ def capitalize_first_letter
186
+ self.sub(/^(.)/) { $1.capitalize }
187
+ end
188
+
189
+ def from_orient
190
+ if rid?
191
+ ActiveOrient::Model.autoload_object self
192
+ elsif
193
+ self =~ /^:.*:$/
194
+ self[1..-2].to_sym
195
+ else
196
+ self
197
+ end
198
+ end
199
+ # alias :reload! from_orient
200
+ # String#ToOrient: if the string contains "#xx:yy" omit quotes
201
+ def to_orient
202
+ if rid?
203
+ if self[0] == "#"
204
+ self
205
+ else
206
+ "#"+self
207
+ end
208
+ else
209
+ self # return the sting (not the quoted string. this is to_or)
210
+ end
211
+ #self.gsub /%/, '(percent)'
212
+ # quote
213
+ end
214
+
215
+ # a rid is either #nn:nn and nn:nn
216
+ def rid?
217
+ self =~ /\A[#]{,1}[0-9]{1,}:[0-9]{1,}\z/
218
+ end
219
+
220
+ # return a valid rid or nil
221
+ def rid
222
+ rid? ? self : nil
223
+ end
224
+
225
+ def to_classname
226
+ if self[0] == '$'
227
+ self[1..-1]
228
+ else
229
+ self
230
+ end
231
+ end
232
+
233
+ def to_or
234
+ quote
235
+ end
236
+
237
+
238
+ def quote
239
+ str = self.dup
240
+ if str[0, 1] == "'" && str[-1, 1] == "'"
241
+ self
242
+ else
243
+ last_pos = 0
244
+ while (pos = str.index("'", last_pos))
245
+ str.insert(pos, "\\") if pos > 0 && str[pos - 1, 1] != "\\"
246
+ last_pos = pos + 1
247
+ end
248
+ "'#{str}'"
249
+ end
250
+ end
251
+
252
+
253
+ end
254
+
255
+ class Symbol
256
+ def to_orient
257
+ ":"+self.to_s+":"
258
+ end
259
+ ## there is no "from_orient" as symbols are stored as strings
260
+ end
261
+
262
+ class Time
263
+ def from_orient
264
+ self
265
+ end
266
+
267
+ def to_orient
268
+ self
269
+ end
270
+ end
271
+
272
+ class TrueClass
273
+ def from_orient
274
+ self
275
+ end
276
+
277
+ def to_orient
278
+ self
279
+ end
280
+ end
@@ -1,88 +1,86 @@
1
+ module ActiveOrient # :nodoc:
1
2
 
2
- module ActiveOrient
3
- class Query < ActiveOrient::Model
3
+ ## this is depreciated and not maintained anymore
4
+ class Query < ActiveOrient::Model
4
5
 
5
- has_many :records
6
- has_many :queries
6
+ has_many :records
7
+ has_many :queries
7
8
 
8
- def reset_records
9
- self.records= []
10
- end
11
- alias reset_results reset_records
9
+ def reset_records
10
+ self.records= []
11
+ end
12
+ alias reset_results reset_records
13
+
14
+ def reset_queries
15
+ self.queries = []
16
+ end
12
17
 
13
- def reset_queries
14
- self.queries = []
15
- end
16
18
  =begin
17
- calls ActiveOrient::ActiveOrient#GetDocuments
18
- stores the query in the query-stack and saves the result in the record-Array
19
+ Calls ActiveOrient::ActiveOrient#GetRecords
20
+ Stores the query in the query-stack and saves the result in the record-Array
19
21
 
20
- returns the count of assigned records
22
+ Returns the count of assigned records
21
23
  =end
22
24
 
23
- def get_documents o_class , **args
24
-
25
- query = OrientSupport::OrientQuery.new class_name(o_class), args
26
- self.queries << query.compose
27
- count= 0
28
- orientdb.get_documents( o_class , query: query.compose ).each{|c| records << c; count+=1 }
29
- count
30
- end
25
+ def get_records o_class , **args
26
+ query = OrientSupport::OrientQuery.new classname(o_class), args
27
+ self.queries << query.compose
28
+ count = 0
29
+ orientdb.get_records(o_class, query: query.compose).each{|c| records << c; count += 1}
30
+ count
31
+ end
32
+ alias get_documents get_records
31
33
 
32
34
  =begin
33
- All predefined queries are send to the database.
34
- The result is stored in the records.
35
- Unknown Records are of Type ActiveOrient::Model::Myquery, uses ActiveOrient::Orientdb.execute which tries to autosuggest the ActiveOrient::Model::{Class}
35
+ All predefined queries are send to the database.
36
+ The result is stored in the records.
37
+ Unknown Records are of Type ActiveOrient::Model::Myquery, uses ActiveOrient::Orientdb.execute which tries to autosuggest the ActiveOrient::Model::{Class}
36
38
 
37
- example: Multible Records
38
- ach = ActiveOrient::Query.new
39
- ach.queries << 'create class Contracts ABSTRACT'
40
- ach.queries << 'create property Contracts.details link'
41
- ach.queries << 'create class Stocks extends Contracts'
42
- result = ach.execute_queries transaction: false
43
-
44
- example: Batch
45
- q = ActiveOrient::Query.new
46
- q.queries << [
47
- "select expand( contracts ) from Openinterest"
48
- "let con = select expand( contracts ) from Openinterest; ",
49
- "let sub = select from Subcategories where contracts in $con;",
50
- "let cat = select from Categories where subcategories in $sub;",
51
- "let ind = select from Industries where categories in $cat;",
52
- "SELECT expand(unionall) FROM (SELECT unionall( $con, $cat))"
53
- ]
54
- q.execute_queries.each{|x| puts "X #{x.inspect}" }
39
+ example: Multible Records
40
+ ach = ActiveOrient::Query.new
41
+ ach.queries << 'create class Contracts ABSTRACT'
42
+ ach.queries << 'create property Contracts.details link'
43
+ ach.queries << 'create class Stocks extends Contracts'
44
+ result = ach.execute_queries transaction: false
55
45
 
46
+ example: Batch
47
+ q = ActiveOrient::Query.new
48
+ q.queries << [
49
+ "select expand( contracts ) from Openinterest"
50
+ "let con = select expand( contracts ) from Openinterest;",
51
+ "let sub = select from Subcategories where contracts in $con;",
52
+ "let cat = select from Categories where subcategories in $sub;",
53
+ "let ind = select from Industries where categories in $cat;",
54
+ "SELECT expand(unionall) FROM (SELECT unionall( $con, $cat))"
55
+ ]
56
+ q.execute_queries.each{|x| puts "X #{x.inspect}" }
56
57
  =end
57
- def execute_queries reset: true, transaction: true
58
- reset_records if reset
59
- begin
60
- orientdb.execute( transaction: transaction ) do
61
- result = queries.map do |q|
62
- # command: words are seperated by one space only, thus squeeze multible spaces
63
- sql_cmd = -> (command) { { type: "cmd", language: "sql", command: command.squeeze(' ') } }
64
- batch_cmd = ->( command_array ){ {type: "script", language: "sql", script: command_array } }
65
- case q
66
- when String
67
- sql_cmd[ q ]
68
- when Hash
69
- q
70
- when Array
71
- batch_cmd[ q ]
72
- else
73
- nil
74
- end # case
75
- end.compact
76
- # save the result in records
77
- result.each{|y| records << y }
78
-
79
- end # block
80
- rescue RestClient::InternalServerError => e
81
- puts e.inspect
82
- end
83
-
84
- end # def execute_queries
85
-
86
- end # class
87
58
 
59
+ def execute_queries reset: true, transaction: true
60
+ reset_records if reset
61
+ begin
62
+ orientdb.execute( transaction: transaction ) do
63
+ result = queries.map do |q|
64
+ # command: words are seperated by one space only, thus squeeze multible spaces
65
+ sql_cmd = -> (command) {{type: "cmd", language: "sql", command: command.squeeze(' ') }}
66
+ batch_cmd = -> (command_array){{type: "script", language: "sql", script: command_array}}
67
+ case q
68
+ when String
69
+ sql_cmd[q]
70
+ when Hash
71
+ q
72
+ when Array
73
+ batch_cmd[q]
74
+ else
75
+ nil
76
+ end # case
77
+ end.compact
78
+ # save the result in records
79
+ result.each{|y| records << y}
80
+ end # block
81
+ rescue RestClient::InternalServerError => e
82
+ puts e.inspect
83
+ end
84
+ end # def execute_queries
85
+ end # class
88
86
  end # module