@SuppressWarnings("unchecked")
    private void getByTagsOperation(DataStoreOperation op)
        throws UnsupportedEncodingException, SQLException {
      Set<String> tags = ((GetByTagsOperation) op).getTags();
      Set<Map<String, String>> result = new HashSet<Map<String, String>>();
      // int i=0;
      // String auxTag;
      for (String tag : tags) {
        if (tag != null) {
          /*if(i==0){
          }
          else {*/
          String query = null;
          if (tag.startsWith("topic")) { // TOPIC
            // auxTag = "#"+tag.toString();
            query =
                "select tweets.tweetID,id,text,date,user from (select tweetID from tweetsTags where  topic = ?) as res inner join tweets on res.tweetID = tweets.tweetID order by date DESC";
          } else if (tag.startsWith("user")) { // USER
            // auxTag = "@"+tag.toString();
            query =
                "select tweets.tweetID,id,text,date,user from (select tweetID from tweetsTags where  user = ?) as res inner join tweets on res.tweetID = tweets.tweetID order by date DESC";
          }

          java.sql.Connection conn = null;
          conn = this.borrowClient();
          PreparedStatement stmt = conn.prepareStatement(query);
          ResultSet results = null;
          try {
            stmt.setString(1, tag);
            results = stmt.executeQuery();

            while (results.next()) {
              Map<String, String> tweet = new HashMap<String, String>();
              tweet.put("id", results.getString("id"));
              tweet.put("text", results.getString("text"));
              tweet.put("date", results.getString("date"));
              tweet.put("user", results.getString("user"));
              result.add(tweet);
            }
          } finally {
            try {
              stmt.close();
            } catch (Exception e) {
            }
            this.releaseClient(conn);
          }
          // }
        }
        // i++;
      }
      ((GetByTagsOperation) op).setResult(result);
      op.notifyListeners();
    }
    @SuppressWarnings("unchecked")
    private void getRangeOperation(DataStoreOperation op)
        throws UnsupportedEncodingException,
            SQLException { /////////////// POR ISTO EM PARALELO COMO O MULIPUT
      Comparable keyMax = ((GetRangeOperation) op).getMax();
      Comparable keyMin = ((GetRangeOperation) op).getMin();
      String tablename = ((GetRangeOperation) op).getTableName();

      int idMax = this.getTweetID((String) keyMax);
      int idMin = this.getTweetID((String) keyMin);
      String userID = this.getUserID((String) keyMax);

      if (tablename.equals("tweets")) {
        java.sql.Connection conn = null;

        conn = this.borrowClient();
        // String query = "select id,text,date,user from "+tablename+" tweetID between ? AND ?";
        String query = "select id,text,date,user from " + tablename + " where tweetID = ?";
        PreparedStatement stmt = conn.prepareStatement(query);
        ResultSet results = null;
        Set<Map<String, String>> result = new HashSet<Map<String, String>>();
        for (int i = idMin; i <= idMax; i++) {
          try {
            stmt.setString(1, new String(userID + "-" + this.getTweetPadding(i)));
            // System.out.println(stmt.toString());
            results = stmt.executeQuery();

            while (results.next()) {
              Map<String, String> value = new HashMap<String, String>();
              value.put("id", results.getString("id"));
              value.put("text", results.getString("text"));
              value.put("date", results.getString("date"));
              value.put("user", results.getString("user"));
              result.add(value);
            }
          } finally {
            try {
              // stmt.close();
            } catch (Exception e) {
            }
          }
        }
        stmt.close();
        this.releaseClient(conn);
        ((GetRangeOperation) op).setResult(result);
        op.notifyListeners();
      }
    }
    @SuppressWarnings("unchecked")
    private void getTimeLineAndTweetsOperation(DataStoreOperation op)
        throws UnsupportedEncodingException, SQLException {
      java.sql.Connection conn = null;
      String userid = ((GetTimeLineAndTweetsOperation) op).getUserid();
      int start = ((GetTimeLineAndTweetsOperation) op).getStart();
      int count = ((GetTimeLineAndTweetsOperation) op).getCount();
      String tablename = ((GetTimeLineAndTweetsOperation) op).getTableName();

      conn = this.borrowClient();
      String query =
          "select tweets.tweetID,id,text,date,user from (select tweetID from friendsTimeLine where userID = ?) as res inner join tweets on res.tweetID = tweets.tweetID order by date DESC limit ?,? ";
      PreparedStatement stmt = conn.prepareStatement(query);
      ResultSet results = null;
      LinkedHashMap<String, Map<String, String>> result;
      try {
        stmt.setString(1, (String) userid);
        // stmt.setString(2, new String().valueOf(start));
        stmt.setInt(2, start);
        // stmt.setString(3, new String().valueOf(start+count));
        stmt.setInt(3, start + count);
        // System.out.println(start+count);
        // System.out.println("QERy:"+stmt.toString());
        results = stmt.executeQuery();

        result = new LinkedHashMap<String, Map<String, String>>();
        while (results.next()) {
          Map<String, String> value = new HashMap<String, String>();
          value.put("id", results.getString("id"));
          value.put("text", results.getString("text"));
          value.put("date", results.getString("date"));
          value.put("user", results.getString("user"));
          result.put(results.getString("tweetID"), value);
        }
      } finally {
        try {
          stmt.close();
        } catch (Exception e) {
        }
        this.releaseClient(conn);
      }
      ((GetTimeLineAndTweetsOperation) op).setResult(result);
      op.notifyListeners();
    }
    @SuppressWarnings("unchecked")
    private void getOperation(DataStoreOperation op)
        throws UnsupportedEncodingException, SQLException {
      java.sql.Connection conn = null;
      Comparable key = ((GetOperation) op).getKey();
      String tablename = ((GetOperation) op).getTableName();

      if (tablename.equals("friendsTimeLine")) {
        // int count = ((GetOperation) op).getCount();
        conn = this.borrowClient();
        String query = "select tweetID,date from " + tablename + " where userID = ?";
        PreparedStatement stmt = conn.prepareStatement(query);
        ResultSet results = null;
        // Map<String,String> res;
        ArrayList<String> res;
        try {
          stmt.setString(1, (String) key);
          results = stmt.executeQuery();
          // res = new HashMap<String,String>();
          res = new ArrayList<String>();
          while (results.next()) {
            // res.put(results.getString("tweetID"), results.getString("date"));
            res.add(results.getString("tweetID") + ":" + results.getString("date"));
          }
        } finally {
          try {
            stmt.close();
          } catch (Exception e) {
          }
          this.releaseClient(conn);
        }
        ((GetOperation) op).setResult(res);
        op.notifyListeners();
      } else {
        if (tablename.equals("users")) {
          String columns = new String();
          List<String> cols = ((GetOperation) op).getColumns();
          if (cols.isEmpty()) columns = this.userColumns; // /////SE FOR VAZIO TRAZ COLUNAS TODAS
          else columns = this.listToString((ArrayList<String>) cols);
          Map<String, String> value = new HashMap<String, String>();

          String query = "select " + columns + " from " + tablename + " where userID = ?";

          conn = this.borrowClient();
          PreparedStatement stmt = conn.prepareStatement(query);
          ResultSet results = null;
          try {
            stmt.setString(1, (String) key);
            // System.out.println("Query select:"+stmt.toString());
            results = stmt.executeQuery();

            String[] arrStr = columns.split(",");
            int size = arrStr.length;
            while (results.next()) {
              for (int i = 0; i < size; i++) {
                value.put(arrStr[i], results.getString(arrStr[i]));
              }
            }
          } finally {
            try {
              stmt.close();
            } catch (Exception e) {
            }
            this.releaseClient(conn);
          }
          ((GetOperation) op).setResult((Map<String, String>) value);
          op.notifyListeners();
        }
      }
    }