Search in sources :

Example 1 with ListResult

use of com.redhat.service.bridge.infra.models.ListResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorDAO method findByBridgeIdAndCustomerId.

public ListResult<Processor> findByBridgeIdAndCustomerId(String bridgeId, String customerId, QueryInfo queryInfo) {
    /*
         * Unfortunately we can't rely on Panaches in-built Paging due the fetched join in our query
         * for Processor e.g. join fetch p.bridge. Instead, we simply build a list of ids to fetch and then
         * execute the join fetch as normal. So the workflow here is:
         *
         * - Count the number of Processors on a bridge. If > 0
         * - Select the ids of the Processors that need to be retrieved based on the page/size requirements
         * - Select the Processors in the list of ids, performing the fetch join of the Bridge
         */
    Parameters p = Parameters.with(Bridge.CUSTOMER_ID_PARAM, customerId).and(Processor.BRIDGE_ID_PARAM, bridgeId);
    Long processorCount = countProcessorsOnBridge(p);
    if (processorCount == 0L) {
        return new ListResult<>(emptyList(), queryInfo.getPageNumber(), processorCount);
    }
    int firstResult = getFirstResult(queryInfo.getPageNumber(), queryInfo.getPageSize());
    TypedQuery<String> idsQuery = getEntityManager().createNamedQuery("PROCESSOR.idsByBridgeIdAndCustomerId", String.class);
    addParamsToNamedQuery(p, idsQuery);
    List<String> ids = idsQuery.setMaxResults(queryInfo.getPageSize()).setFirstResult(firstResult).getResultList();
    List<Processor> processors = getEntityManager().createNamedQuery("PROCESSOR.findByIds", Processor.class).setParameter(IDS_PARAM, ids).getResultList();
    return new ListResult<>(processors, queryInfo.getPageNumber(), processorCount);
}
Also used : ListResult(com.redhat.service.bridge.infra.models.ListResult) Parameters(io.quarkus.panache.common.Parameters) Processor(com.redhat.service.bridge.manager.models.Processor)

Example 2 with ListResult

use of com.redhat.service.bridge.infra.models.ListResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeDAO method findByCustomerId.

public ListResult<Bridge> findByCustomerId(String customerId, QueryInfo queryInfo) {
    Parameters parameters = Parameters.with("customerId", customerId);
    long total = find("#BRIDGE.findByCustomerId", parameters).count();
    List<Bridge> bridges = find("#BRIDGE.findByCustomerId", parameters).page(queryInfo.getPageNumber(), queryInfo.getPageSize()).list();
    return new ListResult<>(bridges, queryInfo.getPageNumber(), total);
}
Also used : ListResult(com.redhat.service.bridge.infra.models.ListResult) Parameters(io.quarkus.panache.common.Parameters) Bridge(com.redhat.service.bridge.manager.models.Bridge)

Aggregations

ListResult (com.redhat.service.bridge.infra.models.ListResult)2 Parameters (io.quarkus.panache.common.Parameters)2 Bridge (com.redhat.service.bridge.manager.models.Bridge)1 Processor (com.redhat.service.bridge.manager.models.Processor)1