use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class ColumnSelectIT method testNestedContextMixedResult.
@Test
public void testNestedContextMixedResult() {
ObjectContext childContext = runtime.newContext(context);
Property<Artist> artistProperty = Property.createSelf(Artist.class);
List<Object[]> data = ObjectSelect.columnQuery(Artist.class, Artist.ARTIST_NAME, artistProperty).select(childContext);
assertEquals(20, data.size());
for (Object[] next : data) {
assertTrue(next[0] instanceof String);
assertTrue(next[1] instanceof Artist);
}
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class DataContextEntityWithMeaningfulPKIT method testToManyRelationshipWithMeaningfulPK1.
@Test
public void testToManyRelationshipWithMeaningfulPK1() {
MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
obj.setPkAttribute(1000);
obj.setDescr("aaa-aaa");
context.commitChanges();
// must be able to resolve to-many relationship
ObjectContext context = runtime.newContext();
List<MeaningfulPKTest1> objects = ObjectSelect.query(MeaningfulPKTest1.class).select(context);
assertEquals(1, objects.size());
obj = objects.get(0);
assertEquals(0, obj.getMeaningfulPKDepArray().size());
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class DataContextEntityWithMeaningfulPKIT method testMeaningfulIntegerPK.
@Test
public void testMeaningfulIntegerPK() {
MeaningfulPkTest2 obj1 = context.newObject(MeaningfulPkTest2.class);
obj1.setIntegerAttribute(10);
obj1.setPkAttribute(1);
MeaningfulPkTest2 obj2 = context.newObject(MeaningfulPkTest2.class);
obj2.setIntegerAttribute(20);
obj2.setPkAttribute(2);
context.commitChanges();
ObjectContext context = runtime.newContext();
List<MeaningfulPkTest2> objects = ObjectSelect.query(MeaningfulPkTest2.class).select(context);
assertEquals(2, objects.size());
assertEquals(Integer.valueOf(1), obj1.getPkAttribute());
assertEquals(Integer.valueOf(2), obj2.getPkAttribute());
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class DataContextLocalObjectIT method testLocalObject_TempId_NestedContext.
@Test
public void testLocalObject_TempId_NestedContext() throws Exception {
final Artist a1 = context1.newObject(Artist.class);
final ObjectContext nestedContext = runtime.newContext(context1);
interceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Artist a3 = nestedContext.localObject(a1);
assertNotSame(a3, a1);
assertEquals(a3.getObjectId(), a1.getObjectId());
assertSame(nestedContext, a3.getObjectContext());
}
});
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class DataContextDataChannelEventsIT method testChangeEventOnChildChange.
@Test
public void testChangeEventOnChildChange() throws Exception {
Artist a = context.newObject(Artist.class);
a.setArtistName("X");
context.commitChanges();
final MockChannelListener listener = new MockChannelListener();
EventUtil.listenForChannelEvents(context, listener);
ObjectContext childContext = runtime.newContext(context);
Artist a1 = childContext.localObject(a);
a1.setArtistName("Y");
childContext.commitChangesToParent();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertFalse(listener.graphCommitted);
assertTrue(listener.graphChanged);
assertFalse(listener.graphRolledBack);
}
}.runTest(10000);
}
Aggregations