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

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

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

Query.fromAll介绍

[英]Queries over all objects.
[中]对所有对象的查询。

代码示例

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

@Override
  public void run() {
    while (triggerTime > System.currentTimeMillis()) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException error) {
        break;
      }
    }
    Query.fromAll()
        .where("_id = ?", cacheId)
        .deleteAll();
  }
}

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

@Override
public Query<?> getSubQueryWithGroupBy() {
  if (subQueryTypes == null) {
    return null;
  }
  Query<?> subQuery = Query.fromAll();
  String keySuffix = "/" + subQueryKey;
  for (ObjectType type : subQueryTypes) {
    subQuery.sortAscending(type.getInternalName() + keySuffix);
  }
  return subQuery;
}

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

/** Returns the number of items completed. */
public long countComplete() {
  return Query.fromAll()
      .where("cms.workstream.completeIds ^= ?", getId().toString() + ",")
      .count();
}

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

@Override
public Query<?> getSubQueryWithSorter(Sorter sorter, int index) {
  if (subQueryTypes == null) {
    return null;
  }
  Query<?> subQuery = Query.fromAll();
  String keySuffix = "/" + subQueryKey;
  for (ObjectType type : subQueryTypes) {
    List<Object> options = new ArrayList<Object>(sorter.getOptions());
    options.set(index, type.getInternalName() + keySuffix);
    subQuery.sort(new Sorter(sorter.getOperator(), options));
    break;
  }
  return subQuery;
}

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

private long getReferencesCount(Object item) {

    return Query
        .fromAll()
        .where("* matches ?", State.getInstance(item).getId())
        .count();
  }
}

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

/**
 * Generates a {@link Query} for the items contained within this {@link SearchResultSelection}.  The returned
 * Query is {@code .fromAll()} and includes visibility-restricted items.
 * @return a {@link Query} for the items contained within this {@link SearchResultSelection}.
 */
public Query<Object> createItemsQuery() {
  Set<UUID> itemIds = new HashSet<>();
  for (SearchResultSelectionItem item : Query
      .from(SearchResultSelectionItem.class)
      .where("selectionId = ?", getId())
      .selectAll()) {
    itemIds.add(item.getItemId());
  }
  return Query.fromAll().where("_id = ?", itemIds);
}

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

public <T> List<T> getObjects() {
    Map<String, FacetField.Count> index = new HashMap<String, FacetField.Count>();
    List<String> ids = new ArrayList<String>();
    for (FacetField.Count c : this.field.getValues()) {
      index.put(c.getName(), c);
      ids.add(c.getName());
    }
    @SuppressWarnings("unchecked")
    List<T> objects = (List<T>) (this.klass == null || this.klass == Query.class
        ? Query.fromAll().where("id = ?", ids).selectAll()
        : Query.from(this.klass).where("id = ?", ids).selectAll());
    if (objects != null) {
      for (Object o : objects) {
        Record record = (Record) o;
        FacetField.Count c = index.get(record.getId().toString());
        record.getState().getExtras().put("count", Long.valueOf(c.getCount()));
      }
    }
    return objects;
  }
}

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

@Override
  protected void afterDelete() {
    State state = getState();

    if (state.isVisible()) {
      return;
    }

    for (Object item : Query
        .fromAll()
        .where("cms.bulkUpload.containerId = ?", state.getId().toString())
        .selectAll()) {
      State.getInstance(item).deleteImmediately();
    }
  }
}

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

@Override
  public void after(Element body) {
    for (Element a : body.getElementsByTag("a")) {
      if (ObjectUtils.equals(a.attr("href"), a.attr("data-cms-href"))) {
        UUID id = ObjectUtils.to(UUID.class, a.attr("data-cms-id"));

        if (id != null) {
          Object item = Query.fromAll().where("_id = ?", id).first();

          if (item != null) {
            String href = item instanceof Content
                ? ((Content) item).getPermalink()
                : State.getInstance(item).as(Directory.ObjectModification.class).getPermalink();

            if (href != null) {
              a.attr("href", href);
            }
          }
        }
      }

      a.removeAttr("data-cms-href");
      a.removeAttr("data-cms-id");
    }
  }
}

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

public Object createCompareObject() {
  UUID compareId = getCompareId();
  if (compareId != null) {
    Object compareObject = Query.fromAll().where("_id = ?", compareId).first();
    if (compareObject != null) {
      if (compareObject instanceof Draft) {
        return ((Draft) compareObject).recreate();
      } else if (compareObject instanceof History) {
        return ((History) compareObject).getObject();
      } else {
        return compareObject;
      }
    }
  }
  return null;
}

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

private Query<?> createQuery(Database database, WebPageContext context) {
  String queryString = context.param(String.class, WebDatabase.QUERY_PARAMETER);
  Object queryObject = ObjectUtils.fromJson(queryString);
  if (!(queryObject instanceof Map)) {
    throw new DatabaseException(database, String.format(
        "Invalid query string! (%s)", queryString));
  }
  @SuppressWarnings("unchecked")
  Map<String, Object> queryMap = (Map<String, Object>) queryObject;
  convertTypeNameToId(database.getEnvironment(), queryMap);
  Query<?> query = Query.fromAll();
  query.getState().putAll(queryMap);
  query.using(database);
  return query;
}

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

@Override
  protected Query<?> createQuery(Directory directory) {
    return (itemType != null ? Query.fromType(itemType) : Query.fromAll())
        .and(page.siteItemsSearchPredicate())
        .and(directory.itemsPredicate(page.getSite()))
        .sortAscending(Directory.PATHS_FIELD);
  }
});

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

@Override
protected void afterSave() {
  if (!isRunAfterSave()
      || !getState().isVisible()) {
    return;
  }
  for (Object item : Query
      .fromAll()
      .where("cms.bulkUpload.containerId = ?", getId().toString())
      .selectAll()) {
    State itemState = State.getInstance(item);
    itemState.as(BulkUploadDraft.class).setContainerId(null);
    itemState.saveImmediately();
  }
}

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

@Override
  protected Query<?> createQuery(Directory directory) {
    return (itemType != null ? Query.fromType(itemType) : Query.fromAll())
        .and(page.siteItemsPredicate())
        .and(directory.itemsPredicate(page.getSite()))
        .and("* matches ?", value)
        .and("cms.directory.paths != missing");
  }
});

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

@Override
public Query<?> getSubQueryWithComparison(ComparisonPredicate comparison) {
  if (subQueryTypes == null) {
    return comparison.findValueQuery();
  }
  Query<?> subQuery = Query.fromAll();
  String keySuffix = "/" + subQueryKey;
  for (ObjectType type : subQueryTypes) {
    subQuery.or(new ComparisonPredicate(
        comparison.getOperator(),
        comparison.isIgnoreCase(),
        type.getInternalName() + keySuffix,
        comparison.getValues()));
  }
  return subQuery;
}

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

@Override
  protected void doService(ToolPageContext page) throws IOException, ServletException {
    page.getRequest().setAttribute("containerObject", Query
        .fromAll()
        .where("_id = ?", page.param(UUID.class, "containerObjectId"))
        .first());

    page.writeHeader();
      page.writeStart("div", "class", "widget widget-queryField");
        JspUtils.include(
            page.getRequest(),
            page.getResponse(),
            page,
            page.toolPath(CmsTool.class, "/WEB-INF/search.jsp"),
            "resultJsp", "/queryFieldResult");
      page.writeEnd();
    page.writeFooter();
  }
}

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

/**
 * Creates a query that can return all objects that reference this
 * index.
 */
public Query<Object> createItemsQuery() {
  Query<Object> query;
  String declaringClass = getJavaDeclaringClassName();
  if (ObjectUtils.isBlank(declaringClass)) {
    query = Query.fromGroup(declaringClass);
  } else {
    ObjectStruct parent = getParent();
    if (parent instanceof ObjectType) {
      query = Query.fromType((ObjectType) parent);
    } else {
      query = Query.fromAll();
    }
  }
  query.resolveToReferenceOnly();
  query.fields(getField());
  return query;
}

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

/**
 * Recreates the originating object with the differences merged.
 *
 * @return {@code null} if the object type is {@code null}.
 */
@SuppressWarnings("deprecation")
public Object recreate() {
  ObjectType type = getObjectType();
  if (type == null) {
    return null;
  }
  UUID id = getObjectId();
  Object object = Query.fromAll()
      .where("_id = ?", id)
      .noCache()
      .resolveInvisible()
      .first();
  if (object == null) {
    object = type.createObject(id);
  }
  merge(object);
  return object;
}

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

public static History publishDifferences(
    Object object,
    Map<String, Map<String, Object>> differences,
    Site site,
    ToolUser user) {
  State state = State.getInstance(object);
  UUID id = state.getId();
  DistributedLock lock = DistributedLock.Static.getInstance(
      Database.Static.getDefault(),
      Content.class.getName() + "/publish/" + id);
  lock.lock();
  try {
    Object oldObject = Query.fromAll().where("_id = ?", id).noCache().first();
    if (oldObject != null) {
      state.setValues(Draft.mergeDifferences(
          state.getDatabase().getEnvironment(),
          State.getInstance(oldObject).getSimpleValues(),
          differences));
    }
    return publish(object, site, user);
  } finally {
    lock.unlock();
  }
}

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

@Override
  protected void doService(ToolPageContext page) throws IOException, ServletException {
    Object content = Query
        .fromAll()
        .where("_id = ?", page.param(UUID.class, "id"))
        .first();

    if (content != null) {
      ContentLock.Static.unlock(content, null, page.getUser());
    }

    String returnUrl = page.param(String.class, "returnUrl");

    if (ObjectUtils.isBlank(returnUrl)) {
      page.writeRaw(page.localize(ContentUnlock.class, "label.ok"));

    } else {
      JspUtils.redirect(
          page.getRequest(),
          page.getResponse(),
          page.param(String.class, "returnUrl"));
    }
  }
}

相关文章