use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.
the class NumericTest method testEqualsAndHashCode.
@Test
public void testEqualsAndHashCode() {
int intValue = random.nextInt(1000);
Numeric[] numerics = { Numeric.create(intValue), Numeric.create((short) intValue), Numeric.create((double) intValue), Numeric.create((long) intValue), Numeric.create((float) intValue), Numeric.create(new BigInteger("" + intValue)), Numeric.create(new BigDecimal("" + intValue)) };
for (Numeric l : numerics) {
for (Numeric r : numerics) {
assertEquals(l, r);
assertEquals(l.hashCode(), r.hashCode());
}
}
assertEquals(Numeric.create(Double.NaN), Numeric.create(Float.NaN));
for (Numeric l : numerics) {
assertNotSame(Numeric.NaN, l);
assertNotSame(l, Numeric.NaN);
assertNotSame(Numeric.create(Float.NaN), l);
assertNotSame(l, Numeric.create(Float.NaN));
assertNotSame(Numeric.create(Double.NaN), l);
assertNotSame(l, Numeric.create(Double.NaN));
}
}
use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.
the class Tuple method getArrayOfNumerics.
/**
* Get an array of {@link Numeric} value at {@code pos}.
*
* @param pos the column
* @return the value
*/
@GenIgnore(GenIgnore.PERMITTED_TYPE)
default Numeric[] getArrayOfNumerics(int pos) {
Object val = getValue(pos);
if (val == null) {
return null;
} else if (val instanceof Numeric[]) {
return (Numeric[]) val;
} else if (val instanceof Number[]) {
Number[] a = (Number[]) val;
int len = a.length;
Numeric[] arr = new Numeric[len];
for (int i = 0; i < len; i++) {
Number elt = a[i];
if (elt != null) {
arr[i] = Numeric.create(elt);
}
}
return arr;
} else if (val instanceof Enum[]) {
Enum<?>[] a = (Enum<?>[]) val;
int len = a.length;
Numeric[] arr = new Numeric[len];
for (int i = 0; i < len; i++) {
Enum<?> elt = a[i];
if (elt != null) {
arr[i] = Numeric.create(elt.ordinal());
}
}
return arr;
} else if (val.getClass() == Object[].class) {
Object[] array = (Object[]) val;
Numeric[] doubleArray = new Numeric[array.length];
for (int i = 0; i < array.length; i++) {
doubleArray[i] = Numeric.create((Number) array[i]);
}
return doubleArray;
} else {
throw new ClassCastException();
}
}
use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.
the class NumericTypesExtendedCodecTest method testEncodeLongArray.
@Test
public void testEncodeLongArray(TestContext ctx) {
Async async = ctx.async();
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
conn.prepare("UPDATE \"ArrayDataType\" SET \"Long\" = $1 WHERE \"id\" = $2 RETURNING \"Long\"", ctx.asyncAssertSuccess(p -> {
p.query().execute(Tuple.tuple().addArrayOfLong(new Long[] { 4L, 5L, 6L, 7L, 8L }).addInteger(2), ctx.asyncAssertSuccess(result -> {
ColumnChecker.checkColumn(0, "Long").returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new long[] { 4, 5, 6, 7, 8 })).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[] { 4, 5, 6, 7, 8 })).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, ColumnChecker.toObjectArray(new int[] { 4, 5, 6, 7, 8 })).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, ColumnChecker.toObjectArray(new long[] { 4, 5, 6, 7, 8 })).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, ColumnChecker.toObjectArray(new float[] { 4, 5, 6, 7, 8 })).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, ColumnChecker.toObjectArray(new double[] { 4, 5, 6, 7, 8 })).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, ColumnChecker.toObjectArray(new Numeric[] { Numeric.create(4), Numeric.create(5), Numeric.create(6), Numeric.create(7), Numeric.create(8) })).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 testEncodeNumericArray.
@Test
public void testEncodeNumericArray(TestContext ctx) {
Async async = ctx.async();
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
conn.prepare("UPDATE \"ArrayDataType\" SET \"Numeric\" = $1 WHERE \"id\" = $2 RETURNING \"Numeric\"", ctx.asyncAssertSuccess(p -> {
Numeric[] expected = { Numeric.create(0), Numeric.create(10000) };
p.query().execute(Tuple.tuple().addValue(expected).addInteger(2), ctx.asyncAssertSuccess(result -> {
ColumnChecker.checkColumn(0, "Numeric").returns(Tuple::getValue, Row::getValue, expected).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, new Short[] { expected[0].shortValue(), expected[1].shortValue() }).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, new Integer[] { expected[0].intValue(), expected[1].intValue() }).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, new Long[] { expected[0].longValue(), expected[1].longValue() }).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, new Float[] { expected[0].floatValue(), expected[1].floatValue() }).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, new Double[] { expected[0].doubleValue(), expected[1].doubleValue() }).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, new Numeric[] { Numeric.create(expected[0]), Numeric.create(expected[1]) }).returns(Numeric.class, expected).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 testDecodeLongArray.
@Test
public void testDecodeLongArray(TestContext ctx) {
Async async = ctx.async();
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
conn.prepare("SELECT \"Long\" FROM \"ArrayDataType\" WHERE \"id\" = $1", ctx.asyncAssertSuccess(p -> {
p.query().execute(Tuple.tuple().addInteger(1), ctx.asyncAssertSuccess(result -> {
ColumnChecker.checkColumn(0, "Long").returns(Tuple::getValue, Row::getValue, new Long[] { 3L }).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, new Short[] { (short) 3 }).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, new Integer[] { 3 }).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, new Long[] { 3L }).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, new Float[] { 3F }).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, new Double[] { 3D }).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, ColumnChecker.toObjectArray(new Numeric[] { Numeric.create(3) })).forRow(result.iterator().next());
async.complete();
}));
}));
}));
}
Aggregations