Class: Voyager::OracleConnection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ OracleConnection

Returns a new instance of OracleConnection.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/oracle_connection.rb', line 7

def initialize(args = {})
  args.symbolize_keys!
  @connection = args[:connection] 


  unless args.has_key?(:connection)
    app_config_filename = File.join(File.dirname(__FILE__), "..",  "config" ,"app_config.yml")

    args = YAML.load_file(app_config_filename)['oracle_connection_details'] if args == {} and File.exists?(app_config_filename)
    args.symbolize_keys!

    raise "Need argument 'user'" unless args.has_key?(:user) 
    raise "Need argument 'password'" unless args.has_key?(:password)
    raise "Need argument 'service'" unless args.has_key?(:service)

    (args[:env] || {}).each do |env_name, value|
      ENV[env_name.to_s] = value
    end

    @connection = OCI8.new(args[:user], args[:password], args[:service])
    @connection.prefetch_rows = 1000
  end

  @results = {}

end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



4
5
6
# File 'lib/oracle_connection.rb', line 4

def connection
  @connection
end

#resultsObject

Returns the value of attribute results.



5
6
7
# File 'lib/oracle_connection.rb', line 5

def results
  @results
end

Instance Method Details

#retrieve_holdings(*bibids) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/oracle_connection.rb', line 45

def retrieve_holdings(*bibids)
  bibids = Array.wrap(bibids).flatten

  query = <<-HERE
    select a.bib_id, a.mfhd_id, c.item_id, item_status
    from bib_mfhd a, mfhd_master b, mfhd_item c, item_status d
    where a.bib_id IN (~bibid~) and
    b.mfhd_id = a.mfhd_id and
    suppress_in_opac = 'N' and
    c.mfhd_id (+) = b.mfhd_id and
    d.item_id (+) = c.item_id
    order by c.mfhd_id, c.item_id, item_status
  HERE

  unless bibids.empty?
    raw_results = execute_select_command(query, bibid: bibids)
    parse_results(raw_results, name: 'retrieve_holdings', hash_by: 'BIB_ID')
  else
    @results['retrieve_holdings'] ||= {}
  end
end

#retrieve_patron_id(*unis) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/oracle_connection.rb', line 34

def retrieve_patron_id(*unis)
  query = <<-HERE
    select institution_id, patron_id from patron where institution_id IN (~unis~)
  HERE

  raw_results = execute_select_command(query, unis: unis)

  parse_results(raw_results, name: 'retrieve_patron_id', hash_by: 'INSTITUTION_ID', single_result: 'PATRON_ID')
end