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?, #supports_trigger_conditions?, #tables, #type_supported?, #values, #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.



47
48
49
50
# File 'lib/sequel/adapters/jdbc/postgresql.rb', line 47

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 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) ⇒ Object

See Sequel::Postgres::Adapter#copy_table



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# 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) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# 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