当前位置: 首页>>代码示例>>Java>>正文


Java SqlMapClientCallback类代码示例

本文整理汇总了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);
}
 
开发者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


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