本文整理汇总了Java中org.springframework.orm.ibatis.SqlMapClientCallback类的典型用法代码示例。如果您正苦于以下问题:Java SqlMapClientCallback类的具体用法?Java SqlMapClientCallback怎么用?Java SqlMapClientCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SqlMapClientCallback类属于org.springframework.orm.ibatis包,在下文中一共展示了SqlMapClientCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
}
示例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);
}
示例7: batchInsert
import org.springframework.orm.ibatis.SqlMapClientCallback; //导入依赖的package包/类
/**
* 엑셀서비스의 배치업로드를 실행한다.
* @param queryId
* <code>String</code>
* @param list
* <code>List<Object></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();
}
});
}
示例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();
}
});
}
示例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);
}
});
}
示例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;
}
});
}
示例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;
}
});
}
示例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;
}
});
}
示例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;
}
});
}
示例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;
}
});
}
示例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()));
}