Class: FDB::Transaction

Inherits:
TransactionRead show all
Defined in:
lib/fdbimpl.rb

Instance Attribute Summary collapse

Attributes inherited from TransactionRead

#db, #tpointer

Instance Method Summary collapse

Methods inherited from TransactionRead

finalize, #get, #get_key, #get_range, #get_range_start_with, #get_read_version, #transact

Constructor Details

#initialize(tpointer, db) ⇒ Transaction

Returns a new instance of Transaction.



827
828
829
830
831
832
833
834
835
836
# File 'lib/fdbimpl.rb', line 827

def initialize(tpointer, db)
  super(tpointer, db, 0)
  @snapshot = TransactionRead.new(tpointer, db, 1)

  @options = TransactionOptions.new lambda { |code, param|
    FDBC.check_error FDBC.fdb_transaction_set_option(@tpointer, code, param, param.nil? ? 0 : param.bytesize)
  }

  ObjectSpace.undefine_finalizer self
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



825
826
827
# File 'lib/fdbimpl.rb', line 825

def options
  @options
end

#snapshotObject (readonly)

Returns the value of attribute snapshot.



825
826
827
# File 'lib/fdbimpl.rb', line 825

def snapshot
  @snapshot
end

Instance Method Details

#add_read_conflict_key(key) ⇒ Object



851
852
853
854
# File 'lib/fdbimpl.rb', line 851

def add_read_conflict_key(key)
  key = FDB.key_to_bytes(key)
  add_read_conflict_range(key, key + "\x00")
end

#add_read_conflict_range(bkey, ekey) ⇒ Object



845
846
847
848
849
# File 'lib/fdbimpl.rb', line 845

def add_read_conflict_range(bkey, ekey)
  bkey = FDB.key_to_bytes(bkey)
  ekey = FDB.key_to_bytes(ekey)
  FDBC.check_error FDBC.fdb_transaction_add_conflict_range(@tpointer, bkey, bkey.bytesize, ekey, ekey.bytesize, @@ConflictRangeType["READ"][0])
end

#add_write_conflict_key(key) ⇒ Object



862
863
864
865
# File 'lib/fdbimpl.rb', line 862

def add_write_conflict_key(key)
  key = FDB.key_to_bytes(key)
  add_write_conflict_range(key, key + "\x00")
end

#add_write_conflict_range(bkey, ekey) ⇒ Object



856
857
858
859
860
# File 'lib/fdbimpl.rb', line 856

def add_write_conflict_range(bkey, ekey)
  bkey = FDB.key_to_bytes(bkey)
  ekey = FDB.key_to_bytes(ekey)
  FDBC.check_error FDBC.fdb_transaction_add_conflict_range(@tpointer, bkey, bkey.bytesize, ekey, ekey.bytesize, @@ConflictRangeType["WRITE"][0])
end

#cancelObject



920
921
922
# File 'lib/fdbimpl.rb', line 920

def cancel
  FDBC.fdb_transaction_cancel @tpointer
end

#clear(key) ⇒ Object



881
882
883
884
# File 'lib/fdbimpl.rb', line 881

def clear(key)
  key = FDB.key_to_bytes(key)
  FDBC.fdb_transaction_clear(@tpointer, key, key.bytesize)
end

#clear_range(bkey, ekey) ⇒ Object



886
887
888
889
890
# File 'lib/fdbimpl.rb', line 886

def clear_range(bkey, ekey)
  bkey = FDB.key_to_bytes(bkey)
  ekey = FDB.key_to_bytes(ekey)
  FDBC.fdb_transaction_clear_range(@tpointer, bkey || "", bkey && bkey.bytesize || 0, ekey || "", ekey && ekey.bytesize || 0)
end

#clear_range_start_with(prefix) ⇒ Object



892
893
894
895
896
# File 'lib/fdbimpl.rb', line 892

def clear_range_start_with(prefix)
  prefix = FDB.key_to_bytes(prefix)
  prefix = prefix.dup.force_encoding "BINARY"
  clear_range(prefix, FDB.strinc(prefix))
end

#commitObject



867
868
869
# File 'lib/fdbimpl.rb', line 867

def commit
  FutureNil.new(FDBC.fdb_transaction_commit(@tpointer))
end

#get_approximate_sizeObject



908
909
910
# File 'lib/fdbimpl.rb', line 908

def get_approximate_size
  Int64Future.new(FDBC.fdb_transaction_get_approximate_size @tpointer)
end

#get_committed_versionObject



902
903
904
905
906
# File 'lib/fdbimpl.rb', line 902

def get_committed_version
  version = FFI::MemoryPointer.new :int64
  FDBC.check_error FDBC.fdb_transaction_get_committed_version(@tpointer, version)
  version.read_long_long
end

#get_versionstampObject



912
913
914
# File 'lib/fdbimpl.rb', line 912

def get_versionstamp
  Key.new(FDBC.fdb_transaction_get_versionstamp(@tpointer))
end

#on_error(e) ⇒ Object



876
877
878
879
# File 'lib/fdbimpl.rb', line 876

def on_error(e)
  raise e if !e.kind_of? Error
  FutureNil.new(FDBC.fdb_transaction_on_error(@tpointer, e.code))
end

#resetObject



916
917
918
# File 'lib/fdbimpl.rb', line 916

def reset
  FDBC.fdb_transaction_reset @tpointer
end

#set(key, value) ⇒ Object Also known as: []=



838
839
840
841
842
# File 'lib/fdbimpl.rb', line 838

def set(key, value)
  key = FDB.key_to_bytes(key)
  value = FDB.value_to_bytes(value)
  FDBC.fdb_transaction_set(@tpointer, key, key.bytesize, value, value.bytesize)
end

#set_read_version(version) ⇒ Object



898
899
900
# File 'lib/fdbimpl.rb', line 898

def set_read_version(version)
  FDBC.fdb_transaction_set_read_version(@tpointer, version)
end

#watch(key) ⇒ Object



871
872
873
874
# File 'lib/fdbimpl.rb', line 871

def watch(key)
  key = FDB.key_to_bytes(key)
  FutureNil.new(FDBC.fdb_transaction_watch(@tpointer, key, key.bytesize))
end