activerecord-jdbc-adapter 0.9.3-java
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +248 -0
- data/LICENSE.txt +21 -0
- data/Manifest.txt +125 -0
- data/README.txt +218 -0
- data/Rakefile +10 -0
- data/lib/active_record/connection_adapters/cachedb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +13 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +13 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +13 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +640 -0
- data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +26 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +13 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +13 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +13 -0
- data/lib/generators/jdbc/jdbc_generator.rb +9 -0
- data/lib/jdbc_adapter.rb +27 -0
- data/lib/jdbc_adapter/jdbc.rake +121 -0
- data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
- data/lib/jdbc_adapter/jdbc_cachedb.rb +33 -0
- data/lib/jdbc_adapter/jdbc_db2.rb +203 -0
- data/lib/jdbc_adapter/jdbc_derby.rb +430 -0
- data/lib/jdbc_adapter/jdbc_firebird.rb +109 -0
- data/lib/jdbc_adapter/jdbc_hsqldb.rb +218 -0
- data/lib/jdbc_adapter/jdbc_informix.rb +147 -0
- data/lib/jdbc_adapter/jdbc_mimer.rb +141 -0
- data/lib/jdbc_adapter/jdbc_mssql.rb +337 -0
- data/lib/jdbc_adapter/jdbc_mysql.rb +236 -0
- data/lib/jdbc_adapter/jdbc_oracle.rb +377 -0
- data/lib/jdbc_adapter/jdbc_postgre.rb +498 -0
- data/lib/jdbc_adapter/jdbc_sqlite3.rb +384 -0
- data/lib/jdbc_adapter/jdbc_sybase.rb +50 -0
- data/lib/jdbc_adapter/missing_functionality_helper.rb +87 -0
- data/lib/jdbc_adapter/rake_tasks.rb +10 -0
- data/lib/jdbc_adapter/tsql_helper.rb +60 -0
- data/lib/jdbc_adapter/version.rb +5 -0
- data/lib/pg.rb +4 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
- data/rakelib/compile.rake +23 -0
- data/rakelib/package.rake +90 -0
- data/rakelib/rails.rake +41 -0
- data/rakelib/test.rake +76 -0
- data/src/java/jdbc_adapter/JdbcAdapterInternalService.java +53 -0
- data/src/java/jdbc_adapter/JdbcConnectionFactory.java +36 -0
- data/src/java/jdbc_adapter/JdbcDerbySpec.java +293 -0
- data/src/java/jdbc_adapter/JdbcMySQLSpec.java +134 -0
- data/src/java/jdbc_adapter/MssqlRubyJdbcConnection.java +71 -0
- data/src/java/jdbc_adapter/PostgresRubyJdbcConnection.java +55 -0
- data/src/java/jdbc_adapter/RubyJdbcConnection.java +1162 -0
- data/src/java/jdbc_adapter/SQLBlock.java +27 -0
- data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +41 -0
- data/test/abstract_db_create.rb +107 -0
- data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
- data/test/cachedb_simple_test.rb +6 -0
- data/test/db/cachedb.rb +9 -0
- data/test/db/db2.rb +9 -0
- data/test/db/derby.rb +14 -0
- data/test/db/h2.rb +11 -0
- data/test/db/hsqldb.rb +12 -0
- data/test/db/informix.rb +11 -0
- data/test/db/jdbc.rb +11 -0
- data/test/db/jndi_config.rb +30 -0
- data/test/db/logger.rb +3 -0
- data/test/db/mssql.rb +9 -0
- data/test/db/mysql.rb +10 -0
- data/test/db/oracle.rb +34 -0
- data/test/db/postgres.rb +9 -0
- data/test/db/sqlite3.rb +15 -0
- data/test/db2_simple_test.rb +10 -0
- data/test/derby_migration_test.rb +21 -0
- data/test/derby_multibyte_test.rb +12 -0
- data/test/derby_simple_test.rb +21 -0
- data/test/generic_jdbc_connection_test.rb +9 -0
- data/test/h2_simple_test.rb +6 -0
- data/test/has_many_through.rb +79 -0
- data/test/helper.rb +5 -0
- data/test/hsqldb_simple_test.rb +6 -0
- data/test/informix_simple_test.rb +48 -0
- data/test/jdbc_adapter/jdbc_db2_test.rb +26 -0
- data/test/jdbc_adapter/jdbc_sybase_test.rb +33 -0
- data/test/jdbc_common.rb +25 -0
- data/test/jndi_callbacks_test.rb +38 -0
- data/test/jndi_test.rb +35 -0
- data/test/manualTestDatabase.rb +191 -0
- data/test/minirunit.rb +109 -0
- data/test/minirunit/testConnect.rb +14 -0
- data/test/minirunit/testH2.rb +73 -0
- data/test/minirunit/testHsqldb.rb +73 -0
- data/test/minirunit/testLoadActiveRecord.rb +3 -0
- data/test/minirunit/testMysql.rb +83 -0
- data/test/minirunit/testRawSelect.rb +24 -0
- data/test/models/add_not_null_column_to_table.rb +12 -0
- data/test/models/auto_id.rb +18 -0
- data/test/models/data_types.rb +28 -0
- data/test/models/entry.rb +23 -0
- data/test/models/mixed_case.rb +20 -0
- data/test/models/reserved_word.rb +18 -0
- data/test/models/string_id.rb +18 -0
- data/test/models/validates_uniqueness_of_string.rb +19 -0
- data/test/mssql_simple_test.rb +6 -0
- data/test/mysql_db_create_test.rb +25 -0
- data/test/mysql_multibyte_test.rb +10 -0
- data/test/mysql_nonstandard_primary_key_test.rb +42 -0
- data/test/mysql_simple_test.rb +32 -0
- data/test/oracle_simple_test.rb +29 -0
- data/test/pick_rails_version.rb +3 -0
- data/test/postgres_db_create_test.rb +21 -0
- data/test/postgres_mixed_case_test.rb +19 -0
- data/test/postgres_nonseq_pkey_test.rb +40 -0
- data/test/postgres_reserved_test.rb +22 -0
- data/test/postgres_schema_search_path_test.rb +46 -0
- data/test/postgres_simple_test.rb +13 -0
- data/test/simple.rb +475 -0
- data/test/sqlite3_simple_test.rb +233 -0
- data/test/sybase_jtds_simple_test.rb +6 -0
- metadata +188 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
if defined?(Rake.application) && Rake.application && ENV["SKIP_AR_JDBC_RAKE_REDEFINES"].nil?
|
2
|
+
jdbc_rakefile = File.dirname(__FILE__) + "/jdbc.rake"
|
3
|
+
if Rake.application.lookup("db:create")
|
4
|
+
# rails tasks already defined; load the override tasks now
|
5
|
+
load jdbc_rakefile
|
6
|
+
else
|
7
|
+
# rails tasks not loaded yet; load as an import
|
8
|
+
Rake.application.add_import(jdbc_rakefile)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Common methods for handling TSQL databases.
|
2
|
+
module TSqlMethods
|
3
|
+
|
4
|
+
def modify_types(tp) #:nodoc:
|
5
|
+
tp[:primary_key] = "int NOT NULL IDENTITY(1, 1) PRIMARY KEY"
|
6
|
+
tp[:integer][:limit] = nil
|
7
|
+
tp[:boolean] = {:name => "bit"}
|
8
|
+
tp[:binary] = { :name => "image"}
|
9
|
+
tp
|
10
|
+
end
|
11
|
+
|
12
|
+
def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
|
13
|
+
return 'uniqueidentifier' if (type.to_s == 'uniqueidentifier')
|
14
|
+
return super unless type.to_s == 'integer'
|
15
|
+
|
16
|
+
if limit.nil? || limit == 4
|
17
|
+
'int'
|
18
|
+
elsif limit == 2
|
19
|
+
'smallint'
|
20
|
+
elsif limit == 1
|
21
|
+
'tinyint'
|
22
|
+
else
|
23
|
+
'bigint'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_limit_offset!(sql, options)
|
28
|
+
if options[:limit] and options[:offset]
|
29
|
+
total_rows = select_all("SELECT count(*) as TotalRows from (#{sql.gsub(/\bSELECT(\s+DISTINCT)?\b/i, "SELECT\\1 TOP 1000000000")}) tally")[0]["TotalRows"].to_i
|
30
|
+
if (options[:limit] + options[:offset]) >= total_rows
|
31
|
+
options[:limit] = (total_rows - options[:offset] >= 0) ? (total_rows - options[:offset]) : 0
|
32
|
+
end
|
33
|
+
sql.sub!(/^\s*SELECT(\s+DISTINCT)?/i, "SELECT * FROM (SELECT TOP #{options[:limit]} * FROM (SELECT\\1 TOP #{options[:limit] + options[:offset]} ")
|
34
|
+
sql << ") AS tmp1"
|
35
|
+
if options[:order]
|
36
|
+
options[:order] = options[:order].split(',').map do |field|
|
37
|
+
parts = field.split(" ")
|
38
|
+
tc = parts[0]
|
39
|
+
if sql =~ /\.\[/ and tc =~ /\./ # if column quoting used in query
|
40
|
+
tc.gsub!(/\./, '\\.\\[')
|
41
|
+
tc << '\\]'
|
42
|
+
end
|
43
|
+
if sql =~ /#{tc} AS (t\d_r\d\d?)/
|
44
|
+
parts[0] = $1
|
45
|
+
elsif parts[0] =~ /\w+\.(\w+)/
|
46
|
+
parts[0] = $1
|
47
|
+
end
|
48
|
+
parts.join(' ')
|
49
|
+
end.join(', ')
|
50
|
+
sql << " ORDER BY #{change_order_direction(options[:order])}) AS tmp2 ORDER BY #{options[:order]}"
|
51
|
+
else
|
52
|
+
sql << " ) AS tmp2"
|
53
|
+
end
|
54
|
+
elsif sql !~ /^\s*SELECT (@@|COUNT\()/i
|
55
|
+
sql.sub!(/^\s*SELECT(\s+DISTINCT)?/i) do
|
56
|
+
"SELECT#{$1} TOP #{options[:limit]}"
|
57
|
+
end unless options[:limit].nil?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/pg.rb
ADDED
@@ -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 application."
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file was generated by the "jdbc" generator, which is provided
|
2
|
+
# by the activerecord-jdbc-adapter gem.
|
3
|
+
#
|
4
|
+
# This file allows the JDBC drivers to be hooked into ActiveRecord
|
5
|
+
# such that you don't have to change anything else in your Rails
|
6
|
+
# application.
|
7
|
+
require 'jdbc_adapter' if defined?(JRUBY_VERSION)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# This file was generated by the "jdbc" generator, which is provided
|
2
|
+
# by the activerecord-jdbc-adapter gem.
|
3
|
+
#
|
4
|
+
# This file allows you to use Rails' various db:* tasks with JDBC.
|
5
|
+
if defined?(JRUBY_VERSION)
|
6
|
+
require 'jdbc_adapter'
|
7
|
+
require 'jdbc_adapter/rake_tasks'
|
8
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
def java_classpath_arg # myriad of ways to discover JRuby classpath
|
2
|
+
begin
|
3
|
+
cpath = Java::java.lang.System.getProperty('java.class.path').split(File::PATH_SEPARATOR)
|
4
|
+
cpath += Java::java.lang.System.getProperty('sun.boot.class.path').split(File::PATH_SEPARATOR)
|
5
|
+
jruby_cpath = cpath.compact.join(File::PATH_SEPARATOR)
|
6
|
+
rescue => e
|
7
|
+
end
|
8
|
+
unless jruby_cpath
|
9
|
+
jruby_cpath = ENV['JRUBY_PARENT_CLASSPATH'] || ENV['JRUBY_HOME'] &&
|
10
|
+
FileList["#{ENV['JRUBY_HOME']}/lib/*.jar"].join(File::PATH_SEPARATOR)
|
11
|
+
end
|
12
|
+
jruby_cpath ? "-cp \"#{jruby_cpath}\"" : ""
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Compile the native Java code."
|
16
|
+
task :java_compile do
|
17
|
+
pkg_classes = File.join(*%w(pkg classes))
|
18
|
+
jar_name = File.join(*%w(lib jdbc_adapter jdbc_adapter_internal.jar))
|
19
|
+
mkdir_p pkg_classes
|
20
|
+
sh "javac -target 1.5 -source 1.5 -d pkg/classes #{java_classpath_arg} #{FileList['src/java/**/*.java'].join(' ')}"
|
21
|
+
sh "jar cf #{jar_name} -C #{pkg_classes} ."
|
22
|
+
end
|
23
|
+
file "lib/jdbc_adapter/jdbc_adapter_internal.jar" => :java_compile
|
@@ -0,0 +1,90 @@
|
|
1
|
+
MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt",
|
2
|
+
"Rakefile", "LICENSE.txt", "lib/**/*.rb", "lib/jdbc_adapter/jdbc_adapter_internal.jar", "test/**/*.rb",
|
3
|
+
"lib/**/*.rake", "src/**/*.java", "rakelib/*.rake", "rails_generators/**/*"]
|
4
|
+
|
5
|
+
file "Manifest.txt" => :manifest
|
6
|
+
task :manifest do
|
7
|
+
File.open("Manifest.txt", "w") {|f| MANIFEST.each {|n| f << "#{n}\n"} }
|
8
|
+
end
|
9
|
+
Rake::Task['manifest'].invoke # Always regen manifest, so Hoe has up-to-date list of files
|
10
|
+
|
11
|
+
require File.dirname(__FILE__) + "/../lib/jdbc_adapter/version"
|
12
|
+
begin
|
13
|
+
require 'hoe'
|
14
|
+
Hoe.plugin :gemcutter
|
15
|
+
hoe = Hoe.spec("activerecord-jdbc-adapter") do |p|
|
16
|
+
p.version = JdbcAdapter::Version::VERSION
|
17
|
+
p.spec_extras[:platform] = Gem::Platform.new("java")
|
18
|
+
p.spec_extras[:files] = MANIFEST
|
19
|
+
p.rubyforge_name = "jruby-extras"
|
20
|
+
p.url = "http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter"
|
21
|
+
p.author = "Nick Sieger, Ola Bini and JRuby contributors"
|
22
|
+
p.email = "nick@nicksieger.com, ola.bini@gmail.com"
|
23
|
+
p.summary = "JDBC adapter for ActiveRecord, for use within JRuby on Rails."
|
24
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
25
|
+
p.description = p.paragraphs_of('README.txt', 0...1).join("\n\n")
|
26
|
+
end
|
27
|
+
hoe.spec.dependencies.delete_if { |dep| dep.name == "hoe" }
|
28
|
+
task :gemspec do
|
29
|
+
File.open("#{hoe.name}.gemspec", "w") {|f| f << hoe.spec.to_ruby }
|
30
|
+
end
|
31
|
+
task :package => :gemspec
|
32
|
+
rescue LoadError => le
|
33
|
+
puts le.to_s, *le.backtrace
|
34
|
+
puts "Problem loading Hoe; please check the error above to ensure that Hoe is installed correctly"
|
35
|
+
rescue => e
|
36
|
+
puts "ignoring error while loading Hoe: #{e.to_s}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def rake(*args)
|
40
|
+
ruby "-S", "rake", *args
|
41
|
+
end
|
42
|
+
|
43
|
+
%w(test package install_gem release clean).each do |task|
|
44
|
+
desc "Run rake #{task} on all available adapters and drivers"
|
45
|
+
task "all:#{task}" => task
|
46
|
+
end
|
47
|
+
|
48
|
+
(Dir["drivers/*/Rakefile"] + Dir["adapters/*/Rakefile"]).each do |rakefile|
|
49
|
+
dir = File.dirname(rakefile)
|
50
|
+
prefix = dir.sub(%r{/}, ':')
|
51
|
+
tasks = %w(package install_gem debug_gem clean gemspec)
|
52
|
+
tasks << "test" if File.directory?(File.join(dir, "test"))
|
53
|
+
tasks.each do |task|
|
54
|
+
desc "Run rake #{task} on #{dir}"
|
55
|
+
task "#{prefix}:#{task}" do
|
56
|
+
Dir.chdir(dir) do
|
57
|
+
rake task
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
task "#{File.dirname(dir)}:#{task}" => "#{prefix}:#{task}"
|
62
|
+
task "all:#{task}" => "#{prefix}:#{task}"
|
63
|
+
end
|
64
|
+
|
65
|
+
# Copy all generated gems to the top-level pkg directory for convenience
|
66
|
+
task "#{prefix}:package" do
|
67
|
+
FileList["#{dir}/pkg/*.gem"].each {|gem| cp gem, "pkg"}
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "Run rake release on #{dir}"
|
71
|
+
task "#{prefix}:release" do
|
72
|
+
Dir.chdir(dir) do
|
73
|
+
version = nil
|
74
|
+
if dir =~ /adapters/
|
75
|
+
version = ENV['VERSION']
|
76
|
+
else
|
77
|
+
Dir["lib/**/*.rb"].each do |file|
|
78
|
+
version ||= File.open(file) {|f| f.read =~ /VERSION = "([^"]+)"/ && $1}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
rake "release", "VERSION=#{version}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
# Only release adapters synchronously with main release. Drivers are versioned
|
85
|
+
# according to their JDBC driver versions.
|
86
|
+
if dir =~ /adapters/
|
87
|
+
task "adapters:release" => "#{prefix}:release"
|
88
|
+
task "all:release" => "#{prefix}:release"
|
89
|
+
end
|
90
|
+
end
|
data/rakelib/rails.rake
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
namespace :rails do
|
2
|
+
def _adapter(n)
|
3
|
+
case n
|
4
|
+
when /postgres/
|
5
|
+
'postgresql'
|
6
|
+
else
|
7
|
+
n
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def _driver(n)
|
12
|
+
case n
|
13
|
+
when /postgres/
|
14
|
+
'postgres'
|
15
|
+
else
|
16
|
+
n
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def _target(n)
|
21
|
+
case n
|
22
|
+
when /postgres/
|
23
|
+
'test_jdbcpostgresql'
|
24
|
+
else
|
25
|
+
"test_jdbc#{n}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
task :test => "java_compile" do
|
30
|
+
driver = ENV['DRIVER']
|
31
|
+
raise "need a DRIVER" unless driver
|
32
|
+
activerecord = ENV['RAILS']
|
33
|
+
raise "need location of RAILS source code" unless activerecord
|
34
|
+
activerecord = File.join(activerecord, 'activerecord') unless activerecord =~ /activerecord$/
|
35
|
+
ar_jdbc = File.expand_path(File.dirname(__FILE__) + '/..')
|
36
|
+
rubylib = "#{ar_jdbc}/lib:#{ar_jdbc}/drivers/#{_driver(driver)}/lib:#{ar_jdbc}/adapters/#{_adapter(driver)}/lib"
|
37
|
+
Dir.chdir(activerecord) do
|
38
|
+
rake "RUBYLIB=#{rubylib}", "#{_target(driver)}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/rakelib/test.rake
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.expand_path('../../test/helper', __FILE__)
|
2
|
+
if defined?(JRUBY_VERSION)
|
3
|
+
databases = [:test_mysql, :test_jdbc, :test_sqlite3]
|
4
|
+
if find_executable?("psql") && `psql -c '\\l'` && $?.exitstatus == 0
|
5
|
+
databases << :test_postgres
|
6
|
+
end
|
7
|
+
require File.expand_path('../../test/pick_rails_version', __FILE__)
|
8
|
+
if ActiveRecord::VERSION::MAJOR < 3
|
9
|
+
# These databases not working with Rails3/Arel yet
|
10
|
+
databases += [:test_derby, :test_hsqldb, :test_h2]
|
11
|
+
end
|
12
|
+
task :test => databases
|
13
|
+
else
|
14
|
+
task :test => [:test_mysql]
|
15
|
+
end
|
16
|
+
|
17
|
+
FileList['drivers/*'].each do |d|
|
18
|
+
next unless File.directory?(d)
|
19
|
+
driver = File.basename(d)
|
20
|
+
Rake::TestTask.new("test_#{driver}") do |t|
|
21
|
+
files = FileList["test/#{driver}*test.rb"]
|
22
|
+
if driver == "derby"
|
23
|
+
files << 'test/activerecord/connection_adapters/type_conversion_test.rb'
|
24
|
+
end
|
25
|
+
t.test_files = files
|
26
|
+
t.libs = []
|
27
|
+
if defined?(JRUBY_VERSION)
|
28
|
+
t.ruby_opts << "-rjdbc/#{driver}"
|
29
|
+
t.libs << "lib" << "#{d}/lib"
|
30
|
+
t.libs.push *FileList["adapters/#{driver}*/lib"]
|
31
|
+
end
|
32
|
+
t.libs << "test"
|
33
|
+
t.verbose = true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Rake::TestTask.new(:test_jdbc) do |t|
|
38
|
+
t.test_files = FileList['test/generic_jdbc_connection_test.rb', 'test/jndi_callbacks_test.rb']
|
39
|
+
t.libs << 'test' << 'drivers/mysql/lib'
|
40
|
+
end
|
41
|
+
|
42
|
+
Rake::TestTask.new(:test_jndi) do |t|
|
43
|
+
t.test_files = FileList['test/jndi_test.rb']
|
44
|
+
t.libs << 'test' << 'drivers/derby/lib'
|
45
|
+
end
|
46
|
+
|
47
|
+
task :test_postgresql => [:test_postgres]
|
48
|
+
task :test_pgsql => [:test_postgres]
|
49
|
+
|
50
|
+
# Ensure driver for these DBs is on your classpath
|
51
|
+
%w(oracle db2 cachedb mssql informix).each do |d|
|
52
|
+
Rake::TestTask.new("test_#{d}") do |t|
|
53
|
+
t.test_files = FileList["test/#{d}_simple_test.rb"]
|
54
|
+
t.libs = []
|
55
|
+
t.libs << 'lib' if defined?(JRUBY_VERSION)
|
56
|
+
t.libs << 'test'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Tests for JDBC adapters that don't require a database.
|
61
|
+
Rake::TestTask.new(:test_jdbc_adapters) do | t |
|
62
|
+
t.test_files = FileList[ 'test/jdbc_adapter/jdbc_sybase_test.rb' ]
|
63
|
+
t.libs << 'test'
|
64
|
+
end
|
65
|
+
|
66
|
+
# Ensure that the jTDS driver is in your classpath before launching rake
|
67
|
+
Rake::TestTask.new(:test_sybase_jtds) do |t|
|
68
|
+
t.test_files = FileList['test/sybase_jtds_simple_test.rb']
|
69
|
+
t.libs << 'test'
|
70
|
+
end
|
71
|
+
|
72
|
+
# Ensure that the jConnect driver is in your classpath before launching rake
|
73
|
+
Rake::TestTask.new(:test_sybase_jconnect) do |t|
|
74
|
+
t.test_files = FileList['test/sybase_jconnect_simple_test.rb']
|
75
|
+
t.libs << 'test'
|
76
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
**** BEGIN LICENSE BLOCK *****
|
3
|
+
* Copyright (c) 2006-2009 Nick Sieger <nick@nicksieger.com>
|
4
|
+
* Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
|
5
|
+
* Copyright (c) 2008-2009 Thomas E Enebo <enebo@acm.org>
|
6
|
+
*
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
* a copy of this software and associated documentation files (the
|
9
|
+
* "Software"), to deal in the Software without restriction, including
|
10
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
* the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be
|
16
|
+
* included in all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
***** END LICENSE BLOCK *****/
|
26
|
+
|
27
|
+
package jdbc_adapter;
|
28
|
+
|
29
|
+
import java.io.IOException;
|
30
|
+
|
31
|
+
import org.jruby.Ruby;
|
32
|
+
import org.jruby.RubyClass;
|
33
|
+
import org.jruby.RubyModule;
|
34
|
+
import org.jruby.RubyObjectAdapter;
|
35
|
+
import org.jruby.javasupport.JavaEmbedUtils;
|
36
|
+
import org.jruby.runtime.load.BasicLibraryService;
|
37
|
+
|
38
|
+
public class JdbcAdapterInternalService implements BasicLibraryService {
|
39
|
+
private static RubyObjectAdapter rubyApi;
|
40
|
+
|
41
|
+
public boolean basicLoad(final Ruby runtime) throws IOException {
|
42
|
+
RubyClass jdbcConnection = RubyJdbcConnection.createJdbcConnectionClass(runtime);
|
43
|
+
PostgresRubyJdbcConnection.createPostgresJdbcConnectionClass(runtime, jdbcConnection);
|
44
|
+
MssqlRubyJdbcConnection.createMssqlJdbcConnectionClass(runtime, jdbcConnection);
|
45
|
+
Sqlite3RubyJdbcConnection.createSqlite3JdbcConnectionClass(runtime, jdbcConnection);
|
46
|
+
RubyModule jdbcSpec = runtime.getOrCreateModule("JdbcSpec");
|
47
|
+
|
48
|
+
rubyApi = JavaEmbedUtils.newObjectAdapter();
|
49
|
+
JdbcMySQLSpec.load(jdbcSpec);
|
50
|
+
JdbcDerbySpec.load(jdbcSpec, rubyApi);
|
51
|
+
return true;
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/***** BEGIN LICENSE BLOCK *****
|
2
|
+
* Copyright (c) 2006-2007 Nick Sieger <nick@nicksieger.com>
|
3
|
+
* Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
|
4
|
+
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
* a copy of this software and associated documentation files (the
|
7
|
+
* "Software"), to deal in the Software without restriction, including
|
8
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
* the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be
|
14
|
+
* included in all copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
***** END LICENSE BLOCK *****/
|
24
|
+
|
25
|
+
package jdbc_adapter;
|
26
|
+
|
27
|
+
import java.sql.Connection;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Interface to be implemented in Ruby for retrieving a new connection
|
31
|
+
*
|
32
|
+
* @author nicksieger
|
33
|
+
*/
|
34
|
+
public interface JdbcConnectionFactory {
|
35
|
+
Connection newConnection();
|
36
|
+
}
|