本文整理汇总了Java中org.springframework.data.mongodb.core.MongoTemplate.save方法的典型用法代码示例。如果您正苦于以下问题:Java MongoTemplate.save方法的具体用法?Java MongoTemplate.save怎么用?Java MongoTemplate.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.mongodb.core.MongoTemplate
的用法示例。
在下文中一共展示了MongoTemplate.save方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addUsers
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
@ChangeSet(order = "02", author = "initiator", id = "02-addUsers")
public void addUsers(MongoTemplate mongoTemplate) {
Authority adminAuthority = new Authority();
adminAuthority.setName(AuthoritiesConstants.ADMIN);
Authority userAuthority = new Authority();
userAuthority.setName(AuthoritiesConstants.USER);
User adminUser = new User();
adminUser.setId("user-0");
adminUser.setLogin("admin");
adminUser.setPassword("$2a$10$gSAhZrxMllrbgj/kkK9UceBPpChGWJA7SYIb1Mqo.n5aNLq1/oRrC");
adminUser.setFirstName("admin");
adminUser.setLastName("Administrator");
adminUser.setEmail("[email protected]");
adminUser.setActivated(true);
adminUser.setLangKey("en");
adminUser.getAuthorities().add(userAuthority);
adminUser.setCreatedBy(adminUser.getLogin());
adminUser.setCreatedDate(ZonedDateTime.now());
adminUser.setLastModifiedBy(adminUser.getLogin());
adminUser.setLastModifiedDate(ZonedDateTime.now());
mongoTemplate.save(adminUser);
}
示例2: defaultRepo
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
@Test
public void defaultRepo() {
// Prepare context
Map<String, Object> props = new HashMap<>();
props.put("spring.data.mongodb.database", "testdb");
context = new SpringApplicationBuilder(TestConfiguration.class).web(false).properties(props).run();
// Prepare test
MongoTemplate mongoTemplate = this.context.getBean(MongoTemplate.class);
mongoTemplate.dropCollection("testapp");
MongoPropertySource ps = new MongoPropertySource();
ps.getSource().put("testkey", "testval");
mongoTemplate.save(ps, "testapp");
// Test
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
Environment environment = repository.findOne("testapp", "default", null);
assertEquals("testapp-default", environment.getPropertySources().get(0).getName());
assertEquals(1, environment.getPropertySources().size());
assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("testkey"));
assertEquals("testval", environment.getPropertySources().get(0).getSource().get("testkey"));
}
开发者ID:spring-cloud-incubator,项目名称:spring-cloud-config-server-mongodb,代码行数:21,代码来源:MongoEnvironmentRepositoryTests.java
示例3: nestedPropertySource
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
@Test
public void nestedPropertySource() {
// Prepare context
Map<String, Object> props = new HashMap<>();
props.put("spring.data.mongodb.database", "testdb");
context = new SpringApplicationBuilder(TestConfiguration.class).web(false).properties(props).run();
// Prepare test
MongoTemplate mongoTemplate = this.context.getBean(MongoTemplate.class);
mongoTemplate.dropCollection("testapp");
MongoPropertySource ps = new MongoPropertySource();
Map<String, String> inner = new HashMap<String, String>();
inner.put("inner", "value");
ps.getSource().put("outer", inner);
mongoTemplate.save(ps, "testapp");
// Test
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
Environment environment = repository.findOne("testapp", "default", null);
assertEquals("testapp-default", environment.getPropertySources().get(0).getName());
assertEquals(1, environment.getPropertySources().size());
assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("outer.inner"));
assertEquals("value", environment.getPropertySources().get(0).getSource().get("outer.inner"));
}
开发者ID:spring-cloud-incubator,项目名称:spring-cloud-config-server-mongodb,代码行数:23,代码来源:MongoEnvironmentRepositoryTests.java
示例4: repoWithProfileAndLabelInSource
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
@Test
public void repoWithProfileAndLabelInSource() {
// Prepare context
Map<String, Object> props = new HashMap<>();
props.put("spring.data.mongodb.database", "testdb");
context = new SpringApplicationBuilder(TestConfiguration.class).web(false).properties(props).run();
// Prepare test
MongoTemplate mongoTemplate = this.context.getBean(MongoTemplate.class);
mongoTemplate.dropCollection("testapp");
MongoPropertySource ps = new MongoPropertySource();
ps.setProfile("confprofile");
ps.setLabel("conflabel");
ps.getSource().put("profile", "sourceprofile");
ps.getSource().put("label", "sourcelabel");
mongoTemplate.save(ps, "testapp");
// Test
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
Environment environment = repository.findOne("testapp", "confprofile", "conflabel");
assertEquals(1, environment.getPropertySources().size());
assertEquals("testapp-confprofile-conflabel", environment.getPropertySources().get(0).getName());
assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("profile"));
assertEquals("sourceprofile", environment.getPropertySources().get(0).getSource().get("profile"));
assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("label"));
assertEquals("sourcelabel", environment.getPropertySources().get(0).getSource().get("label"));
}
开发者ID:spring-cloud-incubator,项目名称:spring-cloud-config-server-mongodb,代码行数:26,代码来源:MongoEnvironmentRepositoryTests.java
示例5: testUnReserveWithValidDevice
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
@Test
public void testUnReserveWithValidDevice() {
MongoTemplate mockMongoTemplate = EasyMock.createMock(MongoTemplate.class);
PersistableDevice persistableDev = EasyMock.createMock(PersistableDevice.class);
DawgPoundMongoService dawgPoundService = new DawgPoundMongoService();
ReflectionTestUtils.setField(dawgPoundService, "mongoTemplate", mockMongoTemplate);
EasyMock.expect(mockMongoTemplate.findById(TestConstants.DEVICE_ID, PersistableDevice.class, TestConstants.COLLECTION_NAME )).andReturn(persistableDev);
EasyMock.expect(persistableDev.unreserve()).andReturn(TestConstants.TOKEN);
mockMongoTemplate.save(persistableDev, TestConstants.COLLECTION_NAME);
EasyMock.replay(mockMongoTemplate, persistableDev);
Assert.assertEquals(dawgPoundService.unreserve(TestConstants.DEVICE_ID), TestConstants.TOKEN);
EasyMock.verify(mockMongoTemplate, persistableDev);
}
示例6: testOverrideReserve
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
@Test
public void testOverrideReserve() {
long expiryTime = System.currentTimeMillis()+ TestConstants.ONE_DAY_IN_MILLIS;
MongoTemplate mockMongoTemplate = EasyMock.createMock(MongoTemplate.class);
PersistableDevice persistableDev = EasyMock.createMock(PersistableDevice.class);
DawgPoundMongoService dawgPoundService = new DawgPoundMongoService();
ReflectionTestUtils.setField(dawgPoundService, "mongoTemplate", mockMongoTemplate);
EasyMock.expect(mockMongoTemplate.findById(TestConstants.DEVICE_ID, PersistableDevice.class, TestConstants.COLLECTION_NAME )).andReturn(persistableDev);
EasyMock.expect(persistableDev.unreserve()).andReturn("previous_token");
EasyMock.expect(persistableDev.reserve(TestConstants.TOKEN)).andReturn(TestConstants.TOKEN);
persistableDev.setExpiration(expiryTime);
mockMongoTemplate.save(persistableDev, TestConstants.COLLECTION_NAME);
EasyMock.replay(mockMongoTemplate,persistableDev);
Assert.assertTrue(dawgPoundService.overrideReserve(TestConstants.DEVICE_ID, TestConstants.TOKEN, expiryTime));
EasyMock.verify(mockMongoTemplate,persistableDev);
}
示例7: testValidReservation
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
@Test
public void testValidReservation() {
String newToken = "8e6488ed-60f9-487f-b4bf-83c74fa0b06a";
long expiryTime = System.currentTimeMillis()+ TestConstants.ONE_DAY_IN_MILLIS;
MongoTemplate mockMongoTemplate = EasyMock.createMock(MongoTemplate.class);
PersistableDevice persistableDev = EasyMock.createMock(PersistableDevice.class);
DawgPoundMongoService dawgPoundService = new DawgPoundMongoService();
ReflectionTestUtils.setField(dawgPoundService, "mongoTemplate", mockMongoTemplate);
EasyMock.expect(mockMongoTemplate.findById(TestConstants.DEVICE_ID, PersistableDevice.class, TestConstants.COLLECTION_NAME )).andReturn(persistableDev);
EasyMock.expect(persistableDev.isReserved()).andReturn(false);
EasyMock.expect(persistableDev.unreserve()).andReturn("previous_token");
EasyMock.expect(persistableDev.reserve(newToken)).andReturn(newToken);
persistableDev.setExpiration(expiryTime);
EasyMock.expect(persistableDev.getKeys()).andReturn(new String[] { });
persistableDev.setKeys(EasyMock.aryEq(new String[] {newToken }));
mockMongoTemplate.save(persistableDev, TestConstants.COLLECTION_NAME);
EasyMock.replay(mockMongoTemplate,persistableDev);
Assert.assertEquals(dawgPoundService.reserve(TestConstants.DEVICE_ID, newToken, expiryTime), newToken);
EasyMock.verify(mockMongoTemplate,persistableDev);
}
示例8: preLoadMongo
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
@Bean
CommandLineRunner preLoadMongo(MongoTemplate mongoTemplate) throws Exception {
return args -> {
mongoTemplate.save(new DataPropertySource("", "", new HashMap<String, Object>() {{
put("key", "value");
}}), "my-app");
};
}
示例9: addAuthorities
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
@ChangeSet(order = "01", author = "initiator", id = "01-addAuthorities")
public void addAuthorities(MongoTemplate mongoTemplate) {
Authority adminAuthority = new Authority();
adminAuthority.setName(AuthoritiesConstants.ADMIN);
Authority userAuthority = new Authority();
userAuthority.setName(AuthoritiesConstants.USER);
mongoTemplate.save(adminAuthority);
mongoTemplate.save(userAuthority);
}
示例10: addAuthorities
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
@ChangeSet(order = "01", author = "initiator", id = "01-addAuthorities")
public void addAuthorities(MongoTemplate mongoTemplate) {
Authority adminAuthority = new Authority();
adminAuthority.setName(AuthoritiesConstants.ADMIN);
Authority userAuthority = new Authority();
userAuthority.setName(AuthoritiesConstants.USER);
mongoTemplate.save(adminAuthority);
mongoTemplate.save(userAuthority);
}
示例11: createCategories
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
public static List<Category> createCategories(MongoTemplate mo) {
List<Category> categories = new ArrayList<Category>();
for (String name : categoryNames) {
Category c = createCategory(name);
mo.save(c);
categories.add(c);
}
return categories;
}
示例12: createProducts
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
public static List<Product> createProducts(List<Category> categories, MongoTemplate mo) {
List<Product> products = new ArrayList<Product>();
for (int i = 0; i < 100; i++) {
Product p = createProduct(categories);
mo.save(p);
products.add(p);
}
return products;
}
示例13: addUsers
import org.springframework.data.mongodb.core.MongoTemplate; //导入方法依赖的package包/类
@ChangeSet(order = "02", author = "initiator", id = "02-addUsers")
public void addUsers(MongoTemplate mongoTemplate) {
Authority adminAuthority = new Authority();
adminAuthority.setName(AuthoritiesConstants.ADMIN);
Authority userAuthority = new Authority();
userAuthority.setName(AuthoritiesConstants.USER);
User systemUser = new User();
systemUser.setId("user-0");
systemUser.setLogin("system");
systemUser.setPassword("$2a$10$mE.qmcV0mFU5NcKh73TZx.z4ueI/.bDWbj0T1BYyqP481kGGarKLG");
systemUser.setFirstName("");
systemUser.setLastName("System");
systemUser.setEmail("[email protected]");
systemUser.setActivated(true);
systemUser.setLangKey("en");
systemUser.setCreatedBy(systemUser.getLogin());
systemUser.setCreatedDate(Instant.now());
systemUser.getAuthorities().add(adminAuthority);
systemUser.getAuthorities().add(userAuthority);
mongoTemplate.save(systemUser);
User anonymousUser = new User();
anonymousUser.setId("user-1");
anonymousUser.setLogin("anonymoususer");
anonymousUser.setPassword("$2a$10$j8S5d7Sr7.8VTOYNviDPOeWX8KcYILUVJBsYV83Y5NtECayypx9lO");
anonymousUser.setFirstName("Anonymous");
anonymousUser.setLastName("User");
anonymousUser.setEmail("[email protected]");
anonymousUser.setActivated(true);
anonymousUser.setLangKey("en");
anonymousUser.setCreatedBy(systemUser.getLogin());
anonymousUser.setCreatedDate(Instant.now());
mongoTemplate.save(anonymousUser);
User adminUser = new User();
adminUser.setId("user-2");
adminUser.setLogin("admin");
adminUser.setPassword("$2a$10$gSAhZrxMllrbgj/kkK9UceBPpChGWJA7SYIb1Mqo.n5aNLq1/oRrC");
adminUser.setFirstName("admin");
adminUser.setLastName("Administrator");
adminUser.setEmail("[email protected]");
adminUser.setActivated(true);
adminUser.setLangKey("en");
adminUser.setCreatedBy(systemUser.getLogin());
adminUser.setCreatedDate(Instant.now());
adminUser.getAuthorities().add(adminAuthority);
adminUser.getAuthorities().add(userAuthority);
mongoTemplate.save(adminUser);
User userUser = new User();
userUser.setId("user-3");
userUser.setLogin("user");
userUser.setPassword("$2a$10$VEjxo0jq2YG9Rbk2HmX9S.k1uZBGYUHdUcid3g/vfiEl7lwWgOH/K");
userUser.setFirstName("");
userUser.setLastName("User");
userUser.setEmail("[email protected]");
userUser.setActivated(true);
userUser.setLangKey("en");
userUser.setCreatedBy(systemUser.getLogin());
userUser.setCreatedDate(Instant.now());
userUser.getAuthorities().add(userAuthority);
mongoTemplate.save(userUser);
}