kb-activerecord-jdbc-adapter 0.9.7.1-java → 1.0.0.beta1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/Manifest.txt +71 -38
- data/lib/active_record/connection_adapters/cachedb_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -661
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -13
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -13
- data/lib/activerecord-jdbc-adapter.rb +2 -2
- data/lib/arjdbc/cachedb/adapter.rb +20 -0
- data/lib/arjdbc/cachedb/connection_methods.rb +10 -0
- data/lib/arjdbc/cachedb.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_db2.rb → arjdbc/db2/adapter.rb} +2 -17
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_derby.rb → arjdbc/derby/adapter.rb} +8 -26
- data/lib/arjdbc/derby/connection_methods.rb +18 -0
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/arjdbc/discover.rb +99 -0
- data/lib/{jdbc_adapter/jdbc_firebird.rb → arjdbc/firebird/adapter.rb} +12 -16
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/arjdbc/h2/adapter.rb +15 -0
- data/lib/arjdbc/h2/connection_methods.rb +12 -0
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_hsqldb.rb → arjdbc/hsqldb/adapter.rb} +6 -58
- data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_informix.rb → arjdbc/informix/adapter.rb} +6 -19
- data/lib/arjdbc/informix/connection_methods.rb +10 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/arjdbc/jdbc/adapter.rb +235 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +38 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +97 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
- data/lib/arjdbc/jdbc/core_ext.rb +24 -0
- data/lib/arjdbc/jdbc/discover.rb +18 -0
- data/lib/arjdbc/jdbc/driver.rb +44 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/{jdbc_adapter → arjdbc/jdbc}/missing_functionality_helper.rb +5 -5
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/{jdbc_adapter → arjdbc/jdbc}/railtie.rb +1 -1
- data/lib/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +119 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_mimer.rb → arjdbc/mimer/adapter.rb} +16 -19
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/{jdbc_adapter/jdbc_mssql.rb → arjdbc/mssql/adapter.rb} +19 -31
- data/lib/arjdbc/mssql/connection_methods.rb +13 -0
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +388 -0
- data/lib/arjdbc/mysql/connection_methods.rb +26 -0
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_oracle.rb → arjdbc/oracle/adapter.rb} +9 -17
- data/lib/arjdbc/oracle/connection_methods.rb +11 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/{jdbc_adapter/jdbc_postgre.rb → arjdbc/postgresql/adapter.rb} +7 -36
- data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/{jdbc_adapter/jdbc_sqlite3.rb → arjdbc/sqlite3/adapter.rb} +106 -104
- data/lib/arjdbc/sqlite3/connection_methods.rb +33 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/arjdbc/sybase/adapter.rb +46 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/arjdbc.rb +29 -0
- data/lib/jdbc_adapter/version.rb +3 -5
- data/lib/jdbc_adapter.rb +2 -27
- data/rails_generators/templates/config/initializers/jdbc.rb +1 -1
- data/rakelib/compile.rake +3 -2
- data/rakelib/package.rake +3 -3
- data/src/java/{jdbc_adapter/JdbcDerbySpec.java → arjdbc/derby/DerbyModule.java} +32 -32
- data/src/java/{jdbc_adapter/JdbcAdapterInternalService.java → arjdbc/jdbc/AdapterJavaService.java} +13 -7
- data/src/java/{jdbc_adapter → arjdbc/jdbc}/JdbcConnectionFactory.java +6 -6
- data/src/java/{jdbc_adapter → arjdbc/jdbc}/RubyJdbcConnection.java +91 -16
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/{jdbc_adapter → arjdbc/mssql}/MssqlRubyJdbcConnection.java +5 -2
- data/src/java/{jdbc_adapter/JdbcMySQLSpec.java → arjdbc/mysql/MySQLModule.java} +12 -12
- data/src/java/{jdbc_adapter/PostgresRubyJdbcConnection.java → arjdbc/postgresql/PostgresqlRubyJdbcConnection.java} +11 -9
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
- data/test/abstract_db_create.rb +4 -1
- data/test/activerecord/connection_adapters/type_conversion_test.rb +1 -1
- data/test/db/cachedb.rb +0 -0
- data/test/db/derby.rb +12 -14
- data/test/db/hsqldb.rb +3 -2
- data/test/db/jndi_config.rb +4 -4
- data/test/db/sqlite3.rb +2 -6
- data/test/db2_simple_test.rb +23 -0
- data/test/derby_migration_test.rb +50 -3
- data/test/jdbc_common.rb +1 -1
- data/test/jndi_callbacks_test.rb +1 -0
- data/test/postgres_nonseq_pkey_test.rb +0 -2
- data/test/postgres_schema_search_path_test.rb +0 -2
- data/test/simple.rb +3 -3
- data/test/sybase_jtds_simple_test.rb +22 -0
- metadata +81 -46
- data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +0 -26
- data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
- data/lib/jdbc_adapter/jdbc_cachedb.rb +0 -33
- data/lib/jdbc_adapter/jdbc_mysql.rb +0 -260
- data/lib/jdbc_adapter/jdbc_sybase.rb +0 -50
- data/src/java/jdbc_adapter/SQLBlock.java +0 -27
- data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +0 -41
- data/test/jdbc_adapter/jdbc_db2_test.rb +0 -26
- data/test/jdbc_adapter/jdbc_sybase_test.rb +0 -33
- data/test/minirunit/testConnect.rb +0 -14
- data/test/minirunit/testH2.rb +0 -73
- data/test/minirunit/testHsqldb.rb +0 -73
- data/test/minirunit/testLoadActiveRecord.rb +0 -3
- data/test/minirunit/testMysql.rb +0 -83
- data/test/minirunit/testRawSelect.rb +0 -24
- data/test/minirunit.rb +0 -109
- /data/lib/{jdbc_adapter → arjdbc/jdbc}/jdbc.rake +0 -0
- /data/lib/{jdbc_adapter → arjdbc/jdbc}/rake_tasks.rb +0 -0
- /data/lib/{jdbc_adapter → arjdbc/mssql}/tsql_helper.rb +0 -0
data/src/java/{jdbc_adapter/JdbcAdapterInternalService.java → arjdbc/jdbc/AdapterJavaService.java}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
**** BEGIN LICENSE BLOCK *****
|
3
|
-
* Copyright (c) 2006-
|
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
|
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
|
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
|
-
|
49
|
+
PostgresqlRubyJdbcConnection.createPostgresqlJdbcConnectionClass(runtime, jdbcConnection);
|
44
50
|
MssqlRubyJdbcConnection.createMssqlJdbcConnectionClass(runtime, jdbcConnection);
|
45
51
|
Sqlite3RubyJdbcConnection.createSqlite3JdbcConnectionClass(runtime, jdbcConnection);
|
46
|
-
RubyModule
|
52
|
+
RubyModule arJdbc = runtime.getOrCreateModule("ArJdbc");
|
47
53
|
|
48
54
|
rubyApi = JavaEmbedUtils.newObjectAdapter();
|
49
|
-
|
50
|
-
|
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-
|
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
|
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
|
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
|
-
|
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(
|
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(
|
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 =
|
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
|
-
|
1112
|
-
|
1113
|
-
|
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) {
|
@@ -0,0 +1,48 @@
|
|
1
|
+
/*
|
2
|
+
**** BEGIN LICENSE BLOCK *****
|
3
|
+
* Copyright (c) 2006-2010 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 arjdbc.jdbc;
|
28
|
+
|
29
|
+
import java.sql.Connection;
|
30
|
+
import java.sql.ResultSet;
|
31
|
+
import java.sql.SQLException;
|
32
|
+
import java.sql.Statement;
|
33
|
+
|
34
|
+
/**
|
35
|
+
*
|
36
|
+
* @author nicksieger
|
37
|
+
*/
|
38
|
+
public abstract class SQLBlock {
|
39
|
+
abstract Object call(Connection c) throws SQLException;
|
40
|
+
|
41
|
+
public void close(Statement statement) {
|
42
|
+
RubyJdbcConnection.close(statement);
|
43
|
+
}
|
44
|
+
|
45
|
+
public void close(ResultSet resultSet) {
|
46
|
+
RubyJdbcConnection.close(resultSet);
|
47
|
+
}
|
48
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
**** BEGIN LICENSE BLOCK *****
|
3
|
-
* Copyright (c) 2006-
|
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
|
*
|
@@ -23,11 +23,14 @@
|
|
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
|
26
|
+
package arjdbc.mssql;
|
27
27
|
|
28
28
|
import java.sql.ResultSet;
|
29
29
|
import java.sql.SQLException;
|
30
30
|
import java.sql.Types;
|
31
|
+
|
32
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
33
|
+
|
31
34
|
import org.jruby.Ruby;
|
32
35
|
import org.jruby.RubyClass;
|
33
36
|
import org.jruby.runtime.ObjectAllocator;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/***** BEGIN LICENSE BLOCK *****
|
2
|
-
* Copyright (c) 2006-
|
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,7 +22,7 @@
|
|
22
22
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
23
|
***** END LICENSE BLOCK *****/
|
24
24
|
|
25
|
-
package
|
25
|
+
package arjdbc.mysql;
|
26
26
|
|
27
27
|
import java.sql.Connection;
|
28
28
|
|
@@ -35,10 +35,10 @@ import org.jruby.runtime.builtin.IRubyObject;
|
|
35
35
|
|
36
36
|
import org.jruby.util.ByteList;
|
37
37
|
|
38
|
-
public class
|
39
|
-
public static void load(RubyModule
|
40
|
-
RubyModule mysql =
|
41
|
-
mysql.defineAnnotatedMethods(
|
38
|
+
public class MySQLModule {
|
39
|
+
public static void load(RubyModule arJdbc) {
|
40
|
+
RubyModule mysql = arJdbc.defineModuleUnder("MySQL");
|
41
|
+
mysql.defineAnnotatedMethods(MySQLModule.class);
|
42
42
|
}
|
43
43
|
|
44
44
|
private final static byte BACKQUOTE = '`';
|
@@ -56,9 +56,9 @@ public class JdbcMySQLSpec {
|
|
56
56
|
public static IRubyObject quote_string(ThreadContext context, IRubyObject recv, IRubyObject string) {
|
57
57
|
ByteList bytes = ((RubyString) string).getByteList();
|
58
58
|
ByteList newBytes = new ByteList();
|
59
|
-
|
59
|
+
|
60
60
|
newBytes.append(bytes);
|
61
|
-
|
61
|
+
|
62
62
|
for(int i = newBytes.begin; i < newBytes.begin + newBytes.realSize; i++) {
|
63
63
|
byte[] rep = null;
|
64
64
|
switch (newBytes.bytes[i]) {
|
@@ -94,7 +94,7 @@ public class JdbcMySQLSpec {
|
|
94
94
|
|
95
95
|
return context.getRuntime().newString(newBytes);
|
96
96
|
}
|
97
|
-
|
97
|
+
|
98
98
|
@JRubyMethod(name = "quote_table_name", frame=false)
|
99
99
|
public static IRubyObject quote_table_name(ThreadContext context, IRubyObject recv, IRubyObject arg) {
|
100
100
|
ByteList bytes = arg.asString().getByteList();
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
**** BEGIN LICENSE BLOCK *****
|
3
|
-
* Copyright (c) 2006-
|
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
|
*
|
@@ -23,7 +23,9 @@
|
|
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
|
26
|
+
package arjdbc.postgresql;
|
27
|
+
|
28
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
27
29
|
|
28
30
|
import org.jruby.Ruby;
|
29
31
|
import org.jruby.RubyClass;
|
@@ -34,22 +36,22 @@ import org.jruby.runtime.builtin.IRubyObject;
|
|
34
36
|
*
|
35
37
|
* @author enebo
|
36
38
|
*/
|
37
|
-
public class
|
38
|
-
protected
|
39
|
+
public class PostgresqlRubyJdbcConnection extends RubyJdbcConnection {
|
40
|
+
protected PostgresqlRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
39
41
|
super(runtime, metaClass);
|
40
42
|
}
|
41
43
|
|
42
|
-
public static RubyClass
|
44
|
+
public static RubyClass createPostgresqlJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
|
43
45
|
RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("PostgresJdbcConnection",
|
44
|
-
jdbcConnection,
|
45
|
-
clazz.defineAnnotatedMethods(
|
46
|
+
jdbcConnection, POSTGRESQL_JDBCCONNECTION_ALLOCATOR);
|
47
|
+
clazz.defineAnnotatedMethods(PostgresqlRubyJdbcConnection.class);
|
46
48
|
|
47
49
|
return clazz;
|
48
50
|
}
|
49
51
|
|
50
|
-
private static ObjectAllocator
|
52
|
+
private static ObjectAllocator POSTGRESQL_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
|
51
53
|
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
52
|
-
return new
|
54
|
+
return new PostgresqlRubyJdbcConnection(runtime, klass);
|
53
55
|
}
|
54
56
|
};
|
55
57
|
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
/*
|
2
|
+
**** BEGIN LICENSE BLOCK *****
|
3
|
+
* Copyright (c) 2006-2010 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 arjdbc.sqlite3;
|
28
|
+
|
29
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
30
|
+
|
31
|
+
import org.jruby.Ruby;
|
32
|
+
import org.jruby.RubyClass;
|
33
|
+
import org.jruby.runtime.ObjectAllocator;
|
34
|
+
import org.jruby.runtime.ThreadContext;
|
35
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
36
|
+
|
37
|
+
/**
|
38
|
+
*
|
39
|
+
* @author enebo
|
40
|
+
*/
|
41
|
+
public class Sqlite3RubyJdbcConnection extends RubyJdbcConnection {
|
42
|
+
protected Sqlite3RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
43
|
+
super(runtime, metaClass);
|
44
|
+
}
|
45
|
+
|
46
|
+
public static RubyClass createSqlite3JdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
|
47
|
+
RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("Sqlite3JdbcConnection",
|
48
|
+
jdbcConnection, SQLITE3_JDBCCONNECTION_ALLOCATOR);
|
49
|
+
clazz.defineAnnotatedMethods(Sqlite3RubyJdbcConnection.class);
|
50
|
+
|
51
|
+
return clazz;
|
52
|
+
}
|
53
|
+
|
54
|
+
private static ObjectAllocator SQLITE3_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
|
55
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
56
|
+
return new Sqlite3RubyJdbcConnection(runtime, klass);
|
57
|
+
}
|
58
|
+
};
|
59
|
+
|
60
|
+
@Override
|
61
|
+
protected IRubyObject tables(ThreadContext context, String catalog, String schemaPattern, String tablePattern, String[] types) {
|
62
|
+
return (IRubyObject) withConnectionAndRetry(context, tableLookupBlock(context.getRuntime(), catalog, schemaPattern, tablePattern, types, true));
|
63
|
+
}
|
64
|
+
}
|
data/test/abstract_db_create.rb
CHANGED
@@ -9,6 +9,9 @@ module Rails
|
|
9
9
|
@config ||= Object.new
|
10
10
|
end
|
11
11
|
end
|
12
|
+
def self.application
|
13
|
+
Rails::Application
|
14
|
+
end
|
12
15
|
end
|
13
16
|
|
14
17
|
module AbstractDbCreate
|
@@ -22,7 +25,7 @@ module AbstractDbCreate
|
|
22
25
|
setup_rails
|
23
26
|
set_rails_constant("env", "unittest")
|
24
27
|
set_rails_constant("root", ".")
|
25
|
-
load File.dirname(__FILE__) + '/../lib/
|
28
|
+
load File.dirname(__FILE__) + '/../lib/arjdbc/jdbc/jdbc.rake' if jruby?
|
26
29
|
task :environment do
|
27
30
|
ActiveRecord::Base.configurations = configurations
|
28
31
|
end
|
data/test/db/cachedb.rb
CHANGED
File without changes
|
data/test/db/derby.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
FileUtils.rm_rf('derby-testdb')
|
14
|
-
}
|
1
|
+
config = {
|
2
|
+
:adapter => 'derby',
|
3
|
+
:database => "derby-testdb"
|
4
|
+
}
|
5
|
+
|
6
|
+
ActiveRecord::Base.establish_connection(config)
|
7
|
+
|
8
|
+
at_exit {
|
9
|
+
# Clean up derby files
|
10
|
+
require 'fileutils'
|
11
|
+
FileUtils.rm_rf('derby-testdb')
|
12
|
+
}
|
data/test/db/hsqldb.rb
CHANGED
@@ -7,6 +7,7 @@ ActiveRecord::Base.establish_connection(config)
|
|
7
7
|
|
8
8
|
at_exit {
|
9
9
|
# Clean up hsqldb when done
|
10
|
-
|
11
|
-
|
10
|
+
require "fileutils"
|
11
|
+
Dir['test.db*'].each {|f| FileUtils.rm_rf(f)}
|
12
|
+
FileUtils.rm_rf('hsqldb-testdb.log') rescue nil #can't delete on windows
|
12
13
|
}
|
data/test/db/jndi_config.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require '
|
2
|
+
require 'arjdbc'
|
3
3
|
|
4
4
|
System = java.lang.System
|
5
5
|
Context = javax.naming.Context
|
6
6
|
InitialContext = javax.naming.InitialContext
|
7
7
|
Reference = javax.naming.Reference
|
8
8
|
StringRefAddr = javax.naming.StringRefAddr
|
9
|
-
|
9
|
+
|
10
10
|
System.set_property(Context::INITIAL_CONTEXT_FACTORY,
|
11
11
|
'com.sun.jndi.fscontext.RefFSContextFactory')
|
12
12
|
project_path = File.expand_path(File.dirname(__FILE__) + '/../..')
|
@@ -18,9 +18,9 @@ System.set_property(Context::PROVIDER_URL, "file://#{jndi_dir}")
|
|
18
18
|
derby_ref = Reference.new('javax.sql.DataSource',
|
19
19
|
'org.apache.commons.dbcp.BasicDataSourceFactory',
|
20
20
|
nil)
|
21
|
-
derby_ref.add StringRefAddr.new('driverClassName',
|
21
|
+
derby_ref.add StringRefAddr.new('driverClassName',
|
22
22
|
'org.apache.derby.jdbc.EmbeddedDriver')
|
23
|
-
derby_ref.add StringRefAddr.new('url',
|
23
|
+
derby_ref.add StringRefAddr.new('url',
|
24
24
|
'jdbc:derby:derby-testdb;create=true')
|
25
25
|
derby_ref.add StringRefAddr.new('username', 'sa')
|
26
26
|
derby_ref.add StringRefAddr.new('password', '')
|
data/test/db/sqlite3.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require 'jdbc/sqlite3' if jruby?
|
2
|
-
|
3
1
|
config = {
|
4
|
-
:adapter =>
|
5
|
-
:
|
6
|
-
# :url => 'jdbc:sqlite:test.sqlite3.db',
|
7
|
-
# :driver => 'org.sqlite.JDBC'
|
2
|
+
:adapter => 'sqlite3',
|
3
|
+
:database => 'test.sqlite3.db'
|
8
4
|
}
|
9
5
|
|
10
6
|
ActiveRecord::Base.establish_connection(config)
|