Skip to content

Commit d27d018

Browse files
committed
Documentation
1 parent bd2278a commit d27d018

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/main/java/org/mybatis/dynamic/sql/where/render/CriterionRenderer.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@
2727
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
2828
import org.mybatis.dynamic.sql.util.FragmentCollector;
2929

30+
/**
31+
* Renders a {@link SqlCriterion} to a {@link RenderedCriterion}. The process is complex because all conditions
32+
* may or may not be a candidate for rendering. For example, "isEqualWhenPresent" will not render when the value
33+
* is null. It is also complex because SqlCriterion may or may not include sub-criteria.
34+
*
35+
* <p>Rendering is a recursive process. The renderer will recurse into each sub-criteria - which may also
36+
* contain further sub-criteria - until all possible sub-criteria are rendered into a single fragment. So, for example,
37+
* the fragment may end up looking like:
38+
*
39+
* <pre>
40+
* col1 = ? and (col2 = ? or (col3 = ? and col4 = ?))
41+
* </pre>
42+
*
43+
* <p>It is also possible that the end result will be empty if all criteria and sub-criteria are not valid for
44+
* rendering.
45+
*
46+
* @author Jeff Butler
47+
* @param <T> the type of column to render. Not used during rendering.
48+
*/
3049
public class CriterionRenderer<T> {
3150
private final SqlCriterion<T> sqlCriterion;
3251
private final AtomicInteger sequence;
@@ -105,7 +124,8 @@ private RenderedCriterion calculateRenderedCriterion(List<RenderedCriterion> sub
105124
subCriteria.subList(1, subCriteria.size()));
106125
}
107126

108-
private RenderedCriterion calculateRenderedCriterion(FragmentAndParameters initialCondition, List<RenderedCriterion> subCriteria) {
127+
private RenderedCriterion calculateRenderedCriterion(FragmentAndParameters initialCondition,
128+
List<RenderedCriterion> subCriteria) {
109129
FragmentCollector fc = subCriteria.stream()
110130
.map(RenderedCriterion::fragmentAndParametersWithConnector)
111131
.collect(FragmentCollector.collect(initialCondition));

0 commit comments

Comments
 (0)