/*
* 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的...
嵌入式八股文面试题库资料知识宝典-华为的面试试题.zip
训练导控系统设计.pdf
嵌入式八股文面试题库资料知识宝典-网络编程.zip
人脸转正GAN模型的高效压缩.pdf
少儿编程scratch项目源代码文件案例素材-几何冲刺 转瞬即逝.zip
少儿编程scratch项目源代码文件案例素材-鸡蛋.zip
嵌入式系统_USB设备枚举与HID通信_CH559单片机USB主机键盘鼠标复合设备控制_基于CH559单片机的USB主机模式设备枚举与键盘鼠标数据收发系统支持复合设备识别与HID
嵌入式八股文面试题库资料知识宝典-linux常见面试题.zip
面向智慧工地的压力机在线数据的预警应用开发.pdf
基于Unity3D的鱼类运动行为可视化研究.pdf
少儿编程scratch项目源代码文件案例素材-霍格沃茨魔法学校.zip
少儿编程scratch项目源代码文件案例素材-金币冲刺.zip
内容概要:本文深入探讨了HarmonyOS编译构建子系统的作用及其技术细节。作为鸿蒙操作系统背后的关键技术之一,编译构建子系统通过GN和Ninja工具实现了高效的源代码到机器代码的转换,确保了系统的稳定性和性能优化。该系统不仅支持多系统版本构建、芯片厂商定制,还具备强大的调试与维护能力。其高效编译速度、灵活性和可扩展性使其在华为设备和其他智能终端中发挥了重要作用。文章还比较了HarmonyOS编译构建子系统与安卓和iOS编译系统的异同,并展望了其未来的发展趋势和技术演进方向。; 适合人群:对操作系统底层技术感兴趣的开发者、工程师和技术爱好者。; 使用场景及目标:①了解HarmonyOS编译构建子系统的基本概念和工作原理;②掌握其在不同设备上的应用和优化策略;③对比HarmonyOS与安卓、iOS编译系统的差异;④探索其未来发展方向和技术演进路径。; 其他说明:本文详细介绍了HarmonyOS编译构建子系统的架构设计、核心功能和实际应用案例,强调了其在万物互联时代的重要性和潜力。阅读时建议重点关注编译构建子系统的独特优势及其对鸿蒙生态系统的深远影响。
嵌入式八股文面试题库资料知识宝典-奇虎360 2015校园招聘C++研发工程师笔试题.zip
嵌入式八股文面试题库资料知识宝典-腾讯2014校园招聘C语言笔试题(附答案).zip
双种群变异策略改进RWCE算法优化换热网络.pdf
内容概要:本文详细介绍了基于瞬时无功功率理论的三电平有源电力滤波器(APF)仿真研究。主要内容涵盖并联型APF的工作原理、三相三电平NPC结构、谐波检测方法(ipiq)、双闭环控制策略(电压外环+电流内环PI控制)以及SVPWM矢量调制技术。仿真结果显示,在APF投入前后,电网电流THD从21.9%降至3.77%,显著提高了电能质量。 适用人群:从事电力系统研究、电力电子技术开发的专业人士,尤其是对有源电力滤波器及其仿真感兴趣的工程师和技术人员。 使用场景及目标:适用于需要解决电力系统中谐波污染和无功补偿问题的研究项目。目标是通过仿真验证APF的有效性和可行性,优化电力系统的电能质量。 其他说明:文中提到的仿真模型涉及多个关键模块,如三相交流电压模块、非线性负载、信号采集模块、LC滤波器模块等,这些模块的设计和协同工作对于实现良好的谐波抑制和无功补偿至关重要。