Class: DataObjects::Transaction
- Inherits:
-
Object
- Object
- DataObjects::Transaction
- Defined in:
- lib/data_objects/transaction.rb
Direct Known Subclasses
Constant Summary collapse
- HOST =
The local host name. Do not attempt to resolve in DNS to prevent potentially long delay
begin Socket.gethostname.to_s rescue 'localhost' end
- @@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, connection = nil) ⇒ 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, connection = nil) ⇒ Transaction
Creates a Transaction bound to a connection for the given DataObjects::URI
30 31 32 33 34 |
# File 'lib/data_objects/transaction.rb', line 30 def initialize(uri, connection = nil) @connection = connection || DataObjects::Connection.new(uri) # PostgreSQL can't handle the full 64 bytes. This should be enough for everyone. @id = Digest::SHA256.hexdigest("#{HOST}:#{$PROCESS_ID}:#{Time.now.to_f}:#{@@counter += 1}")[0..-2] end |
Instance Attribute Details
#connection ⇒ Object (readonly)
The connection object allocated for this transaction
17 18 19 |
# File 'lib/data_objects/transaction.rb', line 17 def connection @connection end |
#id ⇒ Object (readonly)
A unique ID for this transaction
19 20 21 |
# File 'lib/data_objects/transaction.rb', line 19 def id @id end |
Class Method Details
.create_for_uri(uri) ⇒ Object
Instantiate the Transaction subclass that’s appropriate for this uri scheme
22 23 24 25 |
# File 'lib/data_objects/transaction.rb', line 22 def self.create_for_uri(uri) uri = URI.parse(uri) if uri.is_a?(String) DataObjects.const_get(uri.scheme.capitalize)::Transaction.new(uri) end |
Instance Method Details
#begin ⇒ Object
41 42 43 |
# File 'lib/data_objects/transaction.rb', line 41 def begin run 'BEGIN' end |
#begin_prepared ⇒ Object
57 58 59 |
# File 'lib/data_objects/transaction.rb', line 57 def begin_prepared not_implemented end |
#close ⇒ Object
Close the connection for this Transaction
37 38 39 |
# File 'lib/data_objects/transaction.rb', line 37 def close @connection.close end |
#commit ⇒ Object
45 46 47 |
# File 'lib/data_objects/transaction.rb', line 45 def commit run 'COMMIT' end |
#commit_prepared ⇒ Object
61 62 63 |
# File 'lib/data_objects/transaction.rb', line 61 def commit_prepared not_implemented end |
#prepare ⇒ Object
53 54 55 |
# File 'lib/data_objects/transaction.rb', line 53 def prepare not_implemented end |
#rollback ⇒ Object
49 50 51 |
# File 'lib/data_objects/transaction.rb', line 49 def rollback run 'ROLLBACK' end |
#rollback_prepared ⇒ Object
65 66 67 |
# File 'lib/data_objects/transaction.rb', line 65 def rollback_prepared not_implemented end |