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,46 @@
|
|
1
|
+
require 'arjdbc/tasks/jdbc_database_tasks'
|
2
|
+
|
3
|
+
module ArJdbc
|
4
|
+
module Tasks
|
5
|
+
class MSSQLDatabaseTasks < JdbcDatabaseTasks
|
6
|
+
|
7
|
+
def purge
|
8
|
+
test = deep_dup(configuration)
|
9
|
+
test_database = resolve_database(test)
|
10
|
+
test['database'] = 'master'
|
11
|
+
establish_connection(test)
|
12
|
+
connection.recreate_database!(test_database)
|
13
|
+
end
|
14
|
+
|
15
|
+
def structure_dump(filename)
|
16
|
+
config = config_from_url_if_needed
|
17
|
+
`smoscript -s #{config['host']} -d #{config['database']} -u #{config['username']} -p #{config['password']} -f #{filename} -A -U`
|
18
|
+
end
|
19
|
+
|
20
|
+
def structure_load(filename)
|
21
|
+
config = config_from_url_if_needed
|
22
|
+
`sqlcmd -S #{config['host']} -d #{config['database']} -U #{config['username']} -P #{config['password']} -i #{filename}`
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def config_from_url_if_needed
|
28
|
+
config = self.config
|
29
|
+
if config['url'] && ! config.key?('database')
|
30
|
+
config = config_from_url(config['url'])
|
31
|
+
end
|
32
|
+
config
|
33
|
+
end
|
34
|
+
|
35
|
+
def deep_dup(hash)
|
36
|
+
dup = hash.dup
|
37
|
+
dup.each_pair do |k,v|
|
38
|
+
tv = dup[k]
|
39
|
+
dup[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? deep_dup(tv) : v
|
40
|
+
end
|
41
|
+
dup
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module Util
|
3
|
+
# Caches table and column name (quoted) outcomes.
|
4
|
+
# Uses {ThreadSafe::Cache} as a concurrent lock free (on JRuby) cache backend.
|
5
|
+
# The thread_safe gem is a dependency since ActiveSupport 4.0, when using
|
6
|
+
# ActiveRecord <= 3.2 one should add `gem 'thread_safe'` into the *Gemfile*
|
7
|
+
# as it is not forced (currently) as an explicit gem dependency.
|
8
|
+
#
|
9
|
+
# Caching can also be disabled by setting the *arjdbc.quoted_cache.disabled*
|
10
|
+
# system property = 'true'.
|
11
|
+
module QuotedCache
|
12
|
+
|
13
|
+
# @private
|
14
|
+
DISABLED = Java::JavaLang::Boolean.getBoolean('arjdbc.quoted_cache.disabled')
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
# the thread_safe gem is an ActiveSupport dependency (since 4.0) :
|
18
|
+
begin; require 'thread_safe'; rescue LoadError; end unless DISABLED
|
19
|
+
if ! DISABLED && defined? ThreadSafe::Cache
|
20
|
+
base.const_set :QUOTED_TABLE_NAMES, ThreadSafe::Cache.new
|
21
|
+
base.const_set :QUOTED_COLUMN_NAMES, ThreadSafe::Cache.new
|
22
|
+
else
|
23
|
+
base.const_set :QUOTED_TABLE_NAMES, nil
|
24
|
+
base.const_set :QUOTED_COLUMN_NAMES, nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Caches quoted table names, the cache is stored in the class'
|
29
|
+
# `QUOTED_TABLE_NAMES` constant.
|
30
|
+
# @return [String]
|
31
|
+
def quote_table_name(name, *args)
|
32
|
+
if cache = self.class::QUOTED_TABLE_NAMES
|
33
|
+
unless quoted = cache[name]
|
34
|
+
quoted = super
|
35
|
+
cache.put_if_absent name, quoted.freeze
|
36
|
+
end
|
37
|
+
quoted
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Caches quoted table names, the cache is stored in the class'
|
44
|
+
# `QUOTED_COLUMN_NAMES` constant.
|
45
|
+
# @return [String]
|
46
|
+
def quote_column_name(name, *args)
|
47
|
+
if cache = self.class::QUOTED_COLUMN_NAMES
|
48
|
+
unless quoted = cache[name]
|
49
|
+
quoted = super
|
50
|
+
cache.put_if_absent name, quoted.freeze
|
51
|
+
end
|
52
|
+
quoted
|
53
|
+
else
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module Util
|
3
|
+
# Gets included into `ActiveRecord::Base` to support sending LOB values
|
4
|
+
# in a separate update SQL statement for DB adapters that need this.
|
5
|
+
module SerializedAttributes
|
6
|
+
|
7
|
+
# protected
|
8
|
+
|
9
|
+
def update_lob_columns
|
10
|
+
klass = self.class
|
11
|
+
return unless type = klass.lob_type # e.g. /blob/i
|
12
|
+
connection = klass.connection
|
13
|
+
if connection.respond_to?(:update_lob_values?)
|
14
|
+
return false unless connection.update_lob_values?
|
15
|
+
end
|
16
|
+
klass.columns.each do |column|
|
17
|
+
next if column.sql_type !~ type
|
18
|
+
next if ( value = dump_column_value(column) ).nil?
|
19
|
+
if connection.respond_to?(:update_lob_value?)
|
20
|
+
next unless connection.update_lob_value?(value, column)
|
21
|
+
end
|
22
|
+
connection.update_lob_value(self, column, value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def dump_column_value(column)
|
29
|
+
SerializedAttributes.dump_column_value(self, column)
|
30
|
+
end
|
31
|
+
|
32
|
+
if defined? ActiveRecord::Type::Serialized # ArJdbc::AR42
|
33
|
+
|
34
|
+
def self.dump_column_value(record, column)
|
35
|
+
value = record[ column.name.to_s ]
|
36
|
+
column.cast_type.type_cast_for_database(value)
|
37
|
+
end
|
38
|
+
|
39
|
+
else
|
40
|
+
|
41
|
+
def self.dump_column_value(record, column)
|
42
|
+
value = record[ name = column.name.to_s ]
|
43
|
+
if record.class.respond_to?(:serialized_attributes)
|
44
|
+
if coder = record.class.serialized_attributes[name]
|
45
|
+
value = coder.respond_to?(:dump) ? coder.dump(value) : value.to_yaml
|
46
|
+
end
|
47
|
+
else
|
48
|
+
if record.respond_to?(:unserializable_attribute?)
|
49
|
+
value = value.to_yaml if record.unserializable_attribute?(name, column)
|
50
|
+
else
|
51
|
+
value = value.to_yaml if value.is_a?(Hash)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
value
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.setup(lob_type = nil, after_save_alias = nil)
|
60
|
+
ActiveRecord::Base.send :include, self # include SerializedAttributes
|
61
|
+
ActiveRecord::Base.lob_type = lob_type unless lob_type.nil?
|
62
|
+
if after_save_alias
|
63
|
+
ActiveRecord::Base.class_eval do
|
64
|
+
alias_method after_save_alias, 'update_lob_columns'
|
65
|
+
end
|
66
|
+
ActiveRecord::Base.after_save after_save_alias
|
67
|
+
else
|
68
|
+
ActiveRecord::Base.after_save 'update_lob_columns'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.included(base)
|
73
|
+
base.extend ClassMethods
|
74
|
+
end
|
75
|
+
|
76
|
+
module ClassMethods
|
77
|
+
|
78
|
+
def lob_type
|
79
|
+
@lob_type ||= begin
|
80
|
+
if superclass.respond_to?(:lob_type)
|
81
|
+
superclass.lob_type
|
82
|
+
else
|
83
|
+
/blob|clob/i
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def lob_type=(type)
|
89
|
+
@lob_type = type
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
# @private only due backwards compatibility
|
97
|
+
SerializedAttributesHelper = Util::SerializedAttributes
|
98
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module Util
|
3
|
+
module TableCopier
|
4
|
+
|
5
|
+
# taken from SQLite adapter, code loosely based on http://git.io/P7tFQA
|
6
|
+
|
7
|
+
# Performs changes for table by first copying (and preserving contents)
|
8
|
+
# into another (temporary) table, than alters and copies all data back.
|
9
|
+
def alter_table(table_name, options = {})
|
10
|
+
table_name = table_name.to_s.downcase
|
11
|
+
altered_table_name = "a#{table_name}"
|
12
|
+
caller = lambda { |definition| yield definition if block_given? }
|
13
|
+
|
14
|
+
transaction do
|
15
|
+
# A temporary table might improve performance here, but
|
16
|
+
# it doesn't seem to maintain indices across the whole move.
|
17
|
+
move_table(table_name, altered_table_name, options)
|
18
|
+
move_table(altered_table_name, table_name, &caller)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Move a table into another while preserving all content.
|
23
|
+
# @see #copy_table
|
24
|
+
def move_table(from, to, options = {}, &block)
|
25
|
+
copy_table(from, to, options, &block)
|
26
|
+
drop_table(from)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @see #copy_table_contents
|
30
|
+
# @see #copy_table_indexes
|
31
|
+
def copy_table(from, to, options = {})
|
32
|
+
from_primary_key = primary_key(from)
|
33
|
+
create_table(to, options.merge(:id => false)) do |definition|
|
34
|
+
@definition = definition
|
35
|
+
@definition.primary_key(from_primary_key) if from_primary_key.present?
|
36
|
+
columns(from).each do |column|
|
37
|
+
column_name = options[:rename] ?
|
38
|
+
(options[:rename][column.name] ||
|
39
|
+
options[:rename][column.name.to_sym] ||
|
40
|
+
column.name) : column.name
|
41
|
+
|
42
|
+
next if column_name == from_primary_key
|
43
|
+
|
44
|
+
@definition.column(column_name, column.type,
|
45
|
+
:limit => column.limit, :default => column.default,
|
46
|
+
:precision => column.precision, :scale => column.scale,
|
47
|
+
:null => column.null)
|
48
|
+
end
|
49
|
+
yield @definition if block_given?
|
50
|
+
end
|
51
|
+
|
52
|
+
copy_table_indexes(from, to, options[:rename] || {})
|
53
|
+
copy_table_contents(from, to,
|
54
|
+
@definition.columns.map {|column| column.name},
|
55
|
+
options[:rename] || {})
|
56
|
+
end
|
57
|
+
|
58
|
+
# Copies indexes for a given table.
|
59
|
+
def copy_table_indexes(from, to, rename = {})
|
60
|
+
indexes(from).each do |index|
|
61
|
+
name = index.name.downcase
|
62
|
+
if to == "a#{from}"
|
63
|
+
name = "t#{name}"
|
64
|
+
elsif from == "a#{to}"
|
65
|
+
name = name[1..-1]
|
66
|
+
end
|
67
|
+
|
68
|
+
to_column_names = columns(to).map(&:name)
|
69
|
+
columns = index.columns.map { |column| rename[column] || column }
|
70
|
+
columns = columns.select { |column| to_column_names.include?(column) }
|
71
|
+
|
72
|
+
unless columns.empty?
|
73
|
+
# index name can't be the same
|
74
|
+
opts = { :name => name.gsub(/(^|_)(#{from})_/, "\\1#{to}_"), :internal => true }
|
75
|
+
opts[:unique] = true if index.unique
|
76
|
+
add_index(to, columns, opts)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Copies the content of a table into another.
|
82
|
+
def copy_table_contents(from, to, columns, rename = {})
|
83
|
+
column_mappings = Hash[ columns.map { |name| [name, name] } ]
|
84
|
+
rename.each { |a| column_mappings[a.last] = a.first }
|
85
|
+
from_columns = columns(from).collect {|col| col.name}
|
86
|
+
columns = columns.find_all{ |col| from_columns.include?(column_mappings[col]) }
|
87
|
+
quoted_columns = columns.map { |col| quote_column_name(col) } * ','
|
88
|
+
|
89
|
+
quoted_to = quote_table_name(to)
|
90
|
+
|
91
|
+
raw_column_mappings = Hash[ columns(from).map { |c| [c.name, c] } ]
|
92
|
+
|
93
|
+
execute("SELECT * FROM #{quote_table_name(from)}", 'Copy Table').each do |row|
|
94
|
+
sql = "INSERT INTO #{quoted_to} (#{quoted_columns}) VALUES ("
|
95
|
+
|
96
|
+
column_values = columns.map do |col|
|
97
|
+
quote(row[column_mappings[col]], raw_column_mappings[col])
|
98
|
+
end
|
99
|
+
|
100
|
+
sql << column_values * ', '
|
101
|
+
sql << ')'
|
102
|
+
exec_insert sql, 'Copy Table', []
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
# @private @deprecated backwards compatibility
|
109
|
+
MissingFunctionalityHelper = Util::TableCopier
|
110
|
+
end
|
data/lib/arjdbc/version.rb
CHANGED
@@ -6,4 +6,12 @@ class JdbcGenerator < Rails::Generators::Base
|
|
6
6
|
def create_jdbc_files
|
7
7
|
directory '.', '.'
|
8
8
|
end
|
9
|
+
|
10
|
+
def self.desc(description=nil)
|
11
|
+
return super if description
|
12
|
+
"Description:\n" <<
|
13
|
+
" Creates stubs that ensure AR-JDBC is bootstrapped in your Rails application.\n" <<
|
14
|
+
" NOTE: you should not need this if you're on Rails >= 3.0 (using Bundler) ..."
|
15
|
+
end
|
16
|
+
|
9
17
|
end
|
data/lib/jdbc_adapter.rb
CHANGED
data/lib/jdbc_adapter/version.rb
CHANGED
data/pom.xml
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
2
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
3
|
+
<modelVersion>4.0.0</modelVersion>
|
4
|
+
<groupId>org.jruby.rails</groupId>
|
5
|
+
<artifactId>activerecord-jdbc</artifactId>
|
6
|
+
<packaging>jar</packaging>
|
7
|
+
<version>IDE-SNAPSHOT</version>
|
8
|
+
<name>activerecord-jdbc</name>
|
9
|
+
<description>
|
10
|
+
This POM for ActiveRecord-JDBC is just for bootstrapping IDEs.
|
11
|
+
</description>
|
12
|
+
<url>http://github.com/jruby/activerecord-jdbc-adapter/wiki</url>
|
13
|
+
|
14
|
+
<properties>
|
15
|
+
<jruby.version>9.1.6.0</jruby.version>
|
16
|
+
</properties>
|
17
|
+
|
18
|
+
<issueManagement>
|
19
|
+
<system>GitHub</system>
|
20
|
+
<url>http://github.com/jruby/activerecord-jdbc-adapter/issues</url>
|
21
|
+
</issueManagement>
|
22
|
+
|
23
|
+
<scm>
|
24
|
+
<connection>scm:git:git://github.com/jruby/activerecord-jdbc-adapter.git</connection>
|
25
|
+
<developerConnection>scm:git:git@github.com:jruby/activerecord-jdbc-adapter.git</developerConnection>
|
26
|
+
<url>https://github.com/jruby/activerecord-jdbc-adapter</url>
|
27
|
+
</scm>
|
28
|
+
|
29
|
+
<licenses>
|
30
|
+
<license>
|
31
|
+
<name>BSD</name>
|
32
|
+
<url>http://www.opensource.org/licenses/bsd-license.php</url>
|
33
|
+
<distribution>repo</distribution>
|
34
|
+
</license>
|
35
|
+
<license>
|
36
|
+
<name>MIT License</name>
|
37
|
+
<url>http://www.opensource.org/licenses/mit-license.php</url>
|
38
|
+
<distribution>repo</distribution>
|
39
|
+
</license>
|
40
|
+
</licenses>
|
41
|
+
<!--
|
42
|
+
<repositories>
|
43
|
+
<repository>
|
44
|
+
<id>codehaus</id>
|
45
|
+
<name>Codehaus Repository</name>
|
46
|
+
<releases>
|
47
|
+
<enabled>true</enabled>
|
48
|
+
</releases>
|
49
|
+
<snapshots>
|
50
|
+
<enabled>false</enabled>
|
51
|
+
</snapshots>
|
52
|
+
<url>http://repository.codehaus.org</url>
|
53
|
+
</repository>
|
54
|
+
</repositories>-->
|
55
|
+
|
56
|
+
<developers>
|
57
|
+
<developer>
|
58
|
+
<id>nicksieger</id>
|
59
|
+
<name>Nick Sieger</name>
|
60
|
+
<email>nicksieger@gmail.com</email>
|
61
|
+
</developer>
|
62
|
+
<developer>
|
63
|
+
<id>kares</id>
|
64
|
+
<name>Karol Bucek</name>
|
65
|
+
<email>self@kares.org</email>
|
66
|
+
</developer>
|
67
|
+
</developers>
|
68
|
+
|
69
|
+
<dependencies>
|
70
|
+
<dependency>
|
71
|
+
<groupId>org.jruby</groupId>
|
72
|
+
<artifactId>jruby-complete</artifactId>
|
73
|
+
<version>${jruby.version}</version>
|
74
|
+
</dependency>
|
75
|
+
<dependency>
|
76
|
+
<groupId>org.postgresql</groupId>
|
77
|
+
<artifactId>postgresql</artifactId>
|
78
|
+
<version>42.1.4.jre7</version>
|
79
|
+
</dependency>
|
80
|
+
</dependencies>
|
81
|
+
|
82
|
+
<build>
|
83
|
+
|
84
|
+
<sourceDirectory>src/java</sourceDirectory>
|
85
|
+
<resources>
|
86
|
+
<resource>
|
87
|
+
<directory>lib</directory>
|
88
|
+
</resource>
|
89
|
+
</resources>
|
90
|
+
<!--
|
91
|
+
<testSourceDirectory>test/java</testSourceDirectory>-->
|
92
|
+
<testResources>
|
93
|
+
<testResource>
|
94
|
+
<directory>test</directory>
|
95
|
+
</testResource>
|
96
|
+
</testResources>
|
97
|
+
|
98
|
+
<outputDirectory>pkg/classes</outputDirectory>
|
99
|
+
|
100
|
+
<plugins>
|
101
|
+
<plugin>
|
102
|
+
<groupId>org.apache.maven.plugins</groupId>
|
103
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
104
|
+
<version>2.5.1</version>
|
105
|
+
<configuration>
|
106
|
+
<source>1.7</source>
|
107
|
+
<target>1.7</target>
|
108
|
+
</configuration>
|
109
|
+
</plugin>
|
110
|
+
</plugins>
|
111
|
+
|
112
|
+
</build>
|
113
|
+
|
114
|
+
</project>
|