activerecord-jdbc-adapter 1.3.0.beta1 → 1.3.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +12 -11
- data/.travis.yml +36 -7
- data/Appraisals +3 -3
- data/Gemfile +1 -1
- data/Gemfile.lock +13 -6
- data/History.txt +64 -0
- data/README.md +8 -1
- data/Rakefile +3 -1
- data/gemfiles/rails23.gemfile +1 -1
- data/gemfiles/rails23.gemfile.lock +6 -5
- data/gemfiles/rails30.gemfile +1 -1
- data/gemfiles/rails30.gemfile.lock +7 -6
- data/gemfiles/rails31.gemfile +1 -1
- data/gemfiles/rails31.gemfile.lock +6 -5
- data/gemfiles/rails32.gemfile +1 -1
- data/gemfiles/rails32.gemfile.lock +6 -5
- data/gemfiles/rails40.gemfile +2 -4
- data/gemfiles/rails40.gemfile.lock +37 -51
- data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +1 -1
- data/lib/arel/visitors/db2.rb +5 -1
- data/lib/arel/visitors/hsqldb.rb +1 -0
- data/lib/arel/visitors/sql_server.rb +55 -13
- data/lib/arjdbc/db2/adapter.rb +197 -227
- data/lib/arjdbc/db2/as400.rb +124 -0
- data/lib/arjdbc/db2/connection_methods.rb +20 -1
- data/lib/arjdbc/derby/adapter.rb +17 -85
- data/lib/arjdbc/derby/connection_methods.rb +2 -1
- data/lib/arjdbc/discover.rb +55 -47
- data/lib/arjdbc/h2/adapter.rb +52 -18
- data/lib/arjdbc/h2/connection_methods.rb +10 -2
- data/lib/arjdbc/hsqldb/adapter.rb +33 -9
- data/lib/arjdbc/hsqldb/connection_methods.rb +10 -2
- data/lib/arjdbc/informix.rb +2 -1
- data/lib/arjdbc/jdbc.rb +5 -1
- data/lib/arjdbc/jdbc/adapter.rb +167 -89
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +46 -0
- data/lib/arjdbc/jdbc/base_ext.rb +25 -3
- data/lib/arjdbc/jdbc/callbacks.rb +9 -8
- data/lib/arjdbc/jdbc/column.rb +8 -20
- data/lib/arjdbc/jdbc/connection.rb +69 -80
- data/lib/arjdbc/jdbc/extension.rb +6 -8
- data/lib/arjdbc/jdbc/jdbc.rake +3 -141
- data/lib/arjdbc/jdbc/rake_tasks.rb +3 -10
- data/lib/arjdbc/mssql/adapter.rb +108 -34
- data/lib/arjdbc/mssql/connection_methods.rb +3 -1
- data/lib/arjdbc/mssql/limit_helpers.rb +3 -2
- data/lib/arjdbc/mssql/lock_helpers.rb +5 -1
- data/lib/arjdbc/mysql/adapter.rb +127 -70
- data/lib/arjdbc/mysql/connection_methods.rb +5 -2
- data/lib/arjdbc/oracle/adapter.rb +124 -94
- data/lib/arjdbc/oracle/connection_methods.rb +2 -1
- data/lib/arjdbc/postgresql/adapter.rb +99 -67
- data/lib/arjdbc/postgresql/column_cast.rb +3 -5
- data/lib/arjdbc/postgresql/connection_methods.rb +6 -6
- data/lib/arjdbc/railtie.rb +3 -1
- data/lib/arjdbc/sqlite3/adapter.rb +60 -43
- data/lib/arjdbc/sqlite3/connection_methods.rb +9 -9
- data/lib/arjdbc/sybase.rb +1 -1
- data/lib/arjdbc/tasks.rb +13 -0
- data/lib/arjdbc/tasks/database_tasks.rb +50 -0
- data/lib/arjdbc/tasks/databases.rake +89 -0
- data/lib/arjdbc/tasks/databases3.rake +203 -0
- data/lib/arjdbc/tasks/databases4.rake +39 -0
- data/lib/arjdbc/tasks/db2_database_tasks.rb +104 -0
- data/lib/arjdbc/tasks/derby_database_tasks.rb +95 -0
- data/lib/arjdbc/tasks/h2_database_tasks.rb +29 -0
- data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
- data/lib/arjdbc/tasks/jdbc_database_tasks.rb +122 -0
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +36 -0
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +297 -0
- data/lib/arjdbc/tasks/oracle_database_tasks.rb +62 -0
- data/lib/arjdbc/version.rb +1 -1
- data/pom.xml +11 -12
- data/rails_generators/jdbc_generator.rb +1 -1
- data/rails_generators/templates/config/initializers/jdbc.rb +8 -5
- data/rails_generators/templates/lib/tasks/jdbc.rake +7 -4
- data/rakelib/02-test.rake +42 -15
- data/rakelib/compile.rake +29 -2
- data/rakelib/db.rake +2 -1
- data/rakelib/rails.rake +23 -6
- data/src/java/arjdbc/ArJdbcModule.java +175 -0
- data/src/java/arjdbc/db2/DB2Module.java +2 -1
- data/src/java/arjdbc/derby/DerbyModule.java +5 -24
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +3 -2
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +3 -46
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1001 -259
- data/src/java/arjdbc/mssql/MSSQLModule.java +2 -1
- data/src/java/arjdbc/mysql/MySQLModule.java +4 -3
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +12 -7
- data/src/java/arjdbc/oracle/OracleModule.java +2 -1
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +2 -1
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +12 -0
- data/test/db/db2.rb +14 -7
- data/test/db/db2/rake_test.rb +82 -0
- data/test/db/db2/rake_test_data.sql +35 -0
- data/test/db/db2/simple_test.rb +20 -0
- data/test/db/db2/unit_test.rb +3 -1
- data/test/db/derby.rb +7 -5
- data/test/db/derby/rake_test.rb +96 -0
- data/test/db/derby/simple_test.rb +10 -2
- data/test/db/h2.rb +6 -8
- data/test/db/h2/identity_column_test.rb +35 -0
- data/test/db/h2/offset_test.rb +49 -0
- data/test/db/h2/rake_test.rb +98 -0
- data/test/db/h2/schema_dump_test.rb +5 -1
- data/test/db/hsqldb.rb +6 -10
- data/test/db/hsqldb/rake_test.rb +101 -0
- data/test/db/hsqldb/schema_dump_test.rb +5 -1
- data/test/db/hsqldb/simple_test.rb +8 -0
- data/test/db/jndi_config.rb +1 -3
- data/test/db/jndi_pooled_config.rb +1 -3
- data/test/db/mssql/limit_offset_test.rb +23 -14
- data/test/db/mssql/rake_test.rb +143 -0
- data/test/db/mysql/_rails_test_mysql.32.out +1069 -1252
- data/test/db/mysql/nonstandard_primary_key_test.rb +21 -24
- data/test/db/mysql/rake_test.rb +97 -0
- data/test/db/mysql/schema_dump_test.rb +11 -11
- data/test/db/mysql/simple_test.rb +52 -3
- data/test/db/mysql/statement_escaping_test.rb +46 -0
- data/test/db/oracle/rake_test.rb +100 -0
- data/test/db/oracle/simple_test.rb +48 -0
- data/test/db/postgres/_rails_test_postgres.32.out +998 -1370
- data/test/db/postgres/active_schema_unit_test.rb +68 -0
- data/test/db/postgres/connection_test.rb +10 -2
- data/test/db/postgres/data_types_test.rb +2 -2
- data/test/db/postgres/ltree_test.rb +6 -5
- data/test/db/postgres/native_types_test.rb +1 -5
- data/test/db/postgres/rake_test.rb +117 -0
- data/test/db/postgres/schema_dump_test.rb +9 -2
- data/test/db/postgres/schema_test.rb +4 -2
- data/test/db/postgres/simple_test.rb +57 -16
- data/test/db/sqlite3.rb +3 -10
- data/test/db/sqlite3/_rails_test_sqlite3.32.out +1070 -1298
- data/test/db/sqlite3/rake_test.rb +71 -0
- data/test/db/sqlite3/simple_test.rb +9 -9
- data/test/has_many_through.rb +4 -1
- data/test/jdbc/db2.rb +14 -1
- data/test/jdbc_column_test.rb +23 -0
- data/test/{generic_jdbc_connection_test.rb → jdbc_connection_test.rb} +22 -17
- data/test/jndi_callbacks_test.rb +26 -28
- data/test/jndi_test.rb +7 -16
- data/test/models/data_types.rb +2 -1
- data/test/models/thing.rb +1 -0
- data/test/rails/mysql.rb +13 -0
- data/test/rails/sqlite3/version.rb +6 -0
- data/test/rails_stub.rb +31 -0
- data/test/rake_test_support.rb +298 -0
- data/test/serialize.rb +2 -4
- data/test/{helper.rb → shared_helper.rb} +0 -0
- data/test/simple.rb +167 -93
- data/test/test_helper.rb +52 -16
- metadata +388 -354
- data/lib/pg.rb +0 -26
- data/test/abstract_db_create.rb +0 -139
- data/test/activerecord/connection_adapters/type_conversion_test.rb +0 -36
- data/test/db/mssql/db_create_test.rb +0 -29
- data/test/db/mysql/db_create_test.rb +0 -33
- data/test/db/postgres/db_create_test.rb +0 -44
- data/test/db/postgres/db_drop_test.rb +0 -17
|
@@ -10,6 +10,6 @@ class JdbcGenerator < Rails::Generator::Base
|
|
|
10
10
|
|
|
11
11
|
protected
|
|
12
12
|
def banner
|
|
13
|
-
"Usage: #{$0} jdbc\nGenerate JDBC bootstrapping files for your Rails application."
|
|
13
|
+
"Usage: #{$0} jdbc\nGenerate JDBC bootstrapping files for your Rails (2.x) application."
|
|
14
14
|
end
|
|
15
15
|
end
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
# This file was generated by the "jdbc" generator, which is provided
|
|
2
|
-
#
|
|
1
|
+
# This file was generated by the "jdbc" generator, which is provided by the
|
|
2
|
+
# activerecord-jdbc-adapter gem.
|
|
3
3
|
#
|
|
4
|
-
# This file allows the JDBC
|
|
5
|
-
#
|
|
6
|
-
#
|
|
4
|
+
# This file allows the JDBC adapters to be hooked into ActiveRecord such that
|
|
5
|
+
# you don't have to change anything else in your Rails application.
|
|
6
|
+
#
|
|
7
|
+
# NOTE: This is only needed on Rails 2.x - without Bundler since when you're
|
|
8
|
+
# using Bundler than `gem 'activerecord-jdbc-adapter'` will automatically
|
|
9
|
+
# `require 'arjdbc'` by default (unless you set it to `require: false`).
|
|
7
10
|
require 'arjdbc' if defined?(JRUBY_VERSION)
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
# This file was generated by the "jdbc" generator, which is provided
|
|
2
|
-
#
|
|
1
|
+
# This file was generated by the "jdbc" generator, which is provided by the
|
|
2
|
+
# activerecord-jdbc-adapter gem.
|
|
3
3
|
#
|
|
4
|
-
# This file allows you to use Rails' various db:* tasks with JDBC.
|
|
4
|
+
# This file allows you to use Rails' various db:* tasks with the JDBC adapters.
|
|
5
|
+
#
|
|
6
|
+
# NOTE: Only needed on Rails 2.x and it's fine to delete this file otherwise,
|
|
7
|
+
# since on Rails 3.x AR-JDBC provides a Railtie that loads the Rake tasks.
|
|
5
8
|
if defined?(JRUBY_VERSION)
|
|
6
9
|
require 'arjdbc'
|
|
7
|
-
require 'arjdbc/
|
|
10
|
+
require 'arjdbc/tasks'
|
|
8
11
|
end
|
data/rakelib/02-test.rake
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
require File.expand_path('../../test/
|
|
1
|
+
require File.expand_path('../../test/shared_helper', __FILE__)
|
|
2
|
+
|
|
2
3
|
if defined?(JRUBY_VERSION)
|
|
3
4
|
databases = [ :test_mysql, :test_sqlite3, :test_derby, :test_hsqldb, :test_h2 ]
|
|
4
5
|
databases << :test_postgres if PostgresHelper.have_postgres?(false)
|
|
@@ -20,9 +21,8 @@ def set_compat_version(task)
|
|
|
20
21
|
end
|
|
21
22
|
end
|
|
22
23
|
|
|
23
|
-
%w(derby h2 hsqldb mysql sqlite3 postgres mssql oracle db2 informix sybase).each do
|
|
24
|
-
|adapter|
|
|
25
|
-
task "test_#{adapter}_pre" do
|
|
24
|
+
%w(derby h2 hsqldb mysql sqlite3 postgres mssql oracle db2 as400 informix sybase).each do
|
|
25
|
+
|adapter| task "test_#{adapter}_pre" do
|
|
26
26
|
unless (ENV['BUNDLE_GEMFILE'] rescue '') =~ /gemfiles\/.*?\.gemfile/
|
|
27
27
|
appraisals = []; Appraisal::File.each { |file| appraisals << file.name }
|
|
28
28
|
puts "Specify AR version with `rake appraisal:{version} test_#{adapter}'" +
|
|
@@ -56,9 +56,7 @@ def declare_test_task_for(adapter, options = {}, &block)
|
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
declare_test_task_for :derby
|
|
60
|
-
task.test_files << 'test/activerecord/connection_adapters/type_conversion_test.rb'
|
|
61
|
-
end
|
|
59
|
+
declare_test_task_for :derby
|
|
62
60
|
declare_test_task_for :h2
|
|
63
61
|
declare_test_task_for :hsqldb
|
|
64
62
|
declare_test_task_for :mssql, :driver => :jtds
|
|
@@ -81,16 +79,26 @@ declare_test_task_for :sqlite3
|
|
|
81
79
|
end
|
|
82
80
|
end
|
|
83
81
|
|
|
84
|
-
Rake::TestTask.new(:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
Rake::TestTask.new(:test_as400) do |task|
|
|
83
|
+
test_files = FileList["test/db2*_test.rb"]
|
|
84
|
+
test_files += FileList["test/db/db2/*_test.rb"]
|
|
85
|
+
task.test_files = test_files
|
|
86
|
+
task.libs = []
|
|
87
|
+
task.libs << 'lib' if defined?(JRUBY_VERSION)
|
|
88
|
+
task.libs << 'test'
|
|
89
|
+
set_compat_version(task)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
Rake::TestTask.new(:test_jdbc) do |task|
|
|
93
|
+
task.test_files = FileList['test/*jdbc_*test.rb']
|
|
94
|
+
task.libs << 'test' << 'jdbc-mysql/lib' << 'jdbc-derby/lib'
|
|
95
|
+
set_compat_version(task)
|
|
88
96
|
end
|
|
89
97
|
|
|
90
|
-
Rake::TestTask.new(:test_jndi => 'tomcat-jndi:check') do |
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
set_compat_version(
|
|
98
|
+
Rake::TestTask.new(:test_jndi => 'tomcat-jndi:check') do |task|
|
|
99
|
+
task.test_files = FileList['test/*jndi_*test.rb']
|
|
100
|
+
task.libs << 'test' << 'jdbc-derby/lib'
|
|
101
|
+
set_compat_version(task)
|
|
94
102
|
end
|
|
95
103
|
|
|
96
104
|
# tests for JDBC adapters that don't require a database :
|
|
@@ -113,3 +121,22 @@ Rake::TestTask.new(:test_sybase_jconnect) do |task|
|
|
|
113
121
|
task.libs << 'test'
|
|
114
122
|
set_compat_version(task)
|
|
115
123
|
end
|
|
124
|
+
|
|
125
|
+
Rake::TraceOutput.module_eval do
|
|
126
|
+
|
|
127
|
+
# NOTE: avoid TypeError: String can't be coerced into Fixnum
|
|
128
|
+
# due this method gettings a strings == [ 1 ] argument ...
|
|
129
|
+
def trace_on(out, *strings)
|
|
130
|
+
sep = $\ || "\n"
|
|
131
|
+
if strings.empty?
|
|
132
|
+
output = sep
|
|
133
|
+
else
|
|
134
|
+
output = strings.map { |s|
|
|
135
|
+
next if s.nil?; s = s.to_s
|
|
136
|
+
s =~ /#{sep}$/ ? s : s + sep
|
|
137
|
+
}.join
|
|
138
|
+
end
|
|
139
|
+
out.print(output)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
data/rakelib/compile.rake
CHANGED
|
@@ -15,7 +15,34 @@ begin
|
|
|
15
15
|
:classpath => "${java.class.path}:${sun.boot.class.path}:#{driver_jars.join(':')}",
|
|
16
16
|
:includeantRuntime => false
|
|
17
17
|
|
|
18
|
-
ant.
|
|
18
|
+
ant.tstamp do |ts|
|
|
19
|
+
ts.format(:property => 'TODAY', :pattern => 'yyyy-MM-dd HH:mm:ss')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
require 'arjdbc/version'
|
|
23
|
+
gem_version = Gem::Version.create(ArJdbc::VERSION)
|
|
24
|
+
if gem_version.segments.last == 'DEV'
|
|
25
|
+
version = gem_version.segments[0...-1] # 1.3.0.DEV -> 1.3.0
|
|
26
|
+
else
|
|
27
|
+
version = gem_version.segments.dup
|
|
28
|
+
end
|
|
29
|
+
version = version.join('.')
|
|
30
|
+
|
|
31
|
+
ant.manifest :file => 'MANIFEST.MF' do |mf|
|
|
32
|
+
mf.attribute :name => 'Built-By', :value => '${user.name}'
|
|
33
|
+
mf.attribute :name => 'Built-Time', :value => '${TODAY}'
|
|
34
|
+
mf.attribute :name => 'Built-Jdk', :value => '${java.version}'
|
|
35
|
+
mf.attribute :name => 'Built-JRuby', :value => JRUBY_VERSION
|
|
36
|
+
|
|
37
|
+
mf.attribute :name => 'Specification-Title', :value => 'ActiveRecord-JDBC'
|
|
38
|
+
mf.attribute :name => 'Specification-Version', :value => '1.3'
|
|
39
|
+
mf.attribute :name => 'Specification-Vendor', :value => 'JRuby'
|
|
40
|
+
mf.attribute :name => 'Implementation-Version', :value => version
|
|
41
|
+
mf.attribute :name => 'Implementation-Vendor', :value => 'The JRuby Team'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
ant.jar :basedir => "pkg/classes", :includes => "**/*.class",
|
|
45
|
+
:destfile => jar_file, :manifest => 'MANIFEST.MF'
|
|
19
46
|
end
|
|
20
47
|
|
|
21
48
|
desc "Compile the native Java code."
|
|
@@ -23,7 +50,7 @@ begin
|
|
|
23
50
|
|
|
24
51
|
namespace :jar do
|
|
25
52
|
task :force do
|
|
26
|
-
rm jar_file
|
|
53
|
+
rm jar_file if File.exist?(jar_file)
|
|
27
54
|
Rake::Task['jar'].invoke
|
|
28
55
|
end
|
|
29
56
|
end
|
data/rakelib/db.rake
CHANGED
data/rakelib/rails.rake
CHANGED
|
@@ -8,17 +8,23 @@ namespace :rails do
|
|
|
8
8
|
|
|
9
9
|
ar_jdbc_dir = File.expand_path('..', File.dirname(__FILE__))
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
ruby_lib = [
|
|
12
12
|
"#{ar_jdbc_dir}/lib",
|
|
13
|
+
"#{ar_jdbc_dir}/test/rails",
|
|
13
14
|
"#{ar_jdbc_dir}/jdbc-#{_driver(driver)}/lib",
|
|
14
15
|
"#{ar_jdbc_dir}/activerecord-jdbc#{_adapter(driver)}-adapter/lib"
|
|
15
16
|
]
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
ruby_lib << File.expand_path('activesupport/lib', rails_dir)
|
|
18
|
+
ruby_lib << File.expand_path('activemodel/lib', rails_dir)
|
|
19
|
+
ruby_lib << File.expand_path(File.join(activerecord_dir, 'lib'))
|
|
20
|
+
requires = _requires(driver) || []
|
|
20
21
|
|
|
21
|
-
Dir.chdir(activerecord_dir)
|
|
22
|
+
Dir.chdir(activerecord_dir) do
|
|
23
|
+
ruby = FileUtils::RUBY
|
|
24
|
+
rubylib = ruby_lib.join(':') # i_lib = "-I#{rubylib}"
|
|
25
|
+
r_requires = requires.map { |feat| "-r#{feat}" }.join(' ')
|
|
26
|
+
sh "#{ruby} -S rake RUBYLIB=#{rubylib} RUBYOPT=\"#{r_requires}\" #{_target(driver)}"
|
|
27
|
+
end
|
|
22
28
|
end
|
|
23
29
|
|
|
24
30
|
%w(MySQL SQLite3 Postgres).each do |adapter|
|
|
@@ -56,5 +62,16 @@ namespace :rails do
|
|
|
56
62
|
"test_jdbc#{name.downcase}"
|
|
57
63
|
end
|
|
58
64
|
end
|
|
65
|
+
|
|
66
|
+
def _requires(name)
|
|
67
|
+
requires = []
|
|
68
|
+
requires << 'ubygems'
|
|
69
|
+
requires << 'active_support/json' # avoid uninitialized constant BasicsTest::JSON
|
|
70
|
+
case name
|
|
71
|
+
when /mysql/i
|
|
72
|
+
requires << 'mysql' # -rmysql - so Rails tests do not complain about Mysql
|
|
73
|
+
end
|
|
74
|
+
requires
|
|
75
|
+
end
|
|
59
76
|
|
|
60
77
|
end
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2013 Karol Bucek.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
* THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
package arjdbc;
|
|
25
|
+
|
|
26
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
|
27
|
+
|
|
28
|
+
import java.lang.reflect.InvocationTargetException;
|
|
29
|
+
import java.util.Collection;
|
|
30
|
+
|
|
31
|
+
import org.jruby.NativeException;
|
|
32
|
+
import org.jruby.Ruby;
|
|
33
|
+
import org.jruby.RubyArray;
|
|
34
|
+
import org.jruby.RubyClass;
|
|
35
|
+
import org.jruby.RubyModule;
|
|
36
|
+
import org.jruby.anno.JRubyMethod;
|
|
37
|
+
import org.jruby.exceptions.RaiseException;
|
|
38
|
+
import org.jruby.runtime.ThreadContext;
|
|
39
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* ::ArJdbc
|
|
43
|
+
*
|
|
44
|
+
* @author kares
|
|
45
|
+
*/
|
|
46
|
+
public class ArJdbcModule {
|
|
47
|
+
|
|
48
|
+
public static RubyModule load(final Ruby runtime) {
|
|
49
|
+
final RubyModule arJdbc = runtime.getOrCreateModule("ArJdbc");
|
|
50
|
+
arJdbc.defineAnnotatedMethods( ArJdbcModule.class );
|
|
51
|
+
return arJdbc;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Load the Java parts for the given adapter spec module, e.g. to load
|
|
56
|
+
* ArJdbc::MySQL's Java part: <code>ArJdbc.load_java_part :MySQL</code>
|
|
57
|
+
*
|
|
58
|
+
* NOTE: this method is not intended to be called twice for a given adapter !
|
|
59
|
+
* @param context
|
|
60
|
+
* @param self
|
|
61
|
+
* @param args ( moduleName, [ connectionClass, moduleClass ] )
|
|
62
|
+
* @return true
|
|
63
|
+
*/
|
|
64
|
+
@JRubyMethod(name = "load_java_part", meta = true, required = 1, optional = 2)
|
|
65
|
+
public static IRubyObject load_java_part(final ThreadContext context,
|
|
66
|
+
final IRubyObject self, final IRubyObject[] args) {
|
|
67
|
+
|
|
68
|
+
String connectionClass = args.length > 1 ? args[1].toString() : null;
|
|
69
|
+
String moduleClass = args.length > 2 ? args[2].toString() : null;
|
|
70
|
+
|
|
71
|
+
final String moduleName = args[0].toString(); // e.g. 'MySQL'
|
|
72
|
+
final String packagePrefix = "arjdbc." + moduleName.toLowerCase() + "."; // arjdbc.mysql
|
|
73
|
+
|
|
74
|
+
// NOTE: due previous (backwards compatible) conventions there are
|
|
75
|
+
// 2 things we load, the adapter spec module's Java implemented methods
|
|
76
|
+
// and a custom JdbcConnection class (both are actually optional) e.g. :
|
|
77
|
+
//
|
|
78
|
+
// MySQLModule.load(RubyModule); // 'arjdbc.mysql' package is assumed
|
|
79
|
+
// MySQLRubyJdbcConnection.createMySQLJdbcConnectionClass(Ruby, RubyClass);
|
|
80
|
+
//
|
|
81
|
+
|
|
82
|
+
String connectionClass2 = null;
|
|
83
|
+
if (connectionClass == null) {
|
|
84
|
+
// 'arjdbc.mysql.' + 'MySQL' + 'RubyJdbcConnection'
|
|
85
|
+
connectionClass = packagePrefix + moduleName + "RubyJdbcConnection";
|
|
86
|
+
connectionClass2 = packagePrefix + moduleName + "JdbcConnection";
|
|
87
|
+
}
|
|
88
|
+
if (moduleClass == null) {
|
|
89
|
+
// 'arjdbc.mysql.' + 'MySQL' + 'Module'
|
|
90
|
+
moduleClass = packagePrefix + moduleName + "Module";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
final Ruby runtime = context.getRuntime();
|
|
94
|
+
final RubyModule arJdbc = runtime.getModule("ArJdbc");
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
final Class<?> module = Class.forName(moduleClass);
|
|
98
|
+
// MySQLModule.load( arJdbc ) :
|
|
99
|
+
module.getMethod("load", RubyModule.class).invoke(null, arJdbc);
|
|
100
|
+
}
|
|
101
|
+
catch (ClassNotFoundException e) { /* ignored */ }
|
|
102
|
+
catch (NoSuchMethodException e) {
|
|
103
|
+
throw newNativeException(runtime, e);
|
|
104
|
+
}
|
|
105
|
+
catch (IllegalAccessException e) {
|
|
106
|
+
throw newNativeException(runtime, e);
|
|
107
|
+
}
|
|
108
|
+
catch (InvocationTargetException e) {
|
|
109
|
+
throw newNativeException(runtime, e);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
Class<?> connection = null;
|
|
114
|
+
try {
|
|
115
|
+
connection = Class.forName(connectionClass);
|
|
116
|
+
}
|
|
117
|
+
catch (ClassNotFoundException e) {
|
|
118
|
+
if ( connectionClass2 != null ) {
|
|
119
|
+
connection = Class.forName(connectionClass2);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if ( connection != null ) {
|
|
123
|
+
final String method = "create" + moduleName + "JdbcConnectionClass";
|
|
124
|
+
// MySQLRubyJdbcConnection.createMySQLJdbcConnectionClass(runtime, jdbcConnection)
|
|
125
|
+
connection.getMethod(method, Ruby.class, RubyClass.class).
|
|
126
|
+
invoke(null, runtime, RubyJdbcConnection.getJdbcConnectionClass(runtime));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (ClassNotFoundException e) { /* ignored */ }
|
|
130
|
+
catch (NoSuchMethodException e) {
|
|
131
|
+
throw newNativeException(runtime, e);
|
|
132
|
+
}
|
|
133
|
+
catch (IllegalAccessException e) {
|
|
134
|
+
throw newNativeException(runtime, e);
|
|
135
|
+
}
|
|
136
|
+
catch (InvocationTargetException e) {
|
|
137
|
+
throw newNativeException(runtime, e);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return runtime.getTrue();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* <code>ArJdbc.modules</code>
|
|
145
|
+
* @param context
|
|
146
|
+
* @param self
|
|
147
|
+
* @return nested constant values that are modules
|
|
148
|
+
*/
|
|
149
|
+
@JRubyMethod(name = "modules", meta = true)
|
|
150
|
+
public static IRubyObject modules(final ThreadContext context, final IRubyObject self) {
|
|
151
|
+
final Ruby runtime = context.getRuntime();
|
|
152
|
+
final RubyModule arJdbc = (RubyModule) self;
|
|
153
|
+
|
|
154
|
+
final Collection<String> constants = arJdbc.getConstantNames();
|
|
155
|
+
final RubyArray modules = runtime.newArray( constants.size() );
|
|
156
|
+
|
|
157
|
+
for ( final String name : constants ) {
|
|
158
|
+
IRubyObject value = arJdbc.getConstant(name, false);
|
|
159
|
+
// isModule: return false for Ruby Classes
|
|
160
|
+
if ( value != null && value.isModule() ) {
|
|
161
|
+
if ( "MissingFunctionalityHelper".equals(name) ) continue;
|
|
162
|
+
if ( "Version".equals(name) ) continue;
|
|
163
|
+
modules.append(value);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return modules;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private static RaiseException newNativeException(final Ruby runtime, final Throwable cause) {
|
|
170
|
+
RubyClass nativeClass = runtime.getClass(NativeException.CLASS_NAME);
|
|
171
|
+
NativeException nativeException = new NativeException(runtime, nativeClass, cause);
|
|
172
|
+
throw new RaiseException(cause, nativeException);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
}
|
|
@@ -40,9 +40,10 @@ import org.jruby.runtime.builtin.IRubyObject;
|
|
|
40
40
|
*/
|
|
41
41
|
public class DB2Module {
|
|
42
42
|
|
|
43
|
-
public static
|
|
43
|
+
public static RubyModule load(final RubyModule arJdbc) {
|
|
44
44
|
RubyModule db2 = arJdbc.defineModuleUnder("DB2");
|
|
45
45
|
db2.defineAnnotatedMethods( DB2Module.class );
|
|
46
|
+
return db2;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
@JRubyMethod(name = "quote_string", required = 1, frame = false)
|
|
@@ -45,14 +45,14 @@ import org.jruby.util.ByteList;
|
|
|
45
45
|
|
|
46
46
|
public class DerbyModule {
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
static final RubyObjectAdapter rubyApi = JavaEmbedUtils.newObjectAdapter();
|
|
49
49
|
|
|
50
|
-
public static
|
|
50
|
+
public static RubyModule load(final RubyModule arJdbc) {
|
|
51
51
|
RubyModule derby = arJdbc.defineModuleUnder("Derby");
|
|
52
|
-
derby.defineAnnotatedMethods(DerbyModule.class);
|
|
52
|
+
derby.defineAnnotatedMethods( DerbyModule.class );
|
|
53
53
|
RubyModule column = derby.defineModuleUnder("Column");
|
|
54
54
|
column.defineAnnotatedMethods(Column.class);
|
|
55
|
-
|
|
55
|
+
return derby;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
public static class Column {
|
|
@@ -306,29 +306,10 @@ public class DerbyModule {
|
|
|
306
306
|
final IRubyObject self) {
|
|
307
307
|
return RubyString.newString(context.getRuntime(), BYTES_0);
|
|
308
308
|
}
|
|
309
|
-
|
|
310
|
-
@JRubyMethod(name = "select_all", rest = true)
|
|
311
|
-
public static IRubyObject select_all(IRubyObject recv, IRubyObject[] args) {
|
|
312
|
-
return rubyApi.callMethod(recv, "execute", args);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
@JRubyMethod(name = "select_one", rest = true)
|
|
316
|
-
public static IRubyObject select_one(IRubyObject recv, IRubyObject[] args) {
|
|
317
|
-
IRubyObject limit = rubyApi.getInstanceVariable(recv, "@limit");
|
|
318
|
-
if (limit == null || limit.isNil()) {
|
|
319
|
-
rubyApi.setInstanceVariable(recv, "@limit", recv.getRuntime().newFixnum(1));
|
|
320
|
-
}
|
|
321
|
-
try {
|
|
322
|
-
IRubyObject result = rubyApi.callMethod(recv, "execute", args);
|
|
323
|
-
return rubyApi.callMethod(result, "first");
|
|
324
|
-
} finally {
|
|
325
|
-
rubyApi.setInstanceVariable(recv, "@limit", recv.getRuntime().getNil());
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
309
|
|
|
329
310
|
@JRubyMethod(name = "_execute", required = 1, optional = 1)
|
|
330
311
|
public static IRubyObject _execute(final ThreadContext context, final IRubyObject self, final IRubyObject[] args)
|
|
331
|
-
throws SQLException
|
|
312
|
+
throws SQLException {
|
|
332
313
|
final IRubyObject sql = args[0];
|
|
333
314
|
|
|
334
315
|
String sqlStr = sql.toString().trim();
|