use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class SyncMessageTest method testConstructor.
@Test
public void testConstructor() {
ObjectContext source = mock(ObjectContext.class);
GraphDiff diff = new CompoundDiff();
SyncMessage message = new SyncMessage(source, DataChannel.FLUSH_NOCASCADE_SYNC, diff);
assertSame(source, message.getSource());
assertEquals(DataChannel.FLUSH_NOCASCADE_SYNC, message.getType());
assertSame(diff, message.getSenderChanges());
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class SyncMessageTest method testConstructorInvalid.
@Test
public void testConstructorInvalid() {
ObjectContext source = mock(ObjectContext.class);
new SyncMessage(source, DataChannel.FLUSH_NOCASCADE_SYNC, new CompoundDiff());
new SyncMessage(source, DataChannel.FLUSH_CASCADE_SYNC, new CompoundDiff());
new SyncMessage(null, DataChannel.ROLLBACK_CASCADE_SYNC, new CompoundDiff());
int bogusType = 45678;
try {
new SyncMessage(source, bogusType, new CompoundDiff());
fail("invalid type was allowed to go unnoticed...");
} catch (IllegalArgumentException e) {
}
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class SessionContextRequestHandler method requestStart.
public void requestStart(ServletRequest request, ServletResponse response) {
CayenneRuntime.bindThreadInjector(injector);
if (request instanceof HttpServletRequest) {
// this forces session creation if it does not exist yet
HttpSession session = ((HttpServletRequest) request).getSession();
ObjectContext context;
synchronized (session) {
context = (ObjectContext) session.getAttribute(SESSION_CONTEXT_KEY);
if (context == null) {
context = injector.getInstance(ObjectContextFactory.class).createContext();
session.setAttribute(SESSION_CONTEXT_KEY, context);
}
}
BaseContext.bindThreadObjectContext(context);
}
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class PersistentObjectHolderTest method testInvalidate.
@Test
public void testInvalidate() {
ObjectContext context = mock(ObjectContext.class);
ClientMtTable2 o = new ClientMtTable2();
o.setPersistenceState(PersistenceState.COMMITTED);
o.setObjectContext(context);
PersistentObjectHolder holder = new PersistentObjectHolder(o, ClientMtTable2.TABLE1_PROPERTY);
assertTrue(holder.isFault());
ClientMtTable1 o1 = new ClientMtTable1();
o1.setObjectContext(context);
holder.setValueDirectly(o1);
holder.invalidate();
assertTrue(holder.isFault());
assertNull(holder.value);
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class ShallowMergeOperationIT method testMerge_NoOverride.
@Test
public void testMerge_NoOverride() throws Exception {
createArtistsDataSet();
ObjectContext childContext = runtime.newContext(context);
final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
int modifiedId = 33003;
final Artist modified = (Artist) Cayenne.objectForQuery(context, new ObjectIdQuery(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, modifiedId)));
final Artist peerModified = (Artist) Cayenne.objectForQuery(childContext, new ObjectIdQuery(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, modifiedId)));
modified.setArtistName("M1");
peerModified.setArtistName("M2");
assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
assertEquals(PersistenceState.MODIFIED, peerModified.getPersistenceState());
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Persistent peerModified2 = op.merge(modified);
assertSame(peerModified, peerModified2);
assertEquals(PersistenceState.MODIFIED, peerModified2.getPersistenceState());
assertEquals("M2", peerModified.getArtistName());
assertEquals("M1", modified.getArtistName());
}
});
}
Aggregations