use of org.springframework.data.mongodb.core.query.Update in project spring-boot-examples by ityouknow.
the class UserDaoImpl method updateUser.
/**
* 更新对象
* @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;
}
use of org.springframework.data.mongodb.core.query.Update in project spring-integration by spring-projects.
the class MongoDbMessageStore method getNextId.
private int getNextId() {
Query query = Query.query(Criteria.where("_id").is(SEQUENCE_NAME));
query.fields().include(SEQUENCE);
return (Integer) this.template.findAndModify(query, new Update().inc(SEQUENCE, 1), FindAndModifyOptions.options().returnNew(true).upsert(true), Map.class, this.collectionName).get(SEQUENCE);
}
use of org.springframework.data.mongodb.core.query.Update in project Spring-Family by Sierou-Java.
the class UserServiceImpl method updateUser.
/**
* 更新对象
*
* @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);
return result != null ? result.getN() : 0;
}
use of org.springframework.data.mongodb.core.query.Update in project newton by muoncore.
the class MongoSagaRepository method updateSagaCreated.
private void updateSagaCreated(Saga saga, NewtonEvent event) {
Query query = new Query();
query.addCriteria(Criteria.where("sagaId").is(saga.getId()));
Update update = new Update();
update.set("sagaClassName", saga.getClass().getName());
update.set("sagaId", saga.getId());
update.set("eventId", event.getId());
mongoTemplate.upsert(query, update, SagaCreated.class);
}
use of org.springframework.data.mongodb.core.query.Update in project cas by apereo.
the class MongoDbWebAuthnCredentialRepository method update.
@Override
@SneakyThrows
protected void update(final String username, final Collection<CredentialRegistration> givenRecords) {
val records = givenRecords.stream().map(record -> {
if (record.getRegistrationTime() == null) {
return record.withRegistrationTime(Instant.now(Clock.systemUTC()));
}
return record;
}).collect(Collectors.toList());
val query = new Query(Criteria.where(MongoDbWebAuthnCredentialRegistration.FIELD_USERNAME).is(username)).collation(Collation.of(Locale.ENGLISH).strength(Collation.ComparisonLevel.primary()));
val collection = getProperties().getAuthn().getMfa().getWebAuthn().getMongo().getCollection();
if (records.isEmpty()) {
LOGGER.debug("No records are provided for [{}] so entry will be removed", username);
mongoTemplate.remove(query, MongoDbWebAuthnCredentialRegistration.class, collection);
} else {
val jsonRecords = getCipherExecutor().encode(WebAuthnUtils.getObjectMapper().writeValueAsString(records));
val entry = MongoDbWebAuthnCredentialRegistration.builder().records(jsonRecords).username(username).build();
val update = Update.update(MongoDbWebAuthnCredentialRegistration.FIELD_RECORDS, jsonRecords);
val result = mongoTemplate.updateFirst(query, update, collection);
if (result.getMatchedCount() <= 0) {
LOGGER.debug("Storing new registration record for [{}]", username);
mongoTemplate.save(entry, collection);
}
}
}
Aggregations