module Sequel::JDBC::Postgres::DatabaseMethods

  1. lib/sequel/adapters/jdbc/postgresql.rb

Methods

Public Class

  1. extended

Public Instance

  1. add_conversion_proc
  2. copy_into
  3. copy_table
  4. oid_convertor_proc

Public Class methods

extended(db)

Add the primary_keys and primary_key_sequences instance variables, so we can get the correct return values for inserted rows.

[show source]
   # 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

add_conversion_proc(oid, *)

Remove any current entry for the oid in the oid_convertor_map.

[show source]
   # 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
copy_into(table, opts=OPTS)

See Sequel::Postgres::Adapter#copy_into

[show source]
   # 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 = Java::OrgPostgresqlCopy::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
copy_table(table, opts=OPTS)

See Sequel::Postgres::Adapter#copy_table

[show source]
    # File lib/sequel/adapters/jdbc/postgresql.rb
 75 def copy_table(table, opts=OPTS)
 76   synchronize(opts[:server]) do |conn|
 77     copy_manager = Java::OrgPostgresqlCopy::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
oid_convertor_proc(oid)
[show source]
    # 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