Class: DataObjects::Transaction

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

Direct Known Subclasses

SavePoint

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

Class Method Summary collapse

Instance Method Summary collapse

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

#connectionObject (readonly)

The connection object allocated for this transaction



17
18
19
# File 'lib/data_objects/transaction.rb', line 17

def connection
  @connection
end

#idObject (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

#beginObject



41
42
43
# File 'lib/data_objects/transaction.rb', line 41

def begin
  run 'BEGIN'
end

#begin_preparedObject



57
58
59
# File 'lib/data_objects/transaction.rb', line 57

def begin_prepared
  not_implemented
end

#closeObject

Close the connection for this Transaction



37
38
39
# File 'lib/data_objects/transaction.rb', line 37

def close
  @connection.close
end

#commitObject



45
46
47
# File 'lib/data_objects/transaction.rb', line 45

def commit
  run 'COMMIT'
end

#commit_preparedObject



61
62
63
# File 'lib/data_objects/transaction.rb', line 61

def commit_prepared
  not_implemented
end

#prepareObject



53
54
55
# File 'lib/data_objects/transaction.rb', line 53

def prepare
  not_implemented
end

#rollbackObject



49
50
51
# File 'lib/data_objects/transaction.rb', line 49

def rollback
  run 'ROLLBACK'
end

#rollback_preparedObject



65
66
67
# File 'lib/data_objects/transaction.rb', line 65

def rollback_prepared
  not_implemented
end