Developer Guide iBATIS Data Mapper 2.0
Table of Contents
Introduction.......................................................................................................................................................3
Data Mapper..................................................................................................................................................... 3
Installation........................................................................................................................................................ 4
Upgrading from 1.x.....................................................................................................................................5
The SQL Map XML Configuration File ..........................................................................................................7
The <properties> Element...........................................................................................................................8
The <settings> Element...............................................................................................................................8
The <resultObjectFactory> Element.........................................................................................................10
The <typeAlias> Element......................................................................................................................... 11
The <transactionManager> Element.........................................................................................................11
The <dataSource> Element.......................................................................................................................12
The <sqlMap> Element.............................................................................................................................15
The SQL Map XML File ............................................................................................................................... 16
Mapped Statements.........................................................................................................................................17
Statement Types........................................................................................................................................17
The SQL....................................................................................................................................................19
Reusing SQL Fragments........................................................................................................................... 19
Auto-Generated Keys................................................................................................................................20
Stored Procedures..................................................................................................................................... 21
Parameter Maps and Inline Parameters.......................................................................................................... 26
Inline Parameter Maps.............................................................................................................................. 28
Primitive Type Parameters........................................................................................................................30
Map Type Parameters............................................................................................................................... 30
Result Maps.................................................................................................................................................... 31
Implicit Result Maps.................................................................................................................................33
Primitive Results....................................................................................................................................... 33
Complex Properties ..................................................................................................................................34
Avoiding N+1 Selects (1:1)...................................................................................................................... 35
Complex Collection Properties ................................................................................................................ 36
Avoiding N+1 Selects (1:M and M:N)......................................................................................................37
Composite Keys or Multiple Complex Parameters Properties .................................................................38
Supported Types for Parameter Maps and Result Maps.................................................................................40
Creating custom Type Handlers................................................................................................................41
Caching Mapped Statement Results............................................................................................................... 42
Read-Only vs. Read/Write........................................................................................................................ 42
Serializable Read/Write Caches................................................................................................................42
Cache Types..............................................................................................................................................43
Dynamic Mapped Statements......................................................................................................................... 46
Dynamic Element......................................................................................................................................47
Binary Conditional Elements.................................................................................................................... 47
Unary Conditional Elements .................................................................................................................... 48
Other Elements..........................................................................................................................................49
Simple Dynamic SQL Elements..................................................................................................................... 51
Programming with Data Mapper: The API....................................................................................................52
Configuration............................................................................................................................................ 52
Transactions.............................................................................................................................................. 52
Multi Threaded Programming...................................................................................................................54
iBATIS Classloading................................................................................................................................ 55
Batches......................................................................................................................................................55
Executing Statements via the SqlMapClient API......................................................................................57
Logging SqlMap Activity............................................................................................................................... 62
The One Page JavaBeans Course................................................................................................................... 64
Resources (com.ibatis.common.resources.*) .................................................................................................66
SimpleDataSource (com.ibatis.common.jdbc.*).............................................................................................67
http://ibatis.apache.org by Clinton Begin
2