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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations