Skip to content

Commit 019f184

Browse files
committed
fix: remove numeric deprecation
1 parent a430c7f commit 019f184

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/java/arjdbc/jdbc/RubyJdbcConnection.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ protected void doInitialize(final ThreadContext context, final IRubyObject confi
562562

563563
IRubyObject jdbcFetchSize = getConfigValue(context, "jdbc_fetch_size");
564564
if (jdbcFetchSize != context.nil) {
565-
this.fetchSize = RubyNumeric.fix2int(jdbcFetchSize);
565+
this.fetchSize = RubyNumeric.num2int(jdbcFetchSize);
566566
}
567567
}
568568

@@ -1021,15 +1021,15 @@ public IRubyObject execute_query_raw(final ThreadContext context, final IRubyObj
10211021
switch (args.length) {
10221022
case 2:
10231023
if (args[1] instanceof RubyNumeric) { // (sql, max_rows)
1024-
maxRows = RubyNumeric.fix2int(args[1]);
1024+
maxRows = RubyNumeric.num2int(args[1]);
10251025
binds = null;
10261026
} else { // (sql, binds)
10271027
maxRows = 0;
10281028
binds = (RubyArray) TypeConverter.checkArrayType(context, args[1]);
10291029
}
10301030
break;
10311031
case 3: // (sql, max_rows, binds)
1032-
maxRows = RubyNumeric.fix2int(args[1]);
1032+
maxRows = RubyNumeric.num2int(args[1]);
10331033
binds = (RubyArray) TypeConverter.checkArrayType(context, args[2]);
10341034
break;
10351035
default: // (sql) 1-arg
@@ -2673,7 +2673,7 @@ else if ( value instanceof RubyNumeric ) {
26732673
statement.setLong(index, RubyNumeric.num2long(value));
26742674
}
26752675
else {
2676-
statement.setLong(index, value.convertToInteger("to_i").getLongValue());
2676+
statement.setLong(index, RubyNumeric.num2long(value.convertToInteger("to_i")));
26772677
}
26782678
}
26792679

@@ -2686,10 +2686,15 @@ protected void setBigIntegerParameter(final ThreadContext context,
26862686
setLongOrDecimalParameter(statement, index, ((RubyBignum) value).getValue());
26872687
}
26882688
else if ( value instanceof RubyFixnum ) {
2689-
statement.setLong(index, ((RubyFixnum) value).getLongValue());
2689+
statement.setLong(index, RubyNumeric.num2long(value));
26902690
}
26912691
else {
2692-
setLongOrDecimalParameter(statement, index, value.convertToInteger("to_i").getBigIntegerValue());
2692+
RubyInteger intValue = (RubyInteger) value.convertToInteger("to_i");
2693+
if (intValue instanceof RubyBignum) {
2694+
setLongOrDecimalParameter(statement, index, ((RubyBignum) intValue).getValue());
2695+
} else {
2696+
statement.setLong(index, RubyNumeric.num2long(intValue));
2697+
}
26932698
}
26942699
}
26952700

@@ -2710,10 +2715,10 @@ protected void setDoubleParameter(final ThreadContext context,
27102715
final IRubyObject attribute, final int type) throws SQLException {
27112716

27122717
if ( value instanceof RubyNumeric ) {
2713-
statement.setDouble(index, ((RubyNumeric) value).getDoubleValue());
2718+
statement.setDouble(index, RubyNumeric.num2dbl(value));
27142719
}
27152720
else {
2716-
statement.setDouble(index, value.convertToFloat().getDoubleValue());
2721+
statement.setDouble(index, RubyNumeric.num2dbl(value.convertToFloat()));
27172722
}
27182723
}
27192724

@@ -2726,10 +2731,14 @@ protected void setDecimalParameter(final ThreadContext context,
27262731
statement.setBigDecimal(index, ((RubyBigDecimal) value).getValue());
27272732
}
27282733
else if ( value instanceof RubyInteger ) {
2729-
statement.setBigDecimal(index, new BigDecimal(((RubyInteger) value).getBigIntegerValue()));
2734+
if (value instanceof RubyBignum) {
2735+
statement.setBigDecimal(index, new BigDecimal(((RubyBignum) value).getValue()));
2736+
} else {
2737+
statement.setBigDecimal(index, new BigDecimal(RubyNumeric.num2long(value)));
2738+
}
27302739
}
27312740
else if ( value instanceof RubyNumeric ) {
2732-
statement.setDouble(index, ((RubyNumeric) value).getDoubleValue());
2741+
statement.setDouble(index, RubyNumeric.num2dbl(value));
27332742
}
27342743
else { // e.g. `BigDecimal '42.00000000000000000001'`
27352744
Ruby runtime = context.runtime;
@@ -3001,7 +3010,7 @@ private String getAliveSQL(final ThreadContext context) {
30013010
protected int getAliveTimeout(final ThreadContext context) {
30023011
if ( aliveTimeout == Integer.MIN_VALUE ) {
30033012
final IRubyObject timeout = getConfigValue(context, "connection_alive_timeout");
3004-
return aliveTimeout = timeout == context.nil ? 0 : RubyInteger.fix2int(timeout);
3013+
return aliveTimeout = timeout == context.nil ? 0 : RubyNumeric.num2int(timeout);
30053014
}
30063015
return aliveTimeout;
30073016
}

0 commit comments

Comments
 (0)