コード例 #1
0
  @Test
  public void testRefreshingToOne() throws Exception {

    createOneArtistOnePaintingDataSet();

    Painting p = Cayenne.objectForPK(context, Painting.class, 1);

    // resolve artist once before running non-refreshing query, to check that we do
    // not refresh the object

    Artist a = Cayenne.objectForPK(context, Artist.class, 1);
    long v = a.getSnapshotVersion();
    int writeCalls = a.getPropertyWrittenDirectly();
    assertEquals("a1", a.getArtistName());

    assertEquals(1, tArtist.update().set("ARTIST_NAME", "a2").where("ARTIST_ID", 1).execute());

    RelationshipQuery toOne =
        new RelationshipQuery(p.getObjectId(), Painting.TO_ARTIST_PROPERTY, true);

    List<Artist> related = context.performQuery(toOne);
    assertEquals(1, related.size());
    assertTrue(related.contains(a));
    assertEquals("a2", a.getArtistName());
    assertTrue(
        "Looks like relationship query didn't cause a snapshot refresh",
        v < a.getSnapshotVersion());
    assertTrue(
        "Looks like relationship query didn't cause a snapshot refresh",
        writeCalls < a.getPropertyWrittenDirectly());
  }
コード例 #2
0
  @Test
  public void testEvaluate() {
    Expression e = new ASTGreaterOrEqual(new ASTObjPath("estimatedPrice"), new BigDecimal(10000d));

    Painting noMatch = new Painting();
    noMatch.setEstimatedPrice(new BigDecimal(9999));
    assertFalse(e.match(noMatch));

    Painting match1 = new Painting();
    match1.setEstimatedPrice(new BigDecimal(10000));
    assertTrue(e.match(match1));

    Painting match = new Painting();
    match.setEstimatedPrice(new BigDecimal(10001));
    assertTrue("Failed: " + e, e.match(match));
  }