package com.chenyang.nse.bussiness.odbc.business;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.chenyang.nse.bussiness.odbc.po.SQLReplaceInfo;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import util.SqlUtil;

public class SQLReplaceApi implements OdbcApiCallable {
   public Object invoke(byte[] data) {
      Map<String, String> ret = new HashMap();
      ObjectMapper mapper = new ObjectMapper();

      try {
         SQLReplaceInfo info = (SQLReplaceInfo)mapper.readValue(data, SQLReplaceInfo.class);
         SqlUtil util = new SqlUtil();
         String newSql = util.pareSqlReplaceValue2(info.getParams(), info.getReplacedValues());
         ret.put("sql", newSql);
      } catch (IOException e) {
         e.printStackTrace();
      } catch (Exception e) {
         e.printStackTrace();
      }

      return ret;
   }
}
