Class: DataObjects::SavePoint

Inherits:
Transaction show all
Defined in:
lib/data_objects/transaction.rb

Overview

class Transaction

Constant Summary

Constants inherited from Transaction

Transaction::HOST

Instance Attribute Summary

Attributes inherited from Transaction

#connection, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Transaction

#begin_prepared, #commit_prepared, #initialize, #prepare, #rollback_prepared

Constructor Details

This class inherits a constructor from DataObjects::Transaction

Class Method Details

.create_for_uri(uri, connection) ⇒ Object

We don’t bounce through DO::<Adapter/scheme>::SavePoint because there doesn’t appear to be any custom SQL to support this.



70
71
72
73
# File 'lib/data_objects/transaction.rb', line 70

def self.create_for_uri(uri, connection)
  uri = uri.is_a?(String) ? URI::parse(uri) : uri
  DataObjects::SavePoint.new(uri, connection)
end

Instance Method Details

#beginObject



84
85
86
# File 'lib/data_objects/transaction.rb', line 84

def begin
  run %{SAVEPOINT "#{@id}"}
end

#closeObject

SavePoints can only occur in the context of a Transaction, thus they re-use TXN’s connection (which was acquired from the connection pool legitimately via DO::Connection.new). We no-op #close in SP because calling DO::Connection#close will release the connection back into the pool (before the top-level Transaction might be done with it).



80
81
82
# File 'lib/data_objects/transaction.rb', line 80

def close
    # no-op
end

#commitObject



88
89
90
# File 'lib/data_objects/transaction.rb', line 88

def commit
  run %{RELEASE SAVEPOINT "#{@id}"}
end

#rollbackObject



92
93
94
# File 'lib/data_objects/transaction.rb', line 92

def rollback
  run %{ROLLBACK TO SAVEPOINT "#{@id}"}
end