• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / ibatis-2 / 730

28 Dec 2025 10:16PM UTC coverage: 65.615% (+0.5%) from 65.146%
730

push

github

web-flow
Update README.md

1602 of 2802 branches covered (57.17%)

5053 of 7701 relevant lines covered (65.61%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.16
/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/IterateTagHandler.java
1
/*
2
 * Copyright 2004-2025 the original author or authors.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *    https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.ibatis.sqlmap.engine.mapping.sql.dynamic.elements;
17

18
import com.ibatis.common.beans.Probe;
19
import com.ibatis.common.beans.ProbeFactory;
20

21
/**
22
 * The Class IterateTagHandler.
23
 */
24
public class IterateTagHandler extends BaseTagHandler {
1✔
25

26
  /** The Constant PROBE. */
27
  private static final Probe PROBE = ProbeFactory.getProbe();
1✔
28

29
  @Override
30
  public int doStartFragment(SqlTagContext ctx, SqlTag tag, Object parameterObject) {
31
    IterateContext iterate = (IterateContext) ctx.getAttribute(tag);
1✔
32
    if (iterate == null) {
1✔
33
      IterateContext parentIterate = ctx.peekIterateContext();
1✔
34

35
      ctx.pushRemoveFirstPrependMarker(tag);
1✔
36

37
      Object collection;
38
      String prop = tag.getPropertyAttr();
1✔
39
      if (prop != null && !prop.equals("")) {
1!
40
        if (null != parentIterate && parentIterate.isAllowNext()) {
1✔
41
          parentIterate.next();
1✔
42
          parentIterate.setAllowNext(false);
1✔
43
          if (!parentIterate.hasNext()) {
1✔
44
            parentIterate.setFinal(true);
1✔
45
          }
46
        }
47

48
        if (parentIterate != null) {
1✔
49
          prop = parentIterate.addIndexToTagProperty(prop);
1✔
50
        }
51

52
        collection = PROBE.getObject(parameterObject, prop);
1✔
53
      } else {
54
        collection = parameterObject;
1✔
55
      }
56
      iterate = new IterateContext(collection, tag, parentIterate);
1✔
57

58
      iterate.setProperty(null == prop ? "" : prop);
1✔
59

60
      ctx.setAttribute(tag, iterate);
1✔
61
      ctx.pushIterateContext(iterate);
1✔
62
    } else if ("iterate".equals(tag.getRemoveFirstPrepend())) {
1✔
63
      ctx.reEnableRemoveFirstPrependMarker();
1✔
64
    }
65

66
    if (iterate.hasNext()) {
1!
67
      return INCLUDE_BODY;
1✔
68
    }
69
    return SKIP_BODY;
×
70
  }
71

72
  @Override
73
  public int doEndFragment(SqlTagContext ctx, SqlTag tag, Object parameterObject, StringBuilder bodyContent) {
74
    IterateContext iterate = (IterateContext) ctx.getAttribute(tag);
1✔
75

76
    if (!iterate.hasNext() && !iterate.isFinal()) {
1!
77
      return super.doEndFragment(ctx, tag, parameterObject, bodyContent);
×
78
    }
79
    if (iterate.isAllowNext()) {
1!
80
      iterate.next();
×
81
    }
82

83
    if (!bodyContent.toString().trim().isEmpty()) {
1✔
84
      // the sub element produced a result. If it is the first one
85
      // to produce a result, then we need to add the open
86
      // text. If it is not the first to produce a result then
87
      // we need to add the conjunction text
88
      if (iterate.someSubElementsHaveContent()) {
1✔
89
        if (tag.isConjunctionAvailable()) {
1✔
90
          bodyContent.insert(0, tag.getConjunctionAttr());
1✔
91
        }
92
      } else {
93
        // we need to specify that this is the first content
94
        // producing element so that the doPrepend method will
95
        // add the prepend
96
        iterate.setPrependEnabled(true);
1✔
97

98
        if (tag.isOpenAvailable()) {
1✔
99
          bodyContent.insert(0, tag.getOpenAttr());
1✔
100
        }
101
      }
102
      iterate.setSomeSubElementsHaveContent(true);
1✔
103
    }
104

105
    if (iterate.isLast() && iterate.someSubElementsHaveContent() && tag.isCloseAvailable()) {
1✔
106
      bodyContent.append(tag.getCloseAttr());
1✔
107
    }
108

109
    iterate.setAllowNext(true);
1✔
110
    if (iterate.isFinal()) {
1✔
111
      return super.doEndFragment(ctx, tag, parameterObject, bodyContent);
1✔
112
    }
113
    return REPEAT_BODY;
1✔
114
  }
115

116
  @Override
117
  public void doPrepend(SqlTagContext ctx, SqlTag tag, Object parameterObject, StringBuilder bodyContent) {
118
    IterateContext iterate = (IterateContext) ctx.getAttribute(tag);
1✔
119
    if (iterate.isPrependEnabled()) {
1✔
120
      super.doPrepend(ctx, tag, parameterObject, bodyContent);
1✔
121
      iterate.setPrependEnabled(false); // only do the prepend one time
1✔
122
    }
123
  }
1✔
124

125
  /**
126
   * Checks if is post parse required.
127
   *
128
   * @return true, if is post parse required
129
   */
130
  public boolean isPostParseRequired() {
131
    return true;
×
132
  }
133

134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc