class ThinkingSphinx::Connection::JRuby

Attributes

address[R]
options[R]

Public Class Methods

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

Public Instance Methods

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

Private Instance Methods

client() click to toggle source
# File lib/thinking_sphinx/connection/jruby.rb, line 15
def client
  @client ||= Java::ComMysqlJdbc::Driver.new.connect address, properties
rescue base_error => error
  raise ThinkingSphinx::SphinxError.new_from_mysql error
end
properties() click to toggle source
# File lib/thinking_sphinx/connection/jruby.rb, line 21
def properties
  object = Java::JavaUtil::Properties.new
  object.setProperty "user", options[:username]     if options[:username]
  object.setProperty "password", options[:password] if options[:password]
  object
end
results_for(statements) click to toggle source
# File lib/thinking_sphinx/connection/jruby.rb, line 28
def results_for(statements)
  statement = client.createStatement
  statement.execute statements

  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/jruby.rb, line 37
def set_to_array(set)
  return nil if set.nil?

  meta = set.getMetaData
  rows = []

  while set.next
    rows << (1..meta.getColumnCount).inject({}) do |row, index|
      name      = meta.getColumnName index
      row[name] = set.getObject(index)
      row
    end
  end

  rows
end