activerecord-jdbc-alt-adapter 52.5.1-java → 60.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.nvimlog +0 -0
  4. data/.travis.yml +61 -37
  5. data/Gemfile +10 -3
  6. data/README.md +44 -28
  7. data/Rakefile +1 -1
  8. data/Rakefile.jdbc +8 -1
  9. data/activerecord-jdbc-adapter.gemspec +5 -8
  10. data/activerecord-jdbc-alt-adapter.gemspec +5 -8
  11. data/lib/arel/visitors/sqlserver.rb +33 -23
  12. data/lib/arjdbc/abstract/connection_management.rb +7 -0
  13. data/lib/arjdbc/abstract/core.rb +16 -23
  14. data/lib/arjdbc/abstract/database_statements.rb +24 -0
  15. data/lib/arjdbc/abstract/statement_cache.rb +2 -5
  16. data/lib/arjdbc/abstract/transaction_support.rb +5 -3
  17. data/lib/arjdbc/db2/column.rb +0 -39
  18. data/lib/arjdbc/derby/adapter.rb +1 -20
  19. data/lib/arjdbc/firebird/adapter.rb +0 -21
  20. data/lib/arjdbc/h2/adapter.rb +0 -15
  21. data/lib/arjdbc/hsqldb/adapter.rb +0 -14
  22. data/lib/arjdbc/informix/adapter.rb +0 -23
  23. data/lib/arjdbc/jdbc/adapter.rb +3 -1
  24. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  25. data/lib/arjdbc/jdbc/adapter_require.rb +3 -1
  26. data/lib/arjdbc/jdbc/base_ext.rb +3 -1
  27. data/lib/arjdbc/jdbc/callbacks.rb +2 -0
  28. data/lib/arjdbc/jdbc/column.rb +2 -0
  29. data/lib/arjdbc/jdbc/connection.rb +2 -0
  30. data/lib/arjdbc/jdbc/connection_methods.rb +2 -0
  31. data/lib/arjdbc/jdbc/error.rb +2 -0
  32. data/lib/arjdbc/jdbc/extension.rb +2 -0
  33. data/lib/arjdbc/jdbc/java.rb +3 -1
  34. data/lib/arjdbc/jdbc/railtie.rb +3 -1
  35. data/lib/arjdbc/jdbc/rake_tasks.rb +3 -1
  36. data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -1
  37. data/lib/arjdbc/jdbc/type_cast.rb +2 -0
  38. data/lib/arjdbc/jdbc/type_converter.rb +2 -0
  39. data/lib/arjdbc/mssql/adapter.rb +105 -36
  40. data/lib/arjdbc/mssql/column.rb +5 -1
  41. data/lib/arjdbc/mssql/connection_methods.rb +8 -2
  42. data/lib/arjdbc/mssql/database_limits.rb +2 -0
  43. data/lib/arjdbc/mssql/database_statements.rb +43 -5
  44. data/lib/arjdbc/mssql/errors.rb +2 -0
  45. data/lib/arjdbc/mssql/explain_support.rb +3 -1
  46. data/lib/arjdbc/mssql/extensions/attribute_methods.rb +5 -1
  47. data/lib/arjdbc/mssql/extensions/calculations.rb +2 -0
  48. data/lib/arjdbc/mssql/quoting.rb +38 -0
  49. data/lib/arjdbc/mssql/schema_creation.rb +24 -2
  50. data/lib/arjdbc/mssql/schema_definitions.rb +10 -0
  51. data/lib/arjdbc/mssql/schema_dumper.rb +2 -0
  52. data/lib/arjdbc/mssql/schema_statements.rb +63 -21
  53. data/lib/arjdbc/mssql/transaction.rb +2 -0
  54. data/lib/arjdbc/mssql/types/binary_types.rb +2 -0
  55. data/lib/arjdbc/mssql/types/date_and_time_types.rb +2 -0
  56. data/lib/arjdbc/mssql/types/deprecated_types.rb +2 -0
  57. data/lib/arjdbc/mssql/types/numeric_types.rb +2 -0
  58. data/lib/arjdbc/mssql/types/string_types.rb +2 -0
  59. data/lib/arjdbc/mssql/types.rb +2 -0
  60. data/lib/arjdbc/mssql/utils.rb +2 -0
  61. data/lib/arjdbc/mssql.rb +3 -1
  62. data/lib/arjdbc/mysql/adapter.rb +47 -18
  63. data/lib/arjdbc/postgresql/adapter.rb +240 -214
  64. data/lib/arjdbc/postgresql/base/array_decoder.rb +2 -0
  65. data/lib/arjdbc/postgresql/base/array_encoder.rb +4 -2
  66. data/lib/arjdbc/postgresql/base/array_parser.rb +4 -2
  67. data/lib/arjdbc/postgresql/base/pgconn.rb +2 -0
  68. data/lib/arjdbc/postgresql/column.rb +6 -4
  69. data/lib/arjdbc/postgresql/name.rb +2 -0
  70. data/lib/arjdbc/postgresql/oid_types.rb +3 -1
  71. data/lib/arjdbc/sqlite3/adapter.rb +188 -180
  72. data/lib/arjdbc/sqlite3/connection_methods.rb +15 -4
  73. data/lib/arjdbc/tasks/databases.rake +13 -10
  74. data/lib/arjdbc/tasks/mssql_database_tasks.rb +49 -5
  75. data/lib/arjdbc/util/quoted_cache.rb +3 -1
  76. data/lib/arjdbc/util/serialized_attributes.rb +3 -1
  77. data/lib/arjdbc/util/table_copier.rb +3 -1
  78. data/lib/arjdbc/version.rb +1 -1
  79. data/pom.xml +4 -4
  80. data/rakelib/01-tomcat.rake +2 -2
  81. data/src/java/arjdbc/ArJdbcModule.java +5 -5
  82. data/src/java/arjdbc/jdbc/DriverWrapper.java +1 -9
  83. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +406 -629
  84. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +88 -0
  85. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +13 -23
  86. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +56 -30
  87. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +94 -99
  88. data/src/java/arjdbc/util/DateTimeUtils.java +12 -4
  89. metadata +7 -16
@@ -23,17 +23,27 @@ ArJdbc::ConnectionMethods.module_eval do
23
23
  raise
24
24
  end
25
25
  end
26
-
26
+
27
+ config[:properties] ||= {}
28
+
27
29
  database = config[:database] # NOTE: "jdbc:sqlite::memory:" syntax is supported
28
30
  config[:url] ||= "jdbc:sqlite:#{database == ':memory:' ? '' : database}"
29
31
  config[:connection_alive_sql] ||= 'SELECT 1'
30
32
 
33
+ if config[:readonly]
34
+ # See
35
+ # * http://sqlite.org/c3ref/open.html
36
+ # * http://sqlite.org/c3ref/c_open_autoproxy.html
37
+ # => 0x01 = readonly, 0x40 = uri (default in JDBC)
38
+ config[:properties][:open_mode] = 0x01 | 0x40
39
+ end
40
+
31
41
  timeout = config[:timeout]
32
42
  if timeout && timeout.to_s !~ /\A\d+\Z/
33
43
  raise TypeError.new "Timeout must be nil or a number (got: #{timeout})."
34
44
  end
35
45
 
36
- options = ( config[:properties] ||= {} )
46
+ options = config[:properties]
37
47
  options['busy_timeout'] ||= timeout unless timeout.nil?
38
48
 
39
49
  jdbc_connection(config)
@@ -51,8 +61,9 @@ ArJdbc::ConnectionMethods.module_eval do
51
61
  def parse_sqlite3_config!(config)
52
62
  database = ( config[:database] ||= config[:dbfile] )
53
63
  if ':memory:' != database
54
- config[:database] = File.expand_path(database, Rails.root) if defined?(Rails.root)
55
- dirname = File.dirname(database)
64
+ # make sure to have an absolute path. Ruby and Java don't agree on working directory
65
+ config[:database] = File.expand_path(database, defined?(Rails.root) ? Rails.root : nil)
66
+ dirname = File.dirname(config[:database])
56
67
  Dir.mkdir(dirname) unless File.directory?(dirname)
57
68
  end
58
69
  end
@@ -5,25 +5,28 @@ module ActiveRecord::Tasks
5
5
  DatabaseTasks.module_eval do
6
6
 
7
7
  # @override patched to adapt jdbc configuration
8
- def each_current_configuration(environment)
8
+ def each_current_configuration(environment, spec_name = nil)
9
9
  environments = [environment]
10
10
  environments << 'test' if environment == 'development'
11
11
 
12
- configurations = ActiveRecord::Base.configurations.values_at(*environments)
13
- configurations.compact.each do |config|
14
- yield adapt_jdbc_config(config) unless config['database'].blank?
12
+ environments.each do |env|
13
+ ActiveRecord::Base.configurations.configs_for(env_name: env).each do |db_config|
14
+ next if spec_name && spec_name != db_config.spec_name
15
+
16
+ yield adapt_jdbc_config(db_config.config), db_config.spec_name, env unless db_config.config['database'].blank?
17
+ end
15
18
  end
16
19
  end
17
20
 
18
21
  # @override patched to adapt jdbc configuration
19
22
  def each_local_configuration
20
- ActiveRecord::Base.configurations.each_value do |config|
21
- next unless config['database']
23
+ ActiveRecord::Base.configurations.configs_for.each do |db_config|
24
+ next unless db_config.config['database']
22
25
 
23
- if local_database?(config)
24
- yield adapt_jdbc_config(config)
26
+ if local_database?(db_config.config)
27
+ yield adapt_jdbc_config(db_config.config)
25
28
  else
26
- $stderr.puts "This task only modifies local databases. #{config['database']} is on a remote host."
29
+ $stderr.puts "This task only modifies local databases. #{db_config.config['database']} is on a remote host."
27
30
  end
28
31
  end
29
32
  end
@@ -45,4 +48,4 @@ module ActiveRecord::Tasks
45
48
 
46
49
  end if const_defined?(:MySQLDatabaseTasks)
47
50
 
48
- end
51
+ end
@@ -1,17 +1,37 @@
1
+ require 'active_record/tasks/database_tasks'
2
+
1
3
  require 'arjdbc/tasks/jdbc_database_tasks'
2
4
 
3
5
  module ArJdbc
4
6
  module Tasks
5
7
  class MSSQLDatabaseTasks < JdbcDatabaseTasks
8
+ delegate :clear_active_connections!, to: ActiveRecord::Base
9
+
10
+ def create
11
+ establish_master_connection
12
+ connection.create_database(configuration['database'])
13
+ establish_connection configuration
14
+ rescue ActiveRecord::StatementInvalid => error
15
+ case error.message
16
+ when /database .* already exists/i
17
+ raise ActiveRecord::Tasks::DatabaseAlreadyExists
18
+ else
19
+ raise
20
+ end
21
+ end
22
+
23
+ def drop
24
+ establish_master_connection
25
+ connection.drop_database configuration['database']
26
+ end
6
27
 
7
28
  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)
29
+ clear_active_connections!
30
+ drop
31
+ create
13
32
  end
14
33
 
34
+
15
35
  def structure_dump(filename)
16
36
  config = config_from_url_if_needed
17
37
  `smoscript -s #{config['host']} -d #{config['database']} -u #{config['username']} -p #{config['password']} -f #{filename} -A -U`
@@ -24,6 +44,10 @@ module ArJdbc
24
44
 
25
45
  private
26
46
 
47
+ def establish_master_connection
48
+ establish_connection configuration.merge('database' => 'master')
49
+ end
50
+
27
51
  def config_from_url_if_needed
28
52
  config = self.config
29
53
  if config['url'] && ! config.key?('database')
@@ -42,5 +66,25 @@ module ArJdbc
42
66
  end
43
67
 
44
68
  end
69
+
70
+ module DatabaseTasksMSSQL
71
+ extend ActiveSupport::Concern
72
+
73
+ module ClassMethods
74
+
75
+ def check_protected_environments!
76
+ super
77
+ rescue ActiveRecord::JDBCError => error
78
+ case error.message
79
+ when /cannot open database .* requested by the login/i
80
+ else
81
+ raise
82
+ end
83
+ end
84
+
85
+ end
86
+ end
87
+
88
+ ActiveRecord::Tasks::DatabaseTasks.send :include, DatabaseTasksMSSQL
45
89
  end
46
90
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArJdbc
2
4
  module Util
3
5
  # Caches table and column name (quoted) outcomes.
@@ -57,4 +59,4 @@ module ArJdbc
57
59
 
58
60
  end
59
61
  end
60
- end
62
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArJdbc
2
4
  module Util
3
5
  # Gets included into `ActiveRecord::Base` to support sending LOB values
@@ -95,4 +97,4 @@ module ArJdbc
95
97
  end
96
98
  # @private only due backwards compatibility
97
99
  SerializedAttributesHelper = Util::SerializedAttributes
98
- end
100
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArJdbc
2
4
  module Util
3
5
  module TableCopier
@@ -107,4 +109,4 @@ module ArJdbc
107
109
  end
108
110
  # @private @deprecated backwards compatibility
109
111
  MissingFunctionalityHelper = Util::TableCopier
110
- end
112
+ end
@@ -1,3 +1,3 @@
1
1
  module ArJdbc
2
- VERSION = '52.5.1'
2
+ VERSION = '60.2.0'
3
3
  end
data/pom.xml CHANGED
@@ -12,7 +12,7 @@
12
12
  <url>http://github.com/jruby/activerecord-jdbc-adapter/wiki</url>
13
13
 
14
14
  <properties>
15
- <jruby.version>9.1.6.0</jruby.version>
15
+ <jruby.version>9.2.6.0</jruby.version>
16
16
  </properties>
17
17
 
18
18
  <issueManagement>
@@ -75,7 +75,7 @@
75
75
  <dependency>
76
76
  <groupId>org.postgresql</groupId>
77
77
  <artifactId>postgresql</artifactId>
78
- <version>42.1.4.jre7</version>
78
+ <version>42.1.4</version>
79
79
  </dependency>
80
80
  </dependencies>
81
81
 
@@ -103,8 +103,8 @@
103
103
  <artifactId>maven-compiler-plugin</artifactId>
104
104
  <version>2.5.1</version>
105
105
  <configuration>
106
- <source>1.7</source>
107
- <target>1.7</target>
106
+ <source>1.8</source>
107
+ <target>1.8</target>
108
108
  </configuration>
109
109
  </plugin>
110
110
  </plugins>
@@ -1,6 +1,6 @@
1
1
  namespace :'tomcat-jndi' do # contains a FS JNDI impl (for tests)
2
2
 
3
- TOMCAT_MAVEN_REPO = 'http://repo2.maven.org/maven2/org/apache/tomcat'
3
+ TOMCAT_MAVEN_REPO = 'https://repo1.maven.org/maven2/org/apache/tomcat'
4
4
  TOMCAT_VERSION = '7.0.54'
5
5
 
6
6
  DOWNLOAD_DIR = File.expand_path('../test/jars', File.dirname(__FILE__))
@@ -48,4 +48,4 @@ namespace :'tomcat-jndi' do # contains a FS JNDI impl (for tests)
48
48
  rm jar_path if File.exist?(jar_path)
49
49
  end
50
50
 
51
- end
51
+ end
@@ -151,7 +151,7 @@ public class ArJdbcModule {
151
151
  throw newNativeException(runtime, e);
152
152
  }
153
153
 
154
- return runtime.getTrue();
154
+ return context.tru;
155
155
  }
156
156
 
157
157
  /**
@@ -191,7 +191,7 @@ public class ArJdbcModule {
191
191
  }
192
192
 
193
193
  // NOTE: probably useless - only to be useful for the pooled runtime mode when jar at WEB-INF/lib
194
- static final Map<Ruby, Map<String, Boolean>> loadedDrivers = new WeakHashMap<Ruby, Map<String, Boolean>>(8);
194
+ static final Map<Ruby, Map<String, Boolean>> loadedDrivers = new WeakHashMap<>(8);
195
195
 
196
196
  private static IRubyObject loadDriver(final ThreadContext context, final IRubyObject self,
197
197
  final String constName) {
@@ -202,7 +202,7 @@ public class ArJdbcModule {
202
202
  synchronized (ArJdbcModule.class) {
203
203
  loadedMap = loadedDrivers.get(runtime);
204
204
  if ( loadedMap == null ) {
205
- loadedMap = new HashMap<String, Boolean>(4);
205
+ loadedMap = new HashMap<>(4);
206
206
  loadedDrivers.put(runtime, loadedMap);
207
207
  }
208
208
  }
@@ -210,8 +210,8 @@ public class ArJdbcModule {
210
210
 
211
211
  final Boolean driverLoaded = loadedMap.get(constName);
212
212
  if ( driverLoaded != null ) {
213
- if ( driverLoaded.booleanValue() ) return runtime.getFalse();
214
- return runtime.getNil();
213
+ if (driverLoaded) return context.fals;
214
+ return context.nil;
215
215
  }
216
216
 
217
217
  try { // require 'jdbc/mysql'
@@ -60,15 +60,7 @@ public class DriverWrapper {
60
60
 
61
61
  private Driver allocateDriver(final Class<? extends Driver> driverClass)
62
62
  throws InstantiationException, IllegalAccessException {
63
- try {
64
- return driverClass.newInstance();
65
- }
66
- catch (InstantiationException e) {
67
- throw e;
68
- }
69
- catch (IllegalAccessException e) {
70
- throw e;
71
- }
63
+ return driverClass.newInstance();
72
64
  }
73
65
 
74
66
  protected static Class<? extends Driver> loadDriver(final Ruby runtime, final String name)