A Store is a backend of Og used to persist objects. An adapter specializes the Store. For example the SQL Store has the MySQL, PostgreSQL, Sqlite3 etc adapters as specializations.

Contents
Methods
Attributes
[RW] ogmanager
Public Class methods
new(options)

Create a session to the store.

Default options:

  :evolve_schema => :warn
    # File lib/og/store.rb, line 18
18:   def initialize options
19:     @options = {
20:       :evolve_schema => :warn
21:     }.merge(options)
22:     @transaction_nesting = 0
23:   end
Public Instance methods
close()

Close the session to the store.

    # File lib/og/store.rb, line 27
27:   def close
28:   end
enchant(klass, manager)

Enchants a class.

    # File lib/og/store.rb, line 32
32:   def enchant(klass, manager)
33:     pk = klass.primary_key
34:     klass.module_eval %{
35:     
36:       # A managed object is considered saved if it has 
37:       # a valid primary key.
38:       
39:       def saved?
40:         return #{pk}
41:       end
42: 
43:       # The inverse of saved.
44:       
45:       def unsaved?
46:         return !#{pk}
47:       end
48: 
49:       # Evaluate an alias for the primary key.
50: 
51:       alias_method :pk, :#{pk}
52:       alias_method :pk=, :#{pk}=
53:     }
54:   end
Public Instance methods
<<(obj, options = nil)

Alias for #save

aupdate(target, *attributes)

Alias for #update_attributes

count(options)

Count the results returned by the query.

     # File lib/og/store.rb, line 159
159:   def count(options)
160:     raise "Not implemented"
161:   end
delete(obj_or_pk, klass = nil, cascade = true)

Permanently delete an object from the store.

     # File lib/og/store.rb, line 127
127:   def delete(obj_or_pk, klass = nil, cascade = true)
128:     unless obj_or_pk.is_a? ModelMixin 
129:       # create an instance to keep the og_delete
130:       # method as an instance method like the other lifecycle
131:       # methods. This even allows to call og_delete aspects
132:       # that use instance variable (for example, sophisticated
133:       # cache sweepers).
134:       #
135:       # gmosx: the following is not enough!
136:       # obj = klass.allocate
137:       # obj.pk = obj_or_pk
138:       obj = klass[obj_or_pk]
139:       obj.og_delete(self, cascade)
140:     else
141:       obj_or_pk.og_delete(self, cascade)
142:     end
143:   end
delete_all(klass)

Delete all instances of the given class.

     # File lib/og/store.rb, line 147
147:   def delete_all(klass)
148:     raise "Not implemented"
149:   end
exist?(pk, klass)

Alias for #load

find(klass, options)

Perform a query.

     # File lib/og/store.rb, line 153
153:   def find(klass, options)
154:     raise "Not implemented"
155:   end
force_save!(obj, options)

Force the persistence of an Object. Ignore any validation and/or other errors.

     # File lib/og/store.rb, line 96
 96:   def force_save!(obj, options)
 97:     if obj.saved?
 98:       obj.og_update self, options
 99:     else
100:       obj.og_insert self
101:     end
102:   end
insert(obj)

Insert an object in the store.

     # File lib/og/store.rb, line 106
106:   def insert(obj)
107:     obj.og_insert self
108:   end
load(pk, klass)

Loads an object from the store using the primary key.

This method is also aliased as exist?
    # File lib/og/store.rb, line 60
60:   def load(pk, klass)
61:     raise 'Not implemented'
62:   end
reload(obj)

Reloads an object from the store.

    # File lib/og/store.rb, line 67
67:   def reload(obj)
68:     raise 'Not implemented'
69:   end
save(obj, options = nil)

Save an object to store. Insert if this is a new object or update if this is already inserted in the database. Checks if the object is valid before saving. Returns false if the object is invalid and populates obj.errors.

This method is also aliased as << validate_and_save
    # File lib/og/store.rb, line 76
76:   def save(obj, options = nil)
77:     return false unless obj.valid?
78: 
79:     if obj.saved?
80:       update_count = obj.og_update(self, options)
81:     else
82:       update_count = 1 if obj.og_insert(self)
83:     end
84: 
85:     # Save building collections if any.
86:     obj.save_building_collections
87:   
88:     return update_count
89:   end
update(obj, options = nil)

Update an object in the store.

     # File lib/og/store.rb, line 112
112:   def update(obj, options = nil)
113:     obj.og_update self, options
114:   end
update_attribute(target, *attributes)

Alias for #update_attributes

update_attributes(target, *attributes)

Update selected attributes of an object or class of objects.

This method is also aliased as aupdate update_attribute
     # File lib/og/store.rb, line 119
119:   def update_attributes(target, *attributes)
120:     update(target, :only => attributes)
121:   end
validate_and_save(obj, options = nil)

Alias for #save

Public Instance methods
commit()

Commit a transaction.

     # File lib/og/store.rb, line 175
175:   def commit
176:     raise "Not implemented"
177:     @transaction_nesting -= 1
178:     true if @transaction_nesting < 1
179:   end
rollback()

Rollback a transaction.

     # File lib/og/store.rb, line 183
183:   def rollback
184:     @transaction_nesting -= 1
185:     true if @transaction_nesting < 1
186:   end
start()

Start a new transaction.

     # File lib/og/store.rb, line 167
167:   def start
168:     raise "Not implemented"
169:     true if @transaction_nesting < 1
170:     @transaction_nesting += 1
171:   end
transaction() {|self| ...}

Transaction helper. In the transaction block use the db pointer to the backend.

     # File lib/og/store.rb, line 191
191:   def transaction(&block)
192:     start
193:     yield self
194:   rescue Object => ex
195:     rollback
196:   else
197:     commit
198:   end