iBatis - SQLMaps

streakconvertingΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

67 εμφανίσεις

iBatis
-

SQLMaps

DAO (1)


Spring uses the DAO
-
pattern.


Spring provides DAO
-
interfaces for:


JDBC


Hibernate


iBatis


JDO


Toplink


Connections through DataSourceFactory


Common exception handling


Use of Template Patterns (a.o. JdbcTemplate).

DAO (2)

DAO (3)


DAO
-
interface for Jdbc
-

JdbcTemplate:


Update/insert:


JdbcTemplate.update(String sql, Object[] params, int[]
types)


Batch updates:


JdbcTemplate.batchUpdate(sql, setter)


Select of 1 or more rows:


JdbcTemplate.query(String sql, Object[] params,
RowMapper)


Stored procedures:


JdbcTemplate.execute(String name,
CallableStatementCallback)




DAO (4)


iBatis:


Simpler than Hibernate, more advanced
than JDBC


Mapping of SQL queries to Objects and
vice versa, including caching


Version 1.3 (SqlMap) and 2.0
(SqlMapClient) supported by Spring
through SqlMapClientTemplate




DAO (5)


Spring Interface for iBatis SQLMaps
-
SqlMapClientTemplate:


sqlMapClientTemplate.queryForObject(“getXByI
d”, id)


sqlMapClientTemplate.queryForList(“getXById”,
id)


sqlMapClientTemplate.update(“insertX”, x)


sqlMapClientTemplate.delete(“deleteX” ,id)


DAO (6)


Example iBatis
-

Class:


public class IbatisBlogEntryDaoImpl extends SqlMapClientDaoSupport implements BlogEntryDao
{



public List<? extends BlogEntry> getAllBlogEntrys(int limit) {



return (List<BlogEntry>) getSqlMapClientTemplate().queryForList("
getAllBlogEntries
",
limit);



}


}


Sql
-
map
-
config:


<sqlMapConfig>



<typeHandler

javaType="java.net.InetAddress"
callback="com.xebia.springroller.dao.impl.ibatis.InetAddressTypeHandler" />



<sqlMap resource="com/xebia/springroller/dao/impl/ibatis/
BlogEntry.xml
" />


</sqlMapConfig>


BlogEntry.xml:



<select id="
getAllBlogEntries
" resultMap="selectBlogEntryResultMap">




SELECT ID, TITLE, TEXT, AUTHOR_EMAIL, PUBLICATION_DATE,
PUBLICATION_IP_ADDRESS FROM BLOG_ENTRIES ORDER BY




PUBLICATION_DATE DESC LIMIT #value#



</select>




Questions


???