module Sequel::JDBC::Postgres::DatabaseMethods
Public Class Methods
Add the primary_keys and primary_key_sequences instance variables, so we can get the correct return values for inserted rows.
# File lib/sequel/adapters/jdbc/postgresql.rb 22 def self.extended(db) 23 super 24 db.send(:initialize_postgres_adapter) 25 end
Public Instance Methods
Remove any current entry for the oid in the oid_convertor_map.
Sequel::Postgres::DatabaseMethods#add_conversion_proc
# File lib/sequel/adapters/jdbc/postgresql.rb 28 def add_conversion_proc(oid, *) 29 super 30 Sequel.synchronize{@oid_convertor_map.delete(oid)} 31 end
See Sequel::Postgres::Adapter#copy_into
# File lib/sequel/adapters/jdbc/postgresql.rb 34 def copy_into(table, opts=OPTS) 35 data = opts[:data] 36 data = Array(data) if data.is_a?(String) 37 38 if defined?(yield) && data 39 raise Error, "Cannot provide both a :data option and a block to copy_into" 40 elsif !defined?(yield) && !data 41 raise Error, "Must provide either a :data option or a block to copy_into" 42 end 43 44 synchronize(opts[:server]) do |conn| 45 begin 46 copy_manager = org.postgresql.copy.CopyManager.new(conn) 47 copier = copy_manager.copy_in(copy_into_sql(table, opts)) 48 if defined?(yield) 49 while buf = yield 50 java_bytes = buf.to_java_bytes 51 copier.writeToCopy(java_bytes, 0, java_bytes.length) 52 end 53 else 54 data.each do |d| 55 java_bytes = d.to_java_bytes 56 copier.writeToCopy(java_bytes, 0, java_bytes.length) 57 end 58 end 59 rescue Exception => e 60 copier.cancelCopy if copier 61 raise 62 ensure 63 unless e 64 begin 65 copier.endCopy 66 rescue NativeException => e2 67 raise_error(e2) 68 end 69 end 70 end 71 end 72 end
See Sequel::Postgres::Adapter#copy_table
# File lib/sequel/adapters/jdbc/postgresql.rb 75 def copy_table(table, opts=OPTS) 76 synchronize(opts[:server]) do |conn| 77 copy_manager = org.postgresql.copy.CopyManager.new(conn) 78 copier = copy_manager.copy_out(copy_table_sql(table, opts)) 79 begin 80 if defined?(yield) 81 while buf = copier.readFromCopy 82 yield(String.from_java_bytes(buf)) 83 end 84 nil 85 else 86 b = String.new 87 while buf = copier.readFromCopy 88 b << String.from_java_bytes(buf) 89 end 90 b 91 end 92 rescue => e 93 raise_error(e, :disconnect=>true) 94 ensure 95 if buf && !e 96 raise DatabaseDisconnectError, "disconnecting as a partial COPY may leave the connection in an unusable state" 97 end 98 end 99 end 100 end
# File lib/sequel/adapters/jdbc/postgresql.rb 102 def oid_convertor_proc(oid) 103 if (conv = Sequel.synchronize{@oid_convertor_map[oid]}).nil? 104 conv = if pr = conversion_procs[oid] 105 lambda do |r, i| 106 if v = r.getString(i) 107 pr.call(v) 108 end 109 end 110 else 111 false 112 end 113 Sequel.synchronize{@oid_convertor_map[oid] = conv} 114 end 115 conv 116 end
Private Instance Methods
For PostgreSQL-specific types, return the string that should be used as the PGObject value. Returns nil by default, loading pg_* extensions will override this to add support for specific types.
# File lib/sequel/adapters/jdbc/postgresql.rb 127 def bound_variable_arg(arg, conn) 128 nil 129 end
# File lib/sequel/adapters/jdbc/postgresql.rb 120 def disconnect_error?(exception, opts) 121 super || exception.message =~ /\A(This connection has been closed\.|FATAL: terminating connection due to administrator command|An I\/O error occurred while sending to the backend\.)\z/ 122 end
Work around issue when using Sequel’s bound variable support where the same SQL
is used in different bound variable calls, but the schema has changed between the calls. This is necessary as jdbc-postgres versions after 9.4.1200 violate the JDBC
API. These versions cache separate PreparedStatement instances, which are eventually prepared server side after the prepareThreshold is met. The JDBC
API violation is that PreparedStatement#close does not release the server side prepared statement.
# File lib/sequel/adapters/jdbc/postgresql.rb 138 def prepare_jdbc_statement(conn, sql, opts) 139 ps = super 140 unless opts[:name] 141 ps.prepare_threshold = 0 142 end 143 ps 144 end
If the given argument is a recognized PostgreSQL-specific type, create a PGObject instance with unknown type and the bound argument string value, and set that as the prepared statement argument.
# File lib/sequel/adapters/jdbc/postgresql.rb 149 def set_ps_arg(cps, arg, i) 150 if v = bound_variable_arg(arg, nil) 151 obj = org.postgresql.util.PGobject.new 152 obj.setType("unknown") 153 obj.setValue(v) 154 cps.setObject(i, obj) 155 else 156 super 157 end 158 end
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 162 def set_ps_arg_nil(cps, i) 163 cps.setNull(i, JavaSQL::Types::NULL) 164 end
Execute the connection configuration SQL
queries on the connection.
# File lib/sequel/adapters/jdbc/postgresql.rb 167 def setup_connection_with_opts(conn, opts) 168 conn = super 169 statement(conn) do |stmt| 170 connection_configuration_sqls(opts).each{|sql| log_connection_yield(sql, conn){stmt.execute(sql)}} 171 end 172 conn 173 end
# File lib/sequel/adapters/jdbc/postgresql.rb 175 def setup_type_convertor_map 176 super 177 @oid_convertor_map = {} 178 end