Class: LogStash::Filters::Jdbc::BasicDatabase
- Inherits:
-
Object
- Object
- LogStash::Filters::Jdbc::BasicDatabase
show all
- Includes:
- Util::Loggable
- Defined in:
- lib/logstash/filters/jdbc/basic_database.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BasicDatabase.
43
44
45
46
|
# File 'lib/logstash/filters/jdbc/basic_database.rb', line 43
def initialize()
@options_hash = {}
post_initialize
end
|
Instance Attribute Details
#unique_db_name ⇒ Object
Returns the value of attribute unique_db_name.
41
42
43
|
# File 'lib/logstash/filters/jdbc/basic_database.rb', line 41
def unique_db_name
@unique_db_name
end
|
Class Method Details
.create(connection_string = MEMORY_DERBY_LOCAL_CONNECTION_STRING, driver_class = EMBEDDED_DERBY_DRIVER_CLASS, driver_library = nil, user = nil, password = nil) ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/logstash/filters/jdbc/basic_database.rb', line 26
def self.create(
connection_string = MEMORY_DERBY_LOCAL_CONNECTION_STRING,
driver_class = EMBEDDED_DERBY_DRIVER_CLASS,
driver_library = nil,
user = nil,
password = nil)
instance = new
instance.post_create(connection_string, driver_class, driver_library, user, password)
instance
end
|
.random_name(length = 10) ⇒ Object
37
38
39
|
# File 'lib/logstash/filters/jdbc/basic_database.rb', line 37
def self.random_name(length = 10)
SecureRandom.hex(length)
end
|
.wrap_error(new_error_class, exception, message = nil) ⇒ Object
20
21
22
23
24
|
# File 'lib/logstash/filters/jdbc/basic_database.rb', line 20
def self.wrap_error(new_error_class, exception, message = nil)
error = new_error_class.new(message || exception.message)
error.set_backtrace(exception.backtrace)
error
end
|
Instance Method Details
#connect(err_message) ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/logstash/filters/jdbc/basic_database.rb', line 48
def connect(err_message)
begin
@db = ::Sequel.connect(@connection_string, @options_hash)
rescue *CONNECTION_ERRORS => err
logger.error(err_message, :exception => err.message, :backtrace => err.backtrace.take(8))
else
raise "::Sequel.connect returned a nil db instance, connection_string: #{@connection_string}, options: #{@options_hash.inspect}" if @db.nil?
end
end
|
#connected? ⇒ Boolean
71
72
73
|
# File 'lib/logstash/filters/jdbc/basic_database.rb', line 71
def connected?
!@db.nil?
end
|
#disconnect(err_message) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/logstash/filters/jdbc/basic_database.rb', line 59
def disconnect(err_message)
return if @db.nil?
begin
@db.disconnect
rescue *CONNECTION_ERRORS => err
logger.error(err_message, :exception => err.message, :backtrace => err.backtrace.take(8))
ensure
@db = nil
end
end
|
#empty_record_set ⇒ Object
75
76
77
|
# File 'lib/logstash/filters/jdbc/basic_database.rb', line 75
def empty_record_set
[]
end
|
#post_create(connection_string, driver_class, driver_library, user, password) ⇒ Object
79
80
81
|
# File 'lib/logstash/filters/jdbc/basic_database.rb', line 79
def post_create(connection_string, driver_class, driver_library, user, password)
raise NotImplementedError.new("#{self.class.name} is abstract, you must subclass it and implement #post_create()")
end
|