og 0.16.0 → 0.17.0
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.
- data/CHANGELOG +485 -0
- data/README +35 -12
- data/Rakefile +4 -7
- data/benchmark/bench.rb +1 -1
- data/doc/AUTHORS +3 -3
- data/doc/RELEASES +153 -2
- data/doc/config.txt +0 -7
- data/doc/tutorial.txt +7 -0
- data/examples/README +5 -0
- data/examples/mysql_to_psql.rb +25 -50
- data/examples/run.rb +62 -77
- data/install.rb +1 -1
- data/lib/og.rb +45 -106
- data/lib/og/collection.rb +156 -0
- data/lib/og/entity.rb +131 -0
- data/lib/og/errors.rb +10 -15
- data/lib/og/manager.rb +115 -0
- data/lib/og/{mixins → mixin}/hierarchical.rb +43 -37
- data/lib/og/{mixins → mixin}/orderable.rb +35 -35
- data/lib/og/{mixins → mixin}/timestamped.rb +0 -6
- data/lib/og/{mixins → mixin}/tree.rb +0 -4
- data/lib/og/relation.rb +178 -0
- data/lib/og/relation/belongs_to.rb +14 -0
- data/lib/og/relation/has_many.rb +62 -0
- data/lib/og/relation/has_one.rb +17 -0
- data/lib/og/relation/joins_many.rb +69 -0
- data/lib/og/relation/many_to_many.rb +17 -0
- data/lib/og/relation/refers_to.rb +31 -0
- data/lib/og/store.rb +223 -0
- data/lib/og/store/filesys.rb +113 -0
- data/lib/og/store/madeleine.rb +4 -0
- data/lib/og/store/memory.rb +291 -0
- data/lib/og/store/mysql.rb +283 -0
- data/lib/og/store/psql.rb +238 -0
- data/lib/og/store/sql.rb +599 -0
- data/lib/og/store/sqlite.rb +190 -0
- data/lib/og/store/sqlserver.rb +262 -0
- data/lib/og/types.rb +19 -0
- data/lib/og/validation.rb +0 -4
- data/test/og/{mixins → mixin}/tc_hierarchical.rb +21 -23
- data/test/og/{mixins → mixin}/tc_orderable.rb +15 -14
- data/test/og/mixin/tc_timestamped.rb +38 -0
- data/test/og/store/tc_filesys.rb +71 -0
- data/test/og/tc_relation.rb +36 -0
- data/test/og/tc_store.rb +290 -0
- data/test/og/tc_types.rb +21 -0
- metadata +54 -40
- data/examples/mock_example.rb +0 -50
- data/lib/og/adapters/base.rb +0 -706
- data/lib/og/adapters/filesys.rb +0 -117
- data/lib/og/adapters/mysql.rb +0 -350
- data/lib/og/adapters/oracle.rb +0 -368
- data/lib/og/adapters/psql.rb +0 -272
- data/lib/og/adapters/sqlite.rb +0 -265
- data/lib/og/adapters/sqlserver.rb +0 -356
- data/lib/og/database.rb +0 -290
- data/lib/og/enchant.rb +0 -149
- data/lib/og/meta.rb +0 -407
- data/lib/og/testing/mock.rb +0 -165
- data/lib/og/typemacros.rb +0 -24
- data/test/og/adapters/tc_filesys.rb +0 -83
- data/test/og/adapters/tc_sqlite.rb +0 -86
- data/test/og/adapters/tc_sqlserver.rb +0 -96
- data/test/og/tc_automanage.rb +0 -46
- data/test/og/tc_lifecycle.rb +0 -105
- data/test/og/tc_many_to_many.rb +0 -61
- data/test/og/tc_meta.rb +0 -55
- data/test/og/tc_validation.rb +0 -89
- data/test/tc_og.rb +0 -364
data/lib/og/testing/mock.rb
DELETED
@@ -1,165 +0,0 @@
|
|
1
|
-
# * George Moschovitis <gm@navel.gr>
|
2
|
-
# * Thomas Quas <tquas@yahoo.com>
|
3
|
-
# (c) 2004-2005 Navel, all rights reserved.
|
4
|
-
# $Id: mock.rb 1 2005-04-11 11:04:30Z gmosx $
|
5
|
-
|
6
|
-
require 'flexmock'
|
7
|
-
|
8
|
-
require 'og'
|
9
|
-
|
10
|
-
module Og
|
11
|
-
|
12
|
-
# A utility object to Mock a Database in test units.
|
13
|
-
# Extends the standard FlexMock object.
|
14
|
-
#--
|
15
|
-
# TODO: Factor out common functionality with Database
|
16
|
-
# to avoid code duplication.
|
17
|
-
|
18
|
-
class MockDatabase < ::FlexMock
|
19
|
-
include Og::Enchant
|
20
|
-
|
21
|
-
# Managed class metadata
|
22
|
-
#
|
23
|
-
class ManagedClassMeta
|
24
|
-
# The managed class.
|
25
|
-
attr_accessor :klass
|
26
|
-
|
27
|
-
# A mapping of the database fields to the object properties.
|
28
|
-
attr_accessor :field_index
|
29
|
-
|
30
|
-
def initialize(klass = nil)
|
31
|
-
@klass = klass
|
32
|
-
@field_index = {}
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# hash of configuration options.
|
37
|
-
|
38
|
-
attr_accessor :config
|
39
|
-
|
40
|
-
# Pool of connections to the backend.
|
41
|
-
|
42
|
-
attr_accessor :connection_pool
|
43
|
-
|
44
|
-
# Managed classes.
|
45
|
-
|
46
|
-
attr_accessor :managed_classes
|
47
|
-
|
48
|
-
# Initialize the database interface.
|
49
|
-
|
50
|
-
def initialize
|
51
|
-
# Initialize FlexMock
|
52
|
-
super
|
53
|
-
|
54
|
-
@managed_classes = SafeHash.new
|
55
|
-
|
56
|
-
Logger.info "Using mock database."
|
57
|
-
|
58
|
-
if Og.auto_manage_classes
|
59
|
-
# automatically manage classes with properties and metadata.
|
60
|
-
# gmosx: Any idea how to optimize this?
|
61
|
-
|
62
|
-
classes_to_manage = []
|
63
|
-
ObjectSpace.each_object(Class) do |c|
|
64
|
-
if c.respond_to?(:__props) and c.__props
|
65
|
-
classes_to_manage << c
|
66
|
-
end
|
67
|
-
end
|
68
|
-
Logger.info "Og auto manages the following classes:"
|
69
|
-
Logger.info "#{classes_to_manage.inspect}"
|
70
|
-
manage_classes(*classes_to_manage)
|
71
|
-
end
|
72
|
-
|
73
|
-
# use the newly created database.
|
74
|
-
|
75
|
-
Og.use(self)
|
76
|
-
end
|
77
|
-
|
78
|
-
# Shutdown the database interface.
|
79
|
-
|
80
|
-
def shutdown
|
81
|
-
end
|
82
|
-
alias_method :close, :shutdown
|
83
|
-
|
84
|
-
# Get a connection from the pool to access the database.
|
85
|
-
# Stores the connection in a thread-local variable.
|
86
|
-
|
87
|
-
def get_connection
|
88
|
-
# nop
|
89
|
-
end
|
90
|
-
alias_method :connection, :get_connection
|
91
|
-
|
92
|
-
# Restore an unused connection to the pool.
|
93
|
-
|
94
|
-
def put_connection
|
95
|
-
# nop
|
96
|
-
end
|
97
|
-
|
98
|
-
# Register a standard Ruby class as managed.
|
99
|
-
|
100
|
-
def manage(klass)
|
101
|
-
return if managed?(klass) or klass.ancestors.include?(Og::Unmanageable)
|
102
|
-
|
103
|
-
@managed_classes[klass] = ManagedClassMeta.new(klass)
|
104
|
-
|
105
|
-
# Add standard og methods to the class.
|
106
|
-
convert(klass)
|
107
|
-
|
108
|
-
# Add helper methods to the class.
|
109
|
-
enchant(klass) if Og.enchant_managed_classes
|
110
|
-
end
|
111
|
-
|
112
|
-
# Helper method to set multiple managed classes.
|
113
|
-
|
114
|
-
def manage_classes(*klasses)
|
115
|
-
for klass in klasses
|
116
|
-
manage(klass)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# Stop managing a Ruby class
|
121
|
-
|
122
|
-
def unmanage(klass)
|
123
|
-
@managed_classes.delete(klass)
|
124
|
-
end
|
125
|
-
|
126
|
-
# Is this class managed?
|
127
|
-
|
128
|
-
def managed?(klass)
|
129
|
-
return @managed_classes.include?(klass)
|
130
|
-
end
|
131
|
-
|
132
|
-
# Add standard og functionality to the class
|
133
|
-
|
134
|
-
def convert(klass)
|
135
|
-
klass.class_eval %{
|
136
|
-
DBTABLE = "#{Og::Backend.table(klass)}"
|
137
|
-
DBSEQ = "#{Og::Backend.table(klass)}_oids_seq"
|
138
|
-
|
139
|
-
def to_i()
|
140
|
-
@oid
|
141
|
-
end
|
142
|
-
}
|
143
|
-
end
|
144
|
-
|
145
|
-
# Automatically wrap connection methods.
|
146
|
-
|
147
|
-
def self.wrap_method(method, args)
|
148
|
-
args = args.split(/,/)
|
149
|
-
class_eval %{
|
150
|
-
def #{method}(#{args.join(", ")})
|
151
|
-
# nop
|
152
|
-
end
|
153
|
-
}
|
154
|
-
end
|
155
|
-
|
156
|
-
def self.create_db!(config)
|
157
|
-
# nop
|
158
|
-
end
|
159
|
-
|
160
|
-
def self.drop_db!(config)
|
161
|
-
# nop
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
data/lib/og/typemacros.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# * George Moschovitis <gm@navel.gr>
|
2
|
-
# * Michael Neumann <mneumann@ntecs.de>
|
3
|
-
# (c) 2004-2005 Navel, all rights reserved.
|
4
|
-
# $Id: typemacros.rb 1 2005-04-11 11:04:30Z gmosx $
|
5
|
-
|
6
|
-
module Og
|
7
|
-
|
8
|
-
# Some useful type macros to help when defining managed
|
9
|
-
# objects. You can easily code your own type macros.
|
10
|
-
# Just return the array that should be passed
|
11
|
-
#
|
12
|
-
# === Example
|
13
|
-
#
|
14
|
-
# property :name, Og.VarChar(30)
|
15
|
-
|
16
|
-
def VarChar(size)
|
17
|
-
return String, :sql => "VARCHAR(#{size})"
|
18
|
-
end
|
19
|
-
|
20
|
-
NotNull = { :sql => 'NOT NULL' }.freeze
|
21
|
-
|
22
|
-
Null = { :sql => 'NULL' }.freeze
|
23
|
-
|
24
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
require 'og'
|
7
|
-
require 'og/adapters/filesys'
|
8
|
-
|
9
|
-
class TC_OgFilesys < Test::Unit::TestCase # :nodoc: all
|
10
|
-
include Og
|
11
|
-
|
12
|
-
# Forward declaration.
|
13
|
-
|
14
|
-
class Comment; end
|
15
|
-
|
16
|
-
class Article
|
17
|
-
prop_accessor :name, String
|
18
|
-
prop_accessor :age, Fixnum
|
19
|
-
has_many :comments, Comment
|
20
|
-
|
21
|
-
def initialize (name = nil, age = nil)
|
22
|
-
@name, @age = name, age
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class Comment
|
27
|
-
prop_accessor :text, String
|
28
|
-
belongs_to :article, Article
|
29
|
-
|
30
|
-
def initialize(text = nil)
|
31
|
-
@text = text
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def setup
|
36
|
-
config = {
|
37
|
-
:adapter => 'filesys',
|
38
|
-
:database => 'fstest',
|
39
|
-
}
|
40
|
-
|
41
|
-
$DBG = true
|
42
|
-
|
43
|
-
Og::Database.drop_db!(config)
|
44
|
-
@og = Og::Database.new(config)
|
45
|
-
end
|
46
|
-
|
47
|
-
def teardown
|
48
|
-
@og.shutdown
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_all
|
52
|
-
a = Article.new('gmosx', 30)
|
53
|
-
a.save!
|
54
|
-
|
55
|
-
a1 = Article[1]
|
56
|
-
|
57
|
-
assert_equal 'gmosx', a1.name
|
58
|
-
assert_equal 30, a1.age
|
59
|
-
assert_equal 1, a1.oid
|
60
|
-
|
61
|
-
Article.create('drak', 12)
|
62
|
-
Article.create('ekarak', 34)
|
63
|
-
Article.create('mario', 53)
|
64
|
-
Article.create('elathan', 34)
|
65
|
-
=begin
|
66
|
-
articles = Article.all
|
67
|
-
|
68
|
-
assert_equal 5, articles.size
|
69
|
-
=end
|
70
|
-
a3 = Article[3]
|
71
|
-
|
72
|
-
assert_equal 'ekarak', a3.name
|
73
|
-
|
74
|
-
c1 = Comment.new('a comment')
|
75
|
-
c1.save!
|
76
|
-
a3.add_comment(c1)
|
77
|
-
=begin
|
78
|
-
a5 = Article[3]
|
79
|
-
assert_equal 1, a5.comments.size
|
80
|
-
=end
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
require 'og'
|
7
|
-
require 'og/adapters/sqlite'
|
8
|
-
|
9
|
-
if defined?(SQLite3)
|
10
|
-
|
11
|
-
class TC_OgSqlite3 < Test::Unit::TestCase # :nodoc: all
|
12
|
-
|
13
|
-
# Forward declaration.
|
14
|
-
|
15
|
-
class Comment; end
|
16
|
-
|
17
|
-
class Article
|
18
|
-
prop_accessor :name, String
|
19
|
-
prop_accessor :age, Fixnum
|
20
|
-
has_many :comments, Comment
|
21
|
-
|
22
|
-
def initialize (name = nil, age = nil)
|
23
|
-
@name, @age = name, age
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class Comment
|
28
|
-
prop_accessor :text, String
|
29
|
-
belongs_to :article, Article
|
30
|
-
|
31
|
-
def initialize(text = nil)
|
32
|
-
@text = text
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def setup
|
37
|
-
config = {
|
38
|
-
:adapter => 'sqlite',
|
39
|
-
:database => 'test',
|
40
|
-
:connection_count => 2
|
41
|
-
}
|
42
|
-
|
43
|
-
$DBG = true
|
44
|
-
|
45
|
-
Og::Database.drop_db!(config)
|
46
|
-
@og = Og::Database.new(config)
|
47
|
-
end
|
48
|
-
|
49
|
-
def teardown
|
50
|
-
@og.shutdown
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_all
|
54
|
-
a = Article.new('gmosx', 30)
|
55
|
-
a.save!
|
56
|
-
|
57
|
-
a1 = Article[1]
|
58
|
-
|
59
|
-
assert_equal 'gmosx', a1.name
|
60
|
-
assert_equal 30, a1.age
|
61
|
-
assert_equal 1, a1.oid
|
62
|
-
|
63
|
-
Article.create('drak', 12)
|
64
|
-
Article.create('ekarak', 34)
|
65
|
-
Article.create('mario', 53)
|
66
|
-
Article.create('elathan', 34)
|
67
|
-
|
68
|
-
articles = Article.all
|
69
|
-
|
70
|
-
assert_equal 5, articles.size
|
71
|
-
|
72
|
-
a3 = Article[3]
|
73
|
-
|
74
|
-
assert_equal 'ekarak', a3.name
|
75
|
-
|
76
|
-
c1 = Comment.new('a comment')
|
77
|
-
c1.save!
|
78
|
-
a3.add_comment(c1)
|
79
|
-
|
80
|
-
a5 = Article[3]
|
81
|
-
assert_equal 1, a5.comments.size
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
require 'og'
|
7
|
-
require 'og/adapters/sqlserver'
|
8
|
-
|
9
|
-
if defined?(DBI)
|
10
|
-
|
11
|
-
class TC_OgSqlserver < Test::Unit::TestCase # :nodoc: all
|
12
|
-
|
13
|
-
# Forward declaration.
|
14
|
-
|
15
|
-
class Comment; end
|
16
|
-
|
17
|
-
class Article
|
18
|
-
prop_accessor :name, String
|
19
|
-
prop_accessor :age, Fixnum
|
20
|
-
has_many :comments, Comment
|
21
|
-
|
22
|
-
def initialize (name = nil, age = nil)
|
23
|
-
@name, @age = name, age
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class Comment
|
28
|
-
prop_accessor :text, String
|
29
|
-
belongs_to :article, Article
|
30
|
-
|
31
|
-
def initialize(text = nil)
|
32
|
-
@text = text
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def setup
|
37
|
-
config = {
|
38
|
-
:adapter => 'sqlserver',
|
39
|
-
:address => 'localhost',
|
40
|
-
:database => 'test',
|
41
|
-
:user => 'sa',
|
42
|
-
:password => 'sa',
|
43
|
-
:connection_count => 2
|
44
|
-
}
|
45
|
-
|
46
|
-
$DBG = true
|
47
|
-
|
48
|
-
# Og::Database.drop_db!(config)
|
49
|
-
@og = Og::Database.new(config)
|
50
|
-
end
|
51
|
-
|
52
|
-
def teardown
|
53
|
-
@og.shutdown
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_all
|
57
|
-
|
58
|
-
puts Article.all.size
|
59
|
-
Article.each {|a| a.delete! }
|
60
|
-
puts Article.all.size
|
61
|
-
|
62
|
-
a = Article.new('gmosx', 30)
|
63
|
-
a.save!
|
64
|
-
|
65
|
-
baseoid = a.oid
|
66
|
-
|
67
|
-
a1 = Article[baseoid]
|
68
|
-
|
69
|
-
assert_equal 'gmosx', a1.name
|
70
|
-
assert_equal 30, a1.age
|
71
|
-
assert_equal baseoid, a1.oid
|
72
|
-
|
73
|
-
Article.create('drak', 12)
|
74
|
-
Article.create('ekarak', 34)
|
75
|
-
Article.create('mario', 53)
|
76
|
-
Article.create('elathan', 34)
|
77
|
-
|
78
|
-
articles = Article.all
|
79
|
-
|
80
|
-
assert_equal 5, articles.size
|
81
|
-
|
82
|
-
a3 = Article['ekarak']
|
83
|
-
|
84
|
-
assert_equal 'ekarak', a3.name
|
85
|
-
|
86
|
-
c1 = Comment.new('a comment')
|
87
|
-
c1.save!
|
88
|
-
a3.add_comment(c1)
|
89
|
-
|
90
|
-
a5 = Article['ekarak']
|
91
|
-
assert_equal 1, a5.comments.size
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|