Class: RR::Committers::DefaultCommitter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyrep/committers/committers.rb

Overview

This committer does not do anything. This means that the default DBMS behaviour is used (for most DBMS: every DML statement (insert, update, delete) runs in it’s own transaction.

Direct Known Subclasses

BufferedCommitter, NeverCommitter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ DefaultCommitter

A new committer is created for each table sync.

* session: a Session object representing the current database session


67
68
69
70
# File 'lib/rubyrep/committers/committers.rb', line 67

def initialize(session)
  self.session = session
  self.connections = {:left => session.left, :right => session.right}
end

Instance Attribute Details

#connectionsObject

A hash holding the proxy connections

    1. => <left connection>, :right => <right connection>



63
64
65
# File 'lib/rubyrep/committers/committers.rb', line 63

def connections
  @connections
end

#sessionObject

The current Session object



59
60
61
# File 'lib/rubyrep/committers/committers.rb', line 59

def session
  @session
end

Instance Method Details

#delete_record(database, table, values) ⇒ Object

Deletes the specified record in the specified database (either :left or :right). table is the name of the target table. values is a hash of column_name => value pairs. (Only the primary key values will be used and must be included in the hash.)



98
99
100
# File 'lib/rubyrep/committers/committers.rb', line 98

def delete_record(database, table, values)
  connections[database].delete_record(table, values)
end

#finalize(success = true) ⇒ Object

Is called after the last insert / update / delete query. success should be true if there were no problems, false otherwise.



104
105
# File 'lib/rubyrep/committers/committers.rb', line 104

def finalize(success = true)
end

#insert_record(database, table, values) ⇒ Object

Inserts the specified record in the specified database (either :left or :right). table is the name of the target table. values is a hash of column_name => value pairs.



81
82
83
# File 'lib/rubyrep/committers/committers.rb', line 81

def insert_record(database, table, values)
  connections[database].insert_record(table, values)
end

#new_transaction?Boolean

Returns true if a new transaction was started since the last insert / update / delete.

Returns:

  • (Boolean)


74
75
76
# File 'lib/rubyrep/committers/committers.rb', line 74

def new_transaction?
  false
end

#update_record(database, table, values, old_key = nil) ⇒ Object

Updates the specified record in the specified database (either :left or :right). table is the name of the target table. values is a hash of column_name => value pairs. # old_key is a column_name => value hash with the original primary key. If old_key is nil, then the primary key must be contained in values.



90
91
92
# File 'lib/rubyrep/committers/committers.rb', line 90

def update_record(database, table, values, old_key = nil)
  connections[database].update_record(table, values, old_key)
end