class DataObjects::Transaction
Constants
- HOST
The host name. Note, this relies on the host name being configured and resolvable using DNS
Attributes
connection[R]
The connection object allocated for this transaction
id[R]
A unique ID for this transaction
Public Class Methods
create_for_uri(uri)
click to toggle source
Instantiate the Transaction subclass that's appropriate for this uri scheme
# 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
new(uri, connection = nil)
click to toggle source
Creates a Transaction bound to a connection for the given DataObjects::URI
# 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
Public Instance Methods
begin()
click to toggle source
# File lib/data_objects/transaction.rb, line 38 def begin run "BEGIN" end
begin_prepared()
click to toggle source
# File lib/data_objects/transaction.rb, line 51 def begin_prepared; not_implemented; end
close()
click to toggle source
Close the connection for this Transaction
# File lib/data_objects/transaction.rb, line 34 def close @connection.close end
commit()
click to toggle source
# File lib/data_objects/transaction.rb, line 42 def commit run "COMMIT" end
commit_prepared()
click to toggle source
# File lib/data_objects/transaction.rb, line 52 def commit_prepared; not_implemented; end
prepare()
click to toggle source
# File lib/data_objects/transaction.rb, line 50 def prepare; not_implemented; end
rollback()
click to toggle source
# File lib/data_objects/transaction.rb, line 46 def rollback run "ROLLBACK" end
rollback_prepared()
click to toggle source
# File lib/data_objects/transaction.rb, line 53 def rollback_prepared; not_implemented; end
Protected Instance Methods
run(cmd)
click to toggle source
# File lib/data_objects/transaction.rb, line 57 def run(cmd) connection.create_command(cmd).execute_non_query end
Private Instance Methods
not_implemented()
click to toggle source
# File lib/data_objects/transaction.rb, line 62 def not_implemented raise NotImplementedError end