module Sequel::JDBC::Postgres::DatabaseMethods
Methods to add to Database instances that access PostgreSQL via JDBC.
Public Class Methods
extended(db)
click to toggle source
Add the primary_keys and primary_key_sequences instance variables, so we can get the correct return values for inserted rows.
Calls superclass method
# File lib/sequel/adapters/jdbc/postgresql.rb, line 47 def self.extended(db) super db.send(:initialize_postgres_adapter) end
Public Instance Methods
copy_into(table, opts=OPTS)
click to toggle source
See Sequel::Postgres::Adapter#copy_into
# File lib/sequel/adapters/jdbc/postgresql.rb, line 53 def copy_into(table, opts=OPTS) data = opts[:data] data = Array(data) if data.is_a?(String) if block_given? && data raise Error, "Cannot provide both a :data option and a block to copy_into" elsif !block_given? && !data raise Error, "Must provide either a :data option or a block to copy_into" end synchronize(opts) do |conn| begin copy_manager = org.postgresql.copy.CopyManager.new(conn) copier = copy_manager.copy_in(copy_into_sql(table, opts)) if block_given? while buf = yield copier.writeToCopy(buf.to_java_bytes, 0, buf.length) end else data.each { |d| copier.writeToCopy(d.to_java_bytes, 0, d.length) } end rescue Exception => e copier.cancelCopy raise ensure unless e begin copier.endCopy rescue NativeException => e2 raise_error(e2) end end end end end
copy_table(table, opts=OPTS) { |from_java_bytes| ... }
click to toggle source
See Sequel::Postgres::Adapter#copy_table
# File lib/sequel/adapters/jdbc/postgresql.rb, line 90 def copy_table(table, opts=OPTS) synchronize(opts[:server]) do |conn| copy_manager = org.postgresql.copy.CopyManager.new(conn) copier = copy_manager.copy_out(copy_table_sql(table, opts)) begin if block_given? while buf = copier.readFromCopy yield(String.from_java_bytes(buf)) end nil else b = '' while buf = copier.readFromCopy b << String.from_java_bytes(buf) end b end ensure raise DatabaseDisconnectError, "disconnecting as a partial COPY may leave the connection in an unusable state" if buf end end end
oid_convertor_proc(oid)
click to toggle source
# File lib/sequel/adapters/jdbc/postgresql.rb, line 113 def oid_convertor_proc(oid) if (conv = Sequel.synchronize{@oid_convertor_map[oid]}).nil? conv = if pr = conversion_procs[oid] lambda do |r, i| if v = r.getString(i) pr.call(v) end end else false end Sequel.synchronize{@oid_convertor_map[oid] = conv} end conv end
Private Instance Methods
conversion_procs_updated()
click to toggle source
Clear oid convertor map cache when conversion procs are updated.
Calls superclass method
Sequel::Postgres::DatabaseMethods#conversion_procs_updated
# File lib/sequel/adapters/jdbc/postgresql.rb, line 132 def conversion_procs_updated super Sequel.synchronize{@oid_convertor_map = {}} end
disconnect_error?(exception, opts)
click to toggle source
Calls superclass method
# File lib/sequel/adapters/jdbc/postgresql.rb, line 137 def disconnect_error?(exception, opts) super || exception.message =~ /\AThis connection has been closed\.\z|\AFATAL: terminating connection due to administrator command\z/ end
set_ps_arg_nil(cps, i)
click to toggle source
Use setNull for nil arguments as the default behavior of setString with nil doesn't appear to work correctly on PostgreSQL.
# File lib/sequel/adapters/jdbc/postgresql.rb, line 143 def set_ps_arg_nil(cps, i) cps.setNull(i, JavaSQL::Types::NULL) end
setup_connection(conn)
click to toggle source
Execute the connection configuration SQL queries on the connection.
Calls superclass method
# File lib/sequel/adapters/jdbc/postgresql.rb, line 148 def setup_connection(conn) conn = super(conn) statement(conn) do |stmt| connection_configuration_sqls.each{|sql| log_yield(sql){stmt.execute(sql)}} end conn end
setup_type_convertor_map()
click to toggle source
Calls superclass method
# File lib/sequel/adapters/jdbc/postgresql.rb, line 156 def setup_type_convertor_map super @oid_convertor_map = {} @type_convertor_map[:RubyPGArray] = TypeConvertor::INSTANCE.method(:RubyPGArray) @type_convertor_map[:RubyPGHstore] = TypeConvertor::INSTANCE.method(:RubyPGHstore) end