/** * 根据用户名查询对象 * @param userName * @return */ @Override public UserEntity findUserByUserName(String userName) { Query query=new Query(Criteria.where("userName").is(userName)); UserEntity user = mongoTemplate.findOne(query , UserEntity.class); return user; }
/** * 删除对象 * @param id */ @Override public void deleteUserById(Long id) { Query query=new Query(Criteria.where("id").is(id)); mongoTemplate.remove(query,UserEntity.class); } }
@Override public Optional<MongoEndpointRegistration> findByEndpointId(String endpointId) { LOG.debug("Searching for endpoint registration by endpoint ID [{}]", endpointId); Query query = Query.query( Criteria.where(MongoModelConstants.EP_REGISTRATION_ENDPOINT_ID) .is(endpointId)); return Optional.ofNullable(this.findOne(query)); }
@Override public Optional<MongoEndpointRegistration> findByCredentialsId(String credentialsId) { LOG.debug("Searching for endpoint registration by credentials ID [{}]", credentialsId); Query query = Query.query( Criteria.where(MongoModelConstants.EP_REGISTRATION_CREDENTIALS_ID) .is(credentialsId)); return Optional.ofNullable(this.findOne(query)); }
@Override public void removeByAppId(String appId) { LOG.debug("Remove endpoint profile by application id [{}] ", appId); remove(query(where(EP_APPLICATION_ID).is(appId))); }
@Override public Boolean batchRemove(final List<String> ids, final String applicationName) { if (CollectionUtils.isEmpty(ids) || StringUtils.isBlank(applicationName)) { return Boolean.FALSE; } final String mongoTableName = RepositoryPathUtils.buildMongoTableName(applicationName); ids.forEach(id -> { Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); mongoTemplate.remove(query, mongoTableName); }); return Boolean.TRUE; }
@Override public HmilyTransaction findById(final String id) { Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); MongoAdapter cache = template.findOne(query, MongoAdapter.class, collectionName); return buildByCache(Objects.requireNonNull(cache)); }
@Override public int remove(final String transId) { Query query = new Query(); query.addCriteria(new Criteria("transId").is(transId)); template.remove(query, collectionName); return CommonConstant.SUCCESS; }
@Override public int remove(final String id) { AssertUtils.notNull(id); Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); template.remove(query, collectionName); return ROWS; }
@Override public MythTransaction findByTransId(final String transId) { Query query = new Query(); query.addCriteria(new Criteria("transId").is(transId)); MongoAdapter cache = template.findOne(query, MongoAdapter.class, collectionName); return buildByCache(cache); }
@Override public int remove(final String id) { Assert.notNull(id); Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); template.remove(query, collectionName); return ROWS; }
@Override public TransactionRecover findById(final String id) { Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); MongoAdapter cache = template.findOne(query, MongoAdapter.class, collectionName); return buildByCache(cache); }
@Override public List<MongoEndpointNotification> findNotificationsByKeyHash(final byte[] keyHash) { LOG.debug("Find unicast notifications by endpoint key hash [{}] ", keyHash); DBObject dbObject = query(where(EP_ENDPOINT_KEY_HASH).is(keyHash)).getQueryObject(); DBCursor cursor = mongoTemplate.getDb().getCollection(getCollectionName()).find(dbObject); List<MongoEndpointNotification> endpointNotifications = new ArrayList<>(); while (cursor.hasNext()) { endpointNotifications.add(mongoTemplate.getConverter() .read(MongoEndpointNotification.class, cursor.next())); } return endpointNotifications; }
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)); }
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)); }
@Override public int updateStatus(final String id, final Integer status) { Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); Update update = new Update(); update.set("status", status); final UpdateResult updateResult = template.updateFirst(query, update, MongoAdapter.class, collectionName); if (updateResult.getModifiedCount() <= 0) { throw new HmilyRuntimeException("update data exception!"); } return ROWS; }
@Override public int updateStatus(final String id, final Integer status) throws MythRuntimeException { Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); Update update = new Update(); update.set("status", status); final WriteResult writeResult = template.updateFirst(query, update, MongoAdapter.class, collectionName); if (writeResult.getN() <= 0) { throw new MythRuntimeException(ERROR); } return CommonConstant.SUCCESS; }
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(); }
/** * 更新对象 * @param user */ @Override public int updateUser(UserEntity user) { Query query=new Query(Criteria.where("id").is(user.getId())); Update update= new Update().set("userName", user.getUserName()).set("passWord", user.getPassWord()); //更新查询返回结果集的第一条 WriteResult result =mongoTemplate.updateFirst(query,update,UserEntity.class); //更新查询返回结果集的所有 // mongoTemplate.updateMulti(query,update,UserEntity.class); if(result!=null) return result.getN(); else return 0; }
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(); }