active-orient 0.6 → 0.42
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile +4 -10
- data/Guardfile +4 -12
- data/README.md +198 -261
- data/VERSION +1 -1
- data/active-orient-0.4.gem +0 -0
- data/active-orient-0.41.gem +0 -0
- data/active-orient.gemspec +5 -6
- data/config/boot.rb +0 -84
- data/config/connect.yml +4 -8
- data/examples/books.rb +39 -86
- data/examples/streets.rb +84 -85
- data/lib/active-orient.rb +9 -57
- data/lib/base.rb +145 -172
- data/lib/base_properties.rb +44 -40
- data/lib/model.rb +468 -0
- data/lib/orient.rb +60 -114
- data/lib/query.rb +73 -71
- data/lib/rest.rb +1059 -0
- data/lib/support.rb +319 -386
- data/test.rb +4 -0
- data/usecase.md +91 -0
- metadata +20 -65
- data/bin/active-orient-console +0 -38
- data/config/config.yml +0 -10
- data/create_project +0 -19
- data/examples/test_commands.rb +0 -92
- data/examples/test_commands_2.rb +0 -54
- data/examples/test_commands_3.rb +0 -48
- data/examples/test_commands_4.rb +0 -28
- data/examples/time_graph.md +0 -162
- data/gratefuldeadconcerts.md +0 -94
- data/lib/class_utils.rb +0 -300
- data/lib/database_utils.rb +0 -106
- data/lib/init.rb +0 -45
- data/lib/java-api.rb +0 -437
- data/lib/jdbc.rb +0 -211
- data/lib/model/edge.rb +0 -55
- data/lib/model/model.rb +0 -91
- data/lib/model/the_class.rb +0 -500
- data/lib/model/the_record.rb +0 -322
- data/lib/model/vertex.rb +0 -136
- data/lib/orientdb_private.rb +0 -48
- data/lib/other.rb +0 -330
- data/lib/rest/change.rb +0 -137
- data/lib/rest/create.rb +0 -488
- data/lib/rest/delete.rb +0 -134
- data/lib/rest/operations.rb +0 -160
- data/lib/rest/read.rb +0 -150
- data/lib/rest/rest.rb +0 -112
- data/lib/rest_disabled.rb +0 -24
- data/linkmap.md +0 -75
- data/namespace.md +0 -111
- data/old_lib_functions/two_general_class.rb +0 -139
- data/rails.md +0 -125
- data/rails/activeorient.rb +0 -53
- data/rails/config.yml +0 -10
- data/rails/connect.yml +0 -17
- data/usecase_oo.md +0 -61
data/lib/active-orient.rb
CHANGED
@@ -1,59 +1,11 @@
|
|
1
|
+
require "support.rb"
|
2
|
+
require "base.rb"
|
3
|
+
require "base_properties.rb"
|
1
4
|
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
data/lib/base.rb
CHANGED
@@ -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
|
-
|
10
|
+
include ActiveModel::Serializers::Xml
|
12
11
|
include ActiveModel::Serializers::JSON
|
13
|
-
|
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
|
-
|
22
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
73
|
-
|
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
|
-
@
|
54
|
+
# @edges = HashWithIndifferentAccess.new
|
55
|
+
|
76
56
|
run_callbacks :initialize do
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
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
|
99
|
-
@metadata[:type]
|
100
|
-
@metadata[:class]
|
101
|
-
@metadata[: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] =
|
107
|
-
@metadata[:record]
|
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
|
-
|
111
|
-
|
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 =
|
88
|
+
operator, *base_edge = edge.split('_')
|
116
89
|
base_edge = base_edge.join('_')
|
117
|
-
|
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
|
-
|
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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
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
|
-
|
164
|
-
|
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
|
-
|
189
|
-
|
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
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
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
|
-
|
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}") ||
|
209
|
+
self.instance_variable_get("@#{models}") ||
|
210
|
+
self.instance_variable_set("@#{models}", [])
|
242
211
|
end
|
243
212
|
end
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
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
|