use of org.nutz.dao.sql.DaoStatement in project nutz by nutzam.
the class SimpleDaoTest method test_get_sql.
@Test
public void test_get_sql() throws Throwable {
NutDao dao = new NutDao(ioc.get(javax.sql.DataSource.class));
final List<String> sqls = new ArrayList<String>();
final Method m = NutStatement.class.getDeclaredMethod("toStatement", Object[][].class, String.class);
m.setAccessible(true);
dao.setExecutor(new DaoExecutor() {
public void exec(Connection conn, DaoStatement st) {
String psql = st.toPreparedStatement();
sqls.add(psql);
// 事实上根据参数矩阵(getParamMatrix)和Sql语句(toPreparedStatement)就能逐一替换生成
try {
String ssql = (String) m.invoke(st, st.getParamMatrix(), psql);
sqls.add(ssql);
} catch (Exception e) {
e.printStackTrace();
}
}
});
dao.insert(Pet.create("hi"));
for (String sql : sqls) {
System.out.println(sql);
}
}
Aggregations