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


Java Update.set方法代码示例

本文整理汇总了Java中org.springframework.data.mongodb.core.query.Update.set方法的典型用法代码示例。如果您正苦于以下问题:Java Update.set方法的具体用法?Java Update.set怎么用?Java Update.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.data.mongodb.core.query.Update的用法示例。


在下文中一共展示了Update.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateRetry

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的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;
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:28,代码来源:MongoRecoverTransactionServiceImpl.java

示例2: updateParticipant

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
/**
 * 更新 List<Participant>  只更新这一个字段数据
 *
 * @param tccTransaction 实体对象
 */
@Override
public int updateParticipant(TccTransaction tccTransaction) {
    Query query = new Query();
    query.addCriteria(new Criteria("transId").is(tccTransaction.getTransId()));
    Update update = new Update();
    try {
        update.set("contents", objectSerializer.serialize(tccTransaction.getParticipants()));
    } catch (TccException e) {
        e.printStackTrace();
    }
    final WriteResult writeResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
    if (writeResult.getN() <= 0) {
        throw new TccRuntimeException("更新数据异常!");
    }
    return 1;
}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:22,代码来源:MongoCoordinatorRepository.java

示例3: updateFailTransaction

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
/**
 * 更新事务失败日志
 *
 * @param mythTransaction 实体对象
 * @return rows 1 成功
 * @throws MythRuntimeException 异常信息
 */
@Override
public int updateFailTransaction(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("更新数据异常!");
    }
    return CommonConstant.SUCCESS;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:25,代码来源:MongoCoordinatorRepository.java

示例4: updateParticipant

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
/**
 * 更新 List<Participant>  只更新这一个字段数据
 *
 * @param mythTransaction 实体对象
 */
@Override
public int updateParticipant(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("更新数据异常!");
    }
    return CommonConstant.SUCCESS;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:22,代码来源:MongoCoordinatorRepository.java

示例5: saveResourcePlan

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
@Override
public boolean saveResourcePlan(ResourcePlan resourcePlan) {
    boolean result = false;
    if(resourcePlan.getAddTime() == 0) { //insert
        resourcePlan.setAddTime(new Date().getTime());
        resourcePlan.setModTime(new Date().getTime());

        mongoTemplate.save(resourcePlan, Constant.COL_NAME_RESOURCE_PLAN);
        result = Preconditions.isNotBlank(resourcePlan.getId());

    } else {                            //update
        Query query = new Query().addCriteria(Criteria.where("_id").is(resourcePlan.getId()));
        Update update = new Update();
        update.set("startPageNum", resourcePlan.getStartPageNum());
        update.set("endPageNum", resourcePlan.getEndPageNum());
        update.set("modTime", new Date().getTime());

        WriteResult writeResult = mongoTemplate.updateFirst(query, update, Constant.COL_NAME_RESOURCE_PLAN);
        result = writeResult!=null && writeResult.getN() > 0;
    }

    return result;
}
 
开发者ID:fengzhizi715,项目名称:ProxyPool,代码行数:24,代码来源:ProxyResourceDaoImpl.java

示例6: updateNotebook

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的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");
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:21,代码来源:NotebookDaoImpl.java

示例7: updateUser

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
public void updateUser(User user){
    Query query = new Query();
    query.addCriteria(new Criteria("userId").is(user.getUserId()));
    Update update = new Update();
    update.set("username", user.getUsername());
    update.set("personalStatus", user.getPersonalStatus());
    update.set("notebooks", user.getNotebooks());
    update.set("followers", user.getFollowers());
    update.set("followings", user.getFollowings());
    update.set("tags", user.getTags());
    update.set("avatar", user.getAvatar());
    update.set("collections", user.getCollections());
    update.set("valid", user.getValid());
    update.set("deleteCount", user.getDeleteTime());
    update.set("reputation", user.getReputation());
    update.set("qrcode", user.getQrcode());
    mongoTemplate.updateFirst(query, update, User.class,"User");
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:19,代码来源:UserDaoImpl.java

示例8: save

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
public Document save(String id, Document document) {
	Document _documentUpdate = findById(id);
	if(null==_documentUpdate){
		mongoTemplate.insert(document);
	}else{
		Query query = query(where("documentId").is(id));
		Update update = new Update();
		update.set("name",null == document.getName() ? 
				_documentUpdate.getName():document.getName());
		update.set("location",null == document.getLocation() ? 
				_documentUpdate.getLocation():document.getLocation());
		update.set("description",null == document.getDescription() ? 
				_documentUpdate.getDescription() : document.getDescription());
		update.set("type",null == document.getType() ?
				_documentUpdate.getType() : document.getType());
		update.set("modified", new Date());
		mongoTemplate.updateFirst(query, update, Document.class);
		document = findById(id);
	}
	return document;
}
 
开发者ID:Apress,项目名称:introducing-spring-framework,代码行数:22,代码来源:MongoDocumentRespository.java

示例9: doRemoveBy

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
/**
 * Remove events from device in logical way
 * @param tenant
 * @param application
 * @param deviceGuid
 * @param type
 * @throws Exception
 */
protected void doRemoveBy(Tenant tenant, Application application, String deviceGuid, Type type) throws Exception {

    List<Criteria> criterias = new ArrayList<>();

    criterias.add(
            Criteria.where(MessageFormat.format("{0}.{1}", type.getActorFieldName(),"deviceGuid"))
                    .is(deviceGuid)
    );
    Query query = Query.query(
            Criteria.where(
                    MessageFormat.format("{0}.{1}", type.getActorFieldName(),"tenantDomain")
            ).is(tenant.getDomainName())
                    .andOperator(criterias.toArray(new Criteria[criterias.size()])));

    Update update = new Update();
    update.set("deleted", true);
    mongoTemplate.updateMulti(query, update, DBObject.class, type.getCollectionName());
}
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:27,代码来源:EventRepositoryMongoImpl.java

示例10: getDynamicUpdate

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
/**
 * 根据 bean 中的属性值生成 update 对象,不为 null 的属性才添加到 update 中。
 */
protected Update getDynamicUpdate(Object bean, String... properties) {
    if (ArrayUtils.isEmpty(properties)) {
        return null;
    }

    boolean hasUpdate = false;
    Update update = new Update();
    for (String name : properties) {
        Object value = ObjectHelper.getPropertyValueQuietly(bean, name);
        if (value != null) {
            update.set(name, value);
            hasUpdate = true;
        }
    }
    return hasUpdate ? update : null;
}
 
开发者ID:akuma,项目名称:meazza,代码行数:20,代码来源:BasicMongoService.java

示例11: updatePlatform

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
public PlatformVO updatePlatform(PlatformVO vo) {
    Query query = new Query(new Criteria("id").is(vo.getId()));
	
	Update update = new Update();
	update.set("spId", vo.getSpId());
	update.set("serverName", vo.getServerName());
	update.set("serverHost", vo.getServerHost());
	update.set("serverPort", vo.getServerPort());
	update.set("protocol", vo.getProtocol());
	update.set("cseId", vo.getCseId());
	update.set("cseName", vo.getCseName());
	update.set("maxTps", vo.getMaxTps());
	update.set("updateTime", DateTimeUtil.getDateTimeByPattern("yyyy/MM/dd HH:mm:ss"));
	
	mongoTemplate.updateFirst(query, update, COLLECTION_NAME);
	
	return vo;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:19,代码来源:PlatformDAO.java

示例12: insertOrUpdate

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
@Override
public void insertOrUpdate(SensorDataset value) throws DaoException {
    Update update = new Update();
    Query existingQuery = new Query(new Criteria("timestamp").is(value.getTimestamp()));

    if (mongoOperation.exists(existingQuery, SensorDataset.class, collectionName)) {
        TreeMap<Integer, MinuteValues> minuteValues = value.getValues();
        for (Integer minuteTs : minuteValues.keySet()) {
            Query existingMinute = new Query(new Criteria().andOperator(
                    Criteria.where("timestamp").is(value.getTimestamp()),
                    Criteria.where("values." + minuteTs)
            ));
            MinuteValues minute;
            if (mongoOperation.exists(existingMinute, MinuteValues.class, collectionName)) {
                minute = mongoOperation.findOne(existingMinute, MinuteValues.class, collectionName);
                minute.merge(minuteValues.get(minuteTs));
            } else {
                minute = minuteValues.get(minuteTs);
            }
            update.set("values." + minuteTs, minute);
        }
        mongoOperation.updateFirst(existingQuery, update, collectionName);
    } else {
        mongoOperation.save(value, collectionName);
    }
}
 
开发者ID:S23Y,项目名称:myconsumption-server,代码行数:27,代码来源:ValuesRepositoryImpl.java

示例13: createTransition

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void createTransition(HasState hasState, String newState, boolean persist) {
	// TODO validacion maquina estados transicion
	State state = new State();
	state.setCode(newState);
	state.setEntered(timestampProvider.getCurrentDate());
	hasState.setCurrentState(state);
	if (persist && HasIdentifier.class.isAssignableFrom(hasState.getClass())) {
		Assert.notNull(template, "Missing MongoTemplate");
		HasIdentifier<Serializable> hasId = (HasIdentifier<Serializable>) hasState;
		Class<?> entityClass = hasState.getClass();
		Update update = new Update();
		update.set("currentState", state);
		Query query = new Query(Criteria.where("id").is(hasId.getId()));
		template.updateFirst(query, update, entityClass);
		// TODO control historico
	}
}
 
开发者ID:labcabrera,项目名称:lab-insurance,代码行数:19,代码来源:StateMachineService.java

示例14: updateByFeedSync

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
@Override
public int updateByFeedSync(Feed feed) {
	String feedId = feed.getId();
	if (!this.findExistById(feedId)) {
		this.mongoBaseDao.insert(feed);
		return 1;
	}
	Query query = new Query();
	query.addCriteria(new Criteria(DBFeedKeysConstant.id).is(feedId));
	Update update = new Update();
	update.set(DBFeedKeysConstant.title, feed.getTitle());
	update.set(DBFeedKeysConstant.image, feed.getImage());
	update.set(DBFeedKeysConstant.link, feed.getLink());
	update.set(DBFeedKeysConstant.description, feed.getDescription());
	update.set(DBFeedKeysConstant.language, feed.getLanguage());
	update.set(DBFeedKeysConstant.generator, feed.getGenerator());
	update.set(DBFeedKeysConstant.lastBuildDate, feed.getLastBuildDate());
	update.set(DBFeedKeysConstant.ttl, feed.getTtl());
	update.set(DBFeedKeysConstant.copyright, feed.getCopyright());
	update.set(DBFeedKeysConstant.pubDate, feed.getPubDate());
	update.set(DBFeedKeysConstant.category, feed.getCategory());
	update.set(DBFeedKeysConstant.lastedSyncArticleSum, feed.getLastedSyncArticleSum());
	update.set(DBFeedKeysConstant.lastedSyncStatus, feed.getLastedSyncStatus());
	update.set(DBFeedKeysConstant.lastedSyncDate, feed.getLastedSyncDate());
	return this.mongoBaseDao.updateFirst(query, update, Feed.class);
}
 
开发者ID:amao12580,项目名称:RSSReader,代码行数:27,代码来源:FeedDaoImpl.java

示例15: updateServiceAmenities

import org.springframework.data.mongodb.core.query.Update; //导入方法依赖的package包/类
/**
 * Update amenityIds for service(s). The List<JSONObject>  should in the below format
 * [{
 *     "serviceId":"1234", "amenityIds":["2323","33423","33523"]
 * },{
 *     "serviceId":"1434", "amenityIds":["233433","3333423"]
 * }]
 *
 * @return
 */
public boolean updateServiceAmenities(List<JSONObject> services) {
	/*
	BulkOperations ops = mongoTemplate.bulkOps(BulkOperations.BulkMode.UNORDERED, BusService.class);
	for (JSONObject service: services) {
		Query query = new Query(where(AbstractDocument.KEY_ID).is(service.get("serviceId").toString()));
		Update updateOp = new Update();
		updateOp.set("amenityIds", service.get("amenityIds"));
		ops.updateOne(query, updateOp);
	}
	BulkWriteResult result = ops.execute();
	return result.getModifiedCount() == services.size(); */

	for (JSONObject jsonObject : services) {
		Update updateOp = new Update();
		updateOp.set("amenityIds", jsonObject.get("amenityIds"));
		final Query query = new Query();
		query.addCriteria(where("_id").is(jsonObject.get("serviceId")));
		WriteResult writeResult =  mongoTemplate.updateMulti(query, updateOp, BusService.class);
		if(writeResult.getN() != 1) {
			return false;
		}
	}
	return true;
}
 
开发者ID:srinikandula,项目名称:mybus,代码行数:35,代码来源:BusServiceMongoDAO.java


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