use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.
the class NumericTypesSimpleCodecTest method testDecodeNumberArray.
protected void testDecodeNumberArray(TestContext ctx, String arrayData, String columnName, Number... value) {
Async async = ctx.async();
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
conn.query("SELECT " + arrayData + " \"" + columnName + "\"").execute(ctx.asyncAssertSuccess(result -> {
ctx.assertEquals(1, result.size());
Row row = result.iterator().next();
ColumnChecker.checkColumn(0, columnName).returns(Tuple::getValue, Row::getValue, value).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, new Short[] { value[0].shortValue() }).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, new Integer[] { value[0].intValue() }).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, new Long[] { value[0].longValue() }).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, new Float[] { value[0].floatValue() }).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, new Double[] { value[0].doubleValue() }).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, new Numeric[] { Numeric.create(value[0]) }).forRow(row);
async.complete();
}));
}));
}
use of io.vertx.sqlclient.data.Numeric in project vertx-sql-client by eclipse-vertx.
the class NumericTypesSimpleCodecTest method testDecodeEmptyArray.
@Test
public void testDecodeEmptyArray(TestContext ctx) {
Async async = ctx.async();
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
// The extra column makes sure that reading the array remains confined in the value since we are doing
// parsing of the array value
conn.query("SELECT '{}'::bigint[] \"array\", 1 \"Extra\"").execute(ctx.asyncAssertSuccess(result -> {
ColumnChecker.checkColumn(0, "array").returns(Tuple::getValue, Row::getValue, (Object[]) new Long[0]).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, (Object[]) new Short[0]).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, (Object[]) new Integer[0]).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, (Object[]) new Long[0]).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, (Object[]) new Float[0]).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, (Object[]) new Double[0]).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, (Object[]) new Numeric[0]).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 testEncodeFloatArray.
@Test
public void testEncodeFloatArray(TestContext ctx) {
Async async = ctx.async();
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
conn.prepare("UPDATE \"ArrayDataType\" SET \"Float\" = $1 WHERE \"id\" = $2 RETURNING \"Float\"", ctx.asyncAssertSuccess(p -> {
p.query().execute(Tuple.tuple().addArrayOfFloat(new Float[] { 5.2f, 5.3f, 5.4f }).addInteger(2), ctx.asyncAssertSuccess(result -> {
ColumnChecker.checkColumn(0, "Float").returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new float[] { 5.2f, 5.3f, 5.4f })).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[] { (short) 5.2f, (short) 5.3f, (short) 5.4f })).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, ColumnChecker.toObjectArray(new int[] { (int) 5.2f, (int) 5.3f, (int) 5.4f })).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, ColumnChecker.toObjectArray(new long[] { (long) 5.2f, (long) 5.3f, (long) 5.4f })).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, ColumnChecker.toObjectArray(new float[] { 5.2f, 5.3f, 5.4f })).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, ColumnChecker.toObjectArray(new double[] { (double) 5.2f, (double) 5.3f, (double) 5.4f })).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, ColumnChecker.toObjectArray(new Numeric[] { Numeric.create(5.2f), Numeric.create(5.3f), Numeric.create(5.4f) })).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 testDecodeFloatArray.
@Test
public void testDecodeFloatArray(TestContext ctx) {
Async async = ctx.async();
PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
conn.prepare("SELECT \"Float\" FROM \"ArrayDataType\" WHERE \"id\" = $1", ctx.asyncAssertSuccess(p -> {
p.query().execute(Tuple.tuple().addInteger(1), ctx.asyncAssertSuccess(result -> {
ColumnChecker.checkColumn(0, "Float").returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new float[] { 4.1f })).returns(Tuple::getArrayOfShorts, Row::getArrayOfShorts, ColumnChecker.toObjectArray(new short[] { (short) 4.1f })).returns(Tuple::getArrayOfIntegers, Row::getArrayOfIntegers, ColumnChecker.toObjectArray(new int[] { (int) 4.1f })).returns(Tuple::getArrayOfLongs, Row::getArrayOfLongs, ColumnChecker.toObjectArray(new long[] { (long) 4.1f })).returns(Tuple::getArrayOfFloats, Row::getArrayOfFloats, ColumnChecker.toObjectArray(new float[] { 4.1f })).returns(Tuple::getArrayOfDoubles, Row::getArrayOfDoubles, ColumnChecker.toObjectArray(new double[] { (double) 4.1f })).returns(Tuple::getArrayOfNumerics, Row::getArrayOfNumerics, ColumnChecker.toObjectArray(new Numeric[] { Numeric.create(4.1f) })).forRow(result.iterator().next());
async.complete();
}));
}));
}));
}
use of io.vertx.sqlclient.data.Numeric in project Mycat2 by MyCATApache.
the class BaseRowObservable method getObjects.
@NotNull
@SneakyThrows
public static Object[] getObjects(Row row, MycatRowMetaData metaData) {
Object[] objects = new Object[metaData.getColumnCount()];
for (int columnIndex = 0; columnIndex < objects.length; columnIndex++) {
int columnType = metaData.getColumnType(columnIndex);
Object value = null;
switch(columnType) {
case BIT:
case BOOLEAN:
{
value = row.getValue(columnIndex);
if (value == null) {
break;
}
if (value instanceof Boolean) {
break;
}
if (value instanceof Number) {
value = MycatValueFactory.BOOLEAN_VALUE_FACTORY.createFromLong(((Number) value).longValue());
break;
}
throw new UnsupportedOperationException("unsupport type:" + value);
}
case TINYINT:
case SMALLINT:
case INTEGER:
case BIGINT:
{
Numeric numeric = row.getNumeric(columnIndex);
if (numeric == null) {
value = null;
} else {
value = MycatValueFactory.LONG_VALUE_FACTORY.createFromLong(numeric.longValue());
}
break;
}
case FLOAT:
case REAL:
case DOUBLE:
{
Numeric numeric = row.getNumeric(columnIndex);
if (numeric == null) {
value = null;
} else {
value = numeric.doubleValue();
}
break;
}
case DECIMAL:
case NUMERIC:
{
value = row.getBigDecimal(columnIndex);
break;
}
case NCHAR:
case NVARCHAR:
case LONGNVARCHAR:
case LONGVARCHAR:
case VARCHAR:
case CHAR:
{
value = row.getValue(columnIndex);
if (value instanceof String) {
} else if (value instanceof byte[]) {
value = new String((byte[]) value);
}
break;
}
case DATE:
{
value = row.getValue(columnIndex);
if (value == null) {
} else if (value instanceof LocalDate) {
} else if (value instanceof java.sql.Date) {
value = ((Date) value).toLocalDate();
} else if (value instanceof java.util.Date) {
java.util.Date value1 = (java.util.Date) value;
value = LocalDate.of(value1.getYear() + 1900, value1.getMonth() + 1, value1.getDate());
} else if (value instanceof String) {
value = LocalDate.parse((String) value);
} else {
throw new UnsupportedOperationException("unsupport type:" + value);
}
break;
}
case TIME_WITH_TIMEZONE:
case TIME:
{
value = row.getValue(columnIndex);
if (value == null) {
} else if (value instanceof Duration) {
} else {
String s = value.toString();
value = MycatTimeUtil.timeStringToTimeDuration(s);
}
break;
}
case TIMESTAMP_WITH_TIMEZONE:
case TIMESTAMP:
{
value = row.getValue(columnIndex);
if (value == null) {
value = null;
} else if (value instanceof LocalDateTime) {
} else if (value instanceof Timestamp) {
value = ((Timestamp) value).toLocalDateTime();
} else if (value instanceof String) {
value = MycatTimeUtil.timestampStringToTimestamp((String) value);
} else {
throw new UnsupportedOperationException("unsupport type:" + value);
}
break;
}
case NCLOB:
case CLOB:
{
value = row.getValue(columnIndex);
if (value != null && value instanceof Clob) {
Clob value1 = (Clob) value;
try {
value = (value1.getSubString(1, (int) (value1.length())));
} finally {
value1.free();
}
} else {
throw new UnsupportedOperationException("unsupport type:" + value);
}
break;
}
case BLOB:
case LONGVARBINARY:
case VARBINARY:
case BINARY:
{
value = row.getValue(columnIndex);
if (value == null) {
value = null;
} else if (value instanceof String) {
value = new ByteString(((String) value).getBytes());
} else if (value instanceof Buffer) {
value = new ByteString(((Buffer) value).getBytes());
} else if (value instanceof Blob) {
Blob value1 = (Blob) value;
try {
value = new ByteString(value1.getBytes(1, (int) (value1.length())));
} finally {
value1.free();
}
} else if (value instanceof byte[]) {
} else {
throw new UnsupportedOperationException("unsupport type:" + value);
}
break;
}
case NULL:
{
value = null;
break;
}
case ROWID:
case REF_CURSOR:
case OTHER:
case JAVA_OBJECT:
case DISTINCT:
case STRUCT:
case ARRAY:
case REF:
case DATALINK:
default:
value = row.getValue(columnIndex);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("may be unsupported type :{}", JDBCType.valueOf(columnType));
}
}
objects[columnIndex] = value;
}
return objects;
}
Aggregations