Commit 9c04b9f4 authored by Quxl's avatar Quxl

x

parent 17c5cbce
......@@ -487,11 +487,18 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
public ResultMutil executeMutil(final String sql, final Object... args) {
showSql(sql, args);
Map<Integer, OutParameter> out = new HashMap<Integer, OutParameter>();
return super.execute(new CallableStatementCreator() {
public CallableStatement createCallableStatement(final Connection con) throws SQLException {
final CallableStatement cs = con.prepareCall(sql);
for(int i = 0; i < args.length; i++) {
cs.setObject(i+1, args[i]);
Integer index = i + 1;
Object arg = args[i];
if(arg != null && arg instanceof OutParameter) {
out.put(index, (OutParameter)arg);
} else {
cs.setObject(index, arg);
}
}
return cs;
}
......@@ -514,6 +521,11 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
cs.getMoreResults();
}
}
if(out.size() > 0) {
for(Integer key : out.keySet()) {
out.get(key).setValue(cs.getObject(key));
}
}
return new ResultMutil(datas, counts);
}
});
......@@ -553,16 +565,11 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
}
public static class OutParameter {
private final int index;
private final int type;
private Object value;
public OutParameter(int index, int type) {
this.index = index;
public OutParameter(int type) {
this.type = type;
}
public int getIndex() {
return index;
}
public int getType() {
return type;
}
......@@ -574,49 +581,6 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
}
}
public List<Object> exec(final String sql, List<OutParameter> outs, final Object... args) {
showSql(sql, args);
return super.execute(new CallableStatementCreator() {
public CallableStatement createCallableStatement(final Connection con) throws SQLException {
final CallableStatement cs = con.prepareCall(sql);
for(int i = 0; i < args.length; i++) {
cs.setObject(i+1, args[i]);
}
if(outs != null && outs.size() > 0) {
for(OutParameter out : outs) {
cs.registerOutParameter(out.getIndex(), out.getType());
}
}
return cs;
}
}, new CallableStatementCallback<List<Object>>() {
public List<Object> doInCallableStatement(final CallableStatement cs) throws SQLException, DataAccessException {
List<Object> datas = new ArrayList<Object>();
cs.execute();
while(true) {
Integer count = cs.getUpdateCount();
ResultSet resultSet = cs.getResultSet();
if(count == -1 && resultSet == null) {
break;
} else {
if(resultSet != null) {
datas.add(JUtil.resultSetToList(resultSet));
} else {
datas.add(count);
}
cs.getMoreResults();
}
}
if(outs != null && outs.size() > 0) {
for(OutParameter out : outs) {
out.setValue(cs.getObject(out.getIndex()));
}
}
return datas;
}
});
}
public synchronized String getNumber(String... args) {
String sKey = null;
String format = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment