您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Query.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server.data;
  17. import java.io.Serializable;
  18. import java.util.Collections;
  19. import java.util.List;
  20. import java.util.Set;
  21. /**
  22. * Query object used to request data from a backend. Contains index limits,
  23. * sorting and filtering information.
  24. *
  25. * @since 8.0
  26. */
  27. public class Query implements Serializable {
  28. private final int offset;
  29. private final int limit;
  30. private final List<SortOrder<String>> sortOrders;
  31. private final Set<Object> filters;
  32. /**
  33. * Constructs a Query for all rows from 0 to {@link Integer#MAX_VALUE}
  34. * without sorting and filtering.
  35. */
  36. public Query() {
  37. offset = 0;
  38. limit = Integer.MAX_VALUE;
  39. sortOrders = Collections.emptyList();
  40. filters = Collections.emptySet();
  41. }
  42. /**
  43. * Constructs a Query for all rows from 0 to {@link Integer#MAX_VALUE} with
  44. * filtering.
  45. *
  46. * @param filters
  47. * set of back end filters
  48. */
  49. public Query(Set<Object> filters) {
  50. offset = 0;
  51. limit = Integer.MAX_VALUE;
  52. sortOrders = Collections.emptyList();
  53. this.filters = filters;
  54. }
  55. /**
  56. * Constructs a new Query object with given offset, limit, sorting and
  57. * filtering.
  58. *
  59. * @param offset
  60. * first index to fetch
  61. * @param limit
  62. * fetched item count
  63. * @param sortOrders
  64. * sorting order for fetching
  65. * @param filters
  66. * filtering for fetching
  67. */
  68. public Query(int offset, int limit, List<SortOrder<String>> sortOrders,
  69. Set<Object> filters) {
  70. this.offset = offset;
  71. this.limit = limit;
  72. this.sortOrders = sortOrders;
  73. this.filters = filters;
  74. }
  75. /**
  76. * Gets the first index of items to fetch.
  77. *
  78. * @return offset for data request
  79. */
  80. public int getOffset() {
  81. return offset;
  82. }
  83. /**
  84. * Gets the limit of items to fetch.
  85. * <p>
  86. * <strong>Note: </strong>It is possible that
  87. * {@code offset + limit > item count}
  88. *
  89. * @return number of items to fetch
  90. */
  91. public int getLimit() {
  92. return limit;
  93. }
  94. /**
  95. * Gets the sorting for items to fetch.
  96. *
  97. * @return list of sort orders
  98. */
  99. public List<SortOrder<String>> getSortOrders() {
  100. return sortOrders;
  101. }
  102. /**
  103. * Gets the filters for items to fetch.
  104. *
  105. * @return set of filters
  106. */
  107. public Set<Object> getFilters() {
  108. return filters;
  109. }
  110. }