Class: ActiveRecord::ConnectionAdapters::JdbcAdapter
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#_execute(sql, name = nil) ⇒ Object
we need to do it this way, to allow Rails stupid tests to always work even if we define a new execute method.
-
#active? ⇒ Boolean
-
#adapter_name ⇒ Object
-
#adapter_spec(config) ⇒ Object
Locate specialized adapter specification if one exists based on config data.
-
#arel2_visitors ⇒ Object
-
#begin_db_transaction ⇒ Object
-
#commit_db_transaction ⇒ Object
-
#configure_arel2_visitors(config) ⇒ Object
-
#database_name ⇒ Object
-
#disconnect! ⇒ Object
-
#execute(sql, name = nil) ⇒ Object
-
#indexes(table_name, name = nil, schema_name = nil) ⇒ Object
-
#initialize(connection, logger, config) ⇒ JdbcAdapter
constructor
A new instance of JdbcAdapter.
-
#insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
-
#is_a?(klass) ⇒ Boolean
-
#jdbc_column_class ⇒ Object
-
#jdbc_columns(table_name, name = nil) ⇒ Object
-
#jdbc_connection ⇒ Object
Retrieve the raw java.sql.Connection object.
-
#jdbc_connection_class(spec) ⇒ Object
-
#jdbc_insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
-
#jdbc_select_all(sql, name = nil) ⇒ Object
-
#jdbc_update(sql, name = nil) ⇒ Object
-
#modify_types(tp) ⇒ Object
-
#native_database_types ⇒ Object
-
#native_sql_to_type(tp) ⇒ Object
-
#pk_and_sequence_for(table) ⇒ Object
-
#primary_key(table) ⇒ Object
-
#primary_keys(table) ⇒ Object
-
#reconnect! ⇒ Object
-
#rollback_db_transaction ⇒ Object
-
#select(*args) ⇒ Object
-
#select_one(sql, name = nil) ⇒ Object
Do we need this? Not in AR 3.
-
#select_rows(sql, name = nil) ⇒ Object
-
#supports_migrations? ⇒ Boolean
-
#table_exists?(name) ⇒ Boolean
-
#tables(name = nil) ⇒ Object
-
#write_large_object(*args) ⇒ Object
alias_chained_method
included, needed?, #on_checkin, #on_checkout
needed?, #quote_table_name
Constructor Details
#initialize(connection, logger, config) ⇒ JdbcAdapter
Returns a new instance of JdbcAdapter.
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 26
def initialize(connection, logger, config)
@config = config
spec = adapter_spec config
unless connection
connection_class = jdbc_connection_class spec
connection = connection_class.new config
end
super(connection, logger)
extend spec if spec
configure_arel2_visitors(config)
connection.adapter = self
JndiConnectionPoolCallbacks.prepare(self, connection)
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
24
25
26
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 24
def config
@config
end
|
Instance Method Details
#_execute(sql, name = nil) ⇒ Object
we need to do it this way, to allow Rails stupid tests to always work even if we define a new execute method. Instead of mixing in a new execute, an _execute should be mixed in.
190
191
192
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 190
def _execute(sql, name = nil)
@connection.execute(sql)
end
|
#active? ⇒ Boolean
166
167
168
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 166
def active?
@connection.active?
end
|
#adapter_name ⇒ Object
88
89
90
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 88
def adapter_name 'JDBC'
end
|
#adapter_spec(config) ⇒ Object
Locate specialized adapter specification if one exists based on config data
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
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 56
def adapter_spec(config)
2.times do
dialect = (config[:dialect] || config[:driver]).to_s
::ArJdbc.constants.map { |name| ::ArJdbc.const_get name }.each do |constant|
if constant.respond_to? :adapter_matcher
spec = constant.adapter_matcher(dialect, config)
return spec if spec
end
end
break unless config[:jndi] and !config[:dialect]
begin
conn = Java::javax.naming.InitialContext.new.lookup(config[:jndi]).getConnection
config[:dialect] = conn.getMetaData.getDatabaseProductName
if ::ArJdbc::Derby.adapter_matcher(config[:dialect], config)
config[:username] ||= conn.getMetaData.getUserName
end
rescue
conn.close if conn
end
end
nil
end
|
#arel2_visitors ⇒ Object
92
93
94
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 92
def arel2_visitors
{}
end
|
#begin_db_transaction ⇒ Object
243
244
245
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 243
def begin_db_transaction
@connection.begin
end
|
#commit_db_transaction ⇒ Object
247
248
249
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 247
def commit_db_transaction
@connection.commit
end
|
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 96
def configure_arel2_visitors(config)
if defined?(::Arel::Visitors::VISITORS)
visitors = ::Arel::Visitors::VISITORS
visitor = nil
arel2_visitors.each do |k,v|
visitor = v
visitors[k] = v
end
if visitor && config[:adapter] =~ /^(jdbc|jndi)$/
visitors[config[:adapter]] = visitor
end
end
end
|
#database_name ⇒ Object
127
128
129
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 127
def database_name @connection.database_name
end
|
#disconnect! ⇒ Object
175
176
177
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 175
def disconnect!
@connection.disconnect!
end
|
#execute(sql, name = nil) ⇒ Object
179
180
181
182
183
184
185
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 179
def execute(sql, name = nil)
if name == :skip_logging
_execute(sql)
else
log(sql, name) { _execute(sql) }
end
end
|
#indexes(table_name, name = nil, schema_name = nil) ⇒ Object
239
240
241
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 239
def indexes(table_name, name = nil, schema_name = nil)
@connection.indexes(table_name, name, schema_name)
end
|
#insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
221
222
223
224
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 221
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
id = execute(sql, name = nil)
id_value || id
end
|
#is_a?(klass) ⇒ Boolean
110
111
112
113
114
115
116
117
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 110
def is_a?(klass) if Class === klass && klass.name =~ /#{adapter_name}Adapter$/i
true
else
super
end
end
|
#jdbc_column_class ⇒ Object
#jdbc_columns(table_name, name = nil) ⇒ Object
226
227
228
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 226
def jdbc_columns(table_name, name = nil)
@connection.columns(table_name.to_s)
end
|
#jdbc_connection ⇒ Object
Retrieve the raw java.sql.Connection object.
51
52
53
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 51
def jdbc_connection
raw_connection.connection
end
|
#jdbc_connection_class(spec) ⇒ Object
40
41
42
43
44
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 40
def jdbc_connection_class(spec)
connection_class = spec.jdbc_connection_class if spec && spec.respond_to?(:jdbc_connection_class)
connection_class = ::ActiveRecord::ConnectionAdapters::JdbcConnection unless connection_class
connection_class
end
|
#jdbc_insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
194
195
196
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 194
def jdbc_insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
insert_sql(sql, name, pk, id_value, sequence_name)
end
|
#jdbc_select_all(sql, name = nil) ⇒ Object
201
202
203
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 201
def jdbc_select_all(sql, name = nil)
select(sql, name)
end
|
#jdbc_update(sql, name = nil) ⇒ Object
198
199
200
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 198
def jdbc_update(sql, name = nil) execute(sql, name)
end
|
#modify_types(tp) ⇒ Object
84
85
86
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 84
def modify_types(tp)
tp
end
|
#native_database_types ⇒ Object
123
124
125
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 123
def native_database_types @connection.native_database_types
end
|
#native_sql_to_type(tp) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 131
def native_sql_to_type(tp)
if /^(.*?)\(([0-9]+)\)/ =~ tp
tname = $1
limit = $2.to_i
ntype = native_database_types
if ntype[:primary_key] == tp
return :primary_key,nil
else
ntype.each do |name,val|
if name == :primary_key
next
end
if val[:name].downcase == tname.downcase && (val[:limit].nil? || val[:limit].to_i == limit)
return name,limit
end
end
end
elsif /^(.*?)/ =~ tp
tname = $1
ntype = native_database_types
if ntype[:primary_key] == tp
return :primary_key,nil
else
ntype.each do |name,val|
if val[:name].downcase == tname.downcase && val[:limit].nil?
return name,nil
end
end
end
else
return :string,255
end
return nil,nil
end
|
#pk_and_sequence_for(table) ⇒ Object
259
260
261
262
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 259
def pk_and_sequence_for(table)
key = primary_key(table)
[key, nil] if key
end
|
#primary_key(table) ⇒ Object
264
265
266
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 264
def primary_key(table)
primary_keys(table).first
end
|
#primary_keys(table) ⇒ Object
268
269
270
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 268
def primary_keys(table)
@connection.primary_keys(table)
end
|
#reconnect! ⇒ Object
170
171
172
173
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 170
def reconnect!
@connection.reconnect!
@connection
end
|
#rollback_db_transaction ⇒ Object
251
252
253
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 251
def rollback_db_transaction
@connection.rollback
end
|
#select(*args) ⇒ Object
272
273
274
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 272
def select(*args)
execute(*args)
end
|
#select_one(sql, name = nil) ⇒ Object
Do we need this? Not in AR 3.
211
212
213
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 211
def select_one(sql, name = nil)
select(sql, name).first
end
|
#select_rows(sql, name = nil) ⇒ Object
215
216
217
218
219
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 215
def select_rows(sql, name = nil)
rows = []
select(sql, name).each {|row| rows << row.values }
rows
end
|
#supports_migrations? ⇒ Boolean
119
120
121
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 119
def supports_migrations?
true
end
|
#table_exists?(name) ⇒ Boolean
235
236
237
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 235
def table_exists?(name)
jdbc_columns(name) rescue nil
end
|
#tables(name = nil) ⇒ Object
231
232
233
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 231
def tables(name = nil)
@connection.tables
end
|
#write_large_object(*args) ⇒ Object
255
256
257
|
# File 'lib/arjdbc/jdbc/adapter.rb', line 255
def write_large_object(*args)
@connection.write_large_object(*args)
end
|