og 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/CHANGELOG +485 -0
  2. data/README +35 -12
  3. data/Rakefile +4 -7
  4. data/benchmark/bench.rb +1 -1
  5. data/doc/AUTHORS +3 -3
  6. data/doc/RELEASES +153 -2
  7. data/doc/config.txt +0 -7
  8. data/doc/tutorial.txt +7 -0
  9. data/examples/README +5 -0
  10. data/examples/mysql_to_psql.rb +25 -50
  11. data/examples/run.rb +62 -77
  12. data/install.rb +1 -1
  13. data/lib/og.rb +45 -106
  14. data/lib/og/collection.rb +156 -0
  15. data/lib/og/entity.rb +131 -0
  16. data/lib/og/errors.rb +10 -15
  17. data/lib/og/manager.rb +115 -0
  18. data/lib/og/{mixins → mixin}/hierarchical.rb +43 -37
  19. data/lib/og/{mixins → mixin}/orderable.rb +35 -35
  20. data/lib/og/{mixins → mixin}/timestamped.rb +0 -6
  21. data/lib/og/{mixins → mixin}/tree.rb +0 -4
  22. data/lib/og/relation.rb +178 -0
  23. data/lib/og/relation/belongs_to.rb +14 -0
  24. data/lib/og/relation/has_many.rb +62 -0
  25. data/lib/og/relation/has_one.rb +17 -0
  26. data/lib/og/relation/joins_many.rb +69 -0
  27. data/lib/og/relation/many_to_many.rb +17 -0
  28. data/lib/og/relation/refers_to.rb +31 -0
  29. data/lib/og/store.rb +223 -0
  30. data/lib/og/store/filesys.rb +113 -0
  31. data/lib/og/store/madeleine.rb +4 -0
  32. data/lib/og/store/memory.rb +291 -0
  33. data/lib/og/store/mysql.rb +283 -0
  34. data/lib/og/store/psql.rb +238 -0
  35. data/lib/og/store/sql.rb +599 -0
  36. data/lib/og/store/sqlite.rb +190 -0
  37. data/lib/og/store/sqlserver.rb +262 -0
  38. data/lib/og/types.rb +19 -0
  39. data/lib/og/validation.rb +0 -4
  40. data/test/og/{mixins → mixin}/tc_hierarchical.rb +21 -23
  41. data/test/og/{mixins → mixin}/tc_orderable.rb +15 -14
  42. data/test/og/mixin/tc_timestamped.rb +38 -0
  43. data/test/og/store/tc_filesys.rb +71 -0
  44. data/test/og/tc_relation.rb +36 -0
  45. data/test/og/tc_store.rb +290 -0
  46. data/test/og/tc_types.rb +21 -0
  47. metadata +54 -40
  48. data/examples/mock_example.rb +0 -50
  49. data/lib/og/adapters/base.rb +0 -706
  50. data/lib/og/adapters/filesys.rb +0 -117
  51. data/lib/og/adapters/mysql.rb +0 -350
  52. data/lib/og/adapters/oracle.rb +0 -368
  53. data/lib/og/adapters/psql.rb +0 -272
  54. data/lib/og/adapters/sqlite.rb +0 -265
  55. data/lib/og/adapters/sqlserver.rb +0 -356
  56. data/lib/og/database.rb +0 -290
  57. data/lib/og/enchant.rb +0 -149
  58. data/lib/og/meta.rb +0 -407
  59. data/lib/og/testing/mock.rb +0 -165
  60. data/lib/og/typemacros.rb +0 -24
  61. data/test/og/adapters/tc_filesys.rb +0 -83
  62. data/test/og/adapters/tc_sqlite.rb +0 -86
  63. data/test/og/adapters/tc_sqlserver.rb +0 -96
  64. data/test/og/tc_automanage.rb +0 -46
  65. data/test/og/tc_lifecycle.rb +0 -105
  66. data/test/og/tc_many_to_many.rb +0 -61
  67. data/test/og/tc_meta.rb +0 -55
  68. data/test/og/tc_validation.rb +0 -89
  69. data/test/tc_og.rb +0 -364
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = Og 0.16.0 README
1
+ = Og 0.17.0 README
2
2
 
3
3
  Og (ObjectGraph) is a powerfull object-relational mapping library. Og provides
4
4
  transparent serialization of object graphs to a RDBMS
@@ -27,21 +27,29 @@ The library provides the following features:
27
27
 
28
28
  + Object-Relational mapping.
29
29
  + Absolutely no configuration files.
30
- + Multiple backend adapters (PostgreSQL, MySQL, SQLite3, Oracle, SqlServer).
30
+ + Multiple stores (PostgreSQL, MySQL, SQLite, Oraclei, SqlServer, ..).
31
+ + Supports non SQL stores.
31
32
  + ActiveRecord-style meta language and db aware methods.
32
- + Automatially generates join-tables for many_to_many relations.
33
- + Deserialize sql join queries to Ruby Objects (coming soon).
33
+ + Deserialize to Ruby Objects.
34
+ + Deserialize sql join queries to Ruby Objects.
35
+ + Eager associations.
34
36
  + Serialize arbitrary ruby object graphs through YAML.
35
37
  + Connection pooling.
36
- + Thread safety.
38
+ + Thread safety (temporarily dissabled).
37
39
  + SQL transactions.
38
- + Lifecycle event interception and Observers.
40
+ + Aspect oriented constructs allow interception of lifecycle callbacks.
39
41
  + Transparent support for cascading deletes for all backends.
40
- + Dynamic db related mixins (Orderable, etc).
41
- + Hierarchical structures (nested sets, more coming soon).
42
- + Works safely as part of a distributed application.
43
- + Automatic Validation/Constraints.
44
- + Simple and clean implementation.
42
+ + Hierarchical structures (nested sets)
43
+ + Works safely as part of distributed application.
44
+ + Simple implementation.
45
+
46
+
47
+ == What's new
48
+
49
+ For information about the latest changes please consult the
50
+ file
51
+
52
+ doc/RELEASES
45
53
 
46
54
 
47
55
  == Download
@@ -51,7 +59,7 @@ The latest version of Og can be found at
51
59
  * http://nitro.rubyforge.org
52
60
 
53
61
  Documentation for Og can be found in the distribution. You can find
54
- a nice tutorial at www.rubygarden.com
62
+ a nice tutorial at www.rubygarden.com.
55
63
 
56
64
 
57
65
  == Requirements
@@ -69,6 +77,8 @@ Og requires the following applications or libraries:
69
77
  * Ruby-mysql
70
78
  http://tmtm.org/ja/ruby/mysql/README_en.html
71
79
  Ruby interface to the MySQL RDBMS.
80
+ Pure Ruby Mysql interface:
81
+ http://www.tmtm.org/ruby/mysql/
72
82
 
73
83
  * PostgreSQL
74
84
  http://www.postgres.org
@@ -78,6 +88,9 @@ Og requires the following applications or libraries:
78
88
  http://www.mysql.org
79
89
  Used for the Database Backend.
80
90
 
91
+ * SQLite
92
+ http://www.sqlite.org/download.html
93
+
81
94
  Please install the required applications and libraries before continuing
82
95
  with the installation of Og. Only install the libraries needed for
83
96
  the backend you plan to use.
@@ -98,6 +111,16 @@ Then try to run the examples in the examples directory.
98
111
  A tar.gz distribution is also available on http://www.rubyforge.com/projects/nitro.
99
112
 
100
113
 
114
+ == Examples:
115
+
116
+ Some examples can be found in the examples directory. You are also
117
+ encouraged to check out the unit tests. Especially the test:
118
+
119
+ test/og/tc_store.rb
120
+
121
+ demonstrates some advanced features of Og.
122
+
123
+
101
124
  == Support
102
125
 
103
126
  For any questions regarding Og, feel free to ask on the ruby-talk
data/Rakefile CHANGED
@@ -1,7 +1,3 @@
1
- # * George Moschovitis <gm@navel.gr>
2
- # (c) 2005 Navel, all rights reserved.
3
- # $Id$
4
-
5
1
  require 'rake/rdoctask'
6
2
  require 'rake/testtask'
7
3
  require 'rake/gempackagetask'
@@ -61,9 +57,10 @@ spec = Gem::Specification.new do |s|
61
57
  s.description = 'An efficient and transparent Object-Relational mapping library'
62
58
 
63
59
  s.add_dependency 'glue', "= #{s.version}"
64
- # s.add_dependency 'postgres-pr', '>= 0.3.0'
65
- # s.add_dependency 'postgres', '>= 0.7.1'
66
- # s.add_dependency 'sqlite3-ruby', '>= 1.0.0'
60
+ s.add_dependency 'facets', '>= 0.7.1'
61
+ #s.add_dependency 'postgres-pr', '>= 0.3.0'
62
+ #s.add_dependency 'postgres', '>= 0.7.1'
63
+ #s.add_dependency 'sqlite3-ruby', '>= 1.0.0'
67
64
  #s.add_dependency 'mysql', '>= 2.5.1'
68
65
 
69
66
  s.required_ruby_version = '>= 1.8.2'
data/benchmark/bench.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # * George Moschovitis <gm@navel.gr>
2
2
  # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: bench.rb 1 2005-04-11 11:04:30Z gmosx $
3
+ # $Id: bench.rb 34 2005-04-26 09:07:39Z gmosx $
4
4
 
5
5
  require 'og'; include Og
6
6
 
data/doc/AUTHORS CHANGED
@@ -6,14 +6,14 @@ MAIN DEVELOPER:
6
6
 
7
7
  IDEAS, ADDITIONAL CODING, SUPPORT:
8
8
 
9
+ * Michael Neumann <mneumann@ntecs.de>
10
+ Design, additional coding and bug reports.
11
+
9
12
  * Matt Bowen <matt.bowen@farweststeel.com>
10
13
  Additional code and documentation.
11
14
 
12
15
  * Anastasios Koutoumanos <ak@navel.gr>
13
16
  Design, additional coding.
14
17
 
15
- * Michael Neumann <mneumann@ntecs.de>
16
- Design, additional coding and bug reports.
17
-
18
18
  * Thomas Quas <tquas@yahoo.com>
19
19
  Ideas, bug reports, unit tests.
data/doc/RELEASES CHANGED
@@ -1,9 +1,160 @@
1
- == Version 0.16.0
1
+ == Version 0.17.0
2
+
3
+ Og Reloaded!! A totally new, clean and elegant implementation
4
+ that supports tons of new advanced features. This version should
5
+ be considered as a preview, but you really have to *try* this!
6
+ A new version, with the rest of the planned features and bug
7
+ fixes is expected shortly. Many thanks to Michael Neumann and
8
+ the other hackers on the mailing list for ideas and suggestions
9
+ that made this version possible.
10
+
11
+ Most notable additions:
12
+
13
+ * Extremely clean source code. Better names are used thorougout.
14
+ Extra care was taken to make all features more orthogonal.
15
+
16
+ * Brand new relation mechanism. The 'enchanting' of entities
17
+ (managed classes) happens in multiple passes to be more
18
+ flexible. Totaly separated graph/metadata creation and serialization
19
+ code generation. The Graph metadata can be used for advanced
20
+ scaffolding, testing and more.
21
+
22
+ * Support for fully customizable primary keys. You are no longer
23
+ forced to use xxx_oid primary keys. Appart from the extra
24
+ flexibility this feature provides this is an essential step
25
+ towards the planed 'reverse engineering' mode that will allow the
26
+ use of existing schemas with Og.
27
+
28
+ * More elegant inspection mechanism. Example:
29
+
30
+ Article.relation(:user) # => Og::BelongsTo(...)
31
+ Article.relations # => [...]
32
+ Article.properties # => [...]
33
+
34
+ * Joins_many relation, as an alias for one way, join table relations.
35
+
36
+ * Support for 'active' collections. Active collection are
37
+ synchronized with the backend Store and provide a more elegant
38
+ interface and the opportunity for 'session' caching:
39
+
40
+ article.comments << Comment.new
41
+
42
+ instead of
43
+
44
+ article.add_comment(Comment.new) # this is also allowed though.
45
+
46
+ p article.comments
47
+ p article.comments.size # the results of the first query is cached
48
+
49
+ * Eager relations.
50
+
51
+ comments = Article.comments(:include => User)
52
+
53
+ for comment in comments
54
+ p comment.user.name
55
+ end
56
+
57
+ Elegantly solves the N+1 query problem by using one join
58
+ query.
59
+
60
+ * No need for forward references when defining relations. Now,
61
+ the following code magically works:
62
+
63
+ class User
64
+ has_many Comment # works even though Comment is not defined!
65
+ end
66
+
67
+ class Comment
68
+ belongs_to User
69
+ end
70
+
71
+ * Use inflection where possible to infer missing configuration
72
+ options. For example
73
+
74
+ class Article
75
+ belongs_to User # infects relation name :user
76
+ ...
77
+
78
+ * New, lean and mean Store interface. The code needed to teach
79
+ Og how to serialize objects to backend store is dramatically
80
+ reduced. The new interface is SQL agnostic, so non SQL-RDBM's
81
+ stores are possible.
82
+
83
+ * SQL agnostic querying interface, compatible with non-sql
84
+ Stores. Here is an example:
85
+
86
+ Article.find(
87
+ :condition => 'hits > 2 AND rate > 3',
88
+ :order => 'title',
89
+ :offset => 30,
90
+ :limit => 10
91
+ )
92
+
93
+ * More elegant (and non-sql store compatible) way for selective
94
+ updates:
95
+
96
+ article.title = 'Changed'
97
+ article.hits += 1
98
+ article.update(:title, :hits)
99
+
100
+ * New, in-memory store that support all features. This is a pure
101
+ ruby solution useful for experimentation. It will also serve
102
+ as the base for the forthcoming madeleine Store implementation.
103
+
104
+ * Allow for multiple stores in one application. A great example,
105
+ mysql_to_psql is provided. This example uses Og's powerfull
106
+ features to automatically convert a Mysql database to a
107
+ PostgreSQL database. Database migration was never easier.
108
+
109
+ * Uses the excellent Facets utility collection to further
110
+ clenup and minimize the code.
111
+
112
+ * Managed classes or Entities should include the EntityMixin
113
+ or extend the Entity class. Example:
114
+
115
+ class Article < Entity
116
+ ..
117
+ end
118
+
119
+ class Article
120
+ include EntityMixin
121
+ end
122
+
123
+ This is done to avoid the Module module like in earlier
124
+ versions of Og. However, Og is can infer the need to include
125
+ the Managed mixin in typical cases:
126
+
127
+ class Article
128
+ property :title, String
129
+ # when a property is defined Og automatically converts the
130
+ # class to an Entity
131
+ end
132
+
133
+ class Article < AnExistingManagedEntity
134
+ # also includes the mixin
135
+ ...
136
+
137
+ class Article
138
+ include AModuleThatDefinesProperties
139
+ ...
140
+
141
+ * Improved support for og_delete interception.
142
+
143
+ * Support for nested transactions.
144
+
145
+ * Many, many smaller features and changes.
146
+
147
+ Check out the file test/og/tc_store.rb for a demonstration of
148
+ the new features. The stores for Oracle and SqlServer are not
149
+ converted yet.
150
+
151
+
152
+ == Version 0.16.0 was released on 15/04/2005.
2
153
 
3
154
  A snapshot of the latest developments. Many, many subtle improvements,
4
155
  new features and a major cleanup of the source code.
5
156
 
6
- Most notable attitions:
157
+ Most notable additions:
7
158
 
8
159
  * Aspect Oriented Programming support. This new system
9
160
  is used to reimplement features such as Controller filters,
data/doc/config.txt CHANGED
@@ -14,13 +14,6 @@ applications/sites on a single database.
14
14
  If true, use Ruby's advanced introspection capabilities to
15
15
  automatically manage classes that define properties.
16
16
 
17
- === Og.enchant_managed_classes = true
18
-
19
- If true, the library automatically 'enchants' managed classes.
20
- In enchant mode, special db aware methods are added to
21
- managed classes and instances. If false, Og enchants only classes
22
- that define properties.
23
-
24
17
  === Og.create_schema = true
25
18
 
26
19
  If set to true, Og attempts to recreate the database schema
data/doc/tutorial.txt CHANGED
@@ -1,5 +1,12 @@
1
1
  = Og Tutorial
2
2
 
3
+ === WARNING
4
+
5
+ This tutorial is not updated for the latest code. However it is
6
+ a nice read to understand the spirit and feature of Og. Please
7
+ consult the API for the latest more advanced features of Og.
8
+
9
+
3
10
  === Introduction
4
11
 
5
12
  Ruby is a wonderful object oriented language featuring a well
data/examples/README CHANGED
@@ -9,3 +9,8 @@ automatically creates a 'test' database.
9
9
 
10
10
  Demonstrates how easily the Og infrastructure can be mocked,
11
11
  for easy test unit writing.
12
+
13
+ == mysql_to_psql.rb
14
+
15
+ Demonstrates how easy it is to migrate a mysql database
16
+ to postgres using Og.
@@ -1,4 +1,4 @@
1
- # = Og Mysql to PostgreSQL copy example
1
+ # = Mysql to PostgreSQL migration example.
2
2
  #
3
3
  # A simple example to demonstrate the flexibility of
4
4
  # Og. Two connections to different databases are
@@ -6,71 +6,46 @@
6
6
  # to a PostgreSQL database.
7
7
  #
8
8
  # Og makes it easier to switch to a REAL database :)
9
- #
10
- # * George Moschovitis <gm@navel.gr>
11
- # (c) 2004-2005 Navel, all rights reserved.
12
- # $Id: mysql_to_psql.rb 1 2005-04-11 11:04:30Z gmosx $
13
-
14
- raise 'WARNING, this example does not work yet, for the moment ' +
15
- 'just have a look at the source code.'
16
9
 
17
10
  require 'og'
18
11
 
19
- # An example managed object.
20
- # Looks like an ordinary Ruby object.
21
-
22
- class Article
23
- prop_accessor :name, :body, String
24
-
25
- def initialize(name = nil, body = nil)
26
- @name, @body = name, body
27
- end
28
- end
29
-
30
12
  # Configure databases.
31
13
 
32
14
  psql_config = {
33
- :address => 'localhost',
34
- :database => 'test',
35
- :backend => 'psql',
15
+ :destroy => true,
16
+ :name => 'test',
17
+ :store => 'psql',
36
18
  :user => 'postgres',
37
- :password => 'navelrulez',
38
- :connection_count => 1
19
+ :password => 'navelrulez'
39
20
  }
40
21
 
41
22
  mysql_config = {
42
- :address => 'localhost',
43
- :database => 'mysql',
44
- :backend => 'psql',
45
- :user => 'postgres',
46
- :password => 'navelrulez',
47
- :connection_count => 1
48
- }
49
- =begin
50
- mysql_config = {
51
- :address => 'localhost',
52
- :database => 'test',
53
- :backend => 'mysql',
23
+ :destroy => true,
24
+ :name => 'test',
25
+ :store => 'mysql',
54
26
  :user => 'root',
55
- :password => 'navelrulez',
56
- :connection_count => 1
27
+ :password => 'navelrulez'
57
28
  }
58
- =end
59
29
 
60
- # Cleanup the databases, remove data from
61
- # earlier executions.
30
+ # Initialize Og.
62
31
 
63
- Og::Database.drop!(psql_config)
64
- Og::Database.drop!(mysql_config)
32
+ psql = Og.connect(psql_config)
33
+ mysql = Og.connect(mysql_config)
65
34
 
66
- # Initialize Og.
35
+ # An example managed object.
36
+ # Looks like an ordinary Ruby object.
67
37
 
68
- psql = Og::Database.new(psql_config)
69
- mysql = Og::Database.new(mysql_config)
38
+ class Article
39
+ property :name, :body, String
40
+
41
+ def initialize(name = nil, body = nil)
42
+ @name, @body = name, body
43
+ end
44
+ end
70
45
 
71
46
  # First populate the mysql database.
72
47
 
73
- Og.use(mysql)
48
+ mysql.manage(Article)
74
49
 
75
50
  a1 = Article.create('name1', 'body1')
76
51
  a1 = Article.create('name1', 'body1')
@@ -82,15 +57,15 @@ articles = Article.all
82
57
 
83
58
  # Switch to PostgreSQL.
84
59
 
85
- Og.use(psql)
60
+ psql.manage(Article)
86
61
 
87
62
  # Store all articles.
88
63
 
89
64
  for article in articles
90
- article.save!
65
+ article.insert
91
66
  end
92
67
 
93
68
  # Fetch an article from PostgreSQL
94
69
  # as an example. Lookup by name.
95
70
 
96
- article = Article['name1']
71
+ article = Article.find_by_name('name1')