本文整理汇总了Java中org.springframework.data.mongodb.core.FindAndModifyOptions.returnNew方法的典型用法代码示例。如果您正苦于以下问题:Java FindAndModifyOptions.returnNew方法的具体用法?Java FindAndModifyOptions.returnNew怎么用?Java FindAndModifyOptions.returnNew使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.mongodb.core.FindAndModifyOptions
的用法示例。
在下文中一共展示了FindAndModifyOptions.returnNew方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNextSequenceId
import org.springframework.data.mongodb.core.FindAndModifyOptions; //导入方法依赖的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();
}
示例2: getNextSequenceId
import org.springframework.data.mongodb.core.FindAndModifyOptions; //导入方法依赖的package包/类
@Override
public long getNextSequenceId(String key) {
//get sequence id
Query query = new Query(Criteria.where("_id").is(key));
//increase sequence id by 1
Update update = new Update();
update.inc("seq", 1);
//return new increased id
FindAndModifyOptions options = new FindAndModifyOptions();
options.returnNew(true);
SequenceId seqId =
mongoOperation.findAndModify(query, update, options, SequenceId.class);
//if no id, throws SequenceException
if (seqId == null) {
log.error("Unable to get sequence id for key: {}", key);
throw new SequenceException("Unable to get sequence id for key: " + key);
}
log.debug("Next sequendId: {}", seqId);
return seqId.getSeq();
}
示例3: getNextSequenceId
import org.springframework.data.mongodb.core.FindAndModifyOptions; //导入方法依赖的package包/类
@Override
public int getNextSequenceId(String key) throws DataAccessException {
//get sequence id
Query query = new Query(Criteria.where("id").is(key));
//increase sequence id by 1
Update update = new Update();
update.inc("seq", 1);
//return new increased id
FindAndModifyOptions options = new FindAndModifyOptions();
options.returnNew(true);
//this is the magic happened.
Sequence seqId = mongoOperations.findAndModify(query, update, options, Sequence.class);
// if no id, throws SequenceException
// optional, just a way to tell user when the sequence id is failed to
// generate.
if (seqId == null) {
seqId = new Sequence();
seqId.setId(key);
seqId.setSeq(1);
mongoOperations.insert(seqId);
return 1;
}else{
return seqId.getSeq();
}
}
示例4: getNextSequence
import org.springframework.data.mongodb.core.FindAndModifyOptions; //导入方法依赖的package包/类
@Override
public SysSequence getNextSequence(String colName) {
Query query = new Query(Criteria.where("colName").is(colName));
Update update = new Update();
update.inc("sequence",1);
FindAndModifyOptions options = new FindAndModifyOptions();
options.returnNew(true);
return mongoTemplate.findAndModify(query, update, options, SysSequence.class, Constant.COL_NAME_SYS_SEQUENCE);
}
示例5: getNextSequenceId
import org.springframework.data.mongodb.core.FindAndModifyOptions; //导入方法依赖的package包/类
@Override
public long getNextSequenceId(String key) throws SequenceException {
//get sequence id
Query query = new Query(Criteria.where("_id").is(key));
//increase sequence id by 1
Update update = new Update();
update.inc("seq", 1);
//return new increased id
FindAndModifyOptions options = new FindAndModifyOptions();
options.returnNew(true);
//this is the magic happened.
SequenceId seqId =
mongoOperation.findAndModify(query, update, options, SequenceId.class);
//if no id, throws SequenceException
//optional, just a way to tell user when the sequence id is failed to generate.
if (seqId == null) {
throw new SequenceException("Unable to get sequence id for key : " + key);
}
return seqId.getSeq();
}
示例6: getNextSequenceId
import org.springframework.data.mongodb.core.FindAndModifyOptions; //导入方法依赖的package包/类
@Override
public String getNextSequenceId(String key) throws SequenceException {
// get sequence id
Query query = new Query(Criteria.where("_id").is(key));
// increase sequence id by 1
Update update = new Update();
update.inc("seq", 1);
// return new increased id
FindAndModifyOptions options = new FindAndModifyOptions();
options.returnNew(true);
ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class);
MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
if (mongoOperation != null) {
System.out.println(" Mongo Operations Found ");
// this is the magic happened.
SequenceId seqId = mongoOperation.findAndModify(query, update, options, SequenceId.class);
// if no id, throws SequenceException
// optional, just a way to tell user when the sequence id is failed to
// generate.
if (seqId == null) {
throw new SequenceException("Unable to get sequence id for key : " + key);
}
return seqId.getSeq();
} else {
System.out.println("No Mongo Operations Object .. returning 100");
return "100";
}
}
示例7: getNextSequence
import org.springframework.data.mongodb.core.FindAndModifyOptions; //导入方法依赖的package包/类
/**
* 차기 SEQUENCE를 가져온다.
*
* @param name 게시판 ID
* @return 다음 글번호
*/
public Integer getNextSequence(String name) {
Integer nextSeq = 1;
Query query = new Query();
query.addCriteria(Criteria.where("name").is(name));
Update update = new Update();
update.inc("seq", 1);
FindAndModifyOptions options = new FindAndModifyOptions();
options.returnNew(true);
Sequence sequence = mongoTemplate.findAndModify(query, update, options, Sequence.class);
if (sequence == null) {
Sequence newSequence = new Sequence();
newSequence.setName(name);
sequenceRepository.save(newSequence);
log.debug("sequence is Null. Insert new Sequence.");
return nextSeq;
} else {
nextSeq = sequence.getSeq();
return nextSeq;
}
}