Search in sources :

Example 1 with SQLScript

use of org.beetl.sql.core.SQLScript in project jSqlBox by drinkjava2.

the class BeetlSqlTempalte method doRender.

private static PreparedSQL doRender(SQLManager sm, String sqlId, Object paras) {
    Map<String, Object> param = new HashMap<String, Object>();
    param.put("_root", paras);
    SQLScript script = sm.getScript(sqlId);
    SQLResult result = null;
    try {
        // run method in SQLScript is protected, have to make it accessible
        Method method = SQLScript.class.getDeclaredMethod("run", Map.class);
        ReflectionUtils.makeAccessible(method);
        result = (SQLResult) method.invoke(script, param);
    } catch (Exception e) {
        throw new SqlBoxException("Can not access method 'run' in class 'org.beetl.sql.core.SQLScript'");
    }
    PreparedSQL sp = new PreparedSQL();
    sp.setSql(result.jdbcSql);
    List<SQLParameter> sqlparam = result.jdbcPara;
    Object[] params = new Object[sqlparam.size()];
    for (int i = 0; i < sqlparam.size(); i++) {
        params[i] = sqlparam.get(i).value;
    }
    sp.setParams(params);
    return sp;
}
Also used : PreparedSQL(com.github.drinkjava2.jdbpro.inline.PreparedSQL) HashMap(java.util.HashMap) SqlBoxException(com.github.drinkjava2.jsqlbox.SqlBoxException) SQLParameter(org.beetl.sql.core.engine.SQLParameter) SQLScript(org.beetl.sql.core.SQLScript) Method(java.lang.reflect.Method) SqlBoxException(com.github.drinkjava2.jsqlbox.SqlBoxException) SQLResult(org.beetl.sql.core.SQLResult)

Aggregations

PreparedSQL (com.github.drinkjava2.jdbpro.inline.PreparedSQL)1 SqlBoxException (com.github.drinkjava2.jsqlbox.SqlBoxException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 SQLResult (org.beetl.sql.core.SQLResult)1 SQLScript (org.beetl.sql.core.SQLScript)1 SQLParameter (org.beetl.sql.core.engine.SQLParameter)1