1
- <?xml version =" 1.0" encoding =" UTF-8" ?>
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
2
<!--
3
3
4
4
Copyright 2009-2017 the original author or authors.
96
96
methods. For
97
97
example:
98
98
</p >
99
- <source ><![CDATA[ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
99
+ <source ><![CDATA[ SqlSessionFactory factory =
100
+ sqlSessionFactoryBuilder.build(reader, props);
100
101
101
102
// ... or ...
102
103
103
- SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environment, props);
104
+ SqlSessionFactory factory =
105
+ new SqlSessionFactoryBuilder.build(reader, environment, props);
104
106
]]> </source >
105
107
<p >
106
108
If a property exists in more than one of these places, MyBatis
@@ -638,7 +640,8 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ
638
640
<setting name="mapUnderscoreToCamelCase" value="false"/>
639
641
<setting name="localCacheScope" value="SESSION"/>
640
642
<setting name="jdbcTypeForNull" value="OTHER"/>
641
- <setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/>
643
+ <setting name="lazyLoadTriggerMethods"
644
+ value="equals,clone,hashCode,toString"/>
642
645
</settings>]]> </source >
643
646
644
647
</subsection >
@@ -1248,22 +1251,26 @@ public class Author {
1248
1251
public class ExampleTypeHandler extends BaseTypeHandler<String> {
1249
1252
1250
1253
@Override
1251
- public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
1254
+ public void setNonNullParameter(PreparedStatement ps, int i,
1255
+ String parameter, JdbcType jdbcType) throws SQLException {
1252
1256
ps.setString(i, parameter);
1253
1257
}
1254
1258
1255
1259
@Override
1256
- public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
1260
+ public String getNullableResult(ResultSet rs, String columnName)
1261
+ throws SQLException {
1257
1262
return rs.getString(columnName);
1258
1263
}
1259
1264
1260
1265
@Override
1261
- public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
1266
+ public String getNullableResult(ResultSet rs, int columnIndex)
1267
+ throws SQLException {
1262
1268
return rs.getString(columnIndex);
1263
1269
}
1264
1270
1265
1271
@Override
1266
- public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
1272
+ public String getNullableResult(CallableStatement cs, int columnIndex)
1273
+ throws SQLException {
1267
1274
return cs.getString(columnIndex);
1268
1275
}
1269
1276
}
@@ -1351,53 +1358,54 @@ public class GenericTypeHandler<E extends MyObject> extends BaseTypeHandler<E> {
1351
1358
...
1352
1359
]]> </source >
1353
1360
1354
- <p ><code >EnumTypeHandler</code > and <code >EnumOrdinalTypeHandler</code > are generic TypeHandlers. We will learn
1355
- about them in the following section.
1356
- </p >
1361
+ <p ><code >EnumTypeHandler</code > and <code >EnumOrdinalTypeHandler</code > are generic TypeHandlers. We will learn
1362
+ about them in the following section.
1363
+ </p >
1357
1364
1358
1365
</subsection >
1359
1366
1360
1367
<subsection name =" Handling Enums" >
1361
- <p >
1362
- If you want to map an <code >Enum</code >, you'll need to use either
1363
- <code >EnumTypeHandler</code > or <code >EnumOrdinalTypeHandler</code >.
1364
- </p >
1365
-
1366
- <p >For example, let's say that we need to store the rounding mode that
1367
- should be used with some number if it needs to be rounded. By default, MyBatis
1368
- uses <code >EnumTypeHandler</code > to convert the <code >Enum</code >
1369
- values to their names.
1370
- </p >
1371
-
1372
- <b >Note <code >EnumTypeHandler</code > is special in the sense that unlike other handlers,
1373
- it does not handle just one specific class, but any class that extends <code >Enum</code ></b >
1374
-
1375
- <p >However, we may not want to store names. Our DBA may insist on an
1376
- integer code instead. That's just as easy: add <code >EnumOrdinalTypeHandler</code >
1377
- to the <code >typeHandlers</code > in your config file, and now each
1378
- <code >RoundingMode</code > will be mapped to an integer using its ordinal value.
1379
- </p >
1368
+ <p >
1369
+ If you want to map an <code >Enum</code >, you'll need to use either
1370
+ <code >EnumTypeHandler</code > or <code >EnumOrdinalTypeHandler</code >.
1371
+ </p >
1372
+
1373
+ <p >For example, let's say that we need to store the rounding mode that
1374
+ should be used with some number if it needs to be rounded. By default, MyBatis
1375
+ uses <code >EnumTypeHandler</code > to convert the <code >Enum</code >
1376
+ values to their names.
1377
+ </p >
1378
+
1379
+ <b >Note <code >EnumTypeHandler</code > is special in the sense that unlike other handlers,
1380
+ it does not handle just one specific class, but any class that extends <code >Enum</code ></b >
1381
+
1382
+ <p >However, we may not want to store names. Our DBA may insist on an
1383
+ integer code instead. That's just as easy: add <code >EnumOrdinalTypeHandler</code >
1384
+ to the <code >typeHandlers</code > in your config file, and now each
1385
+ <code >RoundingMode</code > will be mapped to an integer using its ordinal value.
1386
+ </p >
1380
1387
<source ><![CDATA[ <!-- mybatis-config.xml -->
1381
1388
<typeHandlers>
1382
- <typeHandler handler="org.apache.ibatis.type.EnumOrdinalTypeHandler" javaType="java.math.RoundingMode"/>
1389
+ <typeHandler handler="org.apache.ibatis.type.EnumOrdinalTypeHandler"
1390
+ javaType="java.math.RoundingMode"/>
1383
1391
</typeHandlers>
1384
1392
]]> </source >
1385
- <p >
1386
- But what if you want to map the same <code >Enum</code > to a
1387
- string in one place and to integer in another?
1388
- </p >
1389
- <p >
1390
- The auto-mapper will automatically use <code >EnumOrdinalTypeHandler</code >,
1391
- so if we want to go back to using plain old ordinary
1392
- <code >EnumTypeHandler</code >, we have to tell it, by explicitly setting
1393
- the type handler to use for those SQL statements.
1394
- </p >
1395
- <p >
1396
- (Mapper files aren't covered until the next section, so if this is your first
1397
- time reading through the documentation, you may want to skip this for now
1398
- and come back to it later.)
1399
- </p >
1400
- <source ><![CDATA[ <!DOCTYPE mapper
1393
+ <p >
1394
+ But what if you want to map the same <code >Enum</code > to a
1395
+ string in one place and to integer in another?
1396
+ </p >
1397
+ <p >
1398
+ The auto-mapper will automatically use <code >EnumOrdinalTypeHandler</code >,
1399
+ so if we want to go back to using plain old ordinary
1400
+ <code >EnumTypeHandler</code >, we have to tell it, by explicitly setting
1401
+ the type handler to use for those SQL statements.
1402
+ </p >
1403
+ <p >
1404
+ (Mapper files aren't covered until the next section, so if this is your first
1405
+ time reading through the documentation, you may want to skip this for now
1406
+ and come back to it later.)
1407
+ </p >
1408
+ <source ><![CDATA[ <!DOCTYPE mapper
1401
1409
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
1402
1410
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
1403
1411
@@ -1406,43 +1414,44 @@ public class GenericTypeHandler<E extends MyObject> extends BaseTypeHandler<E> {
1406
1414
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
1407
1415
1408
1416
<mapper namespace="org.apache.ibatis.submitted.rounding.Mapper">
1409
- <resultMap type="org.apache.ibatis.submitted.rounding.User" id="usermap">
1410
- <id column="id" property="id"/>
1411
- <result column="name" property="name"/>
1412
- <result column="funkyNumber" property="funkyNumber"/>
1413
- <result column="roundingMode" property="roundingMode"/>
1414
- </resultMap>
1415
-
1416
- <select id="getUser" resultMap="usermap">
1417
- select * from users
1418
- </select>
1419
- <insert id="insert">
1420
- insert into users (id, name, funkyNumber, roundingMode) values (
1421
- #{id}, #{name}, #{funkyNumber}, #{roundingMode}
1422
- )
1423
- </insert>
1424
-
1425
- <resultMap type="org.apache.ibatis.submitted.rounding.User" id="usermap2">
1426
- <id column="id" property="id"/>
1427
- <result column="name" property="name"/>
1428
- <result column="funkyNumber" property="funkyNumber"/>
1429
- <result column="roundingMode" property="roundingMode" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
1430
- </resultMap>
1431
- <select id="getUser2" resultMap="usermap2">
1432
- select * from users2
1433
- </select>
1434
- <insert id="insert2">
1435
- insert into users2 (id, name, funkyNumber, roundingMode) values (
1436
- #{id}, #{name}, #{funkyNumber}, #{roundingMode, typeHandler=org.apache.ibatis.type.EnumTypeHandler}
1437
- )
1438
- </insert>
1417
+ <resultMap type="org.apache.ibatis.submitted.rounding.User" id="usermap">
1418
+ <id column="id" property="id"/>
1419
+ <result column="name" property="name"/>
1420
+ <result column="funkyNumber" property="funkyNumber"/>
1421
+ <result column="roundingMode" property="roundingMode"/>
1422
+ </resultMap>
1423
+
1424
+ <select id="getUser" resultMap="usermap">
1425
+ select * from users
1426
+ </select>
1427
+ <insert id="insert">
1428
+ insert into users (id, name, funkyNumber, roundingMode) values (
1429
+ #{id}, #{name}, #{funkyNumber}, #{roundingMode}
1430
+ )
1431
+ </insert>
1432
+
1433
+ <resultMap type="org.apache.ibatis.submitted.rounding.User" id="usermap2">
1434
+ <id column="id" property="id"/>
1435
+ <result column="name" property="name"/>
1436
+ <result column="funkyNumber" property="funkyNumber"/>
1437
+ <result column="roundingMode" property="roundingMode"
1438
+ typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
1439
+ </resultMap>
1440
+ <select id="getUser2" resultMap="usermap2">
1441
+ select * from users2
1442
+ </select>
1443
+ <insert id="insert2">
1444
+ insert into users2 (id, name, funkyNumber, roundingMode) values (
1445
+ #{id}, #{name}, #{funkyNumber}, #{roundingMode, typeHandler=org.apache.ibatis.type.EnumTypeHandler}
1446
+ )
1447
+ </insert>
1439
1448
1440
1449
</mapper>
1441
1450
]]> </source >
1442
- <p >
1443
- Note that this forces us to use a <code >resultMap</code >
1444
- instead of a <code >resultType</code > in our select statements.
1445
- </p >
1451
+ <p >
1452
+ Note that this forces us to use a <code >resultMap</code >
1453
+ instead of a <code >resultType</code > in our select statements.
1454
+ </p >
1446
1455
</subsection >
1447
1456
1448
1457
<subsection name =" objectFactory" >
@@ -1878,19 +1887,19 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, propert
1878
1887
constructor of the InitialContext upon instantiation.
1879
1888
</p >
1880
1889
1881
- <p >
1882
- You can plug any 3rd party DataSource by implementing the interface <code >org.apache.ibatis.datasource.DataSourceFactory</code >:
1883
- </p >
1890
+ <p >
1891
+ You can plug any 3rd party DataSource by implementing the interface <code >org.apache.ibatis.datasource.DataSourceFactory</code >:
1892
+ </p >
1884
1893
1885
1894
<source ><![CDATA[ public interface DataSourceFactory {
1886
1895
void setProperties(Properties props);
1887
1896
DataSource getDataSource();
1888
1897
}]]> </source >
1889
1898
1890
1899
<p >
1891
- <code >org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory</code > can be used as super class
1892
- to build new datasource adapters. For example this is the code needed to plug C3P0:
1893
- </p >
1900
+ <code >org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory</code > can be used as super class
1901
+ to build new datasource adapters. For example this is the code needed to plug C3P0:
1902
+ </p >
1894
1903
1895
1904
<source ><![CDATA[ import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;
1896
1905
import com.mchange.v2.c3p0.ComboPooledDataSource;
@@ -1929,29 +1938,29 @@ public class C3P0DataSourceFactory extends UnpooledDataSourceFactory {
1929
1938
<source ><![CDATA[ <databaseIdProvider type="DB_VENDOR" />
1930
1939
]]> </source >
1931
1940
1932
- <p >
1933
- The DB_VENDOR implementation databaseIdProvider sets as databaseId the String returned by
1934
- <code >DatabaseMetaData#getDatabaseProductName()</code >.
1935
- Given that usually that string is too long and that different versions of the same product may return different values,
1936
- you may want to convert it to a shorter one by adding properties like follows:
1937
- </p >
1941
+ <p >
1942
+ The DB_VENDOR implementation databaseIdProvider sets as databaseId the String returned by
1943
+ <code >DatabaseMetaData#getDatabaseProductName()</code >.
1944
+ Given that usually that string is too long and that different versions of the same product may return different values,
1945
+ you may want to convert it to a shorter one by adding properties like follows:
1946
+ </p >
1938
1947
1939
1948
<source ><![CDATA[ <databaseIdProvider type="DB_VENDOR">
1940
1949
<property name="SQL Server" value="sqlserver"/>
1941
1950
<property name="DB2" value="db2"/>
1942
1951
<property name="Oracle" value="oracle" />
1943
1952
</databaseIdProvider>]]> </source >
1944
1953
1945
- <p >
1946
- When properties are provided, the DB_VENDOR databaseIdProvider will search the property value corresponding to the
1947
- first key found in the returned database product name or "null" if there is not a matching property.
1948
- In this case, if <code >getDatabaseProductName()</code > returns "Oracle (DataDirect)" the databaseId will be set to "oracle".
1949
- </p >
1954
+ <p >
1955
+ When properties are provided, the DB_VENDOR databaseIdProvider will search the property value corresponding to the
1956
+ first key found in the returned database product name or "null" if there is not a matching property.
1957
+ In this case, if <code >getDatabaseProductName()</code > returns "Oracle (DataDirect)" the databaseId will be set to "oracle".
1958
+ </p >
1950
1959
1951
- <p >
1952
- You can build your own DatabaseIdProvider by implementing the interface <code >org.apache.ibatis.mapping.DatabaseIdProvider</code >
1953
- and registering it in mybatis-config.xml:
1954
- </p >
1960
+ <p >
1961
+ You can build your own DatabaseIdProvider by implementing the interface <code >org.apache.ibatis.mapping.DatabaseIdProvider</code >
1962
+ and registering it in mybatis-config.xml:
1963
+ </p >
1955
1964
1956
1965
<source ><![CDATA[ public interface DatabaseIdProvider {
1957
1966
void setProperties(Properties p);
0 commit comments