package cn.com.sigmasoft.test.persistence.dao;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
public class ProcedureDAOImpl {
/**
* SqlMapClient instances are thread safe, so you only need one.
* In this case, we'll use a static singleton. So sue me. ;-)
*/
private static SqlMapClient sqlMapper;
/**
* It's not a good idea to put code that can fail in a class initializer,
* but for sake of argument, here's how you configure an SQL Map.
*/
static {
try {
Reader reader = Resources.getResourceAsReader("cn/com/sigmasoft/test/persistence/sqlmap/SqlMapConfig.xml");
sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
reader.close();
} catch (IOException e) {
// Fail fast.
throw new RuntimeException("Something bad happened while building the SqlMapClient instance." + e, e);
}
}
public static void donothing() throws SQLException {
sqlMapper.update("donothing");
}
/*
* Override method @see cn.com.sigmasoft.test.persistence.dao.ProcedureDAO#getMax_in_example() of the class ProcedureDAOImpl.java
*
* @return
* @throws SQLException
*/
public static Integer getMax_in_example(int a, int b) throws SQLException {
Map<String, Integer> m = new HashMap<String, Integer>(2);
m.put("a", new Integer(a));
m.put("b", new Integer(b));
m.put("c", new Integer(0));
//执行存储过程in_example
sqlMapper.queryForObject("in_example", m);
return m.get("c");
}
/*
* Override method @see cn.com.sigmasoft.test.persistence.dao.ProcedureDAO#swap() of the class ProcedureDAOImpl.java
*
* @return
* @throws SQLException
*/
public static Map swap(int a, int b) throws SQLException {
Map<String, Integer> m = new HashMap<String, Integer>(2);
m.put("a", new Integer(a));
m.put("b", new Integer(b));
//执行存储过程swap
sqlMapper.queryForObject("swapProcedure", m);
return m;
}
/*
* Override method @see cn.com.sigmasoft.test.persistence.dao.ProcedureDAO#maximum() of the class ProcedureDAOImpl.java
*
* @return
* @throws SQLException
*/
public static Integer maximum(int a, int b) throws SQLException {
Map<String, Integer> m = new HashMap<String, Integer>(2);
m.put("a", new Integer(a));
m.put("b", new Integer(b));
m.put("c", new Integer(0));
//执行存储过程maximum
sqlMapper.queryForObject("maxOutProcedure", m);
return m.get("c");
}
}