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
Returns the value of attribute commit_times.
-
#domain_class ⇒ Object
readonly
Returns the value of attribute domain_class.
-
#queries ⇒ Object
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
-
#initialize(domain_class, db_bridge) ⇒ DomainClassCache
constructor
A new instance of DomainClassCache.
- #last_commit_time(pk_id) ⇒ Object
-
#save(db_object) ⇒ Object
Saves a domain object.
- #set_commit_time(d_obj) ⇒ Object
- #transactional_clone ⇒ Object
-
#update_after_commit(db_object) ⇒ Object
:nodoc:.
Constructor Details
#initialize(domain_class, db_bridge) ⇒ DomainClassCache
Returns a new instance of DomainClassCache.
399 400 401 402 403 404 |
# File 'lib/lafcadio/objectStore.rb', line 399 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
Returns the value of attribute commit_times.
397 398 399 |
# File 'lib/lafcadio/objectStore.rb', line 397 def commit_times @commit_times end |
#domain_class ⇒ Object (readonly)
Returns the value of attribute domain_class.
396 397 398 |
# File 'lib/lafcadio/objectStore.rb', line 396 def domain_class @domain_class end |
#queries ⇒ Object
Returns the value of attribute queries.
397 398 399 |
# File 'lib/lafcadio/objectStore.rb', line 397 def queries @queries end |
Instance Method Details
#[](pk_id) ⇒ Object
406 407 408 409 |
# File 'lib/lafcadio/objectStore.rb', line 406 def []( pk_id ) dobj = super dobj ? dobj.clone : nil end |
#collect_from_superset(query) ⇒ Object
411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/lafcadio/objectStore.rb', line 411 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
424 425 426 427 428 429 430 |
# File 'lib/lafcadio/objectStore.rb', line 424 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.
433 434 435 436 |
# File 'lib/lafcadio/objectStore.rb', line 433 def flush( db_object ) delete db_object.pk_id flush_queries end |
#flush_queries ⇒ Object
438 439 440 441 442 |
# File 'lib/lafcadio/objectStore.rb', line 438 def flush_queries queries.keys.each do |query| queries.delete( query ) if query.domain_class == domain_class end end |
#last_commit_time(pk_id) ⇒ Object
444 |
# File 'lib/lafcadio/objectStore.rb', line 444 def last_commit_time( pk_id ); commit_times[pk_id]; end |
#save(db_object) ⇒ Object
Saves a domain object.
447 448 449 450 |
# File 'lib/lafcadio/objectStore.rb', line 447 def save(db_object) self[db_object.pk_id] = db_object flush_queries end |
#set_commit_time(d_obj) ⇒ Object
452 |
# File 'lib/lafcadio/objectStore.rb', line 452 def set_commit_time( d_obj ); commit_times[d_obj.pk_id] = Time.now; end |
#transactional_clone ⇒ Object
454 455 456 457 458 459 |
# File 'lib/lafcadio/objectStore.rb', line 454 def transactional_clone tc = clone tc.commit_times = commit_times.clone tc.queries = queries.clone tc end |
#update_after_commit(db_object) ⇒ Object
:nodoc:
461 462 463 464 465 466 467 468 469 470 |
# File 'lib/lafcadio/objectStore.rb', line 461 def update_after_commit( db_object ) #:nodoc: if [ :update, :insert ].include?( db_object.last_commit_type ) save db_object elsif db_object.last_commit_type == :delete flush db_object end set_commit_time db_object end |