use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class DispatchHelperTest method testBootstrapMessage.
@Test
public void testBootstrapMessage() {
EntityResolver resolver = new EntityResolver();
MockDataChannel channel = new MockDataChannel(resolver);
assertSame(resolver.getClientEntityResolver(), DispatchHelper.dispatch(channel, new BootstrapMessage()));
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class AshwoodEntitySorter method buildDigraph.
protected <E> Digraph<E, Boolean> buildDigraph(ObjEntity objEntity, List<E> objects, Function<E, Persistent> converter) {
EntityResolver resolver = converter.apply(objects.get(0)).getObjectContext().getEntityResolver();
ClassDescriptor descriptor = resolver.getClassDescriptor(objEntity.getName());
String[] reflexiveRelNames = getReflexiveRelationshipsNames(objEntity);
int size = objects.size();
Digraph<E, Boolean> objectDependencyGraph = new MapDigraph<>();
Persistent[] masters = new Persistent[reflexiveRelNames.length];
for (int i = 0; i < size; i++) {
E current = objects.get(i);
objectDependencyGraph.addVertex(current);
int actualMasterCount = 0;
for (int k = 0; k < reflexiveRelNames.length; k++) {
String reflexiveRelName = reflexiveRelNames[k];
if (reflexiveRelName == null) {
continue;
}
Persistent persistent = converter.apply(current);
masters[k] = (Persistent) descriptor.getProperty(reflexiveRelName).readProperty(persistent);
if (masters[k] == null) {
masters[k] = findReflexiveMaster(persistent, objEntity.getRelationship(reflexiveRelName), persistent.getObjectId().getEntityName());
}
if (masters[k] != null) {
actualMasterCount++;
}
}
int mastersFound = 0;
for (int j = 0; j < size && mastersFound < actualMasterCount; j++) {
if (i == j) {
continue;
}
E masterCandidate = objects.get(j);
for (Persistent master : masters) {
if (converter.apply(masterCandidate) == master) {
objectDependencyGraph.putArc(masterCandidate, current, Boolean.TRUE);
mastersFound++;
}
}
}
}
return objectDependencyGraph;
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class EJBQLQueryIT method testCacheParameters.
@Test
public void testCacheParameters() {
String ejbql1 = "select a FROM Artist a WHERE a.artistName = ?1 OR a.artistName = :name";
EJBQLQuery q1 = new EJBQLQuery(ejbql1);
q1.setParameter(1, "X");
q1.setParameter("name", "Y");
q1.setFetchOffset(1);
q1.setFetchLimit(5);
q1.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
String ejbql2 = "select a FROM Artist a WHERE a.artistName = ?1 OR a.artistName = :name";
EJBQLQuery q2 = new EJBQLQuery(ejbql2);
q2.setParameter(1, "X");
q2.setParameter("name", "Y");
q2.setFetchOffset(1);
q2.setFetchLimit(5);
q2.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
assertEquals(q1.getMetaData(resolver).getCacheKey(), q2.getMetaData(resolver).getCacheKey());
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class CayenneContextIT method testBeforePropertyReadShouldInflateHollow.
@Test
public void testBeforePropertyReadShouldInflateHollow() {
ObjectId gid = ObjectId.of("MtTable1", "a", "b");
final ClientMtTable1 inflated = new ClientMtTable1();
inflated.setPersistenceState(PersistenceState.COMMITTED);
inflated.setObjectId(gid);
inflated.setGlobalAttribute1("abc");
ClientConnection connection = mock(ClientConnection.class);
when(connection.sendMessage((ClientMessage) any())).thenAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
ClientMessage arg = (ClientMessage) invocation.getArguments()[0];
if (arg instanceof BootstrapMessage) {
return new EntityResolver();
} else {
return new GenericResponse(Arrays.asList(inflated));
}
}
});
ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false);
// check that a HOLLOW object is infalted on "beforePropertyRead"
ClientMtTable1 hollow = new ClientMtTable1();
hollow.setPersistenceState(PersistenceState.HOLLOW);
hollow.setObjectId(gid);
final boolean[] selectExecuted = new boolean[1];
CayenneContext context = new CayenneContext(channel) {
@Override
public List<?> performQuery(Query query) {
selectExecuted[0] = true;
return super.performQuery(query);
}
};
context.setEntityResolver(serverContext.getEntityResolver().getClientEntityResolver());
context.graphManager.registerNode(hollow.getObjectId(), hollow);
// testing this...
context.prepareForAccess(hollow, ClientMtTable1.GLOBAL_ATTRIBUTE1.getName(), false);
assertTrue(selectExecuted[0]);
assertSame(hollow, context.getGraphManager().getNode(gid));
assertEquals(inflated.getGlobalAttribute1Direct(), hollow.getGlobalAttribute1Direct());
assertEquals(PersistenceState.COMMITTED, hollow.getPersistenceState());
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class CayenneContextIT method testBeforeHollowDeleteShouldChangeStateToCommited.
@Test
public void testBeforeHollowDeleteShouldChangeStateToCommited() {
ObjectId gid = ObjectId.of("MtTable1", "a", "b");
final ClientMtTable1 inflated = new ClientMtTable1();
inflated.setPersistenceState(PersistenceState.COMMITTED);
inflated.setObjectId(gid);
inflated.setGlobalAttribute1("abc");
ClientConnection connection = mock(ClientConnection.class);
when(connection.sendMessage((ClientMessage) any())).thenAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
ClientMessage arg = (ClientMessage) invocation.getArguments()[0];
if (arg instanceof BootstrapMessage) {
return new EntityResolver();
} else {
return new GenericResponse(Arrays.asList(inflated));
}
}
});
ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false);
CayenneContext context = new CayenneContext(channel);
context.setEntityResolver(serverContext.getEntityResolver().getClientEntityResolver());
ClientMtTable1 hollow = context.localObject(inflated);
assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
// testing this...
context.deleteObjects(hollow);
assertSame(hollow, context.getGraphManager().getNode(gid));
assertEquals(inflated.getGlobalAttribute1Direct(), hollow.getGlobalAttribute1Direct());
assertEquals(PersistenceState.DELETED, hollow.getPersistenceState());
}
Aggregations