class ThinkingSphinx::Connection::JRuby

Attributes

address[R]
options[R]

Public Class Methods

new(options) click to toggle source
Calls superclass method ThinkingSphinx::Connection::Client::new
# File lib/thinking_sphinx/connection/jruby.rb, line 6
def initialize(options)
  options.delete :socket

  super

  @address = "jdbc:mysql://#{@options[:host]}:#{@options[:port]}/?allowMultiQueries=true"
end

Public Instance Methods

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

Private Instance Methods

client() click to toggle source
# File lib/thinking_sphinx/connection/jruby.rb, line 20
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 26
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 33
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 42
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