本文整理汇总了Java中org.springframework.data.mongodb.core.query.Criteria类的典型用法代码示例。如果您正苦于以下问题:Java Criteria类的具体用法?Java Criteria怎么用?Java Criteria使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Criteria类属于org.springframework.data.mongodb.core.query包,在下文中一共展示了Criteria类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryPage
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
@Override
public Page<User> queryPage(SysRole role, UserQueryRequest queryRequest) {
int start = queryRequest.getStart();
int limit = queryRequest.getLimit();
Query query = new Query();
query.addCriteria(Criteria.where("roles").in(role));
if (!StringUtils.isEmpty(queryRequest.getUsername())) {
query.addCriteria(Criteria.where("username").regex(queryRequest.getUsername()));
}
query.addCriteria(Criteria.where("deleted").ne(true));
PageRequest pageable = new PageRequest(start, limit, new Sort(Sort.Direction.DESC, "username"));
query.with(pageable);
long count = mongoTemplate.count(query, User.class);
List<User> list = mongoTemplate.find(query, User.class);
return new PageImpl<>(list, pageable, count);
}
示例2: getMyRepositoryPosts
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
/** 자기가 진행중인 저장소의 글을 검색함.
* @param privateAndMassageTags
* @param search
* @param sort
* @param page
* @param size
* @return
*/
public List<Post> getMyRepositoryPosts(List<String> privateAndMassageTags, String search,
String sort, int page,int size) {
Criteria criteria = new Criteria();
criteria.and("tags").in(privateAndMassageTags);
if (search != null)
criteria.andOperator(new Criteria().orOperator(
Criteria.where("title").regex(search),
Criteria.where("content").regex(search)));
this.filter(criteria, sort);
Query query = new Query(criteria);
query.with(new PageRequest(page - 1, size));
this.sorting(query, sort);
return mongoTemplate.find(query, Post.class);
}
示例3: updateUserChangeEmailField
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
/**
* update v5: {@link UserDocument} has changed; String-Field 'email' was replaced with custom Type 'Email'.
* find all user with an email String-value, replace String-Type with Custom-Type and update all UserDocuments.
* if email-Field is Empty or null, you don't have to update user.
*
* @since V6
*/
@ChangeSet(order = "006", id = "updateUserChangeEmailFromStringToCustomClass", author = "admin")
public void updateUserChangeEmailField(final MongoTemplate template) {
final Criteria isEmptyCriteria = new Criteria().orOperator(Criteria.where("email").is(""), Criteria.where("email").is(null));
while (true) {
final UserDocument result = template.findAndModify(new Query(isEmptyCriteria), Update.update("email", new Email()), UserDocument.class);
if (result == null)
break;
}
/**
* if email not null -> Field will be cast to specific class and updates will create correct entries
*/
// final Criteria isNotEmptyCriteria = new Criteria().orOperator(Criteria.where("email").ne(""), Criteria.where("email").ne(null));
// final List<UserDocument> userDocumentList = template.find(new Query(isNotEmptyCriteria), UserDocument.class);
}
示例4: buildQuery
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
private Query buildQuery(AuthEventQueryRequest request) {
Query query = new Query();
if (!StringUtils.isEmpty(request.getRealm())) {
query.addCriteria(Criteria.where("realm").is(request.getRealm()));
}
if (!StringUtils.isEmpty(request.getUsername())) {
query.addCriteria(Criteria.where("username").regex(request.getUsername()));
}
if (request.getBeginDate() != null && request.getEndDate() != null) {
query.addCriteria(new Criteria().andOperator(Criteria.where("loginAt").gte(request.getBeginDate()),
Criteria.where("loginAt").lte(request.getEndDate())));
}
else if (request.getBeginDate() != null) {
query.addCriteria(Criteria.where("loginAt").gte(request.getBeginDate()));
}
else if (request.getEndDate() != null) {
query.addCriteria(Criteria.where("loginAt").lte(request.getEndDate()));
}
Boolean succeed = request.getSucceed();
if (succeed != null) {
query.addCriteria(Criteria.where("succeed").is(succeed.booleanValue()));
}
return query;
}
示例5: batchRemove
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
/**
* 批量删除补偿事务信息
*
* @param ids ids 事务id集合
* @param applicationName 应用名称
* @return true 成功
*/
@Override
public Boolean batchRemove(List<String> ids, String applicationName) {
if (CollectionUtils.isEmpty(ids) || StringUtils.isBlank(applicationName)) {
return Boolean.FALSE;
}
final String mongoTableName = RepositoryPathUtils.buildMongoTableName(applicationName);
ids.forEach(id -> {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(id));
mongoTemplate.remove(query, mongoTableName);
});
return Boolean.TRUE;
}
示例6: updateParticipant
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
/**
* 更新 List<Participant> 只更新这一个字段数据
*
* @param tccTransaction 实体对象
*/
@Override
public int updateParticipant(TccTransaction tccTransaction) {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(tccTransaction.getTransId()));
Update update = new Update();
try {
update.set("contents", objectSerializer.serialize(tccTransaction.getParticipants()));
} catch (TccException e) {
e.printStackTrace();
}
final WriteResult writeResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
if (writeResult.getN() <= 0) {
throw new TccRuntimeException("更新数据异常!");
}
return 1;
}
示例7: updateNotebook
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
public void updateNotebook(Notebook notebook){
Query query = new Query();
query.addCriteria(new Criteria("NotebookId").is(notebook.getNotebookId()));
Update update = new Update();
update.set("title", notebook.getTitle());
update.set("description", notebook.getDescription());
update.set("creator", notebook.getCreator());
update.set("owner", notebook.getOwner());
update.set("star", notebook.getStar());
update.set("collected", notebook.getCollected());
update.set("clickCount", notebook.getClickCount());
update.set("collaborators", notebook.getCollaborators());
update.set("contributors", notebook.getContributors());
update.set("notes", notebook.getNotes());
update.set("createTime", notebook.getCreateTime());
update.set("cover", notebook.getCover());
update.set("tags", notebook.getTags());
update.set("starers", notebook.getStarers());
mongoTemplate.updateFirst(query, update, Notebook.class,"Notebook");
}
示例8: shouldRetrieveDataRelatedBooks
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
/**
* Filter for Data-related books in their title and output the title and authors.
*/
@Test
public void shouldRetrieveDataRelatedBooks() {
Aggregation aggregation = newAggregation( //
match(Criteria.where("volumeInfo.title").regex("data", "i")), //
replaceRoot("volumeInfo"), //
project("title", "authors"), //
sort(Direction.ASC, "title"));
AggregationResults<BookAndAuthors> result = operations.aggregate(aggregation, "books", BookAndAuthors.class);
BookAndAuthors bookAndAuthors = result.getMappedResults().get(1);
assertThat(bookAndAuthors.getTitle()).isEqualTo("Spring Data");
assertThat(bookAndAuthors.getAuthors()).contains("Mark Pollack", "Oliver Gierke", "Thomas Risberg", "Jon Brisbin",
"Michael Hunger");
}
示例9: getSprintStatsByKeywords
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
@Override
public SprintStats getSprintStatsByKeywords(List<String> boards) {
Aggregation agg = newAggregation(
match(Criteria
.where("keywords").in(boards)
.and("sSprintAssetState").is("CLOSED")
.and("sTypeName").in(Arrays.asList("Story","Bug"))
.and("sStatus").in(Arrays.asList("Accepted", "Done"))
),
group("sSprintName")
.first("sprintBeginDate").as("start")
.first("sprintEndDate").as("end")
.sum("dEstimate").as("estimate")
,
group()
.avg("estimate").as("estimateAvg")
.avg(
Ceil.ceilValueOf(
Divide.valueOf(
Subtract.valueOf("end").subtract("start")
).divideBy(3600 * 1000 * 24)
)
).as("daysDurationAvg"),
project("daysDurationAvg","estimateAvg")
.andExclude("_id")
);
AggregationResults<SprintStats> groupResults
= mongoTemplate.aggregate(agg, "feature", SprintStats.class);
return groupResults.getUniqueMappedResult();
}
示例10: postUserSignin
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
@PostMapping("/signin")
public Mono<MyUser> postUserSignin(@RequestBody MyUser myUser)
throws NoSuchAlgorithmException, InvalidKeySpecException {
Query query = new Query();
query.addCriteria(Criteria.where("userId").is(myUser.getUserId()));
MyUser user = this.operations.findOne(query, MyUser.class).switchIfEmpty(Mono.just(new MyUser())).block();
if (user.getUserId() == null) {
String salt = this.passwordEncryption.generateSalt();
String encryptedPassword = this.passwordEncryption.getEncryptedPassword(myUser.getPassword(), salt);
myUser.setPassword(encryptedPassword);
myUser.setSalt(salt);
this.operations.save(myUser).block();
return Mono.just(myUser);
}
return Mono.just(new MyUser());
}
示例11: getTicket
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
@Override
public Ticket getTicket(final String ticketId) {
try {
LOGGER.debug("Locating ticket ticketId [{}]", ticketId);
final String encTicketId = encodeTicketId(ticketId);
if (encTicketId == null) {
LOGGER.debug("Ticket ticketId [{}] could not be found", ticketId);
return null;
}
final TicketHolder d = this.mongoTemplate.findOne(new Query(Criteria.where(TicketHolder.FIELD_NAME_ID).is(encTicketId)),
TicketHolder.class, this.collectionName);
if (d != null) {
return deserializeTicketFromMongoDocument(d);
}
} catch (final Exception e) {
LOGGER.error("Failed fetching [{}]: [{}]", ticketId, e);
}
return null;
}
示例12: getNextSequenceId
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
public Long getNextSequenceId(String key) {
/** Get <code>Sequence</code> object by collection name*/
Query query = new Query(Criteria.where("id").is(key));
/** Increase field sequence by 1*/
Update update = new Update();
update.inc("sequence", 1);
// указываем опцию, что нужно возвращать измененный объект
/** Set option about returning new object*/
FindAndModifyOptions options = new FindAndModifyOptions();
options.returnNew(true);
Sequence sequence = mongoOperations.findAndModify(query, update, options, Sequence.class);
// if no sequence set id value 'key'
if (sequence == null) {
sequence = setSequenceId(key, 1L);
}
return sequence.getCurrent();
}
示例13: processPagePart
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
public static PageRequest processPagePart(Query query, PageQueryRequest queryRequest, Sort sort) {
if (queryRequest instanceof DateRangedQueryRequest) {
DateRangedQueryRequest dateRangedQueryRequest = (DateRangedQueryRequest) queryRequest;
if (dateRangedQueryRequest.getBeginDate() != null && dateRangedQueryRequest.getEndDate() != null) {
query.addCriteria(new Criteria().andOperator(Criteria.where("createdAt")
.gte(dateRangedQueryRequest.getBeginDate()),
Criteria.where("createdAt")
.lte(dateRangedQueryRequest.getEndDate())));
}
else if (dateRangedQueryRequest.getBeginDate() != null) {
query.addCriteria(Criteria.where("createdAt").gte(dateRangedQueryRequest.getBeginDate()));
}
else if (dateRangedQueryRequest.getEndDate() != null) {
query.addCriteria(Criteria.where("createdAt").lte(dateRangedQueryRequest.getEndDate()));
}
}
int start = queryRequest.getStart();
int limit = queryRequest.getLimit();
PageRequest pageable = new PageRequest(start, limit, sort);
query.with(pageable);
return pageable;
}
示例14: findById
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
/**
* 根据id获取对象
*
* @param id 主键id
* @return TransactionRecover
*/
@Override
public TransactionRecover findById(String id) {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(id));
MongoAdapter cache = template.findOne(query, MongoAdapter.class, collectionName);
return buildByCache(cache);
}
示例15: findById
import org.springframework.data.mongodb.core.query.Criteria; //导入依赖的package包/类
/**
* 根据id获取对象
*
* @param id 主键id
* @return TccTransaction
*/
@Override
public TccTransaction findById(String id) {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(id));
MongoAdapter cache = template.findOne(query, MongoAdapter.class, collectionName);
return buildByCache(cache);
}