本文整理了Java中org.springframework.data.mongodb.core.MongoTemplate.save()
方法的一些代码示例,展示了MongoTemplate.save()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MongoTemplate.save()
方法的具体详情如下:
包路径:org.springframework.data.mongodb.core.MongoTemplate
类名称:MongoTemplate
方法名:save
暂无
代码示例来源:origin: ityouknow/spring-boot-examples
/**
* 创建对象
* @param user
*/
@Override
public void saveUser(UserEntity user) {
mongoTemplate.save(user);
}
代码示例来源:origin: kaaproject/kaa
public T save(T object) {
mongoTemplate.save(object);
return object;
}
代码示例来源:origin: kaaproject/kaa
/**
* Save dto to mongo database.
* @param dto data transfer object,
* @param clazz dto class, use it for logging
* @param <V> type of dto data transfer object
* @return dto (saved instance)
*/
public <V> V save(V dto, Class<?> clazz) {
LOG.debug("Save entity of {} class", clazz.getName());
mongoTemplate.save(dto);
return dto;
}
代码示例来源:origin: spring-projects/spring-data-mongodb
@Override
public <T> T save(T objectToSave) {
Assert.notNull(objectToSave, "Object to save must not be null!");
return save(objectToSave, operations.determineEntityCollectionName(objectToSave));
}
代码示例来源:origin: kaaproject/kaa
/**
* Store an object in a database.
*
* @param object object to be stored
* @return saved object
*/
public T save(T object) {
try {
mongoTemplate.save(object);
return object;
} catch (OptimisticLockingFailureException exception) {
LOG.error("[{}] Can't update entity with version {}. Entity already changed!",
getDocumentClass(), object.getVersion());
throw new KaaOptimisticLockingFailureException(
"Can't update entity with version "
+ object.getVersion()
+ ". Entity already changed!");
} catch (DuplicateKeyException exception) {
LOG.error("[{}] Can't insert entity. Entity already exists!", getDocumentClass());
throw new KaaOptimisticLockingFailureException(
"Can't insert entity. Entity already exists!");
}
}
代码示例来源:origin: org.springframework.data/spring-data-mongodb
@Override
public <T> T save(T objectToSave) {
Assert.notNull(objectToSave, "Object to save must not be null!");
return save(objectToSave, operations.determineEntityCollectionName(objectToSave));
}
代码示例来源:origin: yu199195/Raincat
@Override
public int create(final TransactionRecover transactionRecover) {
try {
MongoAdapter mongoAdapter = new MongoAdapter();
mongoAdapter.setTransId(transactionRecover.getId());
mongoAdapter.setCreateTime(transactionRecover.getCreateTime());
mongoAdapter.setGroupId(transactionRecover.getGroupId());
mongoAdapter.setLastTime(transactionRecover.getLastTime());
mongoAdapter.setTaskId(transactionRecover.getTaskId());
mongoAdapter.setRetriedCount(transactionRecover.getRetriedCount());
mongoAdapter.setStatus(transactionRecover.getStatus());
mongoAdapter.setVersion(transactionRecover.getVersion());
final TransactionInvocation invocation = transactionRecover.getTransactionInvocation();
mongoAdapter.setTargetClass(invocation.getTargetClazz().getName());
mongoAdapter.setTargetMethod(invocation.getMethod());
mongoAdapter.setContents(objectSerializer.serialize(invocation));
mongoAdapter.setCompleteFlag(transactionRecover.getCompleteFlag());
mongoAdapter.setOperation(transactionRecover.getOperation());
template.save(mongoAdapter, collectionName);
} catch (TransactionException e) {
e.printStackTrace();
}
return ROWS;
}
代码示例来源:origin: yu199195/myth
@Override
public int create(final MythTransaction mythTransaction) {
try {
MongoAdapter mongoBean = new MongoAdapter();
mongoBean.setTransId(mythTransaction.getTransId());
mongoBean.setCreateTime(mythTransaction.getCreateTime());
mongoBean.setLastTime(mythTransaction.getLastTime());
mongoBean.setRetriedCount(mythTransaction.getRetriedCount());
mongoBean.setStatus(mythTransaction.getStatus());
mongoBean.setRole(mythTransaction.getRole());
mongoBean.setTargetClass(mythTransaction.getTargetClass());
mongoBean.setTargetMethod(mythTransaction.getTargetMethod());
final byte[] cache = objectSerializer.serialize(mythTransaction.getMythParticipants());
mongoBean.setContents(cache);
mongoBean.setErrorMsg(mythTransaction.getErrorMsg());
template.save(mongoBean, collectionName);
return CommonConstant.SUCCESS;
} catch (MythException e) {
e.printStackTrace();
return CommonConstant.ERROR;
}
}
代码示例来源:origin: yu199195/hmily
@Override
public int create(final HmilyTransaction hmilyTransaction) {
try {
MongoAdapter mongoBean = new MongoAdapter();
mongoBean.setTransId(hmilyTransaction.getTransId());
mongoBean.setCreateTime(hmilyTransaction.getCreateTime());
mongoBean.setLastTime(hmilyTransaction.getLastTime());
mongoBean.setRetriedCount(hmilyTransaction.getRetriedCount());
mongoBean.setStatus(hmilyTransaction.getStatus());
mongoBean.setRole(hmilyTransaction.getRole());
mongoBean.setPattern(hmilyTransaction.getPattern());
mongoBean.setTargetClass(hmilyTransaction.getTargetClass());
mongoBean.setTargetMethod(hmilyTransaction.getTargetMethod());
mongoBean.setConfirmMethod(hmilyTransaction.getConfirmMethod());
mongoBean.setCancelMethod(hmilyTransaction.getCancelMethod());
final byte[] cache = objectSerializer.serialize(hmilyTransaction.getHmilyParticipants());
mongoBean.setContents(cache);
template.save(mongoBean, collectionName);
} catch (HmilyException e) {
e.printStackTrace();
}
return ROWS;
}
代码示例来源:origin: spring-projects/spring-integration
@Before
public void setUp() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory);
mongoTemplate.save(this.createPerson("Artem"), COLLECTION_NAME);
mongoTemplate.save(this.createPerson("Gary"), COLLECTION_NAME);
mongoTemplate.save(this.createPerson("Oleg"), COLLECTION_NAME);
mongoTemplate.save(this.createPerson("Xavi"), COLLECTION_NAME);
}
代码示例来源:origin: spring-projects/spring-integration
@SuppressWarnings("unchecked")
private List<Person> queryMultipleElements(Expression queryExpression) throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
MongoTemplate template = new MongoTemplate(mongoDbFactory);
template.save(this.createPerson("Manny"), "data");
template.save(this.createPerson("Moe"), "data");
template.save(this.createPerson("Jack"), "data");
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
messageSource.setBeanFactory(mock(BeanFactory.class));
messageSource.afterPropertiesSet();
return (List<Person>) messageSource.receive().getPayload();
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@MongoDbAvailable
public void testWithQueryExpression() throws Exception {
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
this.mongoInboundAdapterWithQueryExpression.start();
@SuppressWarnings("unchecked")
Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000);
assertNotNull(message);
assertEquals(1, message.getPayload().size());
assertEquals("Bob", message.getPayload().get(0).getName());
this.mongoInboundAdapterWithQueryExpression.stop();
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@MongoDbAvailable
public void testWithStringQueryExpression() throws Exception {
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
this.mongoInboundAdapterWithStringQueryExpression.start();
@SuppressWarnings("unchecked")
Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000);
assertNotNull(message);
assertEquals("Bob", message.getPayload().get(0).getName());
this.mongoInboundAdapterWithStringQueryExpression.stop();
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@MongoDbAvailable
public void testWithNamedCollection() throws Exception {
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
this.mongoInboundAdapterWithNamedCollection.start();
@SuppressWarnings("unchecked")
Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000);
assertNotNull(message);
assertEquals("Bob", message.getPayload().get(0).getName());
this.mongoInboundAdapterWithNamedCollection.stop();
this.replyChannel.purge(null);
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@MongoDbAvailable
public void testWithNamedMongoFactory() throws Exception {
this.mongoTemplate.save(this.createPerson("Bob"), "data");
this.mongoInboundAdapterNamedFactory.start();
@SuppressWarnings("unchecked")
Message<List<Document>> message = (Message<List<Document>>) replyChannel.receive(10000);
assertNotNull(message);
assertEquals("Bob", message.getPayload().get(0).get("name"));
this.mongoInboundAdapterNamedFactory.stop();
this.replyChannel.purge(null);
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@MongoDbAvailable
public void testWithNamedCollectionExpression() throws Exception {
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
this.mongoInboundAdapterWithNamedCollectionExpression.start();
@SuppressWarnings("unchecked")
Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000);
assertNotNull(message);
assertEquals("Bob", message.getPayload().get(0).getName());
this.mongoInboundAdapterWithNamedCollectionExpression.stop();
this.replyChannel.purge(null);
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@MongoDbAvailable
public void testWithDefaultMongoFactory() throws Exception {
this.mongoTemplate.save(createPerson("Bob"), "data");
this.mongoInboundAdapter.start();
@SuppressWarnings("unchecked")
Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000);
assertNotNull(message);
assertEquals("Bob", message.getPayload().get(0).getName());
assertNotNull(this.replyChannel.receive(10000));
this.mongoInboundAdapter.stop();
this.replyChannel.purge(null);
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@MongoDbAvailable
public void testWithMongoConverter() throws Exception {
this.mongoTemplate.save(this.createPerson("Bob"), "data");
this.mongoInboundAdapterWithConverter.start();
@SuppressWarnings("unchecked")
Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000);
assertNotNull(message);
assertEquals("Bob", message.getPayload().get(0).getName());
assertNotNull(replyChannel.receive(10000));
this.mongoInboundAdapterWithConverter.stop();
this.replyChannel.purge(null);
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@MongoDbAvailable
public void testWithMongoTemplate() throws Exception {
this.mongoTemplate.save(this.createPerson("Bob"), "data");
this.mongoInboundAdapterWithTemplate.start();
@SuppressWarnings("unchecked")
Message<Person> message = (Message<Person>) replyChannel.receive(10000);
assertNotNull(message);
assertEquals("Bob", message.getPayload().getName());
this.mongoInboundAdapterWithTemplate.stop();
this.replyChannel.purge(null);
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@MongoDbAvailable
public void testWithOnSuccessDisposition() throws Exception {
this.mongoTemplate.save(createPerson("Bob"), "data");
this.inboundAdapterWithOnSuccessDisposition.start();
assertNotNull(replyChannel.receive(10000));
assertNull(replyChannel.receive(100));
assertNotNull(this.afterCommitChannel.receive(10000));
assertNull(this.mongoTemplate.findOne(new Query(Criteria.where("name").is("Bob")), Person.class, "data"));
this.inboundAdapterWithOnSuccessDisposition.stop();
this.replyChannel.purge(null);
}
内容来源于网络,如有侵权,请联系作者删除!