kb-activerecord-jdbc-adapter 0.9.7.1-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/cachedb/adapter.rb +20 -0
- data/lib/arjdbc/cachedb/connection_methods.rb +10 -0
- data/lib/arjdbc/cachedb.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_db2.rb → arjdbc/db2/adapter.rb} +2 -17
- data/lib/arjdbc/db2.rb +2 -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/derby.rb +7 -0
- data/lib/arjdbc/discover.rb +99 -0
- data/lib/{jdbc_adapter/jdbc_firebird.rb → arjdbc/firebird/adapter.rb} +12 -16
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/arjdbc/h2/adapter.rb +15 -0
- data/lib/arjdbc/h2/connection_methods.rb +12 -0
- data/lib/arjdbc/h2.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/hsqldb.rb +4 -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/informix.rb +3 -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}/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/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +119 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_mimer.rb → arjdbc/mimer/adapter.rb} +16 -19
- data/lib/arjdbc/mimer.rb +2 -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/arjdbc/mssql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +388 -0
- data/lib/arjdbc/mysql/connection_methods.rb +26 -0
- data/lib/arjdbc/mysql.rb +4 -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/oracle.rb +3 -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/postgresql.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/sqlite3.rb +4 -0
- data/lib/arjdbc/sybase/adapter.rb +46 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/arjdbc.rb +29 -0
- data/lib/jdbc_adapter/version.rb +3 -5
- data/lib/jdbc_adapter.rb +2 -27
- 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 +81 -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/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/test/minirunit.rb +0 -109
- /data/lib/{jdbc_adapter → arjdbc/jdbc}/jdbc.rake +0 -0
- /data/lib/{jdbc_adapter → arjdbc/jdbc}/rake_tasks.rb +0 -0
- /data/lib/{jdbc_adapter → arjdbc/mssql}/tsql_helper.rb +0 -0
@@ -1,47 +1,13 @@
|
|
1
|
-
|
2
|
-
# Don't need to load native postgres adapter
|
3
|
-
$LOADED_FEATURES << "active_record/connection_adapters/sqlite3_adapter.rb"
|
1
|
+
require 'arjdbc/jdbc/missing_functionality_helper'
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def sqlite3_connection(config)
|
9
|
-
require File.dirname(__FILE__) + "/../active_record/connection_adapters/sqlite3_adapter"
|
10
|
-
|
11
|
-
parse_sqlite3_config!(config)
|
12
|
-
|
13
|
-
config[:url] ||= "jdbc:sqlite:#{config[:database]}"
|
14
|
-
config[:driver] ||= "org.sqlite.JDBC"
|
15
|
-
jdbc_connection(config)
|
16
|
-
end
|
17
|
-
|
18
|
-
def parse_sqlite3_config!(config)
|
19
|
-
config[:database] ||= config[:dbfile]
|
20
|
-
|
21
|
-
# Allow database path relative to RAILS_ROOT, but only if
|
22
|
-
# the database path is not the special path that tells
|
23
|
-
# Sqlite to build a database only in memory.
|
24
|
-
rails_root_defined = defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
|
25
|
-
if rails_root_defined && ':memory:' != config[:database]
|
26
|
-
rails_root = defined?(Rails.root) ? Rails.root : RAILS_ROOT
|
27
|
-
config[:database] = File.expand_path(config[:database], rails_root)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
3
|
+
module ActiveRecord::ConnectionAdapters
|
4
|
+
Sqlite3Adapter = Class.new(AbstractAdapter) unless const_defined?(:Sqlite3Adapter)
|
5
|
+
end
|
31
6
|
|
7
|
+
module ::ArJdbc
|
32
8
|
module SQLite3
|
33
|
-
def self.extended(base)
|
34
|
-
base.class.class_eval do
|
35
|
-
alias_chained_method :insert, :query_dirty, :insert
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.adapter_matcher(name, *)
|
40
|
-
name =~ /sqlite/i ? self : false
|
41
|
-
end
|
42
|
-
|
43
9
|
def self.column_selector
|
44
|
-
[/sqlite/i, lambda {|cfg,col| col.extend(::
|
10
|
+
[/sqlite/i, lambda {|cfg,col| col.extend(::ArJdbc::SQLite3::Column)}]
|
45
11
|
end
|
46
12
|
|
47
13
|
def self.jdbc_connection_class
|
@@ -57,12 +23,12 @@ module ::JdbcSpec
|
|
57
23
|
return nil if value.nil?
|
58
24
|
case type
|
59
25
|
when :string then value
|
60
|
-
when :integer then
|
26
|
+
when :integer then ArJdbc::SQLite3::Column.cast_to_integer(value)
|
61
27
|
when :primary_key then defined?(value.to_i) ? value.to_i : (value ? 1 : 0)
|
62
28
|
when :float then value.to_f
|
63
|
-
when :datetime then
|
64
|
-
when :date then
|
65
|
-
when :time then
|
29
|
+
when :datetime then ArJdbc::SQLite3::Column.cast_to_date_or_time(value)
|
30
|
+
when :date then ArJdbc::SQLite3::Column.cast_to_date_or_time(value)
|
31
|
+
when :time then ArJdbc::SQLite3::Column.cast_to_time(value)
|
66
32
|
when :decimal then self.class.value_to_decimal(value)
|
67
33
|
when :boolean then self.class.value_to_boolean(value)
|
68
34
|
else value
|
@@ -71,10 +37,10 @@ module ::JdbcSpec
|
|
71
37
|
|
72
38
|
def type_cast_code(var_name)
|
73
39
|
case type
|
74
|
-
when :integer then "
|
75
|
-
when :datetime then "
|
76
|
-
when :date then "
|
77
|
-
when :time then "
|
40
|
+
when :integer then "ArJdbc::SQLite3::Column.cast_to_integer(#{var_name})"
|
41
|
+
when :datetime then "ArJdbc::SQLite3::Column.cast_to_date_or_time(#{var_name})"
|
42
|
+
when :date then "ArJdbc::SQLite3::Column.cast_to_date_or_time(#{var_name})"
|
43
|
+
when :time then "ArJdbc::SQLite3::Column.cast_to_time(#{var_name})"
|
78
44
|
else
|
79
45
|
super
|
80
46
|
end
|
@@ -98,11 +64,11 @@ module ::JdbcSpec
|
|
98
64
|
|
99
65
|
def extract_precision(sql_type)
|
100
66
|
case sql_type
|
101
|
-
when /^(real)\((\d+)(,\d+)?\)/i then $2.to_i
|
67
|
+
when /^(real)\((\d+)(,\d+)?\)/i then $2.to_i
|
102
68
|
else super
|
103
|
-
end
|
69
|
+
end
|
104
70
|
end
|
105
|
-
|
71
|
+
|
106
72
|
def extract_scale(sql_type)
|
107
73
|
case sql_type
|
108
74
|
when /^(real)\((\d+)\)/i then 0
|
@@ -190,14 +156,7 @@ module ::JdbcSpec
|
|
190
156
|
end
|
191
157
|
|
192
158
|
def quote_column_name(name) #:nodoc:
|
193
|
-
name
|
194
|
-
# Did not find reference on values needing quoting, but these
|
195
|
-
# happen in AR unit tests
|
196
|
-
if name == "references" || name =~ /-/
|
197
|
-
%Q("#{name}")
|
198
|
-
else
|
199
|
-
name
|
200
|
-
end
|
159
|
+
%Q("#{name}")
|
201
160
|
end
|
202
161
|
|
203
162
|
def quote_string(str)
|
@@ -262,23 +221,13 @@ module ::JdbcSpec
|
|
262
221
|
execute "ALTER TABLE #{name} RENAME TO #{new_name}"
|
263
222
|
end
|
264
223
|
|
265
|
-
def
|
266
|
-
|
267
|
-
|
268
|
-
end
|
269
|
-
table = sql.split(" ", 4)[2]
|
270
|
-
id_value || last_insert_id(table, nil)
|
271
|
-
end
|
272
|
-
|
273
|
-
def last_insert_id(table, sequence_name)
|
274
|
-
Integer(select_value("SELECT SEQ FROM SQLITE_SEQUENCE WHERE NAME = '#{table}'"))
|
224
|
+
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc:
|
225
|
+
@connection.execute_update(sql)
|
226
|
+
id_value || last_insert_id
|
275
227
|
end
|
276
228
|
|
277
|
-
def
|
278
|
-
|
279
|
-
sql << " LIMIT #{options[:limit]}"
|
280
|
-
sql << " OFFSET #{options[:offset]}" if options[:offset]
|
281
|
-
end
|
229
|
+
def last_insert_id
|
230
|
+
Integer(select_value("SELECT last_insert_rowid()"))
|
282
231
|
end
|
283
232
|
|
284
233
|
def tables(name = nil) #:nodoc:
|
@@ -304,11 +253,13 @@ module ::JdbcSpec
|
|
304
253
|
name = row[0]
|
305
254
|
index_sql = row[1]
|
306
255
|
unique = (index_sql =~ /unique/i)
|
307
|
-
cols = index_sql.match(/\((.*)\)/)[1].gsub(/,/,' ').split
|
256
|
+
cols = index_sql.match(/\((.*)\)/)[1].gsub(/,/,' ').split.map do |c|
|
257
|
+
match = /^"(.+)"$/.match(c); match ? match[1] : c
|
258
|
+
end
|
308
259
|
::ActiveRecord::ConnectionAdapters::IndexDefinition.new(table_name, name, unique, cols)
|
309
260
|
end
|
310
261
|
end
|
311
|
-
|
262
|
+
|
312
263
|
def primary_key(table_name) #:nodoc:
|
313
264
|
column = table_structure(table_name).find {|field| field['pk'].to_i == 1}
|
314
265
|
column ? column['name'] : nil
|
@@ -319,14 +270,10 @@ module ::JdbcSpec
|
|
319
270
|
end
|
320
271
|
|
321
272
|
def _execute(sql, name = nil)
|
322
|
-
|
323
|
-
|
324
|
-
else
|
325
|
-
affected_rows = @connection.execute_update(sql)
|
326
|
-
ActiveRecord::ConnectionAdapters::JdbcConnection::insert?(sql) ? last_insert_id(sql.split(" ", 4)[2], nil) : affected_rows
|
327
|
-
end
|
273
|
+
result = super
|
274
|
+
ActiveRecord::ConnectionAdapters::JdbcConnection::insert?(sql) ? last_insert_id : result
|
328
275
|
end
|
329
|
-
|
276
|
+
|
330
277
|
def select(sql, name=nil)
|
331
278
|
execute(sql, name).map do |row|
|
332
279
|
record = {}
|
@@ -338,49 +285,104 @@ module ::JdbcSpec
|
|
338
285
|
record
|
339
286
|
end
|
340
287
|
end
|
341
|
-
|
288
|
+
|
342
289
|
def table_structure(table_name)
|
343
290
|
structure = @connection.execute_query("PRAGMA table_info(#{quote_table_name(table_name)})")
|
344
291
|
raise ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'" if structure.empty?
|
345
292
|
structure
|
346
293
|
end
|
347
|
-
|
348
|
-
def columns(table_name, name = nil) #:nodoc:
|
294
|
+
|
295
|
+
def columns(table_name, name = nil) #:nodoc:
|
349
296
|
table_structure(table_name).map do |field|
|
350
297
|
::ActiveRecord::ConnectionAdapters::JdbcColumn.new(@config, field['name'], field['dflt_value'], field['type'], field['notnull'] == 0)
|
351
298
|
end
|
352
299
|
end
|
353
|
-
|
300
|
+
|
354
301
|
# SELECT ... FOR UPDATE is redundant since the table is locked.
|
355
302
|
def add_lock!(sql, options) #:nodoc:
|
356
303
|
sql
|
357
304
|
end
|
358
|
-
|
305
|
+
|
359
306
|
protected
|
360
|
-
|
307
|
+
include ArJdbc::MissingFunctionalityHelper
|
308
|
+
|
309
|
+
def translate_exception(exception, message)
|
310
|
+
case exception.message
|
311
|
+
when /column(s)? .* (is|are) not unique/
|
312
|
+
ActiveRecord::RecordNotUnique.new(message, exception)
|
313
|
+
else
|
314
|
+
super
|
315
|
+
end
|
316
|
+
end
|
361
317
|
end
|
362
318
|
end
|
363
319
|
|
364
|
-
module ActiveRecord
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
320
|
+
module ActiveRecord::ConnectionAdapters
|
321
|
+
class SQLiteColumn < JdbcColumn
|
322
|
+
include ArJdbc::SQLite3::Column
|
323
|
+
|
324
|
+
def initialize(name, *args)
|
325
|
+
if Hash === name
|
326
|
+
super
|
327
|
+
else
|
328
|
+
super(nil, name, *args)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
def call_discovered_column_callbacks(*)
|
333
|
+
end
|
334
|
+
|
335
|
+
def self.string_to_binary(value)
|
336
|
+
value.gsub(/\0|%/n) do |b|
|
337
|
+
case b
|
338
|
+
when "\0" then "%00"
|
339
|
+
when "\%" then "%25"
|
373
340
|
end
|
374
341
|
end
|
342
|
+
end
|
375
343
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
end
|
344
|
+
def self.binary_to_string(value)
|
345
|
+
value.gsub(/%00|%25/n) do |b|
|
346
|
+
case b
|
347
|
+
when "%00" then "\0"
|
348
|
+
when "%25" then "%"
|
382
349
|
end
|
383
350
|
end
|
384
351
|
end
|
352
|
+
|
353
|
+
def self.cast_to_integer(value)
|
354
|
+
return nil if value =~ /NULL/ or value.to_s.empty? or value.nil?
|
355
|
+
return (value.to_i) ? value.to_i : (value ? 1 : 0)
|
356
|
+
end
|
357
|
+
|
358
|
+
def self.cast_to_date_or_time(value)
|
359
|
+
return value if value.is_a? Date
|
360
|
+
return nil if value.blank?
|
361
|
+
guess_date_or_time((value.is_a? Time) ? value : cast_to_time(value))
|
362
|
+
end
|
363
|
+
|
364
|
+
def self.cast_to_time(value)
|
365
|
+
return value if value.is_a? Time
|
366
|
+
time_array = ParseDate.parsedate value
|
367
|
+
time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
|
368
|
+
Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil
|
369
|
+
end
|
370
|
+
|
371
|
+
def self.guess_date_or_time(value)
|
372
|
+
(value.hour == 0 and value.min == 0 and value.sec == 0) ?
|
373
|
+
Date.new(value.year, value.month, value.day) : value
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
class SQLite3Adapter < JdbcAdapter
|
378
|
+
include ArJdbc::SQLite3
|
379
|
+
|
380
|
+
def adapter_spec(config)
|
381
|
+
# return nil to avoid extending ArJdbc::SQLite3, which we've already done
|
382
|
+
end
|
383
|
+
|
384
|
+
def jdbc_column_class
|
385
|
+
ActiveRecord::ConnectionAdapters::SQLiteColumn
|
386
|
+
end
|
385
387
|
end
|
386
388
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Don't need to load native sqlite3 adapter
|
2
|
+
$LOADED_FEATURES << "active_record/connection_adapters/sqlite_adapter.rb"
|
3
|
+
$LOADED_FEATURES << "active_record/connection_adapters/sqlite3_adapter.rb"
|
4
|
+
|
5
|
+
class ActiveRecord::Base
|
6
|
+
class << self
|
7
|
+
def sqlite3_connection(config)
|
8
|
+
require "arjdbc/sqlite3"
|
9
|
+
|
10
|
+
parse_sqlite3_config!(config)
|
11
|
+
|
12
|
+
config[:url] ||= "jdbc:sqlite:#{config[:database]}"
|
13
|
+
config[:driver] ||= "org.sqlite.JDBC"
|
14
|
+
config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter
|
15
|
+
jdbc_connection(config)
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_sqlite3_config!(config)
|
19
|
+
config[:database] ||= config[:dbfile]
|
20
|
+
|
21
|
+
# Allow database path relative to RAILS_ROOT, but only if
|
22
|
+
# the database path is not the special path that tells
|
23
|
+
# Sqlite to build a database only in memory.
|
24
|
+
rails_root_defined = defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
|
25
|
+
if rails_root_defined && ':memory:' != config[:database]
|
26
|
+
rails_root = defined?(Rails.root) ? Rails.root : RAILS_ROOT
|
27
|
+
config[:database] = File.expand_path(config[:database], rails_root)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
alias_method :jdbcsqlite3_connection, :sqlite3_connection
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module Sybase
|
3
|
+
def add_limit_offset!(sql, options) # :nodoc:
|
4
|
+
@limit = options[:limit]
|
5
|
+
@offset = options[:offset]
|
6
|
+
if use_temp_table?
|
7
|
+
# Use temp table to hack offset with Sybase
|
8
|
+
sql.sub!(/ FROM /i, ' INTO #artemp FROM ')
|
9
|
+
elsif zero_limit?
|
10
|
+
# "SET ROWCOUNT 0" turns off limits, so we havesy
|
11
|
+
# to use a cheap trick.
|
12
|
+
if sql =~ /WHERE/i
|
13
|
+
sql.sub!(/WHERE/i, 'WHERE 1 = 2 AND ')
|
14
|
+
elsif sql =~ /ORDER\s+BY/i
|
15
|
+
sql.sub!(/ORDER\s+BY/i, 'WHERE 1 = 2 ORDER BY')
|
16
|
+
else
|
17
|
+
sql << 'WHERE 1 = 2'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# If limit is not set at all, we can ignore offset;
|
23
|
+
# if limit *is* set but offset is zero, use normal select
|
24
|
+
# with simple SET ROWCOUNT. Thus, only use the temp table
|
25
|
+
# if limit is set and offset > 0.
|
26
|
+
def use_temp_table?
|
27
|
+
!@limit.nil? && !@offset.nil? && @offset > 0
|
28
|
+
end
|
29
|
+
|
30
|
+
def zero_limit?
|
31
|
+
!@limit.nil? && @limit == 0
|
32
|
+
end
|
33
|
+
|
34
|
+
def modify_types(tp) #:nodoc:
|
35
|
+
tp[:primary_key] = "NUMERIC(22,0) IDENTITY PRIMARY KEY"
|
36
|
+
tp[:integer][:limit] = nil
|
37
|
+
tp[:boolean] = {:name => "bit"}
|
38
|
+
tp[:binary] = {:name => "image"}
|
39
|
+
tp
|
40
|
+
end
|
41
|
+
|
42
|
+
def remove_index(table_name, options = {})
|
43
|
+
execute "DROP INDEX #{table_name}.#{index_name(table_name, options)}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/arjdbc.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
if defined?(JRUBY_VERSION)
|
2
|
+
begin
|
3
|
+
tried_gem ||= false
|
4
|
+
require 'active_record/version'
|
5
|
+
rescue LoadError
|
6
|
+
raise if tried_gem
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'activerecord'
|
9
|
+
tried_gem = true
|
10
|
+
retry
|
11
|
+
end
|
12
|
+
if ActiveRecord::VERSION::MAJOR < 2
|
13
|
+
if defined?(RAILS_CONNECTION_ADAPTERS)
|
14
|
+
RAILS_CONNECTION_ADAPTERS << %q(jdbc)
|
15
|
+
else
|
16
|
+
RAILS_CONNECTION_ADAPTERS = %w(jdbc)
|
17
|
+
end
|
18
|
+
if ActiveRecord::VERSION::MAJOR == 1 && ActiveRecord::VERSION::MINOR == 14
|
19
|
+
require 'arjdbc/jdbc'
|
20
|
+
end
|
21
|
+
else
|
22
|
+
require 'active_record'
|
23
|
+
require 'arjdbc/jdbc'
|
24
|
+
end
|
25
|
+
else
|
26
|
+
warn "ActiveRecord-JDBC is for use with JRuby only"
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'arjdbc/version'
|
data/lib/jdbc_adapter/version.rb
CHANGED
data/lib/jdbc_adapter.rb
CHANGED
@@ -1,27 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
tried_gem ||= false
|
4
|
-
require 'active_record/version'
|
5
|
-
rescue LoadError
|
6
|
-
raise if tried_gem
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'activerecord'
|
9
|
-
tried_gem = true
|
10
|
-
retry
|
11
|
-
end
|
12
|
-
if ActiveRecord::VERSION::MAJOR < 2
|
13
|
-
if defined?(RAILS_CONNECTION_ADAPTERS)
|
14
|
-
RAILS_CONNECTION_ADAPTERS << %q(jdbc)
|
15
|
-
else
|
16
|
-
RAILS_CONNECTION_ADAPTERS = %w(jdbc)
|
17
|
-
end
|
18
|
-
if ActiveRecord::VERSION::MAJOR == 1 && ActiveRecord::VERSION::MINOR == 14
|
19
|
-
require 'active_record/connection_adapters/jdbc_adapter'
|
20
|
-
end
|
21
|
-
else
|
22
|
-
require 'active_record'
|
23
|
-
require 'active_record/connection_adapters/jdbc_adapter'
|
24
|
-
end
|
25
|
-
else
|
26
|
-
warn "ActiveRecord-JDBC is for use with JRuby only"
|
27
|
-
end
|
1
|
+
warn "DEPRECATED: require 'arjdbc' instead of 'jdbc_adapter'."
|
2
|
+
require 'arjdbc'
|
data/rakelib/compile.rake
CHANGED
@@ -12,12 +12,13 @@ def java_classpath_arg # myriad of ways to discover JRuby classpath
|
|
12
12
|
jruby_cpath ? "-cp \"#{jruby_cpath}\"" : ""
|
13
13
|
end
|
14
14
|
|
15
|
+
jar_name = File.join(*%w(lib arjdbc jdbc adapter_java.jar))
|
16
|
+
|
15
17
|
desc "Compile the native Java code."
|
16
18
|
task :java_compile do
|
17
19
|
pkg_classes = File.join(*%w(pkg classes))
|
18
|
-
jar_name = File.join(*%w(lib jdbc_adapter jdbc_adapter_internal.jar))
|
19
20
|
mkdir_p pkg_classes
|
20
21
|
sh "javac -target 1.5 -source 1.5 -d pkg/classes #{java_classpath_arg} #{FileList['src/java/**/*.java'].join(' ')}"
|
21
22
|
sh "jar cf #{jar_name} -C #{pkg_classes} ."
|
22
23
|
end
|
23
|
-
file
|
24
|
+
file jar_name => :java_compile
|
data/rakelib/package.rake
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt",
|
2
|
-
"Rakefile", "LICENSE.txt", "lib/**/*.rb", "lib/
|
2
|
+
"Rakefile", "LICENSE.txt", "lib/**/*.rb", "lib/arjdbc/jdbc/adapter_java.jar", "test/**/*.rb",
|
3
3
|
"lib/**/*.rake", "src/**/*.java", "rakelib/*.rake", "rails_generators/**/*"]
|
4
4
|
|
5
5
|
file "Manifest.txt" => :manifest
|
@@ -8,13 +8,13 @@ task :manifest do
|
|
8
8
|
end
|
9
9
|
Rake::Task['manifest'].invoke # Always regen manifest, so Hoe has up-to-date list of files
|
10
10
|
|
11
|
-
require File.dirname(__FILE__) + "/../lib/
|
11
|
+
require File.dirname(__FILE__) + "/../lib/arjdbc/version"
|
12
12
|
begin
|
13
13
|
require 'hoe'
|
14
14
|
Hoe.plugin :gemcutter
|
15
15
|
hoe = Hoe.spec("activerecord-jdbc-adapter") do |p|
|
16
16
|
p.name = %q{kb-activerecord-jdbc-adapter}
|
17
|
-
p.version =
|
17
|
+
p.version = ArJdbc::Version::VERSION
|
18
18
|
p.spec_extras[:platform] = Gem::Platform.new("java")
|
19
19
|
p.spec_extras[:files] = MANIFEST
|
20
20
|
p.rubyforge_name = "jruby-extras"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/***** BEGIN LICENSE BLOCK *****
|
2
|
-
* Copyright (c) 2006-2007 Nick Sieger <nick@nicksieger.com>
|
2
|
+
* Copyright (c) 2006-2007, 2010 Nick Sieger <nick@nicksieger.com>
|
3
3
|
* Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
|
4
|
-
*
|
4
|
+
*
|
5
5
|
* Permission is hereby granted, free of charge, to any person obtaining
|
6
6
|
* a copy of this software and associated documentation files (the
|
7
7
|
* "Software"), to deal in the Software without restriction, including
|
@@ -9,10 +9,10 @@
|
|
9
9
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
10
10
|
* permit persons to whom the Software is furnished to do so, subject to
|
11
11
|
* the following conditions:
|
12
|
-
*
|
12
|
+
*
|
13
13
|
* The above copyright notice and this permission notice shall be
|
14
14
|
* included in all copies or substantial portions of the Software.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
17
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
18
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -22,33 +22,33 @@
|
|
22
22
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
23
|
***** END LICENSE BLOCK *****/
|
24
24
|
|
25
|
-
package
|
25
|
+
package arjdbc.derby;
|
26
|
+
|
27
|
+
import java.sql.SQLException;
|
28
|
+
|
29
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
26
30
|
|
27
31
|
import org.jruby.Ruby;
|
28
|
-
import org.jruby.
|
29
|
-
import org.jruby.RubyString;
|
30
|
-
import org.jruby.RubyFloat;
|
31
|
-
import org.jruby.RubyFixnum;
|
32
|
+
import org.jruby.RubyBigDecimal;
|
32
33
|
import org.jruby.RubyBignum;
|
33
34
|
import org.jruby.RubyBoolean;
|
34
|
-
import org.jruby.
|
35
|
-
import org.jruby.
|
35
|
+
import org.jruby.RubyFixnum;
|
36
|
+
import org.jruby.RubyFloat;
|
37
|
+
import org.jruby.RubyModule;
|
36
38
|
import org.jruby.RubyNumeric;
|
37
|
-
|
38
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
39
|
-
|
40
|
-
import org.jruby.util.ByteList;
|
41
|
-
|
42
|
-
import java.sql.SQLException;
|
43
39
|
import org.jruby.RubyObjectAdapter;
|
40
|
+
import org.jruby.RubyRange;
|
41
|
+
import org.jruby.RubyString;
|
44
42
|
import org.jruby.anno.JRubyMethod;
|
45
43
|
import org.jruby.runtime.ThreadContext;
|
44
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
45
|
+
import org.jruby.util.ByteList;
|
46
46
|
|
47
|
-
public class
|
47
|
+
public class DerbyModule {
|
48
48
|
private static RubyObjectAdapter rubyApi;
|
49
|
-
public static void load(RubyModule
|
50
|
-
RubyModule derby =
|
51
|
-
derby.defineAnnotatedMethods(
|
49
|
+
public static void load(RubyModule arJdbc, RubyObjectAdapter adapter) {
|
50
|
+
RubyModule derby = arJdbc.defineModuleUnder("Derby");
|
51
|
+
derby.defineAnnotatedMethods(DerbyModule.class);
|
52
52
|
RubyModule column = derby.defineModuleUnder("Column");
|
53
53
|
column.defineAnnotatedMethods(Column.class);
|
54
54
|
rubyApi = adapter;
|
@@ -131,7 +131,7 @@ public class JdbcDerbySpec {
|
|
131
131
|
return quote_string_with_surround(runtime, "'", RubyString.objAsString(context, value), "'");
|
132
132
|
}
|
133
133
|
}
|
134
|
-
}
|
134
|
+
}
|
135
135
|
return super_quote(context, recv, runtime, value, runtime.getNil());
|
136
136
|
}
|
137
137
|
|
@@ -141,25 +141,25 @@ public class JdbcDerbySpec {
|
|
141
141
|
if (value.respondsTo("quoted_id")) {
|
142
142
|
return rubyApi.callMethod(value, "quoted_id");
|
143
143
|
}
|
144
|
-
|
144
|
+
|
145
145
|
IRubyObject type = (col.isNil()) ? col : rubyApi.callMethod(col, "type");
|
146
|
-
RubyModule multibyteChars = (RubyModule)
|
146
|
+
RubyModule multibyteChars = (RubyModule)
|
147
147
|
((RubyModule) ((RubyModule) runtime.getModule("ActiveSupport")).getConstant("Multibyte")).getConstantAt("Chars");
|
148
148
|
if (value instanceof RubyString || rubyApi.isKindOf(value, multibyteChars)) {
|
149
149
|
RubyString svalue = RubyString.objAsString(context, value);
|
150
150
|
if (type == runtime.newSymbol("binary") && col.getType().respondsTo("string_to_binary")) {
|
151
|
-
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(col.getType(), "string_to_binary", svalue)), "'");
|
151
|
+
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(col.getType(), "string_to_binary", svalue)), "'");
|
152
152
|
} else if (type == runtime.newSymbol("integer") || type == runtime.newSymbol("float")) {
|
153
153
|
return RubyString.objAsString(context, ((type == runtime.newSymbol("integer")) ?
|
154
|
-
rubyApi.callMethod(svalue, "to_i") :
|
154
|
+
rubyApi.callMethod(svalue, "to_i") :
|
155
155
|
rubyApi.callMethod(svalue, "to_f")));
|
156
156
|
} else {
|
157
|
-
return quote_string_with_surround(runtime, "'", svalue, "'");
|
157
|
+
return quote_string_with_surround(runtime, "'", svalue, "'");
|
158
158
|
}
|
159
159
|
} else if (value.isNil()) {
|
160
160
|
return runtime.newString(NULL);
|
161
161
|
} else if (value instanceof RubyBoolean) {
|
162
|
-
return (value.isTrue() ?
|
162
|
+
return (value.isTrue() ?
|
163
163
|
(type == runtime.newSymbol(":integer")) ? runtime.newString("1") : rubyApi.callMethod(recv, "quoted_true") :
|
164
164
|
(type == runtime.newSymbol(":integer")) ? runtime.newString("0") : rubyApi.callMethod(recv, "quoted_false"));
|
165
165
|
} else if((value instanceof RubyFloat) || (value instanceof RubyFixnum) || (value instanceof RubyBignum)) {
|
@@ -167,7 +167,7 @@ public class JdbcDerbySpec {
|
|
167
167
|
} else if(value instanceof RubyBigDecimal) {
|
168
168
|
return rubyApi.callMethod(value, "to_s", runtime.newString("F"));
|
169
169
|
} else if (rubyApi.callMethod(value, "acts_like?", runtime.newString("date")).isTrue() || rubyApi.callMethod(value, "acts_like?", runtime.newString("time")).isTrue()) {
|
170
|
-
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(recv, "quoted_date", value)), "'");
|
170
|
+
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(recv, "quoted_date", value)), "'");
|
171
171
|
} else {
|
172
172
|
return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(value, "to_yaml")), "'");
|
173
173
|
}
|
@@ -231,14 +231,14 @@ public class JdbcDerbySpec {
|
|
231
231
|
public static IRubyObject quote_string(IRubyObject recv, IRubyObject string) {
|
232
232
|
boolean replacementFound = false;
|
233
233
|
ByteList bl = ((RubyString) string).getByteList();
|
234
|
-
|
234
|
+
|
235
235
|
for(int i = bl.begin; i < bl.begin + bl.realSize; i++) {
|
236
236
|
switch (bl.bytes[i]) {
|
237
237
|
case '\'': break;
|
238
238
|
default: continue;
|
239
239
|
}
|
240
|
-
|
241
|
-
// On first replacement allocate a different bytelist so we don't manip original
|
240
|
+
|
241
|
+
// On first replacement allocate a different bytelist so we don't manip original
|
242
242
|
if(!replacementFound) {
|
243
243
|
i-= bl.begin;
|
244
244
|
bl = new ByteList(bl);
|