Module: Sequel::JDBC::Postgres::DatabaseMethods

Extended by:
Database::ResetIdentifierMangling
Includes:
Postgres::DatabaseMethods
Defined in:
lib/sequel/adapters/jdbc/postgresql.rb

Overview

Methods to add to Database instances that access PostgreSQL via JDBC.

Constant Summary

Constants included from Postgres::DatabaseMethods

Postgres::DatabaseMethods::FOREIGN_KEY_LIST_ON_DELETE_MAP, Postgres::DatabaseMethods::ON_COMMIT, Postgres::DatabaseMethods::POSTGRES_DEFAULT_RE, Postgres::DatabaseMethods::PREPARED_ARG_PLACEHOLDER, Postgres::DatabaseMethods::RE_CURRVAL_ERROR, Postgres::DatabaseMethods::SELECT_CUSTOM_SEQUENCE_SQL, Postgres::DatabaseMethods::SELECT_PK_SQL, Postgres::DatabaseMethods::SELECT_SERIAL_SEQUENCE_SQL, Postgres::DatabaseMethods::UNLOGGED

Instance Attribute Summary

Attributes included from Postgres::DatabaseMethods

#conversion_procs

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Database::ResetIdentifierMangling

extended

Methods included from Postgres::DatabaseMethods

#commit_prepared_transaction, #create_function, #create_language, #create_schema, #create_trigger, #database_type, #do, #drop_function, #drop_language, #drop_schema, #drop_trigger, #foreign_key_list, #indexes, #locks, #notify, #primary_key, #primary_key_sequence, #refresh_view, #reset_conversion_procs, #reset_primary_key_sequence, #rollback_prepared_transaction, #serial_primary_key_options, #server_version, #supports_create_table_if_not_exists?, #supports_deferrable_constraints?, #supports_deferrable_foreign_key_constraints?, #supports_drop_table_if_exists?, #supports_partial_indexes?, #supports_prepared_transactions?, #supports_savepoints?, #supports_transaction_isolation_levels?, #supports_transactional_ddl?, #tables, #type_supported?, #views

Class Method Details

.extended(db) ⇒ Object

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



18
19
20
21
# File 'lib/sequel/adapters/jdbc/postgresql.rb', line 18

def self.extended(db)
  super
  db.send(:initialize_postgres_adapter)
end

Instance Method Details

#copy_into(table, opts = OPTS) ⇒ Object

See Sequel::Postgres::Adapter#copy_into



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sequel/adapters/jdbc/postgresql.rb', line 24

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) ⇒ Object

See Sequel::Postgres::Adapter#copy_table



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/sequel/adapters/jdbc/postgresql.rb', line 61

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