class LogStash::Filters::Jdbc::DbObject
Attributes
columns[R]
{name => “servers”, index_columns
=> [“ip”], columns => [[“ip”, “text”], [“name”, “text”], [“location”, “text”]]},
index_columns[R]
{name => “servers”, index_columns
=> [“ip”], columns => [[“ip”, “text”], [“name”, “text”], [“location”, “text”]]},
name[R]
{name => “servers”, index_columns
=> [“ip”], columns => [[“ip”, “text”], [“name”, “text”], [“location”, “text”]]},
preserve_existing[R]
{name => “servers”, index_columns
=> [“ip”], columns => [[“ip”, “text”], [“name”, “text”], [“location”, “text”]]},
Public Instance Methods
<=>(other)
click to toggle source
# File lib/logstash/filters/jdbc/db_object.rb, line 28 def <=>(other) @name <=> other.name end
build(db)
click to toggle source
# File lib/logstash/filters/jdbc/db_object.rb, line 12 def build(db) return unless valid? if db.nil? raise "DbObject given a database instance that is nil" end schema_gen = db.create_table_generator() @columns.each {|col| schema_gen.column(col.name, col.datatype)} schema_gen.index(@index_columns) unless @index_columns.empty? options = {:generator => schema_gen} if @preserve_existing db.create_table?(@name, options) else db.create_table(@name, options) end end
inspect()
click to toggle source
# File lib/logstash/filters/jdbc/db_object.rb, line 36 def inspect "<LogStash::Filters::Jdbc::DbObject name: #{@name}, columns: #{@columns.inspect}>" end
to_s()
click to toggle source
# File lib/logstash/filters/jdbc/db_object.rb, line 32 def to_s inspect end
Private Instance Methods
parse_options()
click to toggle source
# File lib/logstash/filters/jdbc/db_object.rb, line 48 def parse_options if !@options.is_a?(Hash) @option_errors << "DbObject options must be a Hash" @valid = false return end @name = @options["name"] unless @name && @name.is_a?(String) @option_errors << "DbObject options must include a 'name' string" @name = "unnamed" end @preserve_existing = @options.fetch("preserve_existing", false) @preserve_existing = true if @preserve_existing == "true" @columns_options = @options["columns"] @columns = [] temp_column_names = [] if @columns_options && @columns_options.is_a?(Array) sizes = @columns_options.map{|option| option.size}.uniq if sizes == [2] @columns_options.each do |option| column = Column.new(option) if column.valid? @columns << column temp_column_names << column.name else @option_errors << column.formatted_errors end end else @option_errors << "The columns array for '#{@name}' is not uniform, it should contain arrays of two strings only" end else @option_errors << "DbObject options for '#{@name}' must include a 'columns' array" end @index_column_options = @options["index_columns"] @index_columns = [] if @index_column_options && @index_column_options.is_a?(Array) @index_column_options.each do |option| if option.is_a?(String) && temp_column_names.member?(option.to_sym) @index_columns << option.to_sym else @option_errors << "The index_columns element: '#{option}' must be a column defined in the columns array" end end end @valid = @option_errors.empty? end
post_initialize()
click to toggle source
# File lib/logstash/filters/jdbc/db_object.rb, line 42 def post_initialize if valid? @name = @name.to_sym end end