Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ public int getLength(final T value) {
}

private static BigDecimal getNumericAsBigDecimal(final Number source) {
if (!(source instanceof BigDecimal)) {
return BigDecimalUtils.toBigDecimal(source.doubleValue());
if (source instanceof BigDecimal) {
return (BigDecimal) source;
}

return (BigDecimal) source;
if (source instanceof BigInteger) {
return new BigDecimal((BigInteger) source);
}
return BigDecimalUtils.toBigDecimal(source.doubleValue());
}

private List<Integer> digits(final BigDecimal value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.postgresql.util.PGInterval;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.UnknownHostException;
Expand Down Expand Up @@ -46,6 +47,7 @@ private static class SampleEntity {
public List<Double> col_double_array;
public String col_jsonb;
public BigDecimal col_numeric;
public BigInteger col_bignumeric;
public Interval col_interval;

public Interval get_col_interval() {
Expand Down Expand Up @@ -124,6 +126,10 @@ public BigDecimal getCol_numeric() {
return col_numeric;
}

public BigInteger getCol_bignumeric() {
return col_bignumeric;
}

}

@Override
Expand Down Expand Up @@ -159,6 +165,7 @@ public SampleEntityMapping() {
mapDoubleArray("col_double_array", SampleEntity::getCol_double_array);
mapJsonb("col_jsonb", SampleEntity::getCol_jsonb);
mapNumeric("col_numeric", SampleEntity::getCol_numeric);
mapNumeric("col_bignumeric", SampleEntity::getCol_bignumeric);
mapInterval("col_interval", SampleEntity::get_col_interval);
}
}
Expand Down Expand Up @@ -251,6 +258,32 @@ public void saveAll_numeric_Test() throws SQLException {
}
}


@Test
public void saveAll_BigNumeric_Test() throws SQLException {

// This list will be inserted.
List<SampleEntity> entities = new ArrayList<>();

// Create the Entity to insert:
SampleEntity entity = new SampleEntity();
entity.col_bignumeric = new BigInteger("999999999999999999999999999999999999");

entities.add(entity);

PgBulkInsert<SampleEntity> pgBulkInsert = new PgBulkInsert<>(new SampleEntityMapping());

pgBulkInsert.saveAll(PostgreSqlUtils.getPGConnection(connection), entities.stream());

ResultSet rs = getAll();

while (rs.next()) {
BigDecimal v = rs.getBigDecimal("col_bignumeric");

Assert.assertEquals(new BigInteger("999999999999999999999999999999999999"), v.toBigInteger());
}
}

@Test
public void saveAll_boolean_Test() throws SQLException {

Expand Down Expand Up @@ -645,7 +678,7 @@ public void saveAll_ByteArray_Test() throws SQLException {
byte byte1 = 1;
byte byte2 = 2;

entity.col_bytearray = new byte[]{ byte1, byte2 };
entity.col_bytearray = new byte[]{byte1, byte2};

entities.add(entity);

Expand Down Expand Up @@ -786,7 +819,8 @@ private boolean createTable() throws SQLException {
" col_int_array integer[], \n" +
" col_double_array double precision[], \n" +
" col_jsonb jsonb, \n" +
" col_numeric numeric(50, 20) \n" +
" col_numeric numeric(50, 20), \n" +
" col_bignumeric numeric(38) \n" +
" );";

Statement statement = connection.createStatement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void setUp() throws Exception {
schema = properties.getProperty("db.schema");

onSetUpBeforeTransaction();
connection.createStatement().execute("SET timezone='UTC'");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

connection.setAutoCommit(false); // Start the Transaction:
onSetUpInTransaction();
}
Expand Down