package com.defonds.wms.module.common.dao;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException;
import org.springframework.orm.ibatis.SqlMapClientCallback;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.ibatis.sqlmap.client.SqlMapExecutor;
import com.ibatis.sqlmap.client.event.RowHandler;
import com.ibatis.sqlmap.engine.execution.BatchException;
import com.ibatis.sqlmap.engine.execution.BatchResult;
public class BaseDaoImpl extends SqlMapClientDaoSupport implements BaseDao {
public void test(){
//SqlMapClientTemplate ddd = super.getSqlMapClientTemplate();
}
private static final Log LOG = LogFactory.getLog(BaseDaoImpl.class);
@SuppressWarnings("unchecked")
public <T> T execute(SqlMapClientCallback action) throws DataAccessException {
return (T) getSqlMapClientTemplate().execute(action);
}
@SuppressWarnings("unchecked")
public <T> T queryForObject(String statementName) throws DataAccessException {
return (T) getSqlMapClientTemplate().queryForObject(statementName);
}
@SuppressWarnings("unchecked")
public <T> T queryForObject(final String statementName, final Object parameterObject) throws DataAccessException {
return (T) getSqlMapClientTemplate().queryForObject(statementName, parameterObject);
}
@SuppressWarnings("unchecked")
public <T> T queryForObject(final String statementName, final Object parameterObject, final Object resultObject) throws DataAccessException {
return (T) getSqlMapClientTemplate().queryForObject(statementName, parameterObject, resultObject);
}
public List<?> queryForList(String statementName) throws DataAccessException {
return queryForList(statementName, null);
}
public List<?> queryForList(final String statementName, final Object parameterObject) throws DataAccessException {
return getSqlMapClientTemplate().queryForList(statementName, parameterObject);
}
public List<?> queryForList(String statementName, int skipResults, int maxResults)throws DataAccessException {
return queryForList(statementName, null, skipResults, maxResults);
}
public List<?> queryForList(final String statementName, final Object parameterObject, final int skipResults, final int maxResults) throws DataAccessException {
return getSqlMapClientTemplate().queryForList(statementName, parameterObject, skipResults, maxResults);
}
public void queryWithRowHandler(String statementName, RowHandler rowHandler)throws DataAccessException {
queryWithRowHandler(statementName, null, rowHandler);
}
public void queryWithRowHandler( final String statementName, final Object parameterObject, final RowHandler rowHandler) throws DataAccessException {
getSqlMapClientTemplate().queryWithRowHandler(statementName, parameterObject, rowHandler);
}
public Map<?,?> queryForMap( final String statementName, final Object parameterObject, final String keyProperty) throws DataAccessException {
return getSqlMapClientTemplate().queryForMap(statementName, parameterObject, keyProperty);
}
public Map<?,?> queryForMap( final String statementName, final Object parameterObject, final String keyProperty, final String valueProperty) throws DataAccessException {
return getSqlMapClientTemplate().queryForMap(statementName, parameterObject, keyProperty, valueProperty);
}
public <T> T insert(String statementName) throws DataAccessException {
return (T) getSqlMapClientTemplate().insert(statementName, null);
}
@SuppressWarnings("unchecked")
public <T> T insert(final String statementName, final Object parameterObject) throws DataAccessException {
return (T) getSqlMapClientTemplate().insert(statementName, parameterObject);
}
public int update(String statementName) throws DataAccessException {
return update(statementName, null);
}
public int update(final String statementName, final Object parameterObject) throws DataAccessException {
Integer result = (Integer) execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return new Integer(executor.update(statementName, parameterObject));
}
});
return result.intValue();
}
public void update(String statementName, Object parameterObject, int requiredRowsAffected)
throws DataAccessException {
int actualRowsAffected = update(statementName, parameterObject);
if (actualRowsAffected != requiredRowsAffected) {
throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(
statementName, requiredRowsAffected, actualRowsAffected);
}
}
public int delete(String statementName) throws DataAccessException {
return delete(statementName, null);
}
public int delete(final String statementName, final Object parameterObject)
throws DataAccessException {
Integer result = (Integer) execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return new Integer(executor.delete(statementName, parameterObject));
}
});
return result.intValue();
}
public void delete(String statementName, Object parameterObject, int requiredRowsAffected) throws DataAccessException {
int actualRowsAffected = delete(statementName, parameterObject);
if (actualRowsAffected != requiredRowsAffected) {
throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(
statementName, requiredRowsAffected, actualRowsAffected);
}
}
public <T> int updateBatch(final String statementName, final List<T> list) {
if(list == null || list.isEmpty()){
return 0;
}
SqlMapClientCallback callback = new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for (Object obj : list) {
executor.update(statementName, obj);
}
try {
return executor.executeBatchDetailed();
} catch (BatchException e) {
LOG.error(e.getMessage(), e);
throw new SQLException("Batch update failed!");
}
}
};
List<BatchResult> retList = (List<BatchResult>) getSqlMapClientTemplate().execute(callback);
return batchResult(retList);
}
/**
* 从批处理结果返回处理成功的记录数
* @param batchResultList
* @return count
*/
private int batchResult(List<BatchResult> batchResultList) {
int count = 0;
if (batchResultList != null && !batchResultList.isEmpty()) {
BatchResult result = batchResultList.get(0);
if (result != null) {
for (int i : result.getUpdateCounts()) {
if (i == java.sql.Statement.SUCCESS_NO_INFO) {
count++;
} else {
count += i;
}
}
}
}
return count;
}
public <T> void insertBatch(final String statementName, final List<T> list) {
getSqlMapClientTemplate().execute(
new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for (int i = 0; i < list.size(); i++) {
T t = (T)list.get(i);
executor.insert(statementName, t);
if (i%50 == 0) {
executor.executeBatch();
}
}
executor.executeBatch();
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
defonds-server-module.zip (65个子文件)
defonds-server-module
pom.xml 10KB
target
test-classes
com
defonds
wms
module
dep-libs
spring-beans-3.1.2.RELEASE.jar 578KB
spring-context-support-3.1.2.RELEASE.jar 105KB
ezmorph-1.0.6.jar 84KB
mysql-connector-java-5.1.19.jar 783KB
commons-collections-3.2.1.jar 562KB
log4j-1.2.16.jar 470KB
aopalliance-1.0.jar 4KB
commons-beanutils-1.8.3.jar 227KB
spring-jdbc-3.1.2.RELEASE.jar 395KB
commons-httpclient-3.1.jar 298KB
spring-asm-3.1.2.RELEASE.jar 52KB
commons-logging-1.1.1.jar 59KB
spring-context-3.1.2.RELEASE.jar 813KB
ibatis-sqlmap-2.3.4.726.jar 375KB
commons-lang-2.6.jar 278KB
commons-dbcp-1.4.jar 157KB
slf4j-api-1.6.6.jar 26KB
slf4j-log4j12-1.6.6.jar 9KB
spring-expression-3.1.2.RELEASE.jar 172KB
commons-codec-1.6.jar 227KB
spring-core-3.1.2.RELEASE.jar 439KB
json-lib-2.4-jdk15.jar 155KB
spring-tx-3.1.2.RELEASE.jar 239KB
spring-aop-3.1.2.RELEASE.jar 325KB
commons-pool-1.6.jar 109KB
spring-orm-3.1.2.RELEASE.jar 371KB
defonds-server-module.jar 16KB
classes
com
defonds
wms
module
server
DefondsWowzaServerListener.class 3KB
test
service
TestServiceImpl.class 2KB
TestService.class 160B
entity
Config.class 2KB
common
dao
BaseDao.class 3KB
BaseDaoImpl$2.class 1KB
BaseDaoImpl$1.class 1KB
BaseDaoImpl.class 7KB
BaseDaoImpl$4.class 2KB
BaseDaoImpl$3.class 2KB
service
BaseService.class 668B
utils
spring
ApplicationContextUtils.class 862B
sqlMapConfig.xml 394B
config.xml 723B
config.properties 77B
spring-context.xml 3KB
.settings
org.maven.ide.eclipse.prefs 249B
org.eclipse.jdt.core.prefs 274B
src
test
java
com
defonds
wms
module
main
java
com
defonds
wms
module
server
DefondsWowzaServerListener.java 2KB
test
service
TestService.java 105B
TestServiceImpl.java 657B
entity
Config.java 2KB
common
dao
BaseDao.java 3KB
BaseDaoImpl.java 8KB
service
BaseService.java 295B
utils
spring
ApplicationContextUtils.java 572B
sqlMapConfig.xml 394B
config.xml 723B
config.properties 77B
spring-context.xml 3KB
.project 575B
.classpath 514B
lib
wms-server.jar 5.43MB
wms-stream-publish.jar 33KB
wms-httpstreamer-cupertinostreaming.jar 296KB
wms-httpstreamer-smoothstreaming.jar 214KB
wms-httpstreamer-directstreaming.jar 8KB
共 65 条
- 1
资源评论
Defonds
- 粉丝: 7097
- 资源: 428
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- python语言解决背包问题,使用递归和动态规划两种思路并比较运行速度
- 基于Django和Celery的中国知网(CNKI)爬虫及数据可视化设计源码
- 基于C++实现的斐波那契数列
- 基于SSM框架的Java家庭财务管理设计源码
- UDP转发脚本udp-forwarding-udp-forward-master.zip
- tio来开发udptio-udp-showcase-master.zip
- 基于Scala的Spark数字仓库推荐系统设计源码
- 基于Django的博客系统设计源码
- 基于Node.js和AngularJS的JsGen社区网站系统设计源码
- 基于Vue和Echarts的数据可视化大屏设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功