use of io.r2dbc.spi.Result in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method selectOneShouldFailWithException.
@Test
void selectOneShouldFailWithException() {
MockRowMetadata metadata = MockRowMetadata.builder().columnMetadata(MockColumnMetadata.builder().name("name").javaType(String.class).build()).build();
MockResult result = MockResult.builder().row(MockRow.builder().identified(0, Object.class, "Walter").metadata(metadata).build(), MockRow.builder().identified(0, Object.class, "White").metadata(metadata).build()).build();
mockStatementFor("SELECT * FROM person", result);
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("SELECT * FROM person").map(row -> row.get(0)).one().as(StepVerifier::create).verifyError(IncorrectResultSizeDataAccessException.class);
}
use of io.r2dbc.spi.Result in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method rowsUpdatedShouldEmitSingleValue.
@Test
@SuppressWarnings("unchecked")
void rowsUpdatedShouldEmitSingleValue() {
Result result = mock(Result.class);
when(result.getRowsUpdated()).thenReturn(Mono.empty(), Mono.just(2), Flux.just(1, 2, 3));
mockStatementFor("DROP TABLE tab;", result);
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("DROP TABLE tab;").fetch().rowsUpdated().as(StepVerifier::create).expectNextCount(1).verifyComplete();
databaseClient.sql("DROP TABLE tab;").fetch().rowsUpdated().as(StepVerifier::create).expectNextCount(1).verifyComplete();
databaseClient.sql("DROP TABLE tab;").fetch().rowsUpdated().as(StepVerifier::create).expectNextCount(1).verifyComplete();
}
use of io.r2dbc.spi.Result in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method shouldApplyExecuteFunction.
@Test
void shouldApplyExecuteFunction() {
Statement statement = mockStatement();
MockResult result = mockSingleColumnResult(MockRow.builder().identified(0, Object.class, "Walter"));
DatabaseClient databaseClient = databaseClientBuilder.executeFunction(stmnt -> Mono.just(result)).build();
databaseClient.sql("SELECT").fetch().all().as(StepVerifier::create).expectNextCount(1).verifyComplete();
verifyNoInteractions(statement);
}
use of io.r2dbc.spi.Result in project jOOQ by jOOQ.
the class R2DBC method block.
@SuppressWarnings("unchecked")
static final <T> T block(Publisher<? extends T> publisher) {
Object complete = new Object();
LinkedBlockingQueue<Object> queue = new LinkedBlockingQueue<>();
publisher.subscribe(subscriber(s -> s.request(1), queue::add, queue::add, () -> queue.add(complete)));
try {
Object result = queue.take();
if (result instanceof Throwable)
throw new DataAccessException("Exception when blocking on publisher", (Throwable) result);
else if (result == complete)
return null;
else
return (T) result;
} catch (InterruptedException e) {
throw new DataAccessException("Exception when blocking on publisher", e);
}
}
Aggregations