activerecord-jdbc-adapter 0.9.7-java → 1.0.0.beta1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/Manifest.txt +71 -38
- data/lib/active_record/connection_adapters/cachedb_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -661
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -13
- data/lib/activerecord-jdbc-adapter.rb +2 -2
- data/lib/arjdbc.rb +29 -0
- data/lib/arjdbc/cachedb.rb +3 -0
- data/lib/arjdbc/cachedb/adapter.rb +20 -0
- data/lib/arjdbc/cachedb/connection_methods.rb +10 -0
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_db2.rb → arjdbc/db2/adapter.rb} +1 -17
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/{jdbc_adapter/jdbc_derby.rb → arjdbc/derby/adapter.rb} +8 -26
- data/lib/arjdbc/derby/connection_methods.rb +18 -0
- data/lib/arjdbc/discover.rb +99 -0
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_firebird.rb → arjdbc/firebird/adapter.rb} +12 -16
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/arjdbc/h2/adapter.rb +15 -0
- data/lib/arjdbc/h2/connection_methods.rb +12 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_hsqldb.rb → arjdbc/hsqldb/adapter.rb} +6 -58
- data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_informix.rb → arjdbc/informix/adapter.rb} +6 -19
- data/lib/arjdbc/informix/connection_methods.rb +10 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/arjdbc/jdbc/adapter.rb +235 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +38 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +97 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
- data/lib/arjdbc/jdbc/core_ext.rb +24 -0
- data/lib/arjdbc/jdbc/discover.rb +18 -0
- data/lib/arjdbc/jdbc/driver.rb +44 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/{jdbc_adapter → arjdbc/jdbc}/jdbc.rake +0 -0
- data/lib/{jdbc_adapter → arjdbc/jdbc}/missing_functionality_helper.rb +5 -5
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/{jdbc_adapter → arjdbc/jdbc}/railtie.rb +1 -1
- data/lib/{jdbc_adapter → arjdbc/jdbc}/rake_tasks.rb +0 -0
- data/lib/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +119 -0
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_mimer.rb → arjdbc/mimer/adapter.rb} +16 -19
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_mssql.rb → arjdbc/mssql/adapter.rb} +19 -31
- data/lib/arjdbc/mssql/connection_methods.rb +13 -0
- data/lib/{jdbc_adapter → arjdbc/mssql}/tsql_helper.rb +1 -1
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +388 -0
- data/lib/arjdbc/mysql/connection_methods.rb +26 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_oracle.rb → arjdbc/oracle/adapter.rb} +9 -17
- data/lib/arjdbc/oracle/connection_methods.rb +11 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_postgre.rb → arjdbc/postgresql/adapter.rb} +7 -36
- data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_sqlite3.rb → arjdbc/sqlite3/adapter.rb} +106 -104
- data/lib/arjdbc/sqlite3/connection_methods.rb +33 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +46 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/jdbc_adapter.rb +2 -27
- data/lib/jdbc_adapter/version.rb +3 -5
- data/rails_generators/templates/config/initializers/jdbc.rb +1 -1
- data/rakelib/compile.rake +3 -2
- data/rakelib/package.rake +3 -3
- data/src/java/{jdbc_adapter/JdbcDerbySpec.java → arjdbc/derby/DerbyModule.java} +32 -32
- data/src/java/{jdbc_adapter/JdbcAdapterInternalService.java → arjdbc/jdbc/AdapterJavaService.java} +13 -7
- data/src/java/{jdbc_adapter → arjdbc/jdbc}/JdbcConnectionFactory.java +6 -6
- data/src/java/{jdbc_adapter → arjdbc/jdbc}/RubyJdbcConnection.java +91 -16
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/{jdbc_adapter → arjdbc/mssql}/MssqlRubyJdbcConnection.java +5 -2
- data/src/java/{jdbc_adapter/JdbcMySQLSpec.java → arjdbc/mysql/MySQLModule.java} +12 -12
- data/src/java/{jdbc_adapter/PostgresRubyJdbcConnection.java → arjdbc/postgresql/PostgresqlRubyJdbcConnection.java} +11 -9
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
- data/test/abstract_db_create.rb +4 -1
- data/test/activerecord/connection_adapters/type_conversion_test.rb +1 -1
- data/test/db/cachedb.rb +0 -0
- data/test/db/derby.rb +12 -14
- data/test/db/hsqldb.rb +3 -2
- data/test/db/jndi_config.rb +4 -4
- data/test/db/sqlite3.rb +2 -6
- data/test/db2_simple_test.rb +23 -0
- data/test/derby_migration_test.rb +50 -3
- data/test/jdbc_common.rb +1 -1
- data/test/jndi_callbacks_test.rb +1 -0
- data/test/postgres_nonseq_pkey_test.rb +0 -2
- data/test/postgres_schema_search_path_test.rb +0 -2
- data/test/simple.rb +3 -3
- data/test/sybase_jtds_simple_test.rb +22 -0
- metadata +82 -46
- data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +0 -26
- data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
- data/lib/jdbc_adapter/jdbc_cachedb.rb +0 -33
- data/lib/jdbc_adapter/jdbc_mysql.rb +0 -260
- data/lib/jdbc_adapter/jdbc_sybase.rb +0 -50
- data/src/java/jdbc_adapter/SQLBlock.java +0 -27
- data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +0 -41
- data/test/jdbc_adapter/jdbc_db2_test.rb +0 -26
- data/test/jdbc_adapter/jdbc_sybase_test.rb +0 -33
- data/test/minirunit.rb +0 -109
- data/test/minirunit/testConnect.rb +0 -14
- data/test/minirunit/testH2.rb +0 -73
- data/test/minirunit/testHsqldb.rb +0 -73
- data/test/minirunit/testLoadActiveRecord.rb +0 -3
- data/test/minirunit/testMysql.rb +0 -83
- data/test/minirunit/testRawSelect.rb +0 -24
data/lib/arjdbc/h2.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Base
|
3
|
+
class << self
|
4
|
+
def h2_connection(config)
|
5
|
+
config[:url] ||= "jdbc:h2:#{config[:database]}"
|
6
|
+
config[:driver] ||= "org.h2.Driver"
|
7
|
+
embedded_driver(config)
|
8
|
+
end
|
9
|
+
alias_method :jdbch2_connection, :h2_connection
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,33 +1,7 @@
|
|
1
|
-
module ::
|
2
|
-
module ActiveRecordExtensions
|
3
|
-
def hsqldb_connection(config)
|
4
|
-
require File.dirname(__FILE__) + "/../active_record/connection_adapters/hsqldb_adapter"
|
5
|
-
config[:url] ||= "jdbc:hsqldb:#{config[:database]}"
|
6
|
-
config[:driver] ||= "org.hsqldb.jdbcDriver"
|
7
|
-
embedded_driver(config)
|
8
|
-
end
|
9
|
-
|
10
|
-
def h2_connection(config)
|
11
|
-
require File.dirname(__FILE__) + "/../active_record/connection_adapters/h2_adapter"
|
12
|
-
config[:url] ||= "jdbc:h2:#{config[:database]}"
|
13
|
-
config[:driver] ||= "org.h2.Driver"
|
14
|
-
embedded_driver(config)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
1
|
+
module ::ArJdbc
|
18
2
|
module HSQLDB
|
19
|
-
def self.extended(mod)
|
20
|
-
mod.class.class_eval do
|
21
|
-
alias_chained_method :insert, :query_dirty, :insert
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.adapter_matcher(name, *)
|
26
|
-
name =~ /hsqldb/i ? self : false
|
27
|
-
end
|
28
|
-
|
29
3
|
def self.column_selector
|
30
|
-
[/hsqldb|\.h2\./i, lambda {|cfg,col| col.extend(::
|
4
|
+
[/hsqldb|\.h2\./i, lambda {|cfg,col| col.extend(::ArJdbc::HSQLDB::Column)}]
|
31
5
|
end
|
32
6
|
|
33
7
|
module Column
|
@@ -63,7 +37,7 @@ module ::JdbcSpec
|
|
63
37
|
end
|
64
38
|
|
65
39
|
def adapter_name #:nodoc:
|
66
|
-
|
40
|
+
'Hsqldb'
|
67
41
|
end
|
68
42
|
|
69
43
|
def modify_types(tp)
|
@@ -159,27 +133,13 @@ module ::JdbcSpec
|
|
159
133
|
execute "ALTER TABLE #{name} RENAME TO #{new_name}"
|
160
134
|
end
|
161
135
|
|
162
|
-
def
|
163
|
-
log(sql,name) do
|
164
|
-
@connection.execute_update(sql)
|
165
|
-
end
|
166
|
-
table = sql.split(" ", 4)[2]
|
167
|
-
id_value || last_insert_id(table, nil)
|
168
|
-
end
|
169
|
-
|
170
|
-
def last_insert_id(table, sequence_name)
|
136
|
+
def last_insert_id
|
171
137
|
Integer(select_value("CALL IDENTITY()"))
|
172
138
|
end
|
173
139
|
|
174
|
-
# Override normal #_execute: See Rubyforge #11567
|
175
140
|
def _execute(sql, name = nil)
|
176
|
-
|
177
|
-
|
178
|
-
elsif ::ActiveRecord::ConnectionAdapters::JdbcConnection::insert?(sql)
|
179
|
-
insert(sql, name)
|
180
|
-
else
|
181
|
-
@connection.execute_update(sql)
|
182
|
-
end
|
141
|
+
result = super
|
142
|
+
ActiveRecord::ConnectionAdapters::JdbcConnection::insert?(sql) ? last_insert_id : result
|
183
143
|
end
|
184
144
|
|
185
145
|
def add_limit_offset!(sql, options) #:nodoc:
|
@@ -206,16 +166,4 @@ module ::JdbcSpec
|
|
206
166
|
execute "DROP INDEX #{quote_column_name(index_name(table_name, options))}"
|
207
167
|
end
|
208
168
|
end
|
209
|
-
|
210
|
-
module H2
|
211
|
-
include HSQLDB
|
212
|
-
|
213
|
-
def self.adapter_matcher(name, *)
|
214
|
-
name =~ /\.h2\./i ? self : false
|
215
|
-
end
|
216
|
-
|
217
|
-
def h2_adapter
|
218
|
-
true
|
219
|
-
end
|
220
|
-
end
|
221
169
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Base
|
3
|
+
class << self
|
4
|
+
def hsqldb_connection(config)
|
5
|
+
require "arjdbc/hsqldb"
|
6
|
+
config[:url] ||= "jdbc:hsqldb:#{config[:database]}"
|
7
|
+
config[:driver] ||= "org.hsqldb.jdbcDriver"
|
8
|
+
embedded_driver(config)
|
9
|
+
end
|
10
|
+
|
11
|
+
alias_method :jdbchsqldb_connection, :hsqldb_connection
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -4,7 +4,7 @@ module ::ActiveRecord
|
|
4
4
|
|
5
5
|
private
|
6
6
|
def write_lobs
|
7
|
-
if connection.is_a?(
|
7
|
+
if connection.is_a?(ArJdbc::Informix)
|
8
8
|
self.class.columns.each do |c|
|
9
9
|
if [:text, :binary].include? c.type
|
10
10
|
value = self[c.name]
|
@@ -25,28 +25,15 @@ module ::ActiveRecord
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
module ::
|
29
|
-
module ActiveRecordExtensions
|
30
|
-
def informix_connection(config)
|
31
|
-
config[:port] ||= 9088
|
32
|
-
config[:url] ||= "jdbc:informix-sqli://#{config[:host]}:#{config[:port]}/#{config[:database]}:INFORMIXSERVER=#{config[:servername]}"
|
33
|
-
config[:driver] = 'com.informix.jdbc.IfxDriver'
|
34
|
-
jdbc_connection(config)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
28
|
+
module ::ArJdbc
|
38
29
|
module Informix
|
39
30
|
def self.extended(base)
|
40
31
|
@@db_major_version = base.select_one("SELECT dbinfo('version', 'major') version FROM systables WHERE tabid = 1")['version'].to_i
|
41
32
|
end
|
42
33
|
|
43
|
-
def self.adapter_matcher(name, *)
|
44
|
-
name =~ /informix/i ? self : false
|
45
|
-
end
|
46
|
-
|
47
34
|
def self.column_selector
|
48
35
|
[ /informix/i,
|
49
|
-
lambda { |cfg, column| column.extend(::
|
36
|
+
lambda { |cfg, column| column.extend(::ArJdbc::Informix::Column) } ]
|
50
37
|
end
|
51
38
|
|
52
39
|
module Column
|
@@ -123,12 +110,12 @@ module ::JdbcSpec
|
|
123
110
|
super(name, options)
|
124
111
|
execute("CREATE SEQUENCE #{name}_seq")
|
125
112
|
end
|
126
|
-
|
113
|
+
|
127
114
|
def rename_table(name, new_name)
|
128
115
|
execute("RENAME TABLE #{name} TO #{new_name}")
|
129
116
|
execute("RENAME SEQUENCE #{name}_seq TO #{new_name}_seq")
|
130
117
|
end
|
131
|
-
|
118
|
+
|
132
119
|
def drop_table(name)
|
133
120
|
super(name)
|
134
121
|
execute("DROP SEQUENCE #{name}_seq")
|
@@ -144,4 +131,4 @@ module ::JdbcSpec
|
|
144
131
|
execute(sql.gsub(/(!=|<>)\s*null/i, "IS NOT NULL").gsub(/=\s*null/i, "IS NULL"), name)
|
145
132
|
end
|
146
133
|
end # module Informix
|
147
|
-
end # module ::
|
134
|
+
end # module ::ArJdbc
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class ActiveRecord::Base
|
2
|
+
class << self
|
3
|
+
def informix_connection(config)
|
4
|
+
config[:port] ||= 9088
|
5
|
+
config[:url] ||= "jdbc:informix-sqli://#{config[:host]}:#{config[:port]}/#{config[:database]}:INFORMIXSERVER=#{config[:servername]}"
|
6
|
+
config[:driver] = 'com.informix.jdbc.IfxDriver'
|
7
|
+
jdbc_connection(config)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/arjdbc/jdbc.rb
ADDED
@@ -0,0 +1,235 @@
|
|
1
|
+
require 'active_record/version'
|
2
|
+
require 'active_record/connection_adapters/abstract_adapter'
|
3
|
+
require 'arjdbc/version'
|
4
|
+
require 'arjdbc/jdbc/require_driver'
|
5
|
+
require 'arjdbc/jdbc/connection_methods'
|
6
|
+
require 'arjdbc/jdbc/compatibility'
|
7
|
+
require 'arjdbc/jdbc/core_ext'
|
8
|
+
require 'arjdbc/jdbc/java'
|
9
|
+
require 'arjdbc/jdbc/type_converter'
|
10
|
+
require 'arjdbc/jdbc/driver'
|
11
|
+
require 'arjdbc/jdbc/column'
|
12
|
+
require 'arjdbc/jdbc/connection'
|
13
|
+
require 'arjdbc/jdbc/callbacks'
|
14
|
+
require 'arjdbc/jdbc/extension'
|
15
|
+
require 'bigdecimal'
|
16
|
+
|
17
|
+
module ActiveRecord
|
18
|
+
module ConnectionAdapters
|
19
|
+
class JdbcAdapter < AbstractAdapter
|
20
|
+
extend ShadowCoreMethods
|
21
|
+
include CompatibilityMethods if CompatibilityMethods.needed?(self)
|
22
|
+
include JdbcConnectionPoolCallbacks if JdbcConnectionPoolCallbacks.needed?
|
23
|
+
|
24
|
+
attr_reader :config
|
25
|
+
|
26
|
+
def initialize(connection, logger, config)
|
27
|
+
@config = config
|
28
|
+
spec = adapter_spec config
|
29
|
+
unless connection
|
30
|
+
connection_class = jdbc_connection_class spec
|
31
|
+
connection = connection_class.new config
|
32
|
+
end
|
33
|
+
super(connection, logger)
|
34
|
+
extend spec if spec
|
35
|
+
connection.adapter = self
|
36
|
+
JndiConnectionPoolCallbacks.prepare(self, connection)
|
37
|
+
end
|
38
|
+
|
39
|
+
def jdbc_connection_class(spec)
|
40
|
+
connection_class = spec.jdbc_connection_class if spec && spec.respond_to?(:jdbc_connection_class)
|
41
|
+
connection_class = ::ActiveRecord::ConnectionAdapters::JdbcConnection unless connection_class
|
42
|
+
connection_class
|
43
|
+
end
|
44
|
+
|
45
|
+
def jdbc_column_class
|
46
|
+
ActiveRecord::ConnectionAdapters::JdbcColumn
|
47
|
+
end
|
48
|
+
|
49
|
+
# Locate specialized adapter specification if one exists based on config data
|
50
|
+
def adapter_spec(config)
|
51
|
+
dialect = (config[:dialect] || config[:driver]).to_s
|
52
|
+
::ArJdbc.constants.map { |name| ::ArJdbc.const_get name }.each do |constant|
|
53
|
+
if constant.respond_to? :adapter_matcher
|
54
|
+
spec = constant.adapter_matcher(dialect, config)
|
55
|
+
return spec if spec
|
56
|
+
end
|
57
|
+
end
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def modify_types(tp)
|
62
|
+
tp
|
63
|
+
end
|
64
|
+
|
65
|
+
def adapter_name #:nodoc:
|
66
|
+
'JDBC'
|
67
|
+
end
|
68
|
+
|
69
|
+
def is_a?(klass) # :nodoc:
|
70
|
+
# This is to fake out current_adapter? conditional logic in AR tests
|
71
|
+
if Class === klass && klass.name =~ /#{adapter_name}Adapter$/i
|
72
|
+
true
|
73
|
+
else
|
74
|
+
super
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def supports_migrations?
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
def native_database_types #:nodoc:
|
83
|
+
@connection.native_database_types
|
84
|
+
end
|
85
|
+
|
86
|
+
def database_name #:nodoc:
|
87
|
+
@connection.database_name
|
88
|
+
end
|
89
|
+
|
90
|
+
def native_sql_to_type(tp)
|
91
|
+
if /^(.*?)\(([0-9]+)\)/ =~ tp
|
92
|
+
tname = $1
|
93
|
+
limit = $2.to_i
|
94
|
+
ntype = native_database_types
|
95
|
+
if ntype[:primary_key] == tp
|
96
|
+
return :primary_key,nil
|
97
|
+
else
|
98
|
+
ntype.each do |name,val|
|
99
|
+
if name == :primary_key
|
100
|
+
next
|
101
|
+
end
|
102
|
+
if val[:name].downcase == tname.downcase && (val[:limit].nil? || val[:limit].to_i == limit)
|
103
|
+
return name,limit
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
elsif /^(.*?)/ =~ tp
|
108
|
+
tname = $1
|
109
|
+
ntype = native_database_types
|
110
|
+
if ntype[:primary_key] == tp
|
111
|
+
return :primary_key,nil
|
112
|
+
else
|
113
|
+
ntype.each do |name,val|
|
114
|
+
if val[:name].downcase == tname.downcase && val[:limit].nil?
|
115
|
+
return name,nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
else
|
120
|
+
return :string,255
|
121
|
+
end
|
122
|
+
return nil,nil
|
123
|
+
end
|
124
|
+
|
125
|
+
def active?
|
126
|
+
@connection.active?
|
127
|
+
end
|
128
|
+
|
129
|
+
def reconnect!
|
130
|
+
@connection.reconnect!
|
131
|
+
@connection
|
132
|
+
end
|
133
|
+
|
134
|
+
def disconnect!
|
135
|
+
@connection.disconnect!
|
136
|
+
end
|
137
|
+
|
138
|
+
def execute(sql, name = nil)
|
139
|
+
if name == :skip_logging
|
140
|
+
_execute(sql)
|
141
|
+
else
|
142
|
+
log(sql, name) { _execute(sql) }
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# we need to do it this way, to allow Rails stupid tests to always work
|
147
|
+
# even if we define a new execute method. Instead of mixing in a new
|
148
|
+
# execute, an _execute should be mixed in.
|
149
|
+
def _execute(sql, name = nil)
|
150
|
+
@connection.execute(sql)
|
151
|
+
end
|
152
|
+
|
153
|
+
def jdbc_insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
|
154
|
+
insert_sql(sql, name, pk, id_value, sequence_name)
|
155
|
+
end
|
156
|
+
|
157
|
+
def jdbc_update(sql, name = nil) #:nodoc:
|
158
|
+
execute(sql, name)
|
159
|
+
end
|
160
|
+
def jdbc_select_all(sql, name = nil)
|
161
|
+
select(sql, name)
|
162
|
+
end
|
163
|
+
|
164
|
+
if ActiveRecord::VERSION::MAJOR < 3
|
165
|
+
# Allow query caching to work even when we override alias_method_chain'd methods
|
166
|
+
alias_chained_method :select_all, :query_cache, :jdbc_select_all
|
167
|
+
alias_chained_method :update, :query_dirty, :jdbc_update
|
168
|
+
alias_chained_method :insert, :query_dirty, :jdbc_insert
|
169
|
+
|
170
|
+
# Do we need this? Not in AR 3.
|
171
|
+
def select_one(sql, name = nil)
|
172
|
+
select(sql, name).first
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def select_rows(sql, name = nil)
|
177
|
+
rows = []
|
178
|
+
select(sql, name).each {|row| rows << row.values }
|
179
|
+
rows
|
180
|
+
end
|
181
|
+
|
182
|
+
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
|
183
|
+
id = execute(sql, name = nil)
|
184
|
+
id_value || id
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
def jdbc_columns(table_name, name = nil)
|
189
|
+
@connection.columns(table_name.to_s)
|
190
|
+
end
|
191
|
+
alias_chained_method :columns, :query_cache, :jdbc_columns
|
192
|
+
|
193
|
+
def tables(name = nil)
|
194
|
+
@connection.tables
|
195
|
+
end
|
196
|
+
|
197
|
+
def indexes(table_name, name = nil, schema_name = nil)
|
198
|
+
@connection.indexes(table_name, name, schema_name)
|
199
|
+
end
|
200
|
+
|
201
|
+
def begin_db_transaction
|
202
|
+
@connection.begin
|
203
|
+
end
|
204
|
+
|
205
|
+
def commit_db_transaction
|
206
|
+
@connection.commit
|
207
|
+
end
|
208
|
+
|
209
|
+
def rollback_db_transaction
|
210
|
+
@connection.rollback
|
211
|
+
end
|
212
|
+
|
213
|
+
def write_large_object(*args)
|
214
|
+
@connection.write_large_object(*args)
|
215
|
+
end
|
216
|
+
|
217
|
+
def pk_and_sequence_for(table)
|
218
|
+
key = primary_key(table)
|
219
|
+
[key, nil] if key
|
220
|
+
end
|
221
|
+
|
222
|
+
def primary_key(table)
|
223
|
+
primary_keys(table).first
|
224
|
+
end
|
225
|
+
|
226
|
+
def primary_keys(table)
|
227
|
+
@connection.primary_keys(table)
|
228
|
+
end
|
229
|
+
|
230
|
+
def select(*args)
|
231
|
+
execute(*args)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|