use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class SelectQueryIT method testMatchByRelatedObjectIdValue.
@Test
public void testMatchByRelatedObjectIdValue() {
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("a1");
Artist a2 = context.newObject(Artist.class);
a2.setArtistName("a2");
Painting p1 = context.newObject(Painting.class);
p1.setPaintingTitle("p1");
p1.setToArtist(a1);
Painting p2 = context.newObject(Painting.class);
p2.setPaintingTitle("p2");
p2.setToArtist(a2);
context.commitChanges();
SelectQuery<Painting> query = new SelectQuery<>(Painting.class);
query.setQualifier(ExpressionFactory.matchExp("toArtist", Cayenne.longPKForObject(a1)));
assertSame(p1, query.selectOne(context));
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class ExpressionIT method testMatch.
@Test
public void testMatch() {
assertTrue(context instanceof DataContext);
DataContext context2 = (DataContext) runtime.newContext();
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("Equals");
Painting p1 = context.newObject(Painting.class);
p1.setToArtist(a1);
p1.setPaintingTitle("painting1");
context.commitChanges();
SelectQuery<Painting> query = new SelectQuery<Painting>(Painting.class);
Expression e = Painting.TO_ARTIST.eq(a1);
query.setQualifier(e);
assertNotSame(context2, context);
List<Painting> objects = context2.select(query);
assertEquals(1, objects.size());
// 2 same objects in different contexts
assertTrue(e.match(objects.get(0)));
// we change one object - so the objects are different now
// (PersistenceState different)
a1.setArtistName("newName");
SelectQuery<Painting> q2 = new SelectQuery<Painting>(Painting.class);
Expression ex2 = Painting.TO_ARTIST.eq(a1);
q2.setQualifier(ex2);
assertTrue(ex2.match(objects.get(0)));
Artist a2 = context.newObject(Artist.class);
a2.setArtistName("Equals");
context.commitChanges();
SelectQuery<Painting> q = new SelectQuery<Painting>(Painting.class);
Expression ex = Painting.TO_ARTIST.eq(a2);
q.setQualifier(ex);
// 2 different objects in different contexts
assertFalse(ex.match(objects.get(0)));
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class ExpressionIT method testFirst.
@Test
public void testFirst() {
List<Painting> paintingList = new ArrayList<Painting>();
Painting p1 = context.newObject(Painting.class);
p1.setPaintingTitle("x1");
paintingList.add(p1);
Painting p2 = context.newObject(Painting.class);
p2.setPaintingTitle("x2");
paintingList.add(p2);
Painting p3 = context.newObject(Painting.class);
p3.setPaintingTitle("x3");
paintingList.add(p3);
Expression e1 = ExpressionFactory.likeExp("paintingTitle", "x%");
assertSame(p1, e1.first(paintingList));
Expression e3 = ExpressionFactory.matchExp("paintingTitle", "x3");
assertSame(p3, e3.first(paintingList));
Expression e4 = ExpressionFactory.matchExp("paintingTitle", "x4");
assertNull(e4.first(paintingList));
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class ASTBetweenTest method testEvaluate.
@Test
public void testEvaluate() {
// evaluate both BETWEEN and NOT_BETWEEN
Expression between = new ASTBetween(new ASTObjPath("estimatedPrice"), new BigDecimal(10d), new BigDecimal(20d));
Expression notBetween = new ASTNotBetween(new ASTObjPath("estimatedPrice"), new BigDecimal(10d), new BigDecimal(20d));
Painting noMatch = new Painting();
noMatch.setEstimatedPrice(new BigDecimal(21));
assertFalse(between.match(noMatch));
assertTrue(notBetween.match(noMatch));
Painting match1 = new Painting();
match1.setEstimatedPrice(new BigDecimal(20));
assertTrue(between.match(match1));
assertFalse(notBetween.match(match1));
Painting match2 = new Painting();
match2.setEstimatedPrice(new BigDecimal(10));
assertTrue("Failed: " + between, between.match(match2));
assertFalse("Failed: " + notBetween, notBetween.match(match2));
Painting match3 = new Painting();
match3.setEstimatedPrice(new BigDecimal(11));
assertTrue("Failed: " + between, between.match(match3));
assertFalse("Failed: " + notBetween, notBetween.match(match3));
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class ASTEqualIT method testEvaluate_TempId.
@Test
public void testEvaluate_TempId() {
Artist a1 = context.newObject(Artist.class);
Artist a2 = context.newObject(Artist.class);
Painting p1 = context.newObject(Painting.class);
Painting p2 = context.newObject(Painting.class);
Painting p3 = context.newObject(Painting.class);
p1.setToArtist(a1);
p2.setToArtist(a2);
Expression e = new ASTEqual(new ASTObjPath("toArtist"), a1.getObjectId());
assertTrue(e.match(p1));
assertFalse(e.match(p2));
assertFalse(e.match(p3));
}
Aggregations