og 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +77 -0
- data/INSTALL +3 -0
- data/README +5 -3
- data/Rakefile +148 -5
- data/benchmark/bench.rb +1 -1
- data/doc/AUTHORS +4 -4
- data/doc/RELEASES +41 -1
- data/examples/mock_example.rb +1 -1
- data/examples/mysql_to_psql.rb +1 -1
- data/examples/run.rb +1 -1
- data/install.rb +1 -1
- data/lib/og.rb +4 -2
- data/lib/og/{adapter.rb → adapters/base.rb} +334 -152
- data/lib/og/adapters/filesys.rb +3 -7
- data/lib/og/adapters/mysql.rb +5 -9
- data/lib/og/adapters/oracle.rb +5 -9
- data/lib/og/adapters/psql.rb +5 -9
- data/lib/og/adapters/sqlite.rb +5 -9
- data/lib/og/adapters/sqlserver.rb +5 -9
- data/lib/og/database.rb +13 -11
- data/lib/og/enchant.rb +1 -1
- data/lib/og/errors.rb +21 -0
- data/lib/og/meta.rb +10 -9
- data/lib/og/mixins/hierarchical.rb +4 -4
- data/lib/og/mixins/orderable.rb +1 -1
- data/lib/og/mixins/timestamped.rb +24 -0
- data/lib/og/mixins/tree.rb +3 -1
- data/lib/og/testing/mock.rb +2 -2
- data/lib/og/typemacros.rb +1 -1
- data/lib/og/validation.rb +4 -4
- data/test/og/{tc_filesys.rb → adapters/tc_filesys.rb} +1 -1
- data/test/og/{tc_sqlite.rb → adapters/tc_sqlite.rb} +3 -4
- data/test/og/{tc_sqlserver.rb → adapters/tc_sqlserver.rb} +5 -2
- data/test/og/mixins/tc_hierarchical.rb +0 -1
- data/test/og/mixins/tc_orderable.rb +0 -1
- data/test/og/tc_automanage.rb +3 -2
- data/test/og/tc_lifecycle.rb +15 -14
- data/test/og/tc_many_to_many.rb +0 -1
- data/test/og/tc_meta.rb +5 -5
- data/test/og/tc_validation.rb +1 -1
- data/test/tc_og.rb +0 -20
- metadata +33 -34
- data/examples/test.db +0 -0
- data/lib/og/connection.rb +0 -325
- data/lib/og/observer.rb +0 -53
- data/test/og/tc_observer.rb +0 -85
data/lib/og/adapters/filesys.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# * George Moschovitis <gm@navel.gr>
|
2
2
|
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
-
# $Id: filesys.rb
|
3
|
+
# $Id: filesys.rb 17 2005-04-14 16:03:40Z gmosx $
|
4
4
|
|
5
5
|
require 'fileutils'
|
6
6
|
|
7
|
-
require 'og/
|
8
|
-
require 'og/connection'
|
9
|
-
require 'glue/attribute'
|
7
|
+
require 'og/adapters/base'
|
10
8
|
|
11
9
|
module Og
|
12
10
|
|
@@ -40,17 +38,15 @@ class FilesysAdapter < Adapter
|
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
43
|
-
def insert_code(klass, db
|
41
|
+
def insert_code(klass, db)
|
44
42
|
props = props_for_insert(klass)
|
45
43
|
values = props.collect { |p| write_prop(p) }.join(',')
|
46
44
|
|
47
45
|
sql = "INSERT INTO #{klass::DBTABLE} (#{props.collect {|p| p.name}.join(',')}) VALUES (#{values})"
|
48
46
|
|
49
47
|
%{
|
50
|
-
#{pre_cb}
|
51
48
|
conn.store.query("#{sql}").close
|
52
49
|
@oid = conn.store.last_insert_row_id
|
53
|
-
#{post_cb}
|
54
50
|
}
|
55
51
|
end
|
56
52
|
|
data/lib/og/adapters/mysql.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# * George Moschovitis <gm@navel.gr>
|
2
2
|
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
-
# $Id: mysql.rb
|
3
|
+
# $Id: mysql.rb 17 2005-04-14 16:03:40Z gmosx $
|
4
4
|
|
5
5
|
begin
|
6
6
|
require 'mysql'
|
@@ -9,9 +9,7 @@ rescue Object => ex
|
|
9
9
|
Logger.error ex
|
10
10
|
end
|
11
11
|
|
12
|
-
require 'og/
|
13
|
-
require 'og/connection'
|
14
|
-
require 'glue/attribute'
|
12
|
+
require 'og/adapters/base'
|
15
13
|
|
16
14
|
module Og
|
17
15
|
|
@@ -94,18 +92,16 @@ class MysqlAdapter < Adapter
|
|
94
92
|
klass.__props.reject { |p| :oid == p.symbol }
|
95
93
|
end
|
96
94
|
|
97
|
-
def insert_code(klass, db
|
95
|
+
def insert_code(klass, db)
|
98
96
|
props = props_for_insert(klass)
|
99
97
|
values = props.collect { |p| write_prop(p) }.join(',')
|
100
98
|
|
101
99
|
sql = "INSERT INTO #{klass::DBTABLE} (#{props.collect {|p| p.name}.join(',')}) VALUES (#{values})"
|
102
100
|
|
103
101
|
%{
|
104
|
-
#{pre_cb}
|
105
102
|
conn.store.query_with_result = false
|
106
103
|
conn.store.query "#{sql}"
|
107
104
|
@oid = conn.store.insert_id()
|
108
|
-
#{post_cb}
|
109
105
|
}
|
110
106
|
end
|
111
107
|
|
@@ -314,7 +310,7 @@ class MysqlConnection < Connection
|
|
314
310
|
return nil unless valid_res?(res)
|
315
311
|
|
316
312
|
row = res.fetch_row
|
317
|
-
obj = klass.
|
313
|
+
obj = klass.allocate
|
318
314
|
obj.og_read(row)
|
319
315
|
|
320
316
|
res.free
|
@@ -329,7 +325,7 @@ class MysqlConnection < Connection
|
|
329
325
|
for tuple in (0...res.num_rows)
|
330
326
|
row = res.fetch_row
|
331
327
|
|
332
|
-
obj = klass.
|
328
|
+
obj = klass.allocate
|
333
329
|
obj.og_read(row)
|
334
330
|
|
335
331
|
objects << obj
|
data/lib/og/adapters/oracle.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# * Matt Bowen <matt.bowen@farweststeel.com>
|
2
2
|
# * George Moschovitis <gm@navel.gr>
|
3
3
|
# (c) 2004-2005 Navel, all rights reserved.
|
4
|
-
# $Id: oracle.rb
|
4
|
+
# $Id: oracle.rb 17 2005-04-14 16:03:40Z gmosx $
|
5
5
|
|
6
6
|
begin
|
7
7
|
require 'oracle'
|
@@ -10,9 +10,7 @@ rescue
|
|
10
10
|
Logger.error ex
|
11
11
|
end
|
12
12
|
|
13
|
-
require 'og/
|
14
|
-
require 'og/connection'
|
15
|
-
require 'glue/attribute'
|
13
|
+
require 'og/adapters/base'
|
16
14
|
|
17
15
|
module Og
|
18
16
|
|
@@ -86,19 +84,17 @@ class OracleAdapter < Adapter
|
|
86
84
|
super
|
87
85
|
end
|
88
86
|
|
89
|
-
def insert_code(klass, db
|
87
|
+
def insert_code(klass, db)
|
90
88
|
props = props_for_insert(klass)
|
91
89
|
values = props.collect { |p| write_prop(p) }.join(',')
|
92
90
|
|
93
91
|
sql = "INSERT INTO #{klass::DBTABLE} (#{props.collect {|p| p.name}.join(',')}) VALUES (#{values})"
|
94
92
|
|
95
93
|
%{
|
96
|
-
#{pre_cb}
|
97
94
|
res = conn.store.exec("SELECT #{klass::DBSEQ}.nextval FROM DUAL")
|
98
95
|
@oid = res.fetch[0].to_i
|
99
96
|
res.close
|
100
97
|
conn.exec "#{sql}"
|
101
|
-
#{post_cb}
|
102
98
|
}
|
103
99
|
end
|
104
100
|
|
@@ -337,7 +333,7 @@ class OracleConnection < Connection
|
|
337
333
|
row = res.fetch
|
338
334
|
return nil unless row
|
339
335
|
|
340
|
-
obj = klass.
|
336
|
+
obj = klass.allocate
|
341
337
|
obj.og_read(row)
|
342
338
|
|
343
339
|
res.close
|
@@ -349,7 +345,7 @@ class OracleConnection < Connection
|
|
349
345
|
objects = []
|
350
346
|
|
351
347
|
while row = res.fetch
|
352
|
-
obj = klass.
|
348
|
+
obj = klass.allocate
|
353
349
|
obj.og_read(row)
|
354
350
|
objects << obj
|
355
351
|
end
|
data/lib/og/adapters/psql.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# * George Moschovitis <gm@navel.gr>
|
2
2
|
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
-
# $Id: psql.rb
|
3
|
+
# $Id: psql.rb 17 2005-04-14 16:03:40Z gmosx $
|
4
4
|
|
5
5
|
begin
|
6
6
|
require 'postgres'
|
@@ -9,9 +9,7 @@ rescue Object => ex
|
|
9
9
|
Logger.error ex
|
10
10
|
end
|
11
11
|
|
12
|
-
require 'og/
|
13
|
-
require 'og/connection'
|
14
|
-
require 'glue/attribute'
|
12
|
+
require 'og/adapters/base'
|
15
13
|
|
16
14
|
module Og
|
17
15
|
|
@@ -65,19 +63,17 @@ class PsqlAdapter < Adapter
|
|
65
63
|
super
|
66
64
|
end
|
67
65
|
|
68
|
-
def insert_code(klass, db
|
66
|
+
def insert_code(klass, db)
|
69
67
|
props = props_for_insert(klass)
|
70
68
|
values = props.collect { |p| write_prop(p) }.join(',')
|
71
69
|
|
72
70
|
sql = "INSERT INTO #{klass::DBTABLE} (#{props.collect {|p| p.name}.join(',')}) VALUES (#{values})"
|
73
71
|
|
74
72
|
%{
|
75
|
-
#{pre_cb}
|
76
73
|
res = conn.store.exec("SELECT nextval('#{klass::DBSEQ}')")
|
77
74
|
@oid = res.getvalue(0, 0).to_i
|
78
75
|
res.clear
|
79
76
|
conn.exec "#{sql}"
|
80
|
-
#{post_cb}
|
81
77
|
}
|
82
78
|
end
|
83
79
|
|
@@ -244,7 +240,7 @@ class PsqlConnection < Connection
|
|
244
240
|
def read_one(res, klass)
|
245
241
|
return nil unless valid_res?(res)
|
246
242
|
|
247
|
-
obj = klass.
|
243
|
+
obj = klass.allocate
|
248
244
|
obj.og_read(res, 0)
|
249
245
|
|
250
246
|
res.clear
|
@@ -256,7 +252,7 @@ class PsqlConnection < Connection
|
|
256
252
|
objects = []
|
257
253
|
|
258
254
|
for tuple in (0...res.num_tuples)
|
259
|
-
obj = klass.
|
255
|
+
obj = klass.allocate
|
260
256
|
obj.og_read(res, tuple)
|
261
257
|
objects << obj
|
262
258
|
end
|
data/lib/og/adapters/sqlite.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# * George Moschovitis <gm@navel.gr>
|
2
2
|
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
-
# $Id: sqlite.rb
|
3
|
+
# $Id: sqlite.rb 17 2005-04-14 16:03:40Z gmosx $
|
4
4
|
|
5
5
|
begin
|
6
6
|
require 'sqlite3'
|
@@ -11,9 +11,7 @@ end
|
|
11
11
|
|
12
12
|
require 'fileutils'
|
13
13
|
|
14
|
-
require 'og/
|
15
|
-
require 'og/connection'
|
16
|
-
require 'glue/attribute'
|
14
|
+
require 'og/adapters/base'
|
17
15
|
|
18
16
|
module Og
|
19
17
|
|
@@ -50,17 +48,15 @@ class SqliteAdapter < Adapter
|
|
50
48
|
end
|
51
49
|
end
|
52
50
|
=end
|
53
|
-
def insert_code(klass, db
|
51
|
+
def insert_code(klass, db)
|
54
52
|
props = props_for_insert(klass)
|
55
53
|
values = props.collect { |p| write_prop(p) }.join(',')
|
56
54
|
|
57
55
|
sql = "INSERT INTO #{klass::DBTABLE} (#{props.collect {|p| p.name}.join(',')}) VALUES (#{values})"
|
58
56
|
|
59
57
|
%{
|
60
|
-
#{pre_cb}
|
61
58
|
conn.store.query("#{sql}").close
|
62
59
|
@oid = conn.store.last_insert_row_id
|
63
|
-
#{post_cb}
|
64
60
|
}
|
65
61
|
=begin
|
66
62
|
props = props_for_insert(klass)
|
@@ -233,7 +229,7 @@ class SqliteConnection < Connection
|
|
233
229
|
row = res.next
|
234
230
|
return nil unless row
|
235
231
|
|
236
|
-
obj = klass.
|
232
|
+
obj = klass.allocate
|
237
233
|
obj.og_read(row)
|
238
234
|
|
239
235
|
res.close
|
@@ -245,7 +241,7 @@ class SqliteConnection < Connection
|
|
245
241
|
objects = []
|
246
242
|
|
247
243
|
res.each do |row|
|
248
|
-
obj = klass.
|
244
|
+
obj = klass.allocate
|
249
245
|
obj.og_read(row)
|
250
246
|
objects << obj
|
251
247
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# * Anastasios Koutoumanos <ak@navel.gr>
|
2
2
|
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
-
# $Id: sqlserver.rb
|
3
|
+
# $Id: sqlserver.rb 17 2005-04-14 16:03:40Z gmosx $
|
4
4
|
|
5
5
|
begin
|
6
6
|
require 'dbi'
|
@@ -9,9 +9,7 @@ rescue Object => ex
|
|
9
9
|
Logger.error ex
|
10
10
|
end
|
11
11
|
|
12
|
-
require '
|
13
|
-
require 'og/adapter'
|
14
|
-
require 'og/connection'
|
12
|
+
require 'og/adapters/base'
|
15
13
|
|
16
14
|
module Og
|
17
15
|
|
@@ -128,20 +126,18 @@ class SqlserverAdapter < Adapter
|
|
128
126
|
klass.__props.reject { |p| :oid == p.symbol }
|
129
127
|
end
|
130
128
|
|
131
|
-
def insert_code(klass, db
|
129
|
+
def insert_code(klass, db)
|
132
130
|
props = props_for_insert(klass)
|
133
131
|
values = props.collect { |p| write_prop(p) }.join(',')
|
134
132
|
|
135
133
|
sql = "INSERT INTO #{klass::DBTABLE} (#{props.collect {|p| p.name}.join(',')}) VALUES (#{values});"
|
136
134
|
|
137
135
|
%{
|
138
|
-
#{pre_cb}
|
139
136
|
conn.exec "#{sql}"
|
140
137
|
conn.commit
|
141
138
|
res = conn.query("SELECT IDENT_CURRENT('#{klass::DBTABLE}')")
|
142
139
|
@oid = res[0][0].to_i
|
143
140
|
#res.finish
|
144
|
-
#{post_cb}
|
145
141
|
}
|
146
142
|
end
|
147
143
|
|
@@ -326,7 +322,7 @@ class SqlserverConnection < Connection
|
|
326
322
|
return nil unless valid_res?(res)
|
327
323
|
return nil unless res
|
328
324
|
|
329
|
-
obj = klass.
|
325
|
+
obj = klass.allocate
|
330
326
|
obj.og_read(res)
|
331
327
|
|
332
328
|
return obj
|
@@ -337,7 +333,7 @@ class SqlserverConnection < Connection
|
|
337
333
|
objects = []
|
338
334
|
|
339
335
|
for tuple in (0...res.size)
|
340
|
-
obj = klass.
|
336
|
+
obj = klass.allocate
|
341
337
|
obj.og_read(res, tuple)
|
342
338
|
objects << obj
|
343
339
|
end
|
data/lib/og/database.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# * George Moschovitis <gm@navel.gr>
|
2
2
|
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
-
# $Id: database.rb
|
3
|
+
# $Id: database.rb 19 2005-04-15 09:24:19Z gmosx $
|
4
4
|
|
5
5
|
require 'glue/logger'
|
6
6
|
require 'glue/attribute'
|
@@ -9,17 +9,17 @@ require 'glue/array'
|
|
9
9
|
require 'glue/hash'
|
10
10
|
require 'glue/time'
|
11
11
|
require 'glue/pool'
|
12
|
+
require 'glue/aspects'
|
12
13
|
|
13
14
|
require 'og/enchant'
|
14
15
|
require 'og/meta'
|
15
|
-
require 'og/observer'
|
16
16
|
|
17
17
|
module Og
|
18
18
|
|
19
19
|
# Encapsulates an Og Database.
|
20
20
|
|
21
21
|
class Database
|
22
|
-
include
|
22
|
+
include Enchant
|
23
23
|
|
24
24
|
# Managed class metadata
|
25
25
|
|
@@ -59,7 +59,7 @@ class Database
|
|
59
59
|
@config = config
|
60
60
|
|
61
61
|
# populate with default options if needed.
|
62
|
-
@config[:connection_count] ||=
|
62
|
+
@config[:connection_count] ||= 5
|
63
63
|
|
64
64
|
Logger.info "Connecting to database '#{@config[:database]}' using the '#{@config[:adapter]}' adapter."
|
65
65
|
|
@@ -67,8 +67,8 @@ class Database
|
|
67
67
|
|
68
68
|
self.class.drop!(config) if config[:drop]
|
69
69
|
|
70
|
-
@connection_pool =
|
71
|
-
@managed_classes =
|
70
|
+
@connection_pool = Pool.new
|
71
|
+
@managed_classes = SafeHash.new
|
72
72
|
|
73
73
|
@config[:connection_count].times do
|
74
74
|
@connection_pool << @adapter.new_connection(self)
|
@@ -202,7 +202,7 @@ class Database
|
|
202
202
|
klass.class_eval %{
|
203
203
|
DBTABLE = "#{Adapter.table(klass)}"
|
204
204
|
DBSEQ = "#{Adapter.table(klass)}_oid_seq"
|
205
|
-
|
205
|
+
|
206
206
|
cattr_accessor :og_db
|
207
207
|
|
208
208
|
def to_i
|
@@ -214,10 +214,6 @@ class Database
|
|
214
214
|
|
215
215
|
klass.og_db = self
|
216
216
|
|
217
|
-
# Add observer support.
|
218
|
-
|
219
|
-
klass.extend(Observable)
|
220
|
-
|
221
217
|
# Create the schema for this class if not available.
|
222
218
|
|
223
219
|
@adapter.create_table(klass, self) if Og.create_schema
|
@@ -285,4 +281,10 @@ class Database
|
|
285
281
|
end
|
286
282
|
end
|
287
283
|
|
284
|
+
# Helper method
|
285
|
+
|
286
|
+
def self.connect(*args)
|
287
|
+
db = Database.new(*args)
|
288
|
+
end
|
289
|
+
|
288
290
|
end
|
data/lib/og/enchant.rb
CHANGED
data/lib/og/errors.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# * George Moschovitis <gm@navel.gr>
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
+
# $Id: errors.rb 1 2005-04-11 11:04:30Z gmosx $
|
4
|
+
|
5
|
+
module Og
|
6
|
+
|
7
|
+
# This exception is thrown when a low level error
|
8
|
+
# happens in the store implementation.
|
9
|
+
#--
|
10
|
+
# TODO: rename adapter_exception to store_exception.
|
11
|
+
#++
|
12
|
+
|
13
|
+
class SqlException < Exception
|
14
|
+
attr_accessor :adapter_exception, :sql
|
15
|
+
|
16
|
+
def initialize(adapter_exception, sql = nil)
|
17
|
+
@adapter_exception, @sql = adapter_exception, sql
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/og/meta.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# * George Moschovitis <gm@navel.gr>
|
2
|
-
# (c)
|
3
|
-
# $Id: meta.rb
|
2
|
+
# (c) 2005 Navel, all rights reserved.
|
3
|
+
# $Id: meta.rb 1 2005-04-11 11:04:30Z gmosx $
|
4
4
|
#--
|
5
5
|
# TODO:
|
6
6
|
# - precreate the meta sql statements as much as possible to
|
@@ -8,12 +8,12 @@
|
|
8
8
|
#++
|
9
9
|
|
10
10
|
require 'glue/inflector'
|
11
|
-
require 'og/
|
11
|
+
require 'og/adapters/base'
|
12
12
|
require 'og/typemacros'
|
13
13
|
|
14
14
|
module Og
|
15
15
|
|
16
|
-
class Relation <
|
16
|
+
class Relation < Property
|
17
17
|
alias foreign_class klass
|
18
18
|
end
|
19
19
|
|
@@ -48,7 +48,7 @@ module MetaUtils # :nodoc: all
|
|
48
48
|
#++
|
49
49
|
|
50
50
|
def self.resolve_class(name, klass)
|
51
|
-
klass ||=
|
51
|
+
klass ||= Inflector.camelize(name)
|
52
52
|
|
53
53
|
return klass if klass.is_a?(Class)
|
54
54
|
|
@@ -178,7 +178,7 @@ module MetaLanguage
|
|
178
178
|
# end
|
179
179
|
|
180
180
|
def has_many(name, klass, options = {})
|
181
|
-
name_s =
|
181
|
+
name_s = Inflector.singularize(name.to_s)
|
182
182
|
|
183
183
|
# linkback is the property of the child object that 'links back'
|
184
184
|
# to this object.
|
@@ -254,9 +254,9 @@ module MetaLanguage
|
|
254
254
|
|
255
255
|
def many_to_many(name, klass, options = {})
|
256
256
|
list_o = name.to_s
|
257
|
-
prop_o =
|
258
|
-
list_m = (options[:linkback] ||
|
259
|
-
prop_m =
|
257
|
+
prop_o = Inflector.singularize(list_o)
|
258
|
+
list_m = (options[:linkback] || Inflector.plural_name(self)).to_s
|
259
|
+
prop_m = Inflector.singularize(list_m)
|
260
260
|
|
261
261
|
# Exit if the class is allready indirectly 'enchanted' from the
|
262
262
|
# other class of the many_to_many relation.
|
@@ -393,6 +393,7 @@ end
|
|
393
393
|
if Og.include_meta_language
|
394
394
|
class Module # :nodoc: all
|
395
395
|
include Og::MetaLanguage
|
396
|
+
|
396
397
|
=begin
|
397
398
|
A hack to avoid forward references. Does not work
|
398
399
|
with namespave modules though. Any idea?
|