Java Reference
In-Depth Information
Table 4.3
Mapped statement types and related XML elements (continued)
Statement type
Attributes
Child elements
Uses
More details
<statement>
id
parameterClass
resultClass
parameterMap
resultMap
cacheModel
xmlResultName
All dynamic elements
Catching all statement
types that can be used to
execute nearly anything
Section
6.3.1;
chapter 8
<sql>
id
All dynamic elements
Not really a mapped
statement, but used to
make components that
can be used in mapped
statements
Section 4.2;
chapter 8
<include>
refid
None
Not really a mapped
statement, but used to
insert components cre-
ated with the <sql> type
into mapped statements
Section 4.2
In this chapter, we focus on the <select> mapped statement type. In addition to
the mapped statement types, two additional elements are included in table 4.3
that are commonly used to build mapped statements: the <sql> element and the
<include> element. These elements work together to create and insert compo-
nents into mapped statements. You will find them useful when you have complex
SQL fragments that you want to be able to reuse without duplicating them.
The <sql> element is used to create text fragments that can be grouped
together to create complete SQL statements. For example, you may have a query
with a complex set of conditions for the WHERE section. If you need to select a
record count using the same complex set of conditions but do not want to dupli-
cate them, you can put them into a <sql> fragment and include them in the query
that does the count, as well as in the query that returns the actual data. Listing 4.1
contains a simple example.
Listing 4.1
An example of the <sql> and <include> tags
B Gets all columns
<sql id="select-order">
select * from order
</sql>
C Gets count
<sql id="select-count">
select count(*) as value from order
Search WWH ::




Custom Search