Module: Hyperion::Sql

Defined in:
lib/hyperion/sql.rb,
lib/hyperion/sql/datastore.rb,
lib/hyperion/sql/sql_query.rb,
lib/hyperion/sql/middleware.rb,
lib/hyperion/sql/transaction.rb,
lib/hyperion/sql/query_builder.rb,
lib/hyperion/sql/query_executor.rb

Defined Under Namespace

Classes: Datastore, Middleware, QueryBuilder, QueryExecutor, SqlQuery, Transaction

Class Method Summary collapse

Class Method Details

.connectionObject



24
25
26
# File 'lib/hyperion/sql.rb', line 24

def self.connection
  Thread.current[:connection] || raise('No Connection Established')
end

.rollbackObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/hyperion/sql.rb', line 28

def self.rollback
  with_txn do |txn|
    savepoint_id = txn.begin_savepoint
    begin
      yield
    ensure
      txn.rollback_to_savepoint(savepoint_id)
    end
  end
end

.transactionObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/hyperion/sql.rb', line 39

def self.transaction
  with_txn do |txn|
    savepoint_id = txn.begin_savepoint
    begin
      result = yield
      txn.release_savepoint(savepoint_id)
      result
    rescue Exception => e
      txn.rollback_to_savepoint(savepoint_id)
      raise e
    end
  end
end

.with_connection(url) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hyperion/sql.rb', line 9

def self.with_connection(url)
  if Thread.current[:connection]
    yield
  else
    connection = DataObjects::Connection.new(url)
    begin
      Util.bind(:connection, connection) do
        yield
      end
    ensure
      connection.close
    end
  end
end