Class: ActiveRecord::ConnectionAdapters::HbaseAdapter

Inherits:
AbstractMysqlAdapter show all
Defined in:
lib/active_record/connection_adapters/hbase_adapter.rb

Defined Under Namespace

Classes: Column, ExplainPrettyPrinter

Constant Summary collapse

ADAPTER_NAME =
'Hbase'
MAX_INDEX_LENGTH_FOR_UTF8MB4 =
191

Constants inherited from AbstractMysqlAdapter

AbstractMysqlAdapter::INDEX_TYPES, AbstractMysqlAdapter::INDEX_USINGS, AbstractMysqlAdapter::LOST_CONNECTION_ERROR_MESSAGES, AbstractMysqlAdapter::NATIVE_DATABASE_TYPES

Instance Method Summary collapse

Methods inherited from AbstractMysqlAdapter

#adapter_name, #add_column_position!, #add_index, #begin_db_transaction, #begin_isolated_db_transaction, #bulk_change_table, #case_insensitive_comparison, #case_sensitive_modifier, #change_column, #change_column_default, #change_column_null, #charset, #collation, #columns, #commit_db_transaction, #create_database, #create_table, #current_database, #disable_referential_integrity, #drop_database, #drop_table, #empty_insert_statement_value, #emulate_booleans, #execute_and_free, #index_algorithms, #indexes, #join_to_update, #limited_update_conditions, #native_database_types, #pk_and_sequence_for, #primary_key, #quote, #quote_column_name, #quote_table_name, #quoted_false, #quoted_true, #recreate_database, #rename_column, #rename_index, #rename_table, #rollback_db_transaction, #schema_creation, #show_variable, #strict_mode?, #supports_bulk_alter?, #supports_index_sort_order?, #supports_migrations?, #supports_primary_key?, #supports_transaction_isolation?, #table_exists?, #tables, #type_cast, #type_to_sql, #update_sql, #valid_type?

Constructor Details

#initialize(connection, logger, connection_options, config) ⇒ HbaseAdapter

Returns a new instance of HbaseAdapter.



58
59
60
61
62
63
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 58

def initialize(connection, logger, connection_options, config)
  super

  @visitor = BindSubstitution.new self
  configure_connection
end

Instance Method Details

#active?Boolean

CONNECTION MANAGEMENT ====================================

Returns:

  • (Boolean)


107
108
109
110
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 107

def active?
  return false unless @connection
  @connection.ping
end

#disconnect!Object

Disconnects from the database if already connected. Otherwise, this method does nothing.



121
122
123
124
125
126
127
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 121

def disconnect!
  super
  unless @connection.nil?
    @connection.close
    @connection = nil
  end
end

#each_hash(result) ⇒ Object

HELPER METHODS ===========================================



80
81
82
83
84
85
86
87
88
89
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 80

def each_hash(result) # :nodoc:

  if block_given?
    result.each(:as => :hash, :symbolize_keys => true) do |row|
      yield row
    end
  else
    to_enum(:each_hash, result)
  end
end

#error_number(exception) ⇒ Object



95
96
97
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 95

def error_number(exception)
  exception.error_number if exception.respond_to?(:error_number)
end

#exec_delete(sql, name, binds) ⇒ Object Also known as: exec_update



272
273
274
275
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 272

def exec_delete(sql, name, binds)
  execute to_sql(sql, binds), name
  @connection.affected_rows
end

#exec_insert(sql, name, binds, pk = nil, sequence_name = nil) ⇒ Object



268
269
270
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 268

def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
  execute to_sql(sql, binds), name
end

#exec_query(sql, name = 'SQL', binds = []) ⇒ Object Also known as: exec_without_stmt



250
251
252
253
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 250

def exec_query(sql, name = 'SQL', binds = [])
  result = execute(sql, name)
  ActiveRecord::Result.new(result.fields, result.to_a)
end

#execute(sql, name = nil) ⇒ Object

Executes the SQL statement in the context of this connection.



240
241
242
243
244
245
246
247
248
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 240

def execute(sql, name = nil)
  if @connection
    # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been
    # made since we established the connection
    @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone
  end

  super
end

#explain(arel, binds = []) ⇒ Object

DATABASE STATEMENTS ======================================



131
132
133
134
135
136
137
138
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 131

def explain(arel, binds = [])
  sql     = "EXPLAIN #{to_sql(arel, binds.dup)}"
  start   = Time.now
  result  = exec_query(sql, 'EXPLAIN', binds)
  elapsed = Time.now - start

  ExplainPrettyPrinter.new.pp(result, elapsed)
end

#initialize_schema_migrations_tableObject



66
67
68
69
70
71
72
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 66

def initialize_schema_migrations_table
  if @config[:encoding] == 'utf8mb4'
    ActiveRecord::SchemaMigration.create_table(MAX_INDEX_LENGTH_FOR_UTF8MB4)
  else
    ActiveRecord::SchemaMigration.create_table
  end
end

#insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object Also known as: create



262
263
264
265
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 262

def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
  super
  id_value || @connection.last_id
end

#last_inserted_id(result) ⇒ Object



278
279
280
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 278

def last_inserted_id(result)
  @connection.last_id
end

#new_column(field, default, type, null, collation, extra = "") ⇒ Object

:nodoc:



91
92
93
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 91

def new_column(field, default, type, null, collation, extra = "") # :nodoc:
  Column.new(field, default, type, null, collation, strict_mode?, extra)
end

#quote_string(string) ⇒ Object

QUOTING ==================================================



101
102
103
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 101

def quote_string(string)
  @connection.escape(string)
end

#reconnect!Object Also known as: reset!



112
113
114
115
116
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 112

def reconnect!
  super
  disconnect!
  connect
end

#select(sql, name = nil, binds = []) ⇒ Object

Returns an ActiveRecord::Result instance.



258
259
260
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 258

def select(sql, name = nil, binds = [])
  exec_query(sql, name)
end

#select_rows(sql, name = nil, binds = []) ⇒ Object

Returns an array of arrays containing the field values. Order is the same as that returned by columns.



235
236
237
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 235

def select_rows(sql, name = nil, binds = [])
  execute(sql, name).to_a
end

#supports_explain?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 74

def supports_explain?
  true
end