Class: Lafcadio::ObjectStore::Cache::DomainClassCache
- Inherits:
-
Hash
- Object
- Hash
- Lafcadio::ObjectStore::Cache::DomainClassCache
- Defined in:
- lib/lafcadio/objectStore.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#commit_times ⇒ Object
readonly
Returns the value of attribute commit_times.
-
#domain_class ⇒ Object
readonly
Returns the value of attribute domain_class.
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
Instance Method Summary collapse
- #[](pk_id) ⇒ Object
- #collect_from_superset(query) ⇒ Object
- #find_superset_pk_ids(query) ⇒ Object
-
#flush(db_object) ⇒ Object
Flushes a domain object.
- #flush_queries ⇒ Object
- #get_by_query(query) ⇒ Object
-
#initialize(domain_class, db_bridge) ⇒ DomainClassCache
constructor
A new instance of DomainClassCache.
- #last_commit_time(pk_id) ⇒ Object
- #query_db(query) ⇒ Object
-
#save(db_object) ⇒ Object
Saves a domain object.
- #set_commit_time(d_obj) ⇒ Object
-
#update_after_commit(db_object) ⇒ Object
:nodoc:.
Constructor Details
#initialize(domain_class, db_bridge) ⇒ DomainClassCache
Returns a new instance of DomainClassCache.
337 338 339 340 341 342 |
# File 'lib/lafcadio/objectStore.rb', line 337 def initialize( domain_class, db_bridge ) super() @domain_class, @db_bridge = domain_class, db_bridge @commit_times = {} @queries = {} end |
Instance Attribute Details
#commit_times ⇒ Object (readonly)
Returns the value of attribute commit_times.
335 336 337 |
# File 'lib/lafcadio/objectStore.rb', line 335 def commit_times @commit_times end |
#domain_class ⇒ Object (readonly)
Returns the value of attribute domain_class.
335 336 337 |
# File 'lib/lafcadio/objectStore.rb', line 335 def domain_class @domain_class end |
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
335 336 337 |
# File 'lib/lafcadio/objectStore.rb', line 335 def queries @queries end |
Instance Method Details
#[](pk_id) ⇒ Object
344 345 346 347 |
# File 'lib/lafcadio/objectStore.rb', line 344 def []( pk_id ) dobj = super dobj ? dobj.clone : nil end |
#collect_from_superset(query) ⇒ Object
349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/lafcadio/objectStore.rb', line 349 def collect_from_superset( query ) if ( pk_ids = find_superset_pk_ids( query ) ) db_objects = ( pk_ids.collect { |pk_id| self[ pk_id ] } ).select { |dobj| query.dobj_satisfies?( dobj ) } db_objects = query.order_and_limit_collection db_objects queries[query] = db_objects.collect { |dobj| dobj.pk_id } true else false end end |
#find_superset_pk_ids(query) ⇒ Object
362 363 364 365 366 367 368 |
# File 'lib/lafcadio/objectStore.rb', line 362 def find_superset_pk_ids( query ) superset_query, pk_ids = queries.find { |other_query, pk_ids| query.implies?( other_query ) } pk_ids end |
#flush(db_object) ⇒ Object
Flushes a domain object.
371 372 373 374 |
# File 'lib/lafcadio/objectStore.rb', line 371 def flush( db_object ) delete db_object.pk_id flush_queries end |
#flush_queries ⇒ Object
376 377 378 379 380 |
# File 'lib/lafcadio/objectStore.rb', line 376 def flush_queries queries.keys.each do |query| queries.delete( query ) if query.domain_class == domain_class end end |
#get_by_query(query) ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/lafcadio/objectStore.rb', line 382 def get_by_query( query ) unless queries[query] collected = collect_from_superset query if !collected and queries.values query_db query end end collection = [] queries[query].each { |pk_id| dobj = self[ pk_id ] collection << dobj if dobj } collection end |
#last_commit_time(pk_id) ⇒ Object
397 |
# File 'lib/lafcadio/objectStore.rb', line 397 def last_commit_time( pk_id ); commit_times[pk_id]; end |
#query_db(query) ⇒ Object
399 400 401 402 403 |
# File 'lib/lafcadio/objectStore.rb', line 399 def query_db( query ) newObjects = @db_bridge.select_dobjs query newObjects.each { |dbObj| save dbObj } queries[query] = newObjects.collect { |dobj| dobj.pk_id } end |
#save(db_object) ⇒ Object
Saves a domain object.
406 407 408 409 |
# File 'lib/lafcadio/objectStore.rb', line 406 def save(db_object) self[db_object.pk_id] = db_object flush_queries end |
#set_commit_time(d_obj) ⇒ Object
411 |
# File 'lib/lafcadio/objectStore.rb', line 411 def set_commit_time( d_obj ); commit_times[d_obj.pk_id] = Time.now; end |
#update_after_commit(db_object) ⇒ Object
:nodoc:
413 414 415 416 417 418 419 420 421 422 |
# File 'lib/lafcadio/objectStore.rb', line 413 def update_after_commit( db_object ) #:nodoc: if [ DomainObject::COMMIT_EDIT, DomainObject::COMMIT_ADD ].include?( db_object.last_commit_type ) save db_object elsif db_object.last_commit_type == DomainObject::COMMIT_DELETE flush db_object end set_commit_time db_object end |