Package com.alimama.mdrill.json

Examples of com.alimama.mdrill.json.JSONObject


    return "";
  }
 
  public static String  setJoinDownload(String tablename,String uuid,String callback) throws SQLException, JSONException
  {
    JSONObject jsonObj = new JSONObject();

    MySqlConn m_fpsql = getConn();

    Connection conn = m_fpsql.getConn();
    String strSql = "update adhoc_joins set download_uuid=?,lastuptime=? where tableName=? ";
    PreparedStatement m_fps = conn.prepareStatement(strSql);
    try {
      int index=1;
      m_fps.setString(index++, uuid);
      m_fps.setTimestamp(index++, new java.sql.Timestamp(System.currentTimeMillis()));
      m_fps.setString(index++, tablename);

      m_fps.executeUpdate();
      String fullstrSql=m_fps.toString();
      jsonObj.put("code", "1");

      return fullstrSql;
    } catch (Exception e) {
      jsonObj.put("code", "0");

      TableJoin.LOG.error("updatePercent"+m_fps.toString(),e);
    }finally{
      m_fps.close();
      m_fpsql.close();
    }
   
    if (callback != null && callback.length() > 0) {
      return callback + "(" + jsonObj.toString() + ")";
    } else {
      return jsonObj.toString();
    }
  }
View Full Code Here


    }
  }
 
  public static String  setJoinDelete(String uuid,String callback) throws SQLException, JSONException
  {
    JSONObject jsonObj = new JSONObject();

    MySqlConn m_fpsql = getConn();

    Connection conn = m_fpsql.getConn();
    String strSql = "update adhoc_joins set status='DEL',lastuptime=? where tableName=? ";
    PreparedStatement m_fps = conn.prepareStatement(strSql);
    try {
      int index=1;
      m_fps.setTimestamp(index++, new java.sql.Timestamp(System.currentTimeMillis()));
      m_fps.setString(index++, uuid);

      m_fps.executeUpdate();
      String fullstrSql=m_fps.toString();
      jsonObj.put("code", "1");
      jsonObj.put("__debug", fullstrSql);
    } catch (Exception e) {
      TableJoin.LOG.error("updatePercent"+m_fps.toString(),e);
      jsonObj.put("__debugerror", m_fps.toString());
      jsonObj.put("code", "0");
    }finally{
      m_fps.close();
      m_fpsql.close();
    }
    if (callback != null && callback.length() > 0) {
      return callback + "(" + jsonObj.toString() + ")";
    } else {
      return jsonObj.toString();
    }
  }
View Full Code Here

    }
  }
 
  public static String  DeleteDownload(String uuid,String callback) throws SQLException, JSONException
  {
    JSONObject jsonObj = new JSONObject();

    MySqlConn m_fpsql = getConn();

    Connection conn = m_fpsql.getConn();
    String strSql = "update adhoc_download set status='DEL',endtime=? where uuid=? ";
    PreparedStatement m_fps = conn.prepareStatement(strSql);
    try {
      int index=1;
      m_fps.setTimestamp(index++, new java.sql.Timestamp(System.currentTimeMillis()));
      m_fps.setString(index++, uuid);

      m_fps.executeUpdate();
      String fullstrSql=m_fps.toString();
      jsonObj.put("code", "1");
      jsonObj.put("__debug", fullstrSql);
    } catch (Exception e) {
      jsonObj.put("code", "0");
      TableJoin.LOG.error("updatePercent"+m_fps.toString(),e);
      jsonObj.put("__debugerror", m_fps.toString());
    }finally{
      m_fps.close();
      m_fpsql.close();
    }
    if (callback != null && callback.length() > 0) {
      return callback + "(" + jsonObj.toString() + ")";
    } else {
      return jsonObj.toString();
    }
  }
View Full Code Here

    buff.append("<td>").append("params").append("</td>");

   
    buff.append("</tr>");   
    while (res.next()) {
      JSONObject item = new JSONObject();

      item.put("source", res.getString("source"));
      item.put("tableShowName", res.getString("tableShowName"));//展示名称
      item.put("tableName", res.getString("tableName"));//uuid
      item.put("colsShowName", res.getString("colsShowName").replaceAll("\\(", "_").replaceAll("\\)", "_").replaceAll(" ", "").replaceAll("_,", ",").replaceAll(",$", ""));
      item.put("colsName", res.getString("colsName"));
      item.put("colsType", res.getString("colsType"));
      item.put("splitString", res.getString("splitString"));
      item.put("txtStorePath", res.getString("txtStorePath"));
      item.put("indexStorePath", res.getString("indexStorePath"));
      item.put("extval", res.getString("extval"));
      item.put("status", res.getString("status"));
      item.put("username", res.getString("username"));
      item.put("createtime", res.getString("createtime"));
      item.put("lastuptime", res.getString("lastuptime"));
      item.put("joins", res.getString("joins"));
      item.put("params", res.getString("params"));
      item.put("stage", res.getString("stage"));
      item.put("percent", res.getString("percent"));
      item.put("resultkb", parseInt(res.getString("resultkb"))>0?res.getString("resultkb"):"<1");
      item.put("memo", String.valueOf(res.getString("memo")));
      boolean isoversize= (!res.getString("source").equals("8"))&&parseInt(res.getString("resultkb"))>512000;
     
     

      boolean issuccess=res.getString("status").equals("INDEX")&&res.getString("extval").equals("0");
     
     
      boolean iserror=res.getString("status").equals("FAIL")||!res.getString("extval").equals("0");
      double percent=parsePercent(res.getString("stage"),res.getString("percent"),issuccess);
     
      if(percent>=100&&res.getString("source").equals("8")&&parseInt(res.getString("resultkb"))<=0)
      {
        issuccess=false;
        iserror=true;
      }
     
      boolean isallowEdit=!res.getString("status").equals("INDEXING")&&res.getString("source").equals("1");
      item.put("allowCreate",String.valueOf(res.getString("source").equals("2")&&issuccess&&percent>=100&&!isoversize));//是否允许将离线下载转换为个人表
      item.put("allowUpload",String.valueOf(isallowEdit&&res.getString("status").equals("init")));//上传
      item.put("allowDownload",String.valueOf((issuccess||res.getString("status").equals("DUMP"))&&percent>=100));//下载
      item.put("allowJoin",String.valueOf(res.getString("source").equals("1")&&issuccess&&percent>=100&&!isoversize));//join
      item.put("allowSend",String.valueOf(issuccess&&percent>=100));//推送
      item.put("isError", iserror);
      String uuidshow=iserror?("<br>"+res.getString("tableName")):"";
      item.put("proccess", ((res.getString("status").equals("DUMP")||iserror)?"0":DF_FORMAT.format(percent))+"%");
     

      item.put("msg", String.valueOf(iserror?"服务器异常":isoversize?"数据文件超过500M  ":res.getString("status").equals("DUMP")?"设置关联关系的字段有重复值":issuccess&&percent>=100?"成功":res.getString("status").equals("init")?"等待上传数据":"处理中...")+uuidshow);

     

      buff.append("<tr>")
      buff.append("<td>").append(item.get("tableShowName")).append("</td>");
      buff.append("<td>").append(item.get("tableName")).append("</td>");
      buff.append("<td>").append(item.get("username")).append("</td>");
      buff.append("<td>").append(item.get("resultkb")).append("</td>");
      buff.append("<td>").append(item.get("createtime")).append("</td>");
      buff.append("<td>").append(item.get("proccess")).append("</td>");
      buff.append("<td>").append(item.get("msg")).append("</td>");
      buff.append("<td>").append(item.get("params")).append("</td>");

     
      buff.append("</tr>");     

     
View Full Code Here

   
   
    String sql=bufferSql.toString();
    TableJoin.LOG.info("getUserTables:"+sql);
    ResultSet res = stmt.executeQuery(sql);
    JSONObject jsonObj = new JSONObject();
    jsonObj.put("code", "1");
    jsonObj.put("_exehql", sql);
    JSONArray jsonArray = new JSONArray();

    while (res.next()) {
      JSONObject item = new JSONObject();

      item.put("source", res.getString("source"));
      item.put("tableShowName", res.getString("tableShowName"));//展示名称
      item.put("tableName", res.getString("tableName"));//uuid
      item.put("colsShowName", res.getString("colsShowName").replaceAll("\\(", "_").replaceAll("\\)", "_").replaceAll(" ", "").replaceAll("_,", ",").replaceAll(",$", ""));
      item.put("colsName", res.getString("colsName"));
      item.put("colsType", res.getString("colsType"));
      item.put("splitString", res.getString("splitString"));
      item.put("txtStorePath", res.getString("txtStorePath"));
      item.put("indexStorePath", res.getString("indexStorePath"));
      item.put("extval", res.getString("extval"));
      item.put("status", res.getString("status"));
      item.put("username", res.getString("username"));
      item.put("createtime", res.getString("createtime"));
      item.put("lastuptime", res.getString("lastuptime"));
      item.put("joins", res.getString("joins"));
      item.put("stage", res.getString("stage"));
      item.put("percent", res.getString("percent"));
      item.put("resultkb", parseInt(res.getString("resultkb"))>0?res.getString("resultkb"):"<1");
      item.put("memo", String.valueOf(res.getString("memo")));
      boolean isoversize= (!res.getString("source").equals("8"))&&parseInt(res.getString("resultkb"))>512000;

      boolean issuccess=res.getString("status").equals("INDEX")&&res.getString("extval").equals("0");
     
     
      boolean iserror=res.getString("status").equals("FAIL")||!res.getString("extval").equals("0");
      double percent=parsePercent(res.getString("stage"),res.getString("percent"),issuccess);
     
     
      if(percent>=100&&res.getString("source").equals("8")&&parseInt(res.getString("resultkb"))<=0)
      {
        issuccess=false;
        iserror=true;
      }
     
      boolean isallowEdit=!res.getString("status").equals("INDEXING")&&res.getString("source").equals("1");
      item.put("allowCreate",String.valueOf(res.getString("source").equals("2")&&issuccess&&percent>=100&&!isoversize));//是否允许将离线下载转换为个人表
      item.put("allowUpload",String.valueOf(isallowEdit&&res.getString("status").equals("init")));//上传
      item.put("allowDownload",String.valueOf((issuccess||res.getString("status").equals("DUMP"))&&percent>=100));//下载
      item.put("allowJoin",String.valueOf(res.getString("source").equals("1")&&issuccess&&percent>=100&&!isoversize));//join
      item.put("allowSend",String.valueOf(issuccess&&percent>=100));//推送
      item.put("isError", iserror);
      String uuidshow=iserror?("<br>"+res.getString("tableName")):"";
      item.put("proccess", ((res.getString("status").equals("DUMP")||iserror)?"0":DF_FORMAT.format(percent))+"%");

      item.put("msg", String.valueOf(iserror?"服务器异常":isoversize?"数据文件超过500M  ":res.getString("status").equals("DUMP")?"设置关联关系的字段有重复值":issuccess&&percent>=100?"成功":res.getString("status").equals("init")?"等待上传数据":"处理中...")+uuidshow);

      
      jsonArray.put(item);
     
        }
    HashMap<String,String> cnt=getUserTablesCount(username, type,moduleName);

    JSONObject data = new JSONObject();
    data.put("list",jsonArray);
    data.put("total",cnt.get("cnt"));
    jsonObj.put("data",data);
    jsonObj.put("total_debug", new JSONObject(cnt));
    m_fpsql.close();
   
 
    if (callback != null && callback.length() > 0) {
      return callback + "(" + jsonObj.toString() + ")";
View Full Code Here

    Long small = -1l;
    Long bigger = -1l;
    JSONArray jsonStr = new JSONArray(queryStr.trim());

    for (int j = 0; j < jsonStr.length(); j++) {
      JSONObject obj = jsonStr.getJSONObject(j);
      if (obj.has("thedate")) {
        JSONObject thedate = obj.getJSONObject("thedate");
        Integer operate = Integer.parseInt(thedate.get("operate").toString());
        OperateType optype=WebServiceParams.parseOperateType(operate);

        String[] val = WebServiceParams.parseFqValue(thedate.getString("value"), operate).split(",");
        if (optype.equals(OperateType.eq)||optype.equals(OperateType.in))
        {
          for (String day : val) {
            Date d = fmt.parse(day.replaceAll("-", ""));
            String[] partions = get(d.getTime(), d.getTime(), parttype);
View Full Code Here

 
 
 
  public static String copyto(String uuid,String mailto,String callback,String memo) throws Exception
  {
    JSONObject jsonObj = new JSONObject();
    HashMap<String,String> tableInfo=getTableInfo(uuid);
   
    if(tableInfo==null)
    {
      //TODO
      Map stormconf = Utils.readStormConfig();
      String hdpConf = (String) stormconf.get("hadoop.conf.dir");
      String connstr = (String) stormconf.get("higo.download.offline.conn");
      String uname = (String) stormconf.get("higo.download.offline.username");
      String passwd = (String) stormconf.get("higo.download.offline.passwd");
      MySqlConn conn = new MySqlConn(connstr, uname, passwd);
      MysqlInfo info = new MysqlInfo(conn);
      HashMap<String, String> result2 = info.get(uuid);
      if(result2!=null)
      {
        tableInfo=new HashMap<String, String>();
        tableInfo.put("tableShowName", result2.get("jobname"));
        tableInfo.put("tableName", result2.get("uuid"));
        tableInfo.put("colsShowName", result2.get("cols"));
        tableInfo.put("colsName", "");
        tableInfo.put("colsType", "");
        tableInfo.put("splitString", "default");
        tableInfo.put("memo", String.valueOf(result2.get("memo")));

        tableInfo.put("txtStorePath", result2.get("storedir"));
        tableInfo.put("indexStorePath", "");
        tableInfo.put("status", "INDEX");
        tableInfo.put("username", result2.get("username"));
        tableInfo.put("createtime", result2.get("starttime"));
        tableInfo.put("lastuptime", result2.get("endtime"));
        tableInfo.put("joins", "");
        tableInfo.put("percent", "Stage-2 map = 100%,  reduce = 100%");
        tableInfo.put("resultkb", result2.get("resultkb"));
        tableInfo.put("download_uuid", "");
        tableInfo.put("copy_uuid", uuid);
      }
    }
   
    tableInfo.put("memo", String.valueOf(memo));//tableInfo.get("username")+":"+
    if(tableInfo==null||tableInfo.isEmpty())
    {
      jsonObj.put("code", "0");
      jsonObj.put("message""该表不存在");
    }else
    if(tableInfo.get("status").equals("INDEXING"))
    {
      jsonObj.put("code", "0");
      jsonObj.put("message", "正在创建索引中请稍后");
      return jsonObj.toString();
    }else
    {
    JSONArray list = new JSONArray();

    for(String username:mailto.split(","))
    {
      JSONObject result=createByMap(tableInfo, uuid,username);
      list.put(result);
    }
    jsonObj.put("code", "1");
    jsonObj.put("data", list);
  }
View Full Code Here

      return jsonObj.toString();
    }  }
 
  public static JSONObject createByMap(final HashMap<String,String> tableInfo,String copyuuid,String username) throws Exception
  {
    JSONObject jsonObj = new JSONObject();

    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
    String day = fmt.format(new Date());
    Map stormconf = Utils.readStormConfig();
    String hdpConf = (String) stormconf.get("hadoop.conf.dir");
    String connstr = (String) stormconf.get("higo.download.offline.conn");
    String uname = (String) stormconf.get("higo.download.offline.username");
    String passwd = (String) stormconf.get("higo.download.offline.passwd");
    String store = (String) stormconf.get("higo.download.offline.store")
        + "/" + day + "/" + java.util.UUID.randomUUID().toString();
    MySqlConn m_fpsql = new MySqlConn(connstr, uname, passwd);
   
    String tableName=java.util.UUID.randomUUID().toString();
    Connection conn = m_fpsql.getConn();
//    tableShowName,tableName,colsShowName,colsName,colsType,splitString,txtStorePath,indexStorePath,status,username,createtime,lastuptime,joins,percent,resultkb,download_uuid,copy_uuid
    String strSql = "insert into adhoc_joins " +
        "(tableShowName,tableName,colsShowName,colsName,colsType,splitString,txtStorePath,indexStorePath,status,username,createtime,lastuptime,joins,percent,resultkb,download_uuid,copy_uuid,memo)" +
        "values" +
        "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    PreparedStatement m_fps = conn.prepareStatement(strSql);
    try {
      int index=1;
      m_fps.setString(index++, tableInfo.get("tableShowName"));
      m_fps.setString(index++, tableName);
      m_fps.setString(index++, tableInfo.get("colsShowName"));
      m_fps.setString(index++, tableInfo.get("colsName"));
      m_fps.setString(index++, tableInfo.get("colsType"));
      m_fps.setString(index++, tableInfo.get("splitString"));
      m_fps.setString(index++, tableInfo.get("txtStorePath"));
      m_fps.setString(index++, tableInfo.get("indexStorePath"));
      m_fps.setString(index++, tableInfo.get("status"));
      m_fps.setString(index++, username);
      long nowtims=System.currentTimeMillis();
      m_fps.setTimestamp(index++, new java.sql.Timestamp(nowtims));
      m_fps.setTimestamp(index++, new java.sql.Timestamp(nowtims));
     
      m_fps.setString(index++, tableInfo.get("joins"));
      m_fps.setString(index++, tableInfo.get("percent"));
      m_fps.setInt(index++, Integer.parseInt(tableInfo.get("resultkb")));
      m_fps.setString(index++, tableInfo.get("download_uuid"));
      m_fps.setString(index++, copyuuid);
      m_fps.setString(index++, tableInfo.get("memo"));
      m_fps.executeUpdate();
      jsonObj.put("code", "1");
      jsonObj.put("tableid", tableName);
      jsonObj.put("____debug", m_fps.toString());
    } catch (Exception e) {
      jsonObj.put("____debug2", m_fps.toString());
      jsonObj.put("____debugerror", e.toString());
      jsonObj.put("code", "0");
    }finally{
      m_fps.close();
      m_fpsql.close();
    }
   
View Full Code Here

    Connection conn = m_fpsql.getConn();
    Statement stmt = conn.createStatement();

    String sql="select tab_key,tab_value from tab_infos where tab_key='"+key+"' limit 10";
    ResultSet res = stmt.executeQuery(sql);
    JSONObject jsonObj = new JSONObject();

    HashMap<String,String> rtn=new HashMap<String,String>();
    jsonObj.put("code", "0");

    boolean issetup=false;
    while (res.next()) {
      rtn.put("tab_key", res.getString("tab_key"));
      rtn.put("tab_value", res.getString("tab_value"));
      issetup=true;
        }
    m_fpsql.close();
   
    if(issetup)
{
      jsonObj.put("data", rtn.get("tab_key"));
      jsonObj.put("code", "1");
    } else {
      jsonObj.put("message", "nodata");
      jsonObj.put("data", "");
      jsonObj.put("code", "1");
    }
    return jsonObj.toString();
  }
View Full Code Here

  public static String set(String key,String value) throws Exception{
    HashMap<String,String> rtn=new HashMap<String,String>();
    rtn.put("code", "0");

    try {
      JSONObject last=new JSONObject(get(key));
      if(last.has("message")&&last.getString("message").equals("nodate"))
      {
        String result=insert(key,value);
        return result;
      }else{
        update(key, value);
        rtn.put("lastdata",last.getString("data"));
      }
      rtn.put("code", "1");

    } catch (Exception e) {
      rtn.put("message", e.toString());
    }
    return new JSONObject(rtn).toString();
  }
View Full Code Here

TOP

Related Classes of com.alimama.mdrill.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.