Class: Rod::Berkeley::Transaction
- Inherits:
-
Object
- Object
- Rod::Berkeley::Transaction
- Defined in:
- lib/rod/berkeley/transaction.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
The environment of the transaction.
Instance Method Summary collapse
-
#abort ⇒ Object
Abort the transaction.
-
#begin(options = {}) ⇒ Object
Begins the transaction.
-
#commit(options = {}) ⇒ Object
Commit the transaction.
-
#finish ⇒ Object
Aborts the transaction if it was started and not finished otherwise leaves it as it is.
-
#finished? ⇒ Boolean
Returns true if the transaction was finished.
-
#initialize(environment) ⇒ Transaction
constructor
Initializes the transaction within the given
environment
. -
#reset ⇒ Object
Restarts the transaction if it was finished.
-
#started? ⇒ Boolean
Returns true if the transaction was started.
Constructor Details
#initialize(environment) ⇒ Transaction
Initializes the transaction within the given environment
.
8 9 10 11 12 |
# File 'lib/rod/berkeley/transaction.rb', line 8 def initialize(environment) @environment = environment @started = false @finished = false end |
Instance Attribute Details
#environment ⇒ Object (readonly)
The environment of the transaction.
5 6 7 |
# File 'lib/rod/berkeley/transaction.rb', line 5 def environment @environment end |
Instance Method Details
#abort ⇒ Object
Abort the transaction.
85 86 87 88 89 |
# File 'lib/rod/berkeley/transaction.rb', line 85 def abort raise DatabaseError.new("The transaction has not been started!") unless started? _abort @finished = true end |
#begin(options = {}) ⇒ Object
Begins the transaction.
The following options are supported (see the Berkeley DB documentation for full description of the flags):
-
+:read_committed: - degree 2 isolation of the transaction, BDB:
DB_READ_COMMITTED
-
+:read_uncommitted: - degree 1 isolation of the transaction, BDB:
DB_READ_UNCOMMITTED
-
+:bulk: - enable transactional bulk insert, NOT SUPPORTED! BDB:
DB_TXN_BULK
-
+:no_sync: - do not flush synchronously to the log (ACI without D), BDB:
DB_TXN_NOSYNC
-
+:no_wait: - raises exception if can’t obtain a lock immediately, BDB:
DB_TXN_NOWAIT
-
+:snapshot: - snapshot isolation of the transaction, BDB:
DB_TXN_SNAPSHOT
-
+:sync: - (default) flush synchronously to the log (full ACID), BDB:
DB_TXN_SYNC
-
+:wait: - (default) wait for locks if they are not available, BDB:
DB_TXN_WAIT
-
+:write_no_sync: - write to the log but don’t flush it, similar to
:no_sync
, BDB:DB_TXN_WRITE_NOSYNC
36 37 38 39 40 |
# File 'lib/rod/berkeley/transaction.rb', line 36 def begin(={}) raise DatabaseError.new("The transaction has already started.") if started? _begin() @started = true end |
#commit(options = {}) ⇒ Object
Commit the transaction.
The following options are supported (see the Berkeley DB documentation for full description of the flags):
-
+:no_sync: - do not flush synchronously to the log (ACI without D), BDB:
DB_TXN_NOSYNC
-
+:sync: - (default) flush synchronously to the log (full ACID), BDB:
DB_TXN_SYNC
-
+:write_no_sync: - write to the log but don’t flush it, similar to
:no_sync
, BDB:DB_TXN_WRITE_NOSYNC
78 79 80 81 82 |
# File 'lib/rod/berkeley/transaction.rb', line 78 def commit(={}) raise DatabaseError.new("The transaction has not been started!") unless started? _commit() @finished = true end |
#finish ⇒ Object
Aborts the transaction if it was started and not finished otherwise leaves it as it is.
62 63 64 65 66 |
# File 'lib/rod/berkeley/transaction.rb', line 62 def finish return unless started? return if finished? self.abort end |
#finished? ⇒ Boolean
Returns true if the transaction was finished.
48 49 50 |
# File 'lib/rod/berkeley/transaction.rb', line 48 def finished? @finished end |
#reset ⇒ Object
Restarts the transaction if it was finished. This allows for preservation of resources.
54 55 56 57 58 |
# File 'lib/rod/berkeley/transaction.rb', line 54 def reset raise DatabaseError.new("Transaction not finished!") if started? && !finished? @started = false @finished = false end |
#started? ⇒ Boolean
Returns true if the transaction was started.
43 44 45 |
# File 'lib/rod/berkeley/transaction.rb', line 43 def started? @started end |