use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class ToManyListIT method testSavedUnresolvedMerge.
@Test
public void testSavedUnresolvedMerge() throws Exception {
ToManyList list = createForExistingArtist();
Painting p1 = context.newObject(Painting.class);
p1.setPaintingTitle("p1");
// list being tested is a separate copy from
// the relationship list that Artist has, so adding a painting
// here will not add the painting to the array being tested
((Artist) list.getRelationshipOwner()).addToPaintingArray(p1);
context.commitChanges();
// immediately tag Artist as MODIFIED, since we are messing up with relationship
// bypassing normal CayenneDataObject methods
list.getRelationshipOwner().setPersistenceState(PersistenceState.MODIFIED);
assertTrue("List must be unresolved...", list.isFault());
list.add(p1);
assertTrue("List must be unresolved when adding an object...", list.isFault());
assertTrue(addedToUnresolved(list).contains(p1));
Painting p2 = context.newObject(Painting.class);
list.add(p2);
assertTrue("List must be unresolved when adding an object...", list.isFault());
assertTrue(addedToUnresolved(list).contains(p2));
// now resolve the list and see how merge worked
int size = list.size();
assertFalse("List must be resolved after checking a size...", list.isFault());
assertEquals(2, size);
assertTrue(getValue(list).contains(p2));
assertTrue(getValue(list).contains(p1));
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class ToManyListIT method testNewAddRemove.
@Test
public void testNewAddRemove() throws Exception {
ToManyList list = createForNewArtist();
assertFalse("Expected resolved list when created with a new object", list.isFault());
assertEquals(0, list.size());
Painting p1 = context.newObject(Painting.class);
list.add(p1);
assertEquals(1, list.size());
Painting p2 = context.newObject(Painting.class);
list.add(p2);
assertEquals(2, list.size());
list.remove(p1);
assertEquals(1, list.size());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class ToManyListIT method testSavedUnresolvedAddRemove.
@Test
public void testSavedUnresolvedAddRemove() throws Exception {
ToManyList list = createForExistingArtist();
// immediately tag Artist as MODIFIED, since we are messing up with relationship
// bypassing normal CayenneDataObject methods
list.getRelationshipOwner().setPersistenceState(PersistenceState.MODIFIED);
assertTrue("List must be unresolved for an existing object", list.isFault());
Painting p1 = context.newObject(Painting.class);
list.add(p1);
assertTrue("List must be unresolved when adding an object...", list.isFault());
assertTrue(addedToUnresolved(list).contains(p1));
Painting p2 = context.newObject(Painting.class);
list.add(p2);
assertTrue("List must be unresolved when adding an object...", list.isFault());
assertTrue(addedToUnresolved(list).contains(p2));
list.remove(p1);
assertTrue("List must be unresolved when removing an object...", list.isFault());
assertFalse(addedToUnresolved(list).contains(p1));
// now resolve
int size = list.size();
assertFalse("List must be resolved after checking a size...", list.isFault());
assertEquals(1, size);
assertTrue(getValue(list).contains(p2));
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class ToManyListIT method testRealRelationship.
@Test
public void testRealRelationship() throws Exception {
Artist artist = context.newObject(Artist.class);
artist.setArtistName("aaa");
Painting p1 = context.newObject(Painting.class);
p1.setPaintingTitle("p1");
context.commitChanges();
context.invalidateObjects(artist);
ToManyList list = (ToManyList) artist.getPaintingArray();
assertTrue("List must be unresolved...", list.isFault());
Painting p2 = context.newObject(Painting.class);
p2.setPaintingTitle("p2");
artist.addToPaintingArray(p1);
artist.addToPaintingArray(p2);
assertTrue("List must be unresolved...", list.isFault());
context.commitChanges();
assertTrue("List must be unresolved...", list.isFault());
int size = list.size();
assertFalse("List must be resolved...", list.isFault());
assertTrue(list.contains(p1));
assertTrue(list.contains(p2));
assertEquals(2, size);
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DefaultSelectTranslatorIT method testDbEntityQualifier_OuterJoin.
@Test
public void testDbEntityQualifier_OuterJoin() throws Exception {
SelectQuery<Painting> q = SelectQuery.query(Painting.class);
q.addOrdering("toArtist+.artistName", SortOrder.ASCENDING);
final DbEntity entity = context.getEntityResolver().getDbEntity("ARTIST");
final DbEntity middleEntity = context.getEntityResolver().getDbEntity("ARTIST_GROUP");
DefaultSelectTranslator transl = new DefaultSelectTranslator(q, dataNode.getAdapter(), dataNode.getEntityResolver());
entity.setQualifier(ExpressionFactory.exp("ARTIST_NAME = \"123\""));
middleEntity.setQualifier(ExpressionFactory.exp("GROUP_ID = 1987"));
try {
String generatedSql = transl.getSql();
// do some simple assertions to make sure all parts are in
assertNotNull(generatedSql);
assertTrue(generatedSql.startsWith("SELECT "));
assertTrue(generatedSql.indexOf(" FROM ") > 0);
if (generatedSql.contains("RTRIM")) {
assertTrue(generatedSql.indexOf("ARTIST_NAME) = ") > generatedSql.indexOf("RTRIM("));
} else if (generatedSql.contains("TRIM")) {
assertTrue(generatedSql.indexOf("ARTIST_NAME) = ") > generatedSql.indexOf("TRIM("));
} else {
assertTrue(generatedSql.indexOf("ARTIST_NAME = ") > 0);
}
} finally {
entity.setQualifier(null);
middleEntity.setQualifier(null);
}
}
Aggregations