use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class CacheInvalidationCacheGroupsHandlerIT method invalidateE2.
@Test
public void invalidateE2() throws Exception {
ObjectContext context = runtime.newContext();
ObjectSelect<E2> g0 = ObjectSelect.query(E2.class).localCache();
ObjectSelect<E2> g1 = ObjectSelect.query(E2.class).localCache("g1");
ObjectSelect<E2> g2 = ObjectSelect.query(E2.class).localCache("g2");
ObjectSelect<E2> g3 = ObjectSelect.query(E2.class).localCache("g3");
ObjectSelect<E2> g5 = ObjectSelect.query(E2.class).localCache("g5");
assertEquals(0, g0.selectCount(context));
assertEquals(0, g1.selectCount(context));
assertEquals(0, g2.selectCount(context));
assertEquals(0, g3.selectCount(context));
assertEquals(0, g5.selectCount(context));
e2.insert(1).insert(2);
// inserted via SQL... query results are still cached...
assertEquals(0, g0.selectCount(context));
assertEquals(0, g1.selectCount(context));
assertEquals(0, g2.selectCount(context));
assertEquals(0, g3.selectCount(context));
assertEquals(0, g5.selectCount(context));
context.newObject(E2.class);
context.commitChanges();
// Typed remove will actually call untyped version, thus 4 + 2
assertEquals(4 + 2, removeGroupUntypedCounter.get());
assertEquals(2, removeGroupTypedCounter.get());
// inserted via Cayenne... "g1" and "g2" should get auto refreshed...
assertEquals(0, g0.selectCount(context));
assertEquals(3, g1.selectCount(context));
assertEquals(3, g2.selectCount(context));
assertEquals(3, g3.selectCount(context));
assertEquals(3, g5.selectCount(context));
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class CacheInvalidationCacheGroupsHandlerIT method invalidateE1.
@Test
public void invalidateE1() throws Exception {
ObjectContext context = runtime.newContext();
ObjectSelect<E1> g0 = ObjectSelect.query(E1.class).localCache();
ObjectSelect<E1> g1 = ObjectSelect.query(E1.class).localCache("g1");
ObjectSelect<E1> g2 = ObjectSelect.query(E1.class).localCache("g2");
assertEquals(0, g0.selectCount(context));
assertEquals(0, g1.selectCount(context));
assertEquals(0, g2.selectCount(context));
e1.insert(1).insert(2);
// inserted via SQL... query results are still cached...
assertEquals(0, g0.selectCount(context));
assertEquals(0, g1.selectCount(context));
assertEquals(0, g2.selectCount(context));
context.newObject(E1.class);
context.commitChanges();
assertEquals(2, removeGroupUntypedCounter.get());
assertEquals(0, removeGroupTypedCounter.get());
// inserted via Cayenne... "g1" and "g2" should get auto refreshed...
assertEquals(0, g0.selectCount(context));
assertEquals(3, g1.selectCount(context));
assertEquals(3, g2.selectCount(context));
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class AshwoodEntitySorter method findReflexiveMaster.
protected Persistent findReflexiveMaster(Persistent object, ObjRelationship toOneRel, String targetEntityName) {
DbRelationship finalRel = toOneRel.getDbRelationships().get(0);
ObjectContext context = object.getObjectContext();
// how do we handle this for NEW objects correctly? For now bail from the method
if (object.getObjectId().isTemporary()) {
return null;
}
ObjectIdQuery query = new ObjectIdQuery(object.getObjectId(), true, ObjectIdQuery.CACHE);
QueryResponse response = context.getChannel().onQuery(null, query);
List<?> result = response.firstList();
if (result == null || result.size() == 0) {
return null;
}
DataRow snapshot = (DataRow) result.get(0);
ObjectId id = snapshot.createTargetObjectId(targetEntityName, finalRel);
// we only care about objects participating in transaction, so no need to create hollow objects
return (id != null) ? (Persistent) context.getGraphManager().getNode(id) : null;
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class DataContextDataChannelEventsIT method testChangeEventOnPeerChangeSecondNestingLevel.
@Test
public void testChangeEventOnPeerChangeSecondNestingLevel() throws Exception {
ObjectContext childPeer1 = runtime.newContext(context);
Artist a = childPeer1.newObject(Artist.class);
a.setArtistName("X");
childPeer1.commitChanges();
final MockChannelListener listener = new MockChannelListener();
EventUtil.listenForChannelEvents((DataChannel) childPeer1, listener);
ObjectContext childPeer2 = runtime.newContext(context);
Artist a1 = childPeer2.localObject(a);
a1.setArtistName("Y");
childPeer2.commitChangesToParent();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertFalse(listener.graphCommitted);
assertTrue(listener.graphChanged);
assertFalse(listener.graphRolledBack);
}
}.runTest(10000);
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class Http2Client method main.
public static void main(String[] args) throws Exception {
HttpsURLConnection.setDefaultHostnameVerifier((hostname, sslSession) -> hostname.equals("localhost"));
System.setProperty("javax.net.ssl.trustStore", Http2Client.class.getResource("/keystore").getPath());
// Setting Protostuff properties
System.setProperty("protostuff.runtime.collection_schema_on_repeated_fields", "true");
System.setProperty("protostuff.runtime.morph_collection_interfaces", "true");
System.setProperty("protostuff.runtime.morph_map_interfaces", "true");
System.setProperty("protostuff.runtime.pojo_schema_on_collection_fields", "true");
System.setProperty("protostuff.runtime.pojo_schema_on_map_fields", "true");
Map<String, String> properties = new HashMap<>();
properties.put(ClientConstants.ROP_SERVICE_URL_PROPERTY, "https://localhost:8443/");
properties.put(ClientConstants.ROP_SERVICE_USE_ALPN_PROPERTY, "false");
properties.put(ClientConstants.ROP_SERVICE_USERNAME_PROPERTY, "cayenne-user");
properties.put(ClientConstants.ROP_SERVICE_PASSWORD_PROPERTY, "secret");
properties.put(ClientConstants.ROP_SERVICE_REALM_PROPERTY, "Cayenne Realm");
ClientRuntime runtime = ClientRuntime.builder().properties(properties).addModule(new ClientJettyHttp2Module()).build();
ObjectContext context = runtime.newContext();
newObjectsTutorial(context);
selectTutorial(context);
deleteTutorial(context);
runtime.shutdown();
}
Aggregations