Package com.alimama.mdrill.adhoc

Examples of com.alimama.mdrill.adhoc.MySqlConn


    return fmt.format(new java.util.Date());

  }
  public String update(String userid,Map<String,String> val,String user) throws SQLException
  {
    MySqlConn m_fpsql = getConn();
    val.put("opuser", String.valueOf(user));
    val.put("optime", getNowTime());
    StringBuffer sqlbuffer=new StringBuffer();
    String joinchar="";
    String[] indexval=new String[val.size()];
    int index=0;
    for(Entry<String, String> e:val.entrySet())
    {
      sqlbuffer.append(joinchar).append(e.getKey()+"=?");
      joinchar=",";
      indexval[index]=e.getValue();
      index++;
    }
   
    Connection conn = m_fpsql.getConn();
    String strSql = "update users_json set " +
        " "+sqlbuffer+" where userid=? ";
    System.out.println(strSql);
    PreparedStatement m_fps = conn.prepareStatement(strSql);
    try {
      for(int i=0;i<indexval.length;i++)
      {
        m_fps.setString(i+1, indexval[i]);

      }
      m_fps.setString(indexval.length+1, userid);

      m_fps.executeUpdate();
      String fullstrSql=m_fps.toString();
      return fullstrSql;
    } catch (Exception e) {
      LOG.error("updatePercent"+m_fps.toString(),e);
    }finally{
      m_fps.close();
      m_fpsql.close();
    }
    return "";
  }
View Full Code Here


    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> result = info.get(uuid);
   
    String rtn= addTxt(tableName, result.get("storedir"),callback);
    setJoinDownload(tableName, uuid,null);
View Full Code Here

    return conf;
  }

  public static String  updatePercent(String uuid,String percent,String status) throws SQLException
  {
    MySqlConn m_fpsql = getConn();

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

      m_fps.executeUpdate();
      String fullstrSql=m_fps.toString();
      return fullstrSql;
    } catch (Exception e) {
      TableJoin.LOG.error("updatePercent"+m_fps.toString(),e);
    }finally{
      m_fps.close();
      m_fpsql.close();
    }
    return "";
  }
View Full Code Here

 
  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 {
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

    }
  }
 
  public static String  updateKb(String uuid,long sz) throws SQLException
  {
    MySqlConn m_fpsql = getConn();

    Connection conn = m_fpsql.getConn();
    String strSql = "update adhoc_joins set " +
        "resultkb=? where tableName=? ";
    System.out.println(strSql);
    PreparedStatement m_fps = conn.prepareStatement(strSql);
    try {
      int index=1;
      m_fps.setInt(index++, (int)sz/1024);
      m_fps.setString(index++, uuid);

      m_fps.executeUpdate();
      String fullstrSql=m_fps.toString();
      return fullstrSql;
    } catch (Exception e) {
      TableJoin.LOG.error("updatePercent"+m_fps.toString(),e);
    }finally{
      m_fps.close();
      m_fpsql.close();
    }
    return "";
  }
View Full Code Here

    String day = fmt.format(new Date());
    Map stormconf = Utils.readStormConfig();
    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 m_fpsql = new MySqlConn(connstr, uname, passwd);
   
    return m_fpsql;
  }
View Full Code Here

    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
    Map stormconf = Utils.readStormConfig();
    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 m_fpsql = new MySqlConn(connstr, uname, passwd);

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

    StringBuffer bufferSql=new StringBuffer();

   
View Full Code Here

    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
    Map stormconf = Utils.readStormConfig();
    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 m_fpsql = new MySqlConn(connstr, uname, passwd);

    Connection conn = m_fpsql.getConn();
    Statement stmt = conn.createStatement();
   
    String strsqlJoin="select '1' as source " +
        ",tableShowName as tableShowName" +
        ",tableName as tableName" +
        ",colsShowName as colsShowName" +
        ",colsName as colsName" +
        ",colsType as colsType" +
        ",splitString as splitString" +
        ",txtStorePath as txtStorePath" +
        ",indexStorePath as indexStorePath" +
        ",'0' as extval" +
        ",'0' as isfinish" +
        ",status as status" +
        ",username as username" +
        ",createtime as createtime" +
        ",lastuptime as lastuptime" +
        ",joins as joins" +
        ",'2' as stage" +
        ",percent as percent" +
        ",resultkb as resultkb" +
        ",memo as memo" +
        " from adhoc_joins where username='"+username.replaceAll("'", "")+"' and status<>'DEL'  and (copy_uuid is null or copy_uuid='')  "+joins+" ";
   
   
    StringBuffer bufferSql=new StringBuffer();
    if(type==0)//个人中心列表
    {
     
      String strsqlJoin2="select '3' as source " +
      ",tableShowName as tableShowName" +
      ",tableName as tableName" +
      ",colsShowName as colsShowName" +
      ",colsName as colsName" +
      ",colsType as colsType" +
      ",splitString as splitString" +
      ",txtStorePath as txtStorePath" +
      ",indexStorePath as indexStorePath" +
      ",'0' as extval" +
      ",'0' as isfinish" +
      ",status as status" +
      ",username as username" +
      ",createtime as createtime" +
      ",lastuptime as lastuptime" +
      ",joins as joins" +
      ",'2' as stage" +
      ",percent as percent" +
      ",resultkb as resultkb" +
      ",memo as memo" +
      " from adhoc_joins where username='"+username.replaceAll("'", "")+"' and status<>'DEL'  and (copy_uuid is not null and copy_uuid<>''  and status='INDEX' )  "+joins+" ";
 
 
     
      String strsqlDownload="select '2' as source " +
      ",jobname as tableShowName" +
      ",uuid as tableName" +
      ",cols as colsShowName" +
      ",'empty' as colsName" +
      ",'empty' as colsType" +
      ",'default' as splitString" +
      ",storedir as txtStorePath" +
      ",'empty' as indexStorePath" +
      ",extval as extval" +
      ",isfinish as isfinish" +
      ",'INDEX' as status" +
      ",username as username" +
      ",starttime as createtime" +
      ",endtime as lastuptime" +
      ",'' as joins" +
      ",stage as stage" +
      ",percent as percent" +
      ",resultkb as resultkb" +
      ",'' as memo" +
      " from adhoc_download where username='"+username.replaceAll("'", "")+"' and status<>'DEL' and  storedir not like '%abtest%'  ";
     
     
      String strsqlAbtest="select '8' as source " +
      ",jobname as tableShowName" +
      ",uuid as tableName" +
      ",cols as colsShowName" +
      ",'empty' as colsName" +
      ",'empty' as colsType" +
      ",'default' as splitString" +
      ",storedir as txtStorePath" +
      ",'empty' as indexStorePath" +
      ",extval as extval" +
      ",isfinish as isfinish" +
      ",'INDEX' as status" +
      ",username as username" +
      ",starttime as createtime" +
      ",endtime as lastuptime" +
      ",'' as joins" +
      ",stage as stage" +
      ",percent as percent" +
      ",resultkb as resultkb" +
      ",'' as memo" +
      " from adhoc_download where username='"+username.replaceAll("'", "")+"' and status<>'DEL' and  storedir like '%abtest%' ";
     
      bufferSql.append("select source,tableShowName,tableName,colsShowName" +
          ",colsName,colsType,splitString,txtStorePath,indexStorePath,extval,status,username," +
          "createtime,lastuptime,joins,stage,percent,resultkb,memo");
      bufferSql.append(" from ("+strsqlJoin+"  union "+strsqlDownload+" union "+strsqlJoin2+" union "+strsqlAbtest+") tmp order by tmp.createtime desc limit "+start+","+rows+" ");
    }
    if(type==1)//for join
    {
      bufferSql.append(strsqlJoin+" and status='INDEX' and resultkb<=512000 order by createtime desc limit "+start+","+rows+" ");
    }
   
   
   
    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() + ")";
    } else {
View Full Code Here

TOP

Related Classes of com.alimama.mdrill.adhoc.MySqlConn

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.