Skip to content

Commit

Permalink
make the jdbc_driver_library accept a list of elements separated by c…
Browse files Browse the repository at this point in the history
…ommas as in some situations we might need to load more than one jar/lib

Fixes #86
  • Loading branch information
Pere Urbon-Bayes authored and Pere Urbon committed Dec 7, 2015
1 parent 4b3591d commit ec24116
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/logstash/plugin_mixins/jdbc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ def self.included(base)

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

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

private
def load_drivers(drivers)
drivers.each do |driver|
require driver
end
end

public
def prepare_jdbc_connection
require "java"
require "sequel"
require "sequel/adapters/jdbc"
require @jdbc_driver_library if @jdbc_driver_library
load_drivers(@jdbc_driver_library.split(",")) if @jdbc_driver_library

begin
Sequel::JDBC.load_driver(@jdbc_driver_class)
rescue Sequel::AdapterNotFound => e
Expand Down
14 changes: 14 additions & 0 deletions spec/inputs/jdbc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@
plugin.stop
end

it "should load all drivers when passing an array" do
mixin_settings['jdbc_driver_library'] = '/foo/bar,/bar/foo'
expect(plugin).to receive(:load_drivers).with(['/foo/bar', '/bar/foo'])
plugin.register
plugin.stop
end

it "should load all drivers when using a single value" do
mixin_settings['jdbc_driver_library'] = '/foo/bar'
expect(plugin).to receive(:load_drivers).with(['/foo/bar'])
plugin.register
plugin.stop
end

it "should stop without raising exception" do
plugin.register
expect { plugin.stop }.to_not raise_error
Expand Down

0 comments on commit ec24116

Please sign in to comment.