﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Samuel LearningiBatis学习</title><link>http://www.blogjava.net/nobody_am/category/33156.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 25 Jul 2008 07:05:30 GMT</lastBuildDate><pubDate>Fri, 25 Jul 2008 07:05:30 GMT</pubDate><ttl>60</ttl><item><title>What causes an Invalid column type error with Oracle </title><link>http://www.blogjava.net/nobody_am/news/2008/07/23/216754.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 16:23:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/23/216754.html</guid><description><![CDATA[<p>This error is a bit misleading. What it is trying to tell you is that your jdbc driver does not know how to set one of your columns to null. In the following section I will show you what causes this error and how to correct it.</p>
<p>First lets start with a simple POJO (Plain Old Java Object).</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>Address.java</strong></div>
<div class="codeContent">
<pre class="code-java"><span class="code-keyword">import</span> java.util.Date;
<span class="code-keyword">public</span> class Address {
<span class="code-keyword">private</span> <span class="code-object">String</span> line1;
<span class="code-keyword">private</span> <span class="code-object">String</span> line2;
<span class="code-keyword">private</span> <span class="code-object">String</span> city;
<span class="code-keyword">private</span> <span class="code-object">String</span> state;
<span class="code-keyword">private</span> <span class="code-object">String</span> postalCode;
<span class="code-keyword">private</span> Date purchaseDate;
<span class="code-keyword">private</span> Date soldDate;
...  Standard mutators (getters setters) ...
}</pre>
</div>
</div>
<p>Here is the example table that we will be using.</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>Address.sql</strong></div>
<div class="codeContent">
<pre class="code-java">Address {
line1			varchar2(100),
line2			varchar2(100),
city			varchar2(100),
state			varchar2(100),
postal_code	varchar2(25),
purchase_date	date,
sold_date		date
}</pre>
</div>
</div>
<p>With this in place we can create the sqlmaps to work with it. With this error only your insert and update statements will be of concern. I will use an insert both the solution works for both.</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>Address.xml</strong></div>
<div class="codeContent">
<pre class="code-java">&lt;typeAlias alias=<span class="code-quote">"Address"</span> type=<span class="code-quote">"com.abc.domain.Address"</span>/&gt;
&lt;insert id=<span class="code-quote">"insertAddress"</span> parameterClass=<span class="code-quote">"Address"</span>&gt;
INSERT INTO
ADDRESS (
line1,
line2,
city,
state,
postal_code,
purchase_date,
sold_date
)
values (
#line1#,
#line2#,
#city#,
#state#,
#postal_code#,
#purchase_date#,
#sold_date#
)
&lt;/insert&gt;</pre>
</div>
</div>
<p>So far everything looks good and will work part of the time. In the following example the classic invalid column type error will be thrown.</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>Example.java</strong></div>
<div class="codeContent">
<pre class="code-java">Address address = <span class="code-keyword">new</span> Address();
address.setLine1(<span class="code-quote">"123 Anywhere Street"</span>);
address.setCity(<span class="code-quote">"Somewhere over the Rainbow"</span>);
address.setState(<span class="code-quote">"Never never land"</span>);
address.setPostalCode(<span class="code-quote">"01234"</span>);
address.setPurcahseDate(purcahseDate);  <span class="code-comment">//purchaseDate defined somewhere above <span class="code-keyword">this</span> code</span></pre>
</div>
</div>
<p>Notice in the code above that I leave the line2 and soldDate properties as null. This is where the problem creeps in. When the insert sqlmap come to the line2 column it will throw an error. There are two solutions for this problem.</p>
<p>The first is to use dynamic conditions.</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>Address.xml</strong></div>
<div class="codeContent">
<pre class="code-java">&lt;typeAlias alias=<span class="code-quote">"Address"</span> type=<span class="code-quote">"com.abc.domain.Address"</span>/&gt;
&lt;insert id=<span class="code-quote">"insertAddress"</span> parameterClass=<span class="code-quote">"Address"</span>&gt;
INSERT INTO
ADDRESS (
line1,
line2,
city,
state,
postal_code,
purchase_date,
sold_date
)
values (
#line1#,
&lt;isNull property=<span class="code-quote">"line2"</span>&gt;
<span class="code-keyword">null</span>,
&lt;/isNull&gt;
&lt;isNotNull property=<span class="code-quote">"line2"</span>&gt;
#line2#,
&lt;/isNotNull&gt;
#city#,
#state#,
#postal_code#,
#purchase_date#,
#sold_date#
)
&lt;/insert&gt;</pre>
</div>
</div>
<p>As you can see this can become a time consuming process to make sure that every column that can be null has these tags. A second and cleaner option is to define what the jdbc type is.</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>Address.xml</strong></div>
<div class="codeContent">
<pre class="code-java">&lt;typeAlias alias=<span class="code-quote">"Address"</span> type=<span class="code-quote">"com.abc.domain.Address"</span>/&gt;
&lt;insert id=<span class="code-quote">"insertAddress"</span> parameterClass=<span class="code-quote">"Address"</span>&gt;
INSERT INTO
ADDRESS (
line1,
line2,
city,
state,
postal_code,
purchase_date,
sold_date
)
values (
#line1#,
#line2:VARCHAR#,
#city#,
#state#,
#postal_code#,
#purchase_date#,
#sold_date:DATE#
)
&lt;/insert&gt;</pre>
</div>
</div>
<p>Just do this only any column that can be null! Now you may be asking yourself what are the valid jdbc types. Look no further they are posted in the Java API documents java.sql.Types.</p>
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="http://opensource.atlassian.com/confluence/oss/display/IBATIS/What+causes+an+Invalid+column+type+error+with+Oracle" dc:identifier="http://opensource.atlassian.com/confluence/oss/display/IBATIS/What+causes+an+Invalid+column+type+error+with+Oracle" dc:title="What causes an Invalid column type error with Oracle" trackback:ping="http://opensource.atlassian.com/confluence/oss/rpc/trackback/235" />
</rdf:RDF>
--><!-- Root decorator: all decisions about how a page is to be decorated via the
                    inline decoration begins here.
--><!-- Switch based upon the context. However, for now, just delegate to a decorator
    identified directly by the context.
--><br />
主要原因是没有对inline参数制定类型。<br />
<img src ="http://www.blogjava.net/nobody_am/aggbug/216754.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-23 00:23 <a href="http://www.blogjava.net/nobody_am/news/2008/07/23/216754.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Why can't I use a property that begins with a single lower-case letter </title><link>http://www.blogjava.net/nobody_am/news/2008/07/23/216753.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 16:21:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/23/216753.html</guid><description><![CDATA[<p>Most likely, it's because your property is not defined correctly.</p>
<table class="confluenceTable">
    <tbody>
        <tr>
            <th class="confluenceTh">property</th>
            <th class="confluenceTh">getter</th>
            <th class="confluenceTh">setter</th>
            <th class="confluenceTh">comment</th>
        </tr>
        <tr>
            <td class="confluenceTd">AString </td>
            <td class="confluenceTd">getAString </td>
            <td class="confluenceTd">setAString </td>
            <td class="confluenceTd">Surprise! This is not a property named aString as you expected..</td>
        </tr>
        <tr>
            <td class="confluenceTd">aString </td>
            <td class="confluenceTd">getaString </td>
            <td class="confluenceTd">setaString </td>
            <td class="confluenceTd">Notice the lower case letter after get/set? That's the key.</td>
        </tr>
        <tr>
            <td class="confluenceTd">string </td>
            <td class="confluenceTd">getString </td>
            <td class="confluenceTd">setString</td>
        </tr>
    </tbody>
</table>
<br />
<br />
<br />
<img src ="http://www.blogjava.net/nobody_am/aggbug/216753.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-23 00:21 <a href="http://www.blogjava.net/nobody_am/news/2008/07/23/216753.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do I get a Map of results instead of a List </title><link>http://www.blogjava.net/nobody_am/news/2008/07/23/216752.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 16:15:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/23/216752.html</guid><description><![CDATA[<p>The following section will explain in detail how to use the queryForMap().</p>
<p><strong><span style="background-color: yellow"><strong>The queryForMap()'s are most useful when you need to work with the result of a query.</strong> </span></strong>In the example below I will use a query that return Student objects as a result. Lets start with the Student class.</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>Student.java</strong></div>
<div class="codeContent">
<pre class="code-java"><span class="code-keyword">public</span> class Student <span class="code-keyword">implements</span> java.io.Serializable {
<span class="code-keyword">private</span> <span class="code-object">String</span> id, firstName, lastName;
<span class="code-keyword">public</span> <span class="code-object">String</span> getId() {
<span class="code-keyword">return</span> id;
}
<span class="code-keyword">public</span> void setId(<span class="code-object">String</span> id) {
<span class="code-keyword">this</span>.id = id;
}
<span class="code-keyword">public</span> <span class="code-object">String</span> getFirstName() {
<span class="code-keyword">return</span> firstName;
}
<span class="code-keyword">public</span> void setFirstName(<span class="code-object">String</span> firstName) {
<span class="code-keyword">this</span>.firstName = firstName;
}
<span class="code-keyword">public</span> <span class="code-object">String</span> getLastName() {
<span class="code-keyword">return</span> lastName;
}
<span class="code-keyword">public</span> void setLastName(<span class="code-object">String</span> lastName) {
<span class="code-keyword">this</span>.lastName = lastName;
}</pre>
</div>
</div>
<p>And now the SqlMap ....</p>
<div class="code">
<div class="codeContent">
<pre class="code-xml"><span class="code-tag">&lt;resultMap id=<span class="code-quote">"studentResult"</span> class=<span class="code-quote">"com.domain.Student"</span>&gt;</span>
<span class="code-tag">&lt;result column=<span class="code-quote">"id"</span> property=<span class="code-quote">"id"</span> /&gt;</span>
<span class="code-tag">&lt;result column=<span class="code-quote">"first_name"</span> property=<span class="code-quote">"firstName"</span> /&gt;</span>
<span class="code-tag">&lt;result column=<span class="code-quote">"last_name"</span> property=<span class="code-quote">"lastName"</span> /&gt;</span>
<span class="code-tag">&lt;/resultMap&gt;</span>
<span class="code-tag">&lt;select id=<span class="code-quote">"getAllStudents"</span> resultMap=<span class="code-quote">"studentResult"</span>&gt;</span>
select
*
from students
<span class="code-tag">&lt;/select&gt;</span></pre>
</div>
</div>
<p>Now that the basics are out of the way query away!</p>
<p><strong><span style="background-color: yellow"><strong>Lets say that you need to do some fast serching on the returned students.</strong> </span></strong>The best way is to have a Map of the Student objects to their id's.</p>
<p>This is where the queryForMap() comes into play. There are two different options and both will be dicussed. The first is perfect for the example given above.</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeContent">
<pre class="code-java"><span class="code-keyword">public</span> Map getAllStudents() {
Map&lt;<span class="code-object">String</span>, Student&gt; studentsMap = queryForMap(<span class="code-quote">"getAllStudents"</span>, <span class="code-keyword">null</span>, <span class="code-quote">"id"</span>);
Student student = studentsMap.get(<span class="code-quote">"123456"</span>);
...
}</pre>
</div>
</div>
<p>You can see that the third parameter in the call looks for the property "id" in the result map and then creates the map with that property as the key.</p>
<p>The second option allow you to specify both the key and the value. </p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeContent">
<pre class="code-java">Map&lt;<span class="code-object">String</span>, <span class="code-object">String</span>&gt; studentsMap = queryForMap(<span class="code-quote">"getAllStudents"</span>, <span class="code-keyword">null</span>, <span class="code-quote">"id"</span>, <span class="code-quote">"firstName"</span>);</pre>
</div>
</div>
<p>The above code will return a Map with the id as the key and the firstName as the value.</p>
<p>There are many other uses for these method so feel free to add them on <img class="emoticon" height="20" alt="" src="http://opensource.atlassian.com/confluence/oss/images/icons/emoticons/smile.gif" width="20" align="absMiddle" border="0" /></p>
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+get+a+Map+of+results+instead+of+a+List" dc:identifier="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+get+a+Map+of+results+instead+of+a+List" dc:title="How do I get a Map of results instead of a List" trackback:ping="http://opensource.atlassian.com/confluence/oss/rpc/trackback/671" />
</rdf:RDF>
--><!-- Root decorator: all decisions about how a page is to be decorated via the
                    inline decoration begins here.
--><!-- Switch based upon the context. However, for now, just delegate to a decorator
    identified directly by the context.
-->
<img src ="http://www.blogjava.net/nobody_am/aggbug/216752.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-23 00:15 <a href="http://www.blogjava.net/nobody_am/news/2008/07/23/216752.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do I use an Oracle Ref Cursor? </title><link>http://www.blogjava.net/nobody_am/news/2008/07/23/216750.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 16:08:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/23/216750.html</guid><description><![CDATA[<table class="infoMacro" cellspacing="8" cellpadding="5" width="85%" align="center" border="0">
    <colgroup>
    <col width="24">
    <col></colgroup>
    <tbody>
        <tr>
            <td valign="top"><img height="16" alt="" src="http://opensource.atlassian.com/confluence/oss/images/icons/emoticons/information.gif" width="16" align="absMiddle" border="0" /></td>
            <td><strong class="strong">iBATIS DataMapper version 2.2.0.638</strong><br />
            <p>This FAQ is based on iBATIS DataMapper (Java) 2.2.0.638</p>
            </td>
        </tr>
    </tbody>
</table>
<p>Release 2.2.0 of iBATIS DataMapper natively supports Oracle REF Cursors - without the need to create a custom type handler. This FAQ shows a very small example on how to use it.<br />
</p>
<p>iBatis2.2.0之后，开始支持Oracle的Cursor，不需要依赖于CTH。<br />
<br />
We start with the (Oracle) database related stuff. For this example we've created an Oracle user <em>ibatis</em>. In SQL*Plus (or whichever tool you use) log in as this user and run the commands shown below.</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>REF_CURSOR_TEST</strong></div>
<div class="codeContent">
<pre class="code-java">CREATE TABLE REFS (
ID   NUMBER       NOT NULL PRIMARY KEY
, NAME VARCHAR2(50) NOT NULL
);
CREATE OR REPLACE PACKAGE REFS_PCK AS
TYPE      REF_CURSOR_T IS REF CURSOR;
FUNCTION  GET_REFS RETURN REF_CURSOR_T;
END REFS_PCK;
/
CREATE OR REPLACE PACKAGE BODY REFS_PCK IS
FUNCTION GET_REFS RETURN REF_CURSOR_T
IS
L_CURSOR REF_CURSOR_T;
BEGIN
OPEN L_CURSOR FOR SELECT * FROM REFS;
RETURN L_CURSOR;
END GET_REFS;
END REFS_PCK;
/
insert into refs values(1,'Jan');
insert into refs values(2,'Danielle');
insert into refs values(3,'Tessa');</pre>
</div>
</div>
<p>We create a simple Java bean class to hold REFS' records.</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>com.cumquatit.examples.ibatis.refs.Ref</strong></div>
<div class="codeContent">
<pre class="code-java"><span class="code-keyword">package</span> com.cumquatit.examples.ibatis.refs;
<span class="code-keyword">public</span> class Ref {
<span class="code-keyword">private</span> <span class="code-object">int</span> id;
<span class="code-keyword">private</span> <span class="code-object">String</span> name;
<span class="code-keyword">public</span> <span class="code-object">int</span> getId() {
<span class="code-keyword">return</span> id;
}
<span class="code-keyword">public</span> void setId(<span class="code-object">int</span> id) {
<span class="code-keyword">this</span>.id = id;
}
<span class="code-keyword">public</span> <span class="code-object">String</span> getName() {
<span class="code-keyword">return</span> name;
}
<span class="code-keyword">public</span> void setName(<span class="code-object">String</span> name) {
<span class="code-keyword">this</span>.name = name;
}
<span class="code-keyword">public</span> <span class="code-object">String</span> toString() {
<span class="code-keyword">return</span> (<span class="code-quote">"id="</span> + id + <span class="code-quote">", name="</span> + name);
}
}</pre>
</div>
</div>
<p>Next create a mapping file for the <em>REFS</em> table.</p>
<div class="code">
<div class="codeContent">
<pre class="code-xml"><span class="code-tag">&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span> ?&gt;</span>
<span class="code-tag">&lt;!DOCTYPE sqlMap PUBLIC <span class="code-quote">"-//iBATIS.com//DTD SQL Map 2.0//EN"</span> <span class="code-quote">"http://ibatis.apache.org/dtd/sql-map-2.dtd"</span>&gt;</span>
<span class="code-tag">&lt;sqlMap&gt;</span>
<span class="code-tag">&lt;typeAlias alias=<span class="code-quote">"Ref"</span> type=<span class="code-quote">"com.cumquatit.examples.ibatis.refs.Ref"</span> /&gt;</span>
<span class="code-tag">&lt;resultMap class=<span class="code-quote">"Ref"</span> id=<span class="code-quote">"ref-mapping"</span>&gt;</span>
<span class="code-tag">&lt;result property=<span class="code-quote">"id"</span> column=<span class="code-quote">"ID"</span> /&gt;</span>
<span class="code-tag">&lt;result property=<span class="code-quote">"name"</span> column=<span class="code-quote">"NAME"</span> /&gt;</span>
<span class="code-tag">&lt;/resultMap&gt;</span>
<span class="code-tag">&lt;parameterMap id=<span class="code-quote">"output"</span> class=<span class="code-quote">"map"</span>&gt;</span>
<span class="code-tag">&lt;parameter property=<span class="code-quote">"o"</span> javaType=<span class="code-quote">"java.sql.ResultSet"</span> <strong style="background-color: yellow">jdbcType=<span class="code-quote">"ORACLECURSOR"</span></strong> mode=<span class="code-quote">"OUT"</span> resultMap=<span class="code-quote">"ref-mapping"</span> /&gt;</span>
<span class="code-tag">&lt;/parameterMap&gt;</span>
<span class="code-tag">&lt;procedure id=<span class="code-quote">"getRefs"</span> parameterMap=<span class="code-quote">"output"</span>&gt;</span>{ ? = call refs_pck.get_refs }<span class="code-tag">&lt;/procedure&gt;</span>
<span class="code-tag">&lt;/sqlMap&gt;</span></pre>
</div>
</div>
<p>Also we need a sqlMapConfig file. Below an example of this file.</p>
<div class="code">
<div class="codeContent">
<pre class="code-xml"><span class="code-tag">&lt;?xml version=<span class="code-quote">"1.0"</span>?&gt;</span>
<span class="code-tag">&lt;!DOCTYPE sqlMapConfig PUBLIC <span class="code-quote">"-//iBATIS.com//DTD SQL Map Config 2.0//EN"</span> <span class="code-quote">"http://ibatis.apache.org/dtd/sql-map-config-2.dtd"</span>&gt;</span>
<span class="code-tag">&lt;sqlMapConfig&gt;</span>
<span class="code-tag">&lt;transactionManager type=<span class="code-quote">"JDBC"</span> commitRequired=<span class="code-quote">"false"</span>&gt;</span>
<span class="code-tag">&lt;dataSource type=<span class="code-quote">"SIMPLE"</span>&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"JDBC.Driver"</span> value=<span class="code-quote">"oracle.jdbc.OracleDriver"</span> /&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"JDBC.ConnectionURL"</span> value=<span class="code-quote">"jdbc:oracle:thin:@//flash.cumquat.office:1524/neon"</span> /&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"JDBC.Username"</span> value=<span class="code-quote">"ibatis"</span> /&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"JDBC.Password"</span> value=<span class="code-quote">"ibatis"</span> /&gt;</span>
<span class="code-tag">&lt;/dataSource&gt;</span>
<span class="code-tag">&lt;/transactionManager&gt;</span>
<span class="code-tag">&lt;sqlMap resource=<span class="code-quote">"com/cumquatit/examples/ibatis/refs/Ref.xml"</span> /&gt;</span>
<span class="code-tag">&lt;/sqlMapConfig&gt;</span></pre>
</div>
</div>
<p>And to finish up, a small tester program.</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>com.cumquatit.examples.ibatis.refs.RefTester</strong></div>
<div class="codeContent">
<pre class="code-java"><span class="code-keyword">package</span> com.cumquatit.examples.ibatis.refs;
<span class="code-keyword">import</span> java.io.Reader;
<span class="code-keyword">import</span> java.util.HashMap;
<span class="code-keyword">import</span> java.util.Map;
<span class="code-keyword">import</span> com.ibatis.common.resources.Resources;
<span class="code-keyword">import</span> com.ibatis.sqlmap.client.SqlMapClient;
<span class="code-keyword">import</span> com.ibatis.sqlmap.client.SqlMapClientBuilder;
<span class="code-keyword">public</span> class RefTester {
<span class="code-keyword">public</span> <span class="code-keyword">static</span> void main(<span class="code-object">String</span>[] args) <span class="code-keyword">throws</span> Exception {
<span class="code-object">String</span> resource;
Reader reader;
SqlMapClient sqlMap;
resource = <span class="code-quote">"com/cumquatit/examples/ibatis/refs/SqlMapConfig.xml"</span>;
reader = Resources.getResourceAsReader(resource);
sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
Map map = <span class="code-keyword">new</span> HashMap();
sqlMap.queryForObject(<span class="code-quote">"getRefs"</span>, map);
<span class="code-object">System</span>.out.println(map.get(<span class="code-quote">"o"</span>));
}
}</pre>
</div>
</div>
<p>That's all folks.</p>
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="http://opensource.atlassian.com/confluence/oss/pages/viewpage.action?pageId=5653" dc:identifier="http://opensource.atlassian.com/confluence/oss/pages/viewpage.action?pageId=5653" dc:title="How do I use an Oracle Ref Cursor?" trackback:ping="http://opensource.atlassian.com/confluence/oss/rpc/trackback/5653" />
</rdf:RDF>
--><!-- Root decorator: all decisions about how a page is to be decorated via the
                    inline decoration begins here.
--><!-- Switch based upon the context. However, for now, just delegate to a decorator
    identified directly by the context.
-->
<img src ="http://www.blogjava.net/nobody_am/aggbug/216750.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-23 00:08 <a href="http://www.blogjava.net/nobody_am/news/2008/07/23/216750.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do I use a BLOB or CLOB </title><link>http://www.blogjava.net/nobody_am/news/2008/07/23/216749.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 16:04:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/23/216749.html</guid><description><![CDATA[<p>因为ibatis从2.0.9开始支持Clob和Blob，所以这个例子和普通的sqlmap用法一致。<br />
Here is an example of how to use the Custom Type Handler (CTH) feature of iBatis with large objects (LOB) such as BLOB's (Binary) and CLOB's (Character). As of release 2.0.9 the iBatis framework has the default CLOB and BLOB type handlers included. The example below was done for Oracle but should work for any database with a well written JDBC driver. Make sure that you do not use the thin driver supplied from Oracle. You need to use the latest ojbc14.jar.</p>
<p>The example below was not the intended way to use CTH's but it works great for me!</p>
<p>First lets take a look at the table. </p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>Report.sql</strong></div>
<div class="codeContent">
<pre class="code-java">REPORT {
id              varchar2(5),
name            varchar2(25),
description     varchar2(1000),
data            BLOB
}</pre>
</div>
</div>
<p>Next we continue by creating a plain old java object (POJO) to represent this table.</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>Report.java</strong></div>
<div class="codeContent">
<pre class="code-java">/*
* Report.java
*
* Created on March 23, 2005, 11:00 AM
*/
<span class="code-keyword">package</span> reporting.viewer.domain;
/**
*
* @author Nathan Maves
*/
<span class="code-keyword">public</span> class Report {
/**
* Holds value of property id.
*/
<span class="code-keyword">private</span> <span class="code-object">String</span> id;
/**
* Holds value of property name.
*/
<span class="code-keyword">private</span> <span class="code-object">String</span> name;
/**
* Holds value of property description.
*/
<span class="code-keyword">private</span> <span class="code-object">String</span> id;
/**
* Holds value of property data.
*/
<span class="code-keyword">private</span> <span class="code-object">byte</span>[] data;
<span class="code-comment">//Standard accessors and mutators
</span>
<span class="code-keyword">public</span> <span class="code-object">byte</span>[] getData() {
<span class="code-keyword">return</span> <span class="code-keyword">this</span>.data;
}
<span class="code-keyword">public</span> void setData(<span class="code-object">byte</span>[] data) {
<span class="code-keyword">this</span>.data = data;
}
}</pre>
</div>
</div>
<p>Now that the easy stuff is completed let connect both the database and the POJO together using iBatis.</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeHeader" style="border-bottom-style: solid"><strong>Report.xml</strong></div>
<div class="codeContent">
<pre class="code-java">&lt;typeAlias alias=<span class="code-quote">"Report"</span> type=<span class="code-quote">"reporting.viewer.domain.Report"</span>/&gt;
&lt;resultMap class=<span class="code-quote">"Report"</span> id=<span class="code-quote">"ReportResult"</span>&gt;
&lt;result column=<span class="code-quote">"id"</span> property=<span class="code-quote">"id"</span> /&gt;
&lt;result column=<span class="code-quote">"name"</span> property=<span class="code-quote">"name"</span> /&gt;
&lt;result column=<span class="code-quote">"description"</span> property=<span class="code-quote">"description"</span> /&gt;
&lt;result column=<span class="code-quote">"data"</span> property=<span class="code-quote">"data"</span> jdbcType=<span class="code-quote">"BLOB"</span>/&gt;
&lt;/resultMap&gt;
&lt;select id=<span class="code-quote">"getReportById"</span> parameterClass=<span class="code-quote">"string"</span> resultMap=<span class="code-quote">"ReportResult"</span>&gt;
SELECT
*
FROM
REPORT
WHERE
id = #value#
&lt;/select&gt;
&lt;insert id=<span class="code-quote">"insertReport"</span> parameterClass=<span class="code-quote">"Report"</span>&gt;
INSERT INTO
REPORT (
id,
name,
description,
data
)
values (
#id#,
#name#,
#description#,
#data#
)
&lt;/insert&gt;
&lt;update id=<span class="code-quote">"updateReport"</span> parameterClass=<span class="code-quote">"Report"</span>&gt;
UPDATE REPORT set
name = #name#,
description = #description#,
data = #data#
WHERE
id = #id#
&lt;/update&gt;</pre>
</div>
</div>
<p>As you can see there is nothing special that you need to do. </p>
<p>When working with a CLOB the only that the you need to change is the property in your bean. Just change byte[] to java.lang.String.</p>
<table class="tipMacro" cellspacing="8" cellpadding="5" width="85%" align="center" border="0">
    <colgroup>
    <col width="24">
    <col></colgroup>
    <tbody>
        <tr>
            <td valign="top"><img height="16" alt="" src="http://opensource.atlassian.com/confluence/oss/images/icons/emoticons/check.gif" width="16" align="absMiddle" border="0" /></td>
            <td><strong class="strong">Data size bigger than max size for this type: ????</strong><br />
            <p>Some of the older jdbc drivers for Oracle have trouble with Strings that are larger then 4k. The first step to correct this issue it to get a jdbc driver from Oracle that is newer then 10g Release 2. This driver will work with both 9i and 10g databases. If you are stuck with an older driver you can try to set a driver property. The property is SetBigStringTryClob=true. If you are using the SimpleDataSource with iBatis use the follow line in the config file. <br clear="all" />
            <br clear="all" />
            &lt;property name="Driver.SetBigStringTryClob" value="true"/&gt;</p>
            </td>
        </tr>
    </tbody>
</table>
<table class="tipMacro" cellspacing="8" cellpadding="5" width="85%" align="center" border="0">
    <colgroup>
    <col width="24">
    <col></colgroup>
    <tbody>
        <tr>
            <td valign="top"><img height="16" alt="" src="http://opensource.atlassian.com/confluence/oss/images/icons/emoticons/check.gif" width="16" align="absMiddle" border="0" /></td>
            <td><strong class="strong">Data size always 86 bytes?</strong><br />
            <p>If you find that the length of your byte[] is always 86, check that you have the jdbcType="BLOB" or jdbcType="CLOB" in your result map.</p>
            </td>
        </tr>
    </tbody>
</table>
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+use+a+BLOB+or+CLOB" dc:identifier="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+use+a+BLOB+or+CLOB" dc:title="How do I use a BLOB or CLOB" trackback:ping="http://opensource.atlassian.com/confluence/oss/rpc/trackback/189" />
</rdf:RDF>
--><!-- Root decorator: all decisions about how a page is to be decorated via the
                    inline decoration begins here.
--><!-- Switch based upon the context. However, for now, just delegate to a decorator
    identified directly by the context.
-->
<div class="wiki-content" style="margin-right: 10px">
<p style="clear: both"><!-- comments should always display underneath the content. we should have a 'clear:both' here just in case there are floats or aligned images in the content --></p>
</div>
<img src ="http://www.blogjava.net/nobody_am/aggbug/216749.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-23 00:04 <a href="http://www.blogjava.net/nobody_am/news/2008/07/23/216749.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do I configure a Jakarta DBCP-datasource </title><link>http://www.blogjava.net/nobody_am/news/2008/07/22/216742.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 15:39:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/22/216742.html</guid><description><![CDATA[<p>The iBATIS documentation already provides information about configuring a DBCP-datasource, however, the implementation has been improved in the meantime to allow for more flexibility. The old (legacy) configuration is still supported, so if your needs are satisfied with the options mentioned in the documentation, read no further.</p>
<p>The old implementation uses the prefix 'Pool.' to pass settings to DBCP, these are hardcoded and are: ValidationQuery, MaximumActiveConnections, MaximumIdleConnections and MaximumWait. The following example illustrates the prefix:<br />
旧版本的dbcp使用方式<br />
</p>
<div class="code">
<div class="codeContent">
<pre class="code-xml"><span class="code-tag">&lt;dataSource type=<span class="code-quote">"DBCP"</span>&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"JDBC.Driver"</span> value=<span class="code-quote">"${driver}"</span>/&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"JDBC.ConnectionURL"</span> value=<span class="code-quote">"${url}"</span>/&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"JDBC.Username"</span> value=<span class="code-quote">"${username}"</span>/&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"JDBC.Password"</span> value=<span class="code-quote">"${password}"</span>/&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"Pool.MaximumActiveConnections"</span> value=<span class="code-quote">"10"</span>/&gt;</span>
<span class="code-tag">&lt;/datasource&gt;</span></pre>
</div>
</div>
<p>To achieve the same and more, use the new implementation, it uses Bean-style settings:<br />
新版本的配置<br />
</p>
<div class="code">
<div class="codeContent">
<pre class="code-xml"><span class="code-tag">&lt;dataSource type=<span class="code-quote">"DBCP"</span>&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"driverClassName"</span> value=<span class="code-quote">"${driver}"</span>/&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"url"</span> value=<span class="code-quote">"${url}"</span>/&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"username"</span> value=<span class="code-quote">"${username}"</span>/&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"password"</span> value=<span class="code-quote">"${password}"</span>/&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"maxActive"</span> value=<span class="code-quote">"10"</span>/&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"initialSize"</span> value=<span class="code-quote">"5"</span>/&gt;</span>
<span class="code-tag"><span class="code-comment">&lt;!-- Oracle specific for getString() / setString() CLOB-handling --&gt;</span></span>
<span class="code-tag">&lt;property name=<span class="code-quote">"Driver.SetBigStringTryClob"</span> value=<span class="code-quote">"true"</span>/&gt;</span>
<span class="code-tag">&lt;/datasource&gt;</span></pre>
</div>
</div>
<p>Notice the use of the property 'initialSize', this one could not be specified in the previous configuration. Additional driver-specific properties can now be specified too, these have to be prefixed with 'Driver.' (see example).</p>
<p>An exhaustive listing of all available properties can be found at the Commons DBCP projectsite: <span class="nobr"><a href="http://jakarta.apache.org/commons/dbcp/configuration.html" rel="nofollow">http://jakarta.apache.org/commons/dbcp/configuration.html<sup><img class="rendericon" height="7" alt="" src="http://opensource.atlassian.com/confluence/oss/images/icons/linkext7.gif" width="7" align="absMiddle" border="0" /></sup></a></span></p>
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+configure+a+Jakarta+DBCP-datasource" dc:identifier="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+configure+a+Jakarta+DBCP-datasource" dc:title="How do I configure a Jakarta DBCP-datasource" trackback:ping="http://opensource.atlassian.com/confluence/oss/rpc/trackback/705" />
</rdf:RDF>
--><!-- Root decorator: all decisions about how a page is to be decorated via the
                    inline decoration begins here.
--><!-- Switch based upon the context. However, for now, just delegate to a decorator
    identified directly by the context.
-->
<img src ="http://www.blogjava.net/nobody_am/aggbug/216742.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-22 23:39 <a href="http://www.blogjava.net/nobody_am/news/2008/07/22/216742.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do I use a JNDI DataSource with iBATIS in Tomcat? </title><link>http://www.blogjava.net/nobody_am/news/2008/07/22/216740.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 15:36:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/22/216740.html</guid><description><![CDATA[<p>This breaks down into two logical parts. First you have to declare the<br />
DataSource in JNDI in Tomcat. Then you have to tell iBATIS to use that<br />
object via its JNDI name.<br />
</p>
<p>分两个逻辑部分，首先你必须在Tomcat里定义JNDI的DataSource，然后你必须告诉 iBatis通过JNDI名称使用那个对象。<br />
<br />
Putting a DataSource into JNDI in Tomcat depends on the version of Tomcat<br />
you have. We'll use Tomcat 5.5 as an example here. Take a look at the<br />
Tomcat docs for specifics on your version or more details in general.<br />
设置JNDI数据源取决于tomcat的版本，我们用Tomcat5.5作为例子。通常需要参考Tomcat文档在不同版本的tomcat上设置数据源。</p>
<p>You declare JNDI DataSource objects in Tomcat using the Resource xml<br />
element. Here's an example:<br />
用Resource元素定义JNDI数据源。这是一个例子：<br />
</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeContent">
<pre class="code-xml">&lt;Resource name=<span class="code-quote">"jdbc/AS400B"</span>
type=<span class="code-quote">"javax.sql.DataSource"</span>
password=<span class="code-quote">"password"</span>
driverClassName=<span class="code-quote">"com.ibm.as400.access.AS400JDBCDriver"</span>
maxIdle=<span class="code-quote">"2"</span>
maxWait=<span class="code-quote">"5000"</span>
validationQuery=<span class="code-quote">"select * from PODATA"</span>
username=<span class="code-quote">"userid"</span>
url=<span class="code-quote">"jdbc:as400:AS400B/RPTSTEXTDB;naming=system;date format=iso;time format=hms;prompt=false"</span>
maxActive=<span class="code-quote">"4"</span>/&gt;</pre>
</div>
</div>
<p>The Resource element either goes in your global JNDI context or in a webapp<br />
specific context. To put it in your global JNDI context, put your<br />
DataSource Resource element as a child of the GlobalNamingResources element<br />
in conf/server.xml. If you put it in the global JNDI context, you need to<br />
use a ResourceLink in either your webapp's context or in the<br />
conf/context.xml (which is shared by all webapps).<br />
</p>
<p>如果想把JNDI数据源定义在全局，需要修改conf/context.xml,加入ResourceLink。<br />
<br />
Here's a ResourceLink<br />
example:</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeContent">
<pre class="code-xml"><span class="code-tag">&lt;ResourceLink name=<span class="code-quote">"jdbc/AS400B"</span> global=<span class="code-quote">"jdbc/AS400B"</span> type=<span class="code-quote">"javax.sql.DataSource"</span>/&gt;</span></pre>
</div>
</div>
<p>To put it in a webapp specific context depends on how your webapps are set<br />
up. If you have a context file for your webapp, you can put the Resource as<br />
a child of the Context element. If you don't have a context file for you<br />
webapp, you can put the Resource element as a child of the webapp's Context<br />
element in conf/server.xml.</p>
<p>Another place for the Resource element could be in the conf/context.xml<br />
file, which is shared by all webapps.</p>
<p>Once the DataSource is bound in JNDI, you need to tell iBATIS to use it.<br />
NOTE: that Tomcat helpfully prepends the string "java:/comp/env/" to your<br />
names, which is needed to do the lookups.</p>
<p>If you're using the iBATIS sqlmap xml config files, you need this:<br />
iBatis的sqlmap配置文件中，你需要这样设置数据源<br />
</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeContent">
<pre class="code-xml"><span class="code-tag">&lt;transactionManager type=<span class="code-quote">"JDBC"</span>&gt;</span>
<span class="code-tag">&lt;dataSource type=<span class="code-quote">"JNDI"</span>&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"DataSource"</span> value=<span class="code-quote">"java:/comp/env/jdbc/AS400B"</span>/&gt;</span>
<span class="code-tag">&lt;/dataSource&gt;</span>
<span class="code-tag">&lt;/transactionManager&gt;</span></pre>
</div>
</div>
<p>If you're using Spring, you need to reference the JNDI DataSource object as<br />
a JndiObjectFactoryBean and then set that as the DataSource on your<br />
SqlMapClientFactoryBean. Here's an example:<br />
Spring的配置需要如下，先用JNDI定义数据源，然后注入到SqlMapClientFacotryBean的dataSource属性里。<br />
</p>
<div class="code" style="border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid">
<div class="codeContent">
<pre class="code-xml"><span class="code-tag">&lt;bean id=<span class="code-quote">"dataSource"</span> class=<span class="code-quote">"org.springframework.jndi.JndiObjectFactoryBean"</span>&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"jndiName"</span>&gt;</span>
<span class="code-tag">&lt;value&gt;</span>java:/comp/env/jdbc/AS400B<span class="code-tag">&lt;/value&gt;</span>
<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"sqlMapClient"</span> class=<span class="code-quote">"org.springframework.orm.ibatis.SqlMapClientFactoryBean"</span>&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"configLocation"</span> value=<span class="code-quote">"classpath:sqlmap-config.xml"</span>/&gt;</span>
<span class="code-tag">&lt;property name=<span class="code-quote">"dataSource"</span> ref=<span class="code-quote">"dataSource"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span></pre>
</div>
</div>
<img src ="http://www.blogjava.net/nobody_am/aggbug/216740.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-22 23:36 <a href="http://www.blogjava.net/nobody_am/news/2008/07/22/216740.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do I use a Custom Type Handler with complex property or Type Safe Enumeration </title><link>http://www.blogjava.net/nobody_am/news/2008/07/22/216736.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 15:18:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/22/216736.html</guid><description><![CDATA[<p>Here is an example of how to set up a custom type handler with a complex property. This example uses the enum features of Java 1.5 but could be used with a Type Safe Enumeration in anything below 1.5.</p>
<p>Lets start by defining the database table</p>
<div class="code">
<div class="codeContent">
<pre class="code-java">SHAPE {
name    varchar2(25),
color   number(100)
}</pre>
</div>
</div>
<p>As you see the color is stored as a number, but in the class Shape is is a Color object. There are two question that I ran into. First, how do you cleanly map the number stored in the database with the instance of a Color? Second, how can iBatis and custom type handlers help?</p>
<p>To answer the first let me show you the code for the Shape class.</p>
<div class="code">
<div class="codeContent">
<pre class="code-java">/*
* Shape.java
*
* Created on September 23, 2005
*/
<span class="code-keyword">package</span> domain;
/**
*
* @author nmaves
*/
<span class="code-keyword">public</span> class Shape {
<span class="code-keyword">public</span> <span class="code-keyword">enum</span> Color {
BLUE(1, <span class="code-quote">"0000FF"</span>), RED(2, <span class="code-quote">"FF0000"</span>), GREEN(3, <span class="code-quote">"00FF00"</span>);
<span class="code-keyword">private</span> <span class="code-object">int</span> id;
<span class="code-keyword">private</span> <span class="code-object">String</span> rgb;
<span class="code-keyword">private</span> Type(<span class="code-object">int</span> id, <span class="code-object">String</span> name) {
<span class="code-keyword">this</span>(id, name, <span class="code-quote">"no mime type"</span>);
}
<span class="code-keyword">private</span> Type(<span class="code-object">int</span> id, <span class="code-object">String</span> rgb) {
<span class="code-keyword">this</span>.id = id;
<span class="code-keyword">this</span>. rgb = rgb;
}
<span class="code-keyword">public</span> <span class="code-object">int</span> getId() {
<span class="code-keyword">return</span> <span class="code-keyword">this</span>.id;
}
<span class="code-keyword">public</span> <span class="code-object">String</span> getRGB() {
<span class="code-keyword">return</span> <span class="code-keyword">this</span>.name;
}
<span class="code-keyword">public</span> <span class="code-keyword">static</span> Type getInstance(<span class="code-object">int</span> i) {
<span class="code-keyword">for</span>(Color color : Color.values()) {
<span class="code-keyword">if</span>(color.id == i) {
<span class="code-keyword">return</span> type;
}
}
<span class="code-keyword">throw</span> <span class="code-keyword">new</span> IllegalArgumentException(<span class="code-quote">"No such Color"</span>);
}
}
<span class="code-keyword">private</span> <span class="code-object">String</span> name;
<span class="code-keyword">private</span> Color color;
/** Creates a <span class="code-keyword">new</span> instance of Frequency */
<span class="code-keyword">private</span> Shape(<span class="code-object">String</span> name, Color color) {
<span class="code-keyword">this</span>.color = color;
<span class="code-keyword">this</span>.name = name;
}
<span class="code-keyword">public</span> <span class="code-object">String</span> toString() {
<span class="code-keyword">return</span> <span class="code-keyword">this</span>.name;
}
<span class="code-keyword">public</span> void setName(<span class="code-object">String</span> name) {
<span class="code-keyword">this</span>.name = name;
}
<span class="code-keyword">public</span> void setColor(Color color) {
<span class="code-keyword">this</span>.color = color;
}
<span class="code-keyword">public</span> <span class="code-object">String</span> getName() {
<span class="code-keyword">return</span> <span class="code-keyword">this</span>.name;
}
<span class="code-keyword">public</span> Color getColor() {
<span class="code-keyword">return</span> <span class="code-keyword">this</span>.color;
}
}</pre>
</div>
</div>
<p>As you see the <tt>getInstance(int i)</tt> method allows for the mapping of the number stored in the database to an instance of this class. I am sure there is a better way of pulling these initial value from a properties file but this is only an example.</p>
<p>For the second part you will need a way to allow iBatis to make the conversion. This is where the custom type handler comes into play.</p>
<p>Below is my ColorTypeHandler.java</p>
<div class="code">
<div class="codeContent">
<pre class="code-java"><span class="code-keyword">package</span> dao.ibatis;
<span class="code-keyword">import</span> com.ibatis.sqlmap.client.extensions.ParameterSetter;
<span class="code-keyword">import</span> com.ibatis.sqlmap.client.extensions.ResultGetter;
<span class="code-keyword">import</span> com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
<span class="code-keyword">import</span> java.sql.SQLException;
<span class="code-keyword">import</span> java.sql.Types;
<span class="code-keyword">import</span> Shape.Color;
<span class="code-keyword">public</span> class ColorTypeHandler <span class="code-keyword">implements</span> TypeHandlerCallback {
<span class="code-keyword">public</span> <span class="code-object">Object</span> getResult(ResultGetter getter) <span class="code-keyword">throws</span> SQLException {
<span class="code-object">int</span> value = getter.getInt();
<span class="code-keyword">if</span> (getter.wasNull()) {
<span class="code-keyword">return</span> <span class="code-keyword">null</span>;
}
Color color = Color.getInstance(value);
<span class="code-keyword">return</span> color;
}
<span class="code-keyword">public</span> void setParameter(ParameterSetter setter, <span class="code-object">Object</span> parameter)
<span class="code-keyword">throws</span> SQLException {
<span class="code-keyword">if</span> (parameter == <span class="code-keyword">null</span>) {
setter.setNull(Types.INTEGER);
} <span class="code-keyword">else</span> {
Color color = (Color) parameter;
setter.setInt(color.getId());
}
}
<span class="code-keyword">public</span> <span class="code-object">Object</span> valueOf(<span class="code-object">String</span> s) {
<span class="code-keyword">return</span> s;
}
}</pre>
</div>
</div>
<p>You are almost there! All you need left to do is tell iBatis to map instances of Frequency object to this handler.</p>
<p>I added the following line into my SqlMapConfig file.</p>
<div class="code">
<div class="codeContent">
<pre class="code-java">&lt;typeHandler javaType=<span class="code-quote">"domain.Shape$Color"</span> callback=<span class="code-quote">"dao.ibatis.ColorTypeHandler"</span>/&gt;</pre>
</div>
</div>
<table class="infoMacro" cellspacing="8" cellpadding="5" width="85%" align="center" border="0">
    <colgroup>
    <col width="24">
    <col></colgroup>
    <tbody>
        <tr>
            <td valign="top"><img height="16" alt="" src="http://opensource.atlassian.com/confluence/oss/images/icons/emoticons/information.gif" width="16" align="absMiddle" border="0" /></td>
            <td><strong class="strong">Useful Information</strong><br />
            <p>Notice the $ in the class name. This is how Java 1.5 denotes enums. If this were a type safe enum you would just use standard notation.</p>
            </td>
        </tr>
    </tbody>
</table>
<p>That is it. No need to change any of your other sqlmap entries. Here is an example of a select and insert that use this handler.</p>
<div class="code">
<div class="codeContent">
<pre class="code-java">&lt;resultMap class=<span class="code-quote">"Shape"</span> id=<span class="code-quote">"ShapeResult"</span>&gt;
&lt;result column=<span class="code-quote">"name"</span> property=<span class="code-quote">"name"</span> /&gt;
&lt;result column=<span class="code-quote">"color"</span> property=<span class="code-quote">"color"</span> /&gt;
&lt;/resultMap&gt;
&lt;select id=<span class="code-quote">"getShapeByName"</span> parameterClass=<span class="code-quote">"string"</span> resultMap=<span class="code-quote">"ShapeResult"</span>&gt;
SELECT
*
FROM
SHAPE
WHERE
name = #value#
&lt;/select&gt;
&lt;insert id=<span class="code-quote">"insertReport"</span> parameterClass=<span class="code-quote">"Report"</span>&gt;
INSERT INTO
SHAPE (
name,
color
)
values (
#name#,
#color#,
)
&lt;/insert&gt;</pre>
</div>
</div>
<p>Notice that there is nothing special that need to be done for the color columns.</p>
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+use+a+Custom+Type+Handler+with+complex+property+or+Type+Safe+Enumeration" dc:identifier="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+use+a+Custom+Type+Handler+with+complex+property+or+Type+Safe+Enumeration" dc:title="How do I use a Custom Type Handler with complex property or Type Safe Enumeration" trackback:ping="http://opensource.atlassian.com/confluence/oss/rpc/trackback/66" />
</rdf:RDF>
--><!-- Root decorator: all decisions about how a page is to be decorated via the
                    inline decoration begins here.
--><!-- Switch based upon the context. However, for now, just delegate to a decorator
    identified directly by the context.
-->
<img src ="http://www.blogjava.net/nobody_am/aggbug/216736.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-22 23:18 <a href="http://www.blogjava.net/nobody_am/news/2008/07/22/216736.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do I use POUND or DOLLAR symbols in my queries </title><link>http://www.blogjava.net/nobody_am/news/2008/07/22/216733.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 15:08:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/22/216733.html</guid><description><![CDATA[<p>Both # and $ can be escaped by doubling: ## or $$ respectively.<br />
#和$都能被##和$$转义。<br />
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+use+POUND+or+DOLLAR+symbols+in+my+queries" dc:identifier="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+use+POUND+or+DOLLAR+symbols+in+my+queries" dc:title="How do I use POUND or DOLLAR symbols in my queries" trackback:ping="http://opensource.atlassian.com/confluence/oss/rpc/trackback/53" />
</rdf:RDF>
--><!-- Root decorator: all decisions about how a page is to be decorated via the
                    inline decoration begins here.
--><!-- Switch based upon the context. However, for now, just delegate to a decorator
    identified directly by the context.
--></p>
<img src ="http://www.blogjava.net/nobody_am/aggbug/216733.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-22 23:08 <a href="http://www.blogjava.net/nobody_am/news/2008/07/22/216733.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do I use LIKE in my queries </title><link>http://www.blogjava.net/nobody_am/news/2008/07/22/216732.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 15:06:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/22/216732.html</guid><description><![CDATA[<p>Because iBATIS uses PreparedStatement for mapped statements, you have to use the $value$ syntax, or make your parameter contain your % or _ characters. For example, let's say you want your database will end up with is this:<br />
</p>
<p>因为iBatis用PreparedStatement来映射statement，你必须用$value$语法，或者确保你的参数包含你的% 或_字符。例如，假设你项执行下面的语句：<br />
<br />
select * from foo where value like 'x%'</p>
<p>You can do this:<br />
</p>
<p>你可以这么写sqlmap语句：<br />
<br />
select * from foo where value like #parm#</p>
<p>But if you do, it becomes this:<br />
</p>
<p>但是如果你这么做，他将按照下面语句执行<br />
select * from foo where value like ?</p>
<p>To make that do what you want, you need to make the parameter "x%" by setting parm to "x%". <br />
</p>
<p>为了保证你的目标，你需要把"x%"作为参数值。<br />
<br />
If you do not like that approach, you can do this instead:<br />
如果你不想这么做，你可以用下面的取代：</p>
<p>select * from foo where value like '$parm$%'</p>
<p>That still uses a PreparedStatement, but the $parm$ gets inserted as a literal instead of a parameter. So, to get the same results as before, you would set parm to "x". Note that this can be vulnerable to SQL injection attacks, so make sure that all single quotes are escaped in parm.<br />
这仍然用PreparedStatement，但是$parm$用parameter作为占位符，所以，为了得到结果，你应该设置参数为x。<br />
注意这可能引起SQL注入攻击，所以确保所有参数里的单引号被过滤到<br />
</p>
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+use+LIKE+in+my+queries" dc:identifier="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+use+LIKE+in+my+queries" dc:title="How do I use LIKE in my queries" trackback:ping="http://opensource.atlassian.com/confluence/oss/rpc/trackback/52" />
</rdf:RDF>
-->
 <img src ="http://www.blogjava.net/nobody_am/aggbug/216732.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-22 23:06 <a href="http://www.blogjava.net/nobody_am/news/2008/07/22/216732.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do I improve SQL Map performance </title><link>http://www.blogjava.net/nobody_am/news/2008/07/22/216730.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 14:56:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/22/216730.html</guid><description><![CDATA[<p>If you're using SQL Maps 2.0, then here's what you want to do (in<br />
order of importance):<br />
</p>
<p>如果你项用SQL Maps2.0，那么下面就是你要作的<br />
<br />
1. Ensure you've specified a parameterMap or parameterClass attribute<br />
on your statement.<br />
1,确保在在你的statement里描述了parameterMap或parameterClass</p>
<p>2. Use an explicitly defined &lt;resultMap&gt; and DON'T allow remapping of<br />
results (new 2.0.9 feature)<br />
</p>
<p>2，用一个显示的定义&lt;resultMap&gt;并且不要允许重映射一个结果。<br />
<br />
3. Use a Java``Bean (not a Map or XML etc.)<br />
3，用JavaBean，不要用Map或xml等。</p>
<p>4. Make sure all of your properties are "simple properties" (no<br />
dot.notation, array[] access or mixed bean/map properties).<br />
</p>
<p>4，确保所有你的属性是简单属性，不是点号格开，数组下表访问或混合bean、map属性。<br />
<br />
5. Try enabling bytecode enhancement in your &lt;settings&gt; element.<br />
5，在&lt;setting&gt;元素打开bytcode enhancement</p>
 <img src ="http://www.blogjava.net/nobody_am/aggbug/216730.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-22 22:56 <a href="http://www.blogjava.net/nobody_am/news/2008/07/22/216730.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do I get SqlMapClient to log SQL statements </title><link>http://www.blogjava.net/nobody_am/news/2008/07/22/216727.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 14:51:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/22/216727.html</guid><description><![CDATA[<p>iBATIS uses commons-logging to log these.<br />
</p>
<p>iBatis用commons-logging来记录这些日志。<br />
<br />
Depending on your logging implementation, your configuration may vary.<br />
依赖于你的日志实现，你的配置可能改变。<br />
<br />
</p>
<p>If you are using log4j, put this line into log4j.properties:<br />
如果你用log4j，把下面这行放入log4j.properties:<br />
<br />
</p>
<p>log4j.logger.java.sql=DEBUG</p>
<p>If you set your default log level to DEBUG, that will work, too...but you will get debug level logging for everything in the world. <br />
</p>
<p>如果你设置默认的日志级别为DEBUG，他将工作，但是你获得全世界每个debug级别的日志。<br />
<br />
Here is another example of how to configure ibatis with log4j using an xml config file.<br />
下面是另一个例子，怎么样用xml格式的log4j配置ibatis</p>
<div class="code">
<div class="codeHeader"><strong>log4j.xml</strong></div>
<div class="codeContent">
<pre class="code-java">&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span> ?&gt;
&lt;!DOCTYPE log4j:configuration SYSTEM <span class="code-quote">"log4j.dtd"</span>&gt;
&lt;log4j:configuration xmlns:log4j=<span class="code-quote">"http:<span class="code-comment">//jakarta.apache.org/log4j/"</span>&gt;
</span>
&lt;!-- Console output --&gt;
&lt;appender name=<span class="code-quote">"STDOUT"</span> class=<span class="code-quote">"org.apache.log4j.ConsoleAppender"</span>&gt;
&lt;layout class=<span class="code-quote">"org.apache.log4j.PatternLayout"</span>&gt;
&lt;param name=<span class="code-quote">"ConversionPattern"</span> value=<span class="code-quote">"%-5p %d{MM-dd HH:mm:ss} %m  (%F:%L) \n"</span>/&gt;
&lt;/layout&gt;
&lt;/appender&gt;
&lt;category name=<span class="code-quote">"com.ibatis"</span>&gt;
&lt;priority value=<span class="code-quote">"debug"</span> /&gt;
&lt;/category&gt;
&lt;category name=<span class="code-quote">"java.sql"</span>&gt;
&lt;priority value=<span class="code-quote">"debug"</span> /&gt;
&lt;/category&gt;
&lt;!--The root category defines the top level of appenders all catagories inherit --&gt;
&lt;root&gt;
&lt;priority value =<span class="code-quote">"error"</span> /&gt;
&lt;appender-ref ref=<span class="code-quote">"STDOUT"</span> /&gt;
&lt;/root&gt;
&lt;/log4j:configuration&gt;</pre>
</div>
</div>
<p>A common question is "Is it possible to show the ACTUAL query being executed?".<br />
</p>
<p>一个更通常的问题：有可能展示某个真正的查询被执行了吗？<br />
The simple answer is NO.<br />
简单得回答：没有</p>
<p>Why? Because the only information we have available is the PreparedStatement and the parameters.<br />
</p>
<p>为什么？因为我们只能获得preparestatement和参数<br />
Quite often, in the process of applying those parameters to the mapped statement it will become very clear where issues lie in the execution of the query.<br />
</p>
<p>更经常，在把参数匹配到statement这个过程中，很明显能看出查询过程哪里有问题。<br />
If you feel that you NEED to see the completed query, you may be interested in hooking up a debugging tool like <span class="nobr"><a href="http://www.p6spy.com/" rel="nofollow">p6spy<sup><img class="rendericon" height="7" alt="" src="http://opensource.atlassian.com/confluence/oss/images/icons/linkext7.gif" width="7" align="absMiddle" border="0" /></sup></a></span>, as it may answer your questions for you.<br />
如果你项看到完整得查询，你最好用p6spy这样得debug工具。</p>
<p>For WebSphere-specific instructions see also <a title="How do I Configure Logging in WebSphere" href="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+Configure+Logging+in+WebSphere">How do I Configure Logging in WebSphere</a>.<br />
Websphare规范简介参考W@!#%@%RQEWRWQR</p>
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+get+SqlMapClient+to+log+SQL+statements" dc:identifier="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+get+SqlMapClient+to+log+SQL+statements" dc:title="How do I get SqlMapClient to log SQL statements" trackback:ping="http://opensource.atlassian.com/confluence/oss/rpc/trackback/49" />
</rdf:RDF>
--><!-- Root decorator: all decisions about how a page is to be decorated via the
                    inline decoration begins here.
--><!-- Switch based upon the context. However, for now, just delegate to a decorator
    identified directly by the context.
-->
 <img src ="http://www.blogjava.net/nobody_am/aggbug/216727.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-22 22:51 <a href="http://www.blogjava.net/nobody_am/news/2008/07/22/216727.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do I get around the N Plus 1 selects problem </title><link>http://www.blogjava.net/nobody_am/news/2008/07/22/216725.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 14:42:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/22/216725.html</guid><description><![CDATA[<p>Here is one solution.<br />
这是一个解决方案<br />
</p>
<div class="code">
<div class="codeHeader"><strong>nplusone.xml</strong></div>
<div class="codeContent">
<pre class="code-java">&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span> standalone=<span class="code-quote">"no"</span>?&gt;
&lt;!DOCTYPE sqlMap PUBLIC <span class="code-quote">"-<span class="code-comment">//ibatis.apache.org//DTD SQL Map 2.0//EN"</span> <span class="code-quote">"http://ibatis.apache.org/dtd/sql-map-2.dtd"</span>&gt;
</span>&lt;sqlMap namespace=<span class="code-quote">"Calendar"</span>&gt;
&lt;resultMap id=<span class="code-quote">"quarterMap"</span> class=<span class="code-quote">"calendarQuarter"</span> groupBy=<span class="code-quote">"quarter"</span>&gt;
&lt;result property=<span class="code-quote">"quarter"</span> column=<span class="code-quote">"quarter"</span>/&gt;
&lt;result property=<span class="code-quote">"name"</span> column=<span class="code-quote">"name"</span>/&gt;
&lt;result property=<span class="code-quote">"description"</span> column=<span class="code-quote">"description"</span>/&gt;
&lt;result property=<span class="code-quote">"months"</span> resultMap=<span class="code-quote">"Calendar.monthMap"</span>/&gt;
&lt;/resultMap&gt;
&lt;resultMap id=<span class="code-quote">"monthMap"</span> class=<span class="code-quote">"calendarMonth"</span>&gt;
&lt;result property=<span class="code-quote">"name"</span> column=<span class="code-quote">"monthName"</span>/&gt;
&lt;result property=<span class="code-quote">"description"</span> column=<span class="code-quote">"monthDescription"</span>/&gt;
&lt;result property=<span class="code-quote">"broadcastStartDate"</span> column=<span class="code-quote">"broadcastStartDate"</span>/&gt;
&lt;result property=<span class="code-quote">"broadcastEndDate"</span> column=<span class="code-quote">"broadcastEndDate"</span>/&gt;
&lt;/resultMap&gt;
&lt;select id=<span class="code-quote">"getQuartersForServiceYear"</span> resultMap=<span class="code-quote">"quarterMap"</span>&gt;
select distinct
QuarterNumber as quarter,
QuarterName as name,
QuarterDesc as description,
SeasonYear as year,
MonthName as monthName,
MonthDesc as monthDescription,
min(broadcastDate) as broadcastStartDate,
max(broadcastDate) as broadcastEndDate
from BroadcastDate
where SeasonYear = #year#
and MonthName is not <span class="code-keyword">null</span>
group by
QuarterDesc,
QuarterNumber,
QuarterName,
SeasonYear,
MonthName,
MonthDesc
order by broadcastStartDate
&lt;/select&gt;
&lt;/sqlMap&gt;</pre>
</div>
</div>
<p>When you call <br />
接着你可以调用<br />
<div class="code">
<div class="codeContent">
<pre class="code-java">List myList = executeQueryForList(<span class="code-quote">"Calendar.getQuartersForServiceYear"</span>, 2005);</pre>
</div>
</div>
the main query is executed, and the results are stored in the <tt>myList</tt> variable as beans of type "calendarQuarter" (an alias). Each object in that List will have a "months" property that is also a List populated from the same query, but using the "monthMap" result map to populate the beans in the child lists. So, you end up with a list containing sub-lists, and only one database query is executed. <br />
<p>主查询被执行，并且在myList里存储calendarQuarter为别名的对象。在List里的每个&#8220;months&#8221;属性里还有一个初始化的子列表，这个子列表的数据也来自这次查询。但是用monthMap结果map来渲染子列表。所以，你得到了一个含有子列表的列表，并且只有一次数据库查询被执行。<br />
</p>
<p>The important items here are the <br />
重要的项在groupby的属性和months属性。<br />
<div class="code">
<div class="codeContent">
<pre class="code-java">groupBy</pre>
</div>
</div>
attribute and the <br />
<br />
<div class="code">
<div class="codeContent">
<pre class="code-java">&lt;result property=<span class="code-quote">"months"</span> resultMap=<span class="code-quote">"Calendar.monthMap"</span>/&gt;</pre>
</div>
</div>
property mapping in the "quarterMap" result map. One other important detail is that the result mapping for the months property is namespace aware - had it been simply "monthMap" it would not work. <br />
<p>另一个需要注意的是month属性的结果映射名是命名空间敏感的－如果配置成&#8220;monthMap&#8221;,他将不能工作。<br />
</p>
<p><strong>Summary:</strong> You have a single query that will return results such as<br />
总结：你有一个简单的查询，他返回下面这样的结果<br />
</p>
<div class="code">
<div class="codeContent">
<pre class="code-java">parent1, child1
parent1, child2
parent2, child1
parent3, child1
parent3, child2
parent3, child3
....</pre>
</div>
</div>
<p>The groupby will take care of figuring out that you really want a list of parent objects with their matching child objects as a list under them.<br />
这个groupby将处理你想得到的父对象组成的列表和相应的在父对象之下的子对象组成的列表。<br />
</p>
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+get+around+the+N+Plus+1+selects+problem" dc:identifier="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+get+around+the+N+Plus+1+selects+problem" dc:title="How do I get around the N Plus 1 selects problem" trackback:ping="http://opensource.atlassian.com/confluence/oss/rpc/trackback/43" />
</rdf:RDF>
--><!-- Root decorator: all decisions about how a page is to be decorated via the
                    inline decoration begins here.
--><!-- Switch based upon the context. However, for now, just delegate to a decorator
    identified directly by the context.
-->
<img src ="http://www.blogjava.net/nobody_am/aggbug/216725.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-22 22:42 <a href="http://www.blogjava.net/nobody_am/news/2008/07/22/216725.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do I call a stored procedure </title><link>http://www.blogjava.net/nobody_am/news/2008/07/22/216720.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Tue, 22 Jul 2008 14:24:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/22/216720.html</guid><description><![CDATA[<p>OK, this is in the User's Guide, but since you apparently did not read it, here it is again. <img class="emoticon" height="20" alt="" src="http://opensource.atlassian.com/confluence/oss/images/icons/emoticons/wink.gif" width="20" align="absMiddle" border="0" /><br />
</p>
<p>这在用户指南里提到过，但是既然你显然没有看过，这里复述一遍。<br />
<br />
Stored procedures are supported via the &lt;procedure&gt; statement element. The following example shows how a stored procedure would be used with output parameters.<br />
存储过程通过&lt;procedure&gt;元素来支持，下面的例子展示怎么样通过output参数来显示怎么使用存储过程。</p>
<div class="code">
<div class="codeHeader"><strong>procedure.xml</strong></div>
<div class="codeContent">
<pre class="code-java">&lt;parameterMap id=<span class="code-quote">"swapParameters"</span> class=<span class="code-quote">"map"</span> &gt;
&lt;parameter property=<span class="code-quote">"email1"</span> jdbcType=<span class="code-quote">"VARCHAR"</span> javaType=<span class="code-quote">"java.lang.<span class="code-object">String</span>"</span> mode=<span class="code-quote">"INOUT"</span>/&gt;
&lt;parameter property=<span class="code-quote">"email2"</span> jdbcType=<span class="code-quote">"VARCHAR"</span> javaType=<span class="code-quote">"java.lang.<span class="code-object">String</span>"</span> mode=<span class="code-quote">"INOUT"</span>/&gt;
&lt;/parameterMap&gt;
&lt;procedure id=<span class="code-quote">"swapEmailAddresses"</span> parameterMap=<span class="code-quote">"swapParameters"</span> &gt;
{call swap_email_address (?, ?)}
&lt;/procedure&gt;</pre>
</div>
</div>
<p>Calling the above procedure would swap two email addresses between two columns (database table) and also in the parameter object (Map). The parameter object is only modified if the parameter mappings mode attribute is set to ?INOUT? or ?OUT?. Otherwise they are left unchanged. Obviously immutable parameter objects (e.g. String) cannot be modified.<br />
</p>
<p>调用上面的存储过程将交换表的两列和输入参数的map里的两个值。参数对象只有在设置位INOUT或OUT时，调换元素位置。否则他们保持不动，显然不便对象String时不能够改动的。<br />
<br />
Note! Always be sure to use the standard JDBC stored procedure syntax. See the JDBC CallableStatement documentation for more information.<br />
注意！总是确保使用标准的JDBC存储过程语法。看JDBC的CallableStatement文档获取更多内容。</p>
<h3><a name="HowdoIcallastoredprocedure-WhatSqlMapClientMethodShouldIUse%3F"></a>What SqlMapClient Method Should I Use?</h3>
<p>我应该用哪些SqlMapClient方法？</p>
<p>It depends. Here is some help...<br />
</p>
<p>那样看情况了，下面这些帮你作出选择...<br />
<br />
If your procedure returns a result set (not a result set in an OUT parameter, but a result set from the procedure itself), then use <strong>queryForList()</strong> or <strong>queryForObject()</strong>. Use queryForList() if you expect more than one result object, or queryForObject() if you expect only one result Object.<br />
如果存储过程返回一个Result Set（不是一个OUT参数，而是来自存储过程自身的Result Set），那么用queryForList()或者queryForObject().<br />
当有多个结果对象时，用queryForList(),否则如果有一个结果对象，使用QueryForObject().</p>
<p>If your procedure returns a result set AND updates data, then you should also configure your <strong>&lt;transactionManager&gt;</strong> with the attribute <strong>commitRequired="true"</strong>. <br />
</p>
<p>如果你的存储过程返回一个结果，并且更新了数据，那么你应该还要配置&lt;transactionManager&gt;，设置commitRequired="true"<br />
<br />
If your procedure does not return result sets, or only returns result sets in OUT parameters, then use the <strong>update()</strong> method.<br />
如果你的存储过程没有返回结果集，而是仅仅从OUT 参数返回结果集，那么用update()方法。</p>
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+call+a+stored+procedure" dc:identifier="http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+call+a+stored+procedure" dc:title="How do I call a stored procedure" trackback:ping="http://opensource.atlassian.com/confluence/oss/rpc/trackback/39" />
</rdf:RDF>
--><!-- Root decorator: all decisions about how a page is to be decorated via the
                    inline decoration begins here.
--><!-- Switch based upon the context. However, for now, just delegate to a decorator
    identified directly by the context.
-->
<img src ="http://www.blogjava.net/nobody_am/aggbug/216720.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-22 22:24 <a href="http://www.blogjava.net/nobody_am/news/2008/07/22/216720.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Converting iBATIS DAO to Spring DAO </title><link>http://www.blogjava.net/nobody_am/news/2008/07/20/216205.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Sun, 20 Jul 2008 10:25:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/20/216205.html</guid><description><![CDATA[<p>The iBATIS DAO has been depreciated and it is recommended that you use the Spring framework instead. This document (originally posted to the user-java list by a user) describes the steps taken to convert jpetstore5 from iBATIS DAO to Spring DAO.<br />
<br />
<span style="background-color: yellow">iBatis DAO已经不建议使用，推荐使用Springframework。这份文档描述如何转换JPetstore5的iBatis DAO到Spring DAO。<br />
</span></p>
<h2><a name="ConvertingiBATISDAOtoSpringDAO-Convertingjpetshop5toibatisspring"></a>Converting jpetshop5 to ibatis-spring</h2>
<p><span style="background-color: yellow">JPetshop5到IBatis－Spring的转换</span></p>
<p>Prerequisite is to have a project similar to jpetstore5, and have it connected to a 'normal' database</p>
<p>There is support for hssqldb in the DaoConfig class what we are going to give up (for now).<br />
</p>
<span style="background-color: yellow">前提是有一个类似jpetstore5的项目，把他链接到正常的数据库上，在daoconfig类里支持hssqldb，我们将放弃对这个类的支持。</span><br />
<h3><a name="ConvertingiBATISDAOtoSpringDAO-Updatingthejarfiles"></a>Updating the jar files</h3>
<p><strong style="background-color: yellow">更新jar文件</strong></p>
<p>Remove the old iBATIS jar files from the class path and create the reference to the new iBATIS and Spring jars:<br />
<span style="background-color: yellow">删除旧的ibatis JAR文件，添加到新的ibatis和spring JAR文件</span></p>
<ul>
    <li>Remove ibatis-common-2.jar
    <li>Remove ibatis-dao-2.jar
    <li>Remove ibatis-sqlmap-2.jar
    <li>Add ibatis-2.3.0.677.jar
    <li>Add spring.jar
    <li>Add commons-dbcp-1.2.1.jar
    <li>Add commons-pool-1.2.jar
    <li>Add commons-collections.jar </li>
</ul>
<h3><a name="ConvertingiBATISDAOtoSpringDAO-Makingthecodechanges"></a>Making the code changes</h3>
<p><strong style="background-color: yellow">改变代码</strong></p>
<p>First, we need to extend the Spring support classes:<br />
<span style="background-color: yellow">首先，我们需要扩展spring的支持类</span><br />
</p>
<div class="code">
<div class="codeHeader"><strong>BaseSqlMapDao.java</strong></div>
<div class="codeContent">
<pre class="code-java"><span class="code-keyword">public</span> class BaseSqlMapDao <span class="code-keyword">extends</span> SqlMapClientTemplate {
<span class="code-keyword">protected</span> <span class="code-keyword">static</span> <span class="code-keyword">final</span> <span class="code-object">int</span> PAGE_SIZE = 4;
}</pre>
</div>
</div>
<p>Next, we can remove the old constructors (that have the DaoManager parameter), as well as the import for the DaoManager from all of the other SqlMapDao files.<br />
</p>
<p><span style="background-color: yellow">下一步，我们删除旧的构造器(有DaoManager参数)，在所有的sqlMapDao文件里删除对DaoManager的引入。</span><br />
<br />
<span style="background-color: yellow">We also need to remove the default constructors from the service classes in the com.ibatis.jpetstore.service package, because the DAO will be injected by spring.<br />
我们还需要从com.ibatis.jpetstore.service包的服务类里删除默认的构造器，因为DAO将被Spring注入。</span></p>
<h3><a name="ConvertingiBATISDAOtoSpringDAO-Dealingwithtransactions%28todo%29"></a>Dealing with transactions (todo)</h3>
<p><strong style="background-color: yellow">处理事务</strong></p>
<p>There is some code to work with transactions in OrderService.java which we'll need to handle differently, but for the moment, we'll remove it here, and remove the DaoManager from the constructor.<br />
<span style="background-color: yellow">在OrderService里，有一些与事务有关的代码，这个OrderService我们需要不同的处理，但是目前，我们删除他，并且删除从构造器里删除DaoManager。<br />
</span></p>
<div class="code">
<div class="codeHeader"><strong>OrderService.java</strong></div>
<div class="codeContent">
<pre class="code-java"><span class="code-keyword">public</span> OrderService(ItemDao itemDao, OrderDao orderDao, SequenceDao sequenceDao) {
<span class="code-keyword">this</span>.itemDao = itemDao;
<span class="code-keyword">this</span>.orderDao = orderDao;
<span class="code-keyword">this</span>.sequenceDao = sequenceDao;
}</pre>
</div>
</div>
<h3><a name="ConvertingiBATISDAOtoSpringDAO-LinkingSpringandiBATIS"></a>Linking Spring and iBATIS</h3>
<p><strong style="background-color: yellow">链接Spring和iBatis</strong></p>
<p>We'll add the SpringInit.java class:<br />
<span style="background-color: yellow">我们增加SpringInit.java类</span><br />
</p>
<div class="code">
<div class="codeHeader"><strong>SpringInit.java</strong></div>
<div class="codeContent">
<pre class="code-java"><span class="code-keyword">public</span> class SpringInit <span class="code-keyword">implements</span> ServletContextListener {
<span class="code-keyword">private</span> <span class="code-keyword">static</span> WebApplicationContext springContext;
<span class="code-keyword">public</span> void contextInitialized(ServletContextEvent event) {
springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
}
<span class="code-keyword">public</span> void contextDestroyed(ServletContextEvent event) {
springContext = <span class="code-keyword">null</span>;
}
<span class="code-keyword">public</span> <span class="code-keyword">static</span> ApplicationContext getApplicationContext() {
<span class="code-keyword">return</span> springContext;
}
}</pre>
</div>
</div>
<p>This class will be instantiated when the website starts, and will contain a reference to the spring managed objects.<br />
<span style="background-color: yellow">当网站启动时，这个类被实例化，并前包含了一个对spring管理的对象的引用。</span><br />
</p>
<p>The presentation layer must connect with the spring managed service layer, so remove the default constructors because we'll be pulling the services from Spring instead.<br />
<span style="background-color: yellow">展示层必须与spring管理的服务层的关联，所以必须删除默认的构造器，因为我们从spring拉服务。<br />
</span></p>
<div class="code">
<div class="codeHeader"><strong>AccountBean.java</strong></div>
<div class="codeContent">
<pre class="code-java"><span class="code-keyword">public</span> AccountBean() {
<span class="code-keyword">this</span>(<span class="code-keyword">new</span> AccountService(), <span class="code-keyword">new</span> CatalogService());
}</pre>
</div>
</div>
<p>Would be replaced with:<br />
<span style="background-color: yellow">上面代码用下面的代码替换：</span><br />
</p>
<div class="code">
<div class="codeHeader"><strong>AccountBean.java</strong></div>
<div class="codeContent">
<pre class="code-java"><span class="code-keyword">public</span> AccountBean() {
<span class="code-keyword">this</span>(
(AccountService) SpringInit.getApplicationContext().getBean(<span class="code-quote">"accountService"</span>),
(CatalogService) SpringInit.getApplicationContext().getBean(<span class="code-quote">"catalogService"</span>)
);
}</pre>
</div>
</div>
<p>This would be repeated for all of the other classes in the presentation package.<br />
<span style="background-color: yellow">在展示层的其他类里也需要做相同的处理。<br />
</span></p>
<h3><a name="ConvertingiBATISDAOtoSpringDAO-Configuration"></a>Configuration</h3>
<p><strong>配置</strong></p>
<p>First setup the listeners to have SpringInit initiated on loading of the site<br />
<span style="background-color: yellow">第一步，建立一个listener让SpringInit在站点启动时初始化</span><br />
</p>
<div class="code">
<div class="codeHeader"><strong>/WEB-INF/web.xml</strong></div>
<div class="codeContent">
<pre class="code-java">&lt;context-param&gt;
&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
&lt;param-value&gt;/WEB-INF/spring.xml&lt;/param-value&gt;
&lt;/context-param&gt;
&lt;listener&gt;
&lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
&lt;/listener&gt;
&lt;listener&gt;
&lt;listener-class&gt;com.listeners.SpringInit&lt;/listener-class&gt;
&lt;/listener&gt;</pre>
</div>
</div>
<p>This tells your context to look for /WEB-INF/spring.xml - this is the one created for jpetstore5:<br />
<span style="background-color: yellow">这个告诉你的上下文去/web-inf/spring.xml里查找－这个时为jpetstore5创建的文件。</span><br />
</p>
<div class="code">
<div class="codeHeader"><strong>/WEB-INF/spring.xml</strong></div>
<div class="codeContent">
<pre class="code-java">&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;
&lt;!DOCTYPE beans PUBLIC <span class="code-quote">"-<span class="code-comment">//SPRING//DTD BEAN//EN"</span>
</span>        <span class="code-quote">"http:<span class="code-comment">//www.springframework.org/dtd/spring-beans.dtd"</span>&gt;
</span>&lt;beans&gt;
&lt;bean id=<span class="code-quote">"propertyConfigurer"</span> class=<span class="code-quote">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span>&gt;
&lt;property name=<span class="code-quote">"location"</span> value=<span class="code-quote">"classpath:properties/database.properties"</span>/&gt;
&lt;/bean&gt;
&lt;bean id=<span class="code-quote">"dataSource"</span> class=<span class="code-quote">"org.apache.commons.dbcp.BasicDataSource"</span>&gt;
&lt;property name=<span class="code-quote">"driverClassName"</span> value=<span class="code-quote">"${driver}"</span>/&gt;
&lt;property name=<span class="code-quote">"url"</span> value=<span class="code-quote">"${url}"</span>/&gt;
&lt;property name=<span class="code-quote">"username"</span> value=<span class="code-quote">"${username}"</span>/&gt;
&lt;property name=<span class="code-quote">"password"</span> value=<span class="code-quote">"${password}"</span>/&gt;
&lt;/bean&gt;
&lt;bean id=<span class="code-quote">"sqlMapClient"</span>
class=<span class="code-quote">"org.springframework.orm.ibatis.SqlMapClientFactoryBean"</span>&gt;
&lt;property name=<span class="code-quote">"configLocation"</span>&gt;
&lt;value&gt;classpath:com/ibatis/jpetstore/persistence/sqlmapdao/sql/sql-map-config.xml&lt;/value&gt;
&lt;/property&gt;
&lt;property name=<span class="code-quote">"useTransactionAwareDataSource"</span>&gt;
&lt;value&gt;<span class="code-keyword">true</span>&lt;/value&gt;
&lt;/property&gt;
&lt;property name=<span class="code-quote">"dataSource"</span>&gt;
&lt;ref bean=<span class="code-quote">"dataSource"</span>/&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id=<span class="code-quote">"sqlMapClientTemplate"</span>
class=<span class="code-quote">"org.springframework.orm.ibatis.SqlMapClientTemplate"</span>&gt;
&lt;property name=<span class="code-quote">"sqlMapClient"</span>&gt;
&lt;ref bean=<span class="code-quote">"sqlMapClient"</span>/&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id=<span class="code-quote">"accountDao"</span> class=<span class="code-quote">"com.ibatis.jpetstore.persistence.sqlmapdao.AccountSqlMapDao"</span>&gt;
&lt;property name=<span class="code-quote">"sqlMapClient"</span>&gt;
&lt;ref bean=<span class="code-quote">"sqlMapClient"</span>/&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id=<span class="code-quote">"categoryDao"</span> class=<span class="code-quote">"com.ibatis.jpetstore.persistence.sqlmapdao.CategorySqlMapDao"</span>&gt;
&lt;property name=<span class="code-quote">"sqlMapClient"</span>&gt;
&lt;ref bean=<span class="code-quote">"sqlMapClient"</span>/&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id=<span class="code-quote">"itemDao"</span> class=<span class="code-quote">"com.ibatis.jpetstore.persistence.sqlmapdao.ItemSqlMapDao"</span>&gt;
&lt;property name=<span class="code-quote">"sqlMapClient"</span>&gt;
&lt;ref bean=<span class="code-quote">"sqlMapClient"</span>/&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id=<span class="code-quote">"orderDao"</span> class=<span class="code-quote">"com.ibatis.jpetstore.persistence.sqlmapdao.OrderSqlMapDao"</span>&gt;
&lt;property name=<span class="code-quote">"sqlMapClient"</span>&gt;
&lt;ref bean=<span class="code-quote">"sqlMapClient"</span>/&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id=<span class="code-quote">"productDao"</span> class=<span class="code-quote">"com.ibatis.jpetstore.persistence.sqlmapdao.ProductSqlMapDao"</span>&gt;
&lt;property name=<span class="code-quote">"sqlMapClient"</span>&gt;
&lt;ref bean=<span class="code-quote">"sqlMapClient"</span>/&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id=<span class="code-quote">"sequenceDao"</span> class=<span class="code-quote">"com.ibatis.jpetstore.persistence.sqlmapdao.SequenceSqlMapDao"</span>&gt;
&lt;property name=<span class="code-quote">"sqlMapClient"</span>&gt;
&lt;ref bean=<span class="code-quote">"sqlMapClient"</span>/&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id=<span class="code-quote">"accountService"</span> class=<span class="code-quote">"com.ibatis.jpetstore.service.AccountService"</span>&gt;
&lt;constructor-arg index=<span class="code-quote">"0"</span> ref=<span class="code-quote">"accountDao"</span>/&gt;
&lt;/bean&gt;
&lt;bean id=<span class="code-quote">"catalogService"</span> class=<span class="code-quote">"com.ibatis.jpetstore.service.CatalogService"</span>&gt;
&lt;constructor-arg index=<span class="code-quote">"0"</span> ref=<span class="code-quote">"categoryDao"</span>/&gt;
&lt;constructor-arg index=<span class="code-quote">"1"</span> ref=<span class="code-quote">"itemDao"</span>/&gt;
&lt;constructor-arg index=<span class="code-quote">"2"</span> ref=<span class="code-quote">"productDao"</span>/&gt;
&lt;/bean&gt;
&lt;bean id=<span class="code-quote">"orderService"</span> class=<span class="code-quote">"com.ibatis.jpetstore.service.OrderService"</span>&gt;
&lt;constructor-arg index=<span class="code-quote">"0"</span> ref=<span class="code-quote">"itemDao"</span>/&gt;
&lt;constructor-arg index=<span class="code-quote">"1"</span> ref=<span class="code-quote">"orderDao"</span>/&gt;
&lt;constructor-arg index=<span class="code-quote">"2"</span> ref=<span class="code-quote">"sequenceDao"</span>/&gt;
&lt;/bean&gt;
&lt;/beans&gt;</pre>
</div>
</div>
<h3><a name="ConvertingiBATISDAOtoSpringDAO-Cleanup"></a>Cleanup</h3>
<p><strong style="background-color: yellow">清扫</strong></p>
<p>Remove the DaoConfig.java class and the dao.xml file from the com.ibatis.jpetstore.persistence package.<br />
<span style="background-color: yellow">从com.ibatis.jpetstore.persistence包删除DaoConfig.java类和dao.xml文件。</span><br />
</p>
<h2><a name="ConvertingiBATISDAOtoSpringDAO-Conclusion"></a>Conclusion</h2>
<p><strong style="background-color: yellow">总结</strong></p>
<p>&nbsp;</p>
<p>This is still a work in progress, so please feel free to add comments and suggestions for making it better. <br />
<span style="background-color: yellow">这个个工作还在进行中，所以请随意添加备注和建议，使得他更完善。</span></p>
<img src ="http://www.blogjava.net/nobody_am/aggbug/216205.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-20 18:25 <a href="http://www.blogjava.net/nobody_am/news/2008/07/20/216205.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>What is the difference between the iBATIS DAO framework and iBATIS SQL Maps</title><link>http://www.blogjava.net/nobody_am/news/2008/07/20/216197.html</link><dc:creator>MingIsMe</dc:creator><author>MingIsMe</author><pubDate>Sun, 20 Jul 2008 09:45:00 GMT</pubDate><guid>http://www.blogjava.net/nobody_am/news/2008/07/20/216197.html</guid><description><![CDATA[<p>DAO framework and SQL Maps framework are different things. You can use both, or either one by itself. <br />
<span style="background-color: yellow">DAO framework和SQL Maps framework是不同的东西，你可以用二者，或者用其中任何一个。</span><br />
</p>
<p>DAO is an abstraction layer that sits between your persistence solution and your service/domain layer. It serves to maintain a consistent API and transaction management facility to all of the higher layers (like service and domain). Without it, you will end up with various different types of artifacts from your persistence solution (like Session, or Connection) all mixed together. You'll also find yourself more tied to your persistence solution. One point about DAO &#8211; don't be afraid to write your own DAO! iBATIS is one implementation, but of anything else in iBATIS, DAO is the part that's is often best written for your specific application and customized to your needs.</p>
<p><span style="background-color: yellow">DAO是处于持久化方案和服务或领域层之间的抽象层。他维护一致的API和事务管理。没有他，你需要为持久层方案累积各种不同类型的东西，例如Session和Connection。你将同时发现处理你的持久化方案很类。DAO的好处就是，不必担心写你的DAO。<br />
IBatis是一个具体实现，但是iBatis之外，DAO是为你的特定的应用和定制你的需要而准备的最好的东西。</span><br />
<br />
SQL Maps is a persistence solution that allows you to easily map SQL to java objects. It is NOT an object-relational mapping tool, but can be used to map tables to objects using SQL.<br />
<span style="background-color: yellow">SQL Maps是一个持久化方案，允许你容易的实现sql到对象的映射。他不是一个对象关系映射工具，但是可以通过sql把表格映射到对象集。</span></p>
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="http://opensource.atlassian.com/confluence/oss/display/IBATIS/What+is+the+difference+between+the+iBATIS+DAO+framework+and+iBATIS+SQL+Maps" dc:identifier="http://opensource.atlassian.com/confluence/oss/display/IBATIS/What+is+the+difference+between+the+iBATIS+DAO+framework+and+iBATIS+SQL+Maps" dc:title="What is the difference between the iBATIS DAO framework and iBATIS SQL Maps" trackback:ping="http://opensource.atlassian.com/confluence/oss/rpc/trackback/68" />
</rdf:RDF>
--><!-- Root decorator: all decisions about how a page is to be decorated via the
                    inline decoration begins here.
--><!-- Switch based upon the context. However, for now, just delegate to a decorator
    identified directly by the context.
-->
 <img src ="http://www.blogjava.net/nobody_am/aggbug/216197.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/nobody_am/" target="_blank">MingIsMe</a> 2008-07-20 17:45 <a href="http://www.blogjava.net/nobody_am/news/2008/07/20/216197.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>