系统原型结构描述(十)
2008-07-29 09:17
232 查看
Book.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Book">
<!-- Use type aliases to avoid typing the full classname every time. -->
<typeAlias alias="Book" type="com.test.domain.Book"/>
<!-- Result maps describe the mapping between the columns returned
from a query, and the class properties. A result map isn't
necessary if the columns (or aliases) match to the properties
exactly. -->
<resultMap id="BookResult" class="Book">
<result property="id" column="ID"/>
<result property="name" column="NAME"/>
<result property="author" column="AUTHOR"/>
<result property="summary" column="SUMMARY"/>
</resultMap>
<!-- Select with no parameters using the result map for Account class. -->
<select id="SelectAllBooks" resultMap="BookResult">
select * from BOOKS
</select>
<select id="GetBookTotal" resultClass="int">
select count(id) from BOOKS
</select>
<!-- A simpler select example without the result map. Note the
aliases to match the properties of the target result class. -->
<select id="SelectBookById" parameterClass="int" resultClass="Book">
select * from BOOKS
where ID = #id#
</select>
<select id="SelectBookByname" parameterClass="String" resultMap="BookResult">
select * from BOOKS
where NAME = #name#
</select>
<!-- Insert example, using the Account parameter class -->
<insert id="InsertBook" parameterClass="Book">
insert into BOOKS (
ID,
NAME,
AUTHOR,
SUMMARY)
values (
#id#, #name#, #author#, #summary#
)
</insert>
<!-- Update example, using the Account parameter class -->
<update id="UpdateBook" parameterClass="Book">
update BOOKS set
NAME = #name#,
AUTHOR = #author#,
SUMMARY = #summary#
where
ID = #id#
</update>
<!-- Delete example, using an integer as the parameter class -->
<delete id="DeleteBookById" parameterClass="int">
delete from BOOKS where ID = #id#
</delete>
</sqlMap>
Config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<!-- List the SQL Map XML files. They can be loaded from the
classpath, as they are here (com.domain.data...) -->
<sqlMap resource="com/test/persistence/Book.xml"/>
</sqlMapConfig>
BookDao.java
package com.test.persistence.dao.impl;
import java.util.List;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import com.test.domain.Book;
import com.test.persistence.dao.IBookDao;
public class BookDao implements IBookDao {
private SqlMapClientTemplate sqlMapClientTemplate = null;
public SqlMapClientTemplate getSqlMapClientTemplate() {
return sqlMapClientTemplate;
}
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
this.sqlMapClientTemplate = sqlMapClientTemplate;
}
public List selectAllBooks(int top, int max) {
return this.sqlMapClientTemplate.queryForList("SelectAllBooks", top, max);
}
public int getBookTotal() {
return ((Integer)this.sqlMapClientTemplate.queryForObject
("GetBookTotal")).intValue();
}
public Book selectBookById(int id) {
return (Book) this.sqlMapClientTemplate.queryForObject("SelectBookById", new
Integer(id));
}
public List selectBookByName(String name) {
return this.sqlMapClientTemplate.queryForList("SelectBookByname", name);
}
public void insertBook(Book book) {
this.sqlMapClientTemplate.insert("InsertBook", book);
}
public void updateBook(Book book) {
this.sqlMapClientTemplate.update("UpdateBook", book);
}
public void deleteBookById(int id) {
this.sqlMapClientTemplate.delete("DeleteBookById", new Integer(id));
}
}
PageManager.java
package com.test.page;
public class PageManager {
private IPage page = null;
private IPageResult pageResult = null;
public IPage getPage() {
return page;
}
public void setPage(Page page) {
this.page = page;
}
public IPageResult getPageResult() {
return pageResult;
}
public void setPageResult(PageResult pageResult) {
this.pageResult = pageResult;
}
public PageValue run(PageValue value) {
value.setRecords(this.pageResult.getTotal());
value = this.page.run(value);
value = this.pageResult.run(value);
return value;
}
}
PageResult.java
package com.test.page;
import java.util.List;
import org.apache.log4j.Logger;
import com.test.persistence.dao.impl.BookDao;
public class PageResult implements IPageResult {
static final Logger logger = Logger.getLogger(PageResult.class);
private BookDao bookDao = null;
public PageValue run(PageValue value) {
//value.setRecords(this.getTotal());
value.setResult(this.getResult(value.getTop(), value.getMax()));
logger.debug("Page : Total record " + value.getRecords());
logger.debug("Page : Result " + value.getResult());
return value;
}
public BookDao getBookDao() {
return bookDao;
}
public void setBookDao(BookDao bookDao) {
this.bookDao = bookDao;
}
public int getTotal() {
return this.bookDao.getBookTotal();
}
public List getResult(int top, int max){
return this.bookDao.selectAllBooks(top, max);
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Book">
<!-- Use type aliases to avoid typing the full classname every time. -->
<typeAlias alias="Book" type="com.test.domain.Book"/>
<!-- Result maps describe the mapping between the columns returned
from a query, and the class properties. A result map isn't
necessary if the columns (or aliases) match to the properties
exactly. -->
<resultMap id="BookResult" class="Book">
<result property="id" column="ID"/>
<result property="name" column="NAME"/>
<result property="author" column="AUTHOR"/>
<result property="summary" column="SUMMARY"/>
</resultMap>
<!-- Select with no parameters using the result map for Account class. -->
<select id="SelectAllBooks" resultMap="BookResult">
select * from BOOKS
</select>
<select id="GetBookTotal" resultClass="int">
select count(id) from BOOKS
</select>
<!-- A simpler select example without the result map. Note the
aliases to match the properties of the target result class. -->
<select id="SelectBookById" parameterClass="int" resultClass="Book">
select * from BOOKS
where ID = #id#
</select>
<select id="SelectBookByname" parameterClass="String" resultMap="BookResult">
select * from BOOKS
where NAME = #name#
</select>
<!-- Insert example, using the Account parameter class -->
<insert id="InsertBook" parameterClass="Book">
insert into BOOKS (
ID,
NAME,
AUTHOR,
SUMMARY)
values (
#id#, #name#, #author#, #summary#
)
</insert>
<!-- Update example, using the Account parameter class -->
<update id="UpdateBook" parameterClass="Book">
update BOOKS set
NAME = #name#,
AUTHOR = #author#,
SUMMARY = #summary#
where
ID = #id#
</update>
<!-- Delete example, using an integer as the parameter class -->
<delete id="DeleteBookById" parameterClass="int">
delete from BOOKS where ID = #id#
</delete>
</sqlMap>
Config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<!-- List the SQL Map XML files. They can be loaded from the
classpath, as they are here (com.domain.data...) -->
<sqlMap resource="com/test/persistence/Book.xml"/>
</sqlMapConfig>
BookDao.java
package com.test.persistence.dao.impl;
import java.util.List;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import com.test.domain.Book;
import com.test.persistence.dao.IBookDao;
public class BookDao implements IBookDao {
private SqlMapClientTemplate sqlMapClientTemplate = null;
public SqlMapClientTemplate getSqlMapClientTemplate() {
return sqlMapClientTemplate;
}
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
this.sqlMapClientTemplate = sqlMapClientTemplate;
}
public List selectAllBooks(int top, int max) {
return this.sqlMapClientTemplate.queryForList("SelectAllBooks", top, max);
}
public int getBookTotal() {
return ((Integer)this.sqlMapClientTemplate.queryForObject
("GetBookTotal")).intValue();
}
public Book selectBookById(int id) {
return (Book) this.sqlMapClientTemplate.queryForObject("SelectBookById", new
Integer(id));
}
public List selectBookByName(String name) {
return this.sqlMapClientTemplate.queryForList("SelectBookByname", name);
}
public void insertBook(Book book) {
this.sqlMapClientTemplate.insert("InsertBook", book);
}
public void updateBook(Book book) {
this.sqlMapClientTemplate.update("UpdateBook", book);
}
public void deleteBookById(int id) {
this.sqlMapClientTemplate.delete("DeleteBookById", new Integer(id));
}
}
PageManager.java
package com.test.page;
public class PageManager {
private IPage page = null;
private IPageResult pageResult = null;
public IPage getPage() {
return page;
}
public void setPage(Page page) {
this.page = page;
}
public IPageResult getPageResult() {
return pageResult;
}
public void setPageResult(PageResult pageResult) {
this.pageResult = pageResult;
}
public PageValue run(PageValue value) {
value.setRecords(this.pageResult.getTotal());
value = this.page.run(value);
value = this.pageResult.run(value);
return value;
}
}
PageResult.java
package com.test.page;
import java.util.List;
import org.apache.log4j.Logger;
import com.test.persistence.dao.impl.BookDao;
public class PageResult implements IPageResult {
static final Logger logger = Logger.getLogger(PageResult.class);
private BookDao bookDao = null;
public PageValue run(PageValue value) {
//value.setRecords(this.getTotal());
value.setResult(this.getResult(value.getTop(), value.getMax()));
logger.debug("Page : Total record " + value.getRecords());
logger.debug("Page : Result " + value.getResult());
return value;
}
public BookDao getBookDao() {
return bookDao;
}
public void setBookDao(BookDao bookDao) {
this.bookDao = bookDao;
}
public int getTotal() {
return this.bookDao.getBookTotal();
}
public List getResult(int top, int max){
return this.bookDao.selectAllBooks(top, max);
}
}
相关文章推荐
- 系统原型结构描述(五)
- 系统原型结构描述(六)
- 系统原型结构描述(七)
- 系统原型结构描述(一)系统原型开发包目录结构清单
- 系统原型结构描述(八)
- 系统原型结构描述(二)系统原型开发包说明
- 系统原型结构描述(九)
- 系统原型结构描述(概述)最近要设计一个框架,大家一起讨论下如何实现?
- 系统原型结构描述(三)
- 系统原型结构描述(十一)
- 系统原型结构描述(四)
- 系统原型结构描述(十二)
- PowerDesigner(八)-面向对象模型(用例图,序列图,类图,生成Java源代码及Java源代码生成类图)面向对象模型 面向对象模型是利用UML(统一建模语言)的图形来描述系统结构的模型,
- 加载内核模块,实现新的系统调用:遍历系统当前所有进程的任务描述符,并将pid组织成树状结构显示
- 虚拟文件系统相关结构描述
- UML中如何描述系统的体系结构(二)
- UML中如何描述系统的体系结构(三)
- Linux下IP协议使用的地址描述数据结构结构的典型原型声明
- 虚拟文件系统相关结构描述【续】
- 系统目录结构文件类型及ls.alias命令