activerecord-jdbc-adapter 52.1-java → 52.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +34 -15
  3. data/Gemfile +1 -2
  4. data/README.md +10 -3
  5. data/lib/arjdbc/abstract/core.rb +12 -2
  6. data/lib/arjdbc/abstract/database_statements.rb +1 -1
  7. data/lib/arjdbc/abstract/statement_cache.rb +4 -4
  8. data/lib/arjdbc/db2/adapter.rb +68 -60
  9. data/lib/arjdbc/db2/as400.rb +12 -0
  10. data/lib/arjdbc/db2/column.rb +3 -0
  11. data/lib/arjdbc/db2/connection_methods.rb +4 -0
  12. data/lib/arjdbc/jdbc.rb +3 -0
  13. data/lib/arjdbc/jdbc/adapter.rb +0 -6
  14. data/lib/arjdbc/jdbc/column.rb +4 -2
  15. data/lib/arjdbc/mysql/adapter.rb +8 -0
  16. data/lib/arjdbc/postgresql/adapter.rb +5 -72
  17. data/lib/arjdbc/postgresql/oid_types.rb +82 -14
  18. data/lib/arjdbc/version.rb +1 -1
  19. data/rakelib/rails.rake +4 -3
  20. data/src/java/arjdbc/ArJdbcModule.java +5 -15
  21. data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +2 -2
  22. data/src/java/arjdbc/jdbc/ConnectionFactory.java +0 -87
  23. data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +0 -1
  24. data/src/java/arjdbc/jdbc/RubyConnectionFactory.java +61 -0
  25. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +46 -18
  26. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +2 -2
  27. data/src/java/arjdbc/postgresql/PgDateTimeUtils.java +52 -0
  28. data/src/java/arjdbc/postgresql/PostgreSQLResult.java +90 -17
  29. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +68 -49
  30. data/src/java/arjdbc/util/DateTimeUtils.java +119 -0
  31. data/src/java/arjdbc/util/PG.java +8 -0
  32. data/src/java/arjdbc/util/QuotingUtils.java +6 -7
  33. metadata +6 -4
  34. data/src/java/arjdbc/postgresql/PgResultSetMetaDataWrapper.java +0 -23
@@ -28,6 +28,7 @@ import java.sql.Time;
28
28
  import java.sql.Timestamp;
29
29
  import java.util.TimeZone;
30
30
 
31
+ import org.joda.time.Chronology;
31
32
  import org.joda.time.DateTime;
32
33
  import org.joda.time.DateTimeZone;
33
34
  import org.joda.time.chrono.GJChronology;
@@ -41,6 +42,7 @@ import org.jruby.runtime.Block;
41
42
  import org.jruby.runtime.ThreadContext;
42
43
  import org.jruby.runtime.builtin.IRubyObject;
43
44
  import org.jruby.util.ByteList;
45
+ import org.jruby.util.TypeConverter;
44
46
 
45
47
  import static arjdbc.util.StringHelper.decByte;
46
48
 
@@ -49,6 +51,17 @@ import static arjdbc.util.StringHelper.decByte;
49
51
  * @author kares
50
52
  */
51
53
  public abstract class DateTimeUtils {
54
+ public static RubyTime toTime(final ThreadContext context, final IRubyObject value) {
55
+ if (!(value instanceof RubyTime)) { // unlikely
56
+ return (RubyTime) TypeConverter.convertToTypeWithCheck(value, context.runtime.getTime(), "to_time");
57
+ }
58
+ return (RubyTime) value;
59
+ }
60
+
61
+ public static DateTime dateTimeInZone(final DateTime dateTime, final DateTimeZone zone) {
62
+ if (zone == dateTime.getZone()) return dateTime;
63
+ return dateTime.withZone(zone);
64
+ }
52
65
 
53
66
  @SuppressWarnings("deprecation")
54
67
  public static ByteList timeToString(final Time time) {
@@ -583,4 +596,110 @@ public abstract class DateTimeUtils {
583
596
  return n;
584
597
  }
585
598
 
599
+
600
+ private static final char[] ZEROS = {'0', '0', '0', '0', '0', '0'};
601
+ private static final char[][] NUMBERS;
602
+
603
+ static {
604
+ // maximum value is 60 (seconds)
605
+ NUMBERS = new char[60][];
606
+ for (int i = 0; i < NUMBERS.length; i++) {
607
+ NUMBERS[i] = ((i < 10 ? "0" : "") + Integer.toString(i)).toCharArray();
608
+ }
609
+ }
610
+
611
+ /**
612
+ * Converts a ruby timestamp to a java string, optionally with timezone and timezone adjustment
613
+ * @param context
614
+ * @param value the ruby value, typically a Time
615
+ * @param zone DateTimeZone to adjust to, optional
616
+ * @param withZone include timezone in the string?
617
+ * @return timestamp as string
618
+ */
619
+ public static String timestampTimeToString(final ThreadContext context,
620
+ final IRubyObject value, DateTimeZone zone, boolean withZone) {
621
+ RubyTime timeValue = toTime(context, value);
622
+ DateTime dt = timeValue.getDateTime();
623
+
624
+ StringBuilder sb = new StringBuilder(36);
625
+
626
+ int year = dt.getYear();
627
+ if (year <= 0) {
628
+ year--;
629
+ } else if (zone != null) {
630
+ dt = dateTimeInZone(dt, zone);
631
+ year = dt.getYear();
632
+ }
633
+
634
+ Chronology chrono = dt.getChronology();
635
+ long millis = dt.getMillis();
636
+
637
+ // always use 4 digits for year to avoid short dates being misinterpreted
638
+ sb.append(Math.abs(year));
639
+ int lead = 4 - sb.length();
640
+ if (lead > 0) sb.insert(0, ZEROS, 0, lead);
641
+ sb.append('-');
642
+ sb.append(NUMBERS[chrono.monthOfYear().get(millis)]);
643
+ sb.append('-');
644
+ sb.append(NUMBERS[chrono.dayOfMonth().get(millis)]);
645
+ if (year < 0) sb.append(" BC");
646
+ sb.append(' ');
647
+
648
+ appendTime(sb, chrono, millis, (int) timeValue.getUSec(), withZone);
649
+
650
+ return sb.toString();
651
+ }
652
+
653
+ /**
654
+ * Converts a ruby time to a java string, optionally with timezone and timezone adjustment
655
+ * @param context
656
+ * @param value the ruby value, typically a Time
657
+ * @param zone DateTimeZone to adjust to, optional
658
+ * @param withZone include timezone in the string?
659
+ * @return time as string
660
+ */
661
+ public static String timeString(final ThreadContext context,
662
+ final IRubyObject value, DateTimeZone zone, boolean withZone) {
663
+ StringBuilder sb = new StringBuilder(21);
664
+ RubyTime timeValue = toTime(context, value);
665
+ DateTime dt = timeValue.getDateTime();
666
+ if (zone != null) dt = dateTimeInZone(dt, zone);
667
+
668
+ appendTime(sb, dt.getChronology(), dt.getMillis(), (int) timeValue.getUSec(), withZone);
669
+ return sb.toString();
670
+ }
671
+
672
+ private static void appendTime(StringBuilder sb, Chronology chrono,
673
+ long millis, int usec, boolean withZone) {
674
+ sb.append(NUMBERS[chrono.hourOfDay().get(millis)]);
675
+ sb.append(':');
676
+ sb.append(NUMBERS[chrono.minuteOfHour().get(millis)]);
677
+ sb.append(':');
678
+ sb.append(NUMBERS[chrono.secondOfMinute().get(millis)]);
679
+
680
+ // PG has microsecond resolution. Change when nanos are required
681
+ int micros = chrono.millisOfSecond().get(millis) * 1000 + usec;
682
+ if (micros > 0) {
683
+ sb.append('.');
684
+
685
+ int len = sb.length();
686
+ sb.append(micros);
687
+ int lead = 6 - (sb.length() - len);
688
+ if (lead > 0) sb.insert(len, ZEROS, 0, lead);
689
+
690
+ for (int end = sb.length() - 1; sb.charAt(end) == '0'; end--) {
691
+ sb.setLength(end);
692
+ }
693
+ }
694
+
695
+ if (withZone) {
696
+ int offset = chrono.getZone().getOffset(millis) / 1000;
697
+ int absoff = Math.abs(offset);
698
+ int hours = absoff / 3600;
699
+ int mins = (absoff - hours * 3600) / 60;
700
+
701
+ sb.append(offset < 0 ? '-' : '+');
702
+ sb.append(NUMBERS[hours]).append(':').append(NUMBERS[mins]);
703
+ }
704
+ }
586
705
  }
@@ -0,0 +1,8 @@
1
+ package arjdbc.util;
2
+
3
+ /**
4
+ * Marker interface used to point out it is used for PG emulation support (used by mini_sql and
5
+ * potentially other libraries).
6
+ */
7
+ public @interface PG {
8
+ }
@@ -52,7 +52,6 @@ public abstract class QuotingUtils {
52
52
  return quoteCharWith(context, string, value, quote, 0, 8);
53
53
  }
54
54
 
55
- @SuppressWarnings("deprecation")
56
55
  public static RubyString quoteCharWith(
57
56
  final ThreadContext context,
58
57
  final RubyString string,
@@ -72,8 +71,8 @@ public abstract class QuotingUtils {
72
71
  new byte[realSize + newOffset + newSizeDiff],
73
72
  stringBytes.getEncoding(), false
74
73
  );
75
- quotedBytes.begin = newOffset;
76
- quotedBytes.realSize = 0;
74
+ quotedBytes.setBegin(newOffset);
75
+ quotedBytes.setRealSize(0);
77
76
  }
78
77
  quotedBytes.append(bytes, appendFrom, i - appendFrom);
79
78
  quotedBytes.append(quote).append(value); // e.g. "'" => "''"
@@ -88,7 +87,6 @@ public abstract class QuotingUtils {
88
87
  return context.runtime.newString(quotedBytes);
89
88
  }
90
89
 
91
- @SuppressWarnings("deprecation")
92
90
  public static RubyString quoteCharAndDecorateWith(
93
91
  final ThreadContext context, final RubyString string,
94
92
  final char value, final char quote,
@@ -102,7 +100,7 @@ public abstract class QuotingUtils {
102
100
  final ByteList quoted = new ByteList(
103
101
  new byte[realSize + 2], string.getEncoding(), false
104
102
  );
105
- quoted.begin = 0; quoted.realSize = 0;
103
+ quoted.setRealSize(0);
106
104
  quoted.append(prefix);
107
105
  quoted.append(str.unsafeBytes(), str.getBegin(), realSize);
108
106
  quoted.append(suffix);
@@ -110,8 +108,9 @@ public abstract class QuotingUtils {
110
108
  }
111
109
  // we got a new string with a reserve of 1 byte front and back :
112
110
  final ByteList quoted = quotedString.getByteList();
113
- quoted.begin = 0; // setBegin invalidates
114
- quoted.bytes[0] = prefix; quoted.realSize++;
111
+ quoted.setBegin(0);
112
+ quoted.unsafeBytes()[0] = prefix;
113
+ quoted.setRealSize(quoted.getRealSize() + 1);
115
114
  quoted.append(suffix);
116
115
  return quotedString;
117
116
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-jdbc-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: '52.1'
4
+ version: '52.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-09-13 00:00:00.000000000 Z
11
+ date: 2019-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -198,6 +198,7 @@ files:
198
198
  - src/java/arjdbc/jdbc/DriverConnectionFactory.java
199
199
  - src/java/arjdbc/jdbc/DriverWrapper.java
200
200
  - src/java/arjdbc/jdbc/JdbcResult.java
201
+ - src/java/arjdbc/jdbc/RubyConnectionFactory.java
201
202
  - src/java/arjdbc/jdbc/RubyJdbcConnection.java
202
203
  - src/java/arjdbc/mssql/MSSQLModule.java
203
204
  - src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java
@@ -206,7 +207,7 @@ files:
206
207
  - src/java/arjdbc/oracle/OracleModule.java
207
208
  - src/java/arjdbc/oracle/OracleRubyJdbcConnection.java
208
209
  - src/java/arjdbc/postgresql/ByteaUtils.java
209
- - src/java/arjdbc/postgresql/PgResultSetMetaDataWrapper.java
210
+ - src/java/arjdbc/postgresql/PgDateTimeUtils.java
210
211
  - src/java/arjdbc/postgresql/PostgreSQLModule.java
211
212
  - src/java/arjdbc/postgresql/PostgreSQLResult.java
212
213
  - src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java
@@ -215,6 +216,7 @@ files:
215
216
  - src/java/arjdbc/util/CallResultSet.java
216
217
  - src/java/arjdbc/util/DateTimeUtils.java
217
218
  - src/java/arjdbc/util/ObjectSupport.java
219
+ - src/java/arjdbc/util/PG.java
218
220
  - src/java/arjdbc/util/QuotingUtils.java
219
221
  - src/java/arjdbc/util/StringCache.java
220
222
  - src/java/arjdbc/util/StringHelper.java
@@ -243,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
245
  version: '0'
244
246
  requirements: []
245
247
  rubyforge_project:
246
- rubygems_version: 2.6.14.1
248
+ rubygems_version: 2.7.9
247
249
  signing_key:
248
250
  specification_version: 4
249
251
  summary: JDBC adapter for ActiveRecord, for use within JRuby on Rails.
@@ -1,23 +0,0 @@
1
- /*
2
- * A class to loosen restrictions on the PgResultSetMetaData class,
3
- * we need to be able to get the field and the method is currently set to "package".
4
- */
5
- package org.postgresql.jdbc;
6
-
7
- import java.sql.SQLException;
8
- import org.postgresql.core.BaseConnection;
9
- import org.postgresql.core.Field;
10
- import org.postgresql.jdbc.PgResultSetMetaData;
11
-
12
- public class PgResultSetMetaDataWrapper {
13
-
14
- private final PgResultSetMetaData metaData;
15
-
16
- public PgResultSetMetaDataWrapper(PgResultSetMetaData metaData) {
17
- this.metaData = metaData;
18
- }
19
-
20
- public Field getField(int i) throws SQLException {
21
- return this.metaData.getField(i);
22
- }
23
- }