active-orient 0.6 → 0.42

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 +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,59 +1,11 @@
1
+ require "support.rb"
2
+ require "base.rb"
3
+ require "base_properties.rb"
1
4
 
2
- module OrientDB
3
- UsingJava = RUBY_PLATFORM == 'java' ? true : false
4
- unless UsingJava
5
- DocumentDatabase = nil
6
- DocumentDatabasePool = nil
7
- DocumentDatabasePooled = nil
8
- GraphDatabase = nil
9
- OTraverse = nil
10
- Document = nil
11
- IndexType = nil
12
- OClassImpl = nil
13
- PropertyImpl = nil
14
- Schema = nil
15
- SchemaProxy = nil
16
- SchemaType = nil
17
- SQLCommand = nil
18
- SQLSynchQuery = nil
19
- User = nil
20
- RemoteStorage = nil
21
- ServerAdmin = nil
22
- # defined in other.rb
23
- #JavaDate
24
- #RecordList = nil
25
- # RidBag = nil
26
- # RecordSet = nil
27
- end
28
- end # module OrientDB
29
- require 'active_model'
30
- #require 'active_model/serializers'
31
- require_relative "support.rb"
32
- require_relative "base.rb"
33
- require_relative "base_properties.rb"
34
- require_relative "orient.rb"
35
- #require_relative "query.rb"
36
- if OrientDB::UsingJava
37
- require_relative 'java-api.rb'
38
- end
39
- require_relative "orientdb_private.rb" # manage private functions
40
- require_relative "database_utils.rb" #common methods without rest.specific content
41
- require_relative "class_utils.rb" #common methods without rest.specific content
42
- require_relative "other.rb"
43
- require_relative "rest/rest.rb"
44
- require_relative "model/model.rb"
45
- require 'active_support/core_ext/string' # provides blank?, present?, presence etc
46
- require_relative 'init.rb'
47
- # create Base Classes
48
- require_relative "model/edge.rb"
49
- require_relative "model/vertex.rb"
50
-
51
- module ActiveOrient
52
- mattr_accessor :database
53
- mattr_accessor :database_classes
54
- mattr_accessor :default_server
55
-
56
-
57
-
58
- end
5
+ require "model.rb"
6
+ require "orient.rb"
7
+ require "rest.rb"
59
8
 
9
+ logger = Logger.new '/dev/stdout'
10
+ ActiveOrient::Model.logger = logger
11
+ ActiveOrient::OrientDB.logger = logger
@@ -1,255 +1,228 @@
1
1
  module ActiveOrient
2
-
3
-
4
- # Base class for tableless IB data Models, extends ActiveModel API
5
-
2
+ require 'active_model'
3
+ #
4
+ # Base class for tableless IB data Models, extends ActiveModel API
6
5
  class Base
7
6
  extend ActiveModel::Naming
8
7
  extend ActiveModel::Callbacks
9
8
  include ActiveModel::Validations
10
9
  include ActiveModel::Serialization
11
- # include ActiveModel::Serializers::Xml
10
+ include ActiveModel::Serializers::Xml
12
11
  include ActiveModel::Serializers::JSON
13
- include OrientDB
14
-
15
- define_model_callbacks :initialize
16
-
17
- # ActiveRecord::Base callback API mocks
18
- define_model_callbacks :initialize, :only => :after
19
- mattr_accessor :logger
12
+
20
13
 
21
- # Used to read the metadata
22
- attr_reader :metadata
14
+ ##Every Rest::Base-Object is stored in the @@rid_store
15
+ ## The Objects are just references to the @@rid_store.
16
+ ## any Change of the Object is thus synchonized to any allocated variable
17
+ #
18
+ @@rid_store = Hash.new
23
19
 
24
- =begin
25
- Every Rest::Base-Object is stored in the @@rid_store
26
- The Objects are just references to the @@rid_store.
27
- Any Change of the Object is thus synchonized to any allocated variable.
28
- =end
29
- @@rid_store = Hash.new
30
-
31
- def self.display_rid
20
+ def self.display_riid
32
21
  @@rid_store
33
22
  end
34
-
35
- def self.remove_rid obj
36
- @@rid_store.delete obj.rid
37
- end
38
-
39
- def self.get_rid rid
40
- rid = rid[1..-1] if rid[0]=='#'
41
- @@rid_store[rid]
23
+ def self.remove_riid obj
24
+ @@rid_store[obj.riid]=nil
42
25
  end
26
+ def self.get_riid link
43
27
 
44
- def self.reset_rid_store
45
- @@rid_store = Hash.new
46
28
  end
47
-
48
- def self.store_rid obj
49
- if obj.rid.present? && obj.rid.rid?
50
- # return the presence of a stored object as true by the block
51
- # the block is only executed if the presence is confirmed
52
- # Nothing is returned from the class-method
53
- if @@rid_store[obj.rid].present?
54
- yield if block_given?
55
- end
56
- @@rid_store[obj.rid] = obj
57
- @@rid_store[obj.rid] # return_value
29
+ def self.store_riid obj
30
+ if obj.rid.present? && obj.riid.all?{|x| x.present? && x>=0} # only positive values are stored
31
+ ## return the presence of a stored object as true by the block
32
+ ## the block is only executed if the presence is confirmed
33
+ ## Nothing is returned from the class-method
34
+ if @@rid_store[obj.riid].present?
35
+ yield if block_given?
36
+ end
37
+ @@rid_store[obj.riid] = obj
38
+ @@rid_store[obj.riid] # return_value
58
39
  else
59
- obj # no rid-value: just return the obj
40
+ obj # no rid-value: just return the obj
60
41
  end
61
42
  end
62
43
 
63
- def document
64
- @d
65
- end
66
44
 
67
- =begin
68
- If a opts hash is given, keys are taken as attribute names, values as data.
69
- The model instance fields are then set automatically from the opts Hash.
70
- =end
45
+ define_model_callbacks :initialize
71
46
 
72
- def initialize attributes = {}, opts = {}
73
- logger.progname = "ActiveOrient::Base#initialize"
47
+ mattr_accessor :logger
48
+ # If a opts hash is given, keys are taken as attribute names, values as data.
49
+ # The model instance fields are then set automatically from the opts Hash.
50
+ def initialize attributes={}, opts={}
51
+ logger.progname= "ActiveOrient::Base#initialize"
52
+ #possible_link_array_candidates = link_candidates = Hash.new
74
53
  @metadata = HashWithIndifferentAccess.new
75
- @d = nil
54
+ # @edges = HashWithIndifferentAccess.new
55
+
76
56
  run_callbacks :initialize do
77
- if RUBY_PLATFORM == 'java' && attributes.is_a?( Document )
78
- @d = attributes
79
- attributes = @d.values
80
- @metadata[:class] = @d.class_name
81
- @metadata[:version] = @d.version
82
- @metadata[:cluster], @metadata[:record] = @d.rid[1,@d.rid.size].split(':')
83
-
84
-
85
-
86
- end
87
- attributes.keys.each do |att|
88
- unless att[0] == "@" # @ identifies Metadata-attributes
89
- att = att.to_sym if att.is_a?(String)
90
- unless self.class.instance_methods.detect{|x| x == att}
91
- self.class.define_property att, nil
57
+ # puts "initialize::attributes: #{attributes.inspect}"
58
+
59
+ attributes.keys.each do | att |
60
+ unless att[0] == "@" # @ identifies Metadata-attributes
61
+ att = att.to_sym if att.is_a?(String)
62
+ unless self.class.instance_methods.detect{|x| x == att }
63
+ self.class.define_property att, nil
64
+ # logger.debug { "property #{att.to_s} assigned to #{self.class.to_s}" }
92
65
  else
93
- #logger.info{"Property #{att.to_s} NOT assigned"}
66
+ # logger.info{ "property #{att.to_s} NOT assigned " }
94
67
  end
95
68
  end
96
69
  end
97
70
 
98
- if attributes['@type'] == 'd' # document via REST
99
- @metadata[:type] = attributes.delete '@type'
100
- @metadata[:class] = attributes.delete '@class'
101
- @metadata[:version] = attributes.delete '@version'
102
- @metadata[:fieldTypes] = attributes.delete '@fieldTypes'
103
- if attributes.has_key?('@rid')
104
- rid = attributes.delete '@rid'
105
- cluster, record = rid[1,rid.size].split(':')
106
- @metadata[:cluster] = cluster.to_i
107
- @metadata[:record] = record.to_i
71
+ if attributes['@type'] == 'd' # document
72
+ @metadata[ :type ] = attributes.delete '@type'
73
+ @metadata[ :class ] = attributes.delete '@class'
74
+ @metadata[ :version ] = attributes.delete '@version'
75
+ @metadata[ :fieldTypes ] = attributes.delete '@fieldTypes'
76
+ if attributes.has_key?( '@rid' )
77
+ rid = attributes.delete '@rid'
78
+ cluster, record = rid[1,rid.size].split(':')
79
+ @metadata[ :cluster ] = cluster.to_i
80
+ @metadata[ :record ] = record.to_i
81
+
108
82
  end
109
83
 
110
- if @metadata[:fieldTypes ].present? && (@metadata[:fieldTypes] =~ /=g/)
111
- @metadata[:edges] = { :in => [], :out => [] }
84
+ #### edges -- remove in_ and out_ and de-capitalize the remaining edge
85
+ if @metadata[ :fieldTypes ].present? && (@metadata[ :fieldTypes ] =~ /=g/)
112
86
  edges = @metadata['fieldTypes'].split(',').find_all{|x| x=~/=g/}.map{|x| x.split('=').first}
113
- # puts "Detected EDGES: #{edges.inspect}"
114
87
  edges.each do |edge|
115
- operator, *base_edge = edge.split('_')
88
+ operator, *base_edge = edge.split('_')
116
89
  base_edge = base_edge.join('_')
117
- @metadata[:edges][operator.to_sym] << base_edge
90
+ unless self.class.instance_methods.detect{|x| x == base_edge }
91
+ ## define two methods: out_{Edge}/{in_Edge} -> edge.
92
+ self.class.define_property base_edge, nil
93
+ self.class.send :alias_method, base_edge.underscore, edge #
94
+ # logger.debug { "#{link}:: edge #{edge} assigned to #{self.class.to_s} and remaped to #{base_edge.underscore}" }
95
+
96
+ end
118
97
  end
119
- # unless self.class.instance_methods.detect{|x| x == base_edge}
120
- # ## define two methods: out_{Edge}/in_{Edge} -> edge.
121
- # self.class.define_property base_edge, nil
122
- # allocate_edge_method = -> (edge) do
123
- # unless (ee=db.get_db_superclass(edge)) == "E"
124
- # allocate_edge_method[ee]
125
- # self.class.send :alias_method, base_edge.underscore, edge
126
- # ## define inherented classes, tooa
127
- #
128
-
129
- # end
130
- # end
131
98
  end
132
99
  end
133
- self.attributes = attributes # set_attribute_defaults is now after_init callback
100
+
101
+
102
+ self.attributes = attributes # set_attribute_defaults is now after_init callback
103
+ end
104
+ ActiveOrient::Base.store_riid self
134
105
  end
135
- # puts "Storing #{self.rid} to rid-store"
136
- ActiveOrient::Base.store_rid self
137
- end
138
106
 
139
- # ActiveModel API (for serialization)
107
+ # ActiveModel API (for serialization)
140
108
 
141
109
  def attributes
142
110
  @attributes ||= HashWithIndifferentAccess.new
143
111
  end
144
112
 
145
113
  def attributes= attrs
146
- attrs.keys.each{|key| self.send("#{key}=", attrs[key])}
114
+ attrs.keys.each { |key| self.send("#{key}=", attrs[key]) }
147
115
  end
148
116
 
149
- def my_metadata key: nil, symbol: nil
150
- if @metadata[:fieldTypes].present?
151
- meta= Hash[ @metadata['fieldTypes'].split(',').map{|x| x.split '='} ]
152
- if key.present?
153
- meta[key.to_s]
154
- elsif symbol.present?
155
- meta.map{|x,y| x if y == symbol.to_s }.compact
117
+ # ActiveModel-style read/write_attribute accessors
118
+ # Here we define the autoload mechanism
119
+ def [] key
120
+
121
+ iv= attributes[key.to_sym]
122
+ # iv.from_orient unless iv.nil?
123
+ if iv.is_a?(String) && iv.rid? #&& @metadata[:fieldTypes].present? && @metadata[:fieldTypes].include?( key.to_s+"=x" )
124
+
125
+
126
+ # puts "autoload: #{iv}"
127
+ ActiveOrient::Model.autoload_object iv
128
+ elsif iv.is_a?(Array) # && @metadata[:fieldTypes].present? && @metadata[:fieldTypes].match( key.to_s+"=[znmgx]" )
129
+ # puts "autoload: #{iv.inspect}"
130
+ OrientSupport::Array.new self, *iv.map{|y| (y.is_a?(String) && y.rid?) ? ActiveOrient::Model.autoload_object( y ) : y }
131
+ else
132
+
133
+ if @metadata[:fieldTypes].present? && @metadata[:fieldTypes].include?( key.to_s+"=t" ) # time
134
+ # switch between date and datetime representation of the date-object
135
+ iv =~ /00:00:00/ ? Date.parse( iv ) : DateTime.parse( iv )
156
136
  else
157
- meta
137
+ iv
158
138
  end
159
139
  end
160
140
  end
161
141
 
142
+ def update_attribute key, value
143
+ @attributes[key] = value
144
+ end
162
145
  =begin
163
- ActiveModel-style read/write_attribute accessors
164
- Autoload mechanism and data conversion are defined in the method "from_orient" of each class
146
+ Here we define how the attributes are initialized
147
+ Key and val are set by the RestCliend
165
148
  =end
166
-
167
- def [] key
168
- iv = attributes[key.to_sym]
169
- # puts my_metadata( key: key)
170
- if my_metadata( key: key) == "t"
171
- # puts "time detected"
172
- iv =~ /00:00:00/ ? Date.parse(iv) : DateTime.parse(iv)
173
- elsif my_metadata( key: key) == "x"
174
- iv = ActiveOrient::Model.autoload_object iv
175
- elsif iv.is_a? Array
176
- OrientSupport::Array.new( work_on: self, work_with: iv.from_orient){ key.to_sym }
177
- elsif iv.is_a? Hash
178
- OrientSupport::Hash.new( self, iv){ key.to_sym }
179
- # elsif iv.is_a? RecordMap
180
- # iv
181
- # puts "RecordSet detected"
182
- else
183
- iv.from_orient
184
- end
185
- end
186
-
187
149
  def []= key, val
188
- # puts "here I am: #{key}, #{val}"
189
- val = val.rid if val.is_a?( ActiveOrient::Model ) && val.rid.rid?
150
+ val = val.rid if val.is_a? ActiveOrient::Model
151
+ # if val.is_a?(Array) # && @metadata[:fieldTypes].present? && @metadata[:fieldTypes].include?( key.to_s+"=n" )
152
+ # if @metadata[ :fieldTypes ] =~ /out=x,in=x/
153
+ # puts "VAL is a ARRAY"
154
+ # else
155
+ # puts "METADATA: #{ @metadata[ :fieldTypes ]} "
156
+ # end
157
+ # val# = val.map{|x| if val.is_a? ActiveOrient::Model then val.rid else val end }
158
+ # end
190
159
  attributes[key.to_sym] = case val
191
- when Array
192
- # puts "I am an Array"
193
- if val.first.is_a?(Hash)
194
- v = val.map do |x|
195
- if x.is_a?(Hash)
196
- HashWithIndifferentAccess.new(x)
197
- else
198
- x
199
- end
200
- end
201
- OrientSupport::Array.new(work_on: self, work_with: v )
202
- else
203
- OrientSupport::Array.new(work_on: self, work_with: val )
204
- end
205
- when Hash
206
- HashWithIndifferentAccess.new(val)
207
- else
208
- val
209
- end
210
- end
211
-
212
- def update_attribute key, value
213
- @attributes[key] = value
160
+ when Array
161
+ if val.first.is_a?(Hash)
162
+ v=val.map do |x|
163
+ if x.is_a?( Hash )
164
+ HashWithIndifferentAccess.new(x)
165
+ else
166
+ x
167
+ end
168
+ end
169
+ OrientSupport::Array.new( self, *v )
170
+ else
171
+ OrientSupport::Array.new( self, *val )
172
+ end
173
+ when Hash
174
+ HashWithIndifferentAccess.new(val)
175
+ else
176
+ val
177
+ end
178
+
214
179
  end
215
180
 
216
181
  def to_model
217
182
  self
218
183
  end
219
184
 
220
- # Noop methods mocking ActiveRecord::Base macros
221
185
 
186
+
187
+ ### Noop methods mocking ActiveRecord::Base macros
188
+
222
189
  def self.attr_protected *args
223
190
  end
224
191
 
225
192
  def self.attr_accessible *args
226
193
  end
227
194
 
228
- # ActiveRecord::Base association API mocks
229
- #
195
+ ### ActiveRecord::Base association API mocks
196
+
230
197
  def self.belongs_to model, *args
231
198
  attr_accessor model
232
199
  end
233
- #
200
+
234
201
  def self.has_one model, *args
235
202
  attr_accessor model
236
203
  end
237
- #
204
+
238
205
  def self.has_many models, *args
239
206
  attr_accessor models
207
+
240
208
  define_method(models) do
241
- self.instance_variable_get("@#{models}") || self.instance_variable_set("@#{models}", [])
209
+ self.instance_variable_get("@#{models}") ||
210
+ self.instance_variable_set("@#{models}", [])
242
211
  end
243
212
  end
244
- #
245
- # def self.find *args
246
- # []
247
- # end
248
- #
249
- # ActiveRecord::Base misc
213
+
214
+ def self.find *args
215
+ []
216
+ end
217
+
218
+ ### ActiveRecord::Base callback API mocks
219
+
220
+ define_model_callbacks :initialize, :only => :after
221
+
222
+ ### ActiveRecord::Base misc
250
223
 
251
224
  def self.serialize *properties
252
225
  end
253
226
 
254
227
  end # Model
255
- end # module
228
+ end # module