public Map < Long , Post > selectPostMap ( final Collection < Long > postIds , final boolean withResolve ) throws SQLException { Map < Long , Post > postMap = Maps . newHashMapWithExpectedSize ( postIds . size ( ) ) ; Connection conn = null ; Statement stmt = null ; ResultSet rs = null ; Timer . Context ctx = metrics . selectPostMapTimer . time ( ) ; StringBuilder sql = new StringBuilder ( selectPostSQL ) . append ( postsTableName ) . append ( " WHERE ID IN (" ) ; sql . append ( inJoiner . join ( postIds ) ) ; sql . append ( ")" ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . createStatement ( ) ; rs = stmt . executeQuery ( sql . toString ( ) ) ; while ( rs . next ( ) ) { Post . Builder post = postFromResultSet ( rs ) ; postMap . put ( post . getId ( ) , withResolve ? resolve ( post ) . build ( ) : post . build ( ) ) ; } return postMap ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt , rs ) ; } }
Selects posts from a collection of ids into a map .