3
4
5
6
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/arjdbc/teradata/connection_methods.rb', line 3
def teradata_connection(config)
begin
require 'jdbc/teradata'
::Jdbc::Teradata.load_driver(:require) if defined?(::Jdbc::Teradata.load_driver)
rescue LoadError end
if config[:jndi]
jndi = config[:jndi].to_s
ctx = javax.naming.InitialContext.new
ds = nil
begin
env = ctx.lookup('java:/comp/env')
ds = env.lookup(jndi)
rescue
ds = ctx.lookup(jndi)
end
if ds.respond_to?('getJdbcUrl')
config[:url] = ds.getJdbcUrl
else
config[:url] = ds.getUrl
end
config[:username] ||= ds.getUsername
config[:database] ||= config[:url][/DATABASE=(.*?),/m, 1] unless config[:url].nil?
config[:password] ||= ds.getPassword
else
config[:username] ||= Java::JavaLang::System.get_property('user.name')
config[:host] ||= 'localhost'
config[:port] ||= 1025
config[:tmode] ||= 'ANSI' config[:charset] ||= 'UTF8'
config[:cop] ||= 'OFF'
config[:log_level] ||= 'ERROR'
config[:xviews] ||= 'OFF'
config[:url] ||= "jdbc:teradata://#{config[:host]}/DATABASE=#{config[:database]},DBS_PORT=#{config[:port]},COP=#{config[:cop]},tmode=#{config[:tmode]},charset=#{config[:charset]},LOG=#{config[:log_level]},USEXVIEWS=#{config[:xviews]}"
end
config[:driver] ||= 'com.teradata.jdbc.TeraDriver'
config[:adapter_class] = ActiveRecord::ConnectionAdapters::TeradataAdapter
config[:adapter_spec] = ::ArJdbc::Teradata
jdbc_connection(config)
end
|