class ThinkingSphinx::Connection::JRuby

Attributes

address[R]
options[R]

Public Class Methods

new(address, port, options) click to toggle source
# File lib/thinking_sphinx/connection.rb, line 129
def initialize(address, port, options)
  @address = "jdbc:mysql://#{address}:#{port}?allowMultiQueries=true"
  @options = options
end

Public Instance Methods

base_error() click to toggle source
# File lib/thinking_sphinx/connection.rb, line 134
def base_error
  Java::JavaSql::SQLException
end

Private Instance Methods

client() click to toggle source
# File lib/thinking_sphinx/connection.rb, line 140
def client
  @client ||= java.sql.DriverManager.getConnection address,
    options[:username], options[:password]
rescue base_error => error
  raise ThinkingSphinx::SphinxError.new_from_mysql error
end
results_for(*statements) click to toggle source
# File lib/thinking_sphinx/connection.rb, line 147
def results_for(*statements)
  statement = client.createStatement
  statement.execute statements.join('; ')

  results   = [set_to_array(statement.getResultSet)]
  results  << set_to_array(statement.getResultSet) while statement.getMoreResults
  results.compact
end
set_to_array(set) click to toggle source
# File lib/thinking_sphinx/connection.rb, line 156
def set_to_array(set)
  return nil if set.nil?

  meta = set.meta_data
  rows = []

  while set.next
    rows << (1..meta.column_count).inject({}) do |row, index|
      name      = meta.column_name index
      row[name] = set.get_object(index)
      row
    end
  end

  rows
end