downgrade BigDecimal to Long automatically

This commit is contained in:
Jörg Prante 2025-03-19 17:07:21 +01:00
parent fdc3fcd3e2
commit 1a8cf5d8da
2 changed files with 6 additions and 2 deletions
gradle.properties
jdbc-query/src/main/java/org/xbib/jdbc/query

View file

@ -1,3 +1,3 @@
group = org.xbib
name = database
version = 2.5.0
version = 2.6.0

View file

@ -548,7 +548,7 @@ public class DatabaseImpl implements Database {
case "java.sql.Time" -> row.add(rows.getLocalTimeOrNull(i + 1));
case "oracle.sql.TIMESTAMPTZ" -> row.add(rows.getOffsetDateTimeOrNull(i + 1));
case "java.sql.Timestamp", "oracle.sql.TIMESTAMP" -> row.add(rows.getLocalDateTimeOrNull(i + 1));
case "java.math.BigDecimal" -> row.add(rows.getBigDecimalOrNull(i + 1));
case "java.math.BigDecimal" -> row.add(maybeLong(rows.getBigDecimalOrNull(i + 1)));
default -> throw new DatabaseException("unexpected column class name: " + className);
}
}
@ -556,6 +556,10 @@ public class DatabaseImpl implements Database {
return row;
}
private Number maybeLong(BigDecimal bigDecimal) {
return bigDecimal != null && bigDecimal.scale() <= 0 ? bigDecimal.longValue() : bigDecimal;
}
@Override
public void writeQueue(String table, String channel, String data, Consumer<Long> consumer) throws SQLException {
writeNextIntoQueue(connection, table, channel, data, consumer);