activerecord-jdbc-adapter 51.1-java → 51.2-java
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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/Rakefile +50 -13
- data/lib/arjdbc/abstract/core.rb +10 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +2 -9
- data/lib/arjdbc/mysql/adapter.rb +2 -2
- data/lib/arjdbc/mysql/connection_methods.rb +8 -5
- data/lib/arjdbc/postgresql/adapter.rb +48 -19
- data/lib/arjdbc/postgresql/connection_methods.rb +9 -2
- data/lib/arjdbc/sqlite3/adapter.rb +1 -2
- data/lib/arjdbc/tasks/database_tasks.rb +16 -36
- data/lib/arjdbc/tasks/databases.rake +32 -75
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/db.rake +21 -7
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +9 -8
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +11 -1
- data/src/java/arjdbc/util/StringHelper.java +6 -20
- metadata +5 -9
- data/lib/arjdbc/jdbc/jdbc.rake +0 -4
- data/lib/arjdbc/tasks/databases3.rake +0 -215
- data/lib/arjdbc/tasks/databases4.rake +0 -39
- data/rakelib/compile.rake +0 -70
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b92cd70cfbcb8827986847b53e1d527f5fcee621
|
|
4
|
+
data.tar.gz: 2480d4df7693895d1ca20ac406dadb26f7c432e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 42f15c16ca5d768f29993be86e43234b832be0fd580625a1d080f9827f405fe9b3a44752cf25970e11a00aeafd3e9d1b20ee715eac15404f042027e5cb8e5643
|
|
7
|
+
data.tar.gz: ba4acdb1f07ab847ee0f560c8c9869f72456cfb812e69823b01ad4c0fb62126331401941a015ccd8058e40be7d395f14c418021a14f8f8d9d8eb42befb7ae16f
|
data/.travis.yml
CHANGED
|
@@ -21,8 +21,8 @@ before_script:
|
|
|
21
21
|
mysql -e "grant all privileges on activerecord_unittest.* to rails@localhost;" && \
|
|
22
22
|
mysql -e "grant all privileges on activerecord_unittest2.* to rails@localhost;" && \
|
|
23
23
|
mysql -e "grant all privileges on inexistent_activerecord_unittest.* to rails@localhost;" && \
|
|
24
|
-
mysql -e "CREATE DATABASE activerecord_unittest;" && \
|
|
25
|
-
mysql -e "CREATE DATABASE activerecord_unittest2;" \
|
|
24
|
+
mysql -e "CREATE DATABASE activerecord_unittest DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;" && \
|
|
25
|
+
mysql -e "CREATE DATABASE activerecord_unittest2 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;" \
|
|
26
26
|
|| true
|
|
27
27
|
- |
|
|
28
28
|
[ "$DB" == "postgresql" ] && [ "$TEST_PREFIX" == "rails:" ] && \
|
data/Rakefile
CHANGED
|
@@ -236,23 +236,43 @@ if defined? JRUBY_VERSION
|
|
|
236
236
|
end
|
|
237
237
|
|
|
238
238
|
classpath = []
|
|
239
|
-
[ 'java.class.path', 'sun.boot.class.path' ].each do |
|
|
240
|
-
classpath +=
|
|
239
|
+
[ 'java.class.path', 'sun.boot.class.path' ].map { |key| ENV_JAVA[key] }.each do |v|
|
|
240
|
+
classpath += v.split(File::PATH_SEPARATOR).find_all { |jar| jar =~ /jruby/i } if v
|
|
241
241
|
end
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
# Using Java 9+. Let's try and infer jruby.jar location from rbconfig
|
|
243
|
+
if classpath.empty?; require 'rbconfig'
|
|
244
|
+
libdir = RbConfig::CONFIG['libdir']
|
|
245
|
+
if libdir.start_with? 'classpath:'
|
|
246
|
+
error "Cannot build activerecord-jdbc with jruby-complete"
|
|
247
|
+
end
|
|
248
|
+
classpath << File.join(libdir, 'jruby.jar')
|
|
249
|
+
end
|
|
250
|
+
|
|
246
251
|
classpath += driver_jars
|
|
247
252
|
classpath = classpath.compact.join(File::PATH_SEPARATOR)
|
|
248
253
|
|
|
249
254
|
source_files = FileList[ 'src/java/**/*.java' ]
|
|
250
255
|
|
|
251
|
-
|
|
256
|
+
version = lambda do
|
|
257
|
+
begin
|
|
258
|
+
require 'arjdbc/version'
|
|
259
|
+
rescue LoadError
|
|
260
|
+
path = File.expand_path('../lib', File.dirname(__FILE__))
|
|
261
|
+
unless $LOAD_PATH.include?(path)
|
|
262
|
+
$LOAD_PATH << path; retry
|
|
263
|
+
end
|
|
264
|
+
end
|
|
252
265
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
266
|
+
gem_version = Gem::Version.create(ArJdbc::VERSION)
|
|
267
|
+
if gem_version.segments.last == 'DEV'
|
|
268
|
+
gem_version.segments[0...-1] # 50.0.DEV -> 50.0
|
|
269
|
+
else
|
|
270
|
+
gem_version.segments.dup
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
require 'tmpdir'; Dir.mktmpdir do |classes_dir|
|
|
275
|
+
# Cross-platform way of finding an executable in the $PATH. Thanks to @mislav
|
|
256
276
|
which = lambda do |cmd|
|
|
257
277
|
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
|
258
278
|
ENV['PATH'].split(File::PATH_SEPARATOR).map do |path|
|
|
@@ -276,7 +296,24 @@ if defined? JRUBY_VERSION
|
|
|
276
296
|
# avoid environment variable expansion using backslash
|
|
277
297
|
# class_files.gsub!('$', '\$') unless windows?
|
|
278
298
|
# args = class_files.map { |path| [ "-C #{classes_dir}", path ] }.flatten
|
|
279
|
-
|
|
299
|
+
|
|
300
|
+
if ENV['RELEASE'] == 'true'; require 'tempfile'
|
|
301
|
+
manifest = "Built-Time: #{Time.now.utc.strftime('%Y-%m-%d %H:%M:%S')}\n"
|
|
302
|
+
manifest += "Built-JRuby: #{JRUBY_VERSION}\n"
|
|
303
|
+
manifest += "Specification-Title: ActiveRecord-JDBC\n"
|
|
304
|
+
manifest += "Specification-Vendor: JRuby\n"
|
|
305
|
+
manifest += "Specification-Version: #{version.call[0].to_s.split('').join('.')}\n" # AR VERSION (52 -> 5.2)
|
|
306
|
+
manifest += "Implementation-Vendor: The JRuby Team\n"
|
|
307
|
+
manifest += "Implementation-Version: #{version.call.join('.')}\n"
|
|
308
|
+
manifest = Tempfile.new('MANIFEST').tap { |f| f << manifest; f.close }.path
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
args = []; opts = '-cf'
|
|
312
|
+
if manifest
|
|
313
|
+
opts = "#{opts}m"
|
|
314
|
+
args = [ "#{manifest}" ]
|
|
315
|
+
end
|
|
316
|
+
args += [ '-C', "#{classes_dir}/ ." ]
|
|
280
317
|
|
|
281
318
|
jar_path = jar_file
|
|
282
319
|
if ext_lib_dir = ENV['RUBYLIBDIR']
|
|
@@ -286,7 +323,7 @@ if defined? JRUBY_VERSION
|
|
|
286
323
|
unless jar = which.call('jar')
|
|
287
324
|
warn "could not find jar tool, please make sure it's on the PATH"
|
|
288
325
|
end
|
|
289
|
-
sh("#{jar}
|
|
326
|
+
sh("#{jar} #{opts} #{jar_path} #{args.join(' ')}") do |ok|
|
|
290
327
|
raise 'could not build .jar extension - packaging failure' unless ok
|
|
291
328
|
end
|
|
292
329
|
cp jar_path, jar_file if ext_lib_dir # NOTE: hopefully RG won't mind?!
|
|
@@ -294,6 +331,6 @@ if defined? JRUBY_VERSION
|
|
|
294
331
|
end
|
|
295
332
|
else
|
|
296
333
|
task :jar do
|
|
297
|
-
|
|
334
|
+
warn "please run `rake jar' under JRuby to re-compile the native (Java) extension"
|
|
298
335
|
end
|
|
299
336
|
end
|
data/lib/arjdbc/abstract/core.rb
CHANGED
|
@@ -60,7 +60,17 @@ module ArJdbc
|
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
+
def extract_raw_bind_values(binds)
|
|
64
|
+
binds.map(&:value_for_database)
|
|
65
|
+
end
|
|
63
66
|
|
|
67
|
+
# this version of log() automatically fills type_casted_binds from binds if necessary
|
|
68
|
+
def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil)
|
|
69
|
+
if binds.any? && (type_casted_binds.nil? || type_casted_binds.empty?)
|
|
70
|
+
type_casted_binds = ->{ extract_raw_bind_values(binds) }
|
|
71
|
+
end
|
|
72
|
+
super
|
|
73
|
+
end
|
|
64
74
|
end
|
|
65
75
|
end
|
|
66
76
|
end
|
|
@@ -4,15 +4,8 @@ module ArJdbc
|
|
|
4
4
|
ConnectionMethods.module_eval do
|
|
5
5
|
|
|
6
6
|
def jdbc_connection(config)
|
|
7
|
-
adapter_class = config[:adapter_class]
|
|
8
|
-
adapter_class
|
|
9
|
-
|
|
10
|
-
# Once all adapters converted to AR5 then this rescue can be removed
|
|
11
|
-
begin
|
|
12
|
-
adapter_class.new(nil, logger, nil, config)
|
|
13
|
-
rescue ArgumentError
|
|
14
|
-
adapter_class.new(nil, logger, config)
|
|
15
|
-
end
|
|
7
|
+
adapter_class = config[:adapter_class] || ::ActiveRecord::ConnectionAdapters::JdbcAdapter
|
|
8
|
+
adapter_class.new(nil, logger, nil, config)
|
|
16
9
|
end
|
|
17
10
|
|
|
18
11
|
def jndi_connection(config); jdbc_connection(config) end
|
data/lib/arjdbc/mysql/adapter.rb
CHANGED
|
@@ -31,8 +31,8 @@ module ActiveRecord
|
|
|
31
31
|
|
|
32
32
|
include ArJdbc::MySQL
|
|
33
33
|
|
|
34
|
-
def initialize(connection, logger, config)
|
|
35
|
-
super
|
|
34
|
+
def initialize(connection, logger, connection_parameters, config)
|
|
35
|
+
super
|
|
36
36
|
@prepared_statements = false unless config.key?(:prepared_statements)
|
|
37
37
|
# configure_connection taken care of at ArJdbc::Abstract::Core
|
|
38
38
|
end
|
|
@@ -13,11 +13,14 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
|
13
13
|
driver = config[:driver] ||=
|
|
14
14
|
defined?(::Jdbc::MySQL.driver_name) ? ::Jdbc::MySQL.driver_name : 'com.mysql.jdbc.Driver'
|
|
15
15
|
|
|
16
|
+
mysql_driver = driver.start_with?('com.mysql.')
|
|
17
|
+
mariadb_driver = ! mysql_driver && driver.start_with?('org.mariadb.')
|
|
18
|
+
|
|
16
19
|
begin
|
|
17
20
|
require 'jdbc/mysql'
|
|
18
21
|
::Jdbc::MySQL.load_driver(:require) if defined?(::Jdbc::MySQL.load_driver)
|
|
19
22
|
rescue LoadError # assuming driver.jar is on the class-path
|
|
20
|
-
end if mysql_driver
|
|
23
|
+
end if mysql_driver
|
|
21
24
|
|
|
22
25
|
config[:username] = 'root' unless config.key?(:username)
|
|
23
26
|
# jdbc:mysql://[host][,failoverhost...][:port]/[database]
|
|
@@ -25,12 +28,12 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
|
25
28
|
# - if the port is not specified, it defaults to 3306
|
|
26
29
|
# - alternate fail-over syntax: [host:port],[host:port]/[database]
|
|
27
30
|
unless config[:url]
|
|
28
|
-
host = config[:host]
|
|
31
|
+
host = config[:host]
|
|
32
|
+
host ||= 'localhost' if mariadb_driver
|
|
33
|
+
host = host.join(',') if host.respond_to?(:join)
|
|
29
34
|
config[:url] = "jdbc:mysql://#{host}#{ config[:port] ? ":#{config[:port]}" : nil }/#{config[:database]}"
|
|
30
35
|
end
|
|
31
36
|
|
|
32
|
-
mariadb_driver = ! mysql_driver && driver.start_with?('org.mariadb.')
|
|
33
|
-
|
|
34
37
|
properties = ( config[:properties] ||= {} )
|
|
35
38
|
if mysql_driver
|
|
36
39
|
properties['zeroDateTimeBehavior'] ||= 'convertToNull'
|
|
@@ -63,8 +66,8 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
|
63
66
|
end
|
|
64
67
|
if config[:sslkey] || sslcert = config[:sslcert] # || config[:use_ssl]
|
|
65
68
|
properties['useSSL'] ||= true # supported by MariaDB as well
|
|
66
|
-
properties['requireSSL'] ||= true if mysql_driver
|
|
67
69
|
if mysql_driver
|
|
70
|
+
properties['requireSSL'] ||= true
|
|
68
71
|
properties['clientCertificateKeyStoreUrl'] ||= java.io.File.new(sslcert).to_url.to_s if sslcert
|
|
69
72
|
if sslca = config[:sslca]
|
|
70
73
|
properties['trustCertificateKeyStoreUrl'] ||= java.io.File.new(sslca).to_url.to_s
|
|
@@ -55,8 +55,30 @@ module ArJdbc
|
|
|
55
55
|
@postgresql_version ||=
|
|
56
56
|
begin
|
|
57
57
|
version = @connection.database_product
|
|
58
|
-
if
|
|
59
|
-
|
|
58
|
+
if match = version.match(/([\d\.]*\d).*?/)
|
|
59
|
+
version = match[1].split('.').map(&:to_i)
|
|
60
|
+
# PostgreSQL version representation does not have more than 4 digits
|
|
61
|
+
# From version 10 onwards, PG has changed its versioning policy to
|
|
62
|
+
# limit it to only 2 digits. i.e. in 10.x, 10 being the major
|
|
63
|
+
# version and x representing the patch release
|
|
64
|
+
# Refer to:
|
|
65
|
+
# https://www.postgresql.org/support/versioning/
|
|
66
|
+
# https://www.postgresql.org/docs/10/static/libpq-status.html -> PQserverVersion()
|
|
67
|
+
# for more info
|
|
68
|
+
|
|
69
|
+
if version.size >= 3
|
|
70
|
+
(version[0] * 100 + version[1]) * 100 + version[2]
|
|
71
|
+
elsif version.size == 2
|
|
72
|
+
if version[0] >= 10
|
|
73
|
+
version[0] * 100 * 100 + version[1]
|
|
74
|
+
else
|
|
75
|
+
(version[0] * 100 + version[1]) * 100
|
|
76
|
+
end
|
|
77
|
+
elsif version.size == 1
|
|
78
|
+
version[0] * 100 * 100
|
|
79
|
+
else
|
|
80
|
+
0
|
|
81
|
+
end
|
|
60
82
|
else
|
|
61
83
|
0
|
|
62
84
|
end
|
|
@@ -217,6 +239,8 @@ module ArJdbc
|
|
|
217
239
|
|
|
218
240
|
def supports_ddl_transactions?; true end
|
|
219
241
|
|
|
242
|
+
def supports_advisory_locks?; true end
|
|
243
|
+
|
|
220
244
|
def supports_explain?; true end
|
|
221
245
|
|
|
222
246
|
def supports_expression_index?; true end
|
|
@@ -233,6 +257,10 @@ module ArJdbc
|
|
|
233
257
|
|
|
234
258
|
def supports_views?; true end
|
|
235
259
|
|
|
260
|
+
def supports_datetime_with_precision?; true end
|
|
261
|
+
|
|
262
|
+
def supports_comments?; true end
|
|
263
|
+
|
|
236
264
|
# Does PostgreSQL support standard conforming strings?
|
|
237
265
|
def supports_standard_conforming_strings?
|
|
238
266
|
standard_conforming_strings?
|
|
@@ -243,6 +271,14 @@ module ArJdbc
|
|
|
243
271
|
postgresql_version >= 90000
|
|
244
272
|
end
|
|
245
273
|
|
|
274
|
+
def supports_materialized_views?
|
|
275
|
+
postgresql_version >= 90300
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
def supports_json?
|
|
279
|
+
postgresql_version >= 90200
|
|
280
|
+
end
|
|
281
|
+
|
|
246
282
|
def supports_insert_with_returning?
|
|
247
283
|
postgresql_version >= 80200
|
|
248
284
|
end
|
|
@@ -376,6 +412,12 @@ module ArJdbc
|
|
|
376
412
|
@connection.configure_connection
|
|
377
413
|
end
|
|
378
414
|
|
|
415
|
+
def default_sequence_name(table_name, pk = "id") #:nodoc:
|
|
416
|
+
serial_sequence(table_name, pk)
|
|
417
|
+
rescue ActiveRecord::StatementInvalid
|
|
418
|
+
%Q("#{table_name}_#{pk}_seq")
|
|
419
|
+
end
|
|
420
|
+
|
|
379
421
|
def last_insert_id_result(sequence_name)
|
|
380
422
|
exec_query("SELECT currval('#{sequence_name}')", 'SQL')
|
|
381
423
|
end
|
|
@@ -581,6 +623,8 @@ module ArJdbc
|
|
|
581
623
|
end
|
|
582
624
|
|
|
583
625
|
def translate_exception(exception, message)
|
|
626
|
+
return super unless exception.is_a?(ActiveRecord::JDBCError)
|
|
627
|
+
|
|
584
628
|
# TODO: Can we base these on an error code of some kind?
|
|
585
629
|
case exception.message
|
|
586
630
|
when /duplicate key value violates unique constraint/
|
|
@@ -668,12 +712,12 @@ module ActiveRecord::ConnectionAdapters
|
|
|
668
712
|
# AR expects OID to be available on the adapter
|
|
669
713
|
OID = ActiveRecord::ConnectionAdapters::PostgreSQL::OID
|
|
670
714
|
|
|
671
|
-
def initialize(connection, logger = nil, config = {})
|
|
715
|
+
def initialize(connection, logger = nil, connection_parameters = nil, config = {})
|
|
672
716
|
# @local_tz is initialized as nil to avoid warnings when connect tries to use it
|
|
673
717
|
@local_tz = nil
|
|
674
718
|
@max_identifier_length = nil
|
|
675
719
|
|
|
676
|
-
super # configure_connection happens in super
|
|
720
|
+
super(connection, logger, config) # configure_connection happens in super
|
|
677
721
|
|
|
678
722
|
initialize_type_map(@type_map = Type::HashLookupTypeMap.new)
|
|
679
723
|
|
|
@@ -695,21 +739,6 @@ module ActiveRecord::ConnectionAdapters
|
|
|
695
739
|
TableDefinition.new(*args)
|
|
696
740
|
end
|
|
697
741
|
|
|
698
|
-
def exec_query(sql, name = nil, binds = [], prepare: false)
|
|
699
|
-
super
|
|
700
|
-
rescue ActiveRecord::StatementInvalid => e
|
|
701
|
-
raise unless e.cause.message.include?('cached plan must not change result type'.freeze)
|
|
702
|
-
|
|
703
|
-
if open_transactions > 0
|
|
704
|
-
# In a transaction, have to fail it - See AR code for details
|
|
705
|
-
raise ActiveRecord::PreparedStatementCacheExpired.new(e.cause.message)
|
|
706
|
-
else
|
|
707
|
-
# Not in a transaction, clear the prepared statement and try again
|
|
708
|
-
delete_cached_statement(sql)
|
|
709
|
-
retry
|
|
710
|
-
end
|
|
711
|
-
end
|
|
712
|
-
|
|
713
742
|
public :sql_for_insert
|
|
714
743
|
|
|
715
744
|
def schema_creation # :nodoc:
|
|
@@ -51,8 +51,15 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
|
51
51
|
properties['tcpKeepAlive'] ||= config[:keepalives] if config.key?(:keepalives)
|
|
52
52
|
properties['kerberosServerName'] ||= config[:krbsrvname] if config[:krbsrvname]
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
prepared_statements = config.fetch(:prepared_statements) { true }
|
|
55
|
+
prepared_statements = false if prepared_statements == 'false'
|
|
56
|
+
if prepared_statements
|
|
57
|
+
# this makes the pgjdbc driver handle hot compatibility internally
|
|
58
|
+
properties['autosave'] ||= 'conservative'
|
|
59
|
+
else
|
|
60
|
+
# If prepared statements are off, lets make sure they are really *off*
|
|
61
|
+
properties['prepareThreshold'] = 0
|
|
62
|
+
end
|
|
56
63
|
|
|
57
64
|
jdbc_connection(config)
|
|
58
65
|
end
|
|
@@ -72,8 +72,7 @@ module ArJdbc
|
|
|
72
72
|
Arel::Visitors::SQLite.new(self)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
def initialize(connection, logger, config)
|
|
75
|
+
def initialize(connection, logger, connection_options, config)
|
|
77
76
|
super(connection, logger, config)
|
|
78
77
|
|
|
79
78
|
@active = nil
|
|
@@ -1,52 +1,32 @@
|
|
|
1
1
|
module ArJdbc
|
|
2
2
|
module Tasks
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def self.register_tasks(pattern, task)
|
|
7
|
-
ActiveRecord::Tasks::DatabaseTasks.register_task(pattern, task)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
# support adapter: mariadb (as if it were mysql)
|
|
11
|
-
register_tasks(/mariadb/, ActiveRecord::Tasks::MySQLDatabaseTasks)
|
|
12
|
-
|
|
13
|
-
else
|
|
14
|
-
|
|
15
|
-
@@tasks = {}
|
|
16
|
-
|
|
17
|
-
def self.register_tasks(pattern, task)
|
|
18
|
-
@@tasks[pattern] = task
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def self.tasks_instance(config)
|
|
22
|
-
adapter = config['adapter']
|
|
23
|
-
key = @@tasks.keys.detect { |pattern| adapter[pattern] }
|
|
24
|
-
( @@tasks[key] || JdbcDatabaseTasks ).new(config)
|
|
25
|
-
end
|
|
26
|
-
|
|
4
|
+
def self.register_tasks(pattern, task)
|
|
5
|
+
ActiveRecord::Tasks::DatabaseTasks.register_task(pattern, task)
|
|
27
6
|
end
|
|
28
7
|
|
|
8
|
+
# support adapter: mariadb (as if it were mysql)
|
|
9
|
+
register_tasks(/mariadb/, ActiveRecord::Tasks::MySQLDatabaseTasks)
|
|
10
|
+
|
|
29
11
|
require 'arjdbc/tasks/jdbc_database_tasks'
|
|
30
|
-
require 'arjdbc/tasks/db2_database_tasks'
|
|
31
|
-
require 'arjdbc/tasks/derby_database_tasks'
|
|
32
|
-
require 'arjdbc/tasks/h2_database_tasks'
|
|
33
|
-
require 'arjdbc/tasks/hsqldb_database_tasks'
|
|
34
|
-
require 'arjdbc/tasks/mssql_database_tasks'
|
|
12
|
+
#require 'arjdbc/tasks/db2_database_tasks'
|
|
13
|
+
#require 'arjdbc/tasks/derby_database_tasks'
|
|
14
|
+
#require 'arjdbc/tasks/h2_database_tasks'
|
|
15
|
+
#require 'arjdbc/tasks/hsqldb_database_tasks'
|
|
16
|
+
#require 'arjdbc/tasks/mssql_database_tasks'
|
|
35
17
|
|
|
36
18
|
# re-invent built-in (but deprecated on 4.0) tasks :
|
|
37
|
-
register_tasks(/sqlserver/, MSSQLDatabaseTasks)
|
|
38
|
-
register_tasks(/mssql/, MSSQLDatabaseTasks) # (built-in) alias
|
|
19
|
+
#register_tasks(/sqlserver/, MSSQLDatabaseTasks)
|
|
20
|
+
#register_tasks(/mssql/, MSSQLDatabaseTasks) # (built-in) alias
|
|
39
21
|
# tasks for custom (JDBC) adapters :
|
|
40
|
-
register_tasks(/db2/, DB2DatabaseTasks)
|
|
41
|
-
register_tasks(/derby/, DerbyDatabaseTasks)
|
|
42
|
-
register_tasks(/h2/, H2DatabaseTasks)
|
|
43
|
-
register_tasks(/hsqldb/, HSQLDBDatabaseTasks)
|
|
22
|
+
#register_tasks(/db2/, DB2DatabaseTasks)
|
|
23
|
+
#register_tasks(/derby/, DerbyDatabaseTasks)
|
|
24
|
+
#register_tasks(/h2/, H2DatabaseTasks)
|
|
25
|
+
#register_tasks(/hsqldb/, HSQLDBDatabaseTasks)
|
|
44
26
|
# (default) generic JDBC task :
|
|
45
27
|
register_tasks(/^jdbc$/, JdbcDatabaseTasks)
|
|
46
28
|
|
|
47
29
|
# NOTE: no need to register "built-in" adapters such as MySQL
|
|
48
|
-
# - on 4.0 these are registered and will be instantiated
|
|
49
|
-
# - while on 2.3/3.x we keep the AR built-in task behavior
|
|
50
30
|
|
|
51
31
|
end
|
|
52
32
|
end
|
|
@@ -1,91 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Rake::DSL.module_eval do
|
|
4
|
-
|
|
5
|
-
def redefine_task(*args, &block)
|
|
6
|
-
if Hash === args.first
|
|
7
|
-
task_name = args.first.keys[0]
|
|
8
|
-
old_prereqs = false # leave as specified
|
|
9
|
-
else
|
|
10
|
-
task_name = args.first; old_prereqs = []
|
|
11
|
-
# args[0] = { task_name => old_prereqs }
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
full_name = Rake::Task.scope_name(Rake.application.current_scope, task_name)
|
|
15
|
-
|
|
16
|
-
if old_task = Rake.application.lookup(task_name)
|
|
17
|
-
old_comment = old_task.full_comment
|
|
18
|
-
old_prereqs = old_task.prerequisites.dup if old_prereqs
|
|
19
|
-
old_actions = old_task.actions.dup
|
|
20
|
-
old_actions.shift # remove the main 'action' block - we're redefining it
|
|
21
|
-
# old_task.clear_prerequisites if old_prereqs
|
|
22
|
-
# old_task.clear_actions
|
|
23
|
-
# remove the (old) task instance from the application :
|
|
24
|
-
Rake.application.send(:instance_variable_get, :@tasks)[full_name.to_s] = nil
|
|
25
|
-
else
|
|
26
|
-
# raise "could not find rake task with (full) name '#{full_name}'"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
new_task = task(*args, &block)
|
|
30
|
-
new_task.comment = old_comment if old_comment
|
|
31
|
-
new_task.actions.concat(old_actions) if old_actions
|
|
32
|
-
new_task.prerequisites.concat(old_prereqs) if old_prereqs
|
|
33
|
-
new_task
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
namespace :db do
|
|
39
|
-
|
|
40
|
-
def rails_env
|
|
41
|
-
defined?(Rails.env) ? Rails.env : ( RAILS_ENV || 'development' )
|
|
42
|
-
end
|
|
1
|
+
require 'arjdbc/tasks/database_tasks'
|
|
43
2
|
|
|
44
|
-
|
|
45
|
-
ArJdbc.warn "double loading #{__FILE__} please delete lib/tasks/jdbc.rake if present!"
|
|
46
|
-
end
|
|
3
|
+
module ActiveRecord::Tasks
|
|
47
4
|
|
|
48
|
-
|
|
49
|
-
return config unless config['adapter']
|
|
50
|
-
config.merge 'adapter' => config['adapter'].sub(/^jdbc/, '')
|
|
51
|
-
end
|
|
5
|
+
DatabaseTasks.module_eval do
|
|
52
6
|
|
|
53
|
-
|
|
7
|
+
# @override patched to adapt jdbc configuration
|
|
8
|
+
def each_current_configuration(environment)
|
|
9
|
+
environments = [environment]
|
|
10
|
+
environments << 'test' if environment == 'development'
|
|
54
11
|
|
|
55
|
-
|
|
56
|
-
|
|
12
|
+
configurations = ActiveRecord::Base.configurations.values_at(*environments)
|
|
13
|
+
configurations.compact.each do |config|
|
|
14
|
+
yield adapt_jdbc_config(config) unless config['database'].blank?
|
|
15
|
+
end
|
|
57
16
|
end
|
|
58
17
|
|
|
59
|
-
|
|
18
|
+
# @override patched to adapt jdbc configuration
|
|
19
|
+
def each_local_configuration
|
|
20
|
+
ActiveRecord::Base.configurations.each_value do |config|
|
|
21
|
+
next unless config['database']
|
|
60
22
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
@current_config ||= ENV['DATABASE_URL'] ?
|
|
67
|
-
database_url_config : ActiveRecord::Base.configurations[options[:env]]
|
|
23
|
+
if local_database?(config)
|
|
24
|
+
yield adapt_jdbc_config(config)
|
|
25
|
+
else
|
|
26
|
+
$stderr.puts "This task only modifies local databases. #{config['database']} is on a remote host."
|
|
27
|
+
end
|
|
68
28
|
end
|
|
69
29
|
end
|
|
70
30
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
unless
|
|
75
|
-
|
|
76
|
-
end
|
|
77
|
-
resolver = ActiveRecord::Base::ConnectionSpecification::Resolver.new(url, {})
|
|
78
|
-
resolver.spec.config.stringify_keys
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def adapt_jdbc_config(config)
|
|
34
|
+
return config unless config['adapter']
|
|
35
|
+
config.merge 'adapter' => config['adapter'].sub(/^jdbc/, '')
|
|
79
36
|
end
|
|
80
37
|
|
|
81
38
|
end
|
|
82
39
|
|
|
83
|
-
|
|
40
|
+
MySQLDatabaseTasks.class_eval do
|
|
84
41
|
|
|
85
|
-
|
|
42
|
+
def error_class
|
|
43
|
+
ActiveRecord::JDBCError
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end if const_defined?(:MySQLDatabaseTasks)
|
|
86
47
|
|
|
87
|
-
|
|
88
|
-
load File.expand_path('databases4.rake', File.dirname(__FILE__))
|
|
89
|
-
else # 3.x / 2.3
|
|
90
|
-
load File.expand_path('databases3.rake', File.dirname(__FILE__))
|
|
91
|
-
end
|
|
48
|
+
end
|
data/lib/arjdbc/version.rb
CHANGED
data/rakelib/db.rake
CHANGED
|
@@ -4,25 +4,35 @@ namespace :db do
|
|
|
4
4
|
task :mysql do
|
|
5
5
|
require File.expand_path('../../test/shared_helper', __FILE__)
|
|
6
6
|
fail "could not create test database: mysql executable not found" unless mysql = which('mysql')
|
|
7
|
+
|
|
7
8
|
load 'test/db/mysql_config.rb' # rescue nil
|
|
8
9
|
enc = MYSQL_CONFIG[:encoding] || 'utf8' # 'utf8mb4'
|
|
9
10
|
puts MYSQL_CONFIG.inspect if $VERBOSE
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
clean_script = sql_script <<-SQL, 'mysqlclean'
|
|
13
|
+
DROP USER #{MYSQL_CONFIG[:username]}@localhost;
|
|
14
|
+
SQL
|
|
15
|
+
|
|
11
16
|
script = sql_script <<-SQL, 'mysql'
|
|
12
17
|
DROP DATABASE IF EXISTS `#{MYSQL_CONFIG[:database]}`;
|
|
13
18
|
CREATE DATABASE `#{MYSQL_CONFIG[:database]}` DEFAULT CHARACTER SET `#{enc}` COLLATE `#{enc}_general_ci`;
|
|
19
|
+
CREATE USER #{MYSQL_CONFIG[:username]}@localhost IDENTIFIED BY '#{MYSQL_CONFIG[:password]}';
|
|
14
20
|
GRANT ALL PRIVILEGES ON `#{MYSQL_CONFIG[:database]}`.* TO #{MYSQL_CONFIG[:username]}@localhost;
|
|
15
21
|
GRANT ALL PRIVILEGES ON `test\_%`.* TO #{MYSQL_CONFIG[:username]}@localhost;
|
|
16
|
-
SET PASSWORD FOR #{MYSQL_CONFIG[:username]}@localhost = PASSWORD('#{MYSQL_CONFIG[:password]}');
|
|
17
22
|
SQL
|
|
23
|
+
|
|
18
24
|
params = { '-u' => 'root' }
|
|
19
|
-
if ENV['DATABASE_YML']
|
|
20
|
-
|
|
25
|
+
if ENV['DATABASE_YML']
|
|
26
|
+
require 'yaml'
|
|
27
|
+
params['-p'] = YAML.load(File.new(ENV['DATABASE_YML']))["production"]["password"]
|
|
21
28
|
end
|
|
22
29
|
params['-u'] = ENV['MY_USER'] if ENV['MY_USER']
|
|
23
30
|
params['-p'] = ENV['MY_PASSWORD'] if ENV['MY_PASSWORD']
|
|
31
|
+
|
|
24
32
|
puts "Creating MySQL (test) database: #{MYSQL_CONFIG[:database]}"
|
|
25
|
-
|
|
33
|
+
mysql_cmd = "#{mysql} -f #{params.map {|k, v| "#{k}#{v}"}.join(' ')}"
|
|
34
|
+
sh "cat #{clean_script.path} | #{mysql_cmd}", verbose: false
|
|
35
|
+
sh "cat #{script.path} | #{mysql_cmd}", verbose: $VERBOSE # so password is not echoed
|
|
26
36
|
end
|
|
27
37
|
|
|
28
38
|
desc "Creates the test database for PostgreSQL"
|
|
@@ -30,8 +40,10 @@ SET PASSWORD FOR #{MYSQL_CONFIG[:username]}@localhost = PASSWORD('#{MYSQL_CONFIG
|
|
|
30
40
|
require File.expand_path('../../test/shared_helper', __FILE__)
|
|
31
41
|
fail 'could not create test database: psql executable not found' unless psql = which('psql')
|
|
32
42
|
fail 'could not create test database: missing "postgres" role' unless PostgresHelper.postgres_role?
|
|
43
|
+
|
|
33
44
|
load 'test/db/postgres_config.rb' # rescue nil
|
|
34
45
|
puts POSTGRES_CONFIG.inspect if $VERBOSE
|
|
46
|
+
|
|
35
47
|
script = sql_script <<-SQL, 'psql'
|
|
36
48
|
DROP DATABASE IF EXISTS #{POSTGRES_CONFIG[:database]};
|
|
37
49
|
DROP USER IF EXISTS #{POSTGRES_CONFIG[:username]};
|
|
@@ -40,12 +52,14 @@ CREATE DATABASE #{POSTGRES_CONFIG[:database]} OWNER #{POSTGRES_CONFIG[:username]
|
|
|
40
52
|
TEMPLATE template0
|
|
41
53
|
ENCODING '#{POSTGRES_CONFIG[:encoding]}' LC_COLLATE '#{POSTGRES_CONFIG[:collate]}' LC_CTYPE '#{POSTGRES_CONFIG[:collate]}';
|
|
42
54
|
SQL
|
|
55
|
+
|
|
43
56
|
params = { '-U' => ENV['PSQL_USER'] || 'postgres' }
|
|
44
57
|
params['-q'] = nil unless $VERBOSE
|
|
58
|
+
|
|
45
59
|
puts "Creating PostgreSQL (test) database: #{POSTGRES_CONFIG[:database]}"
|
|
46
|
-
sh "cat #{script.path} | #{psql} #{params.to_a.join(' ')}", :
|
|
60
|
+
sh "cat #{script.path} | #{psql} #{params.to_a.join(' ')}", verbose: $VERBOSE
|
|
47
61
|
end
|
|
48
|
-
task :
|
|
62
|
+
task postgres: :postgresql
|
|
49
63
|
|
|
50
64
|
private
|
|
51
65
|
|
|
@@ -284,7 +284,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
284
284
|
public static int mapTransactionIsolationLevel(final IRubyObject isolation) {
|
|
285
285
|
final Object isolationString;
|
|
286
286
|
if ( isolation instanceof RubySymbol ) {
|
|
287
|
-
isolationString = isolation.
|
|
287
|
+
isolationString = ((RubySymbol) isolation).asJavaString(); // RubySymbol (interned)
|
|
288
288
|
}
|
|
289
289
|
else {
|
|
290
290
|
isolationString = isolation.asString().toString().toLowerCase(Locale.ENGLISH).intern();
|
|
@@ -2716,7 +2716,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2716
2716
|
|
|
2717
2717
|
private String default_timezone(final ThreadContext context) {
|
|
2718
2718
|
final RubyClass base = getBase(context.runtime);
|
|
2719
|
-
return default_timezone.call(context, base, base).
|
|
2719
|
+
return default_timezone.call(context, base, base).asJavaString(); // :utc (or :local)
|
|
2720
2720
|
}
|
|
2721
2721
|
|
|
2722
2722
|
// ActiveRecord::Base.default_timezone
|
|
@@ -2898,14 +2898,13 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
2898
2898
|
final RubySymbol type = (RubySymbol) attributeSQLType(context, attribute);
|
|
2899
2899
|
|
|
2900
2900
|
// For some reason the driver doesn't like "character varying" as a type
|
|
2901
|
-
if ( type.eql(context.runtime.newSymbol("string")) )
|
|
2902
|
-
return "text";
|
|
2903
|
-
}
|
|
2901
|
+
if ( type.eql(context.runtime.newSymbol("string")) ) return "text";
|
|
2904
2902
|
|
|
2905
2903
|
final RubyHash nativeTypes = (RubyHash) getAdapter().callMethod(context, "native_database_types");
|
|
2904
|
+
// e.g. `integer: { name: 'integer' }`
|
|
2906
2905
|
final RubyHash typeInfo = (RubyHash) nativeTypes.op_aref(context, type);
|
|
2907
2906
|
|
|
2908
|
-
return typeInfo.op_aref(context, context.runtime.newSymbol("name")).
|
|
2907
|
+
return typeInfo.op_aref(context, context.runtime.newSymbol("name")).toString();
|
|
2909
2908
|
}
|
|
2910
2909
|
|
|
2911
2910
|
protected void setXmlParameter(final ThreadContext context,
|
|
@@ -3446,12 +3445,14 @@ public class RubyJdbcConnection extends RubyObject {
|
|
|
3446
3445
|
if ( ! gotConnection ) { // SQLException from driver/data-source
|
|
3447
3446
|
reconnectOnRetry = connected;
|
|
3448
3447
|
}
|
|
3448
|
+
else if (!autoCommit) {
|
|
3449
|
+
// never retry inside a transaction
|
|
3450
|
+
break;
|
|
3451
|
+
}
|
|
3449
3452
|
else if ( isTransient(exception) ) {
|
|
3450
3453
|
reconnectOnRetry = false; // continue;
|
|
3451
3454
|
}
|
|
3452
3455
|
else {
|
|
3453
|
-
if ( ! autoCommit ) break; // do not retry if (inside) transactions
|
|
3454
|
-
|
|
3455
3456
|
if ( isConnectionValid(context, getConnectionImpl()) ) {
|
|
3456
3457
|
break; // connection not broken yet failed (do not retry)
|
|
3457
3458
|
}
|
|
@@ -55,6 +55,7 @@ import org.joda.time.DateTimeZone;
|
|
|
55
55
|
import org.jruby.*;
|
|
56
56
|
import org.jruby.anno.JRubyMethod;
|
|
57
57
|
import org.jruby.exceptions.RaiseException;
|
|
58
|
+
import org.jruby.ext.bigdecimal.RubyBigDecimal;
|
|
58
59
|
import org.jruby.javasupport.JavaUtil;
|
|
59
60
|
import org.jruby.runtime.ObjectAllocator;
|
|
60
61
|
import org.jruby.runtime.ThreadContext;
|
|
@@ -100,6 +101,7 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
|
100
101
|
POSTGRES_JDBC_TYPE_FOR.put("line", Types.OTHER);
|
|
101
102
|
POSTGRES_JDBC_TYPE_FOR.put("lseg", Types.OTHER);
|
|
102
103
|
POSTGRES_JDBC_TYPE_FOR.put("ltree", Types.OTHER);
|
|
104
|
+
POSTGRES_JDBC_TYPE_FOR.put("money", Types.OTHER);
|
|
103
105
|
POSTGRES_JDBC_TYPE_FOR.put("numrange", Types.OTHER);
|
|
104
106
|
POSTGRES_JDBC_TYPE_FOR.put("path", Types.OTHER);
|
|
105
107
|
POSTGRES_JDBC_TYPE_FOR.put("point", Types.OTHER);
|
|
@@ -441,6 +443,14 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
|
441
443
|
}
|
|
442
444
|
break;
|
|
443
445
|
|
|
446
|
+
case "money":
|
|
447
|
+
if (value instanceof RubyBigDecimal) {
|
|
448
|
+
statement.setBigDecimal(index, ((RubyBigDecimal) value).getValue());
|
|
449
|
+
} else {
|
|
450
|
+
setPGobjectParameter(statement, index, value, columnType);
|
|
451
|
+
}
|
|
452
|
+
break;
|
|
453
|
+
|
|
444
454
|
case "lseg":
|
|
445
455
|
pointValues = parseDoubles(value);
|
|
446
456
|
statement.setObject(index, new PGlseg(pointValues[0], pointValues[1], pointValues[2], pointValues[3]));
|
|
@@ -485,7 +495,7 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
|
485
495
|
return points;
|
|
486
496
|
}
|
|
487
497
|
|
|
488
|
-
private Double[] parseDoubles(IRubyObject value) {
|
|
498
|
+
private static Double[] parseDoubles(IRubyObject value) {
|
|
489
499
|
Matcher matches = doubleValuePattern.matcher(value.toString());
|
|
490
500
|
ArrayList<Double> doubles = new ArrayList<Double>(4); // Paths and polygons may be larger but this covers points/circles/boxes/line segments
|
|
491
501
|
|
|
@@ -25,12 +25,9 @@ package arjdbc.util;
|
|
|
25
25
|
|
|
26
26
|
import java.io.IOException;
|
|
27
27
|
import java.io.InputStream;
|
|
28
|
-
import java.nio.charset.Charset;
|
|
29
28
|
|
|
30
29
|
import org.jcodings.Encoding;
|
|
31
|
-
import org.jcodings.specific.UTF8Encoding;
|
|
32
30
|
import org.jruby.Ruby;
|
|
33
|
-
import org.jruby.RubyEncoding;
|
|
34
31
|
import org.jruby.RubyString;
|
|
35
32
|
import org.jruby.util.ByteList;
|
|
36
33
|
|
|
@@ -61,18 +58,6 @@ public abstract class StringHelper {
|
|
|
61
58
|
return RubyString.newString(runtime, new ByteList(bytes, false));
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
private static final Charset ASCII_CHARSET = Charset.forName("ISO-8859-1");
|
|
65
|
-
|
|
66
|
-
public static RubyString newASCIIString(final Ruby runtime, final String str) {
|
|
67
|
-
final ByteList byteList = new ByteList(str.getBytes(ASCII_CHARSET), false);
|
|
68
|
-
return RubyString.newString(runtime, byteList);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public static RubyString newUTF8String(final Ruby runtime, final byte[] bytes) {
|
|
72
|
-
final ByteList byteList = new ByteList(bytes, false);
|
|
73
|
-
return RubyString.newString(runtime, byteList, UTF8Encoding.INSTANCE);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
61
|
public static RubyString newDefaultInternalString(final Ruby runtime, final byte[] bytes) {
|
|
77
62
|
final ByteList byteList = new ByteList(bytes, false);
|
|
78
63
|
Encoding enc = runtime.getDefaultInternalEncoding();
|
|
@@ -83,18 +68,19 @@ public abstract class StringHelper {
|
|
|
83
68
|
public static RubyString newDefaultInternalString(final Ruby runtime, final CharSequence str) {
|
|
84
69
|
Encoding enc = runtime.getDefaultInternalEncoding();
|
|
85
70
|
if (enc == null) enc = runtime.getEncodingService().getJavaDefault();
|
|
86
|
-
return RubyString
|
|
71
|
+
return new RubyString(runtime, runtime.getString(), str, enc);
|
|
87
72
|
}
|
|
88
73
|
|
|
74
|
+
// NOTE: a 'better' RubyString.newInternalFromJavaExternal - to be back-ported in JRuby 9.2
|
|
89
75
|
public static RubyString newDefaultInternalString(final Ruby runtime, final String str) {
|
|
90
|
-
|
|
76
|
+
Encoding enc = runtime.getDefaultInternalEncoding();
|
|
77
|
+
if (enc == null) enc = runtime.getEncodingService().getJavaDefault();
|
|
78
|
+
return RubyString.newString(runtime, str, enc);
|
|
91
79
|
}
|
|
92
80
|
|
|
93
81
|
public static int readBytes(final ByteList output, final InputStream input)
|
|
94
82
|
throws IOException {
|
|
95
|
-
|
|
96
|
-
final int buffSize = output.bytes.length - output.begin;
|
|
97
|
-
return readBytes(output, input, buffSize);
|
|
83
|
+
return readBytes(output, input, output.unsafeBytes().length - output.getBegin());
|
|
98
84
|
}
|
|
99
85
|
|
|
100
86
|
public static int readBytes(final ByteList output, final InputStream input, int buffSize)
|
metadata
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-jdbc-adapter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '51.
|
|
4
|
+
version: '51.2'
|
|
5
5
|
platform: java
|
|
6
6
|
authors:
|
|
7
7
|
- Nick Sieger, Ola Bini, Karol Bucek and JRuby contributors
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-09-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: activerecord
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
16
|
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
18
|
version: 5.1.0
|
|
19
|
+
name: activerecord
|
|
20
|
+
prerelease: false
|
|
21
|
+
type: :runtime
|
|
20
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
21
23
|
requirements:
|
|
22
24
|
- - "~>"
|
|
23
25
|
- !ruby/object:Gem::Version
|
|
24
26
|
version: 5.1.0
|
|
25
|
-
prerelease: false
|
|
26
|
-
type: :runtime
|
|
27
27
|
description: 'AR-JDBC is a database adapter for Rails'' ActiveRecord component designed
|
|
28
28
|
to be used with JRuby built upon Java''s JDBC API for database access. Provides
|
|
29
29
|
(ActiveRecord) built-in adapters: MySQL, PostgreSQL and SQLite3 as well as adapters
|
|
@@ -119,7 +119,6 @@ files:
|
|
|
119
119
|
- lib/arjdbc/jdbc/error.rb
|
|
120
120
|
- lib/arjdbc/jdbc/extension.rb
|
|
121
121
|
- lib/arjdbc/jdbc/java.rb
|
|
122
|
-
- lib/arjdbc/jdbc/jdbc.rake
|
|
123
122
|
- lib/arjdbc/jdbc/railtie.rb
|
|
124
123
|
- lib/arjdbc/jdbc/rake_tasks.rb
|
|
125
124
|
- lib/arjdbc/jdbc/serialized_attributes_helper.rb
|
|
@@ -157,8 +156,6 @@ files:
|
|
|
157
156
|
- lib/arjdbc/tasks.rb
|
|
158
157
|
- lib/arjdbc/tasks/database_tasks.rb
|
|
159
158
|
- lib/arjdbc/tasks/databases.rake
|
|
160
|
-
- lib/arjdbc/tasks/databases3.rake
|
|
161
|
-
- lib/arjdbc/tasks/databases4.rake
|
|
162
159
|
- lib/arjdbc/tasks/db2_database_tasks.rb
|
|
163
160
|
- lib/arjdbc/tasks/derby_database_tasks.rb
|
|
164
161
|
- lib/arjdbc/tasks/h2_database_tasks.rb
|
|
@@ -181,7 +178,6 @@ files:
|
|
|
181
178
|
- rakelib/01-tomcat.rake
|
|
182
179
|
- rakelib/02-test.rake
|
|
183
180
|
- rakelib/bundler_ext.rb
|
|
184
|
-
- rakelib/compile.rake
|
|
185
181
|
- rakelib/db.rake
|
|
186
182
|
- rakelib/rails.rake
|
|
187
183
|
- src/java/arjdbc/ArJdbcModule.java
|
data/lib/arjdbc/jdbc/jdbc.rake
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
module ArJdbc
|
|
2
|
-
module Tasks
|
|
3
|
-
class << self
|
|
4
|
-
|
|
5
|
-
# API similar to ActiveRecord::Tasks::DatabaseTasks on AR 4.0
|
|
6
|
-
|
|
7
|
-
def create(config)
|
|
8
|
-
tasks_instance(config).create
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def drop(config)
|
|
12
|
-
tasks_instance(config).drop
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def purge(config)
|
|
16
|
-
tasks_instance(config).purge
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def charset(config)
|
|
20
|
-
tasks_instance(config).charset
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def collation(config)
|
|
24
|
-
tasks_instance(config).collation
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def structure_dump(config, filename)
|
|
28
|
-
tasks_instance(config).structure_dump(filename)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def structure_load(config, filename)
|
|
32
|
-
tasks_instance(config).structure_load(filename)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
namespace :db do
|
|
40
|
-
|
|
41
|
-
class << self
|
|
42
|
-
alias_method :_rails_create_database, :create_database
|
|
43
|
-
alias_method :_rails_drop_database, :drop_database
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def create_database(config)
|
|
47
|
-
case config['adapter']
|
|
48
|
-
when /mysql2/
|
|
49
|
-
unless defined? Mysql2::Error
|
|
50
|
-
# NOTE: fake it for create_database(config)
|
|
51
|
-
Object.const_set :Mysql2, Module.new
|
|
52
|
-
Mysql2.const_set :Error, ActiveRecord::JDBCError
|
|
53
|
-
ActiveRecord::JDBCError.class_eval do
|
|
54
|
-
def error; self end # Mysql2::Error#error
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
_rails_create_database adapt_jdbc_config(config)
|
|
58
|
-
when /mysql/
|
|
59
|
-
unless defined? Mysql::Error
|
|
60
|
-
# NOTE: fake it for create_database(config)
|
|
61
|
-
Object.const_set :Mysql, Module.new
|
|
62
|
-
Mysql.const_set :Error, ActiveRecord::JDBCError
|
|
63
|
-
ActiveRecord::JDBCError.class_eval do
|
|
64
|
-
def error; self end # Mysql::Error#error
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
_rails_create_database adapt_jdbc_config(config)
|
|
68
|
-
when /postgresql|sqlite/
|
|
69
|
-
_rails_create_database adapt_jdbc_config(config)
|
|
70
|
-
else
|
|
71
|
-
ArJdbc::Tasks.create(config)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def drop_database(config)
|
|
76
|
-
case config['adapter']
|
|
77
|
-
when /mysql|postgresql|sqlite/
|
|
78
|
-
_rails_drop_database adapt_jdbc_config(config)
|
|
79
|
-
else
|
|
80
|
-
ArJdbc::Tasks.drop(config)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
redefine_task :charset do # available on 2.3
|
|
85
|
-
ArJdbc::Tasks.charset ActiveRecord::Base.configurations[rails_env]
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
redefine_task :collation do # available on 2.3
|
|
89
|
-
ArJdbc::Tasks.collation ActiveRecord::Base.configurations[rails_env]
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
namespace :structure do
|
|
93
|
-
|
|
94
|
-
redefine_task :dump do
|
|
95
|
-
config = ActiveRecord::Base.configurations[rails_env] # current_config
|
|
96
|
-
filename = structure_sql
|
|
97
|
-
|
|
98
|
-
case config['adapter']
|
|
99
|
-
when /mysql/
|
|
100
|
-
ActiveRecord::Base.establish_connection(config)
|
|
101
|
-
File.open(filename, 'w:utf-8') { |f| f << ActiveRecord::Base.connection.structure_dump }
|
|
102
|
-
when /postgresql/
|
|
103
|
-
ActiveRecord::Base.establish_connection(config)
|
|
104
|
-
|
|
105
|
-
ENV['PGHOST'] = config['host'] if config['host']
|
|
106
|
-
ENV['PGPORT'] = config['port'].to_s if config['port']
|
|
107
|
-
ENV['PGPASSWORD'] = config['password'].to_s if config['password']
|
|
108
|
-
ENV['PGUSER'] = config['username'].to_s if config['username']
|
|
109
|
-
|
|
110
|
-
require 'shellwords'
|
|
111
|
-
search_path = config['schema_search_path']
|
|
112
|
-
unless search_path.blank?
|
|
113
|
-
search_path = search_path.split(",").map{ |part| "--schema=#{Shellwords.escape(part.strip)}" }.join(" ")
|
|
114
|
-
end
|
|
115
|
-
sh "pg_dump -i -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(config['database'])}"
|
|
116
|
-
|
|
117
|
-
File.open(filename, 'a') { |f| f << "SET search_path TO #{ActiveRecord::Base.connection.schema_search_path};\n\n" }
|
|
118
|
-
when /sqlite/
|
|
119
|
-
dbfile = config['database']
|
|
120
|
-
sh "sqlite3 #{dbfile} .schema > #{filename}"
|
|
121
|
-
else
|
|
122
|
-
ActiveRecord::Base.establish_connection(config)
|
|
123
|
-
ArJdbc::Tasks.structure_dump(config, filename)
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
if ActiveRecord::Base.connection.supports_migrations?
|
|
127
|
-
File.open(filename, 'a') { |f| f << ActiveRecord::Base.connection.dump_schema_information }
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
redefine_task :load do
|
|
133
|
-
config = current_config
|
|
134
|
-
filename = structure_sql
|
|
135
|
-
|
|
136
|
-
case config['adapter']
|
|
137
|
-
when /mysql/
|
|
138
|
-
ActiveRecord::Base.establish_connection(config)
|
|
139
|
-
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
|
|
140
|
-
IO.read(filename).split("\n\n").each do |table|
|
|
141
|
-
ActiveRecord::Base.connection.execute(table)
|
|
142
|
-
end
|
|
143
|
-
when /postgresql/
|
|
144
|
-
ENV['PGHOST'] = config['host'] if config['host']
|
|
145
|
-
ENV['PGPORT'] = config['port'].to_s if config['port']
|
|
146
|
-
ENV['PGPASSWORD'] = config['password'].to_s if config['password']
|
|
147
|
-
ENV['PGUSER'] = config['username'].to_s if config['username']
|
|
148
|
-
|
|
149
|
-
`psql -f "#{filename}" #{config['database']}`
|
|
150
|
-
when /sqlite/
|
|
151
|
-
dbfile = config['database']
|
|
152
|
-
`sqlite3 #{dbfile} < "#{filename}"`
|
|
153
|
-
else
|
|
154
|
-
ArJdbc::Tasks.structure_load(config, filename)
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
def structure_sql
|
|
159
|
-
ENV['DB_STRUCTURE'] ||= begin
|
|
160
|
-
root = defined?(Rails.root) ? Rails.root : ( RAILS_ROOT rescue nil )
|
|
161
|
-
if ActiveRecord::VERSION::STRING > '3.2'
|
|
162
|
-
root ? File.join(root, "db", "structure.sql") : File.join("db", "structure.sql")
|
|
163
|
-
else
|
|
164
|
-
root ? File.join(root, "db/#{rails_env}_structure.sql") : "db/#{rails_env}_structure.sql"
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
namespace :test do
|
|
172
|
-
|
|
173
|
-
# desc "Recreate the test database from an existent structure.sql file"
|
|
174
|
-
redefine_task :load_structure => 'db:test:purge' do # not on 2.3
|
|
175
|
-
begin
|
|
176
|
-
current_config(:config => ActiveRecord::Base.configurations['test'])
|
|
177
|
-
Rake::Task["db:structure:load"].invoke
|
|
178
|
-
ensure
|
|
179
|
-
current_config(:config => nil)
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
# desc "Recreate the test database from a fresh structure.sql file"
|
|
184
|
-
redefine_task :clone_structure => [ "db:structure:dump", "db:test:load_structure" ]
|
|
185
|
-
# same as on 3.2 - but this task gets changed on 2.3 by depending on :load_structure
|
|
186
|
-
|
|
187
|
-
# desc "Empty the test database"
|
|
188
|
-
redefine_task :purge do
|
|
189
|
-
config = ActiveRecord::Base.configurations['test']
|
|
190
|
-
case config['adapter']
|
|
191
|
-
when /mysql/
|
|
192
|
-
ActiveRecord::Base.establish_connection(:test)
|
|
193
|
-
options = mysql_creation_options(config) rescue config
|
|
194
|
-
ActiveRecord::Base.connection.recreate_database(config['database'], options)
|
|
195
|
-
when /postgresql/
|
|
196
|
-
ActiveRecord::Base.clear_active_connections!
|
|
197
|
-
# drop_database(config) :
|
|
198
|
-
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
|
199
|
-
ActiveRecord::Base.connection.drop_database config['database']
|
|
200
|
-
# create_database(config) :
|
|
201
|
-
encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
|
|
202
|
-
ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => encoding))
|
|
203
|
-
when /sqlite/
|
|
204
|
-
dbfile = config['database']
|
|
205
|
-
File.delete(dbfile) if File.exist?(dbfile)
|
|
206
|
-
else
|
|
207
|
-
ArJdbc::Tasks.purge(config)
|
|
208
|
-
end
|
|
209
|
-
end
|
|
210
|
-
# only does (:purge => :environment) on AR < 3.2
|
|
211
|
-
task :purge => :load_config if Rake::Task.task_defined?(:load_config)
|
|
212
|
-
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
module ActiveRecord::Tasks
|
|
2
|
-
|
|
3
|
-
DatabaseTasks.module_eval do
|
|
4
|
-
|
|
5
|
-
# patched to adapt jdbc configuration
|
|
6
|
-
def each_current_configuration(environment)
|
|
7
|
-
environments = [environment]
|
|
8
|
-
environments << 'test' if environment == 'development'
|
|
9
|
-
|
|
10
|
-
configurations = ActiveRecord::Base.configurations.values_at(*environments)
|
|
11
|
-
configurations.compact.each do |config|
|
|
12
|
-
yield adapt_jdbc_config(config) unless config['database'].blank?
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# patched to adapt jdbc configuration
|
|
17
|
-
def each_local_configuration
|
|
18
|
-
ActiveRecord::Base.configurations.each_value do |config|
|
|
19
|
-
next unless config['database']
|
|
20
|
-
|
|
21
|
-
if local_database?(config)
|
|
22
|
-
yield adapt_jdbc_config(config)
|
|
23
|
-
else
|
|
24
|
-
$stderr.puts "This task only modifies local databases. #{config['database']} is on a remote host."
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
MySQLDatabaseTasks.class_eval do
|
|
32
|
-
|
|
33
|
-
def error_class
|
|
34
|
-
ActiveRecord::JDBCError
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
end
|
data/rakelib/compile.rake
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
jar_file = File.join(*%w(lib arjdbc jdbc adapter_java.jar))
|
|
2
|
-
begin
|
|
3
|
-
require 'ant'
|
|
4
|
-
directory classes = "pkg/classes"
|
|
5
|
-
CLEAN << classes
|
|
6
|
-
|
|
7
|
-
driver_jars = []
|
|
8
|
-
# PostgreSQL driver :
|
|
9
|
-
driver_jars << Dir.glob("jdbc-postgres/lib/*.jar").sort.last
|
|
10
|
-
|
|
11
|
-
file jar_file => FileList['src/java/**/*.java', 'pkg/classes'] do
|
|
12
|
-
rm_rf FileList["#{classes}/**/*"]
|
|
13
|
-
ant.javac :srcdir => "src/java", :destdir => "pkg/classes",
|
|
14
|
-
:source => "7", :target => "7", :debug => true, :deprecation => true,
|
|
15
|
-
:classpath => "${java.class.path}:${sun.boot.class.path}:#{driver_jars.join(':')}",
|
|
16
|
-
:includeantRuntime => false
|
|
17
|
-
|
|
18
|
-
ant.tstamp do |ts|
|
|
19
|
-
ts.format(:property => 'TODAY', :pattern => 'yyyy-MM-dd HH:mm:ss')
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
begin
|
|
23
|
-
require 'arjdbc/version'
|
|
24
|
-
rescue LoadError
|
|
25
|
-
path = File.expand_path('../lib', File.dirname(__FILE__))
|
|
26
|
-
unless $LOAD_PATH.include?(path)
|
|
27
|
-
$LOAD_PATH << path; retry
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
gem_version = Gem::Version.create(ArJdbc::VERSION)
|
|
32
|
-
if gem_version.segments.last == 'DEV'
|
|
33
|
-
version = gem_version.segments[0...-1] # 1.3.0.DEV -> 1.3.0
|
|
34
|
-
else
|
|
35
|
-
version = gem_version.segments.dup
|
|
36
|
-
end
|
|
37
|
-
version = version.join('.')
|
|
38
|
-
|
|
39
|
-
ant.manifest :file => 'MANIFEST.MF' do |mf|
|
|
40
|
-
mf.attribute :name => 'Built-By', :value => '${user.name}'
|
|
41
|
-
mf.attribute :name => 'Built-Time', :value => '${TODAY}'
|
|
42
|
-
mf.attribute :name => 'Built-Jdk', :value => '${java.version}'
|
|
43
|
-
mf.attribute :name => 'Built-JRuby', :value => JRUBY_VERSION
|
|
44
|
-
|
|
45
|
-
mf.attribute :name => 'Specification-Title', :value => 'ActiveRecord-JDBC'
|
|
46
|
-
mf.attribute :name => 'Specification-Version', :value => '1.3'
|
|
47
|
-
mf.attribute :name => 'Specification-Vendor', :value => 'JRuby'
|
|
48
|
-
mf.attribute :name => 'Implementation-Version', :value => version
|
|
49
|
-
mf.attribute :name => 'Implementation-Vendor', :value => 'The JRuby Team'
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
ant.jar :basedir => "pkg/classes", :includes => "**/*.class",
|
|
53
|
-
:destfile => jar_file, :manifest => 'MANIFEST.MF'
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
desc "Compile the native Java code."
|
|
57
|
-
task :jar => jar_file
|
|
58
|
-
|
|
59
|
-
namespace :jar do
|
|
60
|
-
task :force do
|
|
61
|
-
rm jar_file if File.exist?(jar_file)
|
|
62
|
-
Rake::Task['jar'].invoke
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
rescue LoadError
|
|
67
|
-
task :jar do
|
|
68
|
-
puts "Run 'jar' with JRuby to re-compile the agent extension class"
|
|
69
|
-
end
|
|
70
|
-
end
|