Module: Sequel::JDBC::Postgres::DatabaseMethods
- 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
Class Method Summary collapse
-
.extended(db) ⇒ Object
Add the primary_keys and primary_key_sequences instance variables, so we can get the correct return values for inserted rows.
Instance Method Summary collapse
-
#add_conversion_proc(oid) ⇒ Object
Remove any current entry for the oid in the oid_convertor_map.
-
#copy_into(table, opts = OPTS) ⇒ Object
See Sequel::Postgres::Adapter#copy_into.
-
#copy_table(table, opts = OPTS) ⇒ Object
See Sequel::Postgres::Adapter#copy_table.
- #oid_convertor_proc(oid) ⇒ Object
Methods included from Postgres::DatabaseMethods
#add_named_conversion_proc, #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, #freeze, #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.
58 59 60 61 |
# File 'lib/sequel/adapters/jdbc/postgresql.rb', line 58 def self.extended(db) super db.send(:initialize_postgres_adapter) end |
Instance Method Details
#add_conversion_proc(oid) ⇒ Object
Remove any current entry for the oid in the oid_convertor_map.
64 65 66 67 |
# File 'lib/sequel/adapters/jdbc/postgresql.rb', line 64 def add_conversion_proc(oid, *) super Sequel.synchronize{@oid_convertor_map.delete(oid)} end |
#copy_into(table, opts = OPTS) ⇒ Object
See Sequel::Postgres::Adapter#copy_into
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/sequel/adapters/jdbc/postgresql.rb', line 70 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[:server]) 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 if copier 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
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/sequel/adapters/jdbc/postgresql.rb', line 107 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 = String.new while buf = copier.readFromCopy b << String.from_java_bytes(buf) end b end rescue => e raise_error(e, :disconnect=>true) ensure if buf && !e raise DatabaseDisconnectError, "disconnecting as a partial COPY may leave the connection in an unusable state" end end end end |
#oid_convertor_proc(oid) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/sequel/adapters/jdbc/postgresql.rb', line 134 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 |