Class: Rod::Berkeley::Environment
- Inherits:
-
Object
- Object
- Rod::Berkeley::Environment
- Defined in:
- lib/rod/berkeley/environment.rb
Class Method Summary collapse
-
.database_error ⇒ Object
C definition of the DatabaseError.
-
.init_builder(builder) ⇒ Object
Calls methods on the C
builder
needed to properly configure the C compiler for Berkeley DB. -
.rod_link_flags ⇒ Object
ROD_BDB_LINK_FLAGS env.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the environment.
-
#initialize ⇒ Environment
constructor
Initialization of the environment.
-
#open(path, options = {}) ⇒ Object
Opens the Berkeley DB environment at given
path
. -
#opened? ⇒ Boolean
Returns true if the environment is opened.
Constructor Details
#initialize ⇒ Environment
Initialization of the environment.
8 9 10 |
# File 'lib/rod/berkeley/environment.rb', line 8 def initialize @opened = false end |
Class Method Details
.database_error ⇒ Object
C definition of the DatabaseError.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rod/berkeley/environment.rb', line 72 def database_error str =<<-END |VALUE databaseError(){ | VALUE klass; | | klass = rb_const_get(rb_cObject, rb_intern("Rod")); | klass = rb_const_get(klass, rb_intern("DatabaseError")); | return klass; |} END str.margin end |
.init_builder(builder) ⇒ Object
Calls methods on the C builder
needed to properly configure the C compiler for Berkeley DB.
65 66 67 68 69 |
# File 'lib/rod/berkeley/environment.rb', line 65 def init_builder(builder) builder.include '<db.h>' builder.include '<stdio.h>' builder.add_link_flags self.rod_link_flags end |
.rod_link_flags ⇒ Object
ROD_BDB_LINK_FLAGS env. variable.
59 60 61 |
# File 'lib/rod/berkeley/environment.rb', line 59 def rod_link_flags ENV['ROD_BDB_LINK_FLAGS'] || '-ldb' end |
Instance Method Details
#close ⇒ Object
Closes the environment.
46 47 48 49 |
# File 'lib/rod/berkeley/environment.rb', line 46 def close _close @opened = false end |
#open(path, options = {}) ⇒ Object
Opens the Berkeley DB environment at given path
. The following options are supported (see the Berkeley DB documentation for full description of the flags):
-
:create
- creates the environment if it not exist, DBD: , BDB:DB_CREATE
-
:transactions
- initializes the transaction subsystem, BDB:DB_INIT_TXN
-
:locking
- initializes the locking subsystem, BDB:DB_INIT_LOCK
-
:logging
- initializes the logging subsystem, BDB:DB_INIT_LOG
-
:cache
- initializes the environment’s cache, BDB:DB_INIT_MPOOL
-
:data_store
- initializes the concurrent data store, BDB:DB_INIT_CDB
-
:replication
- initializes the replication subsystem, BDB:DB_INIT_REP
-
:recovery
- runs normal recovery on the environment, BDB:DB_RECOVER
-
:fatal_recovery
- runs fatal recovery on the environment, BDB:DB_RECOVER_FATAL
-
:lock_in_memory
- forces the environemnt’s shared data to be locked in the memory, BDB:DB_LOCKDOWN
-
:fail_check
- checks for threads that exited leaving invalid locks or transactions, BDB:DB_FAILCHK
-
:recovery_check
- checks if recovery has to be performed beform opening the environment, BDB:DB_REGISTER
-
:private
- the environemnt’s data might be shared only witin one process, so concurrency is allowed only between threads, BDB:DB_PRIVATE
-
:system_memory
- use system shared memory for environment’s shared data, BDB:DB_SYSTEM_MEM
-
:threads
allow multiple threads within one process to access the environment and/or its databases, BDB:DB_THREAD
36 37 38 39 40 41 42 43 |
# File 'lib/rod/berkeley/environment.rb', line 36 def open(path,={}) raise DatabaseError.new("The environment at #{path} is already opened.") if opened? FileUtils.mkdir_p(path) # TODO check for conflicting options # TODO check for validity of options _open(path,) @opened = true end |
#opened? ⇒ Boolean
Returns true if the environment is opened.
52 53 54 |
# File 'lib/rod/berkeley/environment.rb', line 52 def opened? @opened end |