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


Java Datastore.update方法代碼示例

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


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

示例1: 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

示例2: deleteAuthorReferences

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
public void deleteAuthorReferences(Author author) {

		Datastore ds = getDatastore();

		UpdateOperations<Post> ops = ds.createUpdateOperations(Post.class)
				.unset("author");
		ds.update(ds.createQuery(Post.class).field("author").equal(author), ops);
	}
 
開發者ID:machadolucas,項目名稱:avanto,代碼行數:9,代碼來源:PostDAO.java

示例3: changeIssue

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
public static boolean changeIssue(String _id,String title, String info,
		String requirement, String specialty, String total) {
	try {
		Datastore ds = MongoDBUtil.getDatastore();
		ds.update(ds.find(Issue.class).filter("_id", new ObjectId(_id)),
				ds.createUpdateOperations(Issue.class)
				.set("title", title).set("info", info).set("requirement", requirement)
				.set("specialty", specialty).set("total", total));
				
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
開發者ID:findix,項目名稱:GPMS,代碼行數:16,代碼來源:IssueDAO.java

示例4: selectSubject

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
public static String selectSubject(String title){
	Datastore ds = MongoDBUtil.getDatastore();
	Issue issue=ds.find(Issue.class).filter("title", title).get();
	if(issue.getRemain()>0){
		ds.update(issue, 
				ds.createUpdateOperations(Issue.class).set("remain", issue.getRemain()-1));
		return issue.getTeacher();
	}
	else return null;
}
 
開發者ID:findix,項目名稱:GPMS,代碼行數:11,代碼來源:IssueDAO.java

示例5: addSubject

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
public static boolean addSubject(String no, String firstChoice,
		String secondChoice, String thirdChoice) {
	try {
		String teacher;
		Datastore ds = MongoDBUtil.getDatastore();
		ds.update(
				ds.find(Student.class).filter("no", no),
				ds.createUpdateOperations(Student.class)
						.set("firstChoice", firstChoice)
						.set("secondChoice", secondChoice)
						.set("thirdChoice", thirdChoice));
		if((teacher=IssueDAO.selectSubject(firstChoice))!=null){
			ds.update(
					ds.find(Student.class).filter("no", no),
					ds.createUpdateOperations(Student.class)
							.set("teacher", teacher).set("issue", firstChoice));
		}else if((teacher=IssueDAO.selectSubject(secondChoice))!=null){
			ds.update(
					ds.find(Student.class).filter("no", no),
					ds.createUpdateOperations(Student.class)
							.set("teacher", teacher).set("issue", secondChoice));
		}else if((teacher=IssueDAO.selectSubject(thirdChoice))!=null){
			ds.update(
					ds.find(Student.class).filter("no", no),
					ds.createUpdateOperations(Student.class)
							.set("teacher", teacher).set("issue", thirdChoice));
		}
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
開發者ID:findix,項目名稱:GPMS,代碼行數:34,代碼來源:StudentDAO.java

示例6: main

import org.mongodb.morphia.Datastore; //導入方法依賴的package包/類
public static void main(final String[] args) throws UnknownHostException {
    final Morphia morphia = new Morphia();

    // tell morphia where to find your classes
    // can be called multiple times with different packages or classes
    morphia.mapPackage("org.mongodb.morphia.example");

    // create the Datastore connecting to the database running on the default port on the local host
    final Datastore datastore = morphia.createDatastore(new MongoClient(), "morphia_example");
    datastore.getDB().dropDatabase();
    datastore.ensureIndexes();

    final Employee elmer = new Employee("Elmer Fudd", 50000.0);
    datastore.save(elmer);

    final Employee daffy = new Employee("Daffy Duck", 40000.0);
    datastore.save(daffy);

    final Employee pepe = new Employee("Pepé Le Pew", 25000.0);
    datastore.save(pepe);

    elmer.getDirectReports().add(daffy);
    elmer.getDirectReports().add(pepe);

    datastore.save(elmer);

    Query<Employee> query = datastore.find(Employee.class);
    final List<Employee> employees = query.asList();

    Assert.assertEquals(3, employees.size());

    List<Employee> underpaid = datastore.find(Employee.class)
                                        .filter("salary <=", 30000)
                                        .asList();
    Assert.assertEquals(1, underpaid.size());

    underpaid = datastore.find(Employee.class)
                         .field("salary").lessThanOrEq(30000)
                         .asList();
    Assert.assertEquals(1, underpaid.size());

    final Query<Employee> underPaidQuery = datastore.find(Employee.class)
                                                    .filter("salary <=", 30000);
    final UpdateOperations<Employee> updateOperations = datastore.createUpdateOperations(Employee.class)
                                                                 .inc("salary", 10000);

    final UpdateResults results = datastore.update(underPaidQuery, updateOperations);

    Assert.assertEquals(1, results.getUpdatedCount());

    final Query<Employee> overPaidQuery = datastore.find(Employee.class)
                                                   .filter("salary >", 100000);
    datastore.delete(overPaidQuery);
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:55,代碼來源:QuickTour.java

示例7: testEmbeddedClassname

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

    Root r = new Root();
    r.singleA = new A();
    ds.save(r);

    ds.update(ds.find(Root.class), ds.createUpdateOperations(Root.class).addToSet("aList", new A()));
    r = ds.get(Root.class, "id");
    DBObject aRaw = r.singleA.raw;

    // Test that singleA does not contain the class name
    Assert.assertFalse(aRaw.containsField(Mapper.CLASS_NAME_FIELDNAME));

    // Test that aList does not contain the class name
    aRaw = r.aList.get(0).raw;
    Assert.assertFalse(aRaw.containsField(Mapper.CLASS_NAME_FIELDNAME));

    // Test that bList does not contain the class name of the subclass
    ds.update(ds.find(Root.class), ds.createUpdateOperations(Root.class).addToSet("bList", new B()));
    r = ds.get(Root.class, "id");

    aRaw = r.aList.get(0).raw;
    Assert.assertFalse(aRaw.containsField(Mapper.CLASS_NAME_FIELDNAME));

    DBObject bRaw = r.bList.get(0).getRaw();
    Assert.assertFalse(bRaw.containsField(Mapper.CLASS_NAME_FIELDNAME));

    ds.delete(ds.find(Root.class));

    //test saving an B in aList, and it should have the classname.
    Root entity = new Root();
    entity.singleA = new B();
    ds.save(entity);
    ds.update(ds.find(Root.class), ds.createUpdateOperations(Root.class).addToSet("aList", new B()));
    r = ds.get(Root.class, "id");

    // test that singleA.raw *does* contain the classname because we stored a subclass there
    aRaw = r.singleA.raw;
    Assert.assertTrue(aRaw.containsField(Mapper.CLASS_NAME_FIELDNAME));
    DBObject bRaw2 = r.aList.get(0).raw;
    Assert.assertTrue(bRaw2.containsField(Mapper.CLASS_NAME_FIELDNAME));
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:45,代碼來源:TestEmbeddedClassname.java


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