|
27 | 27 | import org.mybatis.dynamic.sql.util.FragmentAndParameters;
|
28 | 28 | import org.mybatis.dynamic.sql.util.FragmentCollector;
|
29 | 29 |
|
| 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 | + */ |
30 | 49 | public class CriterionRenderer<T> {
|
31 | 50 | private final SqlCriterion<T> sqlCriterion;
|
32 | 51 | private final AtomicInteger sequence;
|
@@ -105,7 +124,8 @@ private RenderedCriterion calculateRenderedCriterion(List<RenderedCriterion> sub
|
105 | 124 | subCriteria.subList(1, subCriteria.size()));
|
106 | 125 | }
|
107 | 126 |
|
108 |
| - private RenderedCriterion calculateRenderedCriterion(FragmentAndParameters initialCondition, List<RenderedCriterion> subCriteria) { |
| 127 | + private RenderedCriterion calculateRenderedCriterion(FragmentAndParameters initialCondition, |
| 128 | + List<RenderedCriterion> subCriteria) { |
109 | 129 | FragmentCollector fc = subCriteria.stream()
|
110 | 130 | .map(RenderedCriterion::fragmentAndParametersWithConnector)
|
111 | 131 | .collect(FragmentCollector.collect(initialCondition));
|
|
0 commit comments