本文整理了Java中org.springframework.data.mongodb.core.query.Query.addCriteria
方法的一些代码示例,展示了Query.addCriteria
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.addCriteria
方法的具体详情如下:
包路径:org.springframework.data.mongodb.core.query.Query
类名称:Query
方法名:addCriteria
[英]Adds the given CriteriaDefinition to the current Query.
[中]将给定的CriteriaDefinition添加到当前查询。
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* Creates a new {@link Query} using the given {@link CriteriaDefinition}.
*
* @param criteriaDefinition must not be {@literal null}.
* @since 1.6
*/
public Query(CriteriaDefinition criteriaDefinition) {
addCriteria(criteriaDefinition);
}
代码示例来源:origin: yu199195/hmily
@Override
public List<HmilyTransaction> listAllByDelay(final Date date) {
Query query = new Query();
query.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 Collections.emptyList();
}
代码示例来源:origin: yu199195/myth
@Override
public List<MythTransaction> listAllByDelay(final Date date) {
Query query = new Query();
query.addCriteria(Criteria.where("lastTime").lt(date))
.addCriteria(Criteria.where("status").is(MythStatusEnum.BEGIN.getCode()));
final List<MongoAdapter> mongoBeans = template.find(query, MongoAdapter.class, collectionName);
if (CollectionUtils.isNotEmpty(mongoBeans)) {
return mongoBeans.stream().map(this::buildByCache).collect(Collectors.toList());
}
return Collections.emptyList();
}
代码示例来源:origin: yu199195/hmily
@Override
public Boolean batchRemove(final List<String> ids, final 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;
}
代码示例来源:origin: yu199195/myth
@Override
public Boolean batchRemove(final List<String> ids, final String appName) {
if (CollectionUtils.isEmpty(ids) || StringUtils.isBlank(appName)) {
return Boolean.FALSE;
}
final String mongoTableName = RepositoryPathUtils.buildMongoTableName(appName);
ids.forEach(id -> {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(id));
mongoTemplate.remove(query, mongoTableName);
});
return Boolean.TRUE;
}
代码示例来源:origin: yu199195/Raincat
@Override
public Boolean batchRemove(final List<String> ids, final 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;
}
代码示例来源:origin: yu199195/Raincat
@Override
public List<TransactionRecover> listAllByDelay(final 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;
}
代码示例来源:origin: yu199195/Raincat
@Override
public List<TransactionRecover> listAll() {
Query query = new Query();
query.addCriteria(new Criteria("status")
.in(TransactionStatusEnum.BEGIN.getCode(),
TransactionStatusEnum.FAILURE.getCode(),
TransactionStatusEnum.ROLLBACK.getCode()));
final List<MongoAdapter> mongoAdapterList =
template.find(query, MongoAdapter.class, collectionName);
if (CollectionUtils.isNotEmpty(mongoAdapterList)) {
return mongoAdapterList.stream().map(this::buildByCache).collect(Collectors.toList());
}
return null;
}
代码示例来源:origin: yu199195/hmily
@Override
public HmilyTransaction findById(final String id) {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(id));
MongoAdapter cache = template.findOne(query, MongoAdapter.class, collectionName);
return buildByCache(Objects.requireNonNull(cache));
}
代码示例来源:origin: yu199195/myth
@Override
public int remove(final String transId) {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(transId));
template.remove(query, collectionName);
return CommonConstant.SUCCESS;
}
代码示例来源:origin: yu199195/hmily
@Override
public int remove(final String id) {
AssertUtils.notNull(id);
Query query = new Query();
query.addCriteria(new Criteria("transId").is(id));
template.remove(query, collectionName);
return ROWS;
}
代码示例来源:origin: yu199195/myth
@Override
public MythTransaction findByTransId(final String transId) {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(transId));
MongoAdapter cache = template.findOne(query, MongoAdapter.class, collectionName);
return buildByCache(cache);
}
代码示例来源:origin: yu199195/Raincat
@Override
public int remove(final String id) {
Assert.notNull(id);
Query query = new Query();
query.addCriteria(new Criteria("transId").is(id));
template.remove(query, collectionName);
return ROWS;
}
代码示例来源:origin: yu199195/Raincat
@Override
public TransactionRecover findById(final String id) {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(id));
MongoAdapter cache = template.findOne(query, MongoAdapter.class, collectionName);
return buildByCache(cache);
}
代码示例来源:origin: yu199195/hmily
@Override
public Boolean updateRetry(final String id, final Integer retry, final String appName) {
if (StringUtils.isBlank(id) || StringUtils.isBlank(appName) || Objects.isNull(retry)) {
return Boolean.FALSE;
}
final String mongoTableName = RepositoryPathUtils.buildMongoTableName(appName);
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 UpdateResult updateResult = mongoTemplate.updateFirst(query, update,
MongoAdapter.class, mongoTableName);
if (updateResult.getModifiedCount() <= 0) {
throw new HmilyRuntimeException("更新数据异常!");
}
return Boolean.TRUE;
}
代码示例来源:origin: yu199195/hmily
@Override
public int updateStatus(final String id, final Integer status) {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(id));
Update update = new Update();
update.set("status", status);
final UpdateResult updateResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
if (updateResult.getModifiedCount() <= 0) {
throw new HmilyRuntimeException("update data exception!");
}
return ROWS;
}
代码示例来源:origin: yu199195/myth
@Override
public int updateStatus(final String id, final Integer status) throws MythRuntimeException {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(id));
Update update = new Update();
update.set("status", status);
final WriteResult writeResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
if (writeResult.getN() <= 0) {
throw new MythRuntimeException(ERROR);
}
return CommonConstant.SUCCESS;
}
代码示例来源:origin: yu199195/myth
@Override
public void updateFailTransaction(final MythTransaction mythTransaction) throws MythRuntimeException {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(mythTransaction.getTransId()));
Update update = new Update();
update.set("status", mythTransaction.getStatus());
update.set("errorMsg", mythTransaction.getErrorMsg());
update.set("lastTime", new Date());
update.set("retriedCount", mythTransaction.getRetriedCount());
final WriteResult writeResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
if (writeResult.getN() <= 0) {
throw new MythRuntimeException(ERROR);
}
}
代码示例来源:origin: yu199195/hmily
@Override
public int updateParticipant(final HmilyTransaction hmilyTransaction) {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(hmilyTransaction.getTransId()));
Update update = new Update();
try {
update.set("contents", objectSerializer.serialize(hmilyTransaction.getHmilyParticipants()));
} catch (HmilyException e) {
e.printStackTrace();
}
final UpdateResult updateResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
if (updateResult.getModifiedCount() <= 0) {
throw new HmilyRuntimeException("update data exception!");
}
return ROWS;
}
代码示例来源:origin: yu199195/myth
@Override
public void updateParticipant(final MythTransaction mythTransaction) throws MythRuntimeException {
Query query = new Query();
query.addCriteria(new Criteria("transId").is(mythTransaction.getTransId()));
Update update = new Update();
try {
update.set("contents", objectSerializer.serialize(mythTransaction.getMythParticipants()));
} catch (MythException e) {
e.printStackTrace();
}
final WriteResult writeResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
if (writeResult.getN() <= 0) {
throw new MythRuntimeException(ERROR);
}
}
内容来源于网络,如有侵权,请联系作者删除!