Class: ActiveRecord::ConnectionAdapters::HbaseAdapter
- Inherits:
-
AbstractMysqlAdapter
- Object
- AbstractMysqlAdapter
- ActiveRecord::ConnectionAdapters::HbaseAdapter
- 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
Instance Method Summary collapse
-
#active? ⇒ Boolean
CONNECTION MANAGEMENT ====================================.
-
#disconnect! ⇒ Object
Disconnects from the database if already connected.
-
#each_hash(result) ⇒ Object
HELPER METHODS ===========================================.
- #error_number(exception) ⇒ Object
- #exec_delete(sql, name, binds) ⇒ Object (also: #exec_update)
- #exec_insert(sql, name, binds, pk = nil, sequence_name = nil) ⇒ Object
- #exec_query(sql, name = 'SQL', binds = []) ⇒ Object (also: #exec_without_stmt)
-
#execute(sql, name = nil) ⇒ Object
Executes the SQL statement in the context of this connection.
-
#explain(arel, binds = []) ⇒ Object
DATABASE STATEMENTS ======================================.
-
#initialize(connection, logger, connection_options, config) ⇒ HbaseAdapter
constructor
A new instance of HbaseAdapter.
- #initialize_schema_migrations_table ⇒ Object
- #insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object (also: #create)
- #last_inserted_id(result) ⇒ Object
-
#new_column(field, default, type, null, collation, extra = "") ⇒ Object
:nodoc:.
-
#quote_string(string) ⇒ Object
QUOTING ==================================================.
- #reconnect! ⇒ Object (also: #reset!)
-
#select(sql, name = nil, binds = []) ⇒ Object
Returns an ActiveRecord::Result instance.
-
#select_rows(sql, name = nil, binds = []) ⇒ Object
Returns an array of arrays containing the field values.
- #supports_explain? ⇒ Boolean
Constructor Details
#initialize(connection, logger, connection_options, config) ⇒ HbaseAdapter
Returns a new instance of HbaseAdapter.
54 55 56 57 58 59 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 54 def initialize(connection, logger, , config) super @visitor = BindSubstitution.new self configure_connection end |
Instance Method Details
#active? ⇒ Boolean
CONNECTION MANAGEMENT ====================================
103 104 105 106 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 103 def active? return false unless @connection @connection.ping end |
#disconnect! ⇒ Object
Disconnects from the database if already connected. Otherwise, this method does nothing.
117 118 119 120 121 122 123 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 117 def disconnect! super unless @connection.nil? @connection.close @connection = nil end end |
#each_hash(result) ⇒ Object
HELPER METHODS ===========================================
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 76 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
91 92 93 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 91 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
268 269 270 271 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 268 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
264 265 266 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 264 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
246 247 248 249 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 246 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.
236 237 238 239 240 241 242 243 244 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 236 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.[:database_timezone] = ActiveRecord::Base.default_timezone end super end |
#explain(arel, binds = []) ⇒ Object
DATABASE STATEMENTS ======================================
127 128 129 130 131 132 133 134 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 127 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_table ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 62 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
258 259 260 261 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 258 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
274 275 276 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 274 def last_inserted_id(result) @connection.last_id end |
#new_column(field, default, type, null, collation, extra = "") ⇒ Object
:nodoc:
87 88 89 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 87 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 ==================================================
97 98 99 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 97 def quote_string(string) @connection.escape(string) end |
#reconnect! ⇒ Object Also known as: reset!
108 109 110 111 112 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 108 def reconnect! super disconnect! connect end |
#select(sql, name = nil, binds = []) ⇒ Object
Returns an ActiveRecord::Result instance.
254 255 256 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 254 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.
231 232 233 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 231 def select_rows(sql, name = nil, binds = []) execute(sql, name).to_a end |
#supports_explain? ⇒ Boolean
70 71 72 |
# File 'lib/active_record/connection_adapters/hbase_adapter.rb', line 70 def supports_explain? true end |