Search in sources :

Example 1 with Parameters

use of io.quarkus.panache.common.Parameters 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 Parameters

use of io.quarkus.panache.common.Parameters in project apicurio-registry by Apicurio.

the class TenantsResourceImpl method getTenants.

@Override
public RegistryTenantList getTenants(@QueryParam("status") String status, @QueryParam("offset") @Min(0) Integer offset, @QueryParam("limit") @Min(1) @Max(500) Integer limit, @QueryParam("order") SortOrder order, @QueryParam("orderby") SortBy orderby) {
    offset = (offset != null) ? offset : 0;
    limit = (limit != null) ? limit : 20;
    order = (order != null) ? order : SortOrder.asc;
    orderby = (orderby != null) ? orderby : SortBy.tenantId;
    Sort sort = Sort.by(orderby.value()).direction(order == SortOrder.asc ? Direction.Ascending : Direction.Descending);
    String query = "";
    Parameters parameters = new Parameters();
    if (status != null) {
        query += "status = :status";
        parameters = parameters.and("status", status);
    }
    List<RegistryTenantDto> items = tenantsRepository.queryTenants(query, sort, parameters, offset, limit);
    Long total = tenantsRepository.count(query, parameters);
    RegistryTenantList list = new RegistryTenantList();
    list.setItems(items.stream().map(RegistryTenantDto::toDatamodel).collect(Collectors.toList()));
    list.setCount(total.intValue());
    return list;
}
Also used : RegistryTenantList(io.apicurio.multitenant.api.datamodel.RegistryTenantList) Parameters(io.quarkus.panache.common.Parameters) RegistryTenantDto(io.apicurio.multitenant.storage.dto.RegistryTenantDto) Sort(io.quarkus.panache.common.Sort)

Example 3 with Parameters

use of io.quarkus.panache.common.Parameters in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorDAO method findByBridgeIdAndCustomerId.

private ListResult<Processor> findByBridgeIdAndCustomerId(String bridgeId, String customerId, QueryProcessorResourceInfo queryInfo, Set<ProcessorType> restrictTypes) {
    /*
         * 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
         */
    // We don't consider filtering here; so this could be short-cut more but the additional code doesn't really make it worthwhile
    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);
    }
    ProcessorResults results = getProcessorIds(customerId, bridgeId, queryInfo, restrictTypes);
    List<Processor> processors = find("#PROCESSOR.findByIds", Parameters.with(IDS_PARAM, results.ids)).list();
    return new ListResult<>(processors, queryInfo.getPageNumber(), results.total);
}
Also used : ListResult(com.redhat.service.smartevents.infra.models.ListResult) Parameters(io.quarkus.panache.common.Parameters) Processor(com.redhat.service.smartevents.manager.models.Processor)

Example 4 with Parameters

use of io.quarkus.panache.common.Parameters in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorDAO method getProcessorIds.

private ProcessorResults getProcessorIds(String customerId, String bridgeId, QueryProcessorResourceInfo queryInfo, Set<ProcessorType> restrictTypes) {
    Parameters parameters = Parameters.with("customerId", customerId).and("bridgeId", bridgeId);
    PanacheQuery<Processor> query = find("#PROCESSOR.findByBridgeIdAndCustomerIdNoFilter", parameters);
    // filter by name
    String filterName = queryInfo.getFilterInfo().getFilterName();
    if (Objects.nonNull(filterName)) {
        query.filter("byName", Parameters.with("name", filterName + "%"));
    }
    // filter by status
    Set<ManagedResourceStatus> filterStatus = queryInfo.getFilterInfo().getFilterStatus();
    if (Objects.nonNull(filterStatus) && !filterStatus.isEmpty()) {
        query.filter("byStatus", Parameters.with("status", filterStatus));
    }
    // filter by type, considering onlyUserVisible flag
    ProcessorType filterType = queryInfo.getFilterInfo().getFilterType();
    if (restrictTypes != null) {
        if (Objects.isNull(filterType)) {
            query.filter(BY_TYPE_FILTER_NAME, Parameters.with(BY_TYPE_FILTER_PARAM, restrictTypes));
        } else {
            if (restrictTypes.contains(filterType)) {
                query.filter(BY_TYPE_FILTER_NAME, Parameters.with(BY_TYPE_FILTER_PARAM, Set.of(filterType)));
            } else {
                return new ProcessorResults(emptyList(), 0);
            }
        }
    } else {
        if (Objects.nonNull(filterType)) {
            query.filter(BY_TYPE_FILTER_NAME, Parameters.with(BY_TYPE_FILTER_PARAM, Set.of(filterType)));
        }
    }
    long total = query.count();
    List<Processor> processors = query.page(queryInfo.getPageNumber(), queryInfo.getPageSize()).list();
    List<String> ids = processors.stream().map(Processor::getId).collect(Collectors.toList());
    return new ProcessorResults(ids, total);
}
Also used : Parameters(io.quarkus.panache.common.Parameters) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorType(com.redhat.service.smartevents.infra.models.processors.ProcessorType) ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus)

Example 5 with Parameters

use of io.quarkus.panache.common.Parameters in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeDAO method findByCustomerId.

public ListResult<Bridge> findByCustomerId(String customerId, QueryResourceInfo queryInfo) {
    Parameters parameters = Parameters.with("customerId", customerId);
    PanacheQuery<Bridge> query = find("#BRIDGE.findByCustomerId", parameters);
    String filterName = queryInfo.getFilterInfo().getFilterName();
    Set<ManagedResourceStatus> filterStatus = queryInfo.getFilterInfo().getFilterStatus();
    if (Objects.nonNull(filterName)) {
        query.filter("byName", Parameters.with("name", filterName + "%"));
    }
    if (Objects.nonNull(filterStatus) && !filterStatus.isEmpty()) {
        query.filter("byStatus", Parameters.with("status", filterStatus));
    }
    long total = query.count();
    List<Bridge> bridges = query.page(queryInfo.getPageNumber(), queryInfo.getPageSize()).list();
    return new ListResult<>(bridges, queryInfo.getPageNumber(), total);
}
Also used : ListResult(com.redhat.service.smartevents.infra.models.ListResult) Parameters(io.quarkus.panache.common.Parameters) ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus) Bridge(com.redhat.service.smartevents.manager.models.Bridge)

Aggregations

Parameters (io.quarkus.panache.common.Parameters)7 ListResult (com.redhat.service.bridge.infra.models.ListResult)2 ListResult (com.redhat.service.smartevents.infra.models.ListResult)2 ManagedResourceStatus (com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus)2 Processor (com.redhat.service.smartevents.manager.models.Processor)2 Bridge (com.redhat.service.bridge.manager.models.Bridge)1 Processor (com.redhat.service.bridge.manager.models.Processor)1 ProcessorType (com.redhat.service.smartevents.infra.models.processors.ProcessorType)1 Bridge (com.redhat.service.smartevents.manager.models.Bridge)1 RegistryTenantList (io.apicurio.multitenant.api.datamodel.RegistryTenantList)1 RegistryTenantDto (io.apicurio.multitenant.storage.dto.RegistryTenantDto)1 JavaBeanUtil (io.quarkus.deployment.bean.JavaBeanUtil)1 ClassCreator (io.quarkus.gizmo.ClassCreator)1 ClassOutput (io.quarkus.gizmo.ClassOutput)1 FieldDescriptor (io.quarkus.gizmo.FieldDescriptor)1 FieldDescriptor.of (io.quarkus.gizmo.FieldDescriptor.of)1 MethodCreator (io.quarkus.gizmo.MethodCreator)1 MethodDescriptor (io.quarkus.gizmo.MethodDescriptor)1 ResultHandle (io.quarkus.gizmo.ResultHandle)1 PanacheQuery (io.quarkus.hibernate.orm.panache.PanacheQuery)1