class LogStash::PluginMixins::JdbcStreaming::StatementHandler
so as to not clash with the class of the same name and function in the jdbc input this is in the `module JdbcStreaming` namespace this duplication can be removed in a universal plugin
Attributes
cache[R]
parameters[R]
statement[R]
Public Class Methods
build_statement_handler(plugin)
click to toggle source
# File lib/logstash/plugin_mixins/jdbc_streaming/statement_handler.rb, line 10 def self.build_statement_handler(plugin) klass = plugin.use_prepared_statements ? PreparedStatementHandler : NormalStatementHandler klass.new(plugin) end
new(plugin)
click to toggle source
# File lib/logstash/plugin_mixins/jdbc_streaming/statement_handler.rb, line 17 def initialize(plugin) @statement = plugin.statement klass = plugin.use_cache ? RowCache : NoCache @cache = klass.new(plugin.cache_size, plugin.cache_expiration) post_init(plugin) end
Public Instance Methods
cache_lookup(db, event)
click to toggle source
Get from cache or performs remote lookup and saves to cache @param db [Sequel::Database] @param event [LogStash::Event] @returnparam [CachePayload]
# File lib/logstash/plugin_mixins/jdbc_streaming/statement_handler.rb, line 28 def cache_lookup(db, event) # override in subclass end
Private Instance Methods
common_cache_lookup(db, event)
click to toggle source
# File lib/logstash/plugin_mixins/jdbc_streaming/statement_handler.rb, line 34 def common_cache_lookup(db, event) params = prepare_parameters_from_event(event) @cache.get(params) do result = CachePayload.new begin logger.debug? && logger.debug("Executing JDBC query", :statement => statement, :parameters => params) execute_extract_records(db, params, result) rescue ::Sequel::Error => e # all sequel errors are a subclass of this, let all other standard or runtime errors bubble up result.failed! logger.warn? && logger.warn("Exception when executing JDBC query", :statement => statement, :parameters => params, :exception => e) end # if either of: no records or a Sequel exception occurs the payload is # empty and the default can be substituted later. result end end
execute_extract_records(db, params, result)
click to toggle source
# File lib/logstash/plugin_mixins/jdbc_streaming/statement_handler.rb, line 52 def execute_extract_records(db, params, result) # override in subclass end
post_init(plugin)
click to toggle source
# File lib/logstash/plugin_mixins/jdbc_streaming/statement_handler.rb, line 56 def post_init(plugin) # override in subclass, if needed end
prepare_parameters_from_event(event)
click to toggle source
# File lib/logstash/plugin_mixins/jdbc_streaming/statement_handler.rb, line 60 def prepare_parameters_from_event(event) @parameters.inject({}) do |hash, (k, parameter_handler)| # defer to appropriate parameter handler value = parameter_handler.extract_from(event) hash[k] = value.is_a?(::LogStash::Timestamp) ? value.time : value hash end end