当前位置: 首页>>代码示例>>Java>>正文


Java FindAndModifyOptions.returnNew方法代码示例

本文整理汇总了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();
}
 
开发者ID:chirkovd,项目名称:spring-es-sample,代码行数:23,代码来源:SequenceService.java

示例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();
}
 
开发者ID:edwise,项目名称:complete-spring-project,代码行数:26,代码来源:SequenceIdRepositoryImpl.java

示例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();
	}

}
 
开发者ID:quebic-source,项目名称:microservices-sample-project,代码行数:32,代码来源:SequenceDaoImpl.java

示例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);
}
 
开发者ID:fengzhizi715,项目名称:ProxyPool,代码行数:13,代码来源:CommonDaoImpl.java

示例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();

}
 
开发者ID:lawrencelai,项目名称:Oriole,代码行数:28,代码来源:SequenceDaoImpl.java

示例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";
	}
}
 
开发者ID:CityOfNewYork,项目名称:CROL-WebApp,代码行数:37,代码来源:SequenceDaoImpl.java

示例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;
	}
}
 
开发者ID:JakduK,项目名称:jakduk-api,代码行数:34,代码来源:CommonService.java


注:本文中的org.springframework.data.mongodb.core.FindAndModifyOptions.returnNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。