Class: LogStash::Filters::Jdbc::Loader

Inherits:
Validatable show all
Includes:
Util::Loggable
Defined in:
lib/logstash/filters/jdbc/loader.rb

Constant Summary collapse

CONNECTION_ERROR_MSG =
"Remote DB connection error when executing loader Jdbc query"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Validatable

find_validation_errors, #formatted_errors, #initialize, #valid?

Constructor Details

This class inherits a constructor from LogStash::Filters::Jdbc::Validatable

Instance Attribute Details

#connection_stringObject (readonly)

Returns the value of attribute connection_string.



14
15
16
# File 'lib/logstash/filters/jdbc/loader.rb', line 14

def connection_string
  @connection_string
end

#driver_classObject (readonly)

Returns the value of attribute driver_class.



14
15
16
# File 'lib/logstash/filters/jdbc/loader.rb', line 14

def driver_class
  @driver_class
end

#driver_libraryObject (readonly)

Returns the value of attribute driver_library.



14
15
16
# File 'lib/logstash/filters/jdbc/loader.rb', line 14

def driver_library
  @driver_library
end

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'lib/logstash/filters/jdbc/loader.rb', line 13

def id
  @id
end

#max_rowsObject (readonly)

Returns the value of attribute max_rows.



13
14
15
# File 'lib/logstash/filters/jdbc/loader.rb', line 13

def max_rows
  @max_rows
end

#passwordObject (readonly)

Returns the value of attribute password.



15
16
17
# File 'lib/logstash/filters/jdbc/loader.rb', line 15

def password
  @password
end

#queryObject (readonly)

Returns the value of attribute query.



13
14
15
# File 'lib/logstash/filters/jdbc/loader.rb', line 13

def query
  @query
end

#staging_directoryObject (readonly)

Returns the value of attribute staging_directory.



15
16
17
# File 'lib/logstash/filters/jdbc/loader.rb', line 15

def staging_directory
  @staging_directory
end

#tableObject (readonly)

Returns the value of attribute table.



13
14
15
# File 'lib/logstash/filters/jdbc/loader.rb', line 13

def table
  @table
end

#userObject (readonly)

Returns the value of attribute user.



15
16
17
# File 'lib/logstash/filters/jdbc/loader.rb', line 15

def user
  @user
end

Instance Method Details

#build_remote_dbObject



17
18
19
# File 'lib/logstash/filters/jdbc/loader.rb', line 17

def build_remote_db
  @remote = ReadOnlyDatabase.create(connection_string, driver_class, driver_library, user, password)
end

#closeObject



37
38
39
# File 'lib/logstash/filters/jdbc/loader.rb', line 37

def close
  @remote.disconnect(CONNECTION_ERROR_MSG)
end

#fetchObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/logstash/filters/jdbc/loader.rb', line 21

def fetch
  @remote.connect(CONNECTION_ERROR_MSG)
  row_count = @remote.count(query)
  if row_count.zero?
    logger.warn? && logger.warn("Query returned no results", :lookup_id => @id, :query => query)
    return @remote.empty_record_set
  end
  if row_count > max_rows
    logger.warn? && logger.warn("Query returned more than max_rows results", :lookup_id => @id, :query => query, :count => row_count, :max_rows => max_rows)
    return @remote.empty_record_set
  end
  @remote.query(query)
ensure
  @remote.disconnect(CONNECTION_ERROR_MSG)
end