Skip to content

Commit

Permalink
hacks to make work with push runtime. need to DRY up all the storage …
Browse files Browse the repository at this point in the history
…code.
  • Loading branch information
jhellerstein committed Sep 21, 2011
1 parent 5c20a42 commit cbd1182
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
31 changes: 27 additions & 4 deletions lib/bud/storage/dbm.rb
Expand Up @@ -77,6 +77,10 @@ def each(&block)
each_from([@delta], &block)
each_storage(&block)
end

def each_raw(&block)
each_storage(&block)
end

def each_from(bufs, &block)
bufs.each do |b|
Expand Down Expand Up @@ -131,14 +135,33 @@ def tick_deltas
merge_to_db(@delta)
@delta = @new_delta
@new_delta = {}
return !(@delta == {})
end

public
def flush_deltas
merge_to_db(@delta)
merge_to_db(@new_delta)
@delta = {}
@new_delta = {}
end

# This is verbatim from BudTable. Need to DRY up. Should we be a subclass of BudTable?
public
def pending_delete(o)
if o.class <= Bud::PushElement
o.wire_to_delete self
elsif o.class <= Bud::BudCollection
o.pro.wire_to_delete self
else
@to_delete = @to_delete + o.map{|t| prep_tuple(t) unless t.nil?}
end
end
superator "<-" do |o|
o.each do |tuple|
@to_delete << tuple unless tuple.nil?
end
pending_delete(o)
end



def insert(tuple)
key = @key_colnums.map{|k| tuple[k]}
merge_tuple(key, tuple)
Expand Down
30 changes: 26 additions & 4 deletions lib/bud/storage/tokyocabinet.rb
Expand Up @@ -83,7 +83,11 @@ def each(&block)
each_from([@delta], &block)
each_storage(&block)
end


def each_raw(&block)
each_storage(&block)
end

def each_from(bufs, &block)
bufs.each do |b|
if b == @storage then
Expand Down Expand Up @@ -135,12 +139,30 @@ def tick_deltas
merge_to_hdb(@delta)
@delta = @new_delta
@new_delta = {}
return !(@delta == {})
end

public
def flush_deltas
merge_to_hdb(@delta)
merge_to_hdb(@new_delta)
@delta = {}
@new_delta = {}
end

# This is verbatim from BudTable. Need to DRY up. Should we be a subclass of BudTable?
public
def pending_delete(o)
if o.class <= Bud::PushElement
o.wire_to_delete self
elsif o.class <= Bud::BudCollection
o.pro.wire_to_delete self
else
@to_delete = @to_delete + o.map{|t| prep_tuple(t) unless t.nil?}
end
end
superator "<-" do |o|
o.each do |tuple|
@to_delete << tuple unless tuple.nil?
end
pending_delete(o)
end

def insert(tuple)
Expand Down

0 comments on commit cbd1182

Please sign in to comment.