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


Java Datastore.save方法代碼示例

本文整理匯總了Java中org.mongodb.morphia.Datastore.save方法的典型用法代碼示例。如果您正苦於以下問題:Java Datastore.save方法的具體用法?Java Datastore.save怎麽用?Java Datastore.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.mongodb.morphia.Datastore的用法示例。


在下文中一共展示了Datastore.save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDottedNames

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
@Test
public void testDottedNames() {
    ParentType parentType = new ParentType();
    EmbeddedSubtype embedded = new EmbeddedSubtype();
    embedded.setText("text");
    embedded.setNumber(42L);
    embedded.setFlag(true);
    parentType.setEmbedded(embedded);

    Datastore ds = getDs();
    ds.save(parentType);

    Query<ParentType> query = ds.find(ParentType.class)
                                .disableValidation()
                                .field("embedded.flag").equal(true);

    Assert.assertEquals(parentType, query.get());
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:19,代碼來源:TestEmbeddedValidation.java

示例2: saveObjectGraph

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
/**
 * Saves the whole object graph.
 * TODO: make a generic version for non circular graphs
 * @param ds
 */
public void saveObjectGraph(Datastore ds){
    long startTime = System.nanoTime();

    for (Person e : conversation.getParticipants()){
        ds.save(e.getStatistics());
        ds.save(e);
    }

    ds.save(conversation);
    ds.save(statistics);
    ds.save(this);
    long endTime = System.nanoTime();
    long duration = (endTime - startTime);  //divide by 1000000 to get milliseconds.
    logger.info("Time to save GlobalStatistics object: " + duration / 1000000 + "ms");
}
 
開發者ID:roberterdin,項目名稱:thatsapp,代碼行數:21,代碼來源:GlobalStatistics.java

示例3: should_save_mixed_type_lists

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
@Test
@LocalData
public void should_save_mixed_type_lists() {
    MixedTypeListClass mixed = new MixedTypeListClass();
    Serializable[] mixedList = {1, "teststring", new DummySerialiazable()};
    mixed.mixedTypeList = mixedList;
    Datastore ds = SetupConfig.get().getInjector().getInstance(Datastore.class);
    ds.save(mixed);
    MixedTypeListClass restoredMixed = ds.createQuery(MixedTypeListClass.class).get();

    assertEquals(1, restoredMixed.mixedTypeList[0]);
    assertEquals("teststring", restoredMixed.mixedTypeList[1]);
    assertNotNull(restoredMixed.mixedTypeList[2]);
    assertTrue(restoredMixed.mixedTypeList[2] instanceof DummySerialiazable);
    DummySerialiazable dummy = (DummySerialiazable) restoredMixed.mixedTypeList[2];
    assertEquals("test", dummy.test);
}
 
開發者ID:groupon,項目名稱:DotCi,代碼行數:18,代碼來源:MongoRepositoryTest.java

示例4: list

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public Iterable<Conference> list() {
	Datastore ds = getDatastore();
	if (ds.find(getEntityClass()).countAll() == 0) {
		// TODO Remove
		SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
		ds.save(Arrays.asList(
				create("Test 1", "Description 1", f.parse("2013-01-01 00:00:00"), f.parse("2013-01-03 00:00:00")),
				create("Test 2", "Description 2", f.parse("2013-02-01 00:00:00"), f.parse("2013-02-03 00:00:00")),
				create("Test 3", "Description 3", f.parse("2013-03-01 00:00:00"), f.parse("2013-03-03 00:00:00")),
				create("Test 4", "Description 4", f.parse("2013-04-01 00:00:00"), f.parse("2013-04-03 00:00:00"))
		));
		}
		catch (ParseException e) {
			// Ignore
		}
	}
	
 return super.list();
}
 
開發者ID:pd-pmueller,項目名稱:cpa,代碼行數:25,代碼來源:ConferenceServiceImpl.java

示例5: insertData

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
private void insertData() {
    final Datastore datastore = getDs();

    Channel sportChannel = new Channel("Sport channel");
    datastore.save(sportChannel);

    datastore.save(new Channel("Art channel"));

    Channel fitnessChannel = new Channel("Fitness channel");
    datastore.save(fitnessChannel);

    final List<Key<Channel>> followedChannels = new ArrayList<Key<Channel>>();
    followedChannels.add(datastore.getKey(sportChannel));
    followedChannels.add(datastore.getKey(fitnessChannel));

    datastore.save(new User("Roberto", datastore.getKey(sportChannel), followedChannels));
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:18,代碼來源:KeyMappingTest.java

示例6: shouldFindCitiesCloseToAGivenPointWithinARadiusOfMeters

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
@Test
public void shouldFindCitiesCloseToAGivenPointWithinARadiusOfMeters() {
    // given
    double latitude = 51.5286416;
    double longitude = -0.1015987;
    Datastore datastore = getDs();
    City london = new City("London", point(latitude, longitude));
    datastore.save(london);
    City manchester = new City("Manchester", point(53.4722454, -2.2235922));
    datastore.save(manchester);
    City sevilla = new City("Sevilla", point(37.3753708, -5.9550582));
    datastore.save(sevilla);

    getDs().ensureIndexes();

    // when
    List<City> citiesOrderedByDistanceFromLondon = datastore.find(City.class)
                                                            .field("location")
                                                            .near(pointBuilder().latitude(latitude)
                                                                                .longitude(longitude).build(), 200000)
                                                            .asList();

    // then
    assertThat(citiesOrderedByDistanceFromLondon.size(), is(1));
    assertThat(citiesOrderedByDistanceFromLondon.get(0), is(london));
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:27,代碼來源:GeoQueriesTest.java

示例7: shouldFindCitiesCloseToAGivenPointWithinARadiusOfMeters

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
@Test
public void shouldFindCitiesCloseToAGivenPointWithinARadiusOfMeters() {
    // given
    double latitude = 51.5286416;
    double longitude = -0.1015987;
    Datastore datastore = getDs();
    City london = new City("London", point(latitude, longitude));
    datastore.save(london);
    City manchester = new City("Manchester", point(53.4722454, -2.2235922));
    datastore.save(manchester);
    City sevilla = new City("Sevilla", point(37.3753708, -5.9550582));
    datastore.save(sevilla);

    getDs().ensureIndexes();

    // when
    List<City> citiesOrderedByDistanceFromLondon = datastore.find(City.class)
                                                            .field("location")
                                                            .near(GeoJson.point(latitude, longitude), 200000)
                                                            .asList();

    // then
    assertThat(citiesOrderedByDistanceFromLondon.size(), is(1));
    assertThat(citiesOrderedByDistanceFromLondon.get(0), is(london));
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:26,代碼來源:GeoNearQueriesTest.java

示例8: testMax

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
@Test
@SuppressWarnings("deprecation")
public void testMax() {
    final IndexedEntity a = new IndexedEntity("a");
    final IndexedEntity b = new IndexedEntity("b");
    final IndexedEntity c = new IndexedEntity("c");

    Datastore ds = getDs();

    ds.save(a);
    ds.save(b);
    ds.save(c);

    Assert.assertEquals("last", b.id, ds.find(IndexedEntity.class)
                                        .order("-id")
                                        .upperIndexBound(new BasicDBObject("testField", "c"))
                                        .get()
        .id);
    Assert.assertEquals("last", b.id, ds.find(IndexedEntity.class)
                                        .order("-id")
                                        .get(new FindOptions()
                                                 .modifier("$max", new BasicDBObject("testField", "c")))
        .id);
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:25,代碼來源:TestMaxMin.java

示例9: testMin

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
@Test
@SuppressWarnings("deprecation")
public void testMin() {
    final IndexedEntity a = new IndexedEntity("a");
    final IndexedEntity b = new IndexedEntity("b");
    final IndexedEntity c = new IndexedEntity("c");

    Datastore ds = getDs();

    ds.save(a);
    ds.save(b);
    ds.save(c);

    Assert.assertEquals("last", b.id, ds.find(IndexedEntity.class).order("id")
                                        .lowerIndexBound(new BasicDBObject("testField", "b")).get().id);

    Assert.assertEquals("last", b.id, ds.find(IndexedEntity.class).order("id")
                                        .get(new FindOptions().modifier("$min", new BasicDBObject("testField", "b")))
        .id);
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:21,代碼來源:TestMaxMin.java

示例10: testVersionsWithUpdate

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
@Test
public void testVersionsWithUpdate() {
    final ALongPrimitive initial = new ALongPrimitive();
    Datastore ds = getDs();
    ds.save(initial);

    Query<ALongPrimitive> query = ds.find(ALongPrimitive.class)
                                 .field("id").equal(initial.getId());
    UpdateOperations<ALongPrimitive> update = ds.createUpdateOperations(ALongPrimitive.class)
                                                .set("text", "some new value");
    UpdateResults results = ds.update(query, update);
    assertEquals(1, results.getUpdatedCount());
    ALongPrimitive postUpdate = ds.get(ALongPrimitive.class, initial.getId());

    Assert.assertEquals(initial.version + 1, postUpdate.version);
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:17,代碼來源:VersionTest.java

示例11: testCRUD

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
@Test
public void testCRUD(){
    // CREATE
    Datastore ds = new Morphia().createDatastore(new MongoClient(globalProperties.getProperty("mongoClientHostname")), globalProperties.getProperty("dbTestName"));
    Conversation conversation = new Conversation();
    conversation.addMessage(new Message().fillWithRandom());
    conversation.addMessage(new Message().fillWithRandom());
    conversation.addMessage(new Message().fillWithRandom());

    GlobalStatistics globalStatistics = new GlobalStatistics(conversation);
    globalStatistics.getStatistics().fillWithRandom();

    for (Message message : conversation.getMessages()){
        message.getSender().getStatistics().fillWithRandom();
    }

    globalStatistics.saveObjectGraph(ds);
    assertNotNull(conversation.getId());

    // UPDATE and READ
    ObjectId convId = conversation.getId();
    conversation.addMessage(new Message().fillWithRandom());

    conversation.getParticipants().stream()
            .forEach(e -> {
                        ds.save(e.getStatistics());
                        ds.save(e);
                    }
            );

    ds.save(conversation);

    Conversation retrievedConv = ds.find(Conversation.class, "id", convId).get();

    assertEquals(retrievedConv.getMessages().size(), 4);

    // DELETE
    ds.findAndDelete(ds.createQuery(Conversation.class).filter("id", convId));
    assertEquals(ds.find(Conversation.class, "id", convId).asList().size(), 0);
}
 
開發者ID:roberterdin,項目名稱:thatsapp,代碼行數:41,代碼來源:EnvironmentTests.java

示例12: assignNextBuildNumber

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
public int assignNextBuildNumber(final DynamicProject project) {
    final Datastore datastore = getDatastore();
    BuildNumberCounter seq = datastore.findAndModify(
        datastore.find(BuildNumberCounter.class, "key = ", project.getFullName()), // query
        datastore.createUpdateOperations(BuildNumberCounter.class).inc("counter") // update
    );
    if (seq == null) {
        seq = new BuildNumberCounter(project.getFullName(), 1);
        datastore.save(seq);
    }

    return seq.getCounter();
}
 
開發者ID:groupon,項目名稱:DotCi,代碼行數:14,代碼來源:DynamicProjectRepository.java

示例13: list

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public Iterable<Room> list() {
	Datastore ds = getDatastore();
	if (ds.find(getEntityClass()).countAll() == 0) {
		// TODO Remove
		ds.save(Arrays.asList(
				create("Room 1", 10),
				create("Room 2", 15),
				create("Room 3", 5),
				create("Room 4", 30)
		));
	}
 return super.list();
}
 
開發者ID:pd-pmueller,項目名稱:cpa,代碼行數:18,代碼來源:RoomServiceImpl.java

示例14: list

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public Iterable<Speaker> list() {
	Datastore ds = getDatastore();
	if (ds.find(getEntityClass()).countAll() == 0) {
		// TODO Remove
		ds.save(Arrays.asList(
				create("Speaker 1", "An anonymous speaker"),
				create("Speaker 2", "An anonymous speaker"),
				create("Speaker 3", "An anonymous speaker"),
				create("Speaker 4", "An anonymous speaker")
		));
	}
 return super.list();
}
 
開發者ID:pd-pmueller,項目名稱:cpa,代碼行數:18,代碼來源:SpeakerServiceImpl.java

示例15: shouldNotCreateAnIndexWhenAnIndexedEntityIsMarkedAsNotSaved

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
@Test
public void shouldNotCreateAnIndexWhenAnIndexedEntityIsMarkedAsNotSaved() {
    // given
    getMorphia().map(IndexOnValue.class, NoIndexes.class);
    Datastore ds = getDs();

    // when
    ds.ensureIndexes();
    ds.save(new IndexOnValue());
    ds.save(new NoIndexes());

    // then
    List<DBObject> indexes = getDb().getCollection("NoIndexes").getIndexInfo();
    assertEquals(1, indexes.size());
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:16,代碼來源:TestIndexed.java


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