|
21 | 21 | import java.io.InputStream;
|
22 | 22 | import java.io.Reader;
|
23 | 23 | import java.math.BigDecimal;
|
| 24 | +import java.math.RoundingMode; |
24 | 25 | import java.net.URL;
|
25 | 26 | import java.nio.charset.StandardCharsets;
|
26 | 27 | import java.sql.Array;
|
|
43 | 44 | import java.time.LocalDateTime;
|
44 | 45 | import java.time.ZoneId;
|
45 | 46 | import java.time.ZonedDateTime;
|
46 |
| -import java.util.Calendar; |
47 |
| -import java.util.GregorianCalendar; |
48 |
| -import java.util.Iterator; |
49 |
| -import java.util.List; |
50 |
| -import java.util.Map; |
51 |
| -import java.util.Optional; |
52 |
| -import java.util.TimeZone; |
| 47 | +import java.util.*; |
53 | 48 | import java.util.concurrent.atomic.AtomicBoolean;
|
54 | 49 | import java.util.concurrent.atomic.AtomicLong;
|
55 | 50 | import java.util.concurrent.atomic.AtomicReference;
|
@@ -490,21 +485,43 @@ public double getDouble(int columnIndex)
|
490 | 485 | }
|
491 | 486 | }
|
492 | 487 |
|
493 |
| - @Override |
| 488 | + /** |
| 489 | + * Retrieves a BigDecimal value from the specified column with scaling (Deprecated method) |
| 490 | + * |
| 491 | + * <p><b>Note: This method is deprecated and will be removed in a future release. |
| 492 | + * It is recommended to use the scale-free {@link #getBigDecimal(int)} method |
| 493 | + * to get the raw value and control scaling in the business layer.</b></p> |
| 494 | + * |
| 495 | + * <p><b>Migration Example:</b><br> |
| 496 | + * // Data access layer gets raw value<br> |
| 497 | + * BigDecimal rawValue = resultSet.getBigDecimal("price");<br> |
| 498 | + * // Business layer controls scaling<br> |
| 499 | + * BigDecimal scaledValue = rawValue.setScale(2, RoundingMode.HALF_UP);</p> |
| 500 | + * |
| 501 | + * @param columnIndex 1-based column index |
| 502 | + * @param scale Number of decimal places (must be ≥ 0) |
| 503 | + * @return BigDecimal value with specified scale |
| 504 | + * @throws SQLException If column value is not a valid number format or scale is invalid |
| 505 | + * |
| 506 | + * @deprecated Since JDK 1.2, scheduled for removal. Use {@link #getBigDecimal(int)} |
| 507 | + * with business layer scaling instead. |
| 508 | + */ |
| 509 | + @Override |
| 510 | + @Deprecated |
494 | 511 | public BigDecimal getBigDecimal(int columnIndex, int scale)
|
495 | 512 | throws SQLException {
|
496 | 513 | Object value = column(columnIndex);
|
497 |
| - if (value == null) { |
| 514 | + if (Objects.isNull(value)) { |
498 | 515 | return null;
|
499 | 516 | }
|
500 | 517 | try {
|
501 | 518 | BigDecimal bigDecimal = (BigDecimal) value;
|
502 |
| - return bigDecimal.setScale(scale, BigDecimal.ROUND_HALF_UP); |
| 519 | + return bigDecimal.setScale(scale, RoundingMode.HALF_UP); |
503 | 520 | } catch (ClassCastException e) {
|
504 | 521 | // try to parse bigDecimal
|
505 | 522 | try {
|
506 | 523 | BigDecimal bigDecimal = new BigDecimal(value.toString());
|
507 |
| - return bigDecimal.setScale(scale, BigDecimal.ROUND_HALF_UP); |
| 524 | + return bigDecimal.setScale(scale, RoundingMode.HALF_UP); |
508 | 525 | } catch (NumberFormatException ex) {
|
509 | 526 | throw new SQLException("Value at columnIndex " + columnIndex + " is not a valid BigDecimal.");
|
510 | 527 | }
|
@@ -601,6 +618,7 @@ public InputStream getAsciiStream(int columnIndex)
|
601 | 618 | }
|
602 | 619 |
|
603 | 620 | @Override
|
| 621 | + @Deprecated |
604 | 622 | public InputStream getUnicodeStream(int columnIndex)
|
605 | 623 | throws SQLException {
|
606 | 624 | throw new SQLFeatureNotSupportedException("getUnicodeStream");
|
@@ -678,7 +696,29 @@ public double getDouble(String columnLabel)
|
678 | 696 | return getDouble(columnIndex(columnLabel));
|
679 | 697 | }
|
680 | 698 |
|
681 |
| - @Override |
| 699 | + /** |
| 700 | + * Retrieves a BigDecimal value from the specified column by name with scaling (Deprecated method) |
| 701 | + * |
| 702 | + * <p><strong>Deprecation Notice:</strong><br> |
| 703 | + * This method is scheduled for removal in a future release. The scaling operation should be |
| 704 | + * performed in the business layer rather than during data retrieval.</p> |
| 705 | + * |
| 706 | + * <p><b>Migration Example:</b><br> |
| 707 | + * // Data access layer gets raw value<br> |
| 708 | + * BigDecimal rawValue = getBigDecimal(columnLabel);<br> |
| 709 | + * // Business layer controls scaling<br> |
| 710 | + * BigDecimal scaledValue = rawValue.setScale(desiredScale, RoundingMode.HALF_UP);</p> |
| 711 | + * |
| 712 | + * @param columnLabel the column name label (case sensitivity depends on database) |
| 713 | + * @param scale the number of digits after the decimal point (must be ≥ 0) |
| 714 | + * @return the column value as BigDecimal with specified scale, or null if the value is SQL NULL |
| 715 | + * @throws SQLException if columnLabel is invalid or scale is invalid |
| 716 | + * |
| 717 | + * @deprecated As of JDK 1.2, replaced by {@link #getBigDecimal(String)} combined with |
| 718 | + * explicit scaling in business logic. Scheduled for removal in a future release. |
| 719 | + */ |
| 720 | + @Override |
| 721 | + @Deprecated |
682 | 722 | public BigDecimal getBigDecimal(String columnLabel, int scale)
|
683 | 723 | throws SQLException {
|
684 | 724 | return getBigDecimal(columnIndex(columnLabel), scale);
|
@@ -715,6 +755,7 @@ public InputStream getAsciiStream(String columnLabel)
|
715 | 755 | }
|
716 | 756 |
|
717 | 757 | @Override
|
| 758 | + @Deprecated |
718 | 759 | public InputStream getUnicodeStream(String columnLabel)
|
719 | 760 | throws SQLException {
|
720 | 761 | throw new SQLFeatureNotSupportedException("getUnicodeStream");
|
@@ -789,7 +830,6 @@ public BigDecimal getBigDecimal(int columnIndex)
|
789 | 830 | if (value == null) {
|
790 | 831 | return null;
|
791 | 832 | }
|
792 |
| - |
793 | 833 | return parseBigDecimal(String.valueOf(value));
|
794 | 834 | }
|
795 | 835 |
|
|
0 commit comments