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

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c26b1aeb852d6a51090bf9084b5371336673343434f2ac71e8ce11bacbf1c12
4
- data.tar.gz: 770683c6f0474d1393224eb342768abf987614a6fdb8affc2095cb60dc6ce8fd
3
+ metadata.gz: af6cc4c4563f32b39f0ddac72fbfa090de13e23eefba9a95c14221787478f132
4
+ data.tar.gz: cc6754a427170292ebee5a56201bef82a3dd10cbf2034aff2e8e9d8b52575243
5
5
  SHA512:
6
- metadata.gz: d76c562fb3f75d56af58bec90913e2f60dee2866e18b1c1f8589c6918fcddec36dac70763560af9bb334c021d198a81511e3a3501142b658fe98bd306ad42525
7
- data.tar.gz: 2a4a6fa05469f1246cbc278b10d65a4fd9003e9e963a7bbb8abc302751c6bfabe37a12404f6da0a87c6c9804cd11e868eb11c94f93e58d0843da01e79c77ec6c
6
+ metadata.gz: 91fff9a0aabfb206c84759e0370d92a9e843bc8b6271d38adde65292b534052a4bcc20b1a9d454ea40b28feef2b453f7b1c1a0aac12ae4c06625d71ac72164e0
7
+ data.tar.gz: e66da4371d5fc890788b6cfb3c7c483e7e7f7c706aba84195495b97ae3d5438353fefef852a4aee24bca044d6b3c75315f32f1f68f194cdbd299bb92ff3fc27c
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.tgz
3
3
  *~
4
4
  *.log
5
+ /log/
5
6
  patches*
6
7
  *#
7
8
  TAGS
@@ -13,10 +13,10 @@ module ArJdbc
13
13
  binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
14
14
 
15
15
  if without_prepared_statement?(binds)
16
- log(sql, name) { @connection.execute_insert(sql) }
16
+ log(sql, name) { @connection.execute_insert_pk(sql, pk) }
17
17
  else
18
18
  log(sql, name, binds) do
19
- @connection.execute_insert(sql, binds)
19
+ @connection.execute_insert_pk(sql, binds, pk)
20
20
  end
21
21
  end
22
22
  end
@@ -132,6 +132,13 @@ module ActiveRecord
132
132
  super
133
133
  end
134
134
 
135
+ def reset!
136
+ # execute 'IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION'
137
+ # NOTE: it seems the above line interferes with the jdbc driver
138
+ # and ending up in connection closed, issue seen in rails 5.2 and 6.0
139
+ reconnect!
140
+ end
141
+
135
142
  def disable_referential_integrity
136
143
  tables = tables_with_referential_integrity
137
144
 
@@ -52,6 +52,8 @@ ArJdbc::ConnectionMethods.module_eval do
52
52
 
53
53
  # @note Assumes SQLServer SQL-JDBC driver on the class-path.
54
54
  def sqlserver_connection(config)
55
+ config = config.deep_dup
56
+
55
57
  config[:adapter_spec] ||= ::ArJdbc::MSSQL
56
58
  config[:adapter_class] = ActiveRecord::ConnectionAdapters::MSSQLAdapter unless config.key?(:adapter_class)
57
59
 
@@ -127,7 +127,7 @@ module ActiveRecord
127
127
  end
128
128
 
129
129
  def identity_column_name(table_name)
130
- for column in columns(table_name)
130
+ for column in schema_cache.columns(table_name)
131
131
  return column.name if column.identity?
132
132
  end
133
133
  nil
@@ -46,7 +46,7 @@ module ActiveRecord
46
46
  # NOTE: This is ready, all implemented in the java part of adapter,
47
47
  # it uses MSSQLColumn, SqlTypeMetadata, etc.
48
48
  def columns(table_name)
49
- @connection.columns(table_name)
49
+ log('JDBC: GETCOLUMNS', 'SCHEMA') { @connection.columns(table_name) }
50
50
  rescue => e
51
51
  # raise translate_exception_class(e, nil)
52
52
  # FIXME: this breaks one arjdbc test but fixes activerecord tests
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  ArJdbc::ConnectionMethods.module_eval do
3
3
  def mysql_connection(config)
4
+ config = config.deep_dup
4
5
  # NOTE: this isn't "really" necessary but Rails (in tests) assumes being able to :
5
6
  # ActiveRecord::Base.mysql2_connection ActiveRecord::Base.configurations['arunit'].merge(database: ...)
6
7
  config = symbolize_keys_if_necessary(config)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  ArJdbc::ConnectionMethods.module_eval do
3
3
  def postgresql_connection(config)
4
+ config = config.deep_dup
4
5
  # NOTE: this isn't "really" necessary but Rails (in tests) assumes being able to :
5
6
  # ActiveRecord::Base.postgresql_connection ActiveRecord::Base.configurations['arunit'].merge(:insert_returning => false)
6
7
  # ... while using symbols by default but than configurations returning string keys ;(
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  ArJdbc::ConnectionMethods.module_eval do
3
3
  def sqlite3_connection(config)
4
+ config = config.deep_dup
4
5
  config[:adapter_spec] ||= ::ArJdbc::SQLite3
5
6
  config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter unless config.key?(:adapter_class)
6
7
 
@@ -1,3 +1,3 @@
1
1
  module ArJdbc
2
- VERSION = '52.4.0'
2
+ VERSION = '52.5.1'
3
3
  end
data/rakelib/rails.rake CHANGED
@@ -57,7 +57,7 @@ namespace :rails do
57
57
  ruby_opts_string += " -C \"#{ar_path}\""
58
58
  ruby_opts_string += " -rbundler/setup"
59
59
  ruby_opts_string += " -rminitest -rminitest/excludes" unless ENV['NO_EXCLUDES'].eql?('true')
60
- file_list = ENV["TEST"] ? FileList[ ENV["TEST"] ] : test_files_finder.call
60
+ file_list = ENV["TEST"] ? FileList[ ENV["TEST"].split(',') ] : test_files_finder.call
61
61
  file_list_string = file_list.map { |fn| "\"#{fn}\"" }.join(' ')
62
62
  # test_loader_code = "-e \"ARGV.each{|f| require f}\"" # :direct
63
63
  option_list = ( ENV["TESTOPTS"] || ENV["TESTOPT"] || ENV["TEST_OPTS"] || '' )
@@ -727,7 +727,10 @@ public class RubyJdbcConnection extends RubyObject {
727
727
 
728
728
  private void connectImpl(final boolean forceConnection) throws SQLException {
729
729
  setConnection( forceConnection ? newConnection() : null );
730
- if ( forceConnection ) configureConnection();
730
+ if (forceConnection) {
731
+ if (getConnectionImpl() == null) throw new SQLException("Didn't get a connection. Wrong URL?");
732
+ configureConnection();
733
+ }
731
734
  }
732
735
 
733
736
  @JRubyMethod(name = "read_only?")
@@ -885,15 +888,31 @@ public class RubyJdbcConnection extends RubyObject {
885
888
  return mapQueryResult(context, connection, resultSet);
886
889
  }
887
890
 
891
+ private static String[] createStatementPk(IRubyObject pk) {
892
+ String[] statementPk;
893
+ if (pk instanceof RubyArray) {
894
+ RubyArray ary = (RubyArray) pk;
895
+ int size = ary.size();
896
+ statementPk = new String[size];
897
+ for (int i = 0; i < size; i++) {
898
+ statementPk[i] = sqlString(ary.eltInternal(i));
899
+ }
900
+ } else {
901
+ statementPk = new String[] { sqlString(pk) };
902
+ }
903
+ return statementPk;
904
+ }
905
+
888
906
  /**
889
907
  * Executes an INSERT SQL statement
890
908
  * @param context
891
909
  * @param sql
910
+ * @param pk Rails PK
892
911
  * @return ActiveRecord::Result
893
912
  * @throws SQLException
894
913
  */
895
- @JRubyMethod(name = "execute_insert", required = 1)
896
- public IRubyObject execute_insert(final ThreadContext context, final IRubyObject sql) {
914
+ @JRubyMethod(name = "execute_insert_pk", required = 2)
915
+ public IRubyObject execute_insert_pk(final ThreadContext context, final IRubyObject sql, final IRubyObject pk) {
897
916
  return withConnection(context, new Callable<IRubyObject>() {
898
917
  public IRubyObject call(final Connection connection) throws SQLException {
899
918
  Statement statement = null;
@@ -901,7 +920,13 @@ public class RubyJdbcConnection extends RubyObject {
901
920
  try {
902
921
 
903
922
  statement = createStatement(context, connection);
904
- statement.executeUpdate(query, Statement.RETURN_GENERATED_KEYS);
923
+
924
+ if (pk == context.nil || pk == context.fals || !supportsGeneratedKeys(connection)) {
925
+ statement.executeUpdate(query, Statement.RETURN_GENERATED_KEYS);
926
+ } else {
927
+ statement.executeUpdate(query, createStatementPk(pk));
928
+ }
929
+
905
930
  return mapGeneratedKeys(context, connection, statement);
906
931
 
907
932
  } catch (final SQLException e) {
@@ -914,23 +939,35 @@ public class RubyJdbcConnection extends RubyObject {
914
939
  });
915
940
  }
916
941
 
942
+ @Deprecated
943
+ @JRubyMethod(name = "execute_insert", required = 1)
944
+ public IRubyObject execute_insert(final ThreadContext context, final IRubyObject sql) {
945
+ return execute_insert_pk(context, sql, context.nil);
946
+ }
947
+
917
948
  /**
918
949
  * Executes an INSERT SQL statement using a prepared statement
919
950
  * @param context
920
951
  * @param sql
921
952
  * @param binds RubyArray of values to be bound to the query
953
+ * @param pk Rails PK
922
954
  * @return ActiveRecord::Result
923
955
  * @throws SQLException
924
956
  */
925
- @JRubyMethod(name = "execute_insert", required = 2)
926
- public IRubyObject execute_insert(final ThreadContext context, final IRubyObject sql, final IRubyObject binds) {
957
+ @JRubyMethod(name = "execute_insert_pk", required = 3)
958
+ public IRubyObject execute_insert_pk(final ThreadContext context, final IRubyObject sql, final IRubyObject binds,
959
+ final IRubyObject pk) {
927
960
  return withConnection(context, new Callable<IRubyObject>() {
928
961
  public IRubyObject call(final Connection connection) throws SQLException {
929
962
  PreparedStatement statement = null;
930
963
  final String query = sqlString(sql);
931
964
  try {
965
+ if (pk == context.nil || pk == context.fals || !supportsGeneratedKeys(connection)) {
966
+ statement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
967
+ } else {
968
+ statement = connection.prepareStatement(query, createStatementPk(pk));
969
+ }
932
970
 
933
- statement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
934
971
  setStatementParameters(context, connection, statement, (RubyArray) binds);
935
972
  statement.executeUpdate();
936
973
  return mapGeneratedKeys(context, connection, statement);
@@ -945,6 +982,12 @@ public class RubyJdbcConnection extends RubyObject {
945
982
  });
946
983
  }
947
984
 
985
+ @Deprecated
986
+ @JRubyMethod(name = "execute_insert", required = 2)
987
+ public IRubyObject execute_insert(final ThreadContext context, final IRubyObject binds, final IRubyObject sql) {
988
+ return execute_insert_pk(context, sql, binds, context.nil);
989
+ }
990
+
948
991
  /**
949
992
  * Executes an UPDATE (DELETE) SQL statement
950
993
  * @param context
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: 52.4.0
4
+ version: 52.5.1
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: 2019-11-24 00:00:00.000000000 Z
11
+ date: 2019-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement