class FDB::TransactionRead

Attributes

db[R]
tpointer[R]

Public Class Methods

finalize(ptr) click to toggle source
# File lib/fdbimpl.rb, line 707
def self.finalize(ptr)
  proc do
    #puts "Destroying transaction #{ptr}"
    FDBC.fdb_transaction_destroy(ptr)
  end
end
new(tpointer, db, is_snapshot) click to toggle source
# File lib/fdbimpl.rb, line 714
def initialize(tpointer, db, is_snapshot)
  @tpointer = tpointer
  @db = db
  @is_snapshot = is_snapshot

  ObjectSpace.define_finalizer(self, self.class.finalize(@tpointer))
end

Public Instance Methods

[](key)
Alias for: get
each() { |result| ... } click to toggle source
# File lib/fdbimpl.rb, line 780
def each
  bsel = @bsel
  esel = @esel
  limit = @limit

  iteration = 1 # the first read was fired off when the RangeEnum was initialized
  future = @future

  done = false

  while !done
    if future
      kvs, count, more = future.wait
      index = 0
      future = nil

      return if count.zero?
    end

    result = kvs[index]
    index += 1

    if index == count
      if more.zero? || limit == count
        done = true
      else
        iteration += 1
        if limit.nonzero?
          limit -= count
        end
        if @reverse.nonzero?
          esel = KeySelector.first_greater_or_equal(kvs.last.key)
        else
          bsel = KeySelector.first_greater_than(kvs.last.key)
        end
        future = @get_range.call(bsel, esel, limit, @mode, iteration, @reverse)
      end
    end

    yield result
  end
end
get(key) click to toggle source
# File lib/fdbimpl.rb, line 730
def get(key)
  key = FDB.key_to_bytes(key)
  Value.new(FDBC.fdb_transaction_get(@tpointer, key, key.bytesize, @is_snapshot))
end
Also aliased as: []
get_key(keysel) click to toggle source
# File lib/fdbimpl.rb, line 736
def get_key(keysel)
  key = FDB.key_to_bytes(keysel.key)
  Key.new(FDBC.fdb_transaction_get_key(@tpointer, key, key.bytesize, keysel.or_equal, keysel.offset, @is_snapshot))
end
get_range(bkeysel, ekeysel, options={}, &block) click to toggle source
# File lib/fdbimpl.rb, line 824
def get_range(bkeysel, ekeysel, options={}, &block)
  defaults = { :limit => 0, :reverse => false, :streaming_mode => :iterator }
  options = defaults.merge options
  bsel = to_selector bkeysel
  esel = to_selector ekeysel

  if options[:streaming_mode].kind_of? Symbol
    streaming_mode = @@StreamingMode[options[:streaming_mode].to_s.upcase]
    raise ArgumentError, "#{options[:streaming_mode]} is not a valid streaming mode" if !streaming_mode
    streaming_mode = streaming_mode[0]
  else
    streaming_mode = options[:streaming_mode]
  end

  r = @@RangeEnum.new(lambda {|bsel, esel, limit, streaming_mode, iteration, reverse|
                        begin_key = FDB.key_to_bytes(bsel.key)
                        end_key = FDB.key_to_bytes(esel.key)
                        FDB::FutureKeyValueArray.new(FDBC.fdb_transaction_get_range(@tpointer, begin_key, begin_key.bytesize, bsel.or_equal, bsel.offset, end_key, end_key.bytesize, esel.or_equal, esel.offset, limit, 0, streaming_mode, iteration, @is_snapshot, reverse))
                      }, bsel, esel, options[:limit], options[:reverse] ? 1 : 0, streaming_mode)

  if !block_given?
    r
  else
    r.each &block
  end
end
get_range_start_with(prefix, options={}, &block) click to toggle source
# File lib/fdbimpl.rb, line 851
def get_range_start_with(prefix, options={}, &block)
  prefix = FDB.key_to_bytes(prefix)
  prefix = prefix.dup.force_encoding "BINARY"
  get_range(prefix, FDB.strinc(prefix), options, &block)
end
get_read_version() click to toggle source
# File lib/fdbimpl.rb, line 726
def get_read_version
  Version.new(FDBC.fdb_transaction_get_read_version @tpointer)
end
to_a() click to toggle source
# File lib/fdbimpl.rb, line 766
def to_a
  o = self.dup
  o.instance_eval do
    if @mode == @@StreamingMode["ITERATOR"][0]
      if @limit.zero?
        @mode = @@StreamingMode["WANT_ALL"][0]
      else
        @mode = @@StreamingMode["EXACT"][0]
      end
    end
  end
  Enumerable.instance_method(:to_a).bind(o).call
end
transact() { |self| ... } click to toggle source
# File lib/fdbimpl.rb, line 722
def transact
  yield self
end

Private Instance Methods

to_selector(key_or_selector) click to toggle source
# File lib/fdbimpl.rb, line 741
def to_selector(key_or_selector)
  if key_or_selector.kind_of? KeySelector
    key_or_selector
  else
    KeySelector.first_greater_or_equal key_or_selector
  end
end