Esempio n. 1
0
  public Comments getComments(final Context ctx, String[] expCols, final long... commentIds) {

    final Comments commentList = new Comments();

    GroupedShardResults groupedPropSR = shardComment(commentIds);
    for (final ShardResult propSR : groupedPropSR.getShardResults()) {
      sqlExecutor.openConnection(
          propSR.db,
          new SingleConnectionHandler<List<Comment>>() {
            @Override
            protected List<Comment> handleConnection(Connection conn) {
              String sql = CommentSql.getComments(propSR.table, commentIds);
              SqlExecutor.executeList(
                  ctx,
                  conn,
                  sql,
                  commentList,
                  new ResultSetReader<Comment>() {
                    @Override
                    public Comment read(ResultSet rs, Comment reuse) throws SQLException {
                      return CommentRs.readComment(rs, null);
                    }
                  });
              return commentList;
            }
          });
    }
    return commentList;
  }
Esempio n. 2
0
  public Map<Target, Integer> getCommentCounts(final Context ctx, final Target... targets) {
    String[] strings = new String[targets.length];
    int i = 0;
    for (Target target : targets) {
      strings[i++] = target.id;
    }
    final Map<Target, Integer> map = new HashMap<Target, Integer>();
    GroupedShardResults groupedPropSR = shardCommentTarget(strings);

    for (final ShardResult propSR : groupedPropSR.getShardResults()) {
      // final long[] commentIdsInShard = CollectionsHelper.toLongArray(groupedPropSR.get(propSR));
      sqlExecutor.openConnection(
          propSR.db,
          new SingleConnectionHandler<Map<Target, Integer>>() {
            @Override
            protected Map<Target, Integer> handleConnection(Connection conn) {
              for (Target target : targets) {
                String sql = CommentSql.getCommentCount(propSR.table, target);
                map.put(target, (int) SqlExecutor.executeInt(ctx, conn, sql, 0));
              }
              return map;
            }
          });
    }
    return map;
  }
Esempio n. 3
0
  public Map<Target, long[]> getCommentsOnTarget(
      final Context ctx, final Page page, final Target... targets) {
    String[] strings = new String[targets.length];
    int i = 0;
    for (Target target : targets) {
      strings[i++] = target.id;
    }

    final Map<Target, long[]> map = new HashMap<Target, long[]>();
    GroupedShardResults groupedPropSR = shardComment(strings);

    for (final ShardResult propSR : groupedPropSR.getShardResults()) {
      sqlExecutor.openConnection(
          propSR.db,
          new SingleConnectionHandler<Map<Target, long[]>>() {
            @Override
            protected Map<Target, long[]> handleConnection(Connection conn) {
              for (Target target : targets) {
                final HashSet<Long> existsIds = new HashSet<Long>();
                String sql = CommentSql.getCommentsOnTarget(propSR.table, target, page);
                SqlExecutor.executeCustom(
                    ctx,
                    conn,
                    sql,
                    new ResultSetHandler() {
                      @Override
                      public void handle(ResultSet rs) throws SQLException {
                        CommentRs.readIds(rs, existsIds);
                      }
                    });
                long[] ids = CollectionsHelper.toLongArray(existsIds);
                map.put(target, ids);
              }
              return map;
            }
          });
    }
    return map;
  }