Class: DataObjects::Transaction
- Inherits:
-
Object
- Object
- DataObjects::Transaction
- Defined in:
- lib/data_objects/transaction.rb
Constant Summary collapse
- HOST =
The host name. Note, this relies on the host name being configured and resolvable using DNS
"#{Socket::gethostbyname(Socket::gethostname)[0]}" rescue "localhost"
- @@counter =
0
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
The connection object allocated for this transaction.
-
#id ⇒ Object
readonly
A unique ID for this transaction.
Class Method Summary collapse
-
.create_for_uri(uri) ⇒ Object
Instantiate the Transaction subclass that’s appropriate for this uri scheme.
Instance Method Summary collapse
- #begin ⇒ Object
- #begin_prepared ⇒ Object
-
#close ⇒ Object
Close the connection for this Transaction.
- #commit ⇒ Object
- #commit_prepared ⇒ Object
-
#initialize(uri) ⇒ Transaction
constructor
Creates a Transaction bound to a connection for the given DataObjects::URI.
- #prepare ⇒ Object
- #rollback ⇒ Object
- #rollback_prepared ⇒ Object
Constructor Details
#initialize(uri) ⇒ Transaction
Creates a Transaction bound to a connection for the given DataObjects::URI
26 27 28 29 |
# File 'lib/data_objects/transaction.rb', line 26 def initialize(uri) @connection = DataObjects::Connection.new(uri) @id = Digest::SHA256.hexdigest("#{HOST}:#{$$}:#{Time.now.to_f}:#{@@counter += 1}") end |
Instance Attribute Details
#connection ⇒ Object (readonly)
The connection object allocated for this transaction
13 14 15 |
# File 'lib/data_objects/transaction.rb', line 13 def connection @connection end |
#id ⇒ Object (readonly)
A unique ID for this transaction
15 16 17 |
# File 'lib/data_objects/transaction.rb', line 15 def id @id end |
Class Method Details
.create_for_uri(uri) ⇒ Object
Instantiate the Transaction subclass that’s appropriate for this uri scheme
18 19 20 21 |
# File 'lib/data_objects/transaction.rb', line 18 def self.create_for_uri(uri) uri = uri.is_a?(String) ? URI::parse(uri) : uri DataObjects.const_get(uri.scheme.capitalize)::Transaction.new(uri) end |
Instance Method Details
#begin ⇒ Object
36 37 38 39 |
# File 'lib/data_objects/transaction.rb', line 36 def begin cmd = "BEGIN" connection.create_command(cmd).execute_non_query end |
#begin_prepared ⇒ Object
52 |
# File 'lib/data_objects/transaction.rb', line 52 def begin_prepared; not_implemented; end |
#close ⇒ Object
Close the connection for this Transaction
32 33 34 |
# File 'lib/data_objects/transaction.rb', line 32 def close @connection.close end |
#commit ⇒ Object
41 42 43 44 |
# File 'lib/data_objects/transaction.rb', line 41 def commit cmd = "COMMIT" connection.create_command(cmd).execute_non_query end |
#commit_prepared ⇒ Object
53 |
# File 'lib/data_objects/transaction.rb', line 53 def commit_prepared; not_implemented; end |
#prepare ⇒ Object
51 |
# File 'lib/data_objects/transaction.rb', line 51 def prepare; not_implemented; end |
#rollback ⇒ Object
46 47 48 49 |
# File 'lib/data_objects/transaction.rb', line 46 def rollback cmd = "ROLLBACK" connection.create_command(cmd).execute_non_query end |
#rollback_prepared ⇒ Object
54 |
# File 'lib/data_objects/transaction.rb', line 54 def rollback_prepared; not_implemented; end |