neo-activerecord-jdbc-adapter 5.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +33 -0
- data/.travis.yml +438 -0
- data/.yardopts +4 -0
- data/Appraisals +41 -0
- data/CONTRIBUTING.md +44 -0
- data/Gemfile +62 -0
- data/History.md +1191 -0
- data/LICENSE.txt +25 -0
- data/README.md +266 -0
- data/RUNNING_TESTS.md +88 -0
- data/Rakefile +100 -0
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +42 -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 +60 -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 +19 -0
- data/lib/arjdbc/abstract/database_statements.rb +92 -0
- data/lib/arjdbc/abstract/transaction_support.rb +86 -0
- data/lib/arjdbc/common_jdbc_methods.rb +13 -0
- data/lib/arjdbc/db2.rb +4 -0
- data/lib/arjdbc/db2/adapter.rb +789 -0
- data/lib/arjdbc/db2/as400.rb +130 -0
- data/lib/arjdbc/db2/column.rb +167 -0
- data/lib/arjdbc/db2/connection_methods.rb +44 -0
- data/lib/arjdbc/derby.rb +3 -0
- data/lib/arjdbc/derby/active_record_patch.rb +13 -0
- data/lib/arjdbc/derby/adapter.rb +556 -0
- data/lib/arjdbc/derby/connection_methods.rb +20 -0
- data/lib/arjdbc/derby/schema_creation.rb +15 -0
- data/lib/arjdbc/discover.rb +115 -0
- data/lib/arjdbc/firebird.rb +4 -0
- data/lib/arjdbc/firebird/adapter.rb +434 -0
- data/lib/arjdbc/firebird/connection_methods.rb +23 -0
- data/lib/arjdbc/h2.rb +3 -0
- data/lib/arjdbc/h2/adapter.rb +303 -0
- data/lib/arjdbc/h2/connection_methods.rb +27 -0
- data/lib/arjdbc/hsqldb.rb +3 -0
- data/lib/arjdbc/hsqldb/adapter.rb +297 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +28 -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 +162 -0
- data/lib/arjdbc/informix/connection_methods.rb +9 -0
- data/lib/arjdbc/jdbc.rb +59 -0
- data/lib/arjdbc/jdbc/adapter.rb +899 -0
- 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 +44 -0
- data/lib/arjdbc/jdbc/callbacks.rb +51 -0
- data/lib/arjdbc/jdbc/column.rb +97 -0
- data/lib/arjdbc/jdbc/connection.rb +133 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +36 -0
- data/lib/arjdbc/jdbc/driver.rb +43 -0
- data/lib/arjdbc/jdbc/extension.rb +59 -0
- data/lib/arjdbc/jdbc/java.rb +15 -0
- data/lib/arjdbc/jdbc/jdbc.rake +4 -0
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/arjdbc/jdbc/railtie.rb +2 -0
- data/lib/arjdbc/jdbc/rake_tasks.rb +3 -0
- data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -0
- data/lib/arjdbc/jdbc/type_cast.rb +166 -0
- data/lib/arjdbc/jdbc/type_converter.rb +142 -0
- data/lib/arjdbc/mimer.rb +3 -0
- data/lib/arjdbc/mimer/adapter.rb +142 -0
- data/lib/arjdbc/mssql.rb +7 -0
- data/lib/arjdbc/mssql/adapter.rb +808 -0
- data/lib/arjdbc/mssql/column.rb +200 -0
- data/lib/arjdbc/mssql/connection_methods.rb +79 -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 +1006 -0
- data/lib/arjdbc/mysql/bulk_change_table.rb +150 -0
- data/lib/arjdbc/mysql/column.rb +162 -0
- data/lib/arjdbc/mysql/connection_methods.rb +145 -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 +952 -0
- data/lib/arjdbc/oracle/column.rb +126 -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 +825 -0
- data/lib/arjdbc/postgresql/base/array_decoder.rb +26 -0
- data/lib/arjdbc/postgresql/base/array_encoder.rb +25 -0
- data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
- data/lib/arjdbc/postgresql/base/pgconn.rb +11 -0
- data/lib/arjdbc/postgresql/column.rb +51 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +54 -0
- data/lib/arjdbc/postgresql/name.rb +24 -0
- data/lib/arjdbc/postgresql/oid_types.rb +178 -0
- data/lib/arjdbc/railtie.rb +11 -0
- data/lib/arjdbc/sqlite3.rb +3 -0
- data/lib/arjdbc/sqlite3/adapter.rb +703 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +40 -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 +54 -0
- data/lib/arjdbc/tasks/databases.rake +91 -0
- data/lib/arjdbc/tasks/databases3.rake +215 -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 +110 -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/lib/jdbc_adapter.rb +2 -0
- data/lib/jdbc_adapter/rake_tasks.rb +4 -0
- data/lib/jdbc_adapter/version.rb +4 -0
- data/pom.xml +114 -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 +121 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/compile.rake +62 -0
- data/rakelib/db.rake +58 -0
- data/rakelib/rails.rake +75 -0
- data/src/java/arjdbc/ArJdbcModule.java +178 -0
- data/src/java/arjdbc/db2/DB2Module.java +71 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +142 -0
- data/src/java/arjdbc/derby/DerbyModule.java +179 -0
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +164 -0
- data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +190 -0
- data/src/java/arjdbc/h2/H2Module.java +44 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +67 -0
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +68 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +75 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +45 -0
- data/src/java/arjdbc/jdbc/Callable.java +44 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +45 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +3616 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +54 -0
- data/src/java/arjdbc/mssql/MSSQLModule.java +102 -0
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +195 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +147 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +397 -0
- data/src/java/arjdbc/oracle/OracleModule.java +75 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +465 -0
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +752 -0
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +78 -0
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +351 -0
- data/src/java/arjdbc/util/CallResultSet.java +826 -0
- data/src/java/arjdbc/util/QuotingUtils.java +111 -0
- metadata +255 -0
@@ -0,0 +1,121 @@
|
|
1
|
+
require File.expand_path('../../test/shared_helper', __FILE__)
|
2
|
+
|
3
|
+
test_tasks = [ 'test_mysql', 'test_sqlite3', 'test_postgresql_with_hint' ]
|
4
|
+
if defined?(JRUBY_VERSION)
|
5
|
+
test_tasks.push :test_derby, :test_hsqldb, :test_h2
|
6
|
+
test_tasks.push :test_jndi, :test_jdbc
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Run \"most\" available test_xxx tasks"
|
10
|
+
task :test => test_tasks
|
11
|
+
|
12
|
+
task 'test_postgresql_with_hint' do
|
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
|
+
test_task_for 'JDBC', :desc => 'Run tests against plain JDBC adapter (uses MySQL and Derby)',
|
98
|
+
:prereqs => 'db:mysql', :files => FileList['test/*jdbc_*test.rb'] do |test_task|
|
99
|
+
test_task.libs << 'jdbc-mysql/lib' << 'jdbc-derby/lib'
|
100
|
+
end
|
101
|
+
|
102
|
+
test_task_for 'JNDI', :desc => 'Run tests against a JNDI connection (uses Derby)',
|
103
|
+
:prereqs => 'tomcat-jndi:check',
|
104
|
+
:files => FileList['test/*jndi_*test.rb'] do |test_task|
|
105
|
+
test_task.libs << 'jdbc-derby/lib'
|
106
|
+
end
|
107
|
+
|
108
|
+
test_task_for :MySQL, :name => 'test_jdbc_mysql',
|
109
|
+
:prereqs => 'db:mysql', :database_name => 'MySQL (using adapter: jdbc)' do |test_task|
|
110
|
+
test_task.ruby_opts << '-rdb/jdbc_mysql' # replaces require 'db/mysql'
|
111
|
+
end
|
112
|
+
test_task_for :PostgreSQL, :name => 'test_jdbc_postgresql', :driver => 'postgres',
|
113
|
+
:prereqs => 'db:postgresql', :database_name => 'PostgreSQL (using adapter: jdbc)' do |test_task|
|
114
|
+
test_task.ruby_opts << '-rdb/jdbc_postgres' # replaces require 'db/postgres'
|
115
|
+
end
|
116
|
+
|
117
|
+
# TODO Sybase testing is currently broken, please fix it if you're on Sybase :
|
118
|
+
#test_task_for :Sybase, :desc => "Run tests against Sybase (using jTDS driver)"
|
119
|
+
#task :test_sybase_jtds => :test_sybase # alias
|
120
|
+
#test_task_for :Sybase, :name => 'sybase_jconnect',
|
121
|
+
# :desc => "Run tests against Sybase (ensure jConnect driver is on class-path)"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
jar_file = File.join(*%w(lib arjdbc jdbc adapter_java.jar))
|
2
|
+
begin
|
3
|
+
require 'ant'
|
4
|
+
directory classes = "pkg/classes"
|
5
|
+
CLEAN << classes
|
6
|
+
|
7
|
+
driver_jars = []
|
8
|
+
# PostgreSQL driver :
|
9
|
+
driver_jars << Dir.glob("jdbc-postgres/lib/*.jar").sort.last
|
10
|
+
|
11
|
+
file jar_file => FileList['src/java/**/*.java', 'pkg/classes'] do
|
12
|
+
rm_rf FileList["#{classes}/**/*"]
|
13
|
+
ant.javac :srcdir => "src/java", :destdir => "pkg/classes",
|
14
|
+
:source => "1.6", :target => "1.6", :debug => true, :deprecation => true,
|
15
|
+
:classpath => "${java.class.path}:${sun.boot.class.path}:#{driver_jars.join(':')}",
|
16
|
+
:includeantRuntime => false
|
17
|
+
|
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'
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Compile the native Java code."
|
49
|
+
task :jar => jar_file
|
50
|
+
|
51
|
+
namespace :jar do
|
52
|
+
task :force do
|
53
|
+
rm jar_file if File.exist?(jar_file)
|
54
|
+
Rake::Task['jar'].invoke
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
rescue LoadError
|
59
|
+
task :jar do
|
60
|
+
puts "Run 'jar' with JRuby to re-compile the agent extension class"
|
61
|
+
end
|
62
|
+
end
|
data/rakelib/db.rake
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path('../../test/shared_helper', __FILE__)
|
2
|
+
|
3
|
+
namespace :db do
|
4
|
+
|
5
|
+
desc "Creates the test database for MySQL"
|
6
|
+
task :mysql do
|
7
|
+
fail "could not create test database: mysql executable not found" unless mysql = which('mysql')
|
8
|
+
load 'test/db/mysql_config.rb' # rescue nil
|
9
|
+
script = sql_script <<-SQL, 'mysql'
|
10
|
+
DROP DATABASE IF EXISTS `#{MYSQL_CONFIG[:database]}`;
|
11
|
+
CREATE USER #{MYSQL_CONFIG[:username]}@localhost;
|
12
|
+
CREATE DATABASE `#{MYSQL_CONFIG[:database]}` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_general_ci`;
|
13
|
+
GRANT ALL PRIVILEGES ON `#{MYSQL_CONFIG[:database]}`.* TO #{MYSQL_CONFIG[:username]}@localhost;
|
14
|
+
GRANT ALL PRIVILEGES ON `test\_%`.* TO #{MYSQL_CONFIG[:username]}@localhost;
|
15
|
+
SET PASSWORD FOR #{MYSQL_CONFIG[:username]}@localhost = PASSWORD('#{MYSQL_CONFIG[:password]}');
|
16
|
+
SQL
|
17
|
+
params = { '-u' => 'root' }
|
18
|
+
if ENV['DATABASE_YML']
|
19
|
+
require 'yaml'
|
20
|
+
password = YAML.load(File.new(ENV['DATABASE_YML']))["production"]["password"]
|
21
|
+
params['--password'] = password
|
22
|
+
end
|
23
|
+
puts "Creating MySQL (test) database: #{MYSQL_CONFIG[:database]}"
|
24
|
+
sh "cat #{script.path} | #{mysql} -f #{params.to_a.join(' ')}", :verbose => $VERBOSE # so password is not echoed
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Creates the test database for PostgreSQL"
|
28
|
+
task :postgresql do
|
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,75 @@
|
|
1
|
+
DEFAULT_RAILS_DIR = File.join('..', 'rails')
|
2
|
+
DEFAULT_ADAPTERS = %w(MySQL SQLite3 Postgres)
|
3
|
+
|
4
|
+
namespace :rails do
|
5
|
+
namespace :test do
|
6
|
+
task :all do
|
7
|
+
driver = ENV['DRIVER'] || ENV['ADAPTER']
|
8
|
+
raise "need a DRIVER (DRIVER=mysql)" unless driver
|
9
|
+
rails_dir = _rails_dir
|
10
|
+
|
11
|
+
Dir.chdir(File.join(rails_dir, 'activerecord')) do
|
12
|
+
sh FileUtils::RUBY, '-S', 'rake',
|
13
|
+
"RUBYLIB=#{_ruby_lib(rails_dir, driver)}",
|
14
|
+
_target(driver)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
DEFAULT_ADAPTERS.each do |adapter|
|
19
|
+
desc "Run Rails ActiveRecord tests with #{adapter} (JDBC)"
|
20
|
+
task adapter.downcase do
|
21
|
+
ENV['ADAPTER'] = adapter
|
22
|
+
Rake::Task['rails:test:all'].invoke
|
23
|
+
end
|
24
|
+
|
25
|
+
namespace adapter.downcase do
|
26
|
+
desc "Runs Rails ActiveRecord base_test.rb with #{adapter}"
|
27
|
+
task "base_test" do
|
28
|
+
ENV['TEST'] = "test/cases/base_test.rb"
|
29
|
+
ENV['ADAPTER'] = adapter
|
30
|
+
Rake::Task['rails:test:all'].invoke
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def _rails_dir
|
38
|
+
rails_dir = ENV['RAILS'] || DEFAULT_RAILS_DIR
|
39
|
+
unless File.directory? rails_dir
|
40
|
+
raise "can't find RAILS source '#{rails_dir}' (maybe set ENV['RAILS'])"
|
41
|
+
end
|
42
|
+
rails_dir = File.join(rails_dir, '..') if rails_dir =~ /activerecord$/
|
43
|
+
rails_dir
|
44
|
+
end
|
45
|
+
|
46
|
+
def _ruby_lib(rails_dir, driver)
|
47
|
+
ar_jdbc_dir = File.expand_path('..', File.dirname(__FILE__))
|
48
|
+
|
49
|
+
if driver =~ /postgres/i
|
50
|
+
adapter, driver = 'postgresql', 'postgres'
|
51
|
+
else
|
52
|
+
adapter = driver.downcase
|
53
|
+
driver = adapter
|
54
|
+
end
|
55
|
+
|
56
|
+
[File.join(ar_jdbc_dir, 'lib'),
|
57
|
+
File.join(ar_jdbc_dir, 'test', 'rails'),
|
58
|
+
File.join(ar_jdbc_dir, "jdbc-#{driver}", 'lib'),
|
59
|
+
File.join(ar_jdbc_dir, "activerecord-jdbc#{adapter}-adapter", 'lib'),
|
60
|
+
File.expand_path('activesupport/lib', rails_dir),
|
61
|
+
File.expand_path('activemodel/lib', rails_dir),
|
62
|
+
File.expand_path('activerecord/lib', rails_dir)
|
63
|
+
].join(':')
|
64
|
+
end
|
65
|
+
|
66
|
+
def _target(name)
|
67
|
+
case name
|
68
|
+
when /postgres/i
|
69
|
+
'test_jdbcpostgresql'
|
70
|
+
else
|
71
|
+
"test_jdbc#{name.downcase}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,178 @@
|
|
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 ( "SerializedAttributesHelper".equals(name) ) continue;
|
163
|
+
if ( "QuotedPrimaryKeyExtension".equals(name) ) continue;
|
164
|
+
if ( "Util".equals(name) ) continue;
|
165
|
+
if ( "Version".equals(name) ) continue;
|
166
|
+
modules.append(value);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
return modules;
|
170
|
+
}
|
171
|
+
|
172
|
+
private static RaiseException newNativeException(final Ruby runtime, final Throwable cause) {
|
173
|
+
RubyClass nativeClass = runtime.getClass(NativeException.CLASS_NAME);
|
174
|
+
NativeException nativeException = new NativeException(runtime, nativeClass, cause);
|
175
|
+
throw new RaiseException(cause, nativeException);
|
176
|
+
}
|
177
|
+
|
178
|
+
}
|