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 40 def self.extended(db) 41 super 42 db.send(:initialize_postgres_adapter) 43 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 46 def add_conversion_proc(oid, *) 47 super 48 Sequel.synchronize{@oid_convertor_map.delete(oid)} 49 end
See Sequel::Postgres::Adapter#copy_into
# File lib/sequel/adapters/jdbc/postgresql.rb 52 def copy_into(table, opts=OPTS) 53 data = opts[:data] 54 data = Array(data) if data.is_a?(String) 55 56 if block_given? && data 57 raise Error, "Cannot provide both a :data option and a block to copy_into" 58 elsif !block_given? && !data 59 raise Error, "Must provide either a :data option or a block to copy_into" 60 end 61 62 synchronize(opts[:server]) do |conn| 63 begin 64 copy_manager = org.postgresql.copy.CopyManager.new(conn) 65 copier = copy_manager.copy_in(copy_into_sql(table, opts)) 66 if block_given? 67 while buf = yield 68 java_bytes = buf.to_java_bytes 69 copier.writeToCopy(java_bytes, 0, java_bytes.length) 70 end 71 else 72 data.each do |d| 73 java_bytes = d.to_java_bytes 74 copier.writeToCopy(java_bytes, 0, java_bytes.length) 75 end 76 end 77 rescue Exception => e 78 copier.cancelCopy if copier 79 raise 80 ensure 81 unless e 82 begin 83 copier.endCopy 84 rescue NativeException => e2 85 raise_error(e2) 86 end 87 end 88 end 89 end 90 end
See Sequel::Postgres::Adapter#copy_table
# File lib/sequel/adapters/jdbc/postgresql.rb 93 def copy_table(table, opts=OPTS) 94 synchronize(opts[:server]) do |conn| 95 copy_manager = org.postgresql.copy.CopyManager.new(conn) 96 copier = copy_manager.copy_out(copy_table_sql(table, opts)) 97 begin 98 if block_given? 99 while buf = copier.readFromCopy 100 yield(String.from_java_bytes(buf)) 101 end 102 nil 103 else 104 b = String.new 105 while buf = copier.readFromCopy 106 b << String.from_java_bytes(buf) 107 end 108 b 109 end 110 rescue => e 111 raise_error(e, :disconnect=>true) 112 ensure 113 if buf && !e 114 raise DatabaseDisconnectError, "disconnecting as a partial COPY may leave the connection in an unusable state" 115 end 116 end 117 end 118 end
# File lib/sequel/adapters/jdbc/postgresql.rb 120 def oid_convertor_proc(oid) 121 if (conv = Sequel.synchronize{@oid_convertor_map[oid]}).nil? 122 conv = if pr = conversion_procs[oid] 123 lambda do |r, i| 124 if v = r.getString(i) 125 pr.call(v) 126 end 127 end 128 else 129 false 130 end 131 Sequel.synchronize{@oid_convertor_map[oid] = conv} 132 end 133 conv 134 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 145 def bound_variable_arg(arg, conn) 146 nil 147 end
# File lib/sequel/adapters/jdbc/postgresql.rb 138 def disconnect_error?(exception, opts) 139 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/ 140 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 156 def prepare_jdbc_statement(conn, sql, opts) 157 ps = super 158 unless opts[:name] 159 ps.prepare_threshold = 0 160 end 161 ps 162 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 167 def set_ps_arg(cps, arg, i) 168 if v = bound_variable_arg(arg, nil) 169 obj = org.postgresql.util.PGobject.new 170 obj.setType("unknown") 171 obj.setValue(v) 172 cps.setObject(i, obj) 173 else 174 super 175 end 176 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 180 def set_ps_arg_nil(cps, i) 181 cps.setNull(i, JavaSQL::Types::NULL) 182 end
Execute the connection configuration SQL
queries on the connection.
# File lib/sequel/adapters/jdbc/postgresql.rb 185 def setup_connection_with_opts(conn, opts) 186 conn = super 187 statement(conn) do |stmt| 188 connection_configuration_sqls(opts).each{|sql| log_connection_yield(sql, conn){stmt.execute(sql)}} 189 end 190 conn 191 end
# File lib/sequel/adapters/jdbc/postgresql.rb 193 def setup_type_convertor_map 194 super 195 @oid_convertor_map = {} 196 end