Java Code Examples for org.springframework.data.mongodb.core.query.Update#set()
The following examples show how to use
org.springframework.data.mongodb.core.query.Update#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoCoordinatorRepository.java From hmily with Apache License 2.0 | 6 votes |
@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; }
Example 2
Source File: UserController.java From spring-boot-examples with Apache License 2.0 | 6 votes |
@PostMapping(value = "") public JsonResult add(User user) { String msg = verifySaveForm(user); if (!StringUtils.isEmpty(msg)) { return new JsonResult(false, msg); } if (user.getId() == null) { user.setCreateTime(new Date()); user.setLastUpdateTime(new Date()); User newUser = mongoTemplate.insert(user, "user"); return new JsonResult(true, newUser); } else { Query query = new Query(); query.addCriteria(Criteria.where("_id").is(user.getId())); Update update = new Update(); update.set("name", user.getName()); update.set("password", user.getPassword()); update.set("address", user.getAddress()); update.set("last_update_time", new Date()); UpdateResult updateResult = mongoTemplate.updateFirst(query, update, "user"); return new JsonResult(true, updateResult); } }
Example 3
Source File: PlatformDAO.java From SI with BSD 2-Clause "Simplified" License | 6 votes |
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; }
Example 4
Source File: BaseItemServiceImpl.java From Lottor with MIT License | 6 votes |
@Override public int updateItem(BaseItem baseItem) { Query query = new Query(); query.addCriteria(new Criteria("type").is(baseItem.getType()).and("itemId").is(baseItem.getItemId())); BaseItem item = mongoTemplate.findOne(query, BaseItem.class, CollectionNameEnum.BaseItem.name()); if (Objects.isNull(item)) { baseItem.setHealthyState(false); baseItem.setRetryCount(1); baseItem.setLastModified(System.currentTimeMillis()); mongoTemplate.save(baseItem, collectionName); return baseItem.getRetryCount(); } int count = item.getRetryCount(); Update update = Update.update("retryCount", count + 1); update.set("lastModified", System.currentTimeMillis()); if (count < 1) { update.set("healthyState", false); } mongoTemplate.updateFirst(query, update, BaseItem.class, collectionName); return count + 1; }
Example 5
Source File: MongoCompensationServiceImpl.java From hmily with Apache License 2.0 | 6 votes |
@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; }
Example 6
Source File: DeltaJournal.java From secure-data-service with Apache License 2.0 | 5 votes |
public void journal(Collection<String> ids, String collection, boolean isDelete) { // Don't journal certain collections that use the MongoEntity wrapper (id/type/body/metaData) // but which are not inBloom educational entities and thus never part of the Bulk Extract // delta if ( collection.equals("applicationAuthorization") ) { return; } if (deltasEnabled && !TenantContext.isSystemCall()) { if (subdocCollectionsToCollapse.containsKey(collection)) { journalCollapsedSubDocs(ids, collection); } long now = new Date().getTime(); Update update = new Update(); update.set("t", now); update.set("c", collection); if (isDelete) { update.set("d", now); } else { update.set("u", now); } for (String id : ids) { List<byte[]> idbytes = getByteId(id); if(idbytes.size() > 1) { update.set("i", idbytes.subList(1, idbytes.size())); } template.upsert(Query.query(where("_id").is(idbytes.get(0))), update, DELTA_COLLECTION); } } }
Example 7
Source File: ProxyDaoImpl.java From ProxyPool with Apache License 2.0 | 5 votes |
@Override public boolean updateProxyById(String id) { Query query = new Query(Criteria.where("id").is(id)); Update update = new Update(); update.set("lastSuccessfulTime", new Date().getTime()); //最近一次验证成功的时间 WriteResult writeResult = mongoTemplate.updateFirst(query, update, ProxyData.class,Constant.COL_NAME_PROXY); return writeResult!=null && writeResult.getN() > 0; }
Example 8
Source File: MongoCoordinatorRepository.java From myth with Apache License 2.0 | 5 votes |
@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); } }
Example 9
Source File: StudentServiceImpl.java From blog_demos with Apache License 2.0 | 5 votes |
public String updateByName(Student student) { LOGGER.info("start update [{}]", JSON.toJSONString(student)); //构造查询信息 Query query = buildNameQuery(student.getName()); //构造更新信息 Update update = new Update(); update.set("age", student.getAge()); //执行更新 mongoTemplate.updateFirst(query, update, Student.class); return null; }
Example 10
Source File: MongoEntityRepository.java From secure-data-service with Apache License 2.0 | 5 votes |
/** * Updates the cached education organization hierarchy for the specified school * * @param schoolId * @return whether the update succeeded */ private boolean updateSchoolLineage(String schoolId) { try { NeutralQuery query = new NeutralQuery(new NeutralCriteria("_id", NeutralCriteria.OPERATOR_EQUAL, schoolId)); Update update = new Update(); update.set("metaData.edOrgs", new ArrayList<String>(fetchLineage(schoolId, new HashSet<String>()))); super.doUpdate(EntityNames.EDUCATION_ORGANIZATION, query, update); } catch (RuntimeException e) { LOG.error("Failed to update educational organization lineage for school with Id " + schoolId + ". " + e.getMessage() + ". Related data will not be visible. Re-ingestion required."); throw e; } return true; }
Example 11
Source File: AbstractCreditCalculator.java From biliob_backend with MIT License | 5 votes |
void setExecuted(ObjectId objectId) { // update execute status Query query = new Query(where("_id").is(objectId)); Update update = new Update(); update.set("isExecuted", true); mongoTemplate.updateFirst(query, update, "user_record"); }
Example 12
Source File: DeltaJournal.java From secure-data-service with Apache License 2.0 | 5 votes |
/** * Record a purge event in the delta journal * @param timeOfPurge * start time of purge */ public void journalPurge(long timeOfPurge) { String id = uuidGeneratorStrategy.generateId(); Update update = new Update(); update.set("t", timeOfPurge); update.set("c", PURGE); TenantContext.setIsSystemCall(false); template.upsert(Query.query(where("_id").is(id)), update, DELTA_COLLECTION); }
Example 13
Source File: MongoCoordinatorRepository.java From myth with Apache License 2.0 | 5 votes |
@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); } }
Example 14
Source File: UserRepositoryImpl.java From sanshanblog with Apache License 2.0 | 5 votes |
@Override public WriteResult changeUserInfo(UserDO userDO) { Query query = new Query(); query.addCriteria(new Criteria("username").is(userDO.getUsername())); Update update = new Update(); if (userDO.getBlogLink()!=null){ update.set("blogLink", userDO.getBlogLink()); } if (userDO.getAvatar()!=null){ update.set("avatar", userDO.getAvatar()); } return this.mongoTemplate.upsert(query, update, UserDO.class); }
Example 15
Source File: CreditOperateHandle.java From biliob_backend with MIT License | 5 votes |
private <T> Result<T> updateUserInfoWithOutExp(User user, double value) { double credit = BigDecimal.valueOf(user.getCredit() + value).setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue(); double exp = user.getExp(); String userName = user.getName(); Query query = new Query(where("name").is(userName)); Update update = new Update(); update.set("credit", credit); mongoTemplate.updateFirst(query, update, User.class); return new Result<>(ResultEnum.SUCCEED, credit, exp); }
Example 16
Source File: MongoGenericDao.java From howsun-javaee-framework with Apache License 2.0 | 5 votes |
public static Update setFieldValue( String[] fields, Object[] fieldValues){ Update update = new Update(); for (int i = 0; i < fieldValues.length; i++) { update.set(fields[i], fieldValues[i]); } return update; }
Example 17
Source File: ProxyResourceDaoImpl.java From ProxyPool with Apache License 2.0 | 5 votes |
@Override public boolean saveProxyResource(ProxyResource proxyResource) { boolean result = false; if(Preconditions.isBlank(proxyResource.getResId())) { //insert proxyResource.setResId(commonDao.getNextSequence(Constant.COL_NAME_PROXY_RESOURCE).getSequence()); proxyResource.setAddTime(new Date().getTime()); proxyResource.setModTime(new Date().getTime()); mongoTemplate.save(proxyResource, Constant.COL_NAME_PROXY_RESOURCE); result = Preconditions.isNotBlank(proxyResource.getId()); } else { //update Query query = new Query().addCriteria(Criteria.where("resId").is(proxyResource.getResId())); Update update = new Update(); update.set("webName", proxyResource.getWebName()); update.set("webUrl", proxyResource.getWebUrl()); update.set("pageCount", proxyResource.getPageCount()); update.set("prefix", proxyResource.getPrefix()); update.set("suffix", proxyResource.getSuffix()); update.set("parser", proxyResource.getParser()); update.set("modTime", new Date().getTime()); WriteResult writeResult = mongoTemplate.updateFirst(query, update, Constant.COL_NAME_PROXY_RESOURCE); result = writeResult!=null && writeResult.getN() > 0; } return result; }
Example 18
Source File: UserDAOImpl.java From maven-framework-project with MIT License | 5 votes |
@Override public User updateUser(User user) { Query query = new Query(new Criteria("id").is(user.getId())); Update update = new Update(); update.set("userName", user.getUserName()); update.set("password", user.getPassword()); mongoTemplate.updateFirst(query, update, COLLECTION_NAME); return user; }
Example 19
Source File: ClusterMongoDBDaoImpl.java From chronus with Apache License 2.0 | 5 votes |
@Override public void updateDesc(ClusterEntity clusterEntity) { Update update = new Update(); update.set("clusterDesc", clusterEntity.getClusterDesc()); update.set("dateUpdated", new Date()); if (StringUtils.isNotBlank(clusterEntity.getUpdatedBy())) { update.set("updatedBy", clusterEntity.getUpdatedBy()); } super.updateById(clusterEntity.getId(), update); }
Example 20
Source File: ConfigurationDAO.java From SI with BSD 2-Clause "Simplified" License | 5 votes |
public ConfigurationVO updateConfiguration(ConfigurationVO vo) { Query query = new Query(Criteria.where("CONFIGURATION_NAME").is(vo.getCONFIGURATION_NAME())); Update update = new Update(); update.set("maxPollingSessionNo", vo.getMaxPollingSessionNo()); update.set("maxAENo", vo.getMaxAENo()); update.set("maxCSENo", vo.getMaxCSENo()); update.set("maxTps", vo.getMaxTps()); update.set("updateTime", DateTimeUtil.getDateTimeByPattern("yyyy/MM/dd HH:mm:ss")); mongoTemplate.updateFirst(query, update, COLLECTION_NAME); return vo; }