/*
* 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.sqlmap.engine.impl;
import com.ibatis.common.util.PaginatedList;
import com.ibatis.common.logging.Log;
import com.ibatis.common.logging.LogFactory;
import com.ibatis.sqlmap.client.*;
import com.ibatis.sqlmap.client.event.RowHandler;
import com.ibatis.sqlmap.engine.execution.BatchException;
import com.ibatis.sqlmap.engine.execution.SqlExecutor;
import com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactory;
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
/**
* Implementation of ExtendedSqlMapClient
*/
//澶栭儴SqlMapClient鐨勫疄鐜扮被锛屼篃鏄竴涓腑闂寸被锛屽叿浣撴搷浣滆浆鍖栧埌SqlMapSessionImpl瀹炰緥鍖栧璞″幓
public class SqlMapClientImpl implements SqlMapClient, ExtendedSqlMapClient {
private static final Log log = LogFactory.getLog(SqlMapClientImpl.class);
/**
* Delegate for SQL execution
*/
public SqlMapExecutorDelegate delegate;
protected ThreadLocal localSqlMapSession = new ThreadLocal();//澶勭悊绾跨▼瀹夊叏鐨勫綋鍓嶇嚎绋嬬粍
/**
* Constructor to supply a delegate
*
* @param delegate - the delegate
*/
public SqlMapClientImpl(SqlMapExecutorDelegate delegate) {
this.delegate = delegate;
}
public Object insert(String id, Object param) throws SQLException {
return getLocalSqlMapSession().insert(id, param);
}
public Object insert(String id) throws SQLException {
return getLocalSqlMapSession().insert(id);
}
public int update(String id, Object param) throws SQLException {
return getLocalSqlMapSession().update(id, param);
}
public int update(String id) throws SQLException {
return getLocalSqlMapSession().update(id);
}
public int delete(String id, Object param) throws SQLException {
return getLocalSqlMapSession().delete(id, param);
}
public int delete(String id) throws SQLException {
return getLocalSqlMapSession().delete(id);
}
public Object queryForObject(String id, Object paramObject) throws SQLException {
return getLocalSqlMapSession().queryForObject(id, paramObject);
}
public Object queryForObject(String id) throws SQLException {
return getLocalSqlMapSession().queryForObject(id);
}
public Object queryForObject(String id, Object paramObject, Object resultObject) throws SQLException {
return getLocalSqlMapSession().queryForObject(id, paramObject, resultObject);
}
public List queryForList(String id, Object paramObject) throws SQLException {
return getLocalSqlMapSession().queryForList(id, paramObject);
}
public List queryForList(String id) throws SQLException {
return getLocalSqlMapSession().queryForList(id);
}
public List queryForList(String id, Object paramObject, int skip, int max) throws SQLException {
return getLocalSqlMapSession().queryForList(id, paramObject, skip, max);
}
public List queryForList(String id, int skip, int max) throws SQLException {
return getLocalSqlMapSession().queryForList(id, skip, max);
}
/**
* @deprecated All paginated list features have been deprecated
*/
public PaginatedList queryForPaginatedList(String id, Object paramObject, int pageSize) throws SQLException {
return getLocalSqlMapSession().queryForPaginatedList(id, paramObject, pageSize);
}
/**
* @deprecated All paginated list features have been deprecated
*/
public PaginatedList queryForPaginatedList(String id, int pageSize) throws SQLException {
return getLocalSqlMapSession().queryForPaginatedList(id, pageSize);
}
public Map queryForMap(String id, Object paramObject, String keyProp) throws SQLException {
return getLocalSqlMapSession().queryForMap(id, paramObject, keyProp);
}
public Map queryForMap(String id, Object paramObject, String keyProp, String valueProp) throws SQLException {
return getLocalSqlMapSession().queryForMap(id, paramObject, keyProp, valueProp);
}
public void queryWithRowHandler(String id, Object paramObject, RowHandler rowHandler) throws SQLException {
getLocalSqlMapSession().queryWithRowHandler(id, paramObject, rowHandler);
}
public void queryWithRowHandler(String id, RowHandler rowHandler) throws SQLException {
getLocalSqlMapSession().queryWithRowHandler(id, rowHandler);
}
public void startTransaction() throws SQLException {
getLocalSqlMapSession().startTransaction();
}
public void startTransaction(int transactionIsolation) throws SQLException {
getLocalSqlMapSession().startTransaction(transactionIsolation);
}
public void commitTransaction() throws SQLException {
getLocalSqlMapSession().commitTransaction();
}
public void endTransaction() throws SQLException {
try {
getLocalSqlMapSession().endTransaction();
} finally {
getLocalSqlMapSession().close();
}
}
public void startBatch() throws SQLException {
getLocalSqlMapSession().startBatch();
}
public int executeBatch() throws SQLException {
return getLocalSqlMapSession().executeBatch();
}
public List executeBatchDetailed() throws SQLException, BatchException {
return getLocalSqlMapSession().executeBatchDetailed();
}
public void setUserConnection(Connection connection) throws SQLException {
try {
getLocalSqlMapSession().setUserConnection(connection);
} finally {
if (connection == null) {
getLocalSqlMapSession().close();
}
}
}
/**
* TODO Deprecated
*
* @return Current connection
* @throws SQLException
* @deprecated
*/
public Connection getUserConnection() throws SQLException {
return getCurrentConnection();
}
public Connection getCurrentConnection() throws SQLException {
return getLocalSqlMapSession().getCurrentConnection();
}
public DataSource getDataSource() {
return delegate.getDataSource();
}
public MappedStatement getMappedStatement(String id) {
return delegate.getMappedStatement(id);
}
public boolean isLazyLoadingEnabled() {
return delegate.isLazyLoadingEnabled();
}
public boolean isEnhancementEnabled() {
return delegate.isEnhancementEnabled();
}
public SqlExecutor getSqlExecutor() {
return delegate.getSqlExecutor();
}
public SqlMapExecutorDelegate getDelegate() {
return delegate;
}
public SqlMapSession openSession() {
SqlMapSessionImpl sqlMapSession = new SqlMapSessionImpl(this);
sqlMapSession.open();
return sqlMapSession;
}
public SqlMapSession openSession(Connection conn) {
try {
SqlMapSessionImpl sqlMapSession = new SqlMapSessionImpl(this);
sqlMapSession.open();
sqlMapSession.setUserConnection(conn);
return sqlMapSession;
} catch (SQLException e) {
throw new SqlMapException("Error setting user provided connection. Cause: " + e, e);
}
}
/**
* TODO : DEPRECATED
*
* @deprecated Use openSession()
*/
public SqlMapSession getSession() {
log.warn("Use of a deprecated API detected. SqlMapClient.getSession() is deprecated. Use SqlMapClient.openSession() instead.");
return openSession();
}
public void flushDataCache() {
delegate.flushDataCache();
}
public void flushDataCache(String cacheId) {
delegate.flushDataCache(cacheId);
}
//閲囩敤鍗曚緥妯″紡锛屽疄鐜扮嚎绋嬬殑瀹夊叏鎬�
protected SqlMapSessionImpl getLocalSqlMapSession() {
SqlMapSessionImpl sqlMapSession = (SqlMapSessionImpl) localSqlMapSession.get();
if (sqlMapSession == null || sqlMapSession.isClosed()) {
sqlMapSession = new SqlMapSessionImpl(this);
localSqlMapSession.set(sqlMapSession);
}
return sqlMapSession;
}
public ResultObjectFactory getResultObjectFactory() {
return delegate.getResultObjectFactory();
}
}
分享到:
相关推荐
1. **SqlMapClient接口简介:** SqlMapClient是iBatis的核心接口,它的实现类是SqlMapClientImpl。SqlMapClient负责执行SQL映射工作,包括SELECT、INSERT、UPDATE、DELETE等操作。 2. **SqlMapClient接口方法:** ...
实际应用中,通常会通过`SqlMapClientImpl`类来实现这些功能。`SqlMapSession`是每个数据库会话的表示,可以共享或独立创建,但使用完毕后需调用关闭接口释放资源。 `SqlMapExecutorDelegate`是执行代理类,它是...
该接口的实现类是`SqlMapClientImpl`。 - **queryForList**:用于执行查询操作并将结果封装为`List`对象返回。支持多种重载方法,包括指定参数、限制结果集大小等。 - `queryForList(String id)`:执行指定ID的...
基于springboot大学生就业信息管理系统源码数据库文档.zip
基于java的驾校收支管理可视化平台的开题报告
时间序列 原木 间隔5秒钟 20241120
毕业设计&课设_基于 Vue 的电影在线预订与管理系统:后台 Java(SSM)代码,为毕业设计项目.zip
基于springboot课件通中小学教学课件共享平台源码数据库文档.zip
基于java的网上购物商城的开题报告
Delphi人脸检测与识别Demo1fdef-main.zip
基于java的咖啡在线销售系统的开题报告
基于java的自助医疗服务系统的开题报告.docx
内容概要:本文档全面介绍了Visual Basic(VB)编程语言的基础知识和高级应用。首先概述了VB的基本特性和开发环境,随后详细讲述了VB的数据类型、变量、运算符、控制结构、数组、过程与函数、变量作用域等内容。接着介绍了窗体设计、控件使用、菜单与工具栏的设计,文件操作、数据库访问等关键知识点。最后讨论了VB的学习方法、发展历史及其在桌面应用、Web应用、数据库应用、游戏开发和自动化脚本编写等领域的广泛应用前景。 适合人群:初学者和中级程序员,尤其是希望快速掌握Windows桌面应用开发的人群。 使用场景及目标:①掌握VB的基础语法和开发环境;②学会使用VB创建复杂的用户界面和功能完整的应用程序;③理解数据库操作、文件管理和网络编程等高级主题。 其他说明:Visual Basic是一种简单易学且功能强大的编程语言,尤其适合用于开发Windows桌面应用。文中不仅覆盖了基础知识,还包括了大量的实用案例和技术细节,帮助读者快速提升编程技能。
基于java的疫情期间高校防控系统开题报告.docx
基于springboot+vue社区老年人帮扶系统源码数据库文档.zip
基于java的超市商品管理系统的开题报告.docx
基于SpringBoot房屋买卖平台源码数据库文档.zip
xdu限通院23微处理器系统与应用大作业(两只老虎),适应于汇编语言keil软件,
<项目介绍> - 新闻类网站系统,基于SSM(Spring、Spring MVC、MyBatis)+MySQL开发,高分成品毕业设计,附带往届论文 - 不懂运行,下载完可以私聊问,可远程教学 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 --------
基于java的学生网上请假系统的开题报告.docx