Class: Lore::Connection

Inherits:
Object show all
Defined in:
lib/lore/adapters/postgres/connection.rb,
lib/lore/adapters/postgres-pr/connection.rb

Constant Summary collapse

@@query_count =
0
@@result_row_count =
0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



17
18
# File 'lib/lore/adapters/postgres/connection.rb', line 17

def initialize
end

Class Method Details

.establish(db_name) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/lore/adapters/postgres/connection.rb', line 66

def self.establish(db_name)
  begin
  PGconn.connect(Lore.pg_server, 
                 Lore.pg_port, 
                 '', '', 
                 db_name.to_s, 
                 Lore.user_for(db_name.to_sym), 
                 Lore.pass_for(db_name.to_sym))
  rescue ::Exception => e
    raise Lore::Exceptions::Database_Exception.new(e.message)
  end
end

.perform(query) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/lore/adapters/postgres/connection.rb', line 43

def self.perform(query)
  begin
    @@query_count += 1
  # result = Context.get_connection.exec(query)
    result = Context.get_connection.async_exec(query)
    @@result_row_count += result.num_tuples
    
    if Lore.log_queries? then
      query.split("\n").each { |line|
        Lore.query_logger.debug { "  sql|#{Context.get_context}| #{line}" }
      }
    end
  rescue ::Exception => pge
    pge.message << "\n" << query.inspect
    Lore.logger.error { pge.message }
    Lore.logger.error { 'Context: ' << Context.inspect }
    Lore.logger.error { 'Query: ' << "\n" << query }
    raise Lore::Exceptions::Database_Exception.new(pge.message << "\n" << query.to_s)
  end
  
  return Result.new(query, result)
end

.perform_cacheable(query) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/lore/adapters/postgres/connection.rb', line 33

def self.perform_cacheable(query)
  if Lore::Cache::Cached_Entities.include?(query) then
      result = Lore::Cache::Cached_Entities[query]
  else
    result = perform(query)
    Lore::Cache::Cached_Entities[query] = result
  end
  return result
end

.query_countObject



26
27
28
# File 'lib/lore/adapters/postgres/connection.rb', line 26

def self.query_count
  @@query_count
end

.reset_query_countObject



20
21
22
# File 'lib/lore/adapters/postgres/connection.rb', line 20

def self.reset_query_count
  @@query_count = 0
end

.reset_result_row_countObject



23
24
25
# File 'lib/lore/adapters/postgres/connection.rb', line 23

def self.reset_result_row_count
  @@result_row_count = 0
end

.result_row_countObject



29
30
31
# File 'lib/lore/adapters/postgres/connection.rb', line 29

def self.result_row_count
  @@result_row_count
end