Class: Java::Kyotocabinet::DB

Inherits:
Object
  • Object
show all
Includes:
KyotoCabinet::Adaptation
Defined in:
lib/kyotocabinet.rb

Overview

class Cursor

Constant Summary collapse

GCONCURRENT =

The Java API is thread-safe so this can be a no-op

0

Constants included from KyotoCabinet::Adaptation

KyotoCabinet::Adaptation::BYTE_ARRAY

Instance Method Summary collapse

Methods included from KyotoCabinet::Adaptation

#conv_string_array, included, #ret_bytes, #to_string_array

Instance Method Details

#_acceptObject



249
# File 'lib/kyotocabinet.rb', line 249

alias_method :_accept, :accept

#_accept_bulkObject



263
# File 'lib/kyotocabinet.rb', line 263

alias_method :_accept_bulk, :accept_bulk

#_getObject



296
# File 'lib/kyotocabinet.rb', line 296

alias_method :_get, :get

#_get_bulkObject



302
# File 'lib/kyotocabinet.rb', line 302

alias_method :_get_bulk, :get_bulk

#_incrementObject



314
# File 'lib/kyotocabinet.rb', line 314

alias_method :_increment, :increment

#_increment_doubleObject



319
# File 'lib/kyotocabinet.rb', line 319

alias_method :_increment_double, :increment_double

#_iterateObject



324
# File 'lib/kyotocabinet.rb', line 324

alias_method :_iterate, :iterate

#_match_prefixObject



335
# File 'lib/kyotocabinet.rb', line 335

alias_method :_match_prefix, :match_prefix

#_match_regexObject



340
# File 'lib/kyotocabinet.rb', line 340

alias_method :_match_regex, :match_regex

#_match_similarObject



345
# File 'lib/kyotocabinet.rb', line 345

alias_method :_match_similar, :match_similar

#_mergeObject



350
# File 'lib/kyotocabinet.rb', line 350

alias_method :_merge, :merge

#_occupyObject



355
# File 'lib/kyotocabinet.rb', line 355

alias_method :_occupy, :occupy

#_openObject



360
# File 'lib/kyotocabinet.rb', line 360

alias_method :_open, :open

#_remove_bulkObject



368
# File 'lib/kyotocabinet.rb', line 368

alias_method :_remove_bulk, :remove_bulk

#_setObject



377
# File 'lib/kyotocabinet.rb', line 377

alias_method :_set, :set

#_set_bulkObject



384
# File 'lib/kyotocabinet.rb', line 384

alias_method :_set_bulk, :set_bulk

#_synchronizeObject

TODO: store?



398
# File 'lib/kyotocabinet.rb', line 398

alias_method :_synchronize, :synchronize

#accept(key, visitor = nil, writable = true, &blk) ⇒ Object



250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/kyotocabinet.rb', line 250

def accept(key, visitor=nil, writable=true, &blk)
  vp = if visitor
         VisitorProxy.new(visitor, !writable)
       else
         if writable
           BlockVisitor.wrap(blk)
         else               
           BlockVisitor.wrap_nop(blk)
         end
       end
  self._accept(key.to_java_bytes, vp, writable)
end

#accept_bulk(keys, visitor = nil, writable = true, &blk) ⇒ Object



264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/kyotocabinet.rb', line 264

def accept_bulk(keys, visitor=nil, writable=true, &blk)
  vp = if visitor
         VisitorProxy.new(visitor, !writable)
       else
         if writable
           BlockVisitor.wrap(blk)
         else               
           BlockVisitor.wrap_nop(blk)
         end
       end
  self._accept_bulk(conv_string_array(keys), vp, writable)
end

#cursor_processObject



415
416
417
418
419
420
421
422
# File 'lib/kyotocabinet.rb', line 415

def cursor_process
  cur = self.cursor()
  begin
    yield cur
  ensure
    cur.disable()
  end
end

#each(&blk) ⇒ Object



282
283
284
# File 'lib/kyotocabinet.rb', line 282

def each(&blk)
  _iterate(BlockVisitor.wrap_nop(blk), false)
end

#each_keyObject



286
287
288
289
# File 'lib/kyotocabinet.rb', line 286

def each_key
  _iterate(BlockVisitor.wrap_nop(lambda { |k, v| yield [k] }),
           false)
end

#each_valueObject



291
292
293
294
# File 'lib/kyotocabinet.rb', line 291

def each_value
  _iterate(BlockVisitor.wrap_nop(lambda { |k, v| yield [v] }),
           false)
end

#get(key) ⇒ Object Also known as: []



297
298
299
# File 'lib/kyotocabinet.rb', line 297

def get(key)
  ret_bytes(self._get(key.to_java_bytes))
end

#get_bulk(keys, atomic = true) ⇒ Object



303
304
305
306
307
308
309
310
311
312
# File 'lib/kyotocabinet.rb', line 303

def get_bulk(keys, atomic=true)
  ra = _get_bulk(conv_string_array(keys), atomic)
  h = {}
  i = 0
  while i < ra.size
    h[String.from_java_bytes(ra[i])] = String.from_java_bytes(ra[i + 1])
    i += 2
  end
  h
end

#increment(key, num = 0, orig = 0) ⇒ Object



315
316
317
# File 'lib/kyotocabinet.rb', line 315

def increment(key, num=0, orig=0)
  self._increment(key.to_java_bytes, num, orig)
end

#increment_double(key, num = 0, orig = 0) ⇒ Object



320
321
322
# File 'lib/kyotocabinet.rb', line 320

def increment_double(key, num=0, orig=0)
  _increment_double(key.to_java_bytes, num, orig)
end

#iterate(visitor = nil, writable = true, &blk) ⇒ Object



325
326
327
328
329
330
331
332
333
# File 'lib/kyotocabinet.rb', line 325

def iterate(visitor=nil, writable=true, &blk)
  if visitor
    _iterate(VisitorProxy.new(visitor),
             writable)
  else
    _iterate(BlockVisitor.wrap(blk),
             writable)
  end
end

#match_prefix(prefix, max = -1)) ⇒ Object



336
337
338
# File 'lib/kyotocabinet.rb', line 336

def match_prefix(prefix, max=-1)
  _match_prefix(prefix, max)
end

#match_regex(regex, max = -1)) ⇒ Object



341
342
343
# File 'lib/kyotocabinet.rb', line 341

def match_regex(regex, max=-1)
  _match_regex(regex, max)
end

#match_similar(origin, range = 1, utf = false, max = -1)) ⇒ Object



346
347
348
# File 'lib/kyotocabinet.rb', line 346

def match_similar(origin, range=1, utf=false, max=-1)
  _match_similar(origin, range, utf, max)
end

#merge(srcary, mode = DB::MSET) ⇒ Object



351
352
353
# File 'lib/kyotocabinet.rb', line 351

def merge(srcary, mode=DB::MSET)
  _merge(srcary.to_java(DB), mode)
end

#occupy(writable = false, proc = nil) ⇒ Object



356
357
358
# File 'lib/kyotocabinet.rb', line 356

def occupy(writable=false, proc=nil)
  _occupy(writable, proc)
end

#open(path = ':', mode = DB::OWRITER|DB::OCREATE) ⇒ Object



361
362
363
# File 'lib/kyotocabinet.rb', line 361

def open(path=':', mode=DB::OWRITER|DB::OCREATE)
  _open(path, mode)
end

#remove_bulk(keys, atomic = true) ⇒ Object



369
370
371
# File 'lib/kyotocabinet.rb', line 369

def remove_bulk(keys, atomic=true)
  _remove_bulk(conv_string_array(keys), atomic)
end

#set(k, v) ⇒ Object Also known as: []=, store



378
379
380
# File 'lib/kyotocabinet.rb', line 378

def set(k, v)
  self._set(k.to_java_bytes, v.to_s.to_java_bytes)
end

#set_bulk(rec_h, atomic) ⇒ Object



385
386
387
388
389
390
391
392
393
394
# File 'lib/kyotocabinet.rb', line 385

def set_bulk(rec_h, atomic)
  ba = Java::byte[rec_h.size * 2, 0].new
  i = 0
  rec_h.each_pair do |k, v|
    ba[i]   = k.to_java_bytes
    ba[i+1] = v.to_java_bytes
    i += 2
  end
  self._set_bulk(ba, atomic)
end

#synchronize(hard = false, proc = nil) ⇒ Object



399
400
401
# File 'lib/kyotocabinet.rb', line 399

def synchronize(hard=false, proc=nil)
  self._synchronize(hard, proc)
end

#transaction(hard = false) ⇒ Object



403
404
405
406
407
408
409
410
411
412
# File 'lib/kyotocabinet.rb', line 403

def transaction(hard=false)
  begin_transaction(hard)
  commit = false
  begin
    commit = yield
  ensure
    end_transaction(commit)
  end
  commit
end