Skip to content

Commit ec24116

Browse files
Pere Urbon-BayesPere Urbon
authored andcommitted
make the jdbc_driver_library accept a list of elements separated by commas as in some situations we might need to load more than one jar/lib
Fixes #86
1 parent 4b3591d commit ec24116

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/logstash/plugin_mixins/jdbc.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ def self.included(base)
1818

1919
public
2020
def setup_jdbc_config
21-
# JDBC driver library path to third party driver library.
21+
# JDBC driver library path to third party driver library. In case of multiple libraries being
22+
# required you can pass them separated by a comma.
2223
#
2324
# If not provided, Plugin will look for the driver class in the Logstash Java classpath.
24-
config :jdbc_driver_library, :validate => :path
25+
config :jdbc_driver_library, :validate => :string
2526

2627
# JDBC driver class to load, for exmaple, "org.apache.derby.jdbc.ClientDriver"
2728
# NB per https://github.com/logstash-plugins/logstash-input-jdbc/issues/43 if you are using
@@ -96,12 +97,20 @@ def jdbc_connect
9697
end
9798
end
9899

100+
private
101+
def load_drivers(drivers)
102+
drivers.each do |driver|
103+
require driver
104+
end
105+
end
106+
99107
public
100108
def prepare_jdbc_connection
101109
require "java"
102110
require "sequel"
103111
require "sequel/adapters/jdbc"
104-
require @jdbc_driver_library if @jdbc_driver_library
112+
load_drivers(@jdbc_driver_library.split(",")) if @jdbc_driver_library
113+
105114
begin
106115
Sequel::JDBC.load_driver(@jdbc_driver_class)
107116
rescue Sequel::AdapterNotFound => e

spec/inputs/jdbc_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@
4545
plugin.stop
4646
end
4747

48+
it "should load all drivers when passing an array" do
49+
mixin_settings['jdbc_driver_library'] = '/foo/bar,/bar/foo'
50+
expect(plugin).to receive(:load_drivers).with(['/foo/bar', '/bar/foo'])
51+
plugin.register
52+
plugin.stop
53+
end
54+
55+
it "should load all drivers when using a single value" do
56+
mixin_settings['jdbc_driver_library'] = '/foo/bar'
57+
expect(plugin).to receive(:load_drivers).with(['/foo/bar'])
58+
plugin.register
59+
plugin.stop
60+
end
61+
4862
it "should stop without raising exception" do
4963
plugin.register
5064
expect { plugin.stop }.to_not raise_error

0 commit comments

Comments
 (0)