Skip to content

Commit 570fa39

Browse files
committed
more updates, overwrite logging.xml for ko and ch, added auto-mapping to ja, ko and ch
1 parent 7ed01b1 commit 570fa39

File tree

9 files changed

+481
-130
lines changed

9 files changed

+481
-130
lines changed

src/site/ja/xdoc/sqlmap-xml.xml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,90 @@ public class User {
15551555
</p>
15561556
</subsection>
15571557

1558+
<subsection name="Auto-mapping">
1559+
1560+
<p>
1561+
As you have already seen in the previous sections, in simple cases MyBatis can auto-map the results for you
1562+
and in others you will need to build a result map.
1563+
But as you will see in this section you can also mix both strategies.
1564+
Let's have a deeper look at how auto-mapping works.
1565+
</p>
1566+
1567+
<p>
1568+
When auto-mapping results MyBatis will get the column name and look for a property with the same name ignoring case. That means that if
1569+
a column named <i>ID</i> and property named <i>id</i> are found, MyBatis will set the <i>id</i> property with the <i>ID</i> column value.
1570+
</p>
1571+
1572+
<p>
1573+
Usually database columns are named using uppercase letters and underscores between words and java properties often follow the camelcase
1574+
naming covention. To enable the auto-mapping between them set the setting <code>mapUnderscoreToCamelCase</code> to true.
1575+
</p>
1576+
1577+
<p>
1578+
Auto-mapping works even when there is an specific result map. When this happens, for each result map, all columns that are present in the
1579+
ResultSet that have not a manual mapping will be auto-mapped, then manual mappings will be processed.
1580+
In the following sample <i>id</i> and <i>userName</i> columns will be auto-mapped and <i>hashed_password</i> column will be mapped.</p>
1581+
1582+
<source><![CDATA[<select id="selectUsers" parameterType="int" resultType="User">
1583+
select
1584+
user_id as "id",
1585+
user_name as "userName",
1586+
hashed_password
1587+
from some_table
1588+
where id = #{id}
1589+
</select>]]></source>
1590+
1591+
<source><![CDATA[<resultMap id="userResultMap" type="User">
1592+
<result property="password" column="hashed_password"/>
1593+
</resultMap>]]></source>
1594+
1595+
<p>
1596+
There are three auto-mapping levels:
1597+
</p>
1598+
1599+
<ul>
1600+
<li>
1601+
<code>NONE</code> - disables auto-mapping. Only manually mapped properties will be set.
1602+
</li>
1603+
<li>
1604+
<code>PARTIAL</code> - will auto-map results except those that have nested result mappings defined inside (joins).
1605+
</li>
1606+
<li>
1607+
<code>FULL</code> - auto-maps everything.
1608+
</li>
1609+
</ul>
1610+
1611+
<p>
1612+
The default value is <code>PARTIAL</code>, and it is so for a reason. When <code>FULL</code> is used auto-mapping will
1613+
be performed when processing join results and joins retrieve data of several different entities in the same row
1614+
hence this may result in undesired mappings. To understand the risk have a look at the following sample:
1615+
</p>
1616+
1617+
<source><![CDATA[<select id="selectBlog" parameterType="int" resultMap="blogResult">
1618+
select
1619+
B.id,
1620+
B.title,
1621+
A.username,
1622+
from Blog B left outer join Author A on B.author_id = A.id
1623+
where B.id = #{id}
1624+
</select>]]></source>
1625+
1626+
<source><![CDATA[<resultMap id="blogResult" type="Blog">
1627+
<association property="author" javaType="Author" resultMap="authorResult"/>
1628+
</resultMap>
1629+
1630+
<resultMap id="authorResult" type="Author">
1631+
<result property="username" column="author_username"/>
1632+
</resultMap>]]></source>
1633+
1634+
<p>
1635+
With this result map both <i>Blog</i> and <i>Author</i> will be auto-mapped. But note that <i>Author</i> has an <i>id</i>
1636+
property and there is a column named <i>id</i> in the ResultSet so Author's id will be filled with Blog's id, and that is not
1637+
what you were expecting. So use the <code>FULL</code> option with caution.
1638+
</p>
1639+
1640+
</subsection>
1641+
15581642
<subsection name="cache">
15591643
<p>
15601644
MyBatis には非常に柔軟なトランザクション対応のクエリキャッシング機能が用意されています。

src/site/ko/xdoc/logging.xml

Lines changed: 136 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
<body>
2929
<section name="Logging">
3030
<p></p>
31-
<p>MyBatis 는 내부 로그 팩토리를 사용하여 로깅 정보를 제공한다. 내부 로그 팩토리는 로깅 정보를 다른 로그 구현체 중
32-
하나에 전달한다.</p>
31+
<p>MyBatis provides logging information through the use of an
32+
internal log factory. The internal log factory will delegate logging
33+
information to one of the following log implementations:
34+
</p>
3335
<ul>
3436
<li>
3537
SLF4J
@@ -44,27 +46,50 @@
4446
JDK logging
4547
</li>
4648
</ul>
47-
<p>로깅 솔루션은 내부 MyBatis 로그 팩토리의 런타임 체크를 통해 선택된다. MyBatis 로그 팩토리는 가능하면 첫번째
48-
구현체를 사용할 것이다(위 로깅 구현체의 나열 순서는 내부적으로 선택하는 우선순위이다). 만약 MyBatis 가 위 구현체중
49-
하나도 찾지 못한다면, 로깅을 하지 않을 것이다.</p>
50-
<p>많은 환경은 애플리케이션 서버(좋은 예는 Tomcat 과 WebSphere)의 클래스패스의 일부로 JCL 을 사용한다. 이러한 환경을
51-
아는 것이 중요하다. MyBatis 는 로깅 구현체로 JCL 을 사용할 것이다. WebSphere 와 같은 환경에서 Log4J 설정은 무시될
52-
것이다. 왜냐하면 WebSphere 는 자체 JCL 구현체를 제공하기 때문이다. 이러한 사항은 불만스러울수 있다. 왜냐하면
53-
MyBatis 는 당신의 Log4J 설정을 무시하는 것처럼 보일수도 있기 때문이다. (사실 MyBatis 는 당신의 Log4J 설정을
54-
무시한다. 왜냐하면 MyBatis 는 이러한 환경에서 JCL 을 사용할 것이기 때문이다.) 만약 당신의 애플리케이션이
55-
클래스패스에 JCL 을 포함한 환경에서 돌아가지만 다른 로깅 구현체 중 하나를 더 선호한다면, 다음의 메서드 중 하나를
56-
호출하여 다른 로깅 구현체를 선택 할 수 있다.</p>
49+
<p>The logging solution chosen is based on runtime introspection by
50+
the internal MyBatis log factory. The MyBatis log factory will use
51+
the first logging implementation it finds (implementations are
52+
searched in the above order). If MyBatis finds none of the above
53+
implementations, then logging will be disabled.
54+
</p>
55+
<p>Many environments ship Commons Logging as a part of the application server
56+
classpath (good examples include Tomcat and WebSphere). It is
57+
important to know that in such environments, MyBatis will use Commons Logging as
58+
the logging implementation. In an environment like WebSphere this
59+
will mean that your Log4J configuration will be ignored because
60+
WebSphere supplies its own proprietary implementation of Commons Logging. This
61+
can be very frustrating because it will appear that MyBatis is
62+
ignoring your Log4J configuration (in fact, MyBatis is ignoring your
63+
Log4J configuration because MyBatis will use Commons Logging in such
64+
environments). If your application is running in an environment
65+
where Commons Logging is included in the classpath but you would
66+
rather use one of the other logging implementations you can select a
67+
different logging implementation by calling one of the following
68+
methods:
69+
</p>
5770
<source><![CDATA[org.apache.ibatis.logging.LogFactory.useSlf4jLogging();
5871
org.apache.ibatis.logging.LogFactory.useLog4JLogging();
5972
org.apache.ibatis.logging.LogFactory.useJdkLogging();
6073
org.apache.ibatis.logging.LogFactory.useCommonsLogging();
6174
org.apache.ibatis.logging.LogFactory.useStdOutLogging();]]></source>
62-
<p>MyBatis 메서드를 호출하기 전에 위 메서드 중 하나를 호출해야 한다. 이 메서드들은 런타임 클래스패스에 구현체가
63-
존재하면 그 로그 구현체를 사용하게 한다. 예를 들어, Log4J 로깅을 선택했지만 런타임에 Log4J 구현체가 클래스패스에
64-
없다면, MyBatis 는 Log4J 구현체의 사용을 무시하고 로깅 구현체를 찾아 다시 사용할 것이다.</p>
65-
<p>Jakarta Commons 로깅, Log4J 그리고 JDK 로깅 API 에 대한 설명은 이 문서의 범위를 벗어난다. 이러한 로깅 관련
66-
프레임워크에 대해 좀더 알고 싶다면, 개별 위치에서 좀더 많은 정보를 얻을 수 있을 것이다.</p>
75+
<p>If you choose to call one of these methods, you should do so
76+
before calling any other MyBatis method. Also, these methods
77+
will only switch to the requested log implementation if that
78+
implementation is available on the runtime classpath. For example, if
79+
you try to select Log4J logging and Log4J is not available at runtime,
80+
then MyBatis will ignore the request to use Log4J and will use it's
81+
normal algorithm for discovering logging implementations.
82+
</p>
83+
<p>The specifics of SLF4J, Apache Commons Logging, Apache Log4J and the JDK
84+
Logging API are beyond the scope of this document. However the
85+
example configuration below should get you started. If you would like
86+
to know more about these frameworks, you can get more information from
87+
the following locations:
88+
</p>
6789
<ul>
90+
<li>
91+
<a href="http://www.slf4j.org/">SLF4J</a>
92+
</li>
6893
<li>
6994
<a href="http://commons.apache.org/logging">Apache Commons Logging</a>
7095
</li>
@@ -76,52 +101,111 @@ org.apache.ibatis.logging.LogFactory.useStdOutLogging();]]></source>
76101
</li>
77102
</ul>
78103
<subsection name="Logging Configuration">
79-
<p>MyBatis 가 실제로 사용하는 로그 클래스는 MyBatis 패키지에 포함되어 있지 않다. MyBatis 로깅 구문을 보기 위해서는,
80-
java.sql 패키지의 클래스에 대해 로깅을 활성화해야 할 것이다. 해당되는 클래스 목록들이다.</p>
81-
<ul>
82-
<li><code>java.sql.Connection</code></li>
83-
<li><code>java.sql.PreparedStatement</code></li>
84-
<li><code>java.sql.Resultset</code></li>
85-
<li><code>java.sql.Statement</code></li>
86-
</ul>
87-
<p>Log4J 를 사용하는 방법을 보여줄 것이다. 로깅 서비스는 하나 이상이 설정파일(예를 들면, log4j.properties)과 새로운
88-
JAR 파일(예를 들면, log4j.jar)을 사용한다. 다음의 예제는 Log4J 를 사용하여 로깅 서비스를 설정할 것이다. 두가지 단계를
89-
거친다.</p>
104+
<p>To see MyBatis logging statements you may enable logging on a
105+
package, a mapper fully qualified class name, a namespace
106+
o a fully qualified statement name.
107+
</p>
108+
<p>Again, how you do this is dependent on the logging implementation
109+
in use. We'll show how to do it with Log4J. Configuring the
110+
logging services is simply a matter of including one or more extra
111+
configuration files (e.g. log4j.properties) and sometimes a new JAR
112+
file (e.g. log4j.jar). The following example configuration will
113+
configure full logging services using Log4J as a provider. There
114+
are 2 steps.
115+
</p>
90116
<p></p>
91-
<h4>첫번째 단계 : Log4J JAR 파일 추가하기</h4>
92-
<p>Log4J 를 사용하기 때문에, 애플리케이션에 JAR 파일이 있어야 한다. Log4J 를 사용하기 위해, 애플리케이션의
93-
클래스패스에 JAR 파일을 추가할 필요가 있다. 위 URL 에서 Log4J 를 다운로드 할 수 있다.</p>
94-
<p>웹이나 기업용 애플리케이션에서는 WEB-INF/lib 디렉터리에 log4j.jar 파일을 추가할 수 있다. 단독으로 실행되는
95-
애플리케이션에서는 JVM 의 –classpath 시작 파라미터에서 간단히 추가할 수 있다.</p>
117+
<h4>
118+
Step 1: Add the Log4J JAR file
119+
</h4>
120+
<p>Because we are using Log4J, we will need to ensure its
121+
JAR file is available to our application. To use Log4J, you need to
122+
add the JAR file to your application classpath. You can download
123+
Log4J from the URL above.
124+
</p>
125+
<p>For web or enterprise applications you can add the <code>log4j.jar</code> to
126+
your <code>WEB-INF/lib</code> directory, or for a standalone application you can
127+
simply add it to the JVM <code>-classpath</code> startup parameter.
128+
</p>
96129
<p></p>
97-
<h4>두번째 단계 : Log4J 설정하기</h4>
98-
<p>Log4J 를 설정하는 것은 간단하다. 먼저 log4j.properties 파일을 만들어서 다음처럼 설정하면 된다.</p>
130+
<h4>
131+
Step 2: Configure Log4J
132+
</h4>
133+
<p>Configuring Log4J is simple. Suppose you want to enable the log for this mapper:
134+
</p>
135+
<source><![CDATA[package org.mybatis.example;
136+
public interface BlogMapper {
137+
@Select("SELECT * FROM blog WHERE id = #{id}")
138+
Blog selectBlog(int id);
139+
}]]></source>
140+
<p>Create a file called <code>log4j.properties</code>
141+
as shown below and place it in your classpath:
142+
</p>
99143
<source><![CDATA[# Global logging configuration
100144
log4j.rootLogger=ERROR, stdout
101145
# MyBatis logging configuration...
102-
#log4j.logger.org.apache.ibatis=DEBUG
103-
#log4j.logger.java.sql.Connection=DEBUG
104-
#log4j.logger.java.sql.Statement=DEBUG
105-
#log4j.logger.java.sql.PreparedStatement=DEBUG
106-
#log4j.logger.java.sql.ResultSet=DEBUG
146+
log4j.logger.org.mybatis.example.BlogMapper=TRACE
107147
# Console output...
108148
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
109149
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
110150
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n]]></source>
111-
<p>위 파일은 에러만을 리포트하는 최소한의 설정이다. 파일의 두번째 라인은 stdout appender 에 에러만을 출력한다.
112-
appender 는 출력(예를 들면, 콘솔, 파일, 데이터베이스 등)을 모으는 컴포넌트이다. 로그를 최대한 출력하기 위해서는
113-
다음처럼 설정을 변경해야 한다.</p>
114-
<p></p>
115-
<source>log4j.rootLogger=DEBUG, stdout</source>
116-
<p></p>
117-
<p>두번째 라인을 위처럼 변경하면, Log4J 는 ‘stdout’ appender 에 모든 로깅 이벤트를 출력한다. finer 레벨로 레벨을
118-
조정하고자 한다면, 위 파일에서 ‘SqlMap 로깅 설정’(4 번째라인에서 8 번째라인까지) 에서 각 클래스별로 설정할 수 있다.
119-
PreparedStatement 에 대해 콘솔에 DEBUG 레벨로 로깅(SQL 구문)을 하고 싶다면, 다음처럼 7 번째 라인을 수정하면 된다.</p>
151+
<p>
152+
The above file will cause log4J to report detailed logging for
153+
<code>org.mybatis.example.BlogMapper</code>
154+
and just errors for the rest of the classes of your application.
155+
</p>
156+
<p>
157+
If you want to tune the logging at a finer level you can turn logging
158+
on for specific statements instead of the whole mapper file.
159+
The following line will enable logging just for the <code>selectBlog</code>
160+
statement:
161+
</p>
162+
163+
<source>log4j.logger.org.mybatis.example.BlogMapper.selectBlog=TRACE</source>
164+
165+
<p>By the contrary you may want want to enable logging for a group of mappers.
166+
In that case you should add as a logger the root package where your mappers reside:</p>
167+
168+
<source>log4j.logger.org.mybatis.example=TRACE</source>
169+
170+
<p>There are queries that can return huge result sets. In that cases you may want to see the
171+
SQL stamentent but not the results. For that purpose SQL statements are logged with DEBUG level
172+
(FINE in JDK logging) and results with TRACE level (FINER in JDK logging), so in case
173+
you want to see the statement but not the result, set the level to DEBUG.
174+
</p>
175+
176+
<source>log4j.logger.org.mybatis.example=DEBUG</source>
177+
178+
<p>But what about if you are not using mapper interfaces but mapper XML files like this one?
179+
</p>
180+
181+
<source><![CDATA[<?xml version="1.0" encoding="UTF-8" ?>
182+
<!DOCTYPE mapper
183+
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
184+
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
185+
<mapper namespace="org.mybatis.example.BlogMapper">
186+
<select id="selectBlog" parameterType="int" resultType="Blog">
187+
select * from Blog where id = #{id}
188+
</select>
189+
</mapper>]]></source>
190+
191+
<p>In that case you can enable logging for the whole XML file by adding
192+
a logger for the namespace as shown below:</p>
193+
194+
<source>log4j.logger.org.mybatis.example.BlogMapper=TRACE</source>
195+
196+
<p>Or for an specific statement:</p>
197+
198+
<source>log4j.logger.org.mybatis.example.BlogMapper.selectBlog=TRACE</source>
120199

121-
<source>log4j.logger.java.sql.PreparedStatement=DEBUG</source>
200+
<p>Yes, as you may have noticed, there is no difference in configuring
201+
logging for mapper interfaces or for XML mapper files.</p>
122202

123-
<p>log4j.properties 파일에서 남은 설정은 appender 를 설정하기 위해 사용된다. 하지만 이 내용은 이 문서의 범위를 벗어난다.
124-
어쨌든 Log4J 웹사이트에서 좀더 많은 정보를 찾을 수 있다.</p>
203+
<p>The remaining configuration in the <code>log4j.properties</code> file is used
204+
to configure the appenders, which is beyond the scope of this
205+
document. However, you can find more information at the Log4J
206+
website (URL above). Or, you could simply experiment with it to see
207+
what effects the different configuration options have.
208+
</p>
125209
</subsection>
126210
</section>
127211
</body>

0 commit comments

Comments
 (0)