public List < Post > selectAuthorPosts ( final long userId , final Post . Sort sort , final Paging paging , final boolean withResolve ) throws SQLException { if ( paging . limit < 1 || paging . start < 0 ) { return ImmutableList . of ( ) ; } List < Post . Builder > builders = Lists . newArrayListWithExpectedSize ( paging . limit < 1024 ? paging . limit : 1024 ) ; StringBuilder sql = new StringBuilder ( selectPostSQL ) ; sql . append ( postsTableName ) ; sql . append ( " WHERE post_author=?" ) ; appendPagingSortSQL ( sql , sort , paging ) ; Connection conn = null ; PreparedStatement stmt = null ; ResultSet rs = null ; Timer . Context ctx = metrics . selectAuthorPostsTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( sql . toString ( ) ) ; stmt . setLong ( 1 , userId ) ; if ( paging . interval != null ) { stmt . setTimestamp ( 2 , new Timestamp ( paging . interval . getStartMillis ( ) ) ) ; stmt . setTimestamp ( 3 , new Timestamp ( paging . interval . getStartMillis ( ) ) ) ; stmt . setInt ( 4 , paging . start ) ; stmt . setInt ( 5 , paging . limit ) ; } else { stmt . setInt ( 2 , paging . start ) ; stmt . setInt ( 3 , paging . limit ) ; } rs = stmt . executeQuery ( ) ; while ( rs . next ( ) ) { builders . add ( postFromResultSet ( rs ) ) ; } } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt , rs ) ; } List < Post > posts = Lists . newArrayListWithExpectedSize ( builders . size ( ) ) ; for ( Post . Builder builder : builders ) { if ( withResolve ) { posts . add ( resolve ( builder ) . build ( ) ) ; } else { posts . add ( builder . build ( ) ) ; } } return posts ; }
Selects a page of posts for an author .