本文整理汇总了Java中com.vaadin.data.provider.Query类的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Query类属于com.vaadin.data.provider包,在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchFromBackEnd
import com.vaadin.data.provider.Query; //导入依赖的package包/类
@Override
protected Stream<T> fetchFromBackEnd(Query<T, ExampleFilter<T>> query) {
int page = query.getOffset() / query.getLimit();
List<Sort.Order> sortOrders = query.getSortOrders().stream()
.map(sortOrder -> new Sort.Order(sortOrder.getDirection() == SortDirection.ASCENDING ? Sort.Direction.ASC
: Sort.Direction.DESC,
sortOrder.getSorted()))
.collect(Collectors.toList());
PageRequest pageRequest = new PageRequest(page, query.getLimit(), sortOrders.isEmpty() ? null : new Sort(sortOrders));
List<T> items = null;
if (query.getFilter().isPresent()) {
items = repository.findAll(query.getFilter().get().example, pageRequest).getContent();
}
else {
items = repository.findAll(pageRequest).getContent();
}
return items.subList(query.getOffset() % query.getLimit(), items.size()).stream(); // TODO: comment why this is done
}
示例2: createSpringSort
import com.vaadin.data.provider.Query; //导入依赖的package包/类
private <T, F> Sort createSpringSort(Query<T, F> q) {
List<QuerySortOrder> sortOrders;
if (q.getSortOrders().isEmpty()) {
sortOrders = getDefaultSortOrders();
} else {
sortOrders = q.getSortOrders();
}
List<Order> orders = sortOrders.stream()
.map(PageableDataProvider::queryOrderToSpringOrder)
.collect(Collectors.toList());
if (orders.isEmpty()) {
return null;
} else {
return new Sort(orders);
}
}
示例3: getConfiguration
import com.vaadin.data.provider.Query; //导入依赖的package包/类
protected QueryConfigurationProvider getConfiguration(final Query<ITEM, QueryFilter> query) {
final QueryFilter filter = query.getFilter().orElse(null);
final List<QuerySort> sorts = new LinkedList<>();
List<QuerySortOrder> orders = query.getSortOrders();
if (orders != null && !orders.isEmpty()) {
orders.forEach(o -> sorts.add(fromOrder(o)));
}
final QuerySort sort = getSort(sorts);
return new QueryConfigurationProvider() {
@Override
public QueryFilter getQueryFilter() {
return filter;
}
@Override
public QuerySort getQuerySort() {
return sort;
}
};
}
示例4: testPageLengthNotAligned
import com.vaadin.data.provider.Query; //导入依赖的package包/类
@Test
public void testPageLengthNotAligned() {
controls = pagedDP.getPagingControls();
controls.setPageLength(299);
Assert.assertEquals("Page should be 0 when page length was changed.", 0, controls.getPageNumber());
controls.nextPage();
Assert.assertEquals(1, controls.getPageNumber());
Assert.assertEquals("Last page should have only one item.", 1, pagedDP.size(new Query<>()));
controls.setPageLength(297);
Assert.assertEquals("Page should be 0 when page length was changed.", 0, controls.getPageNumber());
controls.nextPage();
Assert.assertEquals(1, controls.getPageNumber());
Assert.assertEquals("Last page should have only three items.", 3, pagedDP.size(new Query<>()));
}
示例5: testOffsetProvidedByQuery
import com.vaadin.data.provider.Query; //导入依赖的package包/类
@Test
public void testOffsetProvidedByQuery() {
Query<String, SerializablePredicate<String>> zeroOffsetQuery = new Query<>();
Assert.assertEquals(controls.getPageLength(), pagedDP.size(zeroOffsetQuery));
Query<String, SerializablePredicate<String>> singleOffsetQuery = new Query<>(
1,
zeroOffsetQuery.getLimit(),
zeroOffsetQuery.getSortOrders(),
zeroOffsetQuery.getInMemorySorting(),
zeroOffsetQuery.getFilter().orElse(null));
Assert.assertEquals(controls.getPageLength(), pagedDP.size(singleOffsetQuery));
Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(singleOffsetQuery).count());
controls.nextPage();
Assert.assertEquals(controls.getPageLength(), pagedDP.size(singleOffsetQuery));
Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(singleOffsetQuery).count());
}
示例6: testLimitProvidedByQuery
import com.vaadin.data.provider.Query; //导入依赖的package包/类
@Test
public void testLimitProvidedByQuery() {
Query<String, SerializablePredicate<String>> implicitLimitQuery = new Query<>();
Assert.assertEquals(controls.getPageLength(), pagedDP.size(implicitLimitQuery));
Query<String, SerializablePredicate<String>> explicitLimitQuery = new Query<>(
implicitLimitQuery.getOffset(),
controls.getPageLength() - 1,
implicitLimitQuery.getSortOrders(),
implicitLimitQuery.getInMemorySorting(),
implicitLimitQuery.getFilter().orElse(null));
Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery));
Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(explicitLimitQuery).count());
controls.nextPage();
Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery));
Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(explicitLimitQuery).count());
}
示例7: testOffsetAndLimitProvidedByQuery
import com.vaadin.data.provider.Query; //导入依赖的package包/类
@Test
public void testOffsetAndLimitProvidedByQuery() {
Query<String, SerializablePredicate<String>> implicitLimitQuery = new Query<>();
Assert.assertEquals(controls.getPageLength(), pagedDP.size(implicitLimitQuery));
Query<String, SerializablePredicate<String>> explicitLimitQuery = new Query<>(
1,
controls.getPageLength() - 2,
implicitLimitQuery.getSortOrders(),
implicitLimitQuery.getInMemorySorting(),
implicitLimitQuery.getFilter().orElse(null));
Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery));
Assert.assertEquals(controls.getPageLength()- 2, pagedDP.fetch(explicitLimitQuery).count());
controls.nextPage();
Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery));
Assert.assertEquals(controls.getPageLength() - 2, pagedDP.fetch(explicitLimitQuery).count());
}
示例8: testFilterProvidedByQuery
import com.vaadin.data.provider.Query; //导入依赖的package包/类
@Test
public void testFilterProvidedByQuery() {
controls.setPageLength(15);
Query<String, SerializablePredicate<String>> noFilterQuery = new Query<>();
Assert.assertEquals(controls.getPageLength(), pagedDP.size(noFilterQuery));
Assert.assertEquals(controls.getPageLength(), pagedDP.fetch(noFilterQuery).count());
Query<String, SerializablePredicate<String>> filterQuery = new Query<>(x -> x.startsWith("Item 2"));
Assert.assertEquals(controls.getPageLength(), pagedDP.size(filterQuery));
Assert.assertEquals(controls.getPageLength(), pagedDP.fetch(filterQuery).count());
filterQuery = new Query<>(x -> x.startsWith("Item 3"));
Assert.assertEquals(11, pagedDP.size(filterQuery));
Assert.assertEquals(11, pagedDP.fetch(filterQuery).count());
}
示例9: initFooterRow
import com.vaadin.data.provider.Query; //导入依赖的package包/类
/**
* generates a simple totalCount footer
*
* @param grid
* @param items
*/
private void initFooterRow(final Grid<Inhabitants> grid, List<Inhabitants> items) {
final FooterRow footerRow = grid.appendFooterRow();
footerRow.getCell("id")
.setHtml("total:");
final FooterCell footerCell = footerRow.join("gender", "name", "bodySize", "birthday", "onFacebook", "country");
// inital total count
footerCell.setHtml("<b>" + items.size() + "</b>");
// filter change count recalculate
grid.getDataProvider().addDataProviderListener(event -> {
List<Inhabitants> data = event.getSource()
.fetch(new Query<>()).collect(Collectors.toList());
footerCell.setHtml("<b>" + data.size() + "</b>");
});
}
示例10: testEnum
import com.vaadin.data.provider.Query; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testEnum() throws NoSuchFieldException, SecurityException {
Optional<Component> result = cfr.createComponent(MyEntity.class.getField("myEnum"));
assertTrue(result.isPresent());
assertTrue(result.get() instanceof ComboBox);
ComboBox<MyEnum> c = (ComboBox<MyEnum>)result.get();
DataProvider<?, ?> dp = c.getDataProvider();
Query<?, ?> q = new Query<>(0, 2, null, null, null);
assertEquals(2, dp.size((Query)q));
}
示例11: sizeInBackEnd
import com.vaadin.data.provider.Query; //导入依赖的package包/类
@Override
protected int sizeInBackEnd(Query<T, ExampleFilter<T>> query) {
int size = 0;
if (query.getFilter().isPresent()) {
size = Math.toIntExact(repository.count(query.getFilter().get().example));
}
else {
size = Math.toIntExact(repository.count());
}
if (resultLimit > 0 && size > resultLimit) {
return resultLimit;
}
return size;
}
示例12: fromPageable
import com.vaadin.data.provider.Query; //导入依赖的package包/类
private <T> Stream<T> fromPageable(Page<T> result, Pageable pageable,
Query<T, ?> query) {
List<T> items = result.getContent();
int firstRequested = query.getOffset();
int nrRequested = query.getLimit();
int firstReturned = (int) pageable.getOffset();
int firstReal = firstRequested - firstReturned;
int afterLastReal = firstReal + nrRequested;
if (afterLastReal > items.size()) {
afterLastReal = items.size();
}
return items.subList(firstReal, afterLastReal).stream();
}
示例13: fetchFromBackEnd
import com.vaadin.data.provider.Query; //导入依赖的package包/类
@Override
protected Stream<PropertyBox> fetchFromBackEnd(Query<PropertyBox, QueryFilter> query) {
Stream<PropertyBox> results = buildQuery(query, true).stream(propertySet);
if (getItemIdentifier().isPresent()) {
return results.map(pb -> new IdentifiablePropertyBox(pb, getItemIdentifier().get()));
}
return results;
}
示例14: fetchFromBackEnd
import com.vaadin.data.provider.Query; //导入依赖的package包/类
@Override
protected Stream<ITEM> fetchFromBackEnd(Query<ITEM, QueryFilter> query) {
getDataSource().setDataProviderQuery(query);
if (query.getLimit() == Integer.MAX_VALUE) {
return getAllItems().stream();
}
return getItemsByIndex(query.getOffset(), query.getLimit()).stream();
}
示例15: selectAll
import com.vaadin.data.provider.Query; //导入依赖的package包/类
@Override
public void selectAll() {
getDataProvider().ifPresent(dp -> {
Stream<ITEM> allItemsStream = dp.fetch(new Query<>());
LinkedHashSet<ITEM> allItems = new LinkedHashSet<>();
allItemsStream.forEach(allItems::add);
getInternalField().setValue(allItems);
});
}