com.psddev.dari.db.Query.getPredicate()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中com.psddev.dari.db.Query.getPredicate方法的一些代码示例,展示了Query.getPredicate的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getPredicate方法的具体详情如下:
包路径:com.psddev.dari.db.Query
类名称:Query
方法名:getPredicate

Query.getPredicate介绍

[英]Returns the predicate for filtering the result.
[中]返回用于筛选结果的谓词。

代码示例

代码示例来源:origin: perfectsense/dari

  1. /**
  2. * Creates an absolute version of the predicate that can be embedded
  3. * in other queries.
  4. */
  5. public Predicate createAbsolutePredicate() {
  6. Predicate predicate = getPredicate();
  7. return predicate != null ? addPrefix(getGroup() + "/", predicate) : null;
  8. }

代码示例来源:origin: perfectsense/dari

  1. public Set<UUID> getConcreteTypeIds(Database database) {
  2. DatabaseEnvironment environment = database.getEnvironment();
  3. Set<ObjectType> types = getConcreteTypes(environment);
  4. Set<UUID> typeIds = new HashSet<UUID>();
  5. addVisibilityAwareTypeIds(database, environment, types, typeIds, getPredicate());
  6. if (typeIds.isEmpty() || typeIds.remove(null)) {
  7. for (ObjectType type : types) {
  8. typeIds.add(type.getId());
  9. }
  10. }
  11. return typeIds;
  12. }

代码示例来源:origin: perfectsense/dari

  1. /**
  2. * Combines the given {@code predicate} with the current one using
  3. * {@code OR} logic. If the current predicate is {@code null},
  4. * the given {@code predicate} replaces it.
  5. */
  6. public Query<E> or(Predicate predicate) {
  7. if (predicate != null) {
  8. Predicate lastPredicate = getPredicate();
  9. setPredicate(lastPredicate != null
  10. ? CompoundPredicate.combine(PredicateParser.OR_OPERATOR, lastPredicate, predicate)
  11. : predicate);
  12. }
  13. return this;
  14. }

代码示例来源:origin: perfectsense/dari

  1. /** Builds MongoDB query based on the given {@code query}. */
  2. public DBObject buildMongoQuery(Query<?> query) {
  3. Predicate predicate = query.getPredicate();
  4. List<DBObject> mongoChildren = new ArrayList<DBObject>();
  5. if (predicate != null) {
  6. mongoChildren.add(buildMongoPredicate(query, predicate));
  7. }
  8. if (!query.isFromAll()) {
  9. Set<ObjectType> types = getEnvironment().getTypesByGroup(query.getGroup());
  10. List<String> typeIds = new ArrayList<String>();
  11. for (ObjectType type : types) {
  12. typeIds.add(type.getId().toString());
  13. }
  14. mongoChildren.add(new BasicDBObject(
  15. TYPE_ID_KEY, new BasicDBObject("$in", typeIds)));
  16. }
  17. return new BasicDBObject("$and", mongoChildren);
  18. }

代码示例来源:origin: perfectsense/dari

  1. /**
  2. * Combines the given {@code predicate} with the current one using
  3. * {@code NOT} logic. If the current predicate is {@code null},
  4. * the given {@code predicate} replaces it.
  5. */
  6. public Query<E> not(Predicate predicate) {
  7. if (predicate != null) {
  8. predicate = new CompoundPredicate(PredicateParser.NOT_OPERATOR, Arrays.asList(predicate));
  9. Predicate lastPredicate = getPredicate();
  10. setPredicate(lastPredicate != null
  11. ? CompoundPredicate.combine(PredicateParser.AND_OPERATOR, lastPredicate, predicate)
  12. : predicate);
  13. }
  14. return this;
  15. }

代码示例来源:origin: perfectsense/dari

  1. /**
  2. * Maps all keys used in this query to the fields of the types in the
  3. * given {@code environment}. This is a helper method for database
  4. * implementations and isn't meant for general consumption.
  5. *
  6. * @see #mapEmbeddedKey
  7. */
  8. public Map<String, MappedKey> mapEmbeddedKeys(DatabaseEnvironment environment) {
  9. Map<String, MappedKey> mappedKeys = new HashMap<String, MappedKey>();
  10. addMappedPredicate(mappedKeys, environment, getPredicate());
  11. for (Sorter sorter : getSorters()) {
  12. Object first = sorter.getOptions().get(0);
  13. if (first instanceof String) {
  14. addMappedKey(mappedKeys, environment, (String) first);
  15. }
  16. }
  17. return mappedKeys;
  18. }

代码示例来源:origin: perfectsense/dari

  1. Predicate lastPredicate = getPredicate();
  2. setPredicate(lastPredicate != null
  3. ? CompoundPredicate.combine(PredicateParser.AND_OPERATOR, lastPredicate, predicate)

代码示例来源:origin: perfectsense/dari

  1. /**
  2. * Returns a list of values to be matched against the ID if and only if
  3. * the query contains a single predicate in the form of {@code _id = ?}.
  4. *
  5. * @return {@code null} if the query matches against anything other than ID.
  6. */
  7. public List<Object> findIdOnlyQueryValues() {
  8. if (getSorters().isEmpty()) {
  9. Predicate predicate = getPredicate();
  10. if (predicate instanceof ComparisonPredicate) {
  11. ComparisonPredicate comparison = (ComparisonPredicate) predicate;
  12. if (ID_KEY.equals(comparison.getKey())
  13. && PredicateParser.EQUALS_ANY_OPERATOR.equals(comparison.getOperator())
  14. && comparison.findValueQuery() == null) {
  15. return comparison.getValues();
  16. }
  17. }
  18. }
  19. return null;
  20. }

代码示例来源:origin: perfectsense/dari

  1. if (query.getSorters().isEmpty()) {
  2. Predicate predicate = query.getPredicate();
  3. if (predicate instanceof CompoundPredicate) {
  4. && query.getPredicate() == null) {

代码示例来源:origin: perfectsense/dari

  1. if (query.getSorters().isEmpty()) {
  2. Predicate predicate = query.getPredicate();
  3. if (predicate instanceof CompoundPredicate) {
  4. && query.getPredicate() == null) {

代码示例来源:origin: perfectsense/brightspot-cms

  1. public List<?> findDropDownItems(ObjectField field, Search dropDownSearch) {
  2. List<?> items;
  3. if (field.getTypes().contains(ObjectType.getInstance(ObjectType.class))) {
  4. List<ObjectType> types = new ArrayList<ObjectType>();
  5. Predicate predicate = dropDownSearch.toQuery(getSite()).getPredicate();
  6. for (ObjectType t : Database.Static.getDefault().getEnvironment().getTypes()) {
  7. if (t.is(predicate)) {
  8. types.add(t);
  9. }
  10. }
  11. items = new ArrayList<Object>(types);
  12. } else {
  13. items = dropDownSearch.toQuery(getSite()).selectAll();
  14. }
  15. return items;
  16. }

代码示例来源:origin: perfectsense/brightspot-cms

  1. private void writeCsvResponse(Context page) throws IOException {
  2. HttpServletResponse response = page.getResponse();
  3. response.setContentType("text/csv");
  4. response.setHeader("Content-Disposition", "attachment; filename=search-result-" + new DateTime(null, page.getUserDateTimeZone()).toString("yyyy-MM-dd-hh-mm-ss") + ".csv");
  5. page.writeHeaderRow();
  6. Query searchQuery = page.getSearch().toQuery(page.getSite());
  7. if (page.getSelection() != null) {
  8. searchQuery.where(page.getSelection().createItemsQuery().getPredicate());
  9. }
  10. addLegacyDatabaseSupport(searchQuery);
  11. int count = 0;
  12. for (Object item : searchQuery.iterable(0)) {
  13. page.writeDataRow(item);
  14. count++;
  15. if (count % 10000 == 0) {
  16. try {
  17. Thread.sleep(THROTTLE_INTERVAL);
  18. } catch (InterruptedException e) {
  19. LOGGER.error(e.getMessage(), e);
  20. }
  21. }
  22. }
  23. }

代码示例来源:origin: perfectsense/dari

  1. @Override
  2. public <T> PaginatedResult<T> readPartial(Query<T> query, long offset, int limit) {
  3. Client client = openConnection();
  4. try {
  5. Set<UUID> typeIds = query.getConcreteTypeIds(this);
  6. String[] typeIdStrings = typeIds.size() == 0
  7. ? new String[] { "_all" }
  8. : typeIds.stream().map(UUID::toString).toArray(String[]::new);
  9. SearchResponse response = client.prepareSearch(getIndexName())
  10. .setFetchSource(!query.isReferenceOnly())
  11. .setTypes(typeIdStrings)
  12. .setQuery(predicateToQueryBuilder(query.getPredicate()))
  13. .setFrom((int) offset)
  14. .setSize(limit)
  15. .execute()
  16. .actionGet();
  17. SearchHits hits = response.getHits();
  18. List<T> items = new ArrayList<>();
  19. for (SearchHit hit : hits.getHits()) {
  20. items.add(createSavedObjectWithHit(hit, query));
  21. }
  22. return new PaginatedResult<>(offset, limit, hits.getTotalHits(), items);
  23. } finally {
  24. closeConnection(client);
  25. }
  26. }

代码示例来源:origin: perfectsense/dari

  1. @Override
  2. public int hashCode() {
  3. return ObjectUtils.hashCode(
  4. getGroup(),
  5. getObjectClass(),
  6. getPredicate(),
  7. getSorters(),
  8. getDatabase(),
  9. getFields(),
  10. getOptions(),
  11. isResolveToReferenceOnly(),
  12. getTimeout());
  13. }

代码示例来源:origin: perfectsense/dari

  1. if (query.getPredicate() == null) {
  2. throw new IllegalStateException("No unique indexes!");

代码示例来源:origin: perfectsense/brightspot-cms

  1. @Override
  2. public void writeResultsItemHtml(ToolPageContext page, SearchResultSelection selection) throws IOException {
  3. Search search = new Search();
  4. search.setAdditionalPredicate(selection.createItemsQuery().getPredicate().toString());
  5. search.setLimit(10);
  6. page.writeStart("tr");
  7. page.writeStart("td");
  8. page.writeStart("a",
  9. "target", "_top",
  10. "href", page.cmsUrl("/searchAdvancedFull",
  11. "search", ObjectUtils.toJson(search.getState().getSimpleValues()),
  12. "view", MixedSearchResultView.class.getCanonicalName()));
  13. page.writeObjectLabel(selection);
  14. page.writeEnd();
  15. page.writeEnd();
  16. page.writeStart("td");
  17. Set<ToolEntity> entities = selection.getEntities();
  18. page.writeHtml(!ObjectUtils.isBlank(entities)
  19. ? entities.stream().map(e -> e.getState().getLabel()).collect(Collectors.joining(", "))
  20. : "");
  21. page.writeEnd();
  22. page.writeStart("td");
  23. page.writeHtml(page.localize(SelectionsWidget.class, ImmutableMap.of("count", selection.size()), "numItems"));
  24. page.writeEnd();
  25. page.writeEnd();
  26. }

代码示例来源:origin: perfectsense/brightspot-cms

  1. public Query<?> toQuery() {
  2. State state = getState();
  3. Query<?> query = Query.fromType(getQueryType());
  4. Predicate predicate = query.getPredicate();
  5. for (ObjectField field : getIndexedFields()) {
  6. String name = field.getInternalName();
  7. Object value = state.get(FIELD_PREFIX + name);
  8. if (!ObjectUtils.isBlank(value)) {
  9. String type = field.getInternalItemType();
  10. String operator = (String) state.get(OPERATOR_PREFIX + name);
  11. if (operator == null) {
  12. operator = ObjectField.REFERENTIAL_TEXT_TYPE.equals(type) || ObjectField.TEXT_TYPE.equals(type) ? "matchesAll" : "equalsAny";
  13. }
  14. predicate = CompoundPredicate.combine(
  15. PredicateParser.AND_OPERATOR,
  16. predicate,
  17. PredicateParser.Static.parse(name + " " + operator + " ?", value));
  18. }
  19. }
  20. query.setPredicate(predicate);
  21. ObjectField sortField = getSortField();
  22. if (ObjectField.DATE_TYPE.equals(sortField.getInternalItemType())) {
  23. query.sortDescending(sortField.getInternalName());
  24. } else {
  25. query.sortAscending(sortField.getInternalName());
  26. }
  27. return query;
  28. }

代码示例来源:origin: perfectsense/brightspot-cms

  1. private void writeTaxon(Taxon taxon, int nextLevel, String target) throws IOException {
  2. page.writeStart("li");
  3. if (taxon.as(Taxon.Data.class).isSelectable()) {
  4. renderBeforeItem(taxon);
  5. writeTaxonLabel(taxon);
  6. renderAfterItem(taxon);
  7. } else {
  8. writeTaxonLabel(taxon);
  9. }
  10. Predicate predicate = search.toQuery(page.getSite()).getPredicate();
  11. Collection<? extends Taxon> children = Taxon.Static.getChildren(taxon, predicate);
  12. if (children != null && !children.isEmpty()) {
  13. page.writeStart("a",
  14. "href", page.url("", TAXON_PARENT_ID_PARAMETER, taxon.as(Taxon.Data.class).getId(), TAXON_LEVEL_PARAMETER, nextLevel),
  15. "class", "searchResultTaxonomyExpand",
  16. "target", target);
  17. page.writeEnd();
  18. }
  19. page.writeEnd();
  20. }

代码示例来源:origin: perfectsense/brightspot-cms

  1. Predicate predicate = search.toQuery(page.getSite()).getPredicate();

代码示例来源:origin: perfectsense/brightspot-cms

  1. Predicate predicate = search.toQuery(page.getSite()).getPredicate();

相关文章