Class: XMLServiceAdapters::IBM_DBAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/adapters/db2_adapter.rb

Instance Method Summary collapse

Methods inherited from AbstractAdapter

#out_doc, #out_xml, #raw_connection, #raw_options

Constructor Details

#initialize(conn, options) ⇒ IBM_DBAdapter

Returns a new instance of IBM_DBAdapter.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/adapters/db2_adapter.rb', line 7

def initialize(conn,options)
  # yaml connection string "ActiveRecord",
  # so use if active, or start new connection 
  if conn.to_s == "ActiveRecord"
    for i in 0..1
      begin
        conn = ActiveRecord::Base.connection
      rescue
        ActiveRecord::Base.establish_connection(options)
      end
    end
  end
  # raw_connection gives access to actual IBM_DB::Connection
  if conn.is_a?(ActiveRecord::ConnectionAdapters::IBM_DBAdapter)
    super(conn.raw_connection, options)
  elsif conn.is_a?(IBM_DB::Connection)
    super(conn, options)
  else
    raise "#{self.class.name} invalid connection."
  end
end

Instance Method Details

#adapter_nameObject



28
29
30
# File 'lib/adapters/db2_adapter.rb', line 28

def adapter_name
  'XMLSERVICE_IBM_DB'
end

#xmlservice(callme) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/adapters/db2_adapter.rb', line 31

def xmlservice(callme)
  case @xml_size 
  when @xml_size<=4096
    sql = "CALL #{@xml_install}.iPLUG4K(?,?,?,?)"
  when @xml_size>4096 && @xml_size<=32768
    sql = "CALL #{@xml_install}.iPLUG32K(?,?,?,?)"
  when @xml_size>32768 && @xml_size<=65536
    sql = "CALL #{@xml_install}.iPLUG65K(?,?,?,?)"
  when @xml_size>65536 && @xml_size<=524288
    sql = "CALL #{@xml_install}.iPLUG512K(?,?,?,?)"
  when @xml_size>524288 && @xml_size<=1048576
    sql = "CALL #{@xml_install}.iPLUG1M(?,?,?,?)"
  when @xml_size>1048576 && @xml_size<=5242880
    sql = "CALL #{@xml_install}.iPLUG5M(?,?,?,?)"
  when @xml_size>5242880 && @xml_size<=10485760
    sql = "CALL #{@xml_install}.iPLUG10M(?,?,?,?)"
  when @xml_size>10485760
    sql = "CALL #{@xml_install}.iPLUG15M(?,?,?,?)"
  else
    sql = "CALL #{@xml_install}.iPLUG512K(?,?,?,?)"
  end
  ctl = @xml_ctl
  ipc = @xml_ipc
  xmlin = ""
  xmlin << @xml_head
  xmlin << "\n<myscript>\n"
  xmlin << callme.to_xml
  xmlin << "</myscript>\n"
  xmlout = ""
  stmt = IBM_DB::prepare(@xml_conn, sql)
  ret = IBM_DB::bind_param(stmt, 1, "ipc", IBM_DB::SQL_PARAM_INPUT)
  ret = IBM_DB::bind_param(stmt, 2, "ctl", IBM_DB::SQL_PARAM_INPUT)
  ret = IBM_DB::bind_param(stmt, 3, "xmlin", IBM_DB::SQL_PARAM_INPUT)
  ret = IBM_DB::bind_param(stmt, 4, "xmlout", IBM_DB::SQL_PARAM_OUTPUT)
  ret = IBM_DB::execute(stmt)
  @xml_xmlout = xmlout
  @xml_doc = nil
end