本文整理了Java中org.springframework.data.mongodb.core.query.Update.inc()
方法的一些代码示例,展示了Update.inc()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Update.inc()
方法的具体详情如下:
包路径:org.springframework.data.mongodb.core.query.Update
类名称:Update
方法名:inc
[英]Update using the $inc update modifier
[中]使用$inc更新修改器更新
代码示例来源:origin: spring-projects/spring-data-mongodb
@Override
public void inc(String version) {
delegate.inc(version);
}
代码示例来源:origin: spring-projects/spring-data-mongodb
@Override
public void inc(String key) {
inc(key, 1L);
}
代码示例来源:origin: spring-projects/spring-data-examples
private Mono<Process> finish(ReactiveMongoOperations operations, Process process) {
return operations.update(Process.class).matching(Query.query(Criteria.where("id").is(process.getId())))
.apply(Update.update("state", State.DONE).inc("transitionCount", 1)).first() //
.then(Mono.just(process));
}
代码示例来源:origin: spring-projects/spring-data-examples
Mono<Process> start(ReactiveMongoOperations operations, Process process) {
return operations.update(Process.class).matching(Query.query(Criteria.where("id").is(process.getId())))
.apply(Update.update("state", State.ACTIVE).inc("transitionCount", 1)).first() //
.then(Mono.just(process));
}
代码示例来源:origin: spring-projects/spring-data-examples
private void finish(Process process) {
template.update(Process.class).matching(Query.query(Criteria.where("id").is(process.getId())))
.apply(Update.update("state", State.DONE).inc("transitionCount", 1)).first();
}
代码示例来源:origin: spring-projects/spring-data-examples
void start(Process process) {
template.update(Process.class).matching(Query.query(Criteria.where("id").is(process.getId())))
.apply(Update.update("state", State.ACTIVE).inc("transitionCount", 1)).first();
}
代码示例来源:origin: org.springframework.data/spring-data-mongodb
@Override
public void inc(String key) {
inc(key, 1L);
}
代码示例来源:origin: org.springframework.data/spring-data-mongodb
@Override
public void inc(String version) {
delegate.inc(version);
}
代码示例来源:origin: spring-projects/spring-integration
private int getNextId() {
Query query = Query.query(Criteria.where("_id").is(SEQUENCE_NAME));
query.fields().include(SEQUENCE);
return (Integer) this.template.findAndModify(query,
new Update().inc(SEQUENCE, 1),
FindAndModifyOptions.options().returnNew(true).upsert(true),
Map.class,
this.collectionName).get(SEQUENCE); // NOSONAR - never returns null
}
代码示例来源:origin: spring-projects/spring-integration
/**
* Perform MongoDB {@code INC} operation for the document, which contains the {@link MessageDocument}
* {@code sequence}, and return the new incremented value for the new {@link MessageDocument}.
* The {@link #SEQUENCE_NAME} document is created on demand.
* @return the next sequence value.
*/
protected int getNextId() {
Query query = Query.query(Criteria.where("_id").is(SEQUENCE_NAME));
query.fields().include(MessageDocumentFields.SEQUENCE);
return (Integer) this.mongoTemplate.findAndModify(query,
new Update().inc(MessageDocumentFields.SEQUENCE, 1),
FindAndModifyOptions.options().returnNew(true).upsert(true),
Map.class, this.collectionName)
.get(MessageDocumentFields.SEQUENCE); // NOSONAR - never returns null
}
代码示例来源:origin: com.epam.reportportal/commons-dao
private static void decreaseIssueCounter(Update issueStatusAware, String statisticsField, String defectField, int value) {
int negative = value * -1;
StringJoiner joiner = new StringJoiner(".");
String key = joiner.add(ISSUE_COUNTER).add(statisticsField).add(defectField).toString();
issueStatusAware.inc(key, negative);
}
}
代码示例来源:origin: com.epam.reportportal/commons-dao
public static Update fromItemStatusAware(final Status status, final int totalCounter, final int statusCounter) {
Update updateStatusAware = new Update().inc(EXECUTION_COUNTER + ".total", totalCounter);
Status providedStatus = status != null ? status : Status.FAILED;
if (providedStatus.awareStatisticsField() != null && !providedStatus.awareStatisticsField().isEmpty()) {
updateStatusAware = updateStatusAware.inc(EXECUTION_COUNTER + "." + status.awareStatisticsField(), statusCounter);
}
return updateStatusAware;
}
代码示例来源:origin: microcks/microcks
@Override
public void incrementDailyStatistic(String day, String serviceName, String serviceVersion, String hourKey, String minuteKey){
// Build a query to select specific object within collection.
Query query = new Query(Criteria.where("day").is(day)
.and("serviceName").is(serviceName)
.and("serviceVersion").is(serviceVersion));
// Other way to build a query using statically imported methods.
//Query queryShort = query(where("day").is(day).and("serviceName").is(serviceName).and("serviceVersion").is(serviceVersion));
// Build update to increment the 3 fields.
Update update = new Update().inc("dailyCount", 1).inc("hourlyCount." + hourKey, 1).inc("minuteCount." + minuteKey, 1);
// Do an upsert with find and modify.
template.findAndModify(query, update, DailyStatistic.class);
}
代码示例来源:origin: com.sangupta/jerry-services
@Override
public long increment(String name) {
if(AssertUtils.isEmpty(name)) {
throw new IllegalArgumentException("Counter name cannot be empty/null");
}
Update update = new Update();
update.inc("value", 1);
MongoCounter counter = this.mongoTemplate.findAndModify(new Query(Criteria.where("counterName").is(name)), update, MongoCounter.class);
if(counter != null) {
return counter.getValue();
}
return 0l;
}
代码示例来源:origin: com.sangupta/jerry-services
@Override
public long decrement(String name) {
if(AssertUtils.isEmpty(name)) {
throw new IllegalArgumentException("Counter name cannot be empty/null");
}
Update update = new Update();
update.inc("value", -1);
MongoCounter counter = this.mongoTemplate.findAndModify(new Query(Criteria.where("counterName").is(name)), update, MongoCounter.class);
if(counter != null) {
return counter.getValue();
}
return 0l;
}
代码示例来源:origin: com.googlecode.web-commons/web-common-dao
@Override
public long next(String name) {
SequenceEntity seq = mongoTemplate.findAndModify(
Query.query(Criteria.where("_id").is(name)),
new Update().inc("seq", 1L),
SequenceEntity.class);
return (seq != null ? seq.getSeq() : 0L);
}
代码示例来源:origin: com.epam.reportportal/commons-dao
@Override
public long getLaunchNumber(String launchName, String projectName) {
/*
* Project name should be validated on controller level
*/
Query query = Query.query(Criteria.where("_id").is(launchName));
LaunchMetaInfo counter = mongoOperations
.findAndModify(query, new Update().inc("projects." + projectName, 1), options().returnNew(true).upsert(true),
LaunchMetaInfo.class);
return counter.getProjects().get(projectName);
}
代码示例来源:origin: org.springframework.integration/spring-integration-mongodb
private int getNextId() {
Query query = Query.query(Criteria.where("_id").is(SEQUENCE_NAME));
query.fields().include(SEQUENCE);
return (Integer) this.template.findAndModify(query,
new Update().inc(SEQUENCE, 1),
FindAndModifyOptions.options().returnNew(true).upsert(true),
Map.class,
this.collectionName).get(SEQUENCE); // NOSONAR - never returns null
}
代码示例来源:origin: org.springframework.integration/spring-integration-mongodb
/**
* Perform MongoDB {@code INC} operation for the document, which contains the {@link MessageDocument}
* {@code sequence}, and return the new incremented value for the new {@link MessageDocument}.
* The {@link #SEQUENCE_NAME} document is created on demand.
* @return the next sequence value.
*/
protected int getNextId() {
Query query = Query.query(Criteria.where("_id").is(SEQUENCE_NAME));
query.fields().include(MessageDocumentFields.SEQUENCE);
return (Integer) this.mongoTemplate.findAndModify(query,
new Update().inc(MessageDocumentFields.SEQUENCE, 1),
FindAndModifyOptions.options().returnNew(true).upsert(true),
Map.class, this.collectionName)
.get(MessageDocumentFields.SEQUENCE); // NOSONAR - never returns null
}
代码示例来源:origin: jiwhiz/JiwhizBlogWeb
private long increaseCounter(String counterName){
Query query = new Query(Criteria.where("name").is(counterName));
Update update = new Update().inc("sequence", 1);
Counter counter = mongoTemplate.findAndModify(query, update, Counter.class); // return old Counter object
if (counter == null){
counter = new Counter();
counter.setName(counterName);
counter.setSequence(2); //should increase by one.
mongoTemplate.save(counter);
return 1;
}
return counter.getSequence();
}
内容来源于网络,如有侵权,请联系作者删除!