use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.
the class NumericTypesExtendedCodecTest method testDecodeDoubleArray.
@Test
public void testDecodeDoubleArray(TestContext ctx) {
Async async = ctx.async();
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
conn.prepare("SELECT \"Double\" FROM \"ArrayDataType\" WHERE \"id\" = $1", ctx.asyncAssertSuccess(p -> {
p.query().execute(Tuple.tuple().addInteger(1), ctx.asyncAssertSuccess(result -> {
ColumnChecker.checkColumn(0, "Double").returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new double[] { 5.2 })).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[] { (short) 5 })).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, ColumnChecker.toObjectArray(new int[] { 5 })).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, ColumnChecker.toObjectArray(new long[] { 5L })).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, ColumnChecker.toObjectArray(new float[] { 5.2F })).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, ColumnChecker.toObjectArray(new double[] { 5.2D })).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, ColumnChecker.toObjectArray(new Numeric[] { Numeric.create(5.2D) })).forRow(result.iterator().next());
async.complete();
}));
}));
}));
}
use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.
the class NumericTypesExtendedCodecTest method testDecodeShortArray.
@Test
public void testDecodeShortArray(TestContext ctx) {
Async async = ctx.async();
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
conn.prepare("SELECT \"Short\" FROM \"ArrayDataType\" WHERE \"id\" = $1", ctx.asyncAssertSuccess(p -> {
p.query().execute(Tuple.tuple().addInteger(1), ctx.asyncAssertSuccess(result -> {
ColumnChecker.checkColumn(0, "Short").returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new short[] { 1 })).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[] { 1 })).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, ColumnChecker.toObjectArray(new int[] { 1 })).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, ColumnChecker.toObjectArray(new long[] { 1 })).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, ColumnChecker.toObjectArray(new float[] { 1 })).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, ColumnChecker.toObjectArray(new double[] { 1 })).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, ColumnChecker.toObjectArray(new Numeric[] { Numeric.create(1) })).forRow(result.iterator().next());
async.complete();
}));
}));
}));
}
use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.
the class NumericTypesSimpleCodecTest method testNumeric.
@Test
public void testNumeric(TestContext ctx) {
Async async = ctx.async();
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
conn.query("SELECT 919.999999999999999999999999999999999999::NUMERIC \"Numeric\", 'NaN'::NUMERIC \"NaN\"").execute(ctx.asyncAssertSuccess(result -> {
Numeric numeric = Numeric.parse("919.999999999999999999999999999999999999");
Numeric nan = Numeric.parse("NaN");
ctx.assertEquals(1, result.size());
Row row = result.iterator().next();
ColumnChecker.checkColumn(0, "Numeric").returns(Tuple::getValue, Row::getValue, numeric).returns(Tuple::getShort, Row::getShort, (short) 919).returns(Tuple::getInteger, Row::getInteger, 919).returns(Tuple::getLong, Row::getLong, 919L).returns(Tuple::getFloat, Row::getFloat, 920f).returns(Tuple::getDouble, Row::getDouble, 920.0).returns(Tuple::getBigDecimal, Row::getBigDecimal, numeric.bigDecimalValue()).returns(Numeric.class, numeric).forRow(row);
ColumnChecker.checkColumn(1, "NaN").returns(Tuple::getValue, Row::getValue, nan).returns(Tuple::getShort, Row::getShort, (short) 0).returns(Tuple::getInteger, Row::getInteger, 0).returns(Tuple::getLong, Row::getLong, 0L).returns(Tuple::getFloat, Row::getFloat, Float.NaN).returns(Tuple::getDouble, Row::getDouble, Double.NaN).fails(Tuple::getBigDecimal, Row::getBigDecimal).returns(Numeric.class, nan).forRow(row);
async.complete();
}));
}));
}
use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.
the class NumericTypesExtendedCodecTest method testEncodeDoubleArray.
@Test
public void testEncodeDoubleArray(TestContext ctx) {
Async async = ctx.async();
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
conn.prepare("UPDATE \"ArrayDataType\" SET \"Double\" = $1 WHERE \"id\" = $2 RETURNING \"Double\"", ctx.asyncAssertSuccess(p -> {
p.query().execute(Tuple.tuple().addArrayOfDouble(new Double[] { 6.3 }).addInteger(2), ctx.asyncAssertSuccess(result -> {
ColumnChecker.checkColumn(0, "Double").returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new double[] { 6.3 })).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[] { (short) 6.3 })).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, ColumnChecker.toObjectArray(new int[] { (int) 6.3 })).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, ColumnChecker.toObjectArray(new long[] { (long) 6.3 })).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, ColumnChecker.toObjectArray(new float[] { (float) 6.3 })).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, ColumnChecker.toObjectArray(new double[] { 6.3 })).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, ColumnChecker.toObjectArray(new Numeric[] { Numeric.create(6.3) })).forRow(result.iterator().next());
async.complete();
}));
}));
}));
}
use of io.vertx.sqlclient.data.Numeric in project jooqx by zero88.
the class BasicConverterTest method test_big_decimal.
@Test
void test_big_decimal() {
final BigDecimalConverter converter = new BigDecimalConverter();
final Numeric numeric = Numeric.create(10.987654321);
final BigDecimal bigDecimal = BigDecimal.valueOf(10.987654321);
Assertions.assertEquals(bigDecimal, converter.from(numeric));
Assertions.assertEquals(numeric, converter.to(bigDecimal));
}
Aggregations