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
"#{Socket::gethostname}" 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, 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
27 28 29 30 31 |
# File 'lib/data_objects/transaction.rb', line 27 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}:#{$$}:#{Time.now.to_f}:#{@@counter += 1}")[0..-2] end |
Instance Attribute Details
#connection ⇒ Object (readonly)
The connection object allocated for this transaction
14 15 16 |
# File 'lib/data_objects/transaction.rb', line 14 def connection @connection end |
#id ⇒ Object (readonly)
A unique ID for this transaction
16 17 18 |
# File 'lib/data_objects/transaction.rb', line 16 def id @id end |
Class Method Details
.create_for_uri(uri) ⇒ Object
Instantiate the Transaction subclass that’s appropriate for this uri scheme
19 20 21 22 |
# File 'lib/data_objects/transaction.rb', line 19 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
38 39 40 |
# File 'lib/data_objects/transaction.rb', line 38 def begin run "BEGIN" end |
#begin_prepared ⇒ Object
51 |
# File 'lib/data_objects/transaction.rb', line 51 def begin_prepared; not_implemented; end |
#close ⇒ Object
Close the connection for this Transaction
34 35 36 |
# File 'lib/data_objects/transaction.rb', line 34 def close @connection.close end |
#commit ⇒ Object
42 43 44 |
# File 'lib/data_objects/transaction.rb', line 42 def commit run "COMMIT" end |
#commit_prepared ⇒ Object
52 |
# File 'lib/data_objects/transaction.rb', line 52 def commit_prepared; not_implemented; end |
#prepare ⇒ Object
50 |
# File 'lib/data_objects/transaction.rb', line 50 def prepare; not_implemented; end |
#rollback ⇒ Object
46 47 48 |
# File 'lib/data_objects/transaction.rb', line 46 def rollback run "ROLLBACK" end |
#rollback_prepared ⇒ Object
53 |
# File 'lib/data_objects/transaction.rb', line 53 def rollback_prepared; not_implemented; end |