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

mybatis / scala / 444

29 Mar 2025 10:33PM CUT coverage: 0.0%. Remained the same
444

push

github

web-flow
Update ci.yaml

drop jdk 22 and 23-ea, add jdk 24

0 of 476 branches covered (0.0%)

0 of 996 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/mybatis-scala-core/src/main/scala/org/mybatis/scala/config/DynamicSQLBuilder.scala
1
/*
2
 *    Copyright 2011-2015 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 org.mybatis.scala.config
17

18
import org.apache.ibatis.session.{Configuration => MBConfig}
19
import java.util.{List, ArrayList}
20
import org.apache.ibatis.scripting.xmltags._
21
import org.apache.ibatis.mapping.SqlSource
22
import scala.xml._
23

24
/** Builder of Dynamic SQL Trees. */
25
private[scala] class DynamicSQLBuilder(val configuration : MBConfig, val node : Node) {
×
26

27
  /** SqlSource built from an XML Node */
28
  def build : SqlSource =
29
    new DynamicSqlSource(configuration, parse(node))
×
30

31
  private def parse(n : Node) : SqlNode = {
32
    n match {
×
33
      case Text(text) =>
×
34
        new TextSqlNode(text)
×
35
      case PCData(text) =>
×
36
        new TextSqlNode(text)
×
37
      case <xsql>{children @ _*}</xsql> =>
×
38
        parseChildren(children)
×
39
      case trim @ <trim>{children @ _*}</trim> =>
×
40
        val content = parseChildren(children)
×
41
        new TrimSqlNode(
×
42
          configuration,
×
43
          content,
×
44
          attr(trim, "@prefix"),
×
45
          attr(trim, "@prefixOverrides"),
×
46
          attr(trim, "@suffix"),
×
47
          attr(trim, "@suffixOverrides")
×
48
        )
49
      case <where>{children @ _*}</where> =>
×
50
        val content = parseChildren(children)
×
51
        new WhereSqlNode(configuration, content)
×
52
      case <set>{children @ _*}</set> =>
×
53
        val content = parseChildren(children)
×
54
        new SetSqlNode(configuration, content)
×
55
      case foreach @ <foreach>{children @ _*}</foreach> =>
×
56
        val content = parseChildren(children)
×
57
        new ForEachSqlNode(
×
58
          configuration,
×
59
          content,
×
60
          attr(foreach, "@collection"),
×
61
          attr(foreach, "@index"),
×
62
          attr(foreach, "@item"),
×
63
          attr(foreach, "@open"),
×
64
          attr(foreach, "@close"),
×
65
          attr(foreach, "@separator"))
×
66
      case ifNode @ <if>{children @ _*}</if> =>
×
67
        val content = parseChildren(children)
×
68
        new IfSqlNode(content, attr(ifNode, "@test"))
×
69
      case <choose>{children @ _*}</choose> =>
×
70
        val ifNodes = new ArrayList[SqlNode]
×
71
        var defaultNode : MixedSqlNode = null
×
72
        for (child <- children) {
×
73
          child match {
×
74
            case when @ <when>{ch @ _*}</when> => {
×
75
              val content = parseChildren(ch)
×
76
              ifNodes add new IfSqlNode(content, attr(when, "@test"))
×
77
            }
78
            case other @ <otherwise>{ch @ _*}</otherwise> =>
×
79
              if (defaultNode == null)
×
80
                defaultNode = parseChildren(ch)
×
81
              else
82
                throw new ConfigurationException("Too many default (otherwise) elements in choose statement.")
×
83
                //error("Too many default (otherwise) elements in choose statement.")
84
            case _ =>
×
85
          }
86
        }
87
        new ChooseSqlNode(ifNodes, defaultNode)
×
88
      case ifNode @ <when>{children @ _*}</when> =>
×
89
        val content = parseChildren(children)
×
90
        new IfSqlNode(content, attr(ifNode, "@test"))
×
91
      case other @ <otherwise>{children @ _*}</otherwise> =>
×
92
        parseChildren(other)
×
93
      case a : Atom[_] =>
×
94
        new TextSqlNode(a.data.asInstanceOf[String])
×
95
      case bind @ <bind /> =>
×
96
        new VarDeclSqlNode(attr(bind, "@name"), attr(bind, "@value"))
×
97
      case unsupported =>
98
        throw new ConfigurationException("Unknown element " + unsupported.getClass.getName + " in SQL statement.")
×
99
        //error("Unknown element " + unsupported.toString + " in SQL statement.")
100
    }
101
  }
102

103
  private def parseChildren(children : Seq[Node]) : MixedSqlNode = {
104
    val nodes = new ArrayList[SqlNode]
×
105
    for (child <- children) {
×
106
      nodes add parse(child)
×
107
    }
108
    new MixedSqlNode(nodes)
×
109
  }
110

111
  private def attr(n : Node, name : String) : String = {
112
    (n \ name).text match {
×
113
      case "" => null
×
114
      case text => text
×
115
    }
116
  }
117

118
}
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