Class Index [+]

Quicksearch

Sequel::JDBC::H2::DatabaseMethods

Instance methods for H2 Database objects accessed via JDBC.

Constants

PRIMARY_KEY_INDEX_RE

Public Instance Methods

commit_prepared_transaction(transaction_id) click to toggle source

Commit an existing prepared transaction with the given transaction identifier string.

    # File lib/sequel/adapters/jdbc/h2.rb, line 11
11:         def commit_prepared_transaction(transaction_id)
12:           run("COMMIT TRANSACTION #{transaction_id}")
13:         end
database_type() click to toggle source

H2 uses the :h2 database type.

    # File lib/sequel/adapters/jdbc/h2.rb, line 16
16:         def database_type
17:           :h2
18:         end
rollback_prepared_transaction(transaction_id) click to toggle source

Rollback an existing prepared transaction with the given transaction identifier string.

    # File lib/sequel/adapters/jdbc/h2.rb, line 22
22:         def rollback_prepared_transaction(transaction_id)
23:           run("ROLLBACK TRANSACTION #{transaction_id}")
24:         end
serial_primary_key_options() click to toggle source

H2 uses an IDENTITY type

    # File lib/sequel/adapters/jdbc/h2.rb, line 27
27:         def serial_primary_key_options
28:           {:primary_key => true, :type => :identity, :identity=>true}
29:         end
supports_create_table_if_not_exists?() click to toggle source

H2 supports CREATE TABLE IF NOT EXISTS syntax.

    # File lib/sequel/adapters/jdbc/h2.rb, line 32
32:         def supports_create_table_if_not_exists?
33:           true
34:         end
supports_prepared_transactions?() click to toggle source

H2 supports prepared transactions

    # File lib/sequel/adapters/jdbc/h2.rb, line 37
37:         def supports_prepared_transactions?
38:           true
39:         end
supports_savepoints?() click to toggle source

H2 supports savepoints

    # File lib/sequel/adapters/jdbc/h2.rb, line 42
42:         def supports_savepoints?
43:           true
44:         end

Private Instance Methods

alter_table_sql(table, op) click to toggle source

H2 needs to add a primary key column as a constraint

    # File lib/sequel/adapters/jdbc/h2.rb, line 59
59:         def alter_table_sql(table, op)
60:           case op[:op]
61:           when :add_column
62:             if (pk = op.delete(:primary_key)) || (ref = op.delete(:table))
63:               sqls = [super(table, op)]
64:               sqls << "ALTER TABLE #{quote_schema_table(table)} ADD PRIMARY KEY (#{quote_identifier(op[:name])})" if pk
65:               if ref
66:                 op[:table] = ref
67:                 sqls << "ALTER TABLE #{quote_schema_table(table)} ADD FOREIGN KEY (#{quote_identifier(op[:name])}) #{column_references_sql(op)}"
68:               end
69:               sqls
70:             else
71:               super(table, op)
72:             end
73:           when :rename_column
74:             "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} RENAME TO #{quote_identifier(op[:new_name])}"
75:           when :set_column_null
76:             "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} SET#{' NOT' unless op[:null]} NULL"
77:           when :set_column_type
78:             if sch = schema(table)
79:               if cs = sch.each{|k, v| break v if k == op[:name]; nil}
80:                 cs = cs.dup
81:                 cs[:default] = cs[:ruby_default]
82:                 op = cs.merge!(op)
83:               end
84:             end
85:             sql = "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} #{type_literal(op)}"
86:             column_definition_order.each{|m| send(:"column_definition_#{m}_sql", sql, op)}
87:             sql
88:           else
89:             super(table, op)
90:           end
91:         end
commit_transaction(conn, opts={}) click to toggle source

If the :prepare option is given and we aren’t in a savepoint, prepare the transaction for a two-phase commit.

    # File lib/sequel/adapters/jdbc/h2.rb, line 50
50:         def commit_transaction(conn, opts={})
51:           if (s = opts[:prepare]) && _trans(conn)[:savepoint_level] <= 1
52:             log_connection_execute(conn, "PREPARE COMMIT #{s}")
53:           else
54:             super
55:           end
56:         end
connection_pool_default_options() click to toggle source

Default to a single connection for a memory database.

    # File lib/sequel/adapters/jdbc/h2.rb, line 94
94:         def connection_pool_default_options
95:           o = super
96:           uri == 'jdbc:h2:mem:' ? o.merge(:max_connections=>1) : o
97:         end
last_insert_id(conn, opts={}) click to toggle source

Use IDENTITY() to get the last inserted id.

     # File lib/sequel/adapters/jdbc/h2.rb, line 100
100:         def last_insert_id(conn, opts={})
101:           statement(conn) do |stmt|
102:             sql = 'SELECT IDENTITY();'
103:             rs = log_yield(sql){stmt.executeQuery(sql)}
104:             rs.next
105:             rs.getInt(1)
106:           end
107:         end
primary_key_index_re() click to toggle source
     # File lib/sequel/adapters/jdbc/h2.rb, line 109
109:         def primary_key_index_re
110:           PRIMARY_KEY_INDEX_RE
111:         end
schema_column_type(db_type) click to toggle source

Treat clob as string instead of blob

     # File lib/sequel/adapters/jdbc/h2.rb, line 114
114:         def schema_column_type(db_type)
115:           db_type == 'clob' ? :string : super
116:         end
type_literal_generic_bignum(column) click to toggle source

Use BIGINT IDENTITY for identity columns that use bigint, fixes the case where primary_key :column, :type=>Bignum is used.

     # File lib/sequel/adapters/jdbc/h2.rb, line 120
120:         def type_literal_generic_bignum(column)
121:           column[:identity] ? 'BIGINT IDENTITY' : super
122:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.