Developer Guide iBATIS Data Mapper 2.0
Table of Contents
......................................................................................................................................................................... 3
Introduction.......................................................................................................................................................4
Data Mapper..................................................................................................................................................... 4
Installation........................................................................................................................................................ 5
Upgrading from 1.x.....................................................................................................................................5
The SQL Map XML Configuration File ..........................................................................................................8
The <properties> Element...........................................................................................................................9
The <settings> Element...............................................................................................................................9
The <resultObjectFactory> Element.........................................................................................................12
The <typeAlias> Element......................................................................................................................... 13
The <transactionManager> Element.........................................................................................................13
The <dataSource> Element.......................................................................................................................14
The <sqlMap> Element.............................................................................................................................17
The SQL Map XML File ............................................................................................................................... 18
Mapped Statements.........................................................................................................................................19
Statement Types........................................................................................................................................19
The SQL....................................................................................................................................................21
Reusing SQL Fragments........................................................................................................................... 21
Auto-Generated Keys................................................................................................................................22
Stored Procedures..................................................................................................................................... 23
Parameter Maps and Inline Parameters.......................................................................................................... 28
Inline Parameter Maps.............................................................................................................................. 30
Primitive Type Parameters........................................................................................................................32
Map Type Parameters............................................................................................................................... 32
Substitution Strings.........................................................................................................................................33
Result Maps.................................................................................................................................................... 33
Implicit Result Maps.................................................................................................................................36
Primitive Results....................................................................................................................................... 36
Complex Properties ..................................................................................................................................37
Avoiding N+1 Selects (1:1)...................................................................................................................... 38
Complex Collection Properties ................................................................................................................ 39
Avoiding N+1 Selects (1:M and M:N)......................................................................................................40
Composite Keys or Multiple Complex Parameters Properties .................................................................41
Supported Types for Parameter Maps and Result Maps.................................................................................43
Creating custom Type Handlers................................................................................................................44
Caching Mapped Statement Results............................................................................................................... 45
Read-Only vs. Read/Write........................................................................................................................ 45
Serializable Read/Write Caches................................................................................................................45
Cache Types..............................................................................................................................................46
Dynamic Mapped Statements......................................................................................................................... 49
Dynamic Element......................................................................................................................................50
Binary Conditional Elements.................................................................................................................... 50
Unary Conditional Elements .................................................................................................................... 51
Other Elements..........................................................................................................................................52
Simple Dynamic SQL Elements..................................................................................................................... 54
Programming with Data Mapper: The API....................................................................................................55
Configuration............................................................................................................................................ 55
Transactions.............................................................................................................................................. 55
Multi Threaded Programming...................................................................................................................58
iBATIS Classloading................................................................................................................................ 58
Batches......................................................................................................................................................59
Executing Statements via the SqlMapClient API......................................................................................60
Logging SqlMap Activity............................................................................................................................... 65
The One Page JavaBeans Course................................................................................................................... 67
Resources (com.ibatis.common.resources.*) .................................................................................................69
http://ibatis.apache.org by Clinton Begin
2