Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

Commit fc68d0e

Browse files
committed
Merge pull request #186 from patcheng/release-1.2
better support for JNDI URLs
2 parents 8531b95 + a8bf6da commit fc68d0e

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

lib/dm-core/adapters.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,36 @@ module Adapters
1010
# @api private
1111
def self.new(repository_name, options)
1212
options = normalize_options(options)
13-
adapter_class(options.fetch(:adapter)).new(repository_name, options)
13+
14+
case options.fetch(:adapter)
15+
when 'java'
16+
# discover the real adapter
17+
jndi_uri = "#{options[:scheme]}:#{options[:path]}"
18+
context = javax.naming.InitialContext.new
19+
ds= context.lookup(jndi_uri)
20+
conn = ds.getConnection
21+
begin
22+
metadata = conn.getMetaData
23+
driver_name = metadata.getDriverName
24+
25+
driver = case driver_name
26+
when /mysql/i then 'mysql'
27+
when /oracle/i then 'oracle'
28+
when /postgres/i then 'postgres'
29+
when /sqlite/i then 'sqlite'
30+
when /sqlserver|tds|Microsoft SQL/i then 'sqlserver'
31+
else
32+
nil # not supported
33+
end # case
34+
options[:adapter] = driver
35+
ensure
36+
conn.close
37+
end
38+
else
39+
driver = options.fetch(:adapter)
40+
end # case
41+
42+
adapter_class(driver).new(repository_name, options)
1443
end
1544

1645
# The path used to require the in memory adapter

0 commit comments

Comments
 (0)