activerecord-jdbc-adapter-ficoh 1.3.21-java
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.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/.travis.yml +462 -0
- data/.yardopts +4 -0
- data/Appraisals +36 -0
- data/CONTRIBUTING.md +49 -0
- data/Gemfile +68 -0
- data/History.md +1191 -0
- data/LICENSE.txt +25 -0
- data/README.md +277 -0
- data/RUNNING_TESTS.md +88 -0
- data/Rakefile +298 -0
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +63 -0
- data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +1 -0
- data/lib/arel/visitors/compat.rb +64 -0
- data/lib/arel/visitors/db2.rb +137 -0
- data/lib/arel/visitors/derby.rb +112 -0
- data/lib/arel/visitors/firebird.rb +79 -0
- data/lib/arel/visitors/h2.rb +25 -0
- data/lib/arel/visitors/hsqldb.rb +32 -0
- data/lib/arel/visitors/postgresql_jdbc.rb +6 -0
- data/lib/arel/visitors/sql_server.rb +225 -0
- data/lib/arel/visitors/sql_server/ng42.rb +293 -0
- data/lib/arjdbc.rb +22 -0
- data/lib/arjdbc/db2.rb +4 -0
- data/lib/arjdbc/db2/adapter.rb +802 -0
- data/lib/arjdbc/db2/as400.rb +137 -0
- data/lib/arjdbc/db2/column.rb +177 -0
- data/lib/arjdbc/db2/connection_methods.rb +45 -0
- data/lib/arjdbc/derby.rb +3 -0
- data/lib/arjdbc/derby/active_record_patch.rb +13 -0
- data/lib/arjdbc/derby/adapter.rb +567 -0
- data/lib/arjdbc/derby/connection_methods.rb +16 -0
- data/lib/arjdbc/derby/schema_creation.rb +15 -0
- data/lib/arjdbc/discover.rb +104 -0
- data/lib/arjdbc/firebird.rb +4 -0
- data/lib/arjdbc/firebird/adapter.rb +468 -0
- data/lib/arjdbc/firebird/connection_methods.rb +20 -0
- data/lib/arjdbc/h2.rb +3 -0
- data/lib/arjdbc/h2/adapter.rb +335 -0
- data/lib/arjdbc/h2/connection_methods.rb +22 -0
- data/lib/arjdbc/hsqldb.rb +3 -0
- data/lib/arjdbc/hsqldb/adapter.rb +304 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +23 -0
- data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
- data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
- data/lib/arjdbc/informix.rb +5 -0
- data/lib/arjdbc/informix/adapter.rb +160 -0
- data/lib/arjdbc/informix/connection_methods.rb +9 -0
- data/lib/arjdbc/jdbc.rb +62 -0
- data/lib/arjdbc/jdbc/adapter.rb +997 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +46 -0
- data/lib/arjdbc/jdbc/arel_support.rb +149 -0
- data/lib/arjdbc/jdbc/base_ext.rb +34 -0
- data/lib/arjdbc/jdbc/callbacks.rb +52 -0
- data/lib/arjdbc/jdbc/column.rb +83 -0
- data/lib/arjdbc/jdbc/connection.rb +26 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +59 -0
- data/lib/arjdbc/jdbc/driver.rb +44 -0
- data/lib/arjdbc/jdbc/error.rb +75 -0
- data/lib/arjdbc/jdbc/extension.rb +69 -0
- data/lib/arjdbc/jdbc/java.rb +13 -0
- data/lib/arjdbc/jdbc/type_cast.rb +154 -0
- data/lib/arjdbc/jdbc/type_converter.rb +142 -0
- data/lib/arjdbc/mssql.rb +7 -0
- data/lib/arjdbc/mssql/adapter.rb +822 -0
- data/lib/arjdbc/mssql/column.rb +207 -0
- data/lib/arjdbc/mssql/connection_methods.rb +72 -0
- data/lib/arjdbc/mssql/explain_support.rb +99 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +231 -0
- data/lib/arjdbc/mssql/lock_methods.rb +77 -0
- data/lib/arjdbc/mssql/types.rb +343 -0
- data/lib/arjdbc/mssql/utils.rb +82 -0
- data/lib/arjdbc/mysql.rb +3 -0
- data/lib/arjdbc/mysql/adapter.rb +998 -0
- data/lib/arjdbc/mysql/bulk_change_table.rb +150 -0
- data/lib/arjdbc/mysql/column.rb +167 -0
- data/lib/arjdbc/mysql/connection_methods.rb +137 -0
- data/lib/arjdbc/mysql/explain_support.rb +82 -0
- data/lib/arjdbc/mysql/schema_creation.rb +58 -0
- data/lib/arjdbc/oracle.rb +4 -0
- data/lib/arjdbc/oracle/adapter.rb +968 -0
- data/lib/arjdbc/oracle/column.rb +136 -0
- data/lib/arjdbc/oracle/connection_methods.rb +21 -0
- data/lib/arjdbc/postgresql.rb +3 -0
- data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +21 -0
- data/lib/arjdbc/postgresql/adapter.rb +1498 -0
- data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
- data/lib/arjdbc/postgresql/base/oid.rb +412 -0
- data/lib/arjdbc/postgresql/base/pgconn.rb +8 -0
- data/lib/arjdbc/postgresql/base/schema_definitions.rb +132 -0
- data/lib/arjdbc/postgresql/column.rb +640 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +44 -0
- data/lib/arjdbc/postgresql/explain_support.rb +53 -0
- data/lib/arjdbc/postgresql/oid/bytea.rb +3 -0
- data/lib/arjdbc/postgresql/oid_types.rb +265 -0
- data/lib/arjdbc/postgresql/schema_creation.rb +60 -0
- data/lib/arjdbc/railtie.rb +11 -0
- data/lib/arjdbc/sqlite3.rb +3 -0
- data/lib/arjdbc/sqlite3/adapter.rb +654 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +36 -0
- data/lib/arjdbc/sqlite3/explain_support.rb +29 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +47 -0
- data/lib/arjdbc/tasks.rb +13 -0
- data/lib/arjdbc/tasks/database_tasks.rb +66 -0
- data/lib/arjdbc/tasks/databases.rake +91 -0
- data/lib/arjdbc/tasks/databases3.rake +239 -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 +31 -0
- data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
- data/lib/arjdbc/tasks/jdbc_database_tasks.rb +169 -0
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +46 -0
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +297 -0
- data/lib/arjdbc/tasks/oracle_database_tasks.rb +65 -0
- data/lib/arjdbc/util/quoted_cache.rb +60 -0
- data/lib/arjdbc/util/serialized_attributes.rb +98 -0
- data/lib/arjdbc/util/table_copier.rb +108 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/USAGE +9 -0
- data/lib/generators/jdbc/jdbc_generator.rb +17 -0
- data/pom.xml +285 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +10 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +11 -0
- data/rakelib/01-tomcat.rake +51 -0
- data/rakelib/02-test.rake +151 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/db.rake +58 -0
- data/rakelib/rails.rake +77 -0
- data/src/java/arjdbc/ArJdbcModule.java +288 -0
- data/src/java/arjdbc/db2/DB2Module.java +77 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +128 -0
- data/src/java/arjdbc/derby/DerbyModule.java +180 -0
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +153 -0
- data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +190 -0
- data/src/java/arjdbc/h2/H2Module.java +50 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +86 -0
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +74 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +76 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +43 -0
- data/src/java/arjdbc/jdbc/Callable.java +44 -0
- data/src/java/arjdbc/jdbc/ConnectionFactory.java +77 -0
- data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +156 -0
- data/src/java/arjdbc/jdbc/DriverConnectionFactory.java +63 -0
- data/src/java/arjdbc/jdbc/DriverWrapper.java +128 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +32 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +4541 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +54 -0
- data/src/java/arjdbc/jdbc/WithResultSet.java +37 -0
- data/src/java/arjdbc/mssql/MSSQLModule.java +91 -0
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +193 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +140 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +456 -0
- data/src/java/arjdbc/oracle/OracleModule.java +81 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +477 -0
- data/src/java/arjdbc/postgresql/ByteaUtils.java +171 -0
- data/src/java/arjdbc/postgresql/DriverImplementation.java +78 -0
- data/src/java/arjdbc/postgresql/PGDriverImplementation.java +535 -0
- data/src/java/arjdbc/postgresql/PostgreSQLModule.java +189 -0
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +489 -0
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +93 -0
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +405 -0
- data/src/java/arjdbc/util/CallResultSet.java +826 -0
- data/src/java/arjdbc/util/DateTimeUtils.java +517 -0
- data/src/java/arjdbc/util/NumberUtils.java +50 -0
- data/src/java/arjdbc/util/ObjectSupport.java +65 -0
- data/src/java/arjdbc/util/QuotingUtils.java +139 -0
- data/src/java/arjdbc/util/StringCache.java +60 -0
- data/src/java/arjdbc/util/StringHelper.java +155 -0
- metadata +288 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
class JdbcGenerator < Rails::Generator::Base
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
m.directory 'config/initializers'
|
5
|
+
m.template 'config/initializers/jdbc.rb', File.join('config', 'initializers', 'jdbc.rb')
|
6
|
+
m.directory 'lib/tasks'
|
7
|
+
m.template 'lib/tasks/jdbc.rake', File.join('lib', 'tasks', 'jdbc.rake')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
def banner
|
13
|
+
"Usage: #{$0} jdbc\nGenerate JDBC bootstrapping files for your Rails (2.x) application."
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# This file was generated by the "jdbc" generator, which is provided by the
|
2
|
+
# activerecord-jdbc-adapter gem.
|
3
|
+
#
|
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`).
|
10
|
+
require 'arjdbc' if defined?(JRUBY_VERSION)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file was generated by the "jdbc" generator, which is provided by the
|
2
|
+
# activerecord-jdbc-adapter gem.
|
3
|
+
#
|
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.
|
8
|
+
if defined?(JRUBY_VERSION)
|
9
|
+
require 'arjdbc'
|
10
|
+
require 'arjdbc/tasks'
|
11
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
namespace :'tomcat-jndi' do # contains a FS JNDI impl (for tests)
|
2
|
+
|
3
|
+
TOMCAT_MAVEN_REPO = 'http://repo2.maven.org/maven2/org/apache/tomcat'
|
4
|
+
TOMCAT_VERSION = '7.0.61'
|
5
|
+
|
6
|
+
DOWNLOAD_DIR = File.expand_path('../test/jars', File.dirname(__FILE__))
|
7
|
+
|
8
|
+
#tomcat_jar = "tomcat-embed-core.jar"
|
9
|
+
#tomcat_uri = "#{TOMCAT_MAVEN_REPO}/embed/tomcat-embed-core/#{TOMCAT_VERSION}/tomcat-embed-core-#{TOMCAT_VERSION}.jar"
|
10
|
+
|
11
|
+
catalina_jar = "tomcat-catalina.jar"
|
12
|
+
catalina_uri = "#{TOMCAT_MAVEN_REPO}/tomcat-catalina/#{TOMCAT_VERSION}/tomcat-catalina-#{TOMCAT_VERSION}.jar"
|
13
|
+
|
14
|
+
juli_jar = "tomcat-juli.jar"
|
15
|
+
juli_uri = "#{TOMCAT_MAVEN_REPO}/tomcat-juli/#{TOMCAT_VERSION}/tomcat-juli-#{TOMCAT_VERSION}.jar"
|
16
|
+
|
17
|
+
task :download do
|
18
|
+
require 'open-uri'; require 'tmpdir'
|
19
|
+
|
20
|
+
temp_dir = File.join(Dir.tmpdir, (Time.now.to_f * 1000).to_i.to_s)
|
21
|
+
FileUtils.mkdir temp_dir
|
22
|
+
|
23
|
+
downloads = Hash.new
|
24
|
+
downloads[juli_jar] = juli_uri
|
25
|
+
downloads[catalina_jar] = catalina_uri
|
26
|
+
|
27
|
+
Dir.chdir(temp_dir) do
|
28
|
+
FileUtils.mkdir DOWNLOAD_DIR unless File.exist?(DOWNLOAD_DIR)
|
29
|
+
downloads.each do |jar, uri|
|
30
|
+
puts "downloading #{uri}"
|
31
|
+
file = open(uri)
|
32
|
+
FileUtils.cp file.path, File.join(DOWNLOAD_DIR, jar)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
FileUtils.rm_r temp_dir
|
37
|
+
end
|
38
|
+
|
39
|
+
task :check do
|
40
|
+
jar_path = File.join(DOWNLOAD_DIR, catalina_jar)
|
41
|
+
unless File.exist?(jar_path)
|
42
|
+
Rake::Task['tomcat-jndi:download'].invoke
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
task :clear do
|
47
|
+
jar_path = File.join(DOWNLOAD_DIR, catalina_jar)
|
48
|
+
rm jar_path if File.exist?(jar_path)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
|
2
|
+
test_tasks = [ 'test_mysql', 'test_sqlite3', 'test_postgresql_with_hint' ]
|
3
|
+
if defined?(JRUBY_VERSION)
|
4
|
+
test_tasks.push :test_derby, :test_hsqldb, :test_h2
|
5
|
+
test_tasks.push :test_jndi, :test_jdbc
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Run \"most\" available test_xxx tasks"
|
9
|
+
task :test => test_tasks
|
10
|
+
|
11
|
+
task 'test_postgresql_with_hint' do
|
12
|
+
require File.expand_path('../../test/shared_helper', __FILE__)
|
13
|
+
if PostgresHelper.have_postgres?(false)
|
14
|
+
Rake::Task['test_postgresql'].invoke
|
15
|
+
else
|
16
|
+
puts "NOTE: won't run test_postgresql"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
task 'test_appraisal_hint' do
|
21
|
+
next if File.exists?('.disable-appraisal-hint')
|
22
|
+
unless (ENV['BUNDLE_GEMFILE'] || '') =~ /gemfiles\/.*?\.gemfile/
|
23
|
+
appraisals = []; Appraisal::File.each { |file| appraisals << file.name }
|
24
|
+
puts "HINT: specify AR version with `rake appraisal:{version} test_{adapter}'" +
|
25
|
+
" where version=(#{appraisals.join('|')}) (`touch .disable-appraisal-hint' to disable)"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Rake::TestTask.class_eval { attr_reader :test_files }
|
30
|
+
|
31
|
+
def test_task_for(adapter, options = {})
|
32
|
+
desc = options[:desc] || options[:comment] ||
|
33
|
+
"Run tests against #{options[:database_name] || adapter}"
|
34
|
+
adapter = adapter.to_s.downcase
|
35
|
+
driver = adapter if ( driver = options[:driver] ).nil?
|
36
|
+
prereqs = options[:prereqs] || []
|
37
|
+
unless prereqs.frozen?
|
38
|
+
prereqs = [ prereqs ].flatten; prereqs << 'test_appraisal_hint'
|
39
|
+
end
|
40
|
+
name = options[:name] || "test_#{adapter}"
|
41
|
+
test_task = Rake::TestTask.new(name => prereqs) do |test_task|
|
42
|
+
files = options[:files] || begin
|
43
|
+
FileList["test/#{adapter}*_test.rb"] +
|
44
|
+
FileList["test/db/#{adapter}/**/*_test.rb"]
|
45
|
+
end
|
46
|
+
test_task.test_files = files
|
47
|
+
test_task.libs = []
|
48
|
+
if defined?(JRUBY_VERSION)
|
49
|
+
test_task.libs << 'lib'
|
50
|
+
test_task.libs << "jdbc-#{driver}/lib" if driver && File.exists?("jdbc-#{driver}/lib")
|
51
|
+
test_task.libs.push *FileList["activerecord-jdbc#{adapter}*/lib"]
|
52
|
+
end
|
53
|
+
test_task.libs << 'test'
|
54
|
+
test_task.ruby_opts << '-v' if RUBY_VERSION.index('1.8') == 0
|
55
|
+
# set current Ruby compatibility version on JRuby <= 1.7 :
|
56
|
+
if defined?(JRUBY_VERSION) && JRUBY_VERSION.index('1.7') == 0
|
57
|
+
test_task.ruby_opts << "--#{RUBY_VERSION[/^(\d+\.\d+)/, 1]}"
|
58
|
+
end
|
59
|
+
test_task.options = '--use-color=t'
|
60
|
+
test_task.verbose = true if $VERBOSE
|
61
|
+
yield(test_task) if block_given?
|
62
|
+
end
|
63
|
+
task = Rake::Task[name]
|
64
|
+
# reset the description set-up by Rake::TestTask :
|
65
|
+
if task.instance_variable_defined? :@full_comment
|
66
|
+
task.instance_variable_set(:@full_comment, nil)
|
67
|
+
else
|
68
|
+
task.instance_variable_get(:@comments).clear
|
69
|
+
end
|
70
|
+
task.add_description(desc)
|
71
|
+
test_task
|
72
|
+
end
|
73
|
+
|
74
|
+
test_task_for :Derby, :desc => 'Run tests against (embedded) DerbyDB'
|
75
|
+
test_task_for :H2, :desc => 'Run tests against H2 database engine'
|
76
|
+
test_task_for :HSQLDB, :desc => 'Run tests against HyperSQL (Java) database'
|
77
|
+
test_task_for :MSSQL, :driver => :jtds, :database_name => 'MS-SQL (SQLServer)'
|
78
|
+
test_task_for :MySQL, :prereqs => 'db:mysql'
|
79
|
+
test_task_for :PostgreSQL, :driver => 'postgres', :prereqs => 'db:postgresql'
|
80
|
+
task :test_postgres => :test_postgresql # alias
|
81
|
+
test_task_for :SQLite3, :driver => ENV['JDBC_SQLITE_VERSION']
|
82
|
+
task :test_sqlite => :test_sqlite3 # alias
|
83
|
+
test_task_for :Firebird
|
84
|
+
|
85
|
+
test_task_for :MariaDB, :prereqs => 'db:mysql', :files => FileList["test/db/mysql/*_test.rb"]
|
86
|
+
|
87
|
+
# ensure driver for these DBs is on your class-path
|
88
|
+
[ :Oracle, :DB2, :Informix, :CacheDB ].each do |adapter|
|
89
|
+
test_task_for adapter, :desc => "Run tests against #{adapter} (ensure driver is on class-path)"
|
90
|
+
end
|
91
|
+
|
92
|
+
#test_task_for :MSSQL, :name => 'test_sqlserver', :driver => nil, :database_name => 'MS-SQL using SQLJDBC'
|
93
|
+
|
94
|
+
test_task_for :AS400, :desc => "Run tests against AS400 (DB2) (ensure driver is on class-path)",
|
95
|
+
:files => FileList["test/db2*_test.rb"] + FileList["test/db/db2/*_test.rb"]
|
96
|
+
|
97
|
+
#task :test_jdbc => [ :test_jdbc_mysql, :test_jdbc_derby ] if defined?(JRUBY_VERSION)
|
98
|
+
|
99
|
+
test_task_for 'JDBC', :desc => 'Run tests against plain JDBC adapter (uses MySQL and Derby)',
|
100
|
+
:prereqs => [ 'db:mysql' ], :files => FileList['test/*jdbc_*test.rb'] do |test_task|
|
101
|
+
test_task.libs << 'jdbc-mysql/lib' << 'jdbc-derby/lib'
|
102
|
+
end
|
103
|
+
|
104
|
+
task :test_jndi => [ :test_jndi_mysql, :test_jndi_derby ] if defined?(JRUBY_VERSION)
|
105
|
+
|
106
|
+
jndi_classpath = []
|
107
|
+
jndi_classpath << 'test/jars/tomcat-juli.jar'
|
108
|
+
jndi_classpath << 'test/jars/tomcat-catalina.jar'
|
109
|
+
|
110
|
+
jndi_classpath.each do |jar_path|
|
111
|
+
file(jar_path) { Rake::Task['tomcat-jndi:download'].invoke }
|
112
|
+
end
|
113
|
+
|
114
|
+
get_jndi_classpath_opt = lambda do
|
115
|
+
cp = jndi_classpath.map do |jar_path|
|
116
|
+
File.expand_path("../#{jar_path}", File.dirname(__FILE__))
|
117
|
+
end
|
118
|
+
"-J-cp \"#{cp.join(windows? ? ';' : ':')}\""
|
119
|
+
end
|
120
|
+
|
121
|
+
def windows?; require 'rbconfig'; RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw/ end
|
122
|
+
|
123
|
+
test_task_for 'JNDI_Derby', :desc => 'Run tests against a Derby JNDI connection',
|
124
|
+
:prereqs => jndi_classpath,
|
125
|
+
:files => FileList['test/*jndi_derby*test.rb'] do |test_task|
|
126
|
+
test_task.libs << 'jdbc-derby/lib'
|
127
|
+
test_task.ruby_opts << get_jndi_classpath_opt.call
|
128
|
+
#test_task.verbose = true
|
129
|
+
end
|
130
|
+
|
131
|
+
test_task_for 'JNDI_MySQL', :desc => 'Run tests against a MySQL JNDI connection',
|
132
|
+
:prereqs => [ 'db:mysql' ] + jndi_classpath,
|
133
|
+
:files => FileList['test/*jndi_mysql*test.rb'] do |test_task|
|
134
|
+
test_task.libs << 'jdbc-mysql/lib'
|
135
|
+
test_task.ruby_opts << get_jndi_classpath_opt.call
|
136
|
+
end
|
137
|
+
|
138
|
+
test_task_for :MySQL, :name => 'test_jdbc_mysql',
|
139
|
+
:prereqs => 'db:mysql', :database_name => 'MySQL (using adapter: jdbc)' do |test_task|
|
140
|
+
test_task.ruby_opts << '-rdb/jdbc_mysql' # replaces require 'db/mysql'
|
141
|
+
end
|
142
|
+
test_task_for :PostgreSQL, :name => 'test_jdbc_postgresql', :driver => 'postgres',
|
143
|
+
:prereqs => 'db:postgresql', :database_name => 'PostgreSQL (using adapter: jdbc)' do |test_task|
|
144
|
+
test_task.ruby_opts << '-rdb/jdbc_postgres' # replaces require 'db/postgres'
|
145
|
+
end
|
146
|
+
|
147
|
+
# TODO Sybase testing is currently broken, please fix it if you're on Sybase :
|
148
|
+
#test_task_for :Sybase, :desc => "Run tests against Sybase (using jTDS driver)"
|
149
|
+
#task :test_sybase_jtds => :test_sybase # alias
|
150
|
+
#test_task_for :Sybase, :name => 'sybase_jconnect',
|
151
|
+
# :desc => "Run tests against Sybase (ensure jConnect driver is on class-path)"
|
data/rakelib/db.rake
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
namespace :db do
|
2
|
+
|
3
|
+
desc "Creates the test database for MySQL"
|
4
|
+
task :mysql do
|
5
|
+
require File.expand_path('../../test/shared_helper', __FILE__)
|
6
|
+
fail "could not create test database: mysql executable not found" unless mysql = which('mysql')
|
7
|
+
load 'test/db/mysql_config.rb' # rescue nil
|
8
|
+
enc = MYSQL_CONFIG[:encoding] || 'utf8' # 'utf8mb4'
|
9
|
+
script = sql_script <<-SQL, 'mysql'
|
10
|
+
DROP DATABASE IF EXISTS `#{MYSQL_CONFIG[:database]}`;
|
11
|
+
CREATE DATABASE `#{MYSQL_CONFIG[:database]}` DEFAULT CHARACTER SET `#{enc}` COLLATE `#{enc}_general_ci`;
|
12
|
+
GRANT ALL PRIVILEGES ON `#{MYSQL_CONFIG[:database]}`.* TO #{MYSQL_CONFIG[:username]}@localhost;
|
13
|
+
GRANT ALL PRIVILEGES ON `test\_%`.* TO #{MYSQL_CONFIG[:username]}@localhost;
|
14
|
+
SET PASSWORD FOR #{MYSQL_CONFIG[:username]}@localhost = PASSWORD('#{MYSQL_CONFIG[:password]}');
|
15
|
+
SQL
|
16
|
+
params = { '-u' => 'root' }
|
17
|
+
if ENV['DATABASE_YML']
|
18
|
+
require 'yaml'
|
19
|
+
password = YAML.load(File.new(ENV['DATABASE_YML']))["production"]["password"]
|
20
|
+
params['--password'] = password
|
21
|
+
end
|
22
|
+
puts "Creating MySQL (test) database: #{MYSQL_CONFIG[:database]}"
|
23
|
+
sh "cat #{script.path} | #{mysql} #{params.to_a.join(' ')}", :verbose => $VERBOSE # so password is not echoed
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Creates the test database for PostgreSQL"
|
27
|
+
task :postgresql do
|
28
|
+
require File.expand_path('../../test/shared_helper', __FILE__)
|
29
|
+
fail 'could not create test database: psql executable not found' unless psql = which('psql')
|
30
|
+
fail 'could not create test database: missing "postgres" role' unless PostgresHelper.postgres_role?
|
31
|
+
load 'test/db/postgres_config.rb' # rescue nil
|
32
|
+
script = sql_script <<-SQL, 'psql'
|
33
|
+
DROP DATABASE IF EXISTS #{POSTGRES_CONFIG[:database]};
|
34
|
+
DROP USER IF EXISTS #{POSTGRES_CONFIG[:username]};
|
35
|
+
CREATE USER #{POSTGRES_CONFIG[:username]} CREATEDB SUPERUSER LOGIN PASSWORD '#{POSTGRES_CONFIG[:password]}';
|
36
|
+
CREATE DATABASE #{POSTGRES_CONFIG[:database]} OWNER #{POSTGRES_CONFIG[:username]}
|
37
|
+
TEMPLATE template0
|
38
|
+
ENCODING '#{POSTGRES_CONFIG[:encoding]}' LC_COLLATE '#{POSTGRES_CONFIG[:collate]}' LC_CTYPE '#{POSTGRES_CONFIG[:collate]}';
|
39
|
+
SQL
|
40
|
+
params = { '-U' => ENV['PSQL_USER'] || 'postgres' }
|
41
|
+
params['-q'] = nil unless $VERBOSE
|
42
|
+
puts "Creating PostgreSQL (test) database: #{POSTGRES_CONFIG[:database]}"
|
43
|
+
sh "cat #{script.path} | #{psql} #{params.to_a.join(' ')}", :verbose => $VERBOSE
|
44
|
+
end
|
45
|
+
task :postgres => :postgresql
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def sql_script(sql_content, name = 'sql_script')
|
50
|
+
require 'tempfile'; script = Tempfile.new(name)
|
51
|
+
script.puts sql_content
|
52
|
+
yield(script) if block_given?
|
53
|
+
script.close
|
54
|
+
at_exit { script.unlink }
|
55
|
+
script
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/rakelib/rails.rake
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
namespace :rails do
|
2
|
+
|
3
|
+
task :test do
|
4
|
+
raise "need a DRIVER e.g. DRIVER=mysql" unless driver = ENV['DRIVER'] || ENV['ADAPTER']
|
5
|
+
raise "need location of RAILS source code e.g. RAILS=../rails" unless rails_dir = ENV['RAILS']
|
6
|
+
rails_dir = File.join(rails_dir, '..') if rails_dir =~ /activerecord$/
|
7
|
+
activerecord_dir = File.join(rails_dir, 'activerecord') # rails/activerecord
|
8
|
+
|
9
|
+
ar_jdbc_dir = File.expand_path('..', File.dirname(__FILE__))
|
10
|
+
|
11
|
+
ruby_lib = [
|
12
|
+
"#{ar_jdbc_dir}/lib",
|
13
|
+
"#{ar_jdbc_dir}/test/rails",
|
14
|
+
"#{ar_jdbc_dir}/jdbc-#{_driver(driver)}/lib",
|
15
|
+
"#{ar_jdbc_dir}/activerecord-jdbc#{_adapter(driver)}-adapter/lib"
|
16
|
+
]
|
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) || []
|
21
|
+
|
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
|
28
|
+
end
|
29
|
+
|
30
|
+
%w(MySQL SQLite3 Postgres).each do |adapter|
|
31
|
+
desc "Run Rails' ActiveRecord tests with #{adapter} (JDBC)"
|
32
|
+
task "test_#{adapter.downcase}" do
|
33
|
+
ENV['ADAPTER'] = adapter; Rake::Task['rails:test'].invoke
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def _adapter(name)
|
40
|
+
case name
|
41
|
+
when /postgres/i
|
42
|
+
'postgresql'
|
43
|
+
else
|
44
|
+
name.downcase
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def _driver(name)
|
49
|
+
case name
|
50
|
+
when /postgres/i
|
51
|
+
'postgres'
|
52
|
+
else
|
53
|
+
name.downcase
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def _target(name)
|
58
|
+
case name
|
59
|
+
when /postgres/i
|
60
|
+
'test_jdbcpostgresql'
|
61
|
+
else
|
62
|
+
"test_jdbc#{name.downcase}"
|
63
|
+
end
|
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
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,288 @@
|
|
1
|
+
/*
|
2
|
+
* The MIT License
|
3
|
+
*
|
4
|
+
* Copyright 2013-2014 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 java.lang.reflect.InvocationTargetException;
|
27
|
+
import java.util.Collection;
|
28
|
+
import java.util.HashMap;
|
29
|
+
import java.util.Map;
|
30
|
+
import java.util.WeakHashMap;
|
31
|
+
|
32
|
+
import org.jruby.NativeException;
|
33
|
+
import org.jruby.Ruby;
|
34
|
+
import org.jruby.RubyArray;
|
35
|
+
import org.jruby.RubyClass;
|
36
|
+
import org.jruby.RubyModule;
|
37
|
+
import org.jruby.RubyString;
|
38
|
+
import org.jruby.anno.JRubyMethod;
|
39
|
+
import org.jruby.anno.JRubyModule;
|
40
|
+
import org.jruby.exceptions.RaiseException;
|
41
|
+
import org.jruby.runtime.Block;
|
42
|
+
import org.jruby.runtime.ThreadContext;
|
43
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
44
|
+
import org.jruby.util.ByteList;
|
45
|
+
|
46
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
47
|
+
import static arjdbc.jdbc.RubyJdbcConnection.getJdbcConnection;
|
48
|
+
|
49
|
+
/**
|
50
|
+
* ::ArJdbc
|
51
|
+
*
|
52
|
+
* @author kares
|
53
|
+
*/
|
54
|
+
@JRubyModule(name = "ArJdbc")
|
55
|
+
public class ArJdbcModule {
|
56
|
+
|
57
|
+
public static RubyModule load(final Ruby runtime) {
|
58
|
+
final RubyModule arJdbc = runtime.getOrCreateModule("ArJdbc");
|
59
|
+
arJdbc.defineAnnotatedMethods( ArJdbcModule.class );
|
60
|
+
return arJdbc;
|
61
|
+
}
|
62
|
+
|
63
|
+
public static RubyModule get(final Ruby runtime) {
|
64
|
+
return runtime.getModule("ArJdbc");
|
65
|
+
}
|
66
|
+
|
67
|
+
public static void warn(final ThreadContext context, final String message) {
|
68
|
+
final Ruby runtime = context.runtime;
|
69
|
+
get(runtime).callMethod(context, "warn", runtime.newString(message));
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Load the Java parts for the given adapter spec module, e.g. to load
|
74
|
+
* ArJdbc::MySQL's Java part: <code>ArJdbc.load_java_part :MySQL</code>
|
75
|
+
*
|
76
|
+
* NOTE: this method is not intended to be called twice for a given adapter !
|
77
|
+
* @param context
|
78
|
+
* @param self
|
79
|
+
* @param args ( moduleName, [ connectionClass, moduleClass ] )
|
80
|
+
* @return true
|
81
|
+
*/
|
82
|
+
@JRubyMethod(name = "load_java_part", meta = true, required = 1, optional = 2)
|
83
|
+
public static IRubyObject load_java_part(final ThreadContext context,
|
84
|
+
final IRubyObject self, final IRubyObject[] args) {
|
85
|
+
final Ruby runtime = context.runtime;
|
86
|
+
|
87
|
+
String connectionClass = args.length > 1 ? args[1].toString() : null;
|
88
|
+
String moduleClass = args.length > 2 ? args[2].toString() : null;
|
89
|
+
|
90
|
+
final String moduleName = args[0].toString(); // e.g. 'MySQL'
|
91
|
+
final String packagePrefix = "arjdbc." + moduleName.toLowerCase() + "."; // arjdbc.mysql
|
92
|
+
|
93
|
+
// NOTE: due previous (backwards compatible) conventions there are
|
94
|
+
// 2 things we load, the adapter spec module's Java implemented methods
|
95
|
+
// and a custom JdbcConnection class (both are actually optional) e.g. :
|
96
|
+
//
|
97
|
+
// MySQLModule.load(RubyModule); // 'arjdbc.mysql' package is assumed
|
98
|
+
// MySQLRubyJdbcConnection.createMySQLJdbcConnectionClass(Ruby, RubyClass);
|
99
|
+
//
|
100
|
+
|
101
|
+
if (moduleClass == null) {
|
102
|
+
// 'arjdbc.mysql.' + 'MySQL' + 'Module'
|
103
|
+
moduleClass = packagePrefix + moduleName + "Module";
|
104
|
+
}
|
105
|
+
|
106
|
+
final Class<?> module;
|
107
|
+
try {
|
108
|
+
module = Class.forName(moduleClass);
|
109
|
+
// new convention MySQLModule.load( Ruby runtime ) :
|
110
|
+
try {
|
111
|
+
invokeStatic(runtime, module, "load", Ruby.class, runtime);
|
112
|
+
}
|
113
|
+
catch (NoSuchMethodException e) {
|
114
|
+
// old convention MySQLModule.load( RubyModule arJdbc ) :
|
115
|
+
invokeStatic(runtime, module, "load", RubyModule.class, get(runtime));
|
116
|
+
}
|
117
|
+
}
|
118
|
+
catch (ClassNotFoundException e) { /* ignored */ }
|
119
|
+
catch (NoSuchMethodException e) {
|
120
|
+
throw newNativeException(runtime, e);
|
121
|
+
}
|
122
|
+
|
123
|
+
String connectionClass2 = null;
|
124
|
+
if (connectionClass == null) {
|
125
|
+
// 'arjdbc.mysql.' + 'MySQL' + 'RubyJdbcConnection'
|
126
|
+
connectionClass = packagePrefix + moduleName + "RubyJdbcConnection";
|
127
|
+
connectionClass2 = packagePrefix + moduleName + "JdbcConnection";
|
128
|
+
}
|
129
|
+
|
130
|
+
try {
|
131
|
+
Class<?> connection = null;
|
132
|
+
try {
|
133
|
+
connection = Class.forName(connectionClass);
|
134
|
+
}
|
135
|
+
catch (ClassNotFoundException e) {
|
136
|
+
if ( connectionClass2 != null ) {
|
137
|
+
connection = Class.forName(connectionClass2);
|
138
|
+
}
|
139
|
+
}
|
140
|
+
if ( connection != null ) {
|
141
|
+
// convention e.g. MySQLRubyJdbcConnection.load( Ruby runtime ) :
|
142
|
+
try {
|
143
|
+
invokeStatic(runtime, connection, "load", Ruby.class, runtime);
|
144
|
+
}
|
145
|
+
catch (NoSuchMethodException e) {
|
146
|
+
// "old" e.g. MySQLRubyJdbcConnection.createMySQLJdbcConnectionClass(runtime, jdbcConnection)
|
147
|
+
connection.getMethod("create" + moduleName + "JdbcConnectionClass", Ruby.class, RubyClass.class).
|
148
|
+
invoke(null, runtime, getJdbcConnection(runtime));
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
catch (ClassNotFoundException e) { /* ignored */ }
|
153
|
+
catch (NoSuchMethodException e) {
|
154
|
+
throw newNativeException(runtime, e);
|
155
|
+
}
|
156
|
+
catch (IllegalAccessException e) {
|
157
|
+
throw newNativeException(runtime, e);
|
158
|
+
}
|
159
|
+
catch (InvocationTargetException e) {
|
160
|
+
throw newNativeException(runtime, e);
|
161
|
+
}
|
162
|
+
|
163
|
+
return runtime.getTrue();
|
164
|
+
}
|
165
|
+
|
166
|
+
/**
|
167
|
+
* <code>ArJdbc.modules</code>
|
168
|
+
* @param context
|
169
|
+
* @param self
|
170
|
+
* @return nested constant values that are modules
|
171
|
+
*/
|
172
|
+
@JRubyMethod(name = "modules", meta = true)
|
173
|
+
public static IRubyObject modules(final ThreadContext context, final IRubyObject self) {
|
174
|
+
final Ruby runtime = context.runtime;
|
175
|
+
final RubyModule arJdbc = (RubyModule) self;
|
176
|
+
|
177
|
+
final Collection<String> constants = arJdbc.getConstantNames();
|
178
|
+
final RubyArray modules = runtime.newArray( constants.size() );
|
179
|
+
|
180
|
+
for ( final String name : constants ) {
|
181
|
+
final IRubyObject constant = arJdbc.getConstant(name, false);
|
182
|
+
// isModule: return false for Ruby Classes
|
183
|
+
if ( constant != null && constant.isModule() ) {
|
184
|
+
if ( "Util".equals(name) ) continue;
|
185
|
+
if ( "SerializedAttributesHelper".equals(name) ) continue; // deprecated
|
186
|
+
if ( "Version".equals(name) ) continue; // deprecated
|
187
|
+
modules.append( constant );
|
188
|
+
}
|
189
|
+
}
|
190
|
+
return modules;
|
191
|
+
}
|
192
|
+
|
193
|
+
// JDBC "driver" gem helper(s) :
|
194
|
+
|
195
|
+
@JRubyMethod(name = "load_driver", meta = true)
|
196
|
+
public static IRubyObject load_driver(final ThreadContext context, final IRubyObject self,
|
197
|
+
final IRubyObject const_name) { // e.g. load_driver(:MySQL)
|
198
|
+
IRubyObject loaded = loadDriver(context, self, const_name.toString());
|
199
|
+
return loaded == null ? context.nil : loaded;
|
200
|
+
}
|
201
|
+
|
202
|
+
// NOTE: probably useless - only to be useful for the pooled runtime mode when jar at WEB-INF/lib
|
203
|
+
static final Map<Ruby, Map<String, Boolean>> loadedDrivers = new WeakHashMap<Ruby, Map<String, Boolean>>(8);
|
204
|
+
|
205
|
+
private static IRubyObject loadDriver(final ThreadContext context, final IRubyObject self,
|
206
|
+
final String constName) {
|
207
|
+
final Ruby runtime = context.runtime;
|
208
|
+
// look for "cached" loading result :
|
209
|
+
Map<String, Boolean> loadedMap = loadedDrivers.get(runtime);
|
210
|
+
if ( loadedMap == null ) {
|
211
|
+
synchronized (ArJdbcModule.class) {
|
212
|
+
loadedMap = loadedDrivers.get(runtime);
|
213
|
+
if ( loadedMap == null ) {
|
214
|
+
loadedMap = new HashMap<String, Boolean>(4);
|
215
|
+
loadedDrivers.put(runtime, loadedMap);
|
216
|
+
}
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
final Boolean driverLoaded = loadedMap.get(constName);
|
221
|
+
if ( driverLoaded != null ) {
|
222
|
+
if ( driverLoaded.booleanValue() ) return runtime.getFalse();
|
223
|
+
return runtime.getNil();
|
224
|
+
}
|
225
|
+
|
226
|
+
try { // require 'jdbc/mysql'
|
227
|
+
final byte[] name = new byte[5 + constName.length()]; // 'j','d','b','c','/'
|
228
|
+
name[0] = 'j'; name[1] = 'd'; name[2] = 'b'; name[3] = 'c'; name[4] = '/';
|
229
|
+
for ( int i = 0; i < constName.length(); i++ ) {
|
230
|
+
name[ 5 + i ] = (byte) Character.toLowerCase( constName.charAt(i) );
|
231
|
+
}
|
232
|
+
final RubyString strName = RubyString.newString(runtime, new ByteList(name, false));
|
233
|
+
self.callMethod(context, "require", strName); // require 'jdbc/mysql'
|
234
|
+
}
|
235
|
+
catch (RaiseException e) { // LoadError
|
236
|
+
synchronized (loadedMap) {
|
237
|
+
loadedMap.put(constName, Boolean.FALSE);
|
238
|
+
}
|
239
|
+
return null;
|
240
|
+
}
|
241
|
+
|
242
|
+
final RubyModule jdbc = runtime.getModule("Jdbc");
|
243
|
+
if ( jdbc != null ) { // Jdbc::MySQL
|
244
|
+
final RubyModule constant = (RubyModule) jdbc.getConstantAt(constName);
|
245
|
+
if ( constant != null ) { // ::Jdbc::MySQL.load_driver :
|
246
|
+
if ( constant.respondsTo("load_driver") ) {
|
247
|
+
IRubyObject result = constant.callMethod("load_driver");
|
248
|
+
synchronized (loadedMap) {
|
249
|
+
loadedMap.put(constName, Boolean.TRUE);
|
250
|
+
}
|
251
|
+
return result;
|
252
|
+
}
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
synchronized (loadedMap) {
|
257
|
+
loadedMap.put(constName, Boolean.FALSE);
|
258
|
+
}
|
259
|
+
return null;
|
260
|
+
}
|
261
|
+
|
262
|
+
private static Object invokeStatic(final Ruby runtime,
|
263
|
+
final Class<?> klass, final String name, final Class<?> argType, final Object arg)
|
264
|
+
throws NoSuchMethodException {
|
265
|
+
try {
|
266
|
+
return klass.getMethod(name, argType).invoke(null, arg);
|
267
|
+
}
|
268
|
+
catch (IllegalAccessException e) {
|
269
|
+
throw newNativeException(runtime, e);
|
270
|
+
}
|
271
|
+
catch (InvocationTargetException e) {
|
272
|
+
throw newNativeException(runtime, e);
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
private static RaiseException newNativeException(final Ruby runtime, final Throwable cause) {
|
277
|
+
RubyClass nativeClass = runtime.getClass(NativeException.CLASS_NAME);
|
278
|
+
NativeException nativeException = new NativeException(runtime, nativeClass, cause);
|
279
|
+
return new RaiseException(cause, nativeException);
|
280
|
+
}
|
281
|
+
|
282
|
+
@JRubyMethod(meta = true)
|
283
|
+
public static IRubyObject with_meta_data_from_data_source_if_any(final ThreadContext context,
|
284
|
+
final IRubyObject self, final IRubyObject config, final Block block) {
|
285
|
+
return RubyJdbcConnection.with_meta_data_from_data_source_if_any(context, self, config, block);
|
286
|
+
}
|
287
|
+
|
288
|
+
}
|