private void updatePagingAndSortingByOid(RootHibernateQuery hibernateQuery, ObjectPaging paging) { String rootAlias = hibernateQuery.getPrimaryEntityAlias(); if (paging.getOrderBy() != null || paging.getDirection() != null || paging.getOffset() != null) { throw new IllegalArgumentException("orderBy, direction nor offset is allowed on ObjectPaging with cookie"); } if (repoConfiguration.isUsingOracle()) { hibernateQuery.addOrdering("NLSSORT(" + rootAlias + ".oid, 'NLS_SORT=BINARY_AI')", OrderDirection.ASCENDING); } else { hibernateQuery.addOrdering(rootAlias + ".oid", OrderDirection.ASCENDING); } if (paging.getMaxSize() != null) { hibernateQuery.setMaxResults(paging.getMaxSize()); } }
@Override public Query maxSize(Integer n) { getOrCreatePaging().setMaxSize(n); return this; }
@Override public Query offset(Integer n) { getOrCreatePaging().setOffset(n); return this; }
public static void validatePaging(ObjectPaging paging) { if (paging == null) { return; } if (paging.getMaxSize() != null && paging.getMaxSize().longValue() < 0) { throw new IllegalArgumentException("Paging max size must be more than 0."); } if (paging.getOffset() != null && paging.getOffset().longValue() < 0) { throw new IllegalArgumentException("Paging offset index must be more than 0."); } }
public static boolean isCustomPagingOkWithPagedSeqIteration(ObjectQuery query) { if (query == null || query.getPaging() == null) { return true; } ObjectPaging paging = query.getPaging(); return !paging.hasOrdering() && !paging.hasGrouping() && paging.getOffset() == null; }
private void updatePagingAndSorting(InterpretationContext context, ObjectPaging paging) throws QueryException { if (paging == null) { return; } RootHibernateQuery hibernateQuery = context.getHibernateQuery(); if (paging.getOffset() != null) { hibernateQuery.setFirstResult(paging.getOffset()); } if (paging.getMaxSize() != null) { hibernateQuery.setMaxResults(paging.getMaxSize()); } if (paging.hasOrdering()) { for (ObjectOrdering ordering : paging.getOrderingInstructions()) { addOrdering(context, ordering); } } if (paging.hasGrouping()) { for (ObjectGrouping grouping : paging.getGroupingInstructions()) { addGrouping(context, grouping); } } }
remaining = repositoryService.countObjects(type, query, options, result); } else { offset = paging.getOffset() != null ? paging.getOffset() : 0; remaining = paging.getMaxSize() != null ? paging.getMaxSize() : repositoryService.countObjects(type, query, options, result) - offset; paging.setOffset(offset); paging.setMaxSize(remaining < batchSize ? remaining : batchSize);
if (paging.getOrderingInstructions().size() > 1) { throw new UnsupportedOperationException("Ordering by more than one property is not supported: " + paging.getOrderingInstructions()); } else if (paging.getOrderingInstructions().size() == 1) { ItemPath orderBy = paging.getOrderBy(); if (CREATED_PATH.equivalent(orderBy)) { taskQuery = taskQuery.orderByTaskCreateTime(); switch (paging.getDirection()) { case DESCENDING: taskQuery = taskQuery.desc(); break; case ASCENDING:
return allObjects; if (!paging.getOrderingInstructions().isEmpty()) { allObjects.sort((o1, o2) -> { PrismContainerValue pcv1 = pcvExtractor.apply(o1); PrismContainerValue pcv2 = pcvExtractor.apply(o2); for (ObjectOrdering ordering : paging.getOrderingInstructions()) { boolean desc = ordering.getDirection() == OrderDirection.DESCENDING; Comparable<Object> c1 = getComparable(pcv1.find(ordering.getOrderBy())); }); int start = paging.getOffset() != null ? paging.getOffset() : 0; int end = paging.getMaxSize() != null ? Math.min(start + paging.getMaxSize(), allObjects.size()) : allObjects.size(); if (start == 0 && end == allObjects.size()) { return allObjects;
@Override public ObjectQuery build() { if (typeRestriction != null || existsRestriction != null) { // unfinished empty type restriction or exists restriction return addSubfilter(null).build(); } if (parentFilter != null) { throw new IllegalStateException("A block in filter definition was probably not closed."); } ObjectPaging paging = null; if (!orderingList.isEmpty()) { paging = createIfNeeded(null); paging.setOrdering(orderingList); } if (offset != null) { paging = createIfNeeded(paging); paging.setOffset(offset); } if (maxSize != null) { paging = createIfNeeded(paging); paging.setMaxSize(maxSize); } return ObjectQueryImpl.createObjectQuery(simplify(currentFilter), paging); }
ItemPath orderByPath = paging.getOrderBy(); OrderDirection direction = paging.getDirection(); if (direction != null && orderByPath != null && !orderByPath.isEmpty()) { if (orderByPath.size() > 1 || !orderByPath.startsWithName() && !orderByPath.startsWithIdentifier()) {
ObjectQuery pagedQuery; if (query != null) { maxSize = query.getPaging() != null ? query.getPaging().getMaxSize() : null; pagedQuery = query.clone(); } else { pagedQuery.setPaging(paging); main: for (;;) { paging.setCookie(lastOid != null ? lastOid : NULL_OID_MARKER); paging.setMaxSize(Math.min(batchSize, defaultIfNull(maxSize, Integer.MAX_VALUE)));
paging.setOffset(0); paging.setMaxSize(1); query.setPaging(paging); Collection<SelectorOptions<GetOperationOptions>> options = schemaHelper.getOperationOptionsBuilder()
public Integer getMaxSize() { if (paging == null) { return null; } // if (paging.getCookie() != null) { // throw new UnsupportedOperationException("Paging cookie is not supported here."); // } return paging.getMaxSize(); }
public Integer getOffset() { if (paging == null) { return null; } // if (paging.getCookie() != null) { // throw new UnsupportedOperationException("Paging cookie is not supported here."); // } return paging.getOffset(); }
@Test public void test180SearchNullPagingOffset0Size3() throws Exception { final String TEST_NAME = "test180SearchNullPagingSize5"; displayTestTitle(TEST_NAME); ObjectPaging paging = prismContext.queryFactory().createPaging(0,3); paging.setOrdering(createAttributeOrdering(SchemaConstants.ICFS_NAME)); SearchResultMetadata searchMetadata = testSeachIterativePaging(TEST_NAME, null, paging, null, getSortedUsernames18x(0,3)); assertApproxNumberOfAllResults(searchMetadata, getTest18xApproxNumberOfSearchResults()); }
@Override public Query asc(ItemPath path) { getOrCreatePaging().addOrderingInstruction(path, OrderDirection.ASCENDING); return this; }
public ObjectQueryImpl cloneEmpty() { ObjectQueryImpl clone = new ObjectQueryImpl(); if (this.paging != null) { clone.paging = this.paging.clone(); } if (this.allowPartialResults) { clone.allowPartialResults = true; } return clone; }
public <T extends ObjectType> void updateLoadedLookupTable(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Session session) throws SchemaException { if (!SelectorOptions.hasToLoadPath(LookupTableType.F_ROW, options)) { return; } LOGGER.debug("Loading lookup table data."); GetOperationOptions getOption = findLookupTableGetOption(options); RelationalValueSearchQuery queryDef = getOption == null ? null : getOption.getRelationalValueSearchQuery(); Query query = setupLookupTableRowsQuery(session, queryDef, object.getOid()); if (queryDef != null && queryDef.getPaging() != null) { ObjectPaging paging = queryDef.getPaging(); if (paging.getOffset() != null) { query.setFirstResult(paging.getOffset()); } if (paging.getMaxSize() != null) { query.setMaxResults(paging.getMaxSize()); } } List<RLookupTableRow> rows = query.list(); if (rows == null || rows.isEmpty()) { return; } LookupTableType lookup = (LookupTableType) object.asObjectable(); List<LookupTableRowType> jaxbRows = lookup.getRow(); for (RLookupTableRow row : rows) { LookupTableRowType jaxbRow = row.toJAXB(); jaxbRows.add(jaxbRow); } }
private boolean isCustomPagingOkWithFetchAllIteration(ObjectQuery query) { return query != null && query.getPaging() != null && query.getPaging().getMaxSize() != null && query.getPaging().getMaxSize() <= getConfiguration().getMaxObjectsForImplicitFetchAllIterationMethod(); }