public void addAssociation(TableAssociation ass) {
   String indexKey = null;
   TableNode src = ass.getSource();
   TableNode target = ass.getTarget();
   String index1 = src.getName().split("_")[0];
   String index2 = target.getName().split("_")[0];
   if (index1.equals(index2)) {
     indexKey = index1;
     if (index1.length() > 12) indexKey = index1.substring(0, 11);
   } else {
     indexKey = "MIXED";
   }
   kettleDao.addAssociation(ass, indexKey);
 }
  public String generateQuery(Set<TableAssociation> edgeSet) {
    Set<String> tables = new HashSet<String>();
    StringBuffer from = new StringBuffer("FROM ");
    StringBuffer where = new StringBuffer("WHERE ");
    Iterator<TableAssociation> itera = edgeSet.iterator();
    Set<String> sameNodes = new HashSet<String>();
    int seq = 0;
    boolean first = true;
    while (itera.hasNext()) {
      TableAssociation ass = itera.next();
      if (ass == null) return "Invalid association please refresh it and try again";
      String ta = ass.getSource().getName();
      String tb = ass.getTarget().getName();
      seq++;
      if (sameNodes.contains(ta + tb)) continue;
      sameNodes.add(ta + tb);
      if (!tables.contains(ta)) {
        if (!first) from.append(",");
        from.append(ta);
      }
      if (first) first = false;

      String alias = tb;
      if (ta.equals(tb)) {
        alias = tb + "_" + seq;
        from.append(",").append(tb).append(" ").append(alias);
      } else {
        if (!tables.contains(tb)) {
          from.append(",").append(tb);
          tables.add(tb);
        }
      }
      tables.add(ta);
      //

      String ar = ta.replace("A", "#1#").replace("B", "#2#") + ".";

      String br = alias.replace("A", "#1#").replace("B", "#2#") + ".";
      String preprocess = ass.getJoinCondition().replace("A.", ar).replace("B.", br);
      preprocess = preprocess.replace("#1#", "A").replace("#2#", "B");
      where.append(preprocess);
      where.append(token);
      if (seq < edgeSet.size()) {
        where.append("AND ");
      }
    }
    from.append(token);

    StringBuffer select = new StringBuffer("SELECT");
    select.append(token);
    // generate select clause
    int cnt = 0;
    for (String table : tables) {
      cnt++;
      select.append(getSelectClause(table));
      if (cnt < tables.size()) {
        select.append(",");
      }
      select.append(token);
    }

    return select.append(from).append(where).toString();
  }