activerecord-jdbc-adapter 0.9.7-java → 1.0.0.beta1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/History.txt +11 -0
  2. data/Manifest.txt +71 -38
  3. data/lib/active_record/connection_adapters/cachedb_adapter.rb +1 -1
  4. data/lib/active_record/connection_adapters/derby_adapter.rb +1 -13
  5. data/lib/active_record/connection_adapters/h2_adapter.rb +1 -13
  6. data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -13
  7. data/lib/active_record/connection_adapters/informix_adapter.rb +1 -1
  8. data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -661
  9. data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -1
  10. data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -13
  11. data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -13
  12. data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -1
  13. data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -13
  14. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -13
  15. data/lib/activerecord-jdbc-adapter.rb +2 -2
  16. data/lib/arjdbc.rb +29 -0
  17. data/lib/arjdbc/cachedb.rb +3 -0
  18. data/lib/arjdbc/cachedb/adapter.rb +20 -0
  19. data/lib/arjdbc/cachedb/connection_methods.rb +10 -0
  20. data/lib/arjdbc/db2.rb +2 -0
  21. data/lib/{jdbc_adapter/jdbc_db2.rb → arjdbc/db2/adapter.rb} +1 -17
  22. data/lib/arjdbc/derby.rb +7 -0
  23. data/lib/{jdbc_adapter/jdbc_derby.rb → arjdbc/derby/adapter.rb} +8 -26
  24. data/lib/arjdbc/derby/connection_methods.rb +18 -0
  25. data/lib/arjdbc/discover.rb +99 -0
  26. data/lib/arjdbc/firebird.rb +2 -0
  27. data/lib/{jdbc_adapter/jdbc_firebird.rb → arjdbc/firebird/adapter.rb} +12 -16
  28. data/lib/arjdbc/h2.rb +4 -0
  29. data/lib/arjdbc/h2/adapter.rb +15 -0
  30. data/lib/arjdbc/h2/connection_methods.rb +12 -0
  31. data/lib/arjdbc/hsqldb.rb +4 -0
  32. data/lib/{jdbc_adapter/jdbc_hsqldb.rb → arjdbc/hsqldb/adapter.rb} +6 -58
  33. data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
  34. data/lib/arjdbc/informix.rb +3 -0
  35. data/lib/{jdbc_adapter/jdbc_informix.rb → arjdbc/informix/adapter.rb} +6 -19
  36. data/lib/arjdbc/informix/connection_methods.rb +10 -0
  37. data/lib/arjdbc/jdbc.rb +2 -0
  38. data/lib/arjdbc/jdbc/adapter.rb +235 -0
  39. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  40. data/lib/arjdbc/jdbc/callbacks.rb +44 -0
  41. data/lib/arjdbc/jdbc/column.rb +38 -0
  42. data/lib/arjdbc/jdbc/compatibility.rb +51 -0
  43. data/lib/arjdbc/jdbc/connection.rb +97 -0
  44. data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
  45. data/lib/arjdbc/jdbc/core_ext.rb +24 -0
  46. data/lib/arjdbc/jdbc/discover.rb +18 -0
  47. data/lib/arjdbc/jdbc/driver.rb +44 -0
  48. data/lib/arjdbc/jdbc/extension.rb +47 -0
  49. data/lib/arjdbc/jdbc/java.rb +14 -0
  50. data/lib/{jdbc_adapter → arjdbc/jdbc}/jdbc.rake +0 -0
  51. data/lib/{jdbc_adapter → arjdbc/jdbc}/missing_functionality_helper.rb +5 -5
  52. data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
  53. data/lib/{jdbc_adapter → arjdbc/jdbc}/railtie.rb +1 -1
  54. data/lib/{jdbc_adapter → arjdbc/jdbc}/rake_tasks.rb +0 -0
  55. data/lib/arjdbc/jdbc/require_driver.rb +16 -0
  56. data/lib/arjdbc/jdbc/type_converter.rb +119 -0
  57. data/lib/arjdbc/mimer.rb +2 -0
  58. data/lib/{jdbc_adapter/jdbc_mimer.rb → arjdbc/mimer/adapter.rb} +16 -19
  59. data/lib/arjdbc/mssql.rb +4 -0
  60. data/lib/{jdbc_adapter/jdbc_mssql.rb → arjdbc/mssql/adapter.rb} +19 -31
  61. data/lib/arjdbc/mssql/connection_methods.rb +13 -0
  62. data/lib/{jdbc_adapter → arjdbc/mssql}/tsql_helper.rb +1 -1
  63. data/lib/arjdbc/mysql.rb +4 -0
  64. data/lib/arjdbc/mysql/adapter.rb +388 -0
  65. data/lib/arjdbc/mysql/connection_methods.rb +26 -0
  66. data/lib/arjdbc/oracle.rb +3 -0
  67. data/lib/{jdbc_adapter/jdbc_oracle.rb → arjdbc/oracle/adapter.rb} +9 -17
  68. data/lib/arjdbc/oracle/connection_methods.rb +11 -0
  69. data/lib/arjdbc/postgresql.rb +4 -0
  70. data/lib/{jdbc_adapter/jdbc_postgre.rb → arjdbc/postgresql/adapter.rb} +7 -36
  71. data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
  72. data/lib/arjdbc/sqlite3.rb +4 -0
  73. data/lib/{jdbc_adapter/jdbc_sqlite3.rb → arjdbc/sqlite3/adapter.rb} +106 -104
  74. data/lib/arjdbc/sqlite3/connection_methods.rb +33 -0
  75. data/lib/arjdbc/sybase.rb +2 -0
  76. data/lib/arjdbc/sybase/adapter.rb +46 -0
  77. data/lib/arjdbc/version.rb +8 -0
  78. data/lib/jdbc_adapter.rb +2 -27
  79. data/lib/jdbc_adapter/version.rb +3 -5
  80. data/rails_generators/templates/config/initializers/jdbc.rb +1 -1
  81. data/rakelib/compile.rake +3 -2
  82. data/rakelib/package.rake +3 -3
  83. data/src/java/{jdbc_adapter/JdbcDerbySpec.java → arjdbc/derby/DerbyModule.java} +32 -32
  84. data/src/java/{jdbc_adapter/JdbcAdapterInternalService.java → arjdbc/jdbc/AdapterJavaService.java} +13 -7
  85. data/src/java/{jdbc_adapter → arjdbc/jdbc}/JdbcConnectionFactory.java +6 -6
  86. data/src/java/{jdbc_adapter → arjdbc/jdbc}/RubyJdbcConnection.java +91 -16
  87. data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
  88. data/src/java/{jdbc_adapter → arjdbc/mssql}/MssqlRubyJdbcConnection.java +5 -2
  89. data/src/java/{jdbc_adapter/JdbcMySQLSpec.java → arjdbc/mysql/MySQLModule.java} +12 -12
  90. data/src/java/{jdbc_adapter/PostgresRubyJdbcConnection.java → arjdbc/postgresql/PostgresqlRubyJdbcConnection.java} +11 -9
  91. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
  92. data/test/abstract_db_create.rb +4 -1
  93. data/test/activerecord/connection_adapters/type_conversion_test.rb +1 -1
  94. data/test/db/cachedb.rb +0 -0
  95. data/test/db/derby.rb +12 -14
  96. data/test/db/hsqldb.rb +3 -2
  97. data/test/db/jndi_config.rb +4 -4
  98. data/test/db/sqlite3.rb +2 -6
  99. data/test/db2_simple_test.rb +23 -0
  100. data/test/derby_migration_test.rb +50 -3
  101. data/test/jdbc_common.rb +1 -1
  102. data/test/jndi_callbacks_test.rb +1 -0
  103. data/test/postgres_nonseq_pkey_test.rb +0 -2
  104. data/test/postgres_schema_search_path_test.rb +0 -2
  105. data/test/simple.rb +3 -3
  106. data/test/sybase_jtds_simple_test.rb +22 -0
  107. metadata +82 -46
  108. data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +0 -26
  109. data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
  110. data/lib/jdbc_adapter/jdbc_cachedb.rb +0 -33
  111. data/lib/jdbc_adapter/jdbc_mysql.rb +0 -260
  112. data/lib/jdbc_adapter/jdbc_sybase.rb +0 -50
  113. data/src/java/jdbc_adapter/SQLBlock.java +0 -27
  114. data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +0 -41
  115. data/test/jdbc_adapter/jdbc_db2_test.rb +0 -26
  116. data/test/jdbc_adapter/jdbc_sybase_test.rb +0 -33
  117. data/test/minirunit.rb +0 -109
  118. data/test/minirunit/testConnect.rb +0 -14
  119. data/test/minirunit/testH2.rb +0 -73
  120. data/test/minirunit/testHsqldb.rb +0 -73
  121. data/test/minirunit/testLoadActiveRecord.rb +0 -3
  122. data/test/minirunit/testMysql.rb +0 -83
  123. data/test/minirunit/testRawSelect.rb +0 -24
@@ -0,0 +1,33 @@
1
+ # Don't need to load native sqlite3 adapter
2
+ $LOADED_FEATURES << "active_record/connection_adapters/sqlite_adapter.rb"
3
+ $LOADED_FEATURES << "active_record/connection_adapters/sqlite3_adapter.rb"
4
+
5
+ class ActiveRecord::Base
6
+ class << self
7
+ def sqlite3_connection(config)
8
+ require "arjdbc/sqlite3"
9
+
10
+ parse_sqlite3_config!(config)
11
+
12
+ config[:url] ||= "jdbc:sqlite:#{config[:database]}"
13
+ config[:driver] ||= "org.sqlite.JDBC"
14
+ config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter
15
+ jdbc_connection(config)
16
+ end
17
+
18
+ def parse_sqlite3_config!(config)
19
+ config[:database] ||= config[:dbfile]
20
+
21
+ # Allow database path relative to RAILS_ROOT, but only if
22
+ # the database path is not the special path that tells
23
+ # Sqlite to build a database only in memory.
24
+ rails_root_defined = defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
25
+ if rails_root_defined && ':memory:' != config[:database]
26
+ rails_root = defined?(Rails.root) ? Rails.root : RAILS_ROOT
27
+ config[:database] = File.expand_path(config[:database], rails_root)
28
+ end
29
+ end
30
+
31
+ alias_method :jdbcsqlite3_connection, :sqlite3_connection
32
+ end
33
+ end
@@ -0,0 +1,2 @@
1
+ require 'arjdbc/jdbc'
2
+ require 'arjdbc/sybase/adapter.rb'
@@ -0,0 +1,46 @@
1
+ module ArJdbc
2
+ module Sybase
3
+ def add_limit_offset!(sql, options) # :nodoc:
4
+ @limit = options[:limit]
5
+ @offset = options[:offset]
6
+ if use_temp_table?
7
+ # Use temp table to hack offset with Sybase
8
+ sql.sub!(/ FROM /i, ' INTO #artemp FROM ')
9
+ elsif zero_limit?
10
+ # "SET ROWCOUNT 0" turns off limits, so we havesy
11
+ # to use a cheap trick.
12
+ if sql =~ /WHERE/i
13
+ sql.sub!(/WHERE/i, 'WHERE 1 = 2 AND ')
14
+ elsif sql =~ /ORDER\s+BY/i
15
+ sql.sub!(/ORDER\s+BY/i, 'WHERE 1 = 2 ORDER BY')
16
+ else
17
+ sql << 'WHERE 1 = 2'
18
+ end
19
+ end
20
+ end
21
+
22
+ # If limit is not set at all, we can ignore offset;
23
+ # if limit *is* set but offset is zero, use normal select
24
+ # with simple SET ROWCOUNT. Thus, only use the temp table
25
+ # if limit is set and offset > 0.
26
+ def use_temp_table?
27
+ !@limit.nil? && !@offset.nil? && @offset > 0
28
+ end
29
+
30
+ def zero_limit?
31
+ !@limit.nil? && @limit == 0
32
+ end
33
+
34
+ def modify_types(tp) #:nodoc:
35
+ tp[:primary_key] = "NUMERIC(22,0) IDENTITY PRIMARY KEY"
36
+ tp[:integer][:limit] = nil
37
+ tp[:boolean] = {:name => "bit"}
38
+ tp[:binary] = {:name => "image"}
39
+ tp
40
+ end
41
+
42
+ def remove_index(table_name, options = {})
43
+ execute "DROP INDEX #{table_name}.#{index_name(table_name, options)}"
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ module ArJdbc
2
+ module Version
3
+ VERSION = "1.0.0.beta1"
4
+ end
5
+ end
6
+ # Compatibility with older versions of ar-jdbc for other extensions out there
7
+ JdbcAdapter = ArJdbc
8
+ JdbcSpec = ArJdbc
@@ -1,27 +1,2 @@
1
- if defined?(JRUBY_VERSION)
2
- begin
3
- tried_gem ||= false
4
- require 'active_record/version'
5
- rescue LoadError
6
- raise if tried_gem
7
- require 'rubygems'
8
- gem 'activerecord'
9
- tried_gem = true
10
- retry
11
- end
12
- if ActiveRecord::VERSION::MAJOR < 2
13
- if defined?(RAILS_CONNECTION_ADAPTERS)
14
- RAILS_CONNECTION_ADAPTERS << %q(jdbc)
15
- else
16
- RAILS_CONNECTION_ADAPTERS = %w(jdbc)
17
- end
18
- if ActiveRecord::VERSION::MAJOR == 1 && ActiveRecord::VERSION::MINOR == 14
19
- require 'active_record/connection_adapters/jdbc_adapter'
20
- end
21
- else
22
- require 'active_record'
23
- require 'active_record/connection_adapters/jdbc_adapter'
24
- end
25
- else
26
- warn "ActiveRecord-JDBC is for use with JRuby only"
27
- end
1
+ warn "DEPRECATED: require 'arjdbc' instead of 'jdbc_adapter'."
2
+ require 'arjdbc'
@@ -1,5 +1,3 @@
1
- module JdbcAdapter
2
- module Version
3
- VERSION = "0.9.7"
4
- end
5
- end
1
+ warn "DEPRECATED: require 'arjdbc/version' instead of 'jdbc_adapter/version'."
2
+ require 'arjdbc/version'
3
+
@@ -4,4 +4,4 @@
4
4
  # This file allows the JDBC drivers to be hooked into ActiveRecord
5
5
  # such that you don't have to change anything else in your Rails
6
6
  # application.
7
- require 'jdbc_adapter' if defined?(JRUBY_VERSION)
7
+ require 'arjdbc' if defined?(JRUBY_VERSION)
@@ -12,12 +12,13 @@ def java_classpath_arg # myriad of ways to discover JRuby classpath
12
12
  jruby_cpath ? "-cp \"#{jruby_cpath}\"" : ""
13
13
  end
14
14
 
15
+ jar_name = File.join(*%w(lib arjdbc jdbc adapter_java.jar))
16
+
15
17
  desc "Compile the native Java code."
16
18
  task :java_compile do
17
19
  pkg_classes = File.join(*%w(pkg classes))
18
- jar_name = File.join(*%w(lib jdbc_adapter jdbc_adapter_internal.jar))
19
20
  mkdir_p pkg_classes
20
21
  sh "javac -target 1.5 -source 1.5 -d pkg/classes #{java_classpath_arg} #{FileList['src/java/**/*.java'].join(' ')}"
21
22
  sh "jar cf #{jar_name} -C #{pkg_classes} ."
22
23
  end
23
- file "lib/jdbc_adapter/jdbc_adapter_internal.jar" => :java_compile
24
+ file jar_name => :java_compile
@@ -1,5 +1,5 @@
1
1
  MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt",
2
- "Rakefile", "LICENSE.txt", "lib/**/*.rb", "lib/jdbc_adapter/jdbc_adapter_internal.jar", "test/**/*.rb",
2
+ "Rakefile", "LICENSE.txt", "lib/**/*.rb", "lib/arjdbc/jdbc/adapter_java.jar", "test/**/*.rb",
3
3
  "lib/**/*.rake", "src/**/*.java", "rakelib/*.rake", "rails_generators/**/*"]
4
4
 
5
5
  file "Manifest.txt" => :manifest
@@ -8,12 +8,12 @@ task :manifest do
8
8
  end
9
9
  Rake::Task['manifest'].invoke # Always regen manifest, so Hoe has up-to-date list of files
10
10
 
11
- require File.dirname(__FILE__) + "/../lib/jdbc_adapter/version"
11
+ require File.dirname(__FILE__) + "/../lib/arjdbc/version"
12
12
  begin
13
13
  require 'hoe'
14
14
  Hoe.plugin :gemcutter
15
15
  hoe = Hoe.spec("activerecord-jdbc-adapter") do |p|
16
- p.version = JdbcAdapter::Version::VERSION
16
+ p.version = ArJdbc::Version::VERSION
17
17
  p.spec_extras[:platform] = Gem::Platform.new("java")
18
18
  p.spec_extras[:files] = MANIFEST
19
19
  p.rubyforge_name = "jruby-extras"
@@ -1,7 +1,7 @@
1
1
  /***** BEGIN LICENSE BLOCK *****
2
- * Copyright (c) 2006-2007 Nick Sieger <nick@nicksieger.com>
2
+ * Copyright (c) 2006-2007, 2010 Nick Sieger <nick@nicksieger.com>
3
3
  * Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
4
- *
4
+ *
5
5
  * Permission is hereby granted, free of charge, to any person obtaining
6
6
  * a copy of this software and associated documentation files (the
7
7
  * "Software"), to deal in the Software without restriction, including
@@ -9,10 +9,10 @@
9
9
  * distribute, sublicense, and/or sell copies of the Software, and to
10
10
  * permit persons to whom the Software is furnished to do so, subject to
11
11
  * the following conditions:
12
- *
12
+ *
13
13
  * The above copyright notice and this permission notice shall be
14
14
  * included in all copies or substantial portions of the Software.
15
- *
15
+ *
16
16
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
17
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
18
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -22,33 +22,33 @@
22
22
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  ***** END LICENSE BLOCK *****/
24
24
 
25
- package jdbc_adapter;
25
+ package arjdbc.derby;
26
+
27
+ import java.sql.SQLException;
28
+
29
+ import arjdbc.jdbc.RubyJdbcConnection;
26
30
 
27
31
  import org.jruby.Ruby;
28
- import org.jruby.RubyModule;
29
- import org.jruby.RubyString;
30
- import org.jruby.RubyFloat;
31
- import org.jruby.RubyFixnum;
32
+ import org.jruby.RubyBigDecimal;
32
33
  import org.jruby.RubyBignum;
33
34
  import org.jruby.RubyBoolean;
34
- import org.jruby.RubyBigDecimal;
35
- import org.jruby.RubyRange;
35
+ import org.jruby.RubyFixnum;
36
+ import org.jruby.RubyFloat;
37
+ import org.jruby.RubyModule;
36
38
  import org.jruby.RubyNumeric;
37
-
38
- import org.jruby.runtime.builtin.IRubyObject;
39
-
40
- import org.jruby.util.ByteList;
41
-
42
- import java.sql.SQLException;
43
39
  import org.jruby.RubyObjectAdapter;
40
+ import org.jruby.RubyRange;
41
+ import org.jruby.RubyString;
44
42
  import org.jruby.anno.JRubyMethod;
45
43
  import org.jruby.runtime.ThreadContext;
44
+ import org.jruby.runtime.builtin.IRubyObject;
45
+ import org.jruby.util.ByteList;
46
46
 
47
- public class JdbcDerbySpec {
47
+ public class DerbyModule {
48
48
  private static RubyObjectAdapter rubyApi;
49
- public static void load(RubyModule jdbcSpec, RubyObjectAdapter adapter) {
50
- RubyModule derby = jdbcSpec.defineModuleUnder("Derby");
51
- derby.defineAnnotatedMethods(JdbcDerbySpec.class);
49
+ public static void load(RubyModule arJdbc, RubyObjectAdapter adapter) {
50
+ RubyModule derby = arJdbc.defineModuleUnder("Derby");
51
+ derby.defineAnnotatedMethods(DerbyModule.class);
52
52
  RubyModule column = derby.defineModuleUnder("Column");
53
53
  column.defineAnnotatedMethods(Column.class);
54
54
  rubyApi = adapter;
@@ -131,7 +131,7 @@ public class JdbcDerbySpec {
131
131
  return quote_string_with_surround(runtime, "'", RubyString.objAsString(context, value), "'");
132
132
  }
133
133
  }
134
- }
134
+ }
135
135
  return super_quote(context, recv, runtime, value, runtime.getNil());
136
136
  }
137
137
 
@@ -141,25 +141,25 @@ public class JdbcDerbySpec {
141
141
  if (value.respondsTo("quoted_id")) {
142
142
  return rubyApi.callMethod(value, "quoted_id");
143
143
  }
144
-
144
+
145
145
  IRubyObject type = (col.isNil()) ? col : rubyApi.callMethod(col, "type");
146
- RubyModule multibyteChars = (RubyModule)
146
+ RubyModule multibyteChars = (RubyModule)
147
147
  ((RubyModule) ((RubyModule) runtime.getModule("ActiveSupport")).getConstant("Multibyte")).getConstantAt("Chars");
148
148
  if (value instanceof RubyString || rubyApi.isKindOf(value, multibyteChars)) {
149
149
  RubyString svalue = RubyString.objAsString(context, value);
150
150
  if (type == runtime.newSymbol("binary") && col.getType().respondsTo("string_to_binary")) {
151
- return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(col.getType(), "string_to_binary", svalue)), "'");
151
+ return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(col.getType(), "string_to_binary", svalue)), "'");
152
152
  } else if (type == runtime.newSymbol("integer") || type == runtime.newSymbol("float")) {
153
153
  return RubyString.objAsString(context, ((type == runtime.newSymbol("integer")) ?
154
- rubyApi.callMethod(svalue, "to_i") :
154
+ rubyApi.callMethod(svalue, "to_i") :
155
155
  rubyApi.callMethod(svalue, "to_f")));
156
156
  } else {
157
- return quote_string_with_surround(runtime, "'", svalue, "'");
157
+ return quote_string_with_surround(runtime, "'", svalue, "'");
158
158
  }
159
159
  } else if (value.isNil()) {
160
160
  return runtime.newString(NULL);
161
161
  } else if (value instanceof RubyBoolean) {
162
- return (value.isTrue() ?
162
+ return (value.isTrue() ?
163
163
  (type == runtime.newSymbol(":integer")) ? runtime.newString("1") : rubyApi.callMethod(recv, "quoted_true") :
164
164
  (type == runtime.newSymbol(":integer")) ? runtime.newString("0") : rubyApi.callMethod(recv, "quoted_false"));
165
165
  } else if((value instanceof RubyFloat) || (value instanceof RubyFixnum) || (value instanceof RubyBignum)) {
@@ -167,7 +167,7 @@ public class JdbcDerbySpec {
167
167
  } else if(value instanceof RubyBigDecimal) {
168
168
  return rubyApi.callMethod(value, "to_s", runtime.newString("F"));
169
169
  } else if (rubyApi.callMethod(value, "acts_like?", runtime.newString("date")).isTrue() || rubyApi.callMethod(value, "acts_like?", runtime.newString("time")).isTrue()) {
170
- return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(recv, "quoted_date", value)), "'");
170
+ return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(recv, "quoted_date", value)), "'");
171
171
  } else {
172
172
  return quote_string_with_surround(runtime, "'", (RubyString)(rubyApi.callMethod(value, "to_yaml")), "'");
173
173
  }
@@ -231,14 +231,14 @@ public class JdbcDerbySpec {
231
231
  public static IRubyObject quote_string(IRubyObject recv, IRubyObject string) {
232
232
  boolean replacementFound = false;
233
233
  ByteList bl = ((RubyString) string).getByteList();
234
-
234
+
235
235
  for(int i = bl.begin; i < bl.begin + bl.realSize; i++) {
236
236
  switch (bl.bytes[i]) {
237
237
  case '\'': break;
238
238
  default: continue;
239
239
  }
240
-
241
- // On first replacement allocate a different bytelist so we don't manip original
240
+
241
+ // On first replacement allocate a different bytelist so we don't manip original
242
242
  if(!replacementFound) {
243
243
  i-= bl.begin;
244
244
  bl = new ByteList(bl);
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  **** BEGIN LICENSE BLOCK *****
3
- * Copyright (c) 2006-2009 Nick Sieger <nick@nicksieger.com>
3
+ * Copyright (c) 2006-2010 Nick Sieger <nick@nicksieger.com>
4
4
  * Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
5
5
  * Copyright (c) 2008-2009 Thomas E Enebo <enebo@acm.org>
6
6
  *
@@ -24,10 +24,16 @@
24
24
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
25
  ***** END LICENSE BLOCK *****/
26
26
 
27
- package jdbc_adapter;
27
+ package arjdbc.jdbc;
28
28
 
29
29
  import java.io.IOException;
30
30
 
31
+ import arjdbc.postgresql.PostgresqlRubyJdbcConnection;
32
+ import arjdbc.mssql.MssqlRubyJdbcConnection;
33
+ import arjdbc.sqlite3.Sqlite3RubyJdbcConnection;
34
+ import arjdbc.mysql.MySQLModule;
35
+ import arjdbc.derby.DerbyModule;
36
+
31
37
  import org.jruby.Ruby;
32
38
  import org.jruby.RubyClass;
33
39
  import org.jruby.RubyModule;
@@ -35,19 +41,19 @@ import org.jruby.RubyObjectAdapter;
35
41
  import org.jruby.javasupport.JavaEmbedUtils;
36
42
  import org.jruby.runtime.load.BasicLibraryService;
37
43
 
38
- public class JdbcAdapterInternalService implements BasicLibraryService {
44
+ public class AdapterJavaService implements BasicLibraryService {
39
45
  private static RubyObjectAdapter rubyApi;
40
46
 
41
47
  public boolean basicLoad(final Ruby runtime) throws IOException {
42
48
  RubyClass jdbcConnection = RubyJdbcConnection.createJdbcConnectionClass(runtime);
43
- PostgresRubyJdbcConnection.createPostgresJdbcConnectionClass(runtime, jdbcConnection);
49
+ PostgresqlRubyJdbcConnection.createPostgresqlJdbcConnectionClass(runtime, jdbcConnection);
44
50
  MssqlRubyJdbcConnection.createMssqlJdbcConnectionClass(runtime, jdbcConnection);
45
51
  Sqlite3RubyJdbcConnection.createSqlite3JdbcConnectionClass(runtime, jdbcConnection);
46
- RubyModule jdbcSpec = runtime.getOrCreateModule("JdbcSpec");
52
+ RubyModule arJdbc = runtime.getOrCreateModule("ArJdbc");
47
53
 
48
54
  rubyApi = JavaEmbedUtils.newObjectAdapter();
49
- JdbcMySQLSpec.load(jdbcSpec);
50
- JdbcDerbySpec.load(jdbcSpec, rubyApi);
55
+ MySQLModule.load(arJdbc);
56
+ DerbyModule.load(arJdbc, rubyApi);
51
57
  return true;
52
58
  }
53
59
  }
@@ -1,7 +1,7 @@
1
1
  /***** BEGIN LICENSE BLOCK *****
2
- * Copyright (c) 2006-2007 Nick Sieger <nick@nicksieger.com>
2
+ * Copyright (c) 2006-2010 Nick Sieger <nick@nicksieger.com>
3
3
  * Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
4
- *
4
+ *
5
5
  * Permission is hereby granted, free of charge, to any person obtaining
6
6
  * a copy of this software and associated documentation files (the
7
7
  * "Software"), to deal in the Software without restriction, including
@@ -9,10 +9,10 @@
9
9
  * distribute, sublicense, and/or sell copies of the Software, and to
10
10
  * permit persons to whom the Software is furnished to do so, subject to
11
11
  * the following conditions:
12
- *
12
+ *
13
13
  * The above copyright notice and this permission notice shall be
14
14
  * included in all copies or substantial portions of the Software.
15
- *
15
+ *
16
16
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
17
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
18
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -22,13 +22,13 @@
22
22
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  ***** END LICENSE BLOCK *****/
24
24
 
25
- package jdbc_adapter;
25
+ package arjdbc.jdbc;
26
26
 
27
27
  import java.sql.Connection;
28
28
 
29
29
  /**
30
30
  * Interface to be implemented in Ruby for retrieving a new connection
31
- *
31
+ *
32
32
  * @author nicksieger
33
33
  */
34
34
  public interface JdbcConnectionFactory {
@@ -23,7 +23,7 @@
23
23
  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
24
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
25
  ***** END LICENSE BLOCK *****/
26
- package jdbc_adapter;
26
+ package arjdbc.jdbc;
27
27
 
28
28
  import java.io.ByteArrayInputStream;
29
29
  import java.io.IOException;
@@ -68,6 +68,7 @@ import org.jruby.javasupport.Java;
68
68
  import org.jruby.javasupport.JavaObject;
69
69
  import org.jruby.runtime.Arity;
70
70
  import org.jruby.runtime.Block;
71
+ import org.jruby.javasupport.util.RuntimeHelpers;
71
72
 
72
73
  /**
73
74
  * Part of our ActiveRecord::ConnectionAdapters::Connection impl.
@@ -197,15 +198,54 @@ public class RubyJdbcConnection extends RubyObject {
197
198
  return setConnection(null);
198
199
  }
199
200
 
201
+ @JRubyMethod
202
+ public IRubyObject execute(final ThreadContext context, final IRubyObject sql) {
203
+ return (IRubyObject) withConnectionAndRetry(context, new SQLBlock() {
204
+ public Object call(Connection c) throws SQLException {
205
+ Statement stmt = null;
206
+ String query = rubyApi.convertToRubyString(sql).getUnicodeValue();
207
+ try {
208
+ stmt = c.createStatement();
209
+ if (stmt.execute(query)) {
210
+ return unmarshalResult(context, c.getMetaData(), stmt.getResultSet(), false);
211
+ } else {
212
+ IRubyObject key = context.getRuntime().getNil();
213
+ if (c.getMetaData().supportsGetGeneratedKeys()) {
214
+ key = unmarshal_id_result(context.getRuntime(), stmt.getGeneratedKeys());
215
+ }
216
+ if (key.isNil()) {
217
+ return context.getRuntime().newFixnum(stmt.getUpdateCount());
218
+ } else {
219
+ return key;
220
+ }
221
+ }
222
+ } catch (SQLException sqe) {
223
+ if (context.getRuntime().isDebug()) {
224
+ System.out.println("Error SQL: " + query);
225
+ }
226
+ throw sqe;
227
+ } finally {
228
+ close(stmt);
229
+ }
230
+ }
231
+ });
232
+ }
233
+
200
234
  @JRubyMethod(name = "execute_id_insert", required = 2)
201
- public IRubyObject execute_id_insert(ThreadContext context, final IRubyObject sql,
235
+ public IRubyObject execute_id_insert(final ThreadContext context, final IRubyObject sql,
202
236
  final IRubyObject id) throws SQLException {
203
237
  return (IRubyObject) withConnectionAndRetry(context, new SQLBlock() {
204
238
  public Object call(Connection c) throws SQLException {
205
- PreparedStatement ps = c.prepareStatement(rubyApi.convertToRubyString(sql).getUnicodeValue());
239
+ String insert = rubyApi.convertToRubyString(sql).getUnicodeValue();
240
+ PreparedStatement ps = c.prepareStatement(insert);
206
241
  try {
207
242
  ps.setLong(1, RubyNumeric.fix2long(id));
208
243
  ps.executeUpdate();
244
+ } catch (SQLException sqe) {
245
+ if (context.getRuntime().isDebug()) {
246
+ System.out.println("Error SQL: " + insert);
247
+ }
248
+ throw sqe;
209
249
  } finally {
210
250
  close(ps);
211
251
  }
@@ -220,10 +260,16 @@ public class RubyJdbcConnection extends RubyObject {
220
260
  return (IRubyObject) withConnectionAndRetry(context, new SQLBlock() {
221
261
  public Object call(Connection c) throws SQLException {
222
262
  Statement stmt = null;
263
+ String insert = rubyApi.convertToRubyString(sql).getUnicodeValue();
223
264
  try {
224
265
  stmt = c.createStatement();
225
- stmt.executeUpdate(rubyApi.convertToRubyString(sql).getUnicodeValue(), Statement.RETURN_GENERATED_KEYS);
266
+ stmt.executeUpdate(insert, Statement.RETURN_GENERATED_KEYS);
226
267
  return unmarshal_id_result(context.getRuntime(), stmt.getGeneratedKeys());
268
+ } catch (SQLException sqe) {
269
+ if (context.getRuntime().isDebug()) {
270
+ System.out.println("Error SQL: " + insert);
271
+ }
272
+ throw sqe;
227
273
  } finally {
228
274
  close(stmt);
229
275
  }
@@ -257,6 +303,11 @@ public class RubyJdbcConnection extends RubyObject {
257
303
  stmt = c.createStatement();
258
304
  stmt.setMaxRows(maxRows);
259
305
  return unmarshalResult(context, metadata, stmt.executeQuery(query), false);
306
+ } catch (SQLException sqe) {
307
+ if (context.getRuntime().isDebug()) {
308
+ System.out.println("Error SQL: " + query);
309
+ }
310
+ throw sqe;
260
311
  } finally {
261
312
  close(stmt);
262
313
  }
@@ -270,9 +321,15 @@ public class RubyJdbcConnection extends RubyObject {
270
321
  return (IRubyObject) withConnectionAndRetry(context, new SQLBlock() {
271
322
  public Object call(Connection c) throws SQLException {
272
323
  Statement stmt = null;
324
+ String update = rubyApi.convertToRubyString(sql).getUnicodeValue();
273
325
  try {
274
326
  stmt = c.createStatement();
275
- return context.getRuntime().newFixnum((long)stmt.executeUpdate(rubyApi.convertToRubyString(sql).getUnicodeValue()));
327
+ return context.getRuntime().newFixnum((long)stmt.executeUpdate(update));
328
+ } catch (SQLException sqe) {
329
+ if (context.getRuntime().isDebug()) {
330
+ System.out.println("Error SQL: " + update);
331
+ }
332
+ throw sqe;
276
333
  } finally {
277
334
  close(stmt);
278
335
  }
@@ -652,6 +709,14 @@ public class RubyJdbcConnection extends RubyObject {
652
709
  return conn;
653
710
  }
654
711
 
712
+ protected IRubyObject getAdapter(ThreadContext context) {
713
+ return callMethod(context, "adapter");
714
+ }
715
+
716
+ protected IRubyObject getJdbcColumnClass(ThreadContext context) {
717
+ return getAdapter(context).callMethod(context, "jdbc_column_class");
718
+ }
719
+
655
720
  protected JdbcConnectionFactory getConnectionFactory() throws RaiseException {
656
721
  IRubyObject connection_factory = getInstanceVariable("@connection_factory");
657
722
  JdbcConnectionFactory factory = null;
@@ -943,6 +1008,9 @@ public class RubyJdbcConnection extends RubyObject {
943
1008
  if (str.endsWith(" 00:00:00.0")) {
944
1009
  str = str.substring(0, str.length() - (" 00:00:00.0".length()));
945
1010
  }
1011
+ if (str.endsWith(".0")) {
1012
+ str = str.substring(0, str.length() - (".0".length()));
1013
+ }
946
1014
 
947
1015
  return RubyString.newUnicodeString(runtime, str);
948
1016
  }
@@ -1005,7 +1073,7 @@ public class RubyJdbcConnection extends RubyObject {
1005
1073
  boolean isOracle = clzName.indexOf("oracle") != -1 || clzName.indexOf("oci") != -1;
1006
1074
 
1007
1075
  RubyHash types = (RubyHash) native_database_types();
1008
- IRubyObject jdbcCol = getConnectionAdapters(runtime).getConstant("JdbcColumn");
1076
+ IRubyObject jdbcCol = getJdbcColumnClass(context);
1009
1077
 
1010
1078
  while (pkeys.next()) {
1011
1079
  pkeyNames.add(pkeys.getString(COLUMN_NAME));
@@ -1024,13 +1092,6 @@ public class RubyJdbcConnection extends RubyObject {
1024
1092
  });
1025
1093
  columns.add(column);
1026
1094
 
1027
- IRubyObject tp = (IRubyObject)types.fastARef(column.callMethod(context,"type"));
1028
- if (tp != null && !tp.isNil() && tp.callMethod(context, "[]", runtime.newSymbol("limit")).isNil()) {
1029
- column.callMethod(context, "limit=", runtime.getNil());
1030
- if(!column.callMethod(context, "type").equals(runtime.newSymbol("decimal"))) {
1031
- column.callMethod(context, "precision=", runtime.getNil());
1032
- }
1033
- }
1034
1095
  if (pkeyNames.contains(colName)) {
1035
1096
  column.callMethod(context, "primary=", runtime.getTrue());
1036
1097
  }
@@ -1089,6 +1150,11 @@ public class RubyJdbcConnection extends RubyObject {
1089
1150
  while (toWrap.getCause() != null && toWrap.getCause() != toWrap) {
1090
1151
  toWrap = toWrap.getCause();
1091
1152
  }
1153
+
1154
+ if (context.getRuntime().isDebug()) {
1155
+ toWrap.printStackTrace(System.out);
1156
+ }
1157
+
1092
1158
  i++;
1093
1159
  if (autoCommit) {
1094
1160
  if (i == 1) {
@@ -1108,9 +1174,18 @@ public class RubyJdbcConnection extends RubyObject {
1108
1174
  throw wrap(context, toWrap);
1109
1175
  }
1110
1176
 
1111
- private static RuntimeException wrap(ThreadContext context, Throwable exception) {
1112
- RubyClass err = context.getRuntime().getModule("ActiveRecord").getClass("ActiveRecordError");
1113
- return (RuntimeException) new RaiseException(context.getRuntime(), err, exception.getMessage(), false).initCause(exception);
1177
+ protected RuntimeException wrap(ThreadContext context, Throwable exception) {
1178
+ Ruby runtime = context.getRuntime();
1179
+ RaiseException arError = new RaiseException(runtime, runtime.getModule("ActiveRecord").getClass("JDBCError"),
1180
+ exception.getMessage(), true);
1181
+ arError.initCause(exception);
1182
+ if (exception instanceof SQLException) {
1183
+ RuntimeHelpers.invoke(context, arError.getException(),
1184
+ "errno=", runtime.newFixnum(((SQLException) exception).getErrorCode()));
1185
+ RuntimeHelpers.invoke(context, arError.getException(),
1186
+ "sql_exception=", JavaEmbedUtils.javaToRuby(runtime, exception));
1187
+ }
1188
+ return (RuntimeException) arError;
1114
1189
  }
1115
1190
 
1116
1191
  private IRubyObject wrappedConnection(Connection c) {