Search in sources :

Example 16 with Numeric

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();
            }));
        }));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) BigDecimal(java.math.BigDecimal) PgConnection(io.vertx.pgclient.PgConnection) ColumnChecker(io.vertx.sqlclient.ColumnChecker) Row(io.vertx.sqlclient.Row) Test(org.junit.Test) Numeric(io.vertx.sqlclient.data.Numeric) Tuple(io.vertx.sqlclient.Tuple) Numeric(io.vertx.sqlclient.data.Numeric) Async(io.vertx.ext.unit.Async) Row(io.vertx.sqlclient.Row) Tuple(io.vertx.sqlclient.Tuple) Test(org.junit.Test)

Example 17 with Numeric

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();
            }));
        }));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) BigDecimal(java.math.BigDecimal) PgConnection(io.vertx.pgclient.PgConnection) ColumnChecker(io.vertx.sqlclient.ColumnChecker) Row(io.vertx.sqlclient.Row) Test(org.junit.Test) Numeric(io.vertx.sqlclient.data.Numeric) Tuple(io.vertx.sqlclient.Tuple) Numeric(io.vertx.sqlclient.data.Numeric) Async(io.vertx.ext.unit.Async) Row(io.vertx.sqlclient.Row) Tuple(io.vertx.sqlclient.Tuple) Test(org.junit.Test)

Example 18 with Numeric

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();
        }));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) BigDecimal(java.math.BigDecimal) PgConnection(io.vertx.pgclient.PgConnection) ColumnChecker(io.vertx.sqlclient.ColumnChecker) Row(io.vertx.sqlclient.Row) Test(org.junit.Test) Numeric(io.vertx.sqlclient.data.Numeric) Tuple(io.vertx.sqlclient.Tuple) Numeric(io.vertx.sqlclient.data.Numeric) Async(io.vertx.ext.unit.Async) Row(io.vertx.sqlclient.Row) Tuple(io.vertx.sqlclient.Tuple) Test(org.junit.Test)

Example 19 with Numeric

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();
            }));
        }));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) BigDecimal(java.math.BigDecimal) PgConnection(io.vertx.pgclient.PgConnection) ColumnChecker(io.vertx.sqlclient.ColumnChecker) Row(io.vertx.sqlclient.Row) Test(org.junit.Test) Numeric(io.vertx.sqlclient.data.Numeric) Tuple(io.vertx.sqlclient.Tuple) Numeric(io.vertx.sqlclient.data.Numeric) Async(io.vertx.ext.unit.Async) Row(io.vertx.sqlclient.Row) Tuple(io.vertx.sqlclient.Tuple) Test(org.junit.Test)

Example 20 with Numeric

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));
}
Also used : Numeric(io.vertx.sqlclient.data.Numeric) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Aggregations

Numeric (io.vertx.sqlclient.data.Numeric)20 BigDecimal (java.math.BigDecimal)18 Test (org.junit.Test)17 Async (io.vertx.ext.unit.Async)16 TestContext (io.vertx.ext.unit.TestContext)16 PgConnection (io.vertx.pgclient.PgConnection)16 ColumnChecker (io.vertx.sqlclient.ColumnChecker)16 Row (io.vertx.sqlclient.Row)16 Tuple (io.vertx.sqlclient.Tuple)16 GenIgnore (io.vertx.codegen.annotations.GenIgnore)1 Buffer (io.vertx.core.buffer.Buffer)1 JsonObject (io.vertx.core.json.JsonObject)1 BigInteger (java.math.BigInteger)1 java.sql (java.sql)1 Duration (java.time.Duration)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 SneakyThrows (lombok.SneakyThrows)1 ByteString (org.apache.calcite.avatica.util.ByteString)1 NotNull (org.jetbrains.annotations.NotNull)1