Skip to content

Commit d6c31a9

Browse files
committed
apache#624 - tests and experiments
1 parent c4d57b7 commit d6c31a9

5 files changed

Lines changed: 77 additions & 16 deletions

File tree

cayenne/src/main/java/org/apache/cayenne/access/HierarchicalObjectResolver.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,19 @@ PrefetchProcessorNode synchronizedRootResultNodeFromDataRows(
7979

8080
PrefetchProcessorNode decoratedTree = decorateTree(tree, mainResultRows, extraResultsByPath);
8181

82+
/*
83+
Order of processing (before any changes):
84+
1. DisjointByIdProcessor.startDisjointByIdPrefetch()
85+
- empty parent rows, need them to get id
86+
2. DisjointProcessor.startDisjointPrefetch()
87+
- calls processorNode.setObjects(objects);
88+
3. DisjointProcessor.startJointPrefetch()
89+
- calls JointProcessor.startJointPrefetch()
90+
- parent data rows filled only here, but it needs objects set
91+
*/
92+
8293
// prepare data for disjoint by id prefetches
83-
decoratedTree.traverse(new DisjointByIdProcessor());
94+
decoratedTree.traverse(new DisjointByIdProcessor()); // <--- TODO: this is called before joint prefetch node gets data
8495

8596
// resolve objects under global lock to keep object graph consistent
8697
synchronized (context.getObjectStore()) {
@@ -109,6 +120,7 @@ final class DisjointByIdProcessor implements PrefetchProcessor {
109120

110121
@Override
111122
public boolean startDisjointByIdPrefetch(PrefetchTreeNode node) {
123+
System.out.println("DisjointByIdProcessor.startDisjointByIdPrefetch()");
112124
if (node.getParent().isPhantom()) {
113125
// doing nothing in current implementation if parent node is phantom
114126
return true;
@@ -137,6 +149,10 @@ public boolean startDisjointByIdPrefetch(PrefetchTreeNode node) {
137149
parentDataRows = parentProcessorNode.getDataRows();
138150
}
139151

152+
if(parentDataRows == null || parentDataRows.isEmpty()) {
153+
System.out.println("DisjointByIdProcessor.startDisjointByIdPrefetch() - empty parent rows");
154+
}
155+
140156
int maxIdQualifierSize = context.getParentDataDomain().getMaxIdQualifierSize();
141157
List<DbJoin> joins = getDbJoins(relationship);
142158
Map<DbJoin, String> joinToDataRowKey = getDataRowKeys(joins, pathPrefix);
@@ -296,7 +312,7 @@ final class DisjointProcessor implements PrefetchProcessor {
296312

297313
@Override
298314
public boolean startDisjointPrefetch(PrefetchTreeNode node) {
299-
315+
System.out.println("DisjointProcessor.startDisjointPrefetch()");
300316
PrefetchProcessorNode processorNode = (PrefetchProcessorNode) node;
301317

302318
// this means something bad happened during fetch
@@ -317,12 +333,13 @@ public boolean startDisjointPrefetch(PrefetchTreeNode node) {
317333

318334
@Override
319335
public boolean startDisjointByIdPrefetch(PrefetchTreeNode node) {
336+
System.out.println("DisjointProcessor.startDisjointByIdPrefetch()");
320337
return startDisjointPrefetch(node);
321338
}
322339

323340
@Override
324341
public boolean startJointPrefetch(PrefetchTreeNode node) {
325-
342+
System.out.println("DisjointProcessor.startJointPrefetch()");
326343
// delegate processing of the top level joint prefetch to a joint processor,
327344
// skip non-top joint nodes
328345
if (node.getParent() == null || node.getParent().isJointPrefetch()) {
@@ -343,7 +360,7 @@ public boolean startJointPrefetch(PrefetchTreeNode node) {
343360

344361
List<DataRow> parentRows = parent.getDataRows();
345362
// phantom node?
346-
if (parentRows == null || parentRows.size() == 0) {
363+
if (parentRows == null || parentRows.isEmpty()) {
347364
return false;
348365
}
349366

@@ -413,16 +430,19 @@ void setCurrentFlatRow(DataRow currentFlatRow) {
413430
public boolean startDisjointPrefetch(PrefetchTreeNode node) {
414431
// disjoint prefetch that is not the root terminates the walk...
415432
// don't process the root node itself..
433+
System.out.println("JointProcessor.startDisjointPrefetch()");
416434
return node == rootNode;
417435
}
418436

419437
@Override
420438
public boolean startDisjointByIdPrefetch(PrefetchTreeNode node) {
439+
System.out.println("JointProcessor.startDisjointByIdPrefetch()");
421440
return startDisjointPrefetch(node);
422441
}
423442

424443
@Override
425444
public boolean startJointPrefetch(PrefetchTreeNode node) {
445+
System.out.println("JointProcessor.startJointPrefetch()");
426446
PrefetchProcessorJointNode processorNode = (PrefetchProcessorJointNode) node;
427447

428448
// find existing object, if found skip further processing

cayenne/src/main/java/org/apache/cayenne/access/PrefetchProcessorJointNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Persistent getResolved(Map id) {
127127
*/
128128
void putResolved(Map id, Persistent object) {
129129
resolved.put(id, object);
130+
System.out.println("PrefetchProcessorJointNode.putResolved()");
130131
}
131132

132133
/**

cayenne/src/main/java/org/apache/cayenne/access/PrefetchProcessorNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ void setDataRows(List<DataRow> dataRows) {
205205
}
206206

207207
void setObjects(List<Persistent> objects) {
208+
System.out.println("PrefetchNode.setObjects()");
208209
this.objects = objects;
209210
}
210211

cayenne/src/main/java/org/apache/cayenne/access/PrefetchProcessorTreeBuilder.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,20 @@ public boolean startPhantomPrefetch(PrefetchTreeNode node) {
9292
}
9393

9494
private PrefetchProcessorNode createDisjointNode(PrefetchTreeNode node) {
95-
// TODO, Andrus, 11/16/2005 - minor inefficiency: 'adjacentJointNodes'
96-
// would
97-
// grab ALL nodes, we just need to find first and stop...
98-
PrefetchProcessorNode decorated = !node.adjacentJointNodes().isEmpty() ? new PrefetchProcessorJointNode(
99-
getParent(), node.getName()) : new PrefetchProcessorNode(getParent(), node.getName());
95+
// TODO: Andrus, 11/16/2005 - minor inefficiency: 'adjacentJointNodes'
96+
// would grab ALL nodes, we just need to find first and stop...
97+
PrefetchProcessorNode decorated = !node.adjacentJointNodes().isEmpty()
98+
? new PrefetchProcessorJointNode(getParent(), node.getName())
99+
: new PrefetchProcessorNode(getParent(), node.getName());
100100
decorated.setPhantom(false);
101101
return decorated;
102102
}
103103

104104
public boolean startDisjointPrefetch(PrefetchTreeNode node) {
105-
// look ahead for joint children as joint children will require a
106-
// different
107-
// node type.
105+
// look ahead for joint children as joint children will require a different node type.
108106
PrefetchProcessorNode decorated = createDisjointNode(node);
109107

110-
// semantics has to be "DISJOINT" even if the node is joint, as
111-
// semantics
112-
// defines relationship with parent..
108+
// semantics has to be "DISJOINT" even if the node is joint, as semantics defines relationship with parent..
113109
decorated.setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
114110
return addNode(decorated);
115111
}
@@ -129,7 +125,9 @@ public boolean startJointPrefetch(PrefetchTreeNode node) {
129125

130126
// set "jointChildren" flag on all nodes in the same "join group"
131127
PrefetchProcessorNode groupNode = decorated;
132-
while (groupNode.getParent() != null && !groupNode.isDisjointPrefetch() && !groupNode.isDisjointByIdPrefetch()) {
128+
while (groupNode.getParent() != null
129+
&& !groupNode.isDisjointPrefetch()
130+
&& !groupNode.isDisjointByIdPrefetch()) {
133131
groupNode = (PrefetchProcessorNode) groupNode.getParent();
134132
groupNode.setJointChildren(true);
135133
}

cayenne/src/test/java/org/apache/cayenne/access/DataContextPrefetchMultistepIT.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,16 @@ public void testPrefetchAcross2RelationshipsKeepingBoth_JointAndDisjoint() {
341341

342342
assertNotNull(gallery2.getPaintingArray().get(0).getToArtist());
343343
assertNotNull(gallery.getPaintingArray().get(0).getToArtist());
344+
345+
/*
346+
DisjointProcessor.startDisjointPrefetch()
347+
PrefetchNode.setObjects()
348+
DisjointProcessor.startDisjointPrefetch()
349+
PrefetchNode.setObjects()
350+
DisjointProcessor.startJointPrefetch()
351+
JointProcessor.startJointPrefetch()
352+
PrefetchProcessorJointNode.putResolved()
353+
*/
344354
}
345355

346356
@Test
@@ -356,6 +366,27 @@ public void testPrefetchAcross2RelationshipsKeepingBoth_JointAndDisjointById() {
356366
.select(context);
357367

358368
assertNotNull(gallery.getPaintingArray().get(0).getToArtist());
369+
370+
/*
371+
DisjointByIdProcessor.startDisjointByIdPrefetch()
372+
DisjointByIdProcessor.startDisjointByIdPrefetch() - empty parent rows
373+
DisjointProcessor.startDisjointPrefetch()
374+
DisjointProcessor.startJointPrefetch()
375+
JointProcessor.startJointPrefetch()
376+
PrefetchProcessorJointNode.putResolved()
377+
DisjointProcessor.startDisjointByIdPrefetch()
378+
DisjointProcessor.startDisjointPrefetch()
379+
380+
381+
DisjointProcessor.startDisjointPrefetch()
382+
PrefetchNode.setObjects()
383+
DisjointProcessor.startDisjointByIdPrefetch()
384+
DisjointProcessor.startDisjointPrefetch()
385+
DisjointProcessor.startJointPrefetch()
386+
JointProcessor.startJointPrefetch()
387+
PrefetchProcessorJointNode.putResolved()
388+
DisjointByIdProcessor.startDisjointByIdPrefetch()
389+
*/
359390
}
360391

361392
@Test
@@ -416,6 +447,16 @@ public void testPrefetchAcross2RelationshipsKeepingBoth_DisjointByIdAndJoint() {
416447
.select(context);
417448

418449
assertNotNull(gallery.getPaintingArray().get(0).getToArtist());
450+
451+
/*
452+
DisjointByIdProcessor.startDisjointByIdPrefetch()
453+
DisjointProcessor.startDisjointPrefetch()
454+
DisjointProcessor.startDisjointByIdPrefetch()
455+
DisjointProcessor.startDisjointPrefetch()
456+
DisjointProcessor.startJointPrefetch()
457+
JointProcessor.startJointPrefetch()
458+
PrefetchProcessorJointNode.putResolved()
459+
*/
419460
}
420461

421462
@Test

0 commit comments

Comments
 (0)