Hibernate调用执行存储过程
来源:互联网 发布:资源管理器 删除网络 编辑:程序博客网 时间:2024/05/17 07:01
/**
* 执行存储过程的方法(存储过程仅仅支持输入参数的使用,并且无返回值的以后扩展信息)
*
* @param procedureName
* 存储过程的名称
* @param paramList
* 备注:Map<String, Object> paramList 其中String 参数: Object输入的参数对象
* 存储过程参数的信息
*/
public void executeProcedure(String procedureName, final Map<String, Object> paramList) {
if (StringUtils.isNotBlank(procedureName)) {
int length = 0;
if (MapUtils.isNotEmpty(paramList)) {
length = paramList.size();
}
final String executeProcedure = generationExcuteProdure(procedureName, length);
this.getHibernateTemplate().execute(new HibernateCallback() {
@SuppressWarnings("deprecation")
@Override
public Object doInHibernate(Session session) throws HibernateException, SQLException {
boolean flag = false;
Transaction trans = session.beginTransaction();
try {
CallableStatement cstmt = session.connection().prepareCall(executeProcedure);
if (MapUtils.isNotEmpty(paramList)) {
Set<Entry<String, Object>> entrys = paramList.entrySet();
for (Entry<String, Object> entry : entrys) {
cstmt.setObject(entry.getKey(), entry.getValue());
}
}
flag = cstmt.execute();
trans.commit();
} catch (RuntimeException e) {
trans.rollback();
flag = false;
logger.error(e);
}
return flag;
}
});
} else {
throw new RuntimeException(" the procedureName is not null!");
}
}
/**
* 生成存储过程的方法
*
* @param procedureName
* 存储过程的名称
* @param length
* 参数的个数
* @return 生成的执行的存储过程
*/
private String generationExcuteProdure(String procedureName, int length) {
StringBuilder sql = new StringBuilder();
sql.append("{ call ");
sql.append(StringUtils.trim(procedureName));
if (length > 0) {
sql.append("(");
for (int i = 0; i < length; i++) {
sql.append("?");
if (i != length - 1) {
sql.append(",");
}
}
sql.append(")");
}
sql.append("}");
logger.info("executeProcedure", sql.toString());
return sql.toString();
}
- Hibernate调用执行存储过程
- hibernate调用存储过程
- Hibernate调用存储过程
- hibernate调用存储过程
- hibernate 调用存储过程
- hibernate调用存储过程
- Hibernate调用存储过程
- Hibernate调用存储过程
- Hibernate --调用存储过程
- hibernate调用存储过程
- hibernate调用存储过程
- hibernate 调用存储过程
- hibernate调用存储过程
- Hibernate调用存储过程
- hibernate调用存储过程
- hibernate调用存储过程
- hibernate 调用存储过程
- hibernate 调用存储过程
- python 全局变量
- 程序员的七夕
- 【svn】 cleanup 清除锁定
- java关键字--interface
- ASCII与中文互转
- Hibernate调用执行存储过程
- Andorid Map布局 可添加自定义控件
- 修改tableview各个 section之间的间隔
- ubuntu 安装jdk,gogent
- ORA-01940: cannot drop a user that is currently connected
- 内存中的数据对齐
- 在前台加入分页的html代码
- IOS下写文件的方法
- 正则表达式学习