Skip to content

Commit

Permalink
CAY-2837 Deprecate TraversalHelper and move no-op implementations to …
Browse files Browse the repository at this point in the history
…TraversalHandler
  • Loading branch information
stariy95 committed Jan 23, 2024
1 parent 3469340 commit d43d291
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 34 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ CAY-2829 Merge `BaseContext` with `DataContext` and deprecate it
CAY-2830 Cleanup `DataContext` code
CAY-2831 Upgrade Gradle to 8.5
CAY-2834 v11 upgrade handler should update XMLPoolingDataSourceFactory package
CAY-2837 Deprecate TraversalHelper and move no-op implementations to TraversalHandler

Bug Fixes:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,6 @@ protected DbAttribute findDbAttribute(Expression node) {
return result.getLastAttribute();
}

@Override
public void finishedChild(Expression node, int childIndex, boolean hasMoreChildren) {
}

private String expToStr(int type) {
switch (type) {
case AND:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ public Object apply(Object object) {

}

final class InPlaceParamReplacer extends TraversalHelper {
final class InPlaceParamReplacer implements TraversalHandler {

private Object[] parameters;
private int i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,34 @@ public interface TraversalHandler {
* Called during traversal after a child of expression
* has been visited.
*/
public void finishedChild(
default void finishedChild(
Expression node,
int childIndex,
boolean hasMoreChildren);
boolean hasMoreChildren) {
}

/**
* Called during the traversal before an expression node children
* processing is started.
*
* @since 1.1
*/
public void startNode(Expression node, Expression parentNode);
default void startNode(Expression node, Expression parentNode) {
}

/**
* Called during the traversal after an expression node children
* processing is finished.
*
* @since 1.1
*/
public void endNode(Expression node, Expression parentNode);
default void endNode(Expression node, Expression parentNode) {
}

/**
* Called during the traversal when a leaf non-expression node
* is encountered.
*/
public void objectNode(Object leaf, Expression parentNode);
default void objectNode(Object leaf, Expression parentNode) {
}
}
16 changes: 3 additions & 13 deletions cayenne/src/main/java/org/apache/cayenne/exp/TraversalHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,9 @@
* Noop implementation of TraversalHandler.
* Useful as a superclass for partial implementations
* of TraversalHandler.
*
*
* @deprecated since 5.0 as {@link TraversalHandler} has default no-op implementations for all methods
*/
@Deprecated(since = "5.0", forRemoval = true)
public class TraversalHelper implements TraversalHandler {

public void startNode(Expression node, Expression parentNode) {
}

public void endNode(Expression node, Expression parentNode) {
}

public void finishedChild(Expression node, int childIndex, boolean hasMoreChildren) {
}

public void objectNode(Object leaf, Expression parentNode) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.cayenne.CayenneRuntimeException;
import org.apache.cayenne.dba.TypesMapping;
import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.exp.TraversalHelper;
import org.apache.cayenne.exp.TraversalHandler;
import org.apache.cayenne.map.DbAttribute;
import org.apache.cayenne.map.DbEntity;
import org.apache.cayenne.map.DbRelationship;
Expand Down Expand Up @@ -222,7 +222,7 @@ protected void indexQualifiers(final PersistentDescriptor descriptor, EntityInhe
final Map<String, ObjAttribute> attributes = new HashMap<>();
final DbEntity dbEntity = descriptor.getEntity().getDbEntity();

qualifier.traverse(new TraversalHelper() {
qualifier.traverse(new TraversalHandler() {

@Override
public void startNode(Expression node, Expression parentNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Class that collects statistics of expression traversal.
*/
public class TstTraversalHandler implements TraversalHandler {
protected List<Object> treeFlatView = new ArrayList<Object>();
protected List<Object> treeFlatView = new ArrayList<>();
protected int children;
protected int nodes;
protected int nodesStarted;
Expand Down Expand Up @@ -58,10 +58,6 @@ public void assertConsistency() {
Assert.assertEquals(nodesStarted, nodes);
}

public List<Object> getTreeFlatView() {
return treeFlatView;
}

public void traverseExpression(Expression exp) {
reset();
exp.traverse(this);
Expand All @@ -86,10 +82,6 @@ public int getNodes() {
return nodes;
}

public int getNodesStarted() {
return nodesStarted;
}

public int getLeafs() {
return leafs;
}
Expand Down

0 comments on commit d43d291

Please sign in to comment.