activerecord-jdbc-adapter-onsite 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +22 -0
- data/.travis.yml +14 -0
- data/Appraisals +16 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +45 -0
- data/History.txt +488 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +214 -0
- data/Rakefile +62 -0
- data/activerecord-jdbc-adapter.gemspec +23 -0
- data/bench/bench_attributes.rb +13 -0
- data/bench/bench_attributes_new.rb +14 -0
- data/bench/bench_create.rb +12 -0
- data/bench/bench_find_all.rb +12 -0
- data/bench/bench_find_all_mt.rb +25 -0
- data/bench/bench_model.rb +85 -0
- data/bench/bench_new.rb +12 -0
- data/bench/bench_new_valid.rb +12 -0
- data/bench/bench_valid.rb +13 -0
- data/gemfiles/rails23.gemfile +10 -0
- data/gemfiles/rails23.gemfile.lock +38 -0
- data/gemfiles/rails30.gemfile +9 -0
- data/gemfiles/rails30.gemfile.lock +33 -0
- data/gemfiles/rails31.gemfile +9 -0
- data/gemfiles/rails31.gemfile.lock +35 -0
- data/gemfiles/rails32.gemfile +9 -0
- data/gemfiles/rails32.gemfile.lock +35 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +8 -0
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
- data/lib/arel/visitors/compat.rb +13 -0
- data/lib/arel/visitors/db2.rb +17 -0
- data/lib/arel/visitors/derby.rb +32 -0
- data/lib/arel/visitors/firebird.rb +24 -0
- data/lib/arel/visitors/hsqldb.rb +26 -0
- data/lib/arel/visitors/sql_server.rb +46 -0
- data/lib/arjdbc.rb +24 -0
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/arjdbc/db2/adapter.rb +541 -0
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/arjdbc/derby/adapter.rb +358 -0
- data/lib/arjdbc/derby/connection_methods.rb +19 -0
- data/lib/arjdbc/discover.rb +92 -0
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/arjdbc/firebird/adapter.rb +140 -0
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/arjdbc/h2/adapter.rb +54 -0
- data/lib/arjdbc/h2/connection_methods.rb +13 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/arjdbc/hsqldb/adapter.rb +184 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +15 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/arjdbc/informix/adapter.rb +142 -0
- data/lib/arjdbc/informix/connection_methods.rb +11 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/arjdbc/jdbc/adapter.rb +356 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/base_ext.rb +15 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +47 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +134 -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 +35 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/arjdbc/jdbc/jdbc.rake +131 -0
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +88 -0
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/arjdbc/jdbc/railtie.rb +9 -0
- data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
- data/lib/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +126 -0
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/arjdbc/mimer/adapter.rb +142 -0
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/arjdbc/mssql/adapter.rb +477 -0
- data/lib/arjdbc/mssql/connection_methods.rb +31 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +101 -0
- data/lib/arjdbc/mssql/lock_helpers.rb +72 -0
- data/lib/arjdbc/mssql/tsql_helper.rb +61 -0
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +505 -0
- data/lib/arjdbc/mysql/connection_methods.rb +28 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/arjdbc/oracle/adapter.rb +432 -0
- data/lib/arjdbc/oracle/connection_methods.rb +12 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/arjdbc/postgresql/adapter.rb +861 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +23 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/arjdbc/sqlite3/adapter.rb +389 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +35 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +46 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/USAGE +10 -0
- data/lib/generators/jdbc/jdbc_generator.rb +9 -0
- data/lib/jdbc_adapter.rb +2 -0
- data/lib/jdbc_adapter/rake_tasks.rb +3 -0
- data/lib/jdbc_adapter/version.rb +3 -0
- data/lib/pg.rb +26 -0
- data/pom.xml +57 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/compile.rake +23 -0
- data/rakelib/db.rake +39 -0
- data/rakelib/rails.rake +41 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +69 -0
- data/src/java/arjdbc/derby/DerbyModule.java +324 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +74 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +68 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +36 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1346 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +134 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +161 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +82 -0
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +126 -0
- data/test/abstract_db_create.rb +135 -0
- data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
- data/test/activerecord/jall.sh +7 -0
- data/test/activerecord/jtest.sh +3 -0
- data/test/db/db2.rb +11 -0
- data/test/db/derby.rb +12 -0
- data/test/db/h2.rb +11 -0
- data/test/db/hsqldb.rb +13 -0
- data/test/db/informix.rb +11 -0
- data/test/db/jdbc.rb +12 -0
- data/test/db/jndi_config.rb +40 -0
- data/test/db/logger.rb +3 -0
- data/test/db/mssql.rb +9 -0
- data/test/db/mysql.rb +10 -0
- data/test/db/oracle.rb +34 -0
- data/test/db/postgres.rb +18 -0
- data/test/db/sqlite3.rb +11 -0
- data/test/db2_reset_column_information_test.rb +8 -0
- data/test/db2_simple_test.rb +66 -0
- data/test/derby_migration_test.rb +68 -0
- data/test/derby_multibyte_test.rb +12 -0
- data/test/derby_reset_column_information_test.rb +8 -0
- data/test/derby_row_locking_test.rb +9 -0
- data/test/derby_simple_test.rb +139 -0
- data/test/generic_jdbc_connection_test.rb +29 -0
- data/test/h2_change_column_test.rb +68 -0
- data/test/h2_simple_test.rb +41 -0
- data/test/has_many_through.rb +79 -0
- data/test/helper.rb +108 -0
- data/test/hsqldb_simple_test.rb +6 -0
- data/test/informix_simple_test.rb +48 -0
- data/test/jdbc_common.rb +28 -0
- data/test/jndi_callbacks_test.rb +36 -0
- data/test/jndi_test.rb +25 -0
- data/test/manualTestDatabase.rb +191 -0
- data/test/models/add_not_null_column_to_table.rb +9 -0
- data/test/models/auto_id.rb +15 -0
- data/test/models/custom_pk_name.rb +14 -0
- data/test/models/data_types.rb +30 -0
- data/test/models/entry.rb +40 -0
- data/test/models/mixed_case.rb +22 -0
- data/test/models/reserved_word.rb +15 -0
- data/test/models/string_id.rb +17 -0
- data/test/models/thing.rb +16 -0
- data/test/models/validates_uniqueness_of_string.rb +19 -0
- data/test/mssql_db_create_test.rb +26 -0
- data/test/mssql_identity_insert_test.rb +19 -0
- data/test/mssql_ignore_system_views_test.rb +27 -0
- data/test/mssql_legacy_types_test.rb +58 -0
- data/test/mssql_limit_offset_test.rb +136 -0
- data/test/mssql_multibyte_test.rb +18 -0
- data/test/mssql_null_test.rb +14 -0
- data/test/mssql_reset_column_information_test.rb +8 -0
- data/test/mssql_row_locking_sql_test.rb +159 -0
- data/test/mssql_row_locking_test.rb +9 -0
- data/test/mssql_simple_test.rb +55 -0
- data/test/mysql_db_create_test.rb +27 -0
- data/test/mysql_index_length_test.rb +58 -0
- data/test/mysql_info_test.rb +123 -0
- data/test/mysql_multibyte_test.rb +10 -0
- data/test/mysql_nonstandard_primary_key_test.rb +42 -0
- data/test/mysql_reset_column_information_test.rb +8 -0
- data/test/mysql_simple_test.rb +125 -0
- data/test/oracle_reset_column_information_test.rb +8 -0
- data/test/oracle_simple_test.rb +18 -0
- data/test/oracle_specific_test.rb +83 -0
- data/test/postgres_db_create_test.rb +32 -0
- data/test/postgres_drop_db_test.rb +16 -0
- data/test/postgres_information_schema_leak_test.rb +29 -0
- data/test/postgres_mixed_case_test.rb +29 -0
- data/test/postgres_native_type_mapping_test.rb +93 -0
- data/test/postgres_nonseq_pkey_test.rb +38 -0
- data/test/postgres_reserved_test.rb +22 -0
- data/test/postgres_reset_column_information_test.rb +8 -0
- data/test/postgres_schema_search_path_test.rb +48 -0
- data/test/postgres_simple_test.rb +168 -0
- data/test/postgres_table_alias_length_test.rb +15 -0
- data/test/postgres_type_conversion_test.rb +34 -0
- data/test/row_locking.rb +90 -0
- data/test/simple.rb +731 -0
- data/test/sqlite3_reset_column_information_test.rb +8 -0
- data/test/sqlite3_simple_test.rb +316 -0
- data/test/sybase_jtds_simple_test.rb +28 -0
- data/test/sybase_reset_column_information_test.rb +8 -0
- metadata +288 -0
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
package arjdbc.oracle;
|
|
27
|
+
|
|
28
|
+
import java.sql.ResultSet;
|
|
29
|
+
import java.sql.SQLException;
|
|
30
|
+
|
|
31
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
|
32
|
+
|
|
33
|
+
import org.jruby.Ruby;
|
|
34
|
+
import org.jruby.RubyClass;
|
|
35
|
+
import org.jruby.runtime.ObjectAllocator;
|
|
36
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @author nicksieger
|
|
41
|
+
*/
|
|
42
|
+
public class OracleRubyJdbcConnection extends RubyJdbcConnection {
|
|
43
|
+
protected OracleRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
|
44
|
+
super(runtime, metaClass);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public static RubyClass createOracleJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
|
|
48
|
+
RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("OracleJdbcConnection",
|
|
49
|
+
jdbcConnection, ORACLE_JDBCCONNECTION_ALLOCATOR);
|
|
50
|
+
clazz.defineAnnotatedMethods(OracleRubyJdbcConnection.class);
|
|
51
|
+
|
|
52
|
+
return clazz;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private static ObjectAllocator ORACLE_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
|
|
56
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
|
57
|
+
return new OracleRubyJdbcConnection(runtime, klass);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Oracle needs this override to reconstruct NUMBER which is different
|
|
63
|
+
* from NUMBER(x) or NUMBER(x,y).
|
|
64
|
+
*/
|
|
65
|
+
@Override
|
|
66
|
+
protected String typeFromResultSet(ResultSet resultSet) throws SQLException {
|
|
67
|
+
int precision = intFromResultSet(resultSet, COLUMN_SIZE);
|
|
68
|
+
int scale = intFromResultSet(resultSet, DECIMAL_DIGITS);
|
|
69
|
+
|
|
70
|
+
// According to http://forums.oracle.com/forums/thread.jspa?threadID=658646
|
|
71
|
+
// Unadorned NUMBER reports scale == null, so we look for that here.
|
|
72
|
+
if (scale < 0 && resultSet.getInt(DATA_TYPE) == java.sql.Types.DECIMAL) {
|
|
73
|
+
precision = -1;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
String type = resultSet.getString(TYPE_NAME);
|
|
77
|
+
if (precision > 0) {
|
|
78
|
+
type += "(" + precision;
|
|
79
|
+
if(scale > 0) type += "," + scale;
|
|
80
|
+
type += ")";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return type;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
package arjdbc.postgresql;
|
|
27
|
+
|
|
28
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
|
29
|
+
|
|
30
|
+
import java.sql.ResultSet;
|
|
31
|
+
import java.sql.SQLException;
|
|
32
|
+
import java.sql.Types;
|
|
33
|
+
|
|
34
|
+
import org.jruby.Ruby;
|
|
35
|
+
import org.jruby.RubyClass;
|
|
36
|
+
import org.jruby.runtime.ObjectAllocator;
|
|
37
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @author enebo
|
|
42
|
+
*/
|
|
43
|
+
public class PostgresqlRubyJdbcConnection extends RubyJdbcConnection {
|
|
44
|
+
protected PostgresqlRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
|
45
|
+
super(runtime, metaClass);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public static RubyClass createPostgresqlJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
|
|
49
|
+
RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("PostgresJdbcConnection",
|
|
50
|
+
jdbcConnection, POSTGRESQL_JDBCCONNECTION_ALLOCATOR);
|
|
51
|
+
clazz.defineAnnotatedMethods(PostgresqlRubyJdbcConnection.class);
|
|
52
|
+
|
|
53
|
+
return clazz;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Override jdbcToRuby type conversions to handle infinite timestamps.
|
|
58
|
+
* Handing timestamp off to ruby as string so adapter can perform type
|
|
59
|
+
* conversion to timestamp
|
|
60
|
+
*/
|
|
61
|
+
@Override
|
|
62
|
+
protected IRubyObject jdbcToRuby(Ruby runtime, int column, int type,
|
|
63
|
+
ResultSet resultSet)
|
|
64
|
+
throws SQLException {
|
|
65
|
+
if(type == Types.TIMESTAMP) {
|
|
66
|
+
try {
|
|
67
|
+
return stringToRuby(runtime, resultSet,
|
|
68
|
+
resultSet.getString(column));
|
|
69
|
+
} catch(java.io.IOException ioe) {
|
|
70
|
+
SQLException ex = new SQLException(ioe.getMessage());
|
|
71
|
+
throw (SQLException) ex.initCause(ioe);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return super.jdbcToRuby(runtime, column, type, resultSet);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private static ObjectAllocator POSTGRESQL_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
|
|
78
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
|
79
|
+
return new PostgresqlRubyJdbcConnection(runtime, klass);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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 java.io.ByteArrayInputStream;
|
|
30
|
+
import java.io.IOException;
|
|
31
|
+
import java.sql.Connection;
|
|
32
|
+
import java.sql.ResultSet;
|
|
33
|
+
import java.sql.ResultSetMetaData;
|
|
34
|
+
import java.sql.SQLException;
|
|
35
|
+
import java.sql.Statement;
|
|
36
|
+
import java.sql.Types;
|
|
37
|
+
|
|
38
|
+
import arjdbc.jdbc.RubyJdbcConnection;
|
|
39
|
+
import arjdbc.jdbc.SQLBlock;
|
|
40
|
+
|
|
41
|
+
import org.jruby.Ruby;
|
|
42
|
+
import org.jruby.RubyClass;
|
|
43
|
+
import org.jruby.anno.JRubyMethod;
|
|
44
|
+
import org.jruby.runtime.ObjectAllocator;
|
|
45
|
+
import org.jruby.runtime.ThreadContext;
|
|
46
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @author enebo
|
|
51
|
+
*/
|
|
52
|
+
public class Sqlite3RubyJdbcConnection extends RubyJdbcConnection {
|
|
53
|
+
protected Sqlite3RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
|
54
|
+
super(runtime, metaClass);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public static RubyClass createSqlite3JdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
|
|
58
|
+
RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("Sqlite3JdbcConnection",
|
|
59
|
+
jdbcConnection, SQLITE3_JDBCCONNECTION_ALLOCATOR);
|
|
60
|
+
clazz.defineAnnotatedMethods(Sqlite3RubyJdbcConnection.class);
|
|
61
|
+
|
|
62
|
+
return clazz;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private static ObjectAllocator SQLITE3_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
|
|
66
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
|
67
|
+
return new Sqlite3RubyJdbcConnection(runtime, klass);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
@JRubyMethod(name = "last_insert_row_id")
|
|
72
|
+
public IRubyObject getLastInsertRowId(final ThreadContext context)
|
|
73
|
+
throws SQLException {
|
|
74
|
+
return (IRubyObject) withConnectionAndRetry(context, new SQLBlock() {
|
|
75
|
+
public Object call(Connection c) throws SQLException {
|
|
76
|
+
Statement stmt = null;
|
|
77
|
+
try {
|
|
78
|
+
stmt = c.createStatement();
|
|
79
|
+
return unmarshal_id_result(context.getRuntime(),
|
|
80
|
+
stmt.getGeneratedKeys());
|
|
81
|
+
} catch (SQLException sqe) {
|
|
82
|
+
if (context.getRuntime().isDebug()) {
|
|
83
|
+
System.out.println("Error SQL:" + sqe.getMessage());
|
|
84
|
+
}
|
|
85
|
+
throw sqe;
|
|
86
|
+
} finally {
|
|
87
|
+
close(stmt);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@Override
|
|
94
|
+
protected IRubyObject tables(ThreadContext context, String catalog, String schemaPattern, String tablePattern, String[] types) {
|
|
95
|
+
return (IRubyObject) withConnectionAndRetry(context, tableLookupBlock(context.getRuntime(), catalog, schemaPattern, tablePattern, types, true));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@Override
|
|
99
|
+
protected IRubyObject jdbcToRuby(Ruby runtime, int column, int type, ResultSet resultSet)
|
|
100
|
+
throws SQLException {
|
|
101
|
+
try {
|
|
102
|
+
// This is rather gross, and only needed because the resultset metadata for SQLite tries to be overly
|
|
103
|
+
// clever, and returns a type for the column of the "current" row, so an integer value stored in a
|
|
104
|
+
// decimal column is returned as Types.INTEGER. Therefore, if the first row of a resultset was an
|
|
105
|
+
// integer value, all rows of that result set would get truncated.
|
|
106
|
+
if( resultSet instanceof ResultSetMetaData ) {
|
|
107
|
+
type = ((ResultSetMetaData)resultSet).getColumnType(column);
|
|
108
|
+
}
|
|
109
|
+
switch (type) {
|
|
110
|
+
case Types.BINARY:
|
|
111
|
+
case Types.BLOB:
|
|
112
|
+
case Types.LONGVARBINARY:
|
|
113
|
+
case Types.VARBINARY:
|
|
114
|
+
return streamToRuby(runtime, resultSet, new ByteArrayInputStream(resultSet.getBytes(column)));
|
|
115
|
+
case Types.LONGVARCHAR:
|
|
116
|
+
return runtime.is1_9() ?
|
|
117
|
+
readerToRuby(runtime, resultSet, resultSet.getCharacterStream(column)) :
|
|
118
|
+
streamToRuby(runtime, resultSet, new ByteArrayInputStream(resultSet.getBytes(column)));
|
|
119
|
+
default:
|
|
120
|
+
return super.jdbcToRuby(runtime, column, type, resultSet);
|
|
121
|
+
}
|
|
122
|
+
} catch (IOException ioe) {
|
|
123
|
+
throw (SQLException) new SQLException(ioe.getMessage()).initCause(ioe);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
module Rails
|
|
5
|
+
class Configuration
|
|
6
|
+
end
|
|
7
|
+
class Application
|
|
8
|
+
def self.config
|
|
9
|
+
@config ||= Object.new
|
|
10
|
+
end
|
|
11
|
+
def self.paths
|
|
12
|
+
@paths ||= Hash.new { [] }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
def self.application
|
|
16
|
+
Rails::Application
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module AbstractDbCreate
|
|
21
|
+
def self.included(base)
|
|
22
|
+
base.module_eval { include Rake::DSL } if defined?(Rake::DSL)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def setup
|
|
26
|
+
@prevapp = Rake.application
|
|
27
|
+
Rake.application = Rake::Application.new
|
|
28
|
+
verbose(true)
|
|
29
|
+
do_setup
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def do_setup(env = 'unittest', db = 'test_rake_db_create')
|
|
33
|
+
@env = env
|
|
34
|
+
@prevconfigs = ActiveRecord::Base.configurations
|
|
35
|
+
ActiveRecord::Base.connection.disconnect!
|
|
36
|
+
@db_name = db
|
|
37
|
+
setup_rails
|
|
38
|
+
set_rails_constant("env", @env)
|
|
39
|
+
set_rails_constant("root", ".")
|
|
40
|
+
load File.dirname(__FILE__) + '/../lib/arjdbc/jdbc/jdbc.rake' if jruby?
|
|
41
|
+
task :environment do
|
|
42
|
+
ActiveRecord::Base.configurations = configurations
|
|
43
|
+
@full_env_loaded = true
|
|
44
|
+
end
|
|
45
|
+
task :rails_env do
|
|
46
|
+
@rails_env_set = true
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def teardown
|
|
51
|
+
Rake::Task["db:drop"].invoke
|
|
52
|
+
Rake.application = @prevapp
|
|
53
|
+
restore_rails
|
|
54
|
+
ActiveRecord::Base.configurations = @prevconfigs
|
|
55
|
+
ActiveRecord::Base.establish_connection(db_config)
|
|
56
|
+
@rails_env_set = nil
|
|
57
|
+
@full_env_loaded = nil
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def setup_rails
|
|
61
|
+
if ActiveRecord::VERSION::MAJOR == 3
|
|
62
|
+
setup_rails3
|
|
63
|
+
else
|
|
64
|
+
setup_rails2
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def configurations
|
|
69
|
+
the_db_name = @db_name
|
|
70
|
+
the_db_config = db_config
|
|
71
|
+
the_db_config = the_db_config.merge({:database => the_db_name}) if the_db_name
|
|
72
|
+
the_db_config.stringify_keys!
|
|
73
|
+
@configs = { @env => the_db_config }
|
|
74
|
+
@configs["test"] = @configs[@env].dup
|
|
75
|
+
@configs
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def setup_rails2
|
|
79
|
+
configs = configurations
|
|
80
|
+
Rails::Configuration.class_eval do
|
|
81
|
+
define_method(:database_configuration) { configs }
|
|
82
|
+
end
|
|
83
|
+
ar_version = $LOADED_FEATURES.grep(%r{active_record/version}).first
|
|
84
|
+
ar_lib_path = $LOAD_PATH.detect {|p| p if File.exist?File.join(p, ar_version)}
|
|
85
|
+
ar_lib_path = ar_lib_path.sub(%r{activerecord/lib}, 'railties/lib') # edge rails
|
|
86
|
+
rails_lib_path = ar_lib_path.sub(/activerecord-([\d\.]+)/, 'rails-\1') # gem rails
|
|
87
|
+
load "#{rails_lib_path}/tasks/databases.rake"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def setup_rails3
|
|
91
|
+
configs = configurations
|
|
92
|
+
(class << Rails::Application.config; self ; end).instance_eval do
|
|
93
|
+
define_method(:database_configuration) { configs }
|
|
94
|
+
end
|
|
95
|
+
require 'pathname'
|
|
96
|
+
ar_version = $LOADED_FEATURES.grep(%r{active_record/version}).first
|
|
97
|
+
ar_lib_path = $LOAD_PATH.detect do |p|
|
|
98
|
+
Pathname.new(p).absolute? && ar_version.start_with?(p) ||
|
|
99
|
+
File.exist?(File.join(p, ar_version))
|
|
100
|
+
end
|
|
101
|
+
load "#{ar_lib_path}/active_record/railties/databases.rake"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def set_rails_constant(name, value)
|
|
105
|
+
cname ="RAILS_#{name.upcase}"
|
|
106
|
+
@constants ||= {}
|
|
107
|
+
@constants[name] = Object.const_get(cname) rescue nil
|
|
108
|
+
silence_warnings { Object.const_set(cname, value) }
|
|
109
|
+
Rails.instance_eval do
|
|
110
|
+
if instance_methods(false).include?(name)
|
|
111
|
+
alias_method "orig_#{name}", name
|
|
112
|
+
define_method(name) { value }
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def restore_rails
|
|
118
|
+
@constants.each do |key,value|
|
|
119
|
+
silence_warnings { Object.const_set("RAILS_#{key.upcase}", value) }
|
|
120
|
+
Rails.instance_eval do
|
|
121
|
+
if instance_methods(false).include?(name)
|
|
122
|
+
remove_method name
|
|
123
|
+
alias_method name, "orig_#{name}"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def silence_warnings
|
|
130
|
+
prev, $VERBOSE = $VERBOSE, nil
|
|
131
|
+
yield
|
|
132
|
+
ensure
|
|
133
|
+
$VERBOSE = prev
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'java'
|
|
2
|
+
require 'models/data_types'
|
|
3
|
+
require 'arjdbc'
|
|
4
|
+
require 'db/derby'
|
|
5
|
+
require 'test/unit'
|
|
6
|
+
|
|
7
|
+
JInteger = java.lang.Integer
|
|
8
|
+
|
|
9
|
+
class TypeConversionTest < Test::Unit::TestCase
|
|
10
|
+
TEST_TIME = Time.at(1169964202).gmtime
|
|
11
|
+
def setup
|
|
12
|
+
DbTypeMigration.up
|
|
13
|
+
DbType.create(
|
|
14
|
+
:sample_timestamp => TEST_TIME,
|
|
15
|
+
:sample_decimal => JInteger::MAX_VALUE + 1)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def teardown
|
|
19
|
+
DbTypeMigration.down
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_timestamp
|
|
23
|
+
types = DbType.find(:first)
|
|
24
|
+
assert_equal TEST_TIME, types.sample_timestamp.getutc
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_decimal
|
|
28
|
+
types = DbType.find(:first)
|
|
29
|
+
assert_equal((JInteger::MAX_VALUE + 1), types.sample_decimal)
|
|
30
|
+
end
|
|
31
|
+
end
|