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
-
#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
-
#update_after_commit(db_object) ⇒ Object
:nodoc:.
Constructor Details
#initialize(domain_class, db_bridge) ⇒ DomainClassCache
Returns a new instance of DomainClassCache.
372 373 374 375 376 377 |
# File 'lib/lafcadio/objectStore.rb', line 372 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.
370 371 372 |
# File 'lib/lafcadio/objectStore.rb', line 370 def commit_times @commit_times end |
#domain_class ⇒ Object (readonly)
Returns the value of attribute domain_class.
370 371 372 |
# File 'lib/lafcadio/objectStore.rb', line 370 def domain_class @domain_class end |
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
370 371 372 |
# File 'lib/lafcadio/objectStore.rb', line 370 def queries @queries end |
Instance Method Details
#[](pk_id) ⇒ Object
379 380 381 382 |
# File 'lib/lafcadio/objectStore.rb', line 379 def []( pk_id ) dobj = super dobj ? dobj.clone : nil end |
#collect_from_superset(query) ⇒ Object
384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/lafcadio/objectStore.rb', line 384 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
397 398 399 400 401 402 403 |
# File 'lib/lafcadio/objectStore.rb', line 397 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.
406 407 408 409 |
# File 'lib/lafcadio/objectStore.rb', line 406 def flush( db_object ) delete db_object.pk_id flush_queries end |
#flush_queries ⇒ Object
411 412 413 414 415 |
# File 'lib/lafcadio/objectStore.rb', line 411 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
417 |
# File 'lib/lafcadio/objectStore.rb', line 417 def last_commit_time( pk_id ); commit_times[pk_id]; end |
#save(db_object) ⇒ Object
Saves a domain object.
420 421 422 423 |
# File 'lib/lafcadio/objectStore.rb', line 420 def save(db_object) self[db_object.pk_id] = db_object flush_queries end |
#set_commit_time(d_obj) ⇒ Object
425 |
# File 'lib/lafcadio/objectStore.rb', line 425 def set_commit_time( d_obj ); commit_times[d_obj.pk_id] = Time.now; end |
#update_after_commit(db_object) ⇒ Object
:nodoc:
427 428 429 430 431 432 433 434 435 436 |
# File 'lib/lafcadio/objectStore.rb', line 427 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 |