Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<com:TContent ID="body">
2
 
3
<h1>Result Map  Attributes</h1>
4
<p>The <tt>&lt;resultMap&gt;</tt> element accepts three attributes: <tt>id</tt> (required),
5
<tt>class</tt> (optional), and <tt>extends</tt> (optional).</p>
6
 
7
<h2><tt>id</tt> attribute</h2>
8
<p>The required <tt>id</tt> attribute provides a unique identifier for the
9
<tt>&lt;resultMap&gt;</tt> within this Data Map.</p>
10
 
11
<h2><tt>class</tt> attribute</h2>
12
<p>The optional <tt>class</tt> attribute specifies an object class to use with this
13
<tt>&lt;resultMap&gt;</tt>. The full classname must be specified. Any class can be used.</p>
14
 
15
<div class="note"><b class="tip">Note:</b>
16
As with parameter classes, the result class must be a PHP class object or
17
array instance.
18
</div>
19
 
20
<h2><tt>extends</tt> attribute</h2>
21
<p>The optional <tt>extends</tt> attribute allows the result map to inherit all of
22
the properties of the "parent" <tt>resultMap</tt> that it extends.</p>
23
 
24
<h1><tt>&lt;result&gt;</tt> Element attributes</h1>
25
 
26
<p>The <tt>&lt;resultMap&gt;</tt> element holds one or more <tt>&lt;result&gt;</tt> child elements
27
that map SQL result sets to object properties.</p>
28
 
29
<h2><tt>property</tt> attribute</h2>
30
<p>The <tt>property</tt> attribute is the name of a property of the result object
31
that will be returned by the Mapped Statement. The name can be used more than
32
once depending on the number of times it is needed to populate the results.</p>
33
 
34
<h2><tt>column</tt> attribute</h2>
35
<p>The <tt>column</tt> attribute value is the name of the column in the result set
36
from which the value will be used to populate the property.</p>
37
 
38
<h2><tt>columnIndex</tt> attribute</h2>
39
<p>The <tt>columnIndex</tt> attribute value is the index of the column in the
40
ResultSet from which the value will be used to populate the object property.
41
This is not likely needed in 99\% of applications and sacrifices
42
maintainability and readability for speed. Some providers may not realize any
43
performance benefit, while others will speed up dramatically.</p>
44
 
45
<h2><tt>dbType</tt> attribute</h2>
46
<p>The <tt>dbType</tt> attribute is used to explicitly specify the database column
47
type of the ResultSet column that will be used to populate the object
48
property. Although Result Maps do not have the same difficulties with null
49
values, specifying the type can be useful for certain mapping types such as
50
Date properties. Because an application language has one Date value type and
51
SQL databases may have many (usually at least 3), specifying the date may
52
become necessary in some cases to ensure that dates (or other types) are set
53
correctly. Similarly, String types may be populated by a <tt>VarChar</tt>,
54
<tt>Char</tt> or <tt>CLOB</tt>, so specifying the type might be needed in those cases
55
too.</p>
56
 
57
<h2><tt>type</tt> attribute</h2>
58
<p>The <tt>type</tt> attribute is used to explicitly specify the property type of the
59
parameter to be set. If the attribute <tt>type</tt> is not set and the framework
60
cannot otherwise determine the type, the type is assumed to be <tt>StdObject</tt>.</p>
61
 
62
<h2><tt>resultMapping</tt> attribute</h2>
63
<p>The <tt>resultMapping</tt> attribute can be set to the name of another
64
<tt>resultMap</tt> used to fill the property. If the <tt>resultMap</tt> is in an other
65
mapping file, you must specified the fully qualified name as :</p>
66
 
67
<com:TTextHighlighter Language="xml" CssClass="source">
68
resultMapping="[namespace.sqlMap.]resultMappingId"
69
 
70
resultMapping="Newspaper"
71
<!--resultMapping with a fully qualified name.-->
72
resultMapping="LineItem.LineItem"
73
</com:TTextHighlighter>
74
 
75
<h2><tt>nullValue</tt> attribute</h2>
76
<p>The <tt>nullValue</tt> attribute can be set to any valid value (based on property
77
type). The <tt>nullValue</tt> attribute is used to specify an outgoing null value
78
replacement. What this means is that when the value is detected in the object
79
property, a NULL will be written to the database (the opposite behavior of an
80
inbound null value replacement). This allows you to use a "magic" null
81
number in your application for types that do not support null values (such as
82
int, double, float). When these types of properties contain a matching null
83
value (say, -9999), a NULL will be written to the database instead of the
84
value.</p>
85
 
86
<p>If your database has a NULLABLE column, but you want your application to
87
represent NULL with a constant value, you can specify it in the Result Map as
88
shown in the following example.</p>
89
 
90
<com:TTextHighlighter Language="xml" CssClass="source">
91
<resultMap id="get-product-result" class="product">
92
  <result property="id" column="PRD_ID"/>
93
  <result property="description" column="PRD_DESCRIPTION"/>
94
  <result property="subCode" column="PRD_SUB_CODE" nullValue="-9999"/>
95
</resultMap>
96
</com:TTextHighlighter>
97
 
98
<p>In the above example, <tt>PRD_SUB_CODE</tt> is read as <tt>NULL</tt>, then the
99
<tt>subCode</tt> property will be set to the value of -9999. This allows you to
100
use a primitive type to represent a <tt>NULLABLE</tt> column in the database. Remember
101
that if you want this to work for queries as well as updates/inserts, you must
102
also specify the <tt>nullValue</tt> in the <a href="?page=ParameterMaps">Parameter Map</a>.
103
</p>
104
 
105
<h2><tt>select</tt> attribute</h2>
106
<p>The <tt>select</tt> attribute is used to describe a relationship between objects
107
and to automatically load complex (i.e. user defined) property types. The
108
value of the statement property must be the name of another mapped statement.
109
The value of the database column (the column attribute) that is defined in the
110
same property element as this statement attribute will be passed to the
111
related mapped statement as the parameter. More information about supported
112
primitive types and complex property mappings/relationships is discussed later
113
in this document. The <tt>lazyLoad</tt> attribute can be specified with the
114
<tt>select</tt>.</p>
115
 
116
<h2><tt>lazyLoad</tt> attribute</h2>
117
<p>Use the <tt>lazyLoad</tt> attribute with the <tt>select</tt> attribute to indicate
118
whether or not the select statement's results should be lazy loaded. This can
119
provide a performance boost by delaying the loading of the select statement's
120
results until they are needed/accessed.</p>
121
 
122
<h2><tt>typeHandler</tt> attribute</h2>
123
<p>The <tt>typeHandler</tt> attribute allows the use of a
124
<a href="?page=Manual.CustomTypeHandlers">Custom Type Handler</a>.
125
This allows you to extend
126
the DataMapper's capabilities in handling types that are specific to your
127
database provider, are not handled by your database provider, or just happen
128
to be a part of your application design. You can create custom type handlers
129
to deal with storing and retrieving booleans from your database for example.
130
</p>
131
 
132
</com:TContent>