Class: BtrieveSession
- Inherits:
-
Object
- Object
- BtrieveSession
- Includes:
- Btrieve
- Defined in:
- lib/btrieve/btrieve_session.rb
Overview
Concept of a BTR session. Beware, this implementation is NOT thread safe!
Constant Summary collapse
- @@instance =
nil
Constants included from BtrCodes
BtrCodes::ABORT_TRANSACTION, BtrCodes::ACCELERATED_MODE, BtrCodes::BEGIN_TRANSACTION, BtrCodes::CLOSE, BtrCodes::DELETE, BtrCodes::END_TRANSACTION, BtrCodes::EOF, BtrCodes::EXCEPTION_MESSAGES, BtrCodes::EXCLUSIVE_MODE, BtrCodes::GET_DIRECT, BtrCodes::GET_EQUAL, BtrCodes::GET_EQUAL_KEY, BtrCodes::GET_FIRST, BtrCodes::GET_GREATER_THAN_OR_EQUAL, BtrCodes::GET_LESS_THAN_OR_EQUAL, BtrCodes::GET_NEXT, BtrCodes::GET_NEXT_EXTENDED, BtrCodes::GET_NEXT_KEY, BtrCodes::GET_POSITION, BtrCodes::GET_PREVIOUS, BtrCodes::INSERT, BtrCodes::KEY_NOT_FOUND, BtrCodes::LOCAL_ACCELERATED_MODE, BtrCodes::LOCAL_EXCLUSIVE_MODE, BtrCodes::LOCAL_NORMAL_MODE, BtrCodes::LOCAL_READ_ONLY_MODE, BtrCodes::MAX_DATATYPE, BtrCodes::NORMAL_MODE, BtrCodes::NO_CURRENCY_CHANGE, BtrCodes::NO_LOGICAL_CURRENCY_KEY, BtrCodes::NULL_BUFFER, BtrCodes::NULL_KEY, BtrCodes::OK, BtrCodes::OPEN, BtrCodes::POS_BLOCK_SIZE, BtrCodes::READ_ONLY_MODE, BtrCodes::RECORD_POSITION_SIZE, BtrCodes::REMOTE_ACCELERATED_MODE, BtrCodes::REMOTE_EXCLUSIVE_MODE, BtrCodes::REMOTE_NORMAL_MODE, BtrCodes::REMOTE_READ_ONLY_MODE, BtrCodes::RESET, BtrCodes::STEP_NEXT, BtrCodes::STEP_NEXT_EXTENDED, BtrCodes::STOP, BtrCodes::SYSTEM_LOG_KEY, BtrCodes::UPDATE, BtrCodes::VERIFY_MODE
Instance Attribute Summary collapse
-
#btrieve_schema ⇒ Object
readonly
Returns the value of attribute btrieve_schema.
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#db ⇒ Object
Returns the value of attribute db.
Class Method Summary collapse
-
.abort_transaction ⇒ Object
Aborts a transaction when something goes wrong.
-
.begin_transaction ⇒ Object
Delineates the begining of a transaction boundary.
-
.create_session(db) ⇒ Object
Factory of BTR sessions.
-
.destroy_session ⇒ Object
Disposes of the session object, releasing any and all resources consumed/locked on the server.
-
.end_transaction ⇒ Object
Delineates the end of a transaction boundary.
-
.get_session ⇒ Object
Returns the session instance created.
-
.transaction(&block) ⇒ Object
Wraps and executes the block passed in inside a transaction.
Instance Method Summary collapse
Methods included from Btrieve
Instance Attribute Details
#btrieve_schema ⇒ Object (readonly)
Returns the value of attribute btrieve_schema.
4 5 6 |
# File 'lib/btrieve/btrieve_session.rb', line 4 def btrieve_schema @btrieve_schema end |
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
4 5 6 |
# File 'lib/btrieve/btrieve_session.rb', line 4 def cache @cache end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
4 5 6 |
# File 'lib/btrieve/btrieve_session.rb', line 4 def client_id @client_id end |
#db ⇒ Object
Returns the value of attribute db.
5 6 7 |
# File 'lib/btrieve/btrieve_session.rb', line 5 def db @db end |
Class Method Details
.abort_transaction ⇒ Object
Aborts a transaction when something goes wrong. The client has the responsibility of calling this method when a transaction was started without a block AND some unexpected event occured and the client wants to prevent any changes to the persistence to be commited.
61 62 63 |
# File 'lib/btrieve/btrieve_session.rb', line 61 def BtrieveSession.abort_transaction() @@instance.btr_op(ABORT_TRANSACTION, NULL_BUFFER, NULL_BUFFER, NULL_BUFFER, NULL_KEY) end |
.begin_transaction ⇒ Object
Delineates the begining of a transaction boundary. If a client calls this method explicitely, the client also has the responsibility of explicitely ending the transaction once done, or abort the transaction if things did not go well.
48 49 50 |
# File 'lib/btrieve/btrieve_session.rb', line 48 def BtrieveSession.begin_transaction() @@instance.btr_op(BEGIN_TRANSACTION, NULL_BUFFER, NULL_BUFFER, NULL_BUFFER, NULL_KEY) end |
.create_session(db) ⇒ Object
Factory of BTR sessions. A block can be passed into it, or alternatively the factory returns the session instance to the caller, who then must call ‘dispose’ on it when done with it. The ‘host’ argument can be a named server or its IP address. The ‘data_share’ argument is typically the share name of the data folder. The ‘data_share’ argument can also be the database name when “IDS” is used on the client.
14 15 16 17 18 |
# File 'lib/btrieve/btrieve_session.rb', line 14 def BtrieveSession.create_session(db) raise "Cannot create more than one instance of session." if(@@instance != nil) @@instance = new(db) @@instance.set_schema(BtrieveSchema.new()) end |
.destroy_session ⇒ Object
Disposes of the session object, releasing any and all resources consumed/locked on the server.
26 27 28 29 |
# File 'lib/btrieve/btrieve_session.rb', line 26 def BtrieveSession.destroy_session() @@instance.btr_op(RESET, NULL_BUFFER, NULL_BUFFER, NULL_BUFFER, NULL_KEY) @@instance=nil end |
.end_transaction ⇒ Object
Delineates the end of a transaction boundary. The client has the responsibility of calling this method when a transaction was started without a block.
54 55 56 |
# File 'lib/btrieve/btrieve_session.rb', line 54 def BtrieveSession.end_transaction() @@instance.btr_op(END_TRANSACTION, NULL_BUFFER, NULL_BUFFER, NULL_BUFFER, NULL_KEY) end |
.get_session ⇒ Object
Returns the session instance created.
21 22 23 |
# File 'lib/btrieve/btrieve_session.rb', line 21 def BtrieveSession.get_session() @@instance end |
.transaction(&block) ⇒ Object
Wraps and executes the block passed in inside a transaction. The transaction is aborted if the block raises an exception.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/btrieve/btrieve_session.rb', line 33 def BtrieveSession.transaction(&block) begin begin_transaction yield end_transaction rescue Exception => exception # Oops! We must roll back the whole shebang! abort_transaction raise "PSQL TX ABORTED!!! - #{exception.}\n#{exception.backtrace.join("\n\t")}" end end |
Instance Method Details
#set_schema(schema) ⇒ Object
65 66 67 |
# File 'lib/btrieve/btrieve_session.rb', line 65 def set_schema(schema) @btrieve_schema=schema end |