use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class ServerRuntimeBuilderIT method test_UnnamedDomain_CustomNameProjectFile.
/**
* Test case for CAY-2265
*/
@Test
public void test_UnnamedDomain_CustomNameProjectFile() {
localRuntime = new ServerRuntimeBuilder(null).addConfigs(CayenneProjects.CUSTOM_NAME_PROJECT).build();
assertEquals("cayenne", localRuntime.getDataDomain().getName());
ObjectContext context = localRuntime.newContext();
assertNotNull(context);
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class ServerRuntimeTest method testGetDataChannel_CustomModule.
@Test
public void testGetDataChannel_CustomModule() {
final DataChannel channel = new DataChannel() {
public EntityResolver getEntityResolver() {
return null;
}
public EventManager getEventManager() {
return null;
}
public QueryResponse onQuery(ObjectContext originatingContext, Query query) {
return null;
}
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
return null;
}
};
Module module = binder -> binder.bind(DataChannel.class).toInstance(channel);
ServerRuntime runtime = new ServerRuntime(Collections.singleton(module));
assertSame(channel, runtime.getChannel());
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class VerticalInheritanceIT method testUpdateRelation_Sub3.
/**
* @link https://issues.apache.org/jira/browse/CAY-2282
*/
@Test
public void testUpdateRelation_Sub3() throws Exception {
TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
ivRootTable.insert(1, "root1", null);
ivRootTable.insert(2, "root2", null);
ivRootTable.insert(3, "name", "IvSub3");
TableHelper ivSub3Table = new TableHelper(dbHelper, "IV_SUB3");
ivSub3Table.setColumns("ID", "IV_ROOT_ID");
ivSub3Table.insert(3, 1);
IvRoot root = SelectById.query(IvRoot.class, 2).selectOne(context);
IvSub3 sub3 = SelectById.query(IvSub3.class, 3).selectOne(context);
sub3.setName("new name");
sub3.setIvRoot(root);
// this will create 3 queries...
// update for name, insert for new relationship, delete for old relationship
context.commitChanges();
ObjectContext cleanContext = runtime.newContext();
IvSub3 sub3Clean = SelectById.query(IvSub3.class, 3).selectOne(cleanContext);
assertNotNull(sub3Clean);
assertNotSame(sub3, sub3Clean);
assertEquals("new name", sub3.getName());
assertNotNull(sub3Clean.getIvRoot());
assertEquals("root2", sub3Clean.getIvRoot().getName());
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class SimpleAttributeProperty method resolveFault.
protected void resolveFault(Object object) throws PropertyException {
try {
Persistent persistent = (Persistent) object;
ObjectContext context = persistent.getObjectContext();
if (context != null) {
context.prepareForAccess(persistent, getName(), false);
}
} catch (ClassCastException e) {
throw new PropertyException("Object is not a Persistent: '" + object.getClass().getName() + "'", this, object, e);
}
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedDataContextReadIT method testPrefetchingToOne.
@Test
public void testPrefetchingToOne() throws Exception {
createPrefetchingDataSet();
final ObjectContext child = runtime.newContext(context);
final ObjectId prefetchedId = ObjectId.of("Artist", Artist.ARTIST_ID_PK_COLUMN, 33001);
final List<Painting> results = ObjectSelect.query(Painting.class).orderBy(Painting.PAINTING_TITLE.asc()).prefetch(Painting.TO_ARTIST.disjoint()).select(child);
// blockQueries();
queryInterceptor.runWithQueriesBlocked(() -> {
assertEquals(2, results.size());
for (Painting o : results) {
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertSame(child, o.getObjectContext());
Artist o1 = o.getToArtist();
assertNotNull(o1);
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertSame(child, o1.getObjectContext());
assertEquals(prefetchedId, o1.getObjectId());
}
});
}
Aggregations