use of com.varsql.core.sql.builder.SqlSource in project varsql by varsqlinfo.
the class SelectExecutor method execute.
@Override
public SQLExecuteResult execute(SqlStatementInfo statementInfo, AbstractSQLExecutorHandler resultHandler) throws SQLException {
SQLExecuteResult result = new SQLExecuteResult();
Map sqlParamMap = VartechUtils.jsonStringToObject(statementInfo.getSqlParam(), HashMap.class);
ResponseResult parseInfo = SqlSourceBuilder.parseResponseResult(statementInfo.getSql(), sqlParamMap, DBType.getDBType(statementInfo.getDbType()));
List<SqlSource> sqlList = parseInfo.getItems();
result.setStartTime(System.currentTimeMillis());
SqlSource tmpSqlSource = sqlList.get(0);
if (resultHandler == null) {
resultHandler = getDefaultSelectHandler();
}
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ConnectionFactory.getInstance().getConnection(statementInfo.getVconnid());
logger.debug("execute query: {} ", tmpSqlSource.getQuery());
pstmt = conn.prepareStatement(tmpSqlSource.getQuery());
pstmt.setMaxRows(statementInfo.getLimit());
SQLParamUtils.setSqlParameter(pstmt, tmpSqlSource);
rs = pstmt.executeQuery();
SQLResultSetUtils.resultSetHandler(rs, statementInfo, resultHandler, true);
} catch (Throwable e) {
result.setResultCode(VarsqlAppCode.EC_SQL_EXECUTOR);
result.setMessage(" error message : " + e.getMessage());
logger.error("select : {} ", e.getMessage(), e);
} finally {
JdbcUtils.close(conn, pstmt, rs);
}
result.setTotalCount(resultHandler.getTotalCount());
result.setEndTime(System.currentTimeMillis());
result.setResult(resultHandler.getResult());
return result;
}
Aggregations