activerecord-jdbc-adapter 1.0.3-java → 50.1-java
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 +79 -0
- data/.yardopts +4 -0
- data/CONTRIBUTING.md +50 -0
- data/Gemfile +91 -0
- data/History.md +1191 -0
- data/LICENSE.txt +22 -17
- data/README.md +169 -0
- data/RUNNING_TESTS.md +127 -0
- data/Rakefile +294 -5
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +55 -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/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +0 -5
- data/lib/arel/visitors/compat.rb +60 -0
- data/lib/arel/visitors/db2.rb +128 -6
- data/lib/arel/visitors/derby.rb +103 -10
- data/lib/arel/visitors/firebird.rb +79 -0
- data/lib/arel/visitors/h2.rb +25 -0
- data/lib/arel/visitors/hsqldb.rb +18 -10
- 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 +11 -21
- data/lib/arjdbc/abstract/connection_management.rb +35 -0
- data/lib/arjdbc/abstract/core.rb +64 -0
- data/lib/arjdbc/abstract/database_statements.rb +64 -0
- data/lib/arjdbc/abstract/statement_cache.rb +58 -0
- data/lib/arjdbc/abstract/transaction_support.rb +86 -0
- data/lib/arjdbc/db2.rb +3 -1
- data/lib/arjdbc/db2/adapter.rb +630 -250
- 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 +1 -5
- data/lib/arjdbc/derby/active_record_patch.rb +13 -0
- data/lib/arjdbc/derby/adapter.rb +409 -217
- data/lib/arjdbc/derby/connection_methods.rb +16 -14
- data/lib/arjdbc/derby/schema_creation.rb +15 -0
- data/lib/arjdbc/discover.rb +62 -50
- data/lib/arjdbc/firebird.rb +3 -1
- data/lib/arjdbc/firebird/adapter.rb +365 -62
- data/lib/arjdbc/firebird/connection_methods.rb +23 -0
- data/lib/arjdbc/h2.rb +2 -3
- data/lib/arjdbc/h2/adapter.rb +273 -6
- data/lib/arjdbc/h2/connection_methods.rb +23 -8
- data/lib/arjdbc/hsqldb.rb +2 -3
- data/lib/arjdbc/hsqldb/adapter.rb +204 -77
- data/lib/arjdbc/hsqldb/connection_methods.rb +24 -10
- data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
- data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
- data/lib/arjdbc/informix.rb +4 -2
- data/lib/arjdbc/informix/adapter.rb +78 -54
- data/lib/arjdbc/informix/connection_methods.rb +8 -9
- data/lib/arjdbc/jdbc.rb +59 -2
- data/lib/arjdbc/jdbc/adapter.rb +356 -166
- 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 +15 -0
- data/lib/arjdbc/jdbc/callbacks.rb +27 -18
- data/lib/arjdbc/jdbc/column.rb +79 -20
- data/lib/arjdbc/jdbc/connection.rb +5 -119
- data/lib/arjdbc/jdbc/connection_methods.rb +32 -4
- data/lib/arjdbc/jdbc/error.rb +65 -0
- data/lib/arjdbc/jdbc/extension.rb +41 -29
- data/lib/arjdbc/jdbc/java.rb +5 -6
- data/lib/arjdbc/jdbc/jdbc.rake +3 -126
- data/lib/arjdbc/jdbc/railtie.rb +2 -9
- data/lib/arjdbc/jdbc/rake_tasks.rb +3 -10
- 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 +35 -19
- data/lib/arjdbc/mssql.rb +6 -3
- data/lib/arjdbc/mssql/adapter.rb +630 -298
- data/lib/arjdbc/mssql/column.rb +200 -0
- data/lib/arjdbc/mssql/connection_methods.rb +66 -17
- data/lib/arjdbc/mssql/explain_support.rb +99 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +189 -50
- 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 +2 -3
- data/lib/arjdbc/mysql/adapter.rb +86 -356
- data/lib/arjdbc/mysql/connection_methods.rb +159 -23
- data/lib/arjdbc/oracle/adapter.rb +714 -263
- data/lib/arjdbc/postgresql.rb +2 -3
- data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +24 -0
- data/lib/arjdbc/postgresql/adapter.rb +570 -400
- 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 +57 -18
- data/lib/arjdbc/postgresql/name.rb +24 -0
- data/lib/arjdbc/postgresql/oid_types.rb +192 -0
- data/lib/arjdbc/railtie.rb +11 -0
- data/lib/arjdbc/sqlite3.rb +2 -3
- data/lib/arjdbc/sqlite3/adapter.rb +518 -198
- data/lib/arjdbc/sqlite3/connection_methods.rb +49 -24
- data/lib/arjdbc/sybase.rb +2 -2
- data/lib/arjdbc/sybase/adapter.rb +7 -6
- data/lib/arjdbc/tasks.rb +13 -0
- data/lib/arjdbc/tasks/database_tasks.rb +52 -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/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 +1 -6
- data/lib/generators/jdbc/USAGE +9 -0
- data/lib/generators/jdbc/jdbc_generator.rb +8 -0
- data/lib/jdbc_adapter.rb +1 -1
- data/lib/jdbc_adapter/rake_tasks.rb +3 -2
- data/lib/jdbc_adapter/version.rb +2 -1
- data/pom.xml +114 -0
- data/rails_generators/jdbc_generator.rb +1 -1
- data/rails_generators/templates/config/initializers/jdbc.rb +8 -5
- data/rails_generators/templates/lib/tasks/jdbc.rake +7 -4
- data/rakelib/01-tomcat.rake +51 -0
- data/rakelib/02-test.rake +132 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/compile.rake +67 -22
- data/rakelib/db.rake +61 -0
- data/rakelib/rails.rake +204 -29
- data/src/java/arjdbc/ArJdbcModule.java +286 -0
- data/src/java/arjdbc/db2/DB2Module.java +76 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +126 -0
- data/src/java/arjdbc/derby/DerbyModule.java +99 -243
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +152 -0
- data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +174 -0
- data/src/java/arjdbc/{jdbc/JdbcConnectionFactory.java → h2/H2Module.java} +20 -6
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +27 -12
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +73 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +7 -6
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +7 -29
- data/src/java/arjdbc/jdbc/Callable.java +44 -0
- data/src/java/arjdbc/jdbc/ConnectionFactory.java +132 -0
- data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +157 -0
- data/src/java/arjdbc/jdbc/DriverConnectionFactory.java +63 -0
- data/src/java/arjdbc/jdbc/DriverWrapper.java +119 -0
- data/src/java/arjdbc/jdbc/JdbcResult.java +130 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +3622 -948
- data/src/java/arjdbc/mssql/MSSQLModule.java +90 -0
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +181 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +99 -81
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +294 -0
- data/src/java/arjdbc/oracle/OracleModule.java +80 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +387 -17
- data/src/java/arjdbc/postgresql/ByteaUtils.java +157 -0
- data/src/java/arjdbc/postgresql/PgResultSetMetaDataWrapper.java +23 -0
- data/src/java/arjdbc/postgresql/PostgreSQLModule.java +77 -0
- data/src/java/arjdbc/postgresql/PostgreSQLResult.java +184 -0
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +952 -0
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +73 -0
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +525 -0
- data/src/java/arjdbc/util/CallResultSet.java +826 -0
- data/src/java/arjdbc/util/DateTimeUtils.java +580 -0
- data/src/java/arjdbc/util/ObjectSupport.java +65 -0
- data/src/java/arjdbc/util/QuotingUtils.java +138 -0
- data/src/java/arjdbc/util/StringCache.java +63 -0
- data/src/java/arjdbc/util/StringHelper.java +159 -0
- metadata +245 -268
- data/History.txt +0 -369
- data/Manifest.txt +0 -180
- data/README.txt +0 -181
- data/lib/active_record/connection_adapters/oracle_adapter.rb +0 -1
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +0 -9
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +0 -15
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +0 -46
- data/lib/arel/visitors/mssql.rb +0 -44
- data/lib/arjdbc/jdbc/compatibility.rb +0 -51
- data/lib/arjdbc/jdbc/core_ext.rb +0 -24
- data/lib/arjdbc/jdbc/discover.rb +0 -18
- data/lib/arjdbc/jdbc/driver.rb +0 -44
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +0 -87
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +0 -28
- data/lib/arjdbc/jdbc/require_driver.rb +0 -16
- data/lib/arjdbc/mimer.rb +0 -2
- data/lib/arjdbc/mimer/adapter.rb +0 -142
- data/lib/arjdbc/mssql/tsql_helper.rb +0 -61
- data/lib/arjdbc/oracle.rb +0 -3
- data/lib/arjdbc/oracle/connection_methods.rb +0 -11
- data/lib/pg.rb +0 -4
- data/rakelib/package.rake +0 -92
- data/rakelib/test.rake +0 -81
- data/src/java/arjdbc/jdbc/SQLBlock.java +0 -48
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +0 -127
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +0 -57
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +0 -64
- data/test/abstract_db_create.rb +0 -117
- data/test/activerecord/connection_adapters/type_conversion_test.rb +0 -31
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +0 -25
- data/test/db/db2.rb +0 -11
- data/test/db/derby.rb +0 -12
- data/test/db/h2.rb +0 -11
- data/test/db/hsqldb.rb +0 -13
- data/test/db/informix.rb +0 -11
- data/test/db/jdbc.rb +0 -11
- data/test/db/jndi_config.rb +0 -40
- data/test/db/logger.rb +0 -3
- data/test/db/mssql.rb +0 -9
- data/test/db/mysql.rb +0 -10
- data/test/db/oracle.rb +0 -34
- data/test/db/postgres.rb +0 -9
- data/test/db/sqlite3.rb +0 -11
- data/test/db2_simple_test.rb +0 -66
- data/test/derby_migration_test.rb +0 -68
- data/test/derby_multibyte_test.rb +0 -12
- data/test/derby_simple_test.rb +0 -99
- data/test/generic_jdbc_connection_test.rb +0 -29
- data/test/h2_simple_test.rb +0 -41
- data/test/has_many_through.rb +0 -79
- data/test/helper.rb +0 -5
- data/test/hsqldb_simple_test.rb +0 -6
- data/test/informix_simple_test.rb +0 -48
- data/test/jdbc_common.rb +0 -25
- data/test/jndi_callbacks_test.rb +0 -40
- data/test/jndi_test.rb +0 -25
- data/test/manualTestDatabase.rb +0 -191
- data/test/models/add_not_null_column_to_table.rb +0 -12
- data/test/models/auto_id.rb +0 -18
- data/test/models/data_types.rb +0 -28
- data/test/models/entry.rb +0 -43
- data/test/models/mixed_case.rb +0 -25
- data/test/models/reserved_word.rb +0 -18
- data/test/models/string_id.rb +0 -18
- data/test/models/validates_uniqueness_of_string.rb +0 -19
- data/test/mssql_db_create_test.rb +0 -26
- data/test/mssql_identity_insert_test.rb +0 -19
- data/test/mssql_legacy_types_test.rb +0 -58
- data/test/mssql_limit_offset_test.rb +0 -136
- data/test/mssql_multibyte_test.rb +0 -18
- data/test/mssql_simple_test.rb +0 -55
- data/test/mysql_db_create_test.rb +0 -27
- data/test/mysql_info_test.rb +0 -113
- data/test/mysql_multibyte_test.rb +0 -10
- data/test/mysql_nonstandard_primary_key_test.rb +0 -42
- data/test/mysql_simple_test.rb +0 -49
- data/test/oracle_simple_test.rb +0 -18
- data/test/oracle_specific_test.rb +0 -83
- data/test/pick_rails_version.rb +0 -3
- data/test/postgres_db_create_test.rb +0 -32
- data/test/postgres_drop_db_test.rb +0 -16
- data/test/postgres_mixed_case_test.rb +0 -29
- data/test/postgres_nonseq_pkey_test.rb +0 -38
- data/test/postgres_reserved_test.rb +0 -22
- data/test/postgres_schema_search_path_test.rb +0 -44
- data/test/postgres_simple_test.rb +0 -51
- data/test/postgres_table_alias_length_test.rb +0 -15
- data/test/simple.rb +0 -546
- data/test/sqlite3_simple_test.rb +0 -233
- data/test/sybase_jtds_simple_test.rb +0 -28
@@ -0,0 +1,286 @@
|
|
1
|
+
/*
|
2
|
+
* The MIT License
|
3
|
+
*
|
4
|
+
* Copyright 2013-2014 Karol Bucek.
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
11
|
+
* furnished to do so, subject to the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
14
|
+
* all copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
* THE SOFTWARE.
|
23
|
+
*/
|
24
|
+
package arjdbc;
|
25
|
+
|
26
|
+
import java.lang.reflect.InvocationTargetException;
|
27
|
+
import java.util.Collection;
|
28
|
+
import java.util.HashMap;
|
29
|
+
import java.util.Map;
|
30
|
+
import java.util.WeakHashMap;
|
31
|
+
|
32
|
+
import org.jruby.NativeException;
|
33
|
+
import org.jruby.Ruby;
|
34
|
+
import org.jruby.RubyArray;
|
35
|
+
import org.jruby.RubyClass;
|
36
|
+
import org.jruby.RubyModule;
|
37
|
+
import org.jruby.RubyString;
|
38
|
+
import org.jruby.anno.JRubyMethod;
|
39
|
+
import org.jruby.exceptions.RaiseException;
|
40
|
+
import org.jruby.runtime.Block;
|
41
|
+
import org.jruby.runtime.ThreadContext;
|
42
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
43
|
+
import org.jruby.util.ByteList;
|
44
|
+
|
45
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
46
|
+
import static arjdbc.jdbc.RubyJdbcConnection.getJdbcConnection;
|
47
|
+
|
48
|
+
/**
|
49
|
+
* ::ArJdbc
|
50
|
+
*
|
51
|
+
* @author kares
|
52
|
+
*/
|
53
|
+
public class ArJdbcModule {
|
54
|
+
|
55
|
+
public static RubyModule load(final Ruby runtime) {
|
56
|
+
final RubyModule arJdbc = runtime.getOrCreateModule("ArJdbc");
|
57
|
+
arJdbc.defineAnnotatedMethods( ArJdbcModule.class );
|
58
|
+
return arJdbc;
|
59
|
+
}
|
60
|
+
|
61
|
+
public static RubyModule get(final Ruby runtime) {
|
62
|
+
return runtime.getModule("ArJdbc");
|
63
|
+
}
|
64
|
+
|
65
|
+
public static void warn(final ThreadContext context, final String message) {
|
66
|
+
final Ruby runtime = context.runtime;
|
67
|
+
get(runtime).callMethod(context, "warn", runtime.newString(message));
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Load the Java parts for the given adapter spec module, e.g. to load
|
72
|
+
* ArJdbc::MySQL's Java part: <code>ArJdbc.load_java_part :MySQL</code>
|
73
|
+
*
|
74
|
+
* NOTE: this method is not intended to be called twice for a given adapter !
|
75
|
+
* @param context
|
76
|
+
* @param self
|
77
|
+
* @param args ( moduleName, [ connectionClass, moduleClass ] )
|
78
|
+
* @return true
|
79
|
+
*/
|
80
|
+
@JRubyMethod(name = "load_java_part", meta = true, required = 1, optional = 2)
|
81
|
+
public static IRubyObject load_java_part(final ThreadContext context,
|
82
|
+
final IRubyObject self, final IRubyObject[] args) {
|
83
|
+
final Ruby runtime = context.getRuntime();
|
84
|
+
|
85
|
+
String connectionClass = args.length > 1 ? args[1].toString() : null;
|
86
|
+
String moduleClass = args.length > 2 ? args[2].toString() : null;
|
87
|
+
|
88
|
+
final String moduleName = args[0].toString(); // e.g. 'MySQL'
|
89
|
+
final String packagePrefix = "arjdbc." + moduleName.toLowerCase() + "."; // arjdbc.mysql
|
90
|
+
|
91
|
+
// NOTE: due previous (backwards compatible) conventions there are
|
92
|
+
// 2 things we load, the adapter spec module's Java implemented methods
|
93
|
+
// and a custom JdbcConnection class (both are actually optional) e.g. :
|
94
|
+
//
|
95
|
+
// MySQLModule.load(RubyModule); // 'arjdbc.mysql' package is assumed
|
96
|
+
// MySQLRubyJdbcConnection.createMySQLJdbcConnectionClass(Ruby, RubyClass);
|
97
|
+
//
|
98
|
+
|
99
|
+
if (moduleClass == null) {
|
100
|
+
// 'arjdbc.mysql.' + 'MySQL' + 'Module'
|
101
|
+
moduleClass = packagePrefix + moduleName + "Module";
|
102
|
+
}
|
103
|
+
|
104
|
+
final Class<?> module;
|
105
|
+
try {
|
106
|
+
module = Class.forName(moduleClass);
|
107
|
+
// new convention MySQLModule.load( Ruby runtime ) :
|
108
|
+
try {
|
109
|
+
invokeStatic(runtime, module, "load", Ruby.class, runtime);
|
110
|
+
}
|
111
|
+
catch (NoSuchMethodException e) {
|
112
|
+
// old convention MySQLModule.load( RubyModule arJdbc ) :
|
113
|
+
invokeStatic(runtime, module, "load", RubyModule.class, get(runtime));
|
114
|
+
}
|
115
|
+
}
|
116
|
+
catch (ClassNotFoundException e) { /* ignored */ }
|
117
|
+
catch (NoSuchMethodException e) {
|
118
|
+
throw newNativeException(runtime, e);
|
119
|
+
}
|
120
|
+
|
121
|
+
String connectionClass2 = null;
|
122
|
+
if (connectionClass == null) {
|
123
|
+
// 'arjdbc.mysql.' + 'MySQL' + 'RubyJdbcConnection'
|
124
|
+
connectionClass = packagePrefix + moduleName + "RubyJdbcConnection";
|
125
|
+
connectionClass2 = packagePrefix + moduleName + "JdbcConnection";
|
126
|
+
}
|
127
|
+
|
128
|
+
try {
|
129
|
+
Class<?> connection = null;
|
130
|
+
try {
|
131
|
+
connection = Class.forName(connectionClass);
|
132
|
+
}
|
133
|
+
catch (ClassNotFoundException e) {
|
134
|
+
if ( connectionClass2 != null ) {
|
135
|
+
connection = Class.forName(connectionClass2);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
if ( connection != null ) {
|
139
|
+
// convention e.g. MySQLRubyJdbcConnection.load( Ruby runtime ) :
|
140
|
+
try {
|
141
|
+
invokeStatic(runtime, connection, "load", Ruby.class, runtime);
|
142
|
+
}
|
143
|
+
catch (NoSuchMethodException e) {
|
144
|
+
// "old" e.g. MySQLRubyJdbcConnection.createMySQLJdbcConnectionClass(runtime, jdbcConnection)
|
145
|
+
connection.getMethod("create" + moduleName + "JdbcConnectionClass", Ruby.class, RubyClass.class).
|
146
|
+
invoke(null, runtime, getJdbcConnection(runtime));
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
catch (ClassNotFoundException e) { /* ignored */ }
|
151
|
+
catch (NoSuchMethodException e) {
|
152
|
+
throw newNativeException(runtime, e);
|
153
|
+
}
|
154
|
+
catch (IllegalAccessException e) {
|
155
|
+
throw newNativeException(runtime, e);
|
156
|
+
}
|
157
|
+
catch (InvocationTargetException e) {
|
158
|
+
throw newNativeException(runtime, e);
|
159
|
+
}
|
160
|
+
|
161
|
+
return runtime.getTrue();
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* <code>ArJdbc.modules</code>
|
166
|
+
* @param context
|
167
|
+
* @param self
|
168
|
+
* @return nested constant values that are modules
|
169
|
+
*/
|
170
|
+
@JRubyMethod(name = "modules", meta = true)
|
171
|
+
public static IRubyObject modules(final ThreadContext context, final IRubyObject self) {
|
172
|
+
final Ruby runtime = context.getRuntime();
|
173
|
+
final RubyModule arJdbc = (RubyModule) self;
|
174
|
+
|
175
|
+
final Collection<String> constants = arJdbc.getConstantNames();
|
176
|
+
final RubyArray modules = runtime.newArray( constants.size() );
|
177
|
+
|
178
|
+
for ( final String name : constants ) {
|
179
|
+
final IRubyObject constant = arJdbc.getConstant(name, false);
|
180
|
+
// isModule: return false for Ruby Classes
|
181
|
+
if ( constant != null && constant.isModule() ) {
|
182
|
+
if ( "Util".equals(name) ) continue;
|
183
|
+
if ( "SerializedAttributesHelper".equals(name) ) continue; // deprecated
|
184
|
+
if ( "Version".equals(name) ) continue; // deprecated
|
185
|
+
modules.append( constant );
|
186
|
+
}
|
187
|
+
}
|
188
|
+
return modules;
|
189
|
+
}
|
190
|
+
|
191
|
+
// JDBC "driver" gem helper(s) :
|
192
|
+
|
193
|
+
@JRubyMethod(name = "load_driver", meta = true)
|
194
|
+
public static IRubyObject load_driver(final ThreadContext context, final IRubyObject self,
|
195
|
+
final IRubyObject const_name) { // e.g. load_driver(:MySQL)
|
196
|
+
IRubyObject loaded = loadDriver(context, self, const_name.toString());
|
197
|
+
return loaded == null ? context.nil : loaded;
|
198
|
+
}
|
199
|
+
|
200
|
+
// NOTE: probably useless - only to be useful for the pooled runtime mode when jar at WEB-INF/lib
|
201
|
+
static final Map<Ruby, Map<String, Boolean>> loadedDrivers = new WeakHashMap<Ruby, Map<String, Boolean>>(8);
|
202
|
+
|
203
|
+
private static IRubyObject loadDriver(final ThreadContext context, final IRubyObject self,
|
204
|
+
final String constName) {
|
205
|
+
final Ruby runtime = context.runtime;
|
206
|
+
// look for "cached" loading result :
|
207
|
+
Map<String, Boolean> loadedMap = loadedDrivers.get(runtime);
|
208
|
+
if ( loadedMap == null ) {
|
209
|
+
synchronized (ArJdbcModule.class) {
|
210
|
+
loadedMap = loadedDrivers.get(runtime);
|
211
|
+
if ( loadedMap == null ) {
|
212
|
+
loadedMap = new HashMap<String, Boolean>(4);
|
213
|
+
loadedDrivers.put(runtime, loadedMap);
|
214
|
+
}
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
final Boolean driverLoaded = loadedMap.get(constName);
|
219
|
+
if ( driverLoaded != null ) {
|
220
|
+
if ( driverLoaded.booleanValue() ) return runtime.getFalse();
|
221
|
+
return runtime.getNil();
|
222
|
+
}
|
223
|
+
|
224
|
+
try { // require 'jdbc/mysql'
|
225
|
+
final byte[] name = new byte[5 + constName.length()]; // 'j','d','b','c','/'
|
226
|
+
name[0] = 'j'; name[1] = 'd'; name[2] = 'b'; name[3] = 'c'; name[4] = '/';
|
227
|
+
for ( int i = 0; i < constName.length(); i++ ) {
|
228
|
+
name[ 5 + i ] = (byte) Character.toLowerCase( constName.charAt(i) );
|
229
|
+
}
|
230
|
+
final RubyString strName = RubyString.newString(runtime, new ByteList(name, false));
|
231
|
+
self.callMethod(context, "require", strName); // require 'jdbc/mysql'
|
232
|
+
}
|
233
|
+
catch (RaiseException e) { // LoadError
|
234
|
+
synchronized (loadedMap) {
|
235
|
+
loadedMap.put(constName, Boolean.FALSE);
|
236
|
+
}
|
237
|
+
return null;
|
238
|
+
}
|
239
|
+
|
240
|
+
final RubyModule jdbc = runtime.getModule("Jdbc");
|
241
|
+
if ( jdbc != null ) { // Jdbc::MySQL
|
242
|
+
final RubyModule constant = (RubyModule) jdbc.getConstantAt(constName);
|
243
|
+
if ( constant != null ) { // ::Jdbc::MySQL.load_driver :
|
244
|
+
if ( constant.respondsTo("load_driver") ) {
|
245
|
+
IRubyObject result = constant.callMethod("load_driver");
|
246
|
+
synchronized (loadedMap) {
|
247
|
+
loadedMap.put(constName, Boolean.TRUE);
|
248
|
+
}
|
249
|
+
return result;
|
250
|
+
}
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
synchronized (loadedMap) {
|
255
|
+
loadedMap.put(constName, Boolean.FALSE);
|
256
|
+
}
|
257
|
+
return null;
|
258
|
+
}
|
259
|
+
|
260
|
+
private static Object invokeStatic(final Ruby runtime,
|
261
|
+
final Class<?> klass, final String name, final Class<?> argType, final Object arg)
|
262
|
+
throws NoSuchMethodException {
|
263
|
+
try {
|
264
|
+
return klass.getMethod(name, argType).invoke(null, arg);
|
265
|
+
}
|
266
|
+
catch (IllegalAccessException e) {
|
267
|
+
throw newNativeException(runtime, e);
|
268
|
+
}
|
269
|
+
catch (InvocationTargetException e) {
|
270
|
+
throw newNativeException(runtime, e);
|
271
|
+
}
|
272
|
+
}
|
273
|
+
|
274
|
+
private static RaiseException newNativeException(final Ruby runtime, final Throwable cause) {
|
275
|
+
RubyClass nativeClass = runtime.getClass(NativeException.CLASS_NAME);
|
276
|
+
NativeException nativeException = new NativeException(runtime, nativeClass, cause);
|
277
|
+
return new RaiseException(cause, nativeException);
|
278
|
+
}
|
279
|
+
|
280
|
+
@JRubyMethod(meta = true)
|
281
|
+
public static IRubyObject with_meta_data_from_data_source_if_any(final ThreadContext context,
|
282
|
+
final IRubyObject self, final IRubyObject config, final Block block) {
|
283
|
+
return RubyJdbcConnection.with_meta_data_from_data_source_if_any(context, self, config, block);
|
284
|
+
}
|
285
|
+
|
286
|
+
}
|
@@ -0,0 +1,76 @@
|
|
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.db2;
|
25
|
+
|
26
|
+
import static arjdbc.util.QuotingUtils.BYTES_0;
|
27
|
+
import static arjdbc.util.QuotingUtils.BYTES_1;
|
28
|
+
import static arjdbc.util.QuotingUtils.quoteSingleQuotesWithFallback;
|
29
|
+
|
30
|
+
import org.jruby.Ruby;
|
31
|
+
import org.jruby.RubyModule;
|
32
|
+
import org.jruby.RubyString;
|
33
|
+
import org.jruby.anno.JRubyMethod;
|
34
|
+
import org.jruby.runtime.ThreadContext;
|
35
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
36
|
+
|
37
|
+
/**
|
38
|
+
* ArJdbc::DB2
|
39
|
+
*
|
40
|
+
* @author kares
|
41
|
+
*/
|
42
|
+
public class DB2Module {
|
43
|
+
|
44
|
+
public static RubyModule load(final RubyModule arJdbc) {
|
45
|
+
RubyModule db2 = arJdbc.defineModuleUnder("DB2");
|
46
|
+
db2.defineAnnotatedMethods( DB2Module.class );
|
47
|
+
return db2;
|
48
|
+
}
|
49
|
+
|
50
|
+
public static RubyModule load(final Ruby runtime) {
|
51
|
+
return load( arjdbc.ArJdbcModule.get(runtime) );
|
52
|
+
}
|
53
|
+
|
54
|
+
@JRubyMethod(name = "quote_string", required = 1, frame = false)
|
55
|
+
public static IRubyObject quote_string(
|
56
|
+
final ThreadContext context,
|
57
|
+
final IRubyObject self,
|
58
|
+
final IRubyObject string) {
|
59
|
+
return quoteSingleQuotesWithFallback(context, string);
|
60
|
+
}
|
61
|
+
|
62
|
+
@JRubyMethod(name = "quoted_true", required = 0, frame = false)
|
63
|
+
public static IRubyObject quoted_true(
|
64
|
+
final ThreadContext context,
|
65
|
+
final IRubyObject self) {
|
66
|
+
return RubyString.newString(context.runtime, BYTES_1);
|
67
|
+
}
|
68
|
+
|
69
|
+
@JRubyMethod(name = "quoted_false", required = 0, frame = false)
|
70
|
+
public static IRubyObject quoted_false(
|
71
|
+
final ThreadContext context,
|
72
|
+
final IRubyObject self) {
|
73
|
+
return RubyString.newString(context.runtime, BYTES_0);
|
74
|
+
}
|
75
|
+
|
76
|
+
}
|
@@ -0,0 +1,126 @@
|
|
1
|
+
/***** BEGIN LICENSE BLOCK *****
|
2
|
+
* Copyright (c) 2012-2013 Karol Bucek <self@kares.org>
|
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
|
+
package arjdbc.db2;
|
27
|
+
|
28
|
+
import arjdbc.jdbc.Callable;
|
29
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
30
|
+
import arjdbc.util.StringHelper;
|
31
|
+
|
32
|
+
import java.sql.Connection;
|
33
|
+
import java.sql.PreparedStatement;
|
34
|
+
import java.sql.ResultSet;
|
35
|
+
import java.sql.SQLException;
|
36
|
+
|
37
|
+
import org.jruby.Ruby;
|
38
|
+
import org.jruby.RubyBoolean;
|
39
|
+
import org.jruby.RubyClass;
|
40
|
+
import org.jruby.RubyString;
|
41
|
+
import org.jruby.anno.JRubyMethod;
|
42
|
+
import org.jruby.runtime.ObjectAllocator;
|
43
|
+
import org.jruby.runtime.ThreadContext;
|
44
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
45
|
+
import org.jruby.util.ByteList;
|
46
|
+
|
47
|
+
/**
|
48
|
+
*
|
49
|
+
* @author mikestone
|
50
|
+
*/
|
51
|
+
public class DB2RubyJdbcConnection extends RubyJdbcConnection {
|
52
|
+
|
53
|
+
public DB2RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
54
|
+
super(runtime, metaClass);
|
55
|
+
}
|
56
|
+
|
57
|
+
public static RubyClass createDB2JdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
|
58
|
+
RubyClass clazz = getConnectionAdapters(runtime).
|
59
|
+
defineClassUnder("DB2JdbcConnection", jdbcConnection, ALLOCATOR);
|
60
|
+
clazz.defineAnnotatedMethods(DB2RubyJdbcConnection.class);
|
61
|
+
|
62
|
+
return clazz;
|
63
|
+
}
|
64
|
+
|
65
|
+
public static RubyClass load(final Ruby runtime) {
|
66
|
+
RubyClass jdbcConnection = getJdbcConnection(runtime);
|
67
|
+
return createDB2JdbcConnectionClass(runtime, jdbcConnection);
|
68
|
+
}
|
69
|
+
|
70
|
+
protected static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
71
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
72
|
+
return new DB2RubyJdbcConnection(runtime, klass);
|
73
|
+
}
|
74
|
+
};
|
75
|
+
|
76
|
+
@JRubyMethod(name = "select?", required = 1, meta = true, frame = false)
|
77
|
+
public static RubyBoolean select_p(final ThreadContext context,
|
78
|
+
final IRubyObject self, final IRubyObject sql) {
|
79
|
+
final RubyString sqlStr = sql.asString();
|
80
|
+
if ( isValues(sqlStr) ) return context.runtime.getTrue();
|
81
|
+
return arjdbc.jdbc.RubyJdbcConnection.select_p(context, self, sqlStr);
|
82
|
+
}
|
83
|
+
|
84
|
+
// DB2 supports 'stand-alone' VALUES expressions
|
85
|
+
private static final byte[] VALUES = new byte[]{ 'v','a','l','u', 'e', 's' };
|
86
|
+
|
87
|
+
private static boolean isValues(final RubyString sql) {
|
88
|
+
final ByteList sqlBytes = sql.getByteList();
|
89
|
+
return StringHelper.startsWithIgnoreCase(sqlBytes, VALUES);
|
90
|
+
}
|
91
|
+
|
92
|
+
private static final String[] TABLE_TYPES = new String[] {
|
93
|
+
"TABLE", "VIEW", "SYNONYM", "MATERIALIZED QUERY TABLE", "ALIAS"
|
94
|
+
};
|
95
|
+
|
96
|
+
@Override
|
97
|
+
protected String[] getTableTypes() {
|
98
|
+
return TABLE_TYPES;
|
99
|
+
}
|
100
|
+
|
101
|
+
@Override
|
102
|
+
protected boolean databaseSupportsSchemas() {
|
103
|
+
return true;
|
104
|
+
}
|
105
|
+
|
106
|
+
@JRubyMethod(name = {"identity_val_local", "last_insert_id"})
|
107
|
+
public IRubyObject identity_val_local(final ThreadContext context)
|
108
|
+
throws SQLException {
|
109
|
+
return withConnection(context, new Callable<IRubyObject>() {
|
110
|
+
public IRubyObject call(final Connection connection) throws SQLException {
|
111
|
+
PreparedStatement statement = null; ResultSet genKeys = null;
|
112
|
+
try {
|
113
|
+
statement = connection.prepareStatement("VALUES IDENTITY_VAL_LOCAL()");
|
114
|
+
genKeys = statement.executeQuery();
|
115
|
+
return doMapGeneratedKeys(context.runtime, genKeys, true);
|
116
|
+
}
|
117
|
+
catch (final SQLException e) {
|
118
|
+
debugMessage(context.runtime, "failed to get generated keys: ", e);
|
119
|
+
throw e;
|
120
|
+
}
|
121
|
+
finally { close(genKeys); close(statement); }
|
122
|
+
}
|
123
|
+
});
|
124
|
+
}
|
125
|
+
|
126
|
+
}
|