@@ -140,47 +140,58 @@ def jdbc_connect
140
140
141
141
private
142
142
143
+ def load_driver
144
+ if @drivers_loaded . false?
145
+ require "java"
146
+ require "sequel"
147
+ require "sequel/adapters/jdbc"
148
+
149
+ load_driver_jars
150
+ begin
151
+ Sequel ::JDBC . load_driver ( @jdbc_driver_class )
152
+ rescue Sequel ::AdapterNotFound => e # Sequel::AdapterNotFound, "#{@jdbc_driver_class} not loaded"
153
+ # fix this !!!
154
+ message = if jdbc_driver_library_set?
155
+ "Are you sure you've included the correct jdbc driver in :jdbc_driver_library?"
156
+ else
157
+ ":jdbc_driver_library is not set, are you sure you included " +
158
+ "the proper driver client libraries in your classpath?"
159
+ end
160
+ raise LogStash ::PluginLoadingError , "#{ e } . #{ message } "
161
+ end
162
+ @drivers_loaded . make_true
163
+ end
164
+ end
165
+
143
166
def load_driver_jars
144
- unless @jdbc_driver_library . nil? || @jdbc_driver_library . empty ?
167
+ if jdbc_driver_library_set ?
145
168
@jdbc_driver_library . split ( "," ) . each do |driver_jar |
169
+ @logger . debug ( "loading #{ driver_jar } " )
170
+ # load 'driver.jar' is different than load 'some.rb' as it only causes the file to be added to
171
+ # JRuby's class-loader lookup (class) path - won't raise a LoadError when file is not readable
172
+ unless FileTest . readable? ( driver_jar )
173
+ raise LogStash ::PluginLoadingError , "unable to load #{ driver_jar } from :jdbc_driver_library, " +
174
+ "file not readable (please check user and group permissions for the path)"
175
+ end
146
176
begin
147
- @logger . debug ( "loading #{ driver_jar } " )
148
- # Use https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#from-jar-files to make classes from jar
149
- # available
150
177
require driver_jar
151
178
rescue LoadError => e
152
179
raise LogStash ::PluginLoadingError , "unable to load #{ driver_jar } from :jdbc_driver_library, #{ e . message } "
180
+ rescue StandardError => e
181
+ raise LogStash ::PluginLoadingError , "unable to load #{ driver_jar } from :jdbc_driver_library, #{ e } "
153
182
end
154
183
end
155
184
end
156
185
end
157
186
158
- private
159
- def open_jdbc_connection
160
- require "java"
161
- require "sequel"
162
- require "sequel/adapters/jdbc"
187
+ def jdbc_driver_library_set?
188
+ !@jdbc_driver_library . nil? && !@jdbc_driver_library . empty?
189
+ end
163
190
191
+ def open_jdbc_connection
192
+ # at this point driver is already loaded
164
193
Sequel . application_timezone = @plugin_timezone . to_sym
165
- if @drivers_loaded . false?
166
- begin
167
- load_driver_jars
168
- Sequel ::JDBC . load_driver ( @jdbc_driver_class )
169
- rescue LogStash ::Error => e
170
- # raised in load_drivers, e.cause should be the caught Java exceptions
171
- raise LogStash ::PluginLoadingError , "#{ e . message } and #{ e . cause . message } "
172
- rescue Sequel ::AdapterNotFound => e
173
- # fix this !!!
174
- message = if @jdbc_driver_library . nil?
175
- ":jdbc_driver_library is not set, are you sure you included
176
- the proper driver client libraries in your classpath?"
177
- else
178
- "Are you sure you've included the correct jdbc driver in :jdbc_driver_library?"
179
- end
180
- raise LogStash ::PluginLoadingError , "#{ e } . #{ message } "
181
- end
182
- @drivers_loaded . make_true
183
- end
194
+
184
195
@database = jdbc_connect ( )
185
196
@database . extension ( :pagination )
186
197
if @jdbc_default_timezone
0 commit comments