本文整理了Java中com.psddev.dari.db.Query.getPredicate
方法的一些代码示例,展示了Query.getPredicate
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getPredicate
方法的具体详情如下:
包路径:com.psddev.dari.db.Query
类名称:Query
方法名:getPredicate
[英]Returns the predicate for filtering the result.
[中]返回用于筛选结果的谓词。
代码示例来源:origin: perfectsense/dari
/**
* Creates an absolute version of the predicate that can be embedded
* in other queries.
*/
public Predicate createAbsolutePredicate() {
Predicate predicate = getPredicate();
return predicate != null ? addPrefix(getGroup() + "/", predicate) : null;
}
代码示例来源:origin: perfectsense/dari
public Set<UUID> getConcreteTypeIds(Database database) {
DatabaseEnvironment environment = database.getEnvironment();
Set<ObjectType> types = getConcreteTypes(environment);
Set<UUID> typeIds = new HashSet<UUID>();
addVisibilityAwareTypeIds(database, environment, types, typeIds, getPredicate());
if (typeIds.isEmpty() || typeIds.remove(null)) {
for (ObjectType type : types) {
typeIds.add(type.getId());
}
}
return typeIds;
}
代码示例来源:origin: perfectsense/dari
/**
* Combines the given {@code predicate} with the current one using
* {@code OR} logic. If the current predicate is {@code null},
* the given {@code predicate} replaces it.
*/
public Query<E> or(Predicate predicate) {
if (predicate != null) {
Predicate lastPredicate = getPredicate();
setPredicate(lastPredicate != null
? CompoundPredicate.combine(PredicateParser.OR_OPERATOR, lastPredicate, predicate)
: predicate);
}
return this;
}
代码示例来源:origin: perfectsense/dari
/** Builds MongoDB query based on the given {@code query}. */
public DBObject buildMongoQuery(Query<?> query) {
Predicate predicate = query.getPredicate();
List<DBObject> mongoChildren = new ArrayList<DBObject>();
if (predicate != null) {
mongoChildren.add(buildMongoPredicate(query, predicate));
}
if (!query.isFromAll()) {
Set<ObjectType> types = getEnvironment().getTypesByGroup(query.getGroup());
List<String> typeIds = new ArrayList<String>();
for (ObjectType type : types) {
typeIds.add(type.getId().toString());
}
mongoChildren.add(new BasicDBObject(
TYPE_ID_KEY, new BasicDBObject("$in", typeIds)));
}
return new BasicDBObject("$and", mongoChildren);
}
代码示例来源:origin: perfectsense/dari
/**
* Combines the given {@code predicate} with the current one using
* {@code NOT} logic. If the current predicate is {@code null},
* the given {@code predicate} replaces it.
*/
public Query<E> not(Predicate predicate) {
if (predicate != null) {
predicate = new CompoundPredicate(PredicateParser.NOT_OPERATOR, Arrays.asList(predicate));
Predicate lastPredicate = getPredicate();
setPredicate(lastPredicate != null
? CompoundPredicate.combine(PredicateParser.AND_OPERATOR, lastPredicate, predicate)
: predicate);
}
return this;
}
代码示例来源:origin: perfectsense/dari
/**
* Maps all keys used in this query to the fields of the types in the
* given {@code environment}. This is a helper method for database
* implementations and isn't meant for general consumption.
*
* @see #mapEmbeddedKey
*/
public Map<String, MappedKey> mapEmbeddedKeys(DatabaseEnvironment environment) {
Map<String, MappedKey> mappedKeys = new HashMap<String, MappedKey>();
addMappedPredicate(mappedKeys, environment, getPredicate());
for (Sorter sorter : getSorters()) {
Object first = sorter.getOptions().get(0);
if (first instanceof String) {
addMappedKey(mappedKeys, environment, (String) first);
}
}
return mappedKeys;
}
代码示例来源:origin: perfectsense/dari
Predicate lastPredicate = getPredicate();
setPredicate(lastPredicate != null
? CompoundPredicate.combine(PredicateParser.AND_OPERATOR, lastPredicate, predicate)
代码示例来源:origin: perfectsense/dari
/**
* Returns a list of values to be matched against the ID if and only if
* the query contains a single predicate in the form of {@code _id = ?}.
*
* @return {@code null} if the query matches against anything other than ID.
*/
public List<Object> findIdOnlyQueryValues() {
if (getSorters().isEmpty()) {
Predicate predicate = getPredicate();
if (predicate instanceof ComparisonPredicate) {
ComparisonPredicate comparison = (ComparisonPredicate) predicate;
if (ID_KEY.equals(comparison.getKey())
&& PredicateParser.EQUALS_ANY_OPERATOR.equals(comparison.getOperator())
&& comparison.findValueQuery() == null) {
return comparison.getValues();
}
}
}
return null;
}
代码示例来源:origin: perfectsense/dari
if (query.getSorters().isEmpty()) {
Predicate predicate = query.getPredicate();
if (predicate instanceof CompoundPredicate) {
&& query.getPredicate() == null) {
代码示例来源:origin: perfectsense/dari
if (query.getSorters().isEmpty()) {
Predicate predicate = query.getPredicate();
if (predicate instanceof CompoundPredicate) {
&& query.getPredicate() == null) {
代码示例来源:origin: perfectsense/brightspot-cms
public List<?> findDropDownItems(ObjectField field, Search dropDownSearch) {
List<?> items;
if (field.getTypes().contains(ObjectType.getInstance(ObjectType.class))) {
List<ObjectType> types = new ArrayList<ObjectType>();
Predicate predicate = dropDownSearch.toQuery(getSite()).getPredicate();
for (ObjectType t : Database.Static.getDefault().getEnvironment().getTypes()) {
if (t.is(predicate)) {
types.add(t);
}
}
items = new ArrayList<Object>(types);
} else {
items = dropDownSearch.toQuery(getSite()).selectAll();
}
return items;
}
代码示例来源:origin: perfectsense/brightspot-cms
private void writeCsvResponse(Context page) throws IOException {
HttpServletResponse response = page.getResponse();
response.setContentType("text/csv");
response.setHeader("Content-Disposition", "attachment; filename=search-result-" + new DateTime(null, page.getUserDateTimeZone()).toString("yyyy-MM-dd-hh-mm-ss") + ".csv");
page.writeHeaderRow();
Query searchQuery = page.getSearch().toQuery(page.getSite());
if (page.getSelection() != null) {
searchQuery.where(page.getSelection().createItemsQuery().getPredicate());
}
addLegacyDatabaseSupport(searchQuery);
int count = 0;
for (Object item : searchQuery.iterable(0)) {
page.writeDataRow(item);
count++;
if (count % 10000 == 0) {
try {
Thread.sleep(THROTTLE_INTERVAL);
} catch (InterruptedException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
}
代码示例来源:origin: perfectsense/dari
@Override
public <T> PaginatedResult<T> readPartial(Query<T> query, long offset, int limit) {
Client client = openConnection();
try {
Set<UUID> typeIds = query.getConcreteTypeIds(this);
String[] typeIdStrings = typeIds.size() == 0
? new String[] { "_all" }
: typeIds.stream().map(UUID::toString).toArray(String[]::new);
SearchResponse response = client.prepareSearch(getIndexName())
.setFetchSource(!query.isReferenceOnly())
.setTypes(typeIdStrings)
.setQuery(predicateToQueryBuilder(query.getPredicate()))
.setFrom((int) offset)
.setSize(limit)
.execute()
.actionGet();
SearchHits hits = response.getHits();
List<T> items = new ArrayList<>();
for (SearchHit hit : hits.getHits()) {
items.add(createSavedObjectWithHit(hit, query));
}
return new PaginatedResult<>(offset, limit, hits.getTotalHits(), items);
} finally {
closeConnection(client);
}
}
代码示例来源:origin: perfectsense/dari
@Override
public int hashCode() {
return ObjectUtils.hashCode(
getGroup(),
getObjectClass(),
getPredicate(),
getSorters(),
getDatabase(),
getFields(),
getOptions(),
isResolveToReferenceOnly(),
getTimeout());
}
代码示例来源:origin: perfectsense/dari
if (query.getPredicate() == null) {
throw new IllegalStateException("No unique indexes!");
代码示例来源:origin: perfectsense/brightspot-cms
@Override
public void writeResultsItemHtml(ToolPageContext page, SearchResultSelection selection) throws IOException {
Search search = new Search();
search.setAdditionalPredicate(selection.createItemsQuery().getPredicate().toString());
search.setLimit(10);
page.writeStart("tr");
page.writeStart("td");
page.writeStart("a",
"target", "_top",
"href", page.cmsUrl("/searchAdvancedFull",
"search", ObjectUtils.toJson(search.getState().getSimpleValues()),
"view", MixedSearchResultView.class.getCanonicalName()));
page.writeObjectLabel(selection);
page.writeEnd();
page.writeEnd();
page.writeStart("td");
Set<ToolEntity> entities = selection.getEntities();
page.writeHtml(!ObjectUtils.isBlank(entities)
? entities.stream().map(e -> e.getState().getLabel()).collect(Collectors.joining(", "))
: "");
page.writeEnd();
page.writeStart("td");
page.writeHtml(page.localize(SelectionsWidget.class, ImmutableMap.of("count", selection.size()), "numItems"));
page.writeEnd();
page.writeEnd();
}
代码示例来源:origin: perfectsense/brightspot-cms
public Query<?> toQuery() {
State state = getState();
Query<?> query = Query.fromType(getQueryType());
Predicate predicate = query.getPredicate();
for (ObjectField field : getIndexedFields()) {
String name = field.getInternalName();
Object value = state.get(FIELD_PREFIX + name);
if (!ObjectUtils.isBlank(value)) {
String type = field.getInternalItemType();
String operator = (String) state.get(OPERATOR_PREFIX + name);
if (operator == null) {
operator = ObjectField.REFERENTIAL_TEXT_TYPE.equals(type) || ObjectField.TEXT_TYPE.equals(type) ? "matchesAll" : "equalsAny";
}
predicate = CompoundPredicate.combine(
PredicateParser.AND_OPERATOR,
predicate,
PredicateParser.Static.parse(name + " " + operator + " ?", value));
}
}
query.setPredicate(predicate);
ObjectField sortField = getSortField();
if (ObjectField.DATE_TYPE.equals(sortField.getInternalItemType())) {
query.sortDescending(sortField.getInternalName());
} else {
query.sortAscending(sortField.getInternalName());
}
return query;
}
代码示例来源:origin: perfectsense/brightspot-cms
private void writeTaxon(Taxon taxon, int nextLevel, String target) throws IOException {
page.writeStart("li");
if (taxon.as(Taxon.Data.class).isSelectable()) {
renderBeforeItem(taxon);
writeTaxonLabel(taxon);
renderAfterItem(taxon);
} else {
writeTaxonLabel(taxon);
}
Predicate predicate = search.toQuery(page.getSite()).getPredicate();
Collection<? extends Taxon> children = Taxon.Static.getChildren(taxon, predicate);
if (children != null && !children.isEmpty()) {
page.writeStart("a",
"href", page.url("", TAXON_PARENT_ID_PARAMETER, taxon.as(Taxon.Data.class).getId(), TAXON_LEVEL_PARAMETER, nextLevel),
"class", "searchResultTaxonomyExpand",
"target", target);
page.writeEnd();
}
page.writeEnd();
}
代码示例来源:origin: perfectsense/brightspot-cms
Predicate predicate = search.toQuery(page.getSite()).getPredicate();
代码示例来源:origin: perfectsense/brightspot-cms
Predicate predicate = search.toQuery(page.getSite()).getPredicate();
内容来源于网络,如有侵权,请联系作者删除!