Académique Documents
Professionnel Documents
Culture Documents
s
.
Rich Client
Java Swing
G
U
I
Remoting
Browser
HTTP
Integration
P
r
o
x
y
Persistent Domain Objects / Core OO Model / DTOs
Mobile Device
G
U
I
Java ME
Remoting
W
e
b
A
c
t
i
o
n
s
R
e
m
o
t
e
S
e
r
v
i
c
e
E
x
p
o
r
t
e
r
s
Remoting
Rich Client
.NET
Framework
G
U
I
O
/
R
M
a
p
p
i
n
g
D
a
t
a
A
c
c
e
s
s
O
b
j
e
c
t
(
D
A
O
)
V
i
e
w
C
o
m
p
o
n
e
n
t
s
JDBC
JDBC
MOM
(Queue)
JMS
Crosscutting Concerns (Transaction, Security )
Email
Unit & IntegrationTesting
A
J
A
X
HTTP
B
u
s
i
n
e
s
s
S
e
r
v
i
c
e
69
Spring DAO Support
The DAO (Data Access Object) support in Spring is
primarily aimed at making it easy to work with different
data access technologies (like JDBC, Hibernate, EJB3 or
iBATIS) in a standardized way.
This allows to switch between them fairly easily and to
code without worrying about catching exceptions that are
specific to each technology.
70
Spring common persistence features
replaces DAOFactory classes with configurations and
dependency injection
easy configuration of DAO using dependency injection
base DaoSupport classes for popular persistence
frameworks
JDBC, iBATIS, Hibernate, Toplink, EJB3,
converts exceptions to a common exception hierarchy
template classes reduce redundant code
opens and closes necessary resources (such as
database connections)
71
Using Spring iBATIS DAO Abstraction
public class UserDAOSqlMap extends SqlMapClientDaoSupport implements UserDAO {
public User getUser(Long id) {
return (User) getSqlMapClientTemplate().queryForObject("getUser", id);
}
...
<sqlMap namespace="User">
<resultMap id="result" class="com.tvd.auction.domain.User">
<result property="id" column="user_id"/>
<result property="firstName" column="first_name"/>
<result property="lastName" column="last_name"/>
<result property="password" column="password"/>
<result property="email" column="email"/>
</resultMap>
<statement id="getUser" resultMap="result" parameterClass="java.lang.Long">
SELECT usr.user_id, usr.first_name, usr.last_name, usr.password, usr.email,
FROM user_t usr WHERE usr.user_id = #id#
</statement>
72
Using Spring iBATIS DAO Abstraction
<bean id="dataSource">...</bean>
<bean id="incrementer">...</bean>
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:/com/tvd/auction/context/sqlmap-config.xml</value>
</property>
</bean>
<bean id="user" class="com.tvd.auction.dao.UserDAOSqlMap">
<property name="dataSource"><ref local="dataSource" /></property>
<property name="sqlMapClient"><ref local="sqlMapClient"/></property>
<property name="incrementer"><ref local="incrementer" /></property>
</bean>
73
On-line Resources
Apache iBATIS Site
http://ibatis.apache.org/
Frequently Asked Questions
http://opensource2.atlassian.com/confluence/oss/display/IBATIS/Fre
quently+Asked+Questions
Article: iBatis Dao
http://www.onjava.com/pub/a/onjava/2005/08/10/ibatisdao.html
Article: Using iBatis SQL Maps for Java Data Access
http://www.developer.com/db/article.php/3346301
Spring Framework
http://www.springframework.org
74
iBATIS SQL Maps is a straightforward data access tool
Externalizes SQL statements
full control over the SQL issued
Can replace direct JDBC coding completely
Do you ever again want to use plain JDBC ?
The SQL Maps approach is particularly suitable for read-
only reference data
A complex read-write domain model is not a good fit !
Good integration with the Spring Framework
Apache iBATIS: Summary
Thanks!
?