/*
* 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的...
微信小程序Artandw_eapp-artand
本项目是一款基于Vue和JavaScript开发的心旅途个性化推荐旅游平台设计源码,整合了513个Java文件、76个PNG图片、70个XML配置文件、62个JavaScript文件、42个Vue组件文件、28个CSS样式文件、22个HTML文件、18个YAML配置文件、16个属性文件、11个Vue模板文件,总计919个文件。平台采用现代化前端技术堆栈,旨在为用户提供个性化的旅游推荐服务。
微信小程序开发地图演示、地图导航、标记标注_echat-weapp-mpdemo
Vue和Axios文件
该项目为基于Python语言开发的HTML与任务清单关系系统,包含50个文件,其中16个为HTML文件,14个为Python源代码文件,其余包括Python编译文件、Markdown文件、图片、数据库文件、配置文件、模板文件、文本文件等,旨在为用户提供简单便捷的生活时间段安排及任务规划管理工具。
全国大学生电子设计大赛项目合集全国电赛优秀作品大学生电子竞赛历届题目
该项目是一款基于Python和pygame引擎开发的植物大战僵尸游戏,包含125个文件,涵盖93个PNG图像文件、11个Python源代码文件、10个Python字节码文件、8个GIF动画文件、1个Git忽略配置文件、1个JSON数据文件以及1个Markdown说明文件。游戏设计源码为学习游戏开发提供了丰富的实践素材。
本项目是一款以Java为核心开发的Qiniu服务端设计源码整合的RunFlow桌面端效率工具,总文件数29个,包括17个Java源文件、2个属性文件、1个Git忽略文件、1个JAR包文件、1个LICENSE文件、1个Markdown文件、1个YAML文件、1个Maven配置文件和1个命令文件。该工具旨在提升工作效率,适用于各种桌面环境下的便捷使用。
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
Golang支付-微信公众号、微信应用、微信小程序、微信企业支付、支付宝网络版、支付宝应用、支付宝企业支付_支付宝
医疗辅助诊断系统-开题
该项目为东东购物网的后台开发源码,采用JavaScript为主要编程语言,辅以CSS、Java、HTML等多种语言,共包含1300个文件。具体文件类型分布如下:458个PNG图片文件、215个JavaScript文件、160个JPG图片文件、159个GIF图片文件、107个CSS样式表文件、96个Java源代码文件、28个HTML文件、24个XML文件、12个JSON文件、8个Map文件。该系统旨在提供高效、便捷的购物后台管理功能。
content_1728052071778.apk
资源视频编辑软件win781064位系统
职业心理测试人格气质情绪控制测试18个文件
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
该项目为基于Python语言的微信小程序源码,全面整合了JavaScript和微信小程序开发技术。项目结构包含50个文件,涵盖了15个PNG图片、9个JSON配置、8个JavaScript脚本、7个wxss样式表、6个WXML模板和4个JPG图片。此外,还包括1个Markdown文档。该小程序的设计与实现展现了Python编程的强大能力,适用于微信生态下的各类应用场景。