mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Add support for findEach() on SqlQuery with RowMapper and scalar result
This commit is contained in:
@@ -493,6 +493,10 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void findSingleAttributeEach(SpiSqlQuery query, Class<T> cls, Consumer<T> consumer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T findOneMapper(SpiSqlQuery query, RowMapper<T> mapper) {
|
||||
return null;
|
||||
|
||||
@@ -39,6 +39,28 @@ public class SqlQueryTests extends BaseTestCase {
|
||||
assertThat(lineAmounts).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findSingleAttributeEach_decimal() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
String sql = "select (unit_price * order_qty) from o_order_detail where unit_price > ? order by (unit_price * order_qty) desc";
|
||||
|
||||
AtomicLong counter = new AtomicLong();
|
||||
AtomicLong inc = new AtomicLong();
|
||||
|
||||
DB.sqlQuery(sql)
|
||||
.setParameter(3)
|
||||
.mapToScalar(BigDecimal.class)
|
||||
.findEach(val -> {
|
||||
counter.incrementAndGet();
|
||||
inc.addAndGet(val.longValue());
|
||||
});
|
||||
|
||||
assertThat(inc.get()).isGreaterThan(counter.get());
|
||||
assertThat(counter.get()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findSingleDecimal() {
|
||||
|
||||
@@ -141,6 +163,24 @@ public class SqlQueryTests extends BaseTestCase {
|
||||
|
||||
private static final CustMapper CUST_MAPPER = new CustMapper();
|
||||
|
||||
@Test
|
||||
public void findEach_mapper() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
String sql = "select id, name, status from o_customer where name is not null";
|
||||
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
DB.sqlQuery(sql)
|
||||
.mapTo(CUST_MAPPER)
|
||||
.findEach(custDto -> {
|
||||
counter.incrementAndGet();
|
||||
assertThat(custDto.name).isNotNull();
|
||||
});
|
||||
|
||||
assertThat(counter.get()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOne_mapper() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user