• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SqlMapClientCallback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.orm.ibatis.SqlMapClientCallback的典型用法代码示例。如果您正苦于以下问题:Java SqlMapClientCallback类的具体用法?Java SqlMapClientCallback怎么用?Java SqlMapClientCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SqlMapClientCallback类属于org.springframework.orm.ibatis包,在下文中一共展示了SqlMapClientCallback类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: batchUpdate

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
/**
 * 
 * 批量更新指定SQL的数据
 *
 * @author zhangshaobin
 * @created 2012-11-5 下午7:36:32
 *
 * @param sqlId	SQL语句ID
 * @param params	SQL语句中占位符对应的值
 * @return	成功更新的记录数
 */
@Override
public int[] batchUpdate(final String sqlId, final List<? extends BaseEntity> params) {
	// 执行回调
	final SqlMapClientCallback<Object> callback = new SqlMapClientCallback<Object>() {
		// 实现回调接口
		@Override
		public Object doInSqlMapClient(final SqlMapExecutor executor) throws SQLException {
			// 开始批处理
			executor.startBatch();
			final int[] rtnUpd = new int[params.size()];
			for (int i = 0; i < params.size(); i++) {
				//rtnUpd[i] = executor.update(sqlId, params.get(i));
				rtnUpd[i] = executor.update(sqlId, executeRouter(sqlId, params.get(i)));
			}
			// 执行批处理
			executor.executeBatch();
			return rtnUpd;
		}
	};

	return (int[]) getWriteSqlMapClientTemplate().execute(callback);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:34,代码来源:BaseIbatisDaoContext.java


示例2: batchDelete

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
/**
 * 
 * 批量删除指定SQL的数据
 * 
 * @author zhangshaobin
 * @created 2012-12-3 下午2:19:55
 *
 * @param sqlId	SQL语句ID
 * @param params	删除数据的参数集合;NOT NULL
 * @return	成功更新的记录数
 */
@Override
public int[] batchDelete(final String sqlId, final List<BaseEntity> params) {
	// 执行回调
	final SqlMapClientCallback<Object> callback = new SqlMapClientCallback<Object>() {
		// 实现回调接口
		@Override
		public Object doInSqlMapClient(final SqlMapExecutor executor) throws SQLException {
			// 开始批处理
			executor.startBatch();
			final int[] rtnDel = new int[params.size()];
			for (int i = 0; i < params.size(); i++) {
				//rtnDel[i] = executor.delete(sqlId, params.get(i));
				rtnDel[i] = executor.delete(sqlId, executeRouter(sqlId, params.get(i)));
			}
			// 执行批处理
			executor.executeBatch();
			return rtnDel;
		}
	};

	return (int[]) getWriteSqlMapClientTemplate().execute(callback);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:34,代码来源:BaseIbatisDaoContext.java


示例3: batchDelete

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
/**
 * 
 * 批量删除指定SQL的数据
 *
 * @author zhangshaobin
 * @created 2012-12-3 下午2:19:55
 *
 * @param sqlId	SQL语句ID
 * @param params	SQL语句中占位符对应的值
 * @return	成功更新的记录数
 */
public int[] batchDelete(final String sqlId, final List<BaseEntity> params) {
	// 执行回调
	SqlMapClientCallback<Object> callback = new SqlMapClientCallback<Object>() {
		// 实现回调接口
		public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
			// 开始批处理
			executor.startBatch();
			int[] rtnDel = new int[params.size()];
			for (int i = 0; i < params.size(); i++) {
				rtnDel[i] = executor.delete(sqlId, params.get(i));
			}
			// 执行批处理
			executor.executeBatch();
			return rtnDel;
		}
	};

	return (int[]) template.execute(callback);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:31,代码来源:BaseIbatisDAO.java


示例4: batchUpdate

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
/**
 * 
 * 批量更新指定SQL的数据
 *
 * @author zhangshaobin
 * @created 2012-11-5 下午7:36:32
 *
 * @param sqlId	SQL语句ID
 * @param params	SQL语句中占位符对应的值
 * @return	成功更新的记录数
 */
public int[] batchUpdate(final String sqlId, final List<? extends BaseEntity> params) {
	// 执行回调
	SqlMapClientCallback<Object> callback = new SqlMapClientCallback<Object>() {
		// 实现回调接口
		public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
			// 开始批处理
			executor.startBatch();
			int[] rtnUpd = new int[params.size()];
			for (int i = 0; i < params.size(); i++) {
				rtnUpd[i] = executor.update(sqlId, params.get(i));
			}
			// 执行批处理
			executor.executeBatch();
			return rtnUpd;
		}
	};

	return (int[]) template.execute(callback);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:31,代码来源:BaseIbatisDAO.java


示例5: executeWith

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
protected Object executeWith(Connection connection, SqlMapClientCallback action) {
    SqlMapSession session = getSqlMapClient().openSession();
    try {
        try {
            session.setUserConnection(connection);
        } catch (SQLException e) {
            throw new CannotGetJdbcConnectionException("Could not get JDBC Connection", e);
        }
        try {
            return action.doInSqlMapClient(session);
        } catch (SQLException ex) {
            throw new SQLErrorCodeSQLExceptionTranslator().translate("SqlMapClient operation",
                    null, ex);
        }
    } finally {
        session.close();
    }
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:19,代码来源:DefaultConcurrentRequestProcessor.java


示例6: testExecutePrefixMethodsOnCobarSqlMapClientTemplate

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
/**
 * since {@link CobarSqlMapClientTemplate#execute(SqlMapClientCallback)},
 * {@link CobarSqlMapClientTemplate#executeWithListResult(SqlMapClientCallback)
 * )} and
 * {@link CobarSqlMapClientTemplate#executeWithMapResult(SqlMapClientCallback)
 * )} don't support partitioning behaviors, we can unit test them together
 * and use one of them as their representation.
 */
public void testExecutePrefixMethodsOnCobarSqlMapClientTemplate() {

    getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
        public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
            Follower f = new Follower("fname");
            return executor.insert("com.alibaba.cobar.client.entities.Follower.create", f);
        }
    });

    String confirmSQL = "select name from followers where name='fname'";
    // execute method doesn't support partitioning behavior, so the entity will be inserted into default data source, that's , partition1, not partition2 as the rules state.
    verifyEntityExistenceOnSpecificDataSource(confirmSQL, jt1m);
    verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt1s);
    verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt2m);
    verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt2s);
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:25,代码来源:CobarSqlMapClientTemplateWithNamespaceRouterTest.java


示例7: batchInsert

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
/**
 * 엑셀서비스의 배치업로드를 실행한다.
 * @param queryId
 *        <code>String</code>
 * @param list
 *        <code>List&lt;Object&gt;</code>
 * @return
 */
public Integer batchInsert(final String queryId, final List<Object> list) {
    return (Integer) getSqlMapClientTemplate().execute(
        new SqlMapClientCallback() {

            public Object doInSqlMapClient(SqlMapExecutor executor)
                    throws SQLException {

                executor.startBatch();

                for (Iterator<Object> itr = list.iterator(); itr.hasNext();) {
                    executor.insert(queryId, itr.next());
                }

                return executor.executeBatch();
            }
        });
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:26,代码来源:EgovExcelServiceDAO.java


示例8: batchInsertEmp

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
public Integer batchInsertEmp(final String queryId, final List<EmpVO> list) {
    return (Integer) getSqlMapClientTemplate().execute(
        new SqlMapClientCallback() {
            public Object doInSqlMapClient(SqlMapExecutor executor)
                    throws SQLException {
                Iterator<EmpVO> itr = list.iterator();

                executor.startBatch();
                while (itr.hasNext()) {
                    executor.insert(queryId, itr.next());
                }
                // autoboxing
                return executor.executeBatch();
            }
        });

}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:18,代码来源:EmpDAO.java


示例9: queryForList

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public List queryForList(final String statementName, final Object parameterObject, String dataSource){
    return sqlMapClientTemplate.execute(new SqlMapClientCallback<List>() {

        public List doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
            return executor.queryForList(statementName, parameterObject);
        }
    });
}
 
开发者ID:shuqin,项目名称:ALLIN,代码行数:10,代码来源:SqlMapClientTemplateSupport.java


示例10: saveAuthorities

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
/** {@inheritDoc} */
public Boolean saveAuthorities(final Integer groupId, final List<Integer> authorities) {

    return execute(new SqlMapClientCallback<Boolean>() {
        @SuppressWarnings("unchecked")
        public Boolean doInSqlMapClient(SqlMapExecutor executor) {
            int ris = 0;
            try {

                executor.startBatch();
                Iterator<Integer> iter = authorities.iterator();

                while (iter.hasNext()) {
                    Map params = new HashMap();
                    params.put("group_id", groupId);
                    params.put("id", iter.next());
                    executor.insert("updateGroupAuthority", params);
                }
                ris = executor.executeBatch();
            } catch (SQLException e) {
                Logger log = LoggerFactory.getLogger(this.getClass());
                StringBuffer sb = new StringBuffer("saveAuthorities failed \n").append("num items batch:").append(authorities.size()).append("\n").append(" groupId:").append(groupId).append("\n")
                        .append(e.getNextException());
                log.error(sb.toString());
            }
            return ris > 0;
        }
    });
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:30,代码来源:AuthorityRepositoryIbatis.java


示例11: saveItems

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
private Boolean saveItems(final Integer authority, final List<?> items) {

        return execute(new SqlMapClientCallback<Boolean>() {
            @SuppressWarnings("unchecked")
            public Boolean doInSqlMapClient(SqlMapExecutor executor) {
                int ris = 0;
                try {

                    executor.startBatch();
                    Iterator<Integer> iter = (Iterator<Integer>) items.iterator();

                    while (iter.hasNext()) {
                        Map params = new HashMap();
                        params.put("categoryId", iter.next());
                        params.put("authorityId", authority);
                        executor.insert("inserAuthorityItem", params);
                    }
                    ris = executor.executeBatch();
                } catch (SQLException e) {
                    Logger log = LoggerFactory.getLogger(this.getClass());
                    StringBuffer sb = new StringBuffer("saveItems failed \n").append("num items batch:").append(items.size()).append("\n").append(" idUser:").append(authority).append("\n").append(
                            e.getNextException());
                    log.error(sb.toString());
                }
                return ris > 0;
            }
        });
    }
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:29,代码来源:AuthorityRepositoryIbatis.java


示例12: saveItems

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
private Boolean saveItems(final String username, final List<?> items) {

        return execute(new SqlMapClientCallback<Boolean>() {
            @SuppressWarnings("unchecked")
            public Boolean doInSqlMapClient(SqlMapExecutor executor) {
                int ris = 0;
                try {

                    executor.startBatch();
                    Iterator<Integer> iter = (Iterator<Integer>) items.iterator();

                    while (iter.hasNext()) {
                        Map params = new HashMap();
                        params.put("id", iter.next());
                        params.put("username", username);
                        executor.insert("insertUserItem", params);
                    }
                    ris = executor.executeBatch();
                } catch (SQLException e) {
                    Logger log = LoggerFactory.getLogger(this.getClass());
                    StringBuffer sb = new StringBuffer("saveItems failed \n").append("num groups batch:").append(items.size()).append("\n").append(" username:").append(username).append("\n").append(
                            e.getNextException());
                    log.error(sb.toString());
                }
                return ris > 0;
            }
        });
    }
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:29,代码来源:UserRepositoryIbatis.java


示例13: saveGroups

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
/** {@inheritDoc} */
public Boolean saveGroups(final String username, final List<Integer> groups) {

    return execute(new SqlMapClientCallback<Boolean>() {
        @SuppressWarnings("unchecked")
        public Boolean doInSqlMapClient(SqlMapExecutor executor) {
            int ris = 0;
            try {

                executor.startBatch();
                Iterator<Integer> iter = groups.iterator();

                while (iter.hasNext()) {
                    Map params = new HashMap();
                    params.put("username", username);
                    params.put("id", iter.next());
                    executor.insert("insertGroupUser", params);
                }
                ris = executor.executeBatch();
            } catch (SQLException e) {
                Logger log = LoggerFactory.getLogger(this.getClass());
                StringBuffer sb = new StringBuffer("saveGroups failed \n").append("num groups batch:").append(groups.size()).append("\n").append(" username:").append(username).append("\n")
                        .append(e.getNextException());
                log.error(sb.toString());
            }
            return ris > 0;
        }
    });
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:30,代码来源:GroupRepositoryIbatis.java


示例14: saveAuthorities

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
private Boolean saveAuthorities(final Integer group, final List<?> authorities) {

        return execute(new SqlMapClientCallback<Boolean>() {
            @SuppressWarnings("unchecked")
            public Boolean doInSqlMapClient(SqlMapExecutor executor) {
                int ris = 0;
                try {
                    executor.startBatch();
                    Iterator<Integer> iter = (Iterator<Integer>) authorities.iterator();

                    while (iter.hasNext()) {
                        Map params = new HashMap();
                        params.put("id", iter.next());
                        params.put("groupId", group);
                        executor.update("updateGroupAuthority", params);
                    }
                    ris = executor.executeBatch();
                } catch (SQLException e) {
                    Logger log = LoggerFactory.getLogger(this.getClass());
                    StringBuffer sb = new StringBuffer("saveAuthorities failed \n").append("num authorities batch:").append(authorities.size()).append("\n").append(" group:").append(group).append(
                            "\n").append(e.getNextException());
                    log.error(sb.toString());
                }
                return ris > 0;
            }
        });
    }
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:28,代码来源:GroupRepositoryIbatis.java


示例15: shouldNotAllowDirectInvocationOfExecute

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
@Test
public void shouldNotAllowDirectInvocationOfExecute() {
    User loser = new User("loser");
    userDao.saveOrUpdate(loser);

    final User[] loadedUser = new User[1];

    try {
        assertionUtil.doInTxnWithCachePut(new TransactionCacheAssertionUtil.DoInTxn() {
                public void invoke() {
                    daoSupport.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
                        public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
                            loadedUser[0] = userDao.allUsers().get(0);
                            return null;
                        }
                    });
                }
            });
        fail("should not have allowed direct execute invocation");
    } catch (Exception e) {
        assertThat(e, is(instanceOf(UnsupportedOperationException.class)));
        assertThat(e.getMessage(),
                is("Please call one of the supported methods. Refer " + SqlMapClientDaoSupport.SqlMapClientTemplate.class.getCanonicalName() + " for details. This is to ensure read consistency during transactions."));
    }

    assertThat(loadedUser[0], is(nullValue()));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:28,代码来源:SqlMapClientDaoSupportTest.java


示例16: batchInsert

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
public int batchInsert(final String statementName, final Collection<?> entities)
        throws DataAccessException {
    if (isPartitionBehaviorEnabled()) {
        int counter = 0;
        DataAccessException lastEx = null;
        for (Object parameterObject : entities) {
            try {
                getSqlMapClientTemplate().insert(statementName, parameterObject);
                counter++;
            } catch (DataAccessException e) {
                lastEx = e;
            }
        }
        if (lastEx != null) {
            throw lastEx;
        }
        return counter;
    } else {
        return (Integer) getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
            public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
                executor.startBatch();
                for (Object item : entities) {
                    executor.insert(statementName, item);
                }
                return executor.executeBatch();
            }
        });
    }
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:30,代码来源:CobarSqlMapClientDaoSupport.java


示例17: batchDelete

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
public int batchDelete(final String statementName, final Collection<?> entities)
        throws DataAccessException {
    if (isPartitionBehaviorEnabled()) {
        int counter = 0;
        DataAccessException lastEx = null;
        for (Object entity : entities) {
            try {
                counter += getSqlMapClientTemplate().delete(statementName, entity);
            } catch (DataAccessException e) {
                lastEx = e;
            }
        }
        if (lastEx != null) {
            throw lastEx;
        }
        return counter;
    } else {
        return (Integer) getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
            public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
                executor.startBatch();
                for (Object parameterObject : entities) {
                    executor.delete(statementName, parameterObject);
                }
                return executor.executeBatch();
            }
        });
    }
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:29,代码来源:CobarSqlMapClientDaoSupport.java


示例18: update

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
@Override
public int update(final String statementName, final Object parameterObject)
        throws DataAccessException {
    auditSqlIfNecessary(statementName, parameterObject);

    long startTimestamp = System.currentTimeMillis();
    try {
        if (isPartitioningBehaviorEnabled()) {
            SortedMap<String, DataSource> dsMap = lookupDataSourcesByRouter(statementName,
                    parameterObject);
            if (!MapUtils.isEmpty(dsMap)) {

                SqlMapClientCallback action = new SqlMapClientCallback() {
                    public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
                        return executor.update(statementName, parameterObject);
                    }
                };

                List<Object> results = executeInConcurrency(action, dsMap);
                Integer rowAffacted = 0;

                for (Object item : results) {
                    rowAffacted += (Integer) item;
                }
                return rowAffacted;
            }
        } // end if for partitioning status checking
        return super.update(statementName, parameterObject);
    } finally {
        if (isProfileLongTimeRunningSql()) {
            long interval = System.currentTimeMillis() - startTimestamp;
            if (interval > getLongTimeRunningSqlIntervalThreshold()) {
                logger
                        .warn(
                                "SQL Statement [{}] with parameter object [{}] ran out of the normal time range, it consumed [{}] milliseconds.",
                                new Object[] { statementName, parameterObject, interval });
            }
        }
    }
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:41,代码来源:CobarSqlMapClientTemplate.java


示例19: executeInConcurrency

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
public List<Object> executeInConcurrency(SqlMapClientCallback action,
                                         SortedMap<String, DataSource> dsMap) {
    List<ConcurrentRequest> requests = new ArrayList<ConcurrentRequest>();

    for (Map.Entry<String, DataSource> entry : dsMap.entrySet()) {
        ConcurrentRequest request = new ConcurrentRequest();
        request.setAction(action);
        request.setDataSource(entry.getValue());
        request.setExecutor(getDataSourceSpecificExecutors().get(entry.getKey()));
        requests.add(request);
    }

    List<Object> results = getConcurrentRequestProcessor().process(requests);
    return results;
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:16,代码来源:CobarSqlMapClientTemplate.java


示例20: execute

import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
@Override public Object execute(SqlMapClientCallback action) throws DataAccessException {
    if (isInternalCall()) {
        return super.execute(action);
    }
    throw new UnsupportedOperationException("Please call one of the supported methods. Refer " + SqlMapClientDaoSupport.SqlMapClientTemplate.class.getCanonicalName() + " for details. This is to ensure read consistency during transactions.");
}
 
开发者ID:gocd,项目名称:gocd,代码行数:7,代码来源:SqlMapClientDaoSupport.java



注:本文中的org.springframework.orm.ibatis.SqlMapClientCallback类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LongSet类代码示例发布时间:2022-05-23
下一篇:
Java DefaultDependencyResolutionRequest类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap