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 (92个子文件)
defonds-server-module
.project 575B
src
test
java
main
java
spring-context.xml 3KB
config.properties 77B
sqlMapConfig.xml 394B
com
defonds
wms
module
common
service
BaseService.java 295B
dao
BaseDaoImpl.java 8KB
BaseDao.java 3KB
utils
spring
ApplicationContextUtils.java 572B
test
service
TestService.java 105B
TestServiceImpl.java 855B
entity
Config.java 2KB
server
RibbonChangeInstanceService.java 2KB
DefondsWowzaServerListener.java 2KB
RibbonLBRestService.java 3KB
ServerMonitorHttpInterface.java 1KB
config.xml 723B
sample-client.properties 789B
lib
wms-stream-publish.jar 33KB
wms-server.jar 5.43MB
wms-httpstreamer-directstreaming.jar 8KB
wms-httpstreamer-cupertinostreaming.jar 296KB
wms-httpstreamer-smoothstreaming.jar 214KB
target
dep-libs
ribbon-core-0.3.12.jar 190KB
slf4j-log4j12-1.6.6.jar 9KB
spring-aop-3.1.2.RELEASE.jar 325KB
log4j-1.2.16.jar 470KB
servo-core-0.4.44.jar 175KB
commons-beanutils-1.8.3.jar 227KB
httpclient-4.2.1.jar 417KB
netflix-commons-util-0.1.1.jar 7KB
commons-codec-1.6.jar 227KB
spring-tx-3.1.2.RELEASE.jar 239KB
commons-httpclient-3.1.jar 298KB
ezmorph-1.0.6.jar 84KB
guava-14.0.1.jar 2.09MB
spring-context-support-3.1.2.RELEASE.jar 105KB
mysql-connector-java-5.1.19.jar 783KB
spring-core-3.1.2.RELEASE.jar 439KB
netflix-statistics-0.1.1.jar 13KB
commons-dbcp-1.4.jar 157KB
jackson-mapper-asl-1.9.11.jar 762KB
jersey-apache-client4-1.11.jar 15KB
annotations-2.0.0.jar 72KB
httpcore-4.2.1.jar 218KB
commons-logging-1.1.1.jar 59KB
spring-expression-3.1.2.RELEASE.jar 172KB
spring-context-3.1.2.RELEASE.jar 813KB
spring-orm-3.1.2.RELEASE.jar 371KB
slf4j-api-1.6.6.jar 26KB
spring-asm-3.1.2.RELEASE.jar 52KB
archaius-core-0.5.12.jar 125KB
jersey-client-1.11.jar 127KB
ribbon-httpclient-0.3.12.jar 47KB
jersey-core-1.11.jar 451KB
jsr311-api-1.1.1.jar 45KB
spring-beans-3.1.2.RELEASE.jar 578KB
json-lib-2.4-jdk15.jar 155KB
aopalliance-1.0.jar 4KB
commons-configuration-1.8.jar 346KB
ibatis-sqlmap-2.3.4.726.jar 375KB
commons-pool-1.6.jar 109KB
rxjava-core-0.14.2.jar 747KB
commons-lang-2.6.jar 278KB
commons-collections-3.2.1.jar 562KB
jackson-core-asl-1.9.11.jar 227KB
spring-jdbc-3.1.2.RELEASE.jar 395KB
defonds-server-module.jar 22KB
classes
spring-context.xml 3KB
config.properties 77B
sqlMapConfig.xml 394B
com
defonds
wms
module
common
service
BaseService.class 668B
dao
BaseDaoImpl$2.class 1KB
BaseDaoImpl.class 7KB
BaseDaoImpl$3.class 2KB
BaseDao.class 3KB
BaseDaoImpl$4.class 2KB
BaseDaoImpl$1.class 1KB
utils
spring
ApplicationContextUtils.class 862B
test
service
TestServiceImpl.class 2KB
TestService.class 160B
entity
Config.class 2KB
server
RibbonLBRestService.class 5KB
ServerMonitorHttpInterface.class 2KB
RibbonChangeInstanceService.class 3KB
DefondsWowzaServerListener.class 3KB
config.xml 723B
sample-client.properties 789B
test-classes
.settings
org.maven.ide.eclipse.prefs 249B
org.eclipse.jdt.core.prefs 695B
org.eclipse.core.resources.prefs 88B
pom.xml 10KB
.classpath 512B
共 92 条
- 1
资源评论
Defonds
- 粉丝: 7097
- 资源: 428
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功