Search in sources :

Example 1 with Numeric

use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.

the class NumericTypesExtendedCodecTest method testEncodeIntArray.

@Test
public void testEncodeIntArray(TestContext ctx) {
    Async async = ctx.async();
    PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
        conn.prepare("UPDATE \"ArrayDataType\" SET \"Integer\" = $1  WHERE \"id\" = $2 RETURNING \"Integer\"", ctx.asyncAssertSuccess(p -> {
            p.query().execute(Tuple.tuple().addArrayOfInteger(new Integer[] { 3, 4, 5, 6 }).addInteger(2), ctx.asyncAssertSuccess(result -> {
                ColumnChecker.checkColumn(0, "Integer").returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new int[] { 3, 4, 5, 6 })).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[] { 3, 4, 5, 6 })).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, ColumnChecker.toObjectArray(new int[] { 3, 4, 5, 6 })).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, ColumnChecker.toObjectArray(new long[] { 3, 4, 5, 6 })).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, ColumnChecker.toObjectArray(new float[] { 3, 4, 5, 6 })).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, ColumnChecker.toObjectArray(new double[] { 3, 4, 5, 6 })).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, ColumnChecker.toObjectArray(new Numeric[] { Numeric.create(3), Numeric.create(4), Numeric.create(5), Numeric.create(6) })).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 2 with Numeric

use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.

the class NumericTypesExtendedCodecTest method testEncodeShortArray.

@Test
public void testEncodeShortArray(TestContext ctx) {
    Async async = ctx.async();
    PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
        conn.prepare("UPDATE \"ArrayDataType\" SET \"Short\" = $1  WHERE \"id\" = $2 RETURNING \"Short\"", ctx.asyncAssertSuccess(p -> {
            p.query().execute(Tuple.tuple().addArrayOfShort(new Short[] { 2, 3, 4 }).addInteger(2), ctx.asyncAssertSuccess(result -> {
                ColumnChecker.checkColumn(0, "Short").returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new short[] { 2, 3, 4 })).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[] { 2, 3, 4 })).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, ColumnChecker.toObjectArray(new int[] { 2, 3, 4 })).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, ColumnChecker.toObjectArray(new long[] { 2, 3, 4 })).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, ColumnChecker.toObjectArray(new float[] { 2, 3, 4 })).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, ColumnChecker.toObjectArray(new double[] { 2, 3, 4 })).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, ColumnChecker.toObjectArray(new Numeric[] { Numeric.create(2), Numeric.create(3), Numeric.create(4) })).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 3 with Numeric

use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.

the class NumericTypesExtendedCodecTest method testDecodeNumericArray.

@Test
public void testDecodeNumericArray(TestContext ctx) {
    Async async = ctx.async();
    PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
        conn.prepare("SELECT \"Numeric\" FROM \"ArrayDataType\" WHERE \"id\" = $1", ctx.asyncAssertSuccess(p -> {
            p.query().execute(Tuple.tuple().addInteger(1), ctx.asyncAssertSuccess(result -> {
                Numeric[] expected = { Numeric.create(0), Numeric.create(1), Numeric.create(2), Numeric.create(3) };
                ColumnChecker.checkColumn(0, "Numeric").returns(Tuple::getValue, Row::getValue, expected).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, new Short[] { 0, 1, 2, 3 }).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, new Integer[] { 0, 1, 2, 3 }).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, new Long[] { 0L, 1L, 2L, 3L }).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, new Float[] { 0f, 1f, 2f, 3f }).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, new Double[] { 0D, 1D, 2D, 3D }).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, new Numeric[] { Numeric.create(0), Numeric.create(1), Numeric.create(2), Numeric.create(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) Async(io.vertx.ext.unit.Async) Row(io.vertx.sqlclient.Row) Tuple(io.vertx.sqlclient.Tuple) Test(org.junit.Test)

Example 4 with Numeric

use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.

the class NumericTypesExtendedCodecTest method testEncodeEmptyArray.

@Test
public void testEncodeEmptyArray(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[] {}).addInteger(2), ctx.asyncAssertSuccess(result -> {
                ColumnChecker.checkColumn(0, "Double").returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new double[] {})).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[] {})).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, ColumnChecker.toObjectArray(new int[] {})).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, ColumnChecker.toObjectArray(new long[] {})).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, ColumnChecker.toObjectArray(new float[] {})).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, ColumnChecker.toObjectArray(new double[] {})).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, ColumnChecker.toObjectArray(new Numeric[] {})).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 5 with Numeric

use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.

the class NumericTypesExtendedCodecTest method testDecodeIntArray.

@Test
public void testDecodeIntArray(TestContext ctx) {
    Async async = ctx.async();
    PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
        conn.prepare("SELECT \"Integer\" FROM \"ArrayDataType\" WHERE \"id\" = $1", ctx.asyncAssertSuccess(p -> {
            p.query().execute(Tuple.tuple().addInteger(1), ctx.asyncAssertSuccess(result -> {
                ColumnChecker.checkColumn(0, "Integer").returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new int[] { 2 })).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[] { 2 })).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, ColumnChecker.toObjectArray(new int[] { 2 })).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, ColumnChecker.toObjectArray(new long[] { 2 })).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, ColumnChecker.toObjectArray(new float[] { 2 })).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, ColumnChecker.toObjectArray(new double[] { 2 })).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, ColumnChecker.toObjectArray(new Numeric[] { Numeric.create(2) })).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)

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