Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/arjdbc/cassandra/connection_methods.rb

Class Method Summary collapse

Class Method Details

.cassandra_connection(config) ⇒ Object Also known as: jdbccassandra_connection



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/arjdbc/cassandra/connection_methods.rb', line 3

def cassandra_connection(config)
  begin
    require 'jdbc/cassandra'
    ::Jdbc::Cassandra.load_driver(:require) if defined?(::Jdbc::Cassandra.load_driver)
  rescue LoadError # assuming driver.jar is on the class-path
  end

  config[:host] ||= '127.0.0.1'
  config[:port] ||= 9160
  config[:url] ||= "jdbc:cassandra://#{config[:host]}:#{config[:port]}/#{config[:database]}"
  config[:driver] ||= defined?(::Jdbc::Cassandra.driver_name) ? ::Jdbc::Cassandra.driver_name : 'org.apache.cassandra.cql.jdbc.CassandraDriver'
  config[:adapter_class] = ActiveRecord::ConnectionAdapters::CassandraAdapter
  config[:adapter_spec] = ::ArJdbc::Cassandra

  options = (config[:options] ||= {})
  #options['zeroDateTimeBehavior'] ||= 'convertToNull'
  #options['jdbcCompliantTruncation'] ||= 'false'
  #options['useUnicode'] ||= 'true'
  #options['characterEncoding'] = config[:encoding] || 'utf8'

  jdbc_connection(config)
end