本文整理匯總了Java中org.springframework.data.mongodb.core.query.Query類的典型用法代碼示例。如果您正苦於以下問題:Java Query類的具體用法?Java Query怎麽用?Java Query使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Query類屬於org.springframework.data.mongodb.core.query包,在下文中一共展示了Query類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMyRepositoryPosts
import org.springframework.data.mongodb.core.query.Query; //導入依賴的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);
}
示例2: listAllByDelay
import org.springframework.data.mongodb.core.query.Query; //導入依賴的package包/類
/**
* 獲取延遲多長時間後的事務信息,隻要為了防止並發的時候,剛新增的數據被執行
*
* @param date 延遲後的時間
* @return List<TransactionRecover>
*/
@Override
public List<TransactionRecover> listAllByDelay(Date date) {
Query query = new Query();
query.addCriteria(new Criteria("status")
.in(TransactionStatusEnum.BEGIN.getCode(),
TransactionStatusEnum.FAILURE.getCode(),
TransactionStatusEnum.ROLLBACK.getCode()))
.addCriteria(Criteria.where("lastTime").lt(date));
final List<MongoAdapter> mongoBeans =
template.find(query, MongoAdapter.class, collectionName);
if (CollectionUtils.isNotEmpty(mongoBeans)) {
return mongoBeans.stream().map(this::buildByCache).collect(Collectors.toList());
}
return null;
}
示例3: batchRemove
import org.springframework.data.mongodb.core.query.Query; //導入依賴的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;
}
示例4: updateRetry
import org.springframework.data.mongodb.core.query.Query; //導入依賴的package包/類
/**
* 更改恢複次數
*
* @param id 事務id
* @param retry 恢複次數
* @param applicationName 應用名稱
* @return true 成功
*/
@Override
public Boolean updateRetry(String id, Integer retry, String applicationName) {
if (StringUtils.isBlank(id) || StringUtils.isBlank(applicationName) || Objects.isNull(retry)) {
return Boolean.FALSE;
}
final String mongoTableName = RepositoryPathUtils.buildMongoTableName(applicationName);
Query query = new Query();
query.addCriteria(new Criteria("transId").is(id));
Update update = new Update();
update.set("lastTime", DateUtils.getCurrentDateTime());
update.set("retriedCount", retry);
final WriteResult writeResult = mongoTemplate.updateFirst(query, update,
MongoAdapter.class, mongoTableName);
if (writeResult.getN() <= 0) {
throw new TransactionRuntimeException("更新數據異常!");
}
return Boolean.TRUE;
}
示例5: shouldInsertAndCountData
import org.springframework.data.mongodb.core.query.Query; //導入依賴的package包/類
/**
* This sample performs a count, inserts data and performs a count again using reactive operator chaining. It prints
* the two counts ({@code 4} and {@code 6}) to the console.
*/
@Test
public void shouldInsertAndCountData() throws Exception {
CountDownLatch countDownLatch = new CountDownLatch(1);
template.count(new Query(), Person.class) //
.doOnNext(System.out::println) //
.thenMany(template.save(Flux.just(new Person("Hank", "Schrader", 43), //
new Person("Mike", "Ehrmantraut", 62)))) //
.last() //
.flatMap(v -> template.count(new Query(), Person.class)) //
.doOnNext(System.out::println) //
.doOnComplete(countDownLatch::countDown) //
.doOnError(throwable -> countDownLatch.countDown()) //
.subscribe();
countDownLatch.await();
}
開發者ID:callistaenterprise,項目名稱:spring-react-one,代碼行數:23,代碼來源:ReactiveMongoTemplateIntegrationTest.java
示例6: countCodes
import org.springframework.data.mongodb.core.query.Query; //導入依賴的package包/類
/** 검색한 코드의 갯수를 셈.
* @param tags
* @param search
* @param writer
* @param sort
* @return
*/
public long countCodes(
Weaver writer,
List<String> tags,
String search,
String sort) {
Criteria criteria = new Criteria();
if(search != null && search.length()>0)
criteria.orOperator(new Criteria("name").regex(search),
new Criteria("content").regex(search),
new Criteria("readme").regex(search));
if(tags != null)
criteria.and("tags").all(tags);
if(writer != null)
criteria.and("writer").is(writer);
this.filter(criteria, sort);
return mongoTemplate.count(new Query(criteria), Code.class);
}
示例7: updateMessage
import org.springframework.data.mongodb.core.query.Query; //導入依賴的package包/類
@Override
public Conversation updateMessage(ObjectId conversationId, Message message) {
final Query query = new Query(Criteria.where("_id").is(conversationId))
.addCriteria(Criteria.where("messages._id").is(message.getId()));
final Update update = new Update()
.set("messages.$", message)
.currentDate("lastModified");
final WriteResult writeResult = mongoTemplate.updateFirst(query, update, Conversation.class);
if (writeResult.getN() == 1) {
return mongoTemplate.findById(conversationId, Conversation.class);
} else {
return null;
}
}
示例8: countPostsAsMassageTag
import org.springframework.data.mongodb.core.query.Query; //導入依賴的package包/類
/** 메세지 태그를 이용하여 글을 검색하고 셈
* @param userTags
* @param search
* @param writer
* @param my
* @param sort
* @return
*/
public long countPostsAsMassageTag(String massageTag, String search, Weaver writer,
boolean my, String sort) {
Criteria criteria;
if (my) // 유저가 test1라면 $test1 하나만 들어왔을때
criteria = new Criteria().orOperator(
Criteria.where("kind").is(3).and("tags").in(massageTag),
Criteria.where("kind").is(3).and("writer")
.is(writer));
else // 유저가 test1고 $test2 하나만 들어왔을때
{
String orderWeaverName = massageTag.substring(1);
criteria = new Criteria().orOperator(
Criteria.where("kind").is(3).and("writer") // test1이 test2에게 보낸 것
.is(writer).and("tags").in(massageTag),
Criteria.where("kind").is(3).and("writer.id") // test2가 test1에게 보낸 쪽지
.is(orderWeaverName).and("tags").in("$"+writer.getId()));
}
if (search != null)
criteria.andOperator(new Criteria().orOperator(
Criteria.where("title").regex(search),
Criteria.where("content").regex(search)));
this.filter(criteria, sort);
return mongoTemplate.count(new Query(criteria), Post.class);
}
示例9: processPagePart
import org.springframework.data.mongodb.core.query.Query; //導入依賴的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;
}
示例10: countPostsAsWriter
import org.springframework.data.mongodb.core.query.Query; //導入依賴的package包/類
/** 로그인한 회원이 다른 사용자의 글을 검색할때 숫자를 셈.
* @param publicTags
* @param loginWeaverprivateAndMassageTags
* @param writer
* @param loginWeaver
* @param search
* @param sort
* @return
*/
public long countPostsAsWriter(
List<String> publicTags, List<String> loginWeaverprivateAndMassageTags,
Weaver writer, Weaver loginWeaver, String search, String sort) {
Criteria criteria = new Criteria();
criteria.orOperator(
Criteria.where("kind").is(1).and("writer").is(writer),
Criteria.where("tags").in(loginWeaverprivateAndMassageTags)
.and("writer").is(writer));
if (search != null)
criteria.andOperator(new Criteria().orOperator(
Criteria.where("title").regex(search),
Criteria.where("content").regex(search)));
if (publicTags != null)
criteria.and("tags").all(publicTags);
this.filter(criteria, sort);
return mongoTemplate.count(new Query(criteria), Post.class);
}
示例11: updateNotebook
import org.springframework.data.mongodb.core.query.Query; //導入依賴的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");
}
示例12: getMyPosts
import org.springframework.data.mongodb.core.query.Query; //導入依賴的package包/類
/** 자기글과 자기한테 온 메세지를 검색함.(자기가 보낸 쪽지는 제외)
* @param publicTags
* @param privateAndMassageTags
* @param writer
* @param search
* @param sort
* @param page
* @param size
* @return
*/
public List<Post> getMyPosts(List<String> publicTags,List<String> privateAndMassageTags, Weaver writer, String search,
String sort, int page, int size) {
Criteria criteria = new Criteria();
if(privateAndMassageTags != null)
criteria.orOperator(Criteria.where("writer").is(writer).and("kind").ne(3),
Criteria.where("tags").in(privateAndMassageTags));
else
criteria.orOperator(Criteria.where("writer").is(writer).and("kind").ne(3));
if (search != null)
criteria.andOperator(new Criteria().orOperator(
Criteria.where("title").regex(search),
Criteria.where("content").regex(search)));
if (publicTags != null)
criteria.and("tags").all(publicTags);
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);
}
示例13: getRepositories
import org.springframework.data.mongodb.core.query.Query; //導入依賴的package包/類
/** 저장소를 검색
* @param tags
* @param search
* @param creator
* @param sort
* @param page
* @param size
* @return
*/
public List<Repository> getRepositories(
List<String> tags,
String search,
String sort,
int page,
int size) {
Criteria criteria = new Criteria();
if(search != null && search.length()>0)
criteria.orOperator(new Criteria("name").regex(search),
new Criteria("description").regex(search));
if(tags != null)
criteria.and("tags").all(tags);
this.filter(criteria, sort);
Query query = new Query(criteria);
query.with(new PageRequest(page-1, size));
this.sorting(query, sort);
return mongoTemplate.find(query, Repository.class);
}
示例14: find
import org.springframework.data.mongodb.core.query.Query; //導入依賴的package包/類
/**
* 查詢
* @param pd
* @param collectionName 表名
* @return
*/
public List<PageData> find(PageData pd, String collectionName, int limit, int skip, String... order) {
Query query = new Query();
for (Object key : pd.keySet()) {
if (key.equals("M_GOAL")) {
query.addCriteria(new Criteria().orOperator(Criteria.where("M_GOAL").is(pd.getString("M_GOAL")), Criteria.where((String) key).is("all")));
}
else {
query.addCriteria(Criteria.where((String) key).is(pd.getString(key)));
}
}
for (String od : order) {
query.with(new Sort(Sort.Direction.DESC, od));
}
query.limit(limit);
query.skip(skip);
return mongoTemplate.find(query, PageData.class, collectionName);
}
示例15: getTicket
import org.springframework.data.mongodb.core.query.Query; //導入依賴的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;
}