Java Reference
In-Depth Information
8.2.1
The <dynamic> tag
The <dynamic> tag is a top-level only tag; this means that it cannot be nested. It is
used to demarcate a section of Dynamic SQL . The tag is meant to provide a means
for prefixing a common prepend , open , or close value to the resulting content of
its body. The <dynamic> tag attributes are shown in table 8.1.
Table 8.1
<dynamic> tag attributes
This value is used to prepend to the tag's resulting body content. The prepend value
will not be prepended when the tag's resulting body content is empty.
prepend
(optional)
This value is used to prefix to the tag's resulting body content. The open value will not
be prefixed if the tag's resulting body content is empty. The open value is prefixed
before the prepend attribute's value is prefixed. For example, if prepend="WHEN" and
open="(" , then the resulting combined prefix would be "WHEN (" .
open
(optional)
close
(optional)
This value is used to append to the tag's resulting body content. The append value will
not be appended if the tag's resulting body content is empty.
Now that you have a reference for the attributes that can be used in the tag, list-
ing 8.3 illustrates how to use the <dynamic> tag.
Listing 8.3
<dynamic> tag example
<select id="getChildCategories" parameterClass="Category"
resultClass="Category">
SELECT *
FROM category
<dynamic prepend="WHERE ">
<isNull property="parentCategoryId">
parentCategoryId IS NULL
</isNull>
<isNotNull property="parentCategoryId">
parentCategoryId=#parentCategoryId#
</isNotNull>
</dynamic>
</select>
In listing 8.3, we use Dynamic SQL to build a WHERE clause for our select statement
that looks at the parentCategoryId property and builds the SQL based on it.
Search WWH ::




Custom Search