Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import io.vertx.core.impl.logging.Logger;
import io.vertx.core.impl.logging.LoggerFactory;
import io.vertx.oracleclient.OracleException;
import io.vertx.oracleclient.impl.commands.OraclePreparedQueryCommand;
import io.vertx.oracleclient.impl.commands.OracleResponse;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.impl.RowDesc;
Expand All @@ -40,7 +39,7 @@ public class RowReader<C, R> implements Flow.Subscriber<Row>, Function<oracle.jd
private static final Logger LOG = LoggerFactory.getLogger(RowReader.class);

private final ContextInternal context;
private final List<String> types;
private final List<Class<?>> classes;
private final RowDesc description;
private final Statement resultSetStatement;

Expand All @@ -63,9 +62,9 @@ public RowReader(ContextInternal context, Collector<Row, C, R> collector, Oracle
resultSetStatement = ors.getStatement();
ResultSetMetaData metaData = ors.getMetaData();
int cols = metaData.getColumnCount();
types = new ArrayList<>(cols);
classes = new ArrayList<>(cols);
for (int i = 1; i <= cols; i++) {
types.add(metaData.getColumnClassName(i));
classes.add(getType(metaData.getColumnClassName(i)));
}
Flow.Publisher<Row> publisher = ors.publisherOracle(this);
description = OracleRowDesc.create(metaData);
Expand Down Expand Up @@ -170,24 +169,24 @@ private OracleResponse<R> createResponse() {
@Override
public Row apply(oracle.jdbc.OracleRow oracleRow) {
try {
return transform(types, description, oracleRow);
return transform(classes, description, oracleRow);
} catch (SQLException e) {
throw new OracleException(e);
}
}

private static Row transform(List<String> ors, RowDesc desc, oracle.jdbc.OracleRow or) throws SQLException {
private static Row transform(List<Class<?>> classes, RowDesc desc, oracle.jdbc.OracleRow or) throws SQLException {
Row row = new OracleRow(desc);
for (int i = 1; i <= desc.columnNames().size(); i++) {
Object res = convertSqlValue(or.getObject(i, getType(ors.get(i - 1))));
Object res = convertSqlValue(or.getObject(i, classes.get(i - 1)));
row.addValue(res);
}
return row;
}

private static Class<?> getType(String cn) {
try {
return OraclePreparedQueryCommand.class.getClassLoader().loadClass(cn);
return Class.forName(cn, true, RowReader.class.getClassLoader());
} catch (ClassNotFoundException e) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ private <T> void testDecode(TestContext ctx, String columnName, JDBCType jdbcTyp
}));
}

private void testDecodeUsingStream(TestContext ctx, String columnName, JDBCType jdbcType, Buffer expected) {
pool.getConnection().onComplete(ctx.asyncAssertSuccess(conn -> {
conn.prepare("SELECT " + columnName + " FROM binary_data_types WHERE id = 1")
.onComplete(ctx.asyncAssertSuccess(preparedStatement -> {
preparedStatement.cursor().read(10).onComplete(ctx.asyncAssertSuccess(result -> {
ctx.assertEquals(1, result.size());
Row row = result.iterator().next();
ctx.assertEquals(expected, row.get(Buffer.class, 0));
ctx.assertEquals(expected, row.get(Buffer.class, columnName));
ColumnDescriptor columnDescriptor = result.columnDescriptors().get(0);
ctx.assertEquals(jdbcType, columnDescriptor.jdbcType());
ctx.assertNotNull(columnDescriptor);
}));
}));
}));
}

@Test
public void testDecodeRawUsingStream(TestContext ctx) {
testDecodeUsingStream(ctx, "test_raw", JDBCType.VARBINARY, Buffer.buffer("See you space cowboy..."));
}

@Test
public void testEncodeNull(TestContext ctx) {
pool
Expand Down