Class: DataObjects::Transaction

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

Constant Summary collapse

HOST =

The host name. Note, this relies on the host name being configured and resolvable using DNS

"#{Socket::gethostbyname(Socket::gethostname)[0]}" rescue "localhost"
@@counter =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Transaction

Creates a Transaction bound to a connection for the given DataObjects::URI



26
27
28
29
# File 'lib/data_objects/transaction.rb', line 26

def initialize(uri)
  @connection = DataObjects::Connection.new(uri)
  @id = Digest::SHA256.hexdigest("#{HOST}:#{$$}:#{Time.now.to_f}:#{@@counter += 1}")
end

Instance Attribute Details

#connectionObject (readonly)

The connection object allocated for this transaction



13
14
15
# File 'lib/data_objects/transaction.rb', line 13

def connection
  @connection
end

#idObject (readonly)

A unique ID for this transaction



15
16
17
# File 'lib/data_objects/transaction.rb', line 15

def id
  @id
end

Class Method Details

.create_for_uri(uri) ⇒ Object

Instantiate the Transaction subclass that’s appropriate for this uri scheme



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

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

#beginObject



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

def begin
  cmd = "BEGIN"
  connection.create_command(cmd).execute_non_query
end

#begin_preparedObject



52
# File 'lib/data_objects/transaction.rb', line 52

def begin_prepared; not_implemented; end

#closeObject

Close the connection for this Transaction



32
33
34
# File 'lib/data_objects/transaction.rb', line 32

def close
  @connection.close
end

#commitObject



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

def commit
  cmd = "COMMIT"
  connection.create_command(cmd).execute_non_query
end

#commit_preparedObject



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

def commit_prepared; not_implemented; end

#prepareObject



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

def prepare; not_implemented; end

#rollbackObject



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

def rollback
  cmd = "ROLLBACK"
  connection.create_command(cmd).execute_non_query
end

#rollback_preparedObject



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

def rollback_prepared; not_implemented; end