/*
* Copyright 2004 Clinton Begin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ibatis.dao.client.template;
import com.ibatis.common.util.PaginatedList;
import com.ibatis.dao.client.DaoException;
import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.engine.transaction.sqlmap.SqlMapDaoTransaction;
import com.ibatis.sqlmap.client.SqlMapExecutor;
import com.ibatis.sqlmap.client.SqlMapTransactionManager;
import com.ibatis.sqlmap.client.event.RowHandler;
import com.ibatis.sqlmap.engine.execution.BatchException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
/**
* A DaoTemplate for SQL Map implementations that provides a
* convenient method to access the SqlMapExecutor. This class
* also provides SqlMapExecutor method wrappers that conveniently
* wrap SQLExceptions with DAO Exceptions.
*
* @author Zach Scott
*/
public abstract class SqlMapDaoTemplate extends DaoTemplate implements SqlMapExecutor {
/**
* The DaoManager that manages this Dao instance will be passed
* in as the parameter to this constructor automatically upon
* instantiation.
*
* @param daoManager
*/
public SqlMapDaoTemplate(DaoManager daoManager) {
super(daoManager);
}
/**
* Gets the SQL Map Executor associated with the current
* DaoTransaction that this Dao is working under. The SqlMapExecutor
* interface declares a number of methods for executing statements
* via an SqlMapClient instance.
*
* @return A SqlMapExecutor instance.
*/
protected SqlMapExecutor getSqlMapExecutor() {
SqlMapDaoTransaction trans = (SqlMapDaoTransaction) daoManager.getTransaction(this);
return trans.getSqlMap();
}
/**
* Gets the SQL Map Transaction Manager associated with the current
* DaoTransaction that this Dao is working under. The SqlMapExecutor
* interface declares a number of methods for executing statements
* via an SqlMapClient instance.
* <p/>
* NOTE: It is rare to require this in a DAO. Only very special
* cases of DAO implementations will require access to the
* SqlMapTransactionManager. Messing with transactions at this
* level might be dangerous to your data integrity (e.g. committing
* too early).
*
* @return A SqlMapTransactionManager instance.
*/
protected SqlMapTransactionManager getSqlMapTransactionManager() {
SqlMapDaoTransaction trans = (SqlMapDaoTransaction) daoManager.getTransaction(this);
return trans.getSqlMap();
}
/**
* Executes a mapped SQL INSERT statement.
* Insert is a bit different from other update methods, as it
* provides facilities for returning the primary key of the
* newly inserted row (rather than the effected rows). This
* functionality is of course optional.
* <p/>
* The parameter object is generally used to supply the input
* data for the INSERT values.
*
* @param id The name of the statement to execute.
* @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
* @return The primary key of the newly inserted row. This might be automatically
* generated by the RDBMS, or selected from a sequence table or other source.
*/
//此template在进行crud时做了两件事:1.封装getsqlmapexector的过程;2.异常封装,将sqlexception变为daoexception
public Object insert(String id, Object parameterObject) {
try {
return getSqlMapExecutor().insert(id, parameterObject);
} catch (SQLException e) {
throw new DaoException("Failed to insert - id ["
+ id + "], parameterObject [" + parameterObject + "]. Cause: " + e, e);
}
}
/**
* Executes a mapped SQL INSERT statement.
* Insert is a bit different from other update methods, as it
* provides facilities for returning the primary key of the
* newly inserted row (rather than the effected rows). This
* functionality is of course optional.
* <p/>
* This overload assumes no parameter is needed.
*
* @param id The name of the statement to execute.
* @return The primary key of the newly inserted row. This might be automatically
* generated by the RDBMS, or selected from a sequence table or other source.
*/
public Object insert(String id) {
try {
return getSqlMapExecutor().insert(id);
} catch (SQLException e) {
throw new DaoException("Failed to insert - id ["
+ id + "]. Cause: " + e, e);
}
}
/**
* Executes a mapped SQL UPDATE statement.
* Update can also be used for any other update statement type,
* such as inserts and deletes. Update returns the number of
* rows effected.
* <p/>
* The parameter object is generally used to supply the input
* data for the UPDATE values as well as the WHERE clause parameter(s).
*
* @param id The name of the statement to execute.
* @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
* @return The number of rows effected.
*/
public int update(String id, Object parameterObject) {
try {
return getSqlMapExecutor().update(id, parameterObject);
} catch (SQLException e) {
throw new DaoException("Failed to update - id ["
+ id + "] - parameterObject [" + parameterObject + "]. Cause: " + e, e);
}
}
/**
* Executes a mapped SQL UPDATE statement.
* Update can also be used for any other update statement type,
* such as inserts and deletes. Update returns the number of
* rows effected.
* <p/>
* This overload assumes no parameter is needed.
*
* @param id The name of the statement to execute.
* @return The number of rows effected.
*/
public int update(String id) {
try {
return getSqlMapExecutor().update(id);
} catch (SQLException e) {
throw new DaoException("Failed to update - id ["
+ id + "]. Cause: " + e, e);
}
}
/**
* Executes a mapped SQL DELETE statement.
* Delete returns the number of rows effected.
* <p/>
* The parameter object is generally used to supply the input
* data for the WHERE clause parameter(s) of the DELETE statement.
*
* @param id The name of the statement to execute.
* @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
* @return The number of rows effected.
*/
public int delete(String id, Object parameterObject) {
try {
return getSqlMapExecutor().delete(id, parameterObject);
} catch (SQLException e) {
throw new DaoException("Failed to delete - id ["
+ id + "] - parameterObject [" + parameterObject + "]. Cause: " + e, e);
}
}
/**
* Executes a mapped SQL DELETE statement.
* Delete returns the number of rows effected.
* <p/>
* This overload assumes no parameter is needed.
*
* @param id The name of the statement to execute.
* @return The number of rows effected.
*/
public int delete(String id) {
try {
return getSqlMapExecutor().delete(id);
} catch (SQLException e) {
throw new DaoException("Failed to delete - id ["
+ id + "]. Cause: " + e, e);
}
}
/**
* Executes a mapped SQL SELECT statement tha
没有合适的资源?快使用搜索试试~ 我知道了~
iBATIS-DAO-2.3.4.726.rar_com.ibatis.dao_iBATIS dao 2_iBatis DAO_
共91个文件
class:35个
java:34个
jar:14个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 135 浏览量
2022-09-20
20:08:12
上传
评论
收藏 12.94MB RAR 举报
温馨提示
ibaits dao的源码分析,在源码的基础上添加注释说明
资源推荐
资源详情
资源评论
收起资源包目录
iBATIS-DAO-2.3.4.726.rar (91个子文件)
iBATIS DAO-2.3.4.726
bin
com
ibatis
dao
client
Dao.class 109B
DaoException.class 743B
DaoTransaction.class 131B
DaoManager.class 445B
DaoManagerBuilder.class 830B
template
HibernateDaoTemplate.class 11KB
DaoTemplate.class 484B
JdbcDaoTemplate.class 1KB
OjbBrokerDaoTemplate.class 3KB
SqlMapDaoTemplate.class 7KB
ToplinkDaoTemplate.class 1KB
engine
builder
xml
DaoClasspathEntityResolver.class 2KB
dao-2.dtd 577B
XmlDaoManagerBuilder$SimpleErrorHandler.class 2KB
XmlDaoManagerBuilder.class 11KB
transaction
jdbc
JdbcDaoTransactionManager.class 4KB
JdbcDaoTransaction.class 2KB
toplink
ToplinkDaoTransaction.class 3KB
ToplinkDaoTransactionManager.class 2KB
sqlmap
SqlMapDaoTransaction.class 2KB
SqlMapDaoTransactionManager.class 2KB
jta
JtaDaoTransaction.class 3KB
JtaDaoTransactionManager.class 2KB
ConnectionDaoTransaction.class 257B
ojb
OjbBrokerDaoTransaction.class 2KB
OjbBrokerTransactionManager.class 1KB
hibernate
HibernateDaoTransaction.class 2KB
HibernateDaoTransactionManager.class 3KB
DaoTransactionManager.class 377B
external
ExternalDaoTransaction.class 555B
ExternalDaoTransactionManager.class 1KB
impl
DaoContext.class 4KB
DaoProxy.class 3KB
StandardDaoManager.class 5KB
DaoImpl.class 2KB
DaoTransactionState.class 576B
build.xml 3KB
.settings
org.eclipse.core.resources.prefs 88B
org.eclipse.jdt.ui.prefs 99B
org.eclipse.jdt.core.prefs 598B
src
com
ibatis
dao
client
Dao.java 1KB
DaoManager.java 5KB
DaoTransaction.java 1KB
DaoManagerBuilder.java 2KB
DaoException.java 1KB
template
JdbcDaoTemplate.java 2KB
DaoTemplate.java 1KB
OjbBrokerDaoTemplate.java 4KB
HibernateDaoTemplate.java 13KB
ToplinkDaoTemplate.java 4KB
SqlMapDaoTemplate.java 20KB
engine
builder
xml
DaoClasspathEntityResolver.java 3KB
dao-2.dtd 577B
XmlDaoManagerBuilder.java 15KB
transaction
jdbc
JdbcDaoTransactionManager.java 4KB
JdbcDaoTransaction.java 2KB
toplink
ToplinkDaoTransactionManager.java 4KB
ToplinkDaoTransaction.java 5KB
sqlmap
SqlMapDaoTransaction.java 2KB
SqlMapDaoTransactionManager.java 3KB
jta
JtaDaoTransactionManager.java 2KB
JtaDaoTransaction.java 4KB
ojb
OjbBrokerTransactionManager.java 1KB
OjbBrokerDaoTransaction.java 2KB
hibernate
HibernateDaoTransaction.java 2KB
HibernateDaoTransactionManager.java 2KB
DaoTransactionManager.java 1011B
ConnectionDaoTransaction.java 860B
external
ExternalDaoTransaction.java 901B
ExternalDaoTransactionManager.java 1KB
impl
DaoContext.java 4KB
DaoImpl.java 2KB
StandardDaoManager.java 5KB
DaoProxy.java 3KB
DaoTransactionState.java 1KB
.project 396B
.classpath 1KB
lib
ibatis-2.3.4.726.jar 375KB
commons-logging-1.0.4.jar 37KB
cglib-2.1.3.jar 276KB
jakarta-oro.jar 64KB
hibernate2.jar 945KB
rt.jar 32.01MB
toplink-essentials.jar 2.33MB
toplink-api.jar 52KB
commons-lang-2.0.jar 166KB
oscache-2.1.jar 112KB
commons-dbcp-1.2.2.jar 119KB
db-ojb-1.0.4.jar 917KB
jboss-j2ee.jar 403KB
log4j-1.2.11.jar 342KB
共 91 条
- 1
资源评论
Kinonoyomeo
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功