use of org.summerb.approaches.jdbccrud.api.dto.PaginatedList in project summerb by skarpushin.
the class EasyCrudDaoMySqlImpl method query.
@Override
public PaginatedList<TDto> query(PagerParams pagerParams, Query optionalQuery, OrderBy... orderBy) {
MapSqlParameterSource params = new MapSqlParameterSource();
String whereClause = optionalQuery == null ? "" : "WHERE " + queryToNativeSqlCompiler.buildWhereClauseAndPopulateParams(optionalQuery, params);
params.addValue("offset", pagerParams.getOffset());
params.addValue("max", pagerParams.getMax());
String query = sqlFindByCustomQuery + whereClause + buildOrderBySubclause(orderBy);
if (!PagerParams.ALL.equals(pagerParams)) {
query = query + sqlPartPaginator;
}
List<TDto> list = jdbc.query(query, params, rowMapper);
int totalResultsCount;
if (Top.is(pagerParams) || (PagerParams.ALL.equals(pagerParams) || (pagerParams.getOffset() == 0 && list.size() < pagerParams.getMax()))) {
totalResultsCount = list.size();
} else {
totalResultsCount = jdbc.queryForInt(sqlFindByCustomQueryForCount + whereClause, params);
}
return new PaginatedList<TDto>(pagerParams, list, totalResultsCount);
}
use of org.summerb.approaches.jdbccrud.api.dto.PaginatedList in project summerb by skarpushin.
the class DataSetLoaderImplTest method testLoadObjectsByIds_ExpectManyLoadByLongsNfe.
@Test(expected = GenericEntityNotFoundException.class)
public void testLoadObjectsByIds_ExpectManyLoadByLongsNfe() throws Exception {
DataSetLoaderImpl fixture = buildMockedInstance();
EasyCrudService service = Mockito.mock(EasyCrudService.class);
when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto1")).thenReturn(service);
PaginatedList mockret = new PaginatedList<>(new PagerParams(), Collections.emptyList(), 0);
when(service.query(any(PagerParams.class), any(Query.class))).thenReturn(mockret);
fixture.loadObjectsByIds(ids(1L, 2L), "dto1");
}
Aggregations