activerecord-jdbc-alt-adapter 60.0.0-java → 60.1.0-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/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +1 -1
- data/README.md +19 -19
- data/lib/arjdbc/postgresql/adapter.rb +22 -3
- data/lib/arjdbc/postgresql/oid_types.rb +1 -1
- data/lib/arjdbc/sqlite3/adapter.rb +20 -7
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/01-tomcat.rake +2 -2
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1 -1
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +51 -0
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +20 -14
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f83a5e387ec9999cc730027498dec97428cfee7b3c3edcc6845a779c01c4272a
|
4
|
+
data.tar.gz: 3a7e9ce2b8e6e968bdb21f4ac72a9f498e3226c414ec4b003e4b463dffc74062
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f71a50d80a6f01837512d87a52ef32ec69a245e1927086cc0736efa35835c57710652f1ad6c294039422ad69eea20d308b48df02ba8d43e7c1acea4de7358ee0
|
7
|
+
data.tar.gz: 732cde407f1c4ff98bb7e528ea183dd483e2b8edf8a475f60f445dc7580fd8e8d3374ca248b5d7eb2f02b1c596efdeed5ce7dc393563425565657ca6302d6145
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -69,6 +69,9 @@ matrix:
|
|
69
69
|
- addons:
|
70
70
|
postgresql: "10"
|
71
71
|
env: DB=postgresql PREPARED_STATEMENTS=true INSERT_RETURNING=true
|
72
|
+
- addons:
|
73
|
+
postgresql: "10"
|
74
|
+
env: DB=postgresql PREPARED_STATEMENTS=true JRUBY_OPTS=-J-Duser.timezone=America/Detroit
|
72
75
|
- addons:
|
73
76
|
postgresql: "9.4"
|
74
77
|
env: DB=postgresql PREPARED_STATEMENTS=true
|
data/Gemfile
CHANGED
@@ -55,7 +55,7 @@ group :test do
|
|
55
55
|
gem 'mocha', '~> 1.2', require: false # Rails has '~> 0.14'
|
56
56
|
|
57
57
|
gem 'bcrypt', '~> 3.1.11', require: false
|
58
|
-
gem 'jdbc-mssql', '~> 0.
|
58
|
+
gem 'jdbc-mssql', '~> 0.9.0', require: nil
|
59
59
|
# gem 'pry-debugger-jruby', platform: :jruby
|
60
60
|
end
|
61
61
|
|
data/README.md
CHANGED
@@ -6,16 +6,20 @@ supported by the original adapter such as PostgreSQL but it is advised to
|
|
6
6
|
use the [original adapter](https://github.com/jruby/active)
|
7
7
|
|
8
8
|
This adapter only works with JRuby and it is advised to install the latest
|
9
|
-
stable
|
9
|
+
stable of this adapter and Rails
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
| Gem Version | Rails Version | min JRuby |
|
12
|
+
| ----------- | ------------- | --------- |
|
13
|
+
| 50.6.1 | 5.0.7.2 | 9.1.x |
|
14
|
+
| 51.6.1 | 5.1.7 | 9.1.x |
|
15
|
+
| 52.5.1 | 5.2.4.1 | 9.1.x |
|
16
|
+
| 60.0.0 | 6.0.2 | 9.2.9 |
|
16
17
|
|
17
18
|
This adapter passes most of the Rails tests (ActiveRecord tests) with the
|
18
|
-
exception of some test that are not compatible with the SQL Server
|
19
|
+
exception of some test that are not compatible with the SQL Server. To run
|
20
|
+
the test use the following fork [Rails](https://github.com/JesseChavez/rails/tree/6-0-stable-dev),
|
21
|
+
and the instructions in file `RUNNING_TESTS.md`. The fork has some
|
22
|
+
schema tweaks to make it compatible with SQL Server.
|
19
23
|
|
20
24
|
### How to use it:
|
21
25
|
|
@@ -24,13 +28,17 @@ Add the following to your `Gemfile`:
|
|
24
28
|
```ruby
|
25
29
|
platforms :jruby do
|
26
30
|
# Use jdbc as the database for Active Record
|
27
|
-
gem 'activerecord-jdbc-alt-adapter', '~>
|
28
|
-
gem 'jdbc-mssql', '~> 0.
|
31
|
+
gem 'activerecord-jdbc-alt-adapter', '~> 60.0.0'
|
32
|
+
gem 'jdbc-mssql', '~> 0.7.0'
|
29
33
|
end
|
30
34
|
```
|
31
35
|
|
32
|
-
Or look at the sample rails
|
33
|
-
|
36
|
+
Or look at the sample rails and see how is set up:
|
37
|
+
|
38
|
+
- Rails 6.0 sample app [wombat60](https://github.com/JesseChavez/wombat60)
|
39
|
+
|
40
|
+
- Old rails 5.0 app [wombat50](https://github.com/JesseChavez/wombat50)
|
41
|
+
|
34
42
|
|
35
43
|
### Breaking changes
|
36
44
|
|
@@ -102,14 +110,6 @@ production:
|
|
102
110
|
```
|
103
111
|
|
104
112
|
|
105
|
-
### NOTE
|
106
|
-
|
107
|
-
Keep one eye in the Rails connection pool, we have not thoroughly tested that
|
108
|
-
part since we don't use the default Rails connection pool, other than that
|
109
|
-
this adapter should just work.
|
110
|
-
|
111
|
-
|
112
|
-
|
113
113
|
# ActiveRecord JDBC Adapter
|
114
114
|
|
115
115
|
[][7]
|
@@ -303,6 +303,10 @@ module ArJdbc
|
|
303
303
|
@has_pg_hint_plan
|
304
304
|
end
|
305
305
|
|
306
|
+
def supports_common_table_expressions?
|
307
|
+
true
|
308
|
+
end
|
309
|
+
|
306
310
|
def supports_lazy_transactions?
|
307
311
|
true
|
308
312
|
end
|
@@ -379,13 +383,23 @@ module ArJdbc
|
|
379
383
|
end
|
380
384
|
end
|
381
385
|
|
386
|
+
def execute_batch(statements, name = nil)
|
387
|
+
if statements.is_a? Array
|
388
|
+
execute(combine_multi_statements(statements), name)
|
389
|
+
else
|
390
|
+
execute(statements, name)
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
382
394
|
def explain(arel, binds = [])
|
383
395
|
sql, binds = to_sql_and_binds(arel, binds)
|
384
396
|
ActiveRecord::ConnectionAdapters::PostgreSQL::ExplainPrettyPrinter.new.pp(exec_query("EXPLAIN #{sql}", 'EXPLAIN', binds))
|
385
397
|
end
|
386
398
|
|
387
399
|
# from ActiveRecord::ConnectionAdapters::PostgreSQL::DatabaseStatements
|
388
|
-
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
400
|
+
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
401
|
+
:begin, :commit, :explain, :select, :set, :show, :release, :savepoint, :rollback, :with
|
402
|
+
) # :nodoc:
|
389
403
|
private_constant :READ_QUERY
|
390
404
|
|
391
405
|
def write_query?(sql) # :nodoc:
|
@@ -435,7 +449,12 @@ module ArJdbc
|
|
435
449
|
end
|
436
450
|
|
437
451
|
def build_truncate_statements(*table_names)
|
438
|
-
"TRUNCATE TABLE #{table_names.map(&method(:quote_table_name)).join(", ")}"
|
452
|
+
["TRUNCATE TABLE #{table_names.flatten.map(&method(:quote_table_name)).join(", ")}"]
|
453
|
+
end
|
454
|
+
|
455
|
+
def truncate(table_name, name = nil)
|
456
|
+
ActiveRecord::Base.clear_query_caches_for_current_thread if @query_cache_enabled
|
457
|
+
execute("TRUNCATE TABLE #{quote_table_name(table_name)}", name)
|
439
458
|
end
|
440
459
|
|
441
460
|
def all_schemas
|
@@ -493,7 +512,7 @@ module ArJdbc
|
|
493
512
|
alias_method :quote_schema_name, :quote_column_name
|
494
513
|
|
495
514
|
# Need to clear the cache even though the AR adapter doesn't for some reason
|
496
|
-
def remove_column(table_name, column_name, type = nil, options
|
515
|
+
def remove_column(table_name, column_name, type = nil, **options)
|
497
516
|
super
|
498
517
|
clear_cache!
|
499
518
|
end
|
@@ -213,7 +213,7 @@ module ArJdbc
|
|
213
213
|
if oid
|
214
214
|
if oid.is_a? Numeric || oid.match(/^\d+$/)
|
215
215
|
# numeric OID
|
216
|
-
query += "WHERE t.oid
|
216
|
+
query += "WHERE t.oid = %s" % oid
|
217
217
|
|
218
218
|
elsif m = oid.match(/"?(\w+)"?\."?(\w+)"?/)
|
219
219
|
# namespace and type name
|
@@ -97,6 +97,10 @@ module ArJdbc
|
|
97
97
|
true
|
98
98
|
end
|
99
99
|
|
100
|
+
def supports_common_table_expressions?
|
101
|
+
database_version >= "3.8.3"
|
102
|
+
end
|
103
|
+
|
100
104
|
def supports_insert_on_conflict?
|
101
105
|
database_version >= "3.24.0"
|
102
106
|
end
|
@@ -154,7 +158,9 @@ module ArJdbc
|
|
154
158
|
# DATABASE STATEMENTS ======================================
|
155
159
|
#++
|
156
160
|
|
157
|
-
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
161
|
+
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
162
|
+
:begin, :commit, :explain, :select, :pragma, :release, :savepoint, :rollback, :with
|
163
|
+
) # :nodoc:
|
158
164
|
private_constant :READ_QUERY
|
159
165
|
|
160
166
|
def write_query?(sql) # :nodoc:
|
@@ -223,7 +229,7 @@ module ArJdbc
|
|
223
229
|
end
|
224
230
|
end
|
225
231
|
|
226
|
-
def remove_column(table_name, column_name, type = nil, options
|
232
|
+
def remove_column(table_name, column_name, type = nil, **options) #:nodoc:
|
227
233
|
alter_table(table_name) do |definition|
|
228
234
|
definition.remove_column column_name
|
229
235
|
definition.foreign_keys.delete_if do |_, fk_options|
|
@@ -317,11 +323,17 @@ module ArJdbc
|
|
317
323
|
SQLite3Adapter::Version.new(query_value("SELECT sqlite_version(*)"))
|
318
324
|
end
|
319
325
|
|
326
|
+
def build_truncate_statement(table_name)
|
327
|
+
"DELETE FROM #{quote_table_name(table_name)}"
|
328
|
+
end
|
329
|
+
|
320
330
|
def build_truncate_statements(*table_names)
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
331
|
+
table_names.flatten.map { |table_name| build_truncate_statement table_name }
|
332
|
+
end
|
333
|
+
|
334
|
+
def truncate(table_name, name = nil)
|
335
|
+
ActiveRecord::Base.clear_query_caches_for_current_thread if @query_cache_enabled
|
336
|
+
execute(build_truncate_statement(table_name), name)
|
325
337
|
end
|
326
338
|
|
327
339
|
def check_version
|
@@ -352,7 +364,8 @@ module ArJdbc
|
|
352
364
|
# See: https://www.sqlite.org/lang_altertable.html
|
353
365
|
# SQLite has an additional restriction on the ALTER TABLE statement
|
354
366
|
def invalid_alter_table_type?(type, options)
|
355
|
-
type.to_sym == :primary_key || options[:primary_key]
|
367
|
+
type.to_sym == :primary_key || options[:primary_key] ||
|
368
|
+
options[:null] == false && options[:default].nil?
|
356
369
|
end
|
357
370
|
|
358
371
|
def alter_table(table_name, foreign_keys = foreign_keys(table_name), **options)
|
data/lib/arjdbc/version.rb
CHANGED
data/rakelib/01-tomcat.rake
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
namespace :'tomcat-jndi' do # contains a FS JNDI impl (for tests)
|
2
2
|
|
3
|
-
TOMCAT_MAVEN_REPO = '
|
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
|
@@ -2165,7 +2165,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
2165
2165
|
return RubyString.newString(runtime, DateTimeUtils.dateToString(value));
|
2166
2166
|
}
|
2167
2167
|
|
2168
|
-
return DateTimeUtils.newDateAsTime(context, value,
|
2168
|
+
return DateTimeUtils.newDateAsTime(context, value, DateTimeZone.UTC).callMethod(context, "to_date");
|
2169
2169
|
}
|
2170
2170
|
|
2171
2171
|
protected IRubyObject timeToRuby(final ThreadContext context,
|
@@ -204,6 +204,57 @@ public class MSSQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
204
204
|
});
|
205
205
|
}
|
206
206
|
|
207
|
+
/**
|
208
|
+
* Executes an INSERT SQL statement
|
209
|
+
* @param context
|
210
|
+
* @param sql
|
211
|
+
* @param pk Rails PK
|
212
|
+
* @return ActiveRecord::Result
|
213
|
+
* @throws SQLException
|
214
|
+
*/
|
215
|
+
@Override
|
216
|
+
@JRubyMethod(name = "execute_insert_pk", required = 2)
|
217
|
+
public IRubyObject execute_insert_pk(final ThreadContext context, final IRubyObject sql, final IRubyObject pk) {
|
218
|
+
|
219
|
+
// MSSQL does not like composite primary keys here so chop it if there is more than one column
|
220
|
+
IRubyObject modifiedPk = pk;
|
221
|
+
|
222
|
+
if (pk instanceof RubyArray) {
|
223
|
+
RubyArray ary = (RubyArray) pk;
|
224
|
+
if (ary.size() > 0) {
|
225
|
+
modifiedPk = ary.eltInternal(0);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
return super.execute_insert_pk(context, sql, modifiedPk);
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Executes an INSERT SQL statement using a prepared statement
|
234
|
+
* @param context
|
235
|
+
* @param sql
|
236
|
+
* @param binds RubyArray of values to be bound to the query
|
237
|
+
* @param pk Rails PK
|
238
|
+
* @return ActiveRecord::Result
|
239
|
+
* @throws SQLException
|
240
|
+
*/
|
241
|
+
@Override
|
242
|
+
@JRubyMethod(name = "execute_insert_pk", required = 3)
|
243
|
+
public IRubyObject execute_insert_pk(final ThreadContext context, final IRubyObject sql, final IRubyObject binds,
|
244
|
+
final IRubyObject pk) {
|
245
|
+
// MSSQL does not like composite primary keys here so chop it if there is more than one column
|
246
|
+
IRubyObject modifiedPk = pk;
|
247
|
+
|
248
|
+
if (pk instanceof RubyArray) {
|
249
|
+
RubyArray ary = (RubyArray) pk;
|
250
|
+
if (ary.size() > 0) {
|
251
|
+
modifiedPk = ary.eltInternal(0);
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
return super.execute_insert_pk(context, sql, binds, modifiedPk);
|
256
|
+
}
|
257
|
+
|
207
258
|
@Override
|
208
259
|
protected Integer jdbcTypeFor(final String type) {
|
209
260
|
|
@@ -36,26 +36,18 @@ import java.io.ByteArrayInputStream;
|
|
36
36
|
import java.lang.StringBuilder;
|
37
37
|
import java.lang.reflect.InvocationTargetException;
|
38
38
|
import java.math.BigDecimal;
|
39
|
-
import java.sql
|
40
|
-
import java.sql.
|
41
|
-
import java.
|
42
|
-
import java.sql.ResultSet;
|
43
|
-
import java.sql.ResultSetMetaData;
|
44
|
-
import java.sql.SQLException;
|
45
|
-
import java.sql.Timestamp;
|
46
|
-
import java.sql.Types;
|
47
|
-
import java.util.ArrayList;
|
48
|
-
import java.util.Collections;
|
49
|
-
import java.util.HashMap;
|
50
|
-
import java.util.Map;
|
51
|
-
import java.util.UUID;
|
39
|
+
import java.sql.*;
|
40
|
+
import java.sql.Date;
|
41
|
+
import java.util.*;
|
52
42
|
import java.util.regex.Pattern;
|
53
43
|
import java.util.regex.Matcher;
|
54
44
|
|
45
|
+
import org.joda.time.DateTime;
|
55
46
|
import org.jruby.*;
|
56
47
|
import org.jruby.anno.JRubyMethod;
|
57
48
|
import org.jruby.exceptions.RaiseException;
|
58
49
|
import org.jruby.ext.bigdecimal.RubyBigDecimal;
|
50
|
+
import org.jruby.ext.date.RubyDate;
|
59
51
|
import org.jruby.javasupport.JavaUtil;
|
60
52
|
import org.jruby.runtime.ObjectAllocator;
|
61
53
|
import org.jruby.runtime.ThreadContext;
|
@@ -115,6 +107,7 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
115
107
|
|
116
108
|
// Used to wipe trailing 0's from points (3.0, 5.6) -> (3, 5.6)
|
117
109
|
private static final Pattern pointCleanerPattern = Pattern.compile("\\.0\\b");
|
110
|
+
private static final TimeZone TZ_DEFAULT = TimeZone.getDefault();
|
118
111
|
|
119
112
|
private RubyClass resultClass;
|
120
113
|
private RubyHash typeMap = null;
|
@@ -386,7 +379,20 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
386
379
|
}
|
387
380
|
}
|
388
381
|
|
389
|
-
|
382
|
+
if ( ! "Date".equals(value.getMetaClass().getName()) && value.respondsTo("to_date") ) {
|
383
|
+
value = value.callMethod(context, "to_date");
|
384
|
+
}
|
385
|
+
|
386
|
+
if (value instanceof RubyDate) {
|
387
|
+
RubyDate rubyDate = (RubyDate) value;
|
388
|
+
DateTime dt = rubyDate.getDateTime();
|
389
|
+
// pgjdbc needs adjustment for default JVM timezone
|
390
|
+
statement.setDate(index, new Date(dt.getMillis() - TZ_DEFAULT.getOffset(dt.getMillis())));
|
391
|
+
return;
|
392
|
+
}
|
393
|
+
|
394
|
+
// NOTE: assuming Date#to_s does right ...
|
395
|
+
statement.setDate(index, Date.valueOf(value.toString()));
|
390
396
|
}
|
391
397
|
|
392
398
|
@Override
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-jdbc-alt-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 60.
|
4
|
+
version: 60.1.0
|
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:
|
11
|
+
date: 2021-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -17,8 +17,8 @@ dependencies:
|
|
17
17
|
- !ruby/object:Gem::Version
|
18
18
|
version: 6.0.0
|
19
19
|
name: activerecord
|
20
|
-
prerelease: false
|
21
20
|
type: :runtime
|
21
|
+
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
@@ -264,8 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
264
264
|
- !ruby/object:Gem::Version
|
265
265
|
version: '0'
|
266
266
|
requirements: []
|
267
|
-
|
268
|
-
rubygems_version: 2.7.10
|
267
|
+
rubygems_version: 3.0.6
|
269
268
|
signing_key:
|
270
269
|
specification_version: 4
|
271
270
|
summary: ActiveRecord JDBC adapter, for use within JRuby on Rails and SQL Server
|