Module: Persist::TCAdapter
- Includes:
- TSVAdapter
- Defined in:
- lib/rbbt/persist/tsv/tokyocabinet.rb
Constant Summary
Constants included
from TSVAdapter
Persist::TSVAdapter::MAX_CHAR
Instance Attribute Summary collapse
Attributes included from TSVAdapter
#closed, #mutex, #persistence_path, #writable
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from TSVAdapter
#closed?, #collect, #delete, #get_prefix, #merge!, #prefix, #range, #read?, #read_and_close, #write?, #write_and_close, #write_and_read
Instance Attribute Details
#tokyocabinet_class ⇒ Object
Returns the value of attribute tokyocabinet_class.
8
9
10
|
# File 'lib/rbbt/persist/tsv/tokyocabinet.rb', line 8
def tokyocabinet_class
@tokyocabinet_class
end
|
Class Method Details
.open(path, write, serializer, tokyocabinet_class = TokyoCabinet::HDB) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/rbbt/persist/tsv/tokyocabinet.rb', line 10
def self.open(path, write, serializer, tokyocabinet_class = TokyoCabinet::HDB)
if String === tokyocabinet_class and tokyocabinet_class.include? ":big"
big = true
tokyocabinet_class = tokyocabinet_class.split(":").first
else
big = false
end
tokyocabinet_class = TokyoCabinet::HDB if tokyocabinet_class == "HDB" or tokyocabinet_class.nil?
tokyocabinet_class = TokyoCabinet::BDB if tokyocabinet_class == "BDB"
database = CONNECTIONS[path] ||= tokyocabinet_class.new
if big and not Open.exists? path
database.tune(nil,nil,nil,tokyocabinet_class::TLARGE | tokyocabinet_class::TDEFLATE)
end
flags = (write ? tokyocabinet_class::OWRITER | tokyocabinet_class::OCREAT : tokyocabinet_class::OREADER)
database.close
if !database.open(path, flags)
ecode = database.ecode
raise "Open error: #{database.errmsg(ecode)}. Trying to open file #{path}"
end
database.extend Persist::TCAdapter unless Persist::TCAdapter === database
database.persistence_path ||= path
database.tokyocabinet_class = tokyocabinet_class
database.mutex = Mutex.new
database
end
|
Instance Method Details
#close ⇒ Object
44
45
46
47
|
# File 'lib/rbbt/persist/tsv/tokyocabinet.rb', line 44
def close
@closed = true
super
end
|
#read(force = false) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/rbbt/persist/tsv/tokyocabinet.rb', line 49
def read(force = false)
return if not write? and not closed and not force
self.close
if !self.open(@persistence_path, tokyocabinet_class::OREADER)
ecode = self.ecode
raise "Open error: #{self.errmsg(ecode)}. Trying to open file #{@persistence_path}"
end
@writable = false
@closed = false
self
end
|
#write(force = true) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/rbbt/persist/tsv/tokyocabinet.rb', line 61
def write(force = true)
return if write? and not closed and not force
self.close
if !self.open(@persistence_path, tokyocabinet_class::OWRITER)
ecode = self.ecode
raise "Open error: #{self.errmsg(ecode)}. Trying to open file #{@persistence_path}"
end
@writable = true
@closed = false
self
end
|