public boolean addPostTerm ( final long postId , final TaxonomyTerm taxonomyTerm ) throws SQLException { List < TaxonomyTerm > currTerms = selectPostTerms ( postId , taxonomyTerm . taxonomy ) ; for ( TaxonomyTerm currTerm : currTerms ) { if ( currTerm . term . name . equals ( taxonomyTerm . term . name ) ) { return false ; } } Connection conn = null ; PreparedStatement stmt = null ; Timer . Context ctx = metrics . postTermsSetTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( insertPostTermSQL ) ; stmt . setLong ( 1 , postId ) ; stmt . setLong ( 2 , taxonomyTerm . id ) ; stmt . setInt ( 3 , currTerms . size ( ) ) ; //Add at the last position... return stmt . executeUpdate ( ) > 0 ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt ) ; } }
Adds a term at the end of the current terms if it does not already exist .