示例#1
0
  @Test
  public void testMapOfListsEmb() throws Exception {
    MorphiumSingleton.get().dropCollection(MapListObject.class);

    CMapListObject o = new CMapListObject();
    Map<String, List<EmbObj>> m = new HashMap<String, List<EmbObj>>();
    List<EmbObj> lst = new ArrayList<EmbObj>();
    lst.add(new EmbObj("bla", 12));
    lst.add(new EmbObj("fasel", 42));
    m.put("m1", lst);

    lst = new ArrayList<EmbObj>();
    lst.add(new EmbObj("foo", 42452));
    lst.add(new EmbObj("bar", 2));
    lst.add(new EmbObj("grin", 7331));
    m.put("m2", lst);
    o.setMap4(m);

    MorphiumSingleton.get().store(o);

    Query<CMapListObject> q =
        MorphiumSingleton.get().createQueryFor(CMapListObject.class).f("id").eq(o.getId());
    q.setReadPreferenceLevel(ReadPreferenceLevel.PRIMARY);
    CMapListObject ml = q.get();
    assert (ml.getMap4().get("m1").get(1).getTest().equals("fasel"));
    assert (ml.getMap4().get("m1").get(1).getValue() == 42);
    assert (ml.getMap4().get("m2").get(2).getTest().equals("grin"));
    assert (ml.getMap4().get("m2").get(2).getValue() == 7331);
  }
示例#2
0
  @Test
  public void partialUpdateTest() throws Exception {
    MorphiumSingleton.get().clearCollection(PartUpdTestObj.class);
    PartUpdTestObj o = new PartUpdTestObj();
    o.setName("1st");
    o.setValue(5);
    MorphiumSingleton.get().store(o);
    waitForWrites();

    Query<PartUpdTestObj> q = MorphiumSingleton.get().createQueryFor(PartUpdTestObj.class);
    q = q.f("value").eq(5);
    PartUpdTestObj po = q.get();
    assert (po.getValue() == o.getValue()) : "Values different?";
    assert (po.getName().equals(o.getName())) : "Names different?";
    assert (po instanceof PartiallyUpdateable) : "No partial updateable?";
    po.inc();
    assert (((PartiallyUpdateable) po).getAlteredFields().contains("value")) : "Value not changed?";
    MorphiumSingleton.get().store(po);

    po.setName("neuer Name");
    assert (!((PartiallyUpdateable) po).getAlteredFields().contains("value"))
        : "Value still in altered fields?";
    assert (((PartiallyUpdateable) po).getAlteredFields().contains("name")) : "Name not changed?";
    MorphiumSingleton.get().store(po);
    waitForWrites();
    q.setReadPreferenceLevel(ReadPreferenceLevel.PRIMARY);
    po = q.q().f("value").eq(6).get();
    assert (po.getName().equals("neuer Name")) : "Name not changed?";
  }