本文整理了Java中com.psddev.dari.db.Query.and
方法的一些代码示例,展示了Query.and
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.and
方法的具体详情如下:
包路径:com.psddev.dari.db.Query
类名称:Query
方法名:and
[英]Combines the given predicate with the current one using AND logic. If the current predicate is null, the given predicate replaces it. For example:
Query<Article> query = Query.from(Article.class);
for (...) {
query.and("tags = ?", tag);
}
is equivalent to:
Query<Article> query = Query.from(Article.class);
for (...) {
if (isFirst) {
query.where("tags = ?", tag);
} else {
query.and("tags = ?", tag);
}
}
[中]使用AND逻辑将给定谓词与当前谓词组合。如果当前谓词为null,则给定的谓词将替换它。例如:
Query<Article> query = Query.from(Article.class);
for (...) {
query.and("tags = ?", tag);
}
相当于:
Query<Article> query = Query.from(Article.class);
for (...) {
if (isFirst) {
query.where("tags = ?", tag);
} else {
query.and("tags = ?", tag);
}
}
代码示例来源:origin: perfectsense/dari
/** @see #and(Predicate) */
public Query<E> where(Predicate predicate) {
return and(predicate);
}
代码示例来源:origin: perfectsense/dari
/** @see #and(String, Object...) */
public Query<E> where(String predicateString, Object... parameters) {
return and(predicateString, parameters);
}
代码示例来源:origin: perfectsense/brightspot-cms
public void apply(SearchQueryBuilder queryBuilder, Query query, List<String> queryTerms) {
if (onlyReturnPathed) {
query.and(Directory.Static.hasPathPredicate());
}
}
}
代码示例来源:origin: perfectsense/dari
@Override
public Query<T> createItemsQuery() {
Query<T> itemsQuery = Query.fromQuery(query);
for (int i = 0, length = fields.length; i < length; ++ i) {
itemsQuery.and(fields[i] + " = ?", keys.get(i));
}
return itemsQuery;
}
代码示例来源:origin: perfectsense/dari
/**
* Parses the given {@linkplain PredicateParser.Static#parse predicateString}
* with the given {@code parameters} and {@linkplain #and(Predicate)
* adds it} to the current one.
*/
public Query<E> and(String predicateString, Object... parameters) {
return and(PredicateParser.Static.parse(predicateString, parameters));
}
代码示例来源: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/brightspot-cms
public void apply(SearchQueryBuilder queryBuilder, Query query, List<String> queryTerms) {
if (!ObjectUtils.isBlank(queryTerms)) {
for (String queryTerm : queryTerms) {
for (String spotLightTerm : spotLightTerms) {
if (spotLightTerm.equalsIgnoreCase(queryTerm)) {
query.and("id != ?", getSpotlightContent());
break;
}
}
}
}
}
代码示例来源:origin: perfectsense/brightspot-cms
public Query toQuery(Site site, Object... terms) {
List<String> queryTerms = normalizeTerms(terms);
Query query = Query.from(Object.class);
if (site != null) {
query.and(site.itemsPredicate());
}
for (Rule rule : getRules()) {
rule.apply(this, query, queryTerms);
}
if (!queryTerms.isEmpty()) {
query.and("_any matchesAny ?", queryTerms);
}
Set<ObjectType> allTypes = new HashSet<ObjectType>();
for (ObjectType type : getTypes()) {
allTypes.addAll(type.as(ToolUi.class).findDisplayTypes());
}
query.and("_type = ?", allTypes);
return query;
}
代码示例来源:origin: perfectsense/brightspot-cms
public Query<?> toPreviousQuery(State state) {
String sortFieldName = getSortFieldName();
Query<?> query = toQuery().and(sortFieldName + " <= ? and _id != ?", state.get(sortFieldName), state.getId());
for (ListIterator<Sorter> i = query.getSorters().listIterator(); i.hasNext();) {
Sorter sorter = i.next();
if (Sorter.ASCENDING_OPERATOR.equals(sorter.getOperator())) {
List<Object> options = sorter.getOptions();
if (options != null
&& options.size() > 0
&& sortFieldName.equals(options.get(0))) {
i.set(new Sorter(Sorter.DESCENDING_OPERATOR, options));
}
}
}
return query;
}
代码示例来源:origin: perfectsense/brightspot-cms
/**
* Releases the exclusive write lock on the content with the given
* {@code id}.
*
* @param id Can't be {@code null}.
*/
public void unlockContent(UUID id) {
String idPrefix = id.toString() + '/';
Set<String> locks = createLocks(idPrefix);
ToolUser user = Query
.from(ToolUser.class)
.where("_id != ?", this)
.and("contentLocks = ?", locks)
.first();
if (user != null) {
for (Iterator<String> i = user.contentLocks.iterator(); i.hasNext();) {
if (i.next().startsWith(idPrefix)) {
i.remove();
}
}
user.save();
}
}
代码示例来源: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
public Query<?> toNextQuery(State state) {
String sortFieldName = getSortFieldName();
return toQuery().and(sortFieldName + " >= ? and _id != ?", state.get(sortFieldName), state.getId());
}
}
代码示例来源:origin: perfectsense/brightspot-cms
/** Returns the number of remaining items to be worked on. */
public long countIncomplete() {
return getQuery().clone()
.and("id != ?", Query.from(Object.class).where("cms.workstream.completeIds ^= ?", getId().toString() + ","))
.count();
}
代码示例来源:origin: perfectsense/brightspot-cms
/**
* Removes the Object with itemId from this SearchResultSelection.
* @param itemId the id of the Object to be removed. Cannot be {@code null}.
*/
public boolean removeItem(UUID itemId) {
if (itemId == null) {
throw new IllegalArgumentException("itemId cannot be null!");
}
SearchResultSelectionItem item = Query
.from(SearchResultSelectionItem.class)
.where("selectionId = ?", getId())
.and("itemId = ?", itemId).first();
if (item == null) {
return false;
}
item.delete();
return true;
}
代码示例来源:origin: perfectsense/brightspot-cms
public static <T extends Taxon> List<T> getRoots(Class<T> taxonClass, Site site, Predicate predicate) {
Query<T> query = Query.from(taxonClass).where("cms.taxon.root = true");
if (site != null) {
query.and(site.itemsPredicate());
}
List<T> roots = query.selectAll();
return filter(roots, predicate);
}
代码示例来源:origin: perfectsense/brightspot-cms
@Override
public Query<SearchResultSelection> getQuery(ToolPageContext page) {
Query<SearchResultSelection> query = Query.from(SearchResultSelection.class).where("name != missing");
ToolEntityType entityType = page.pageParam(ToolEntityType.class, TOOL_ENTITY_TYPE_PARAMETER, ToolEntityType.ANYONE);
UUID entityId = null;
if (entityType == ToolEntityType.USER || entityType == ToolEntityType.ROLE) {
entityId = page.pageParam(UUID.class, TOOL_ENTITY_VALUE_PARAMETER, null);
} else if (entityType == ToolEntityType.ME) {
entityId = page.getUser().getId();
}
if (entityId != null) {
query.and("entities = ?", entityId);
}
return query;
}
代码示例来源:origin: perfectsense/brightspot-cms
private void deleteWorksInProgress(Object object) {
UUID contentId = object instanceof Draft
? ((Draft) object).getObjectId()
: State.getInstance(object).getId();
Query.from(WorkInProgress.class)
.where("owner = ?", getUser())
.and("contentId = ?", contentId)
.deleteAll();
}
代码示例来源:origin: perfectsense/brightspot-cms
/**
* Adds the Object with itemId to this SearchResultSelection.
* @param itemId the id of the Object to be added. Cannot be {@code null}.
*/
public boolean addItem(UUID itemId) {
if (itemId == null) {
throw new IllegalArgumentException("itemId cannot be null!");
}
SearchResultSelectionItem item = Query
.from(SearchResultSelectionItem.class)
.where("selectionId = ?", getId())
.and("itemId = ?", itemId)
.first();
if (item == null) {
item = new SearchResultSelectionItem();
item.setSelectionId(getId());
item.setItemId(itemId);
item.save();
return true;
}
return false;
}
代码示例来源:origin: perfectsense/brightspot-cms
private PaginatedResult<WorkStream> getResults(ToolPageContext page) {
Query<WorkStream> query = Query.from(WorkStream.class).where(page.siteItemsPredicate());
ToolEntityType entityType = page.pageParam(ToolEntityType.class, TOOL_ENTITY_TYPE_PARAMETER, ToolEntityType.ANYONE);
UUID entityId = null;
if (entityType == ToolEntityType.USER || entityType == ToolEntityType.ROLE) {
entityId = page.pageParam(UUID.class, TOOL_ENTITY_VALUE_PARAMETER, null);
} else if (entityType == ToolEntityType.ME) {
entityId = page.getUser().getId();
}
if (entityId != null) {
query.and("assignedEntities = ?", entityId);
}
return query.select(page.param(long.class, OFFSET_PARAMETER), page.paramOrDefault(int.class, LIMIT_PARAMETER, LIMITS[0]));
}
代码示例来源:origin: perfectsense/brightspot-cms
public void writeCheckboxHtml(ToolPageContext page, Search search, Object item) throws IOException {
String url = page.toolUrl(CmsTool.class, "/searchResultActions",
"search", ObjectUtils.toJson(search.getState().getSimpleValues()),
SearchResultActions.ITEM_ID_PARAMETER, State.getInstance(item).getId());
SearchResultSelection currentSelection = page.getUser().getCurrentSearchResultSelection();
boolean selected = currentSelection != null
&& item != null
&& Query.from(SearchResultSelectionItem.class).where("selectionId = ?", currentSelection).and("itemId = ?", item).first() != null;
page.writeElement("input",
"type", "checkbox",
"name", "id",
"checked", (selected ? "checked" : null),
"value", State.getInstance(item).getId(),
"data-frame-target", search.createFrameName("SearchResultActions"),
"data-frame-check", StringUtils.addQueryParameters(url, SearchResultActions.ACTION_PARAMETER, SearchResultActions.ACTION_ADD),
"data-frame-uncheck", StringUtils.addQueryParameters(url, SearchResultActions.ACTION_PARAMETER, SearchResultActions.ACTION_REMOVE));
}
内容来源于网络,如有侵权,请联系作者删除!