當前位置: 首頁>>代碼示例>>Java>>正文


Java MongoTemplate.save方法代碼示例

本文整理匯總了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);
}
 
開發者ID:benoyprakash,項目名稱:java-hostel,代碼行數:24,代碼來源:InitialSetupMigration.java

示例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);
}
 
開發者ID:Comcast,項目名稱:dawg,代碼行數:17,代碼來源:DawgPoundMongoServiceTest.java

示例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);
}
 
開發者ID:Comcast,項目名稱:dawg,代碼行數:21,代碼來源:DawgPoundMongoServiceTest.java

示例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);
}
 
開發者ID:Comcast,項目名稱:dawg,代碼行數:26,代碼來源:DawgPoundMongoServiceTest.java

示例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");
    };
}
 
開發者ID:cynicLT,項目名稱:spring-cloud-config-server-data,代碼行數:9,代碼來源:MongoDataConfigServerTest.java

示例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);
}
 
開發者ID:benoyprakash,項目名稱:java-hostel,代碼行數:10,代碼來源:InitialSetupMigration.java

示例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);
}
 
開發者ID:alikemalocalan,項目名稱:MicroBlog,代碼行數:10,代碼來源:InitialSetupMigration.java

示例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;

}
 
開發者ID:jvalenciag,項目名稱:VaadinSpringShiroMongoDB,代碼行數:11,代碼來源:MockDataGenerator.java

示例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;
}
 
開發者ID:jvalenciag,項目名稱:VaadinSpringShiroMongoDB,代碼行數:11,代碼來源:MockDataGenerator.java

示例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);
}
 
開發者ID:alikemalocalan,項目名稱:MicroBlog,代碼行數:65,代碼來源:InitialSetupMigration.java


注:本文中的org.springframework.data.mongodb.core.MongoTemplate.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。