Search in sources :

Example 6 with PaginatedList

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);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) PaginatedList(org.summerb.approaches.jdbccrud.api.dto.PaginatedList)

Example 7 with PaginatedList

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");
}
Also used : DataSetLoaderImpl(org.summerb.approaches.jdbccrud.impl.relations.DataSetLoaderImpl) EasyCrudService(org.summerb.approaches.jdbccrud.api.EasyCrudService) Query(org.summerb.approaches.jdbccrud.api.query.Query) PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) PaginatedList(org.summerb.approaches.jdbccrud.api.dto.PaginatedList) Test(org.junit.Test)

Aggregations

PaginatedList (org.summerb.approaches.jdbccrud.api.dto.PaginatedList)7 PagerParams (org.summerb.approaches.jdbccrud.api.dto.PagerParams)6 Test (org.junit.Test)4 EasyCrudService (org.summerb.approaches.jdbccrud.api.EasyCrudService)3 Query (org.summerb.approaches.jdbccrud.api.query.Query)3 DataSetLoaderImpl (org.summerb.approaches.jdbccrud.impl.relations.DataSetLoaderImpl)3 TestDto1 (integr.org.summerb.jdbccrud.TestDto1)2 HasId (org.summerb.approaches.jdbccrud.api.dto.HasId)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 AliasEntry (org.summerb.microservices.properties.impl.dao.AliasEntry)1 StringIdAliasDao (org.summerb.microservices.properties.impl.dao.StringIdAliasDao)1 AuthToken (org.summerb.microservices.users.api.dto.AuthToken)1 User (org.summerb.microservices.users.api.dto.User)1 AuthTokenDao (org.summerb.microservices.users.impl.dao.AuthTokenDao)1