public Post updatePost ( Post post , final TimeZone tz ) throws SQLException { if ( post . id < 1L ) { throw new SQLException ( "The post id must be specified for update" ) ; } if ( post . modifiedTimestamp < 1 ) { post = post . modifiedNow ( ) ; } int offset = tz . getOffset ( post . publishTimestamp ) ; Connection conn = null ; PreparedStatement stmt = null ; Timer . Context ctx = metrics . updatePostTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( updatePostSQL ) ; stmt . setLong ( 1 , post . authorId ) ; stmt . setTimestamp ( 2 , new Timestamp ( post . publishTimestamp ) ) ; stmt . setTimestamp ( 3 , new Timestamp ( post . publishTimestamp - offset ) ) ; stmt . setString ( 4 , Strings . nullToEmpty ( post . content ) ) ; stmt . setString ( 5 , Strings . nullToEmpty ( post . title ) ) ; stmt . setString ( 6 , Strings . nullToEmpty ( post . excerpt ) ) ; stmt . setString ( 7 , post . status . toString ( ) . toLowerCase ( ) ) ; stmt . setString ( 8 , Strings . nullToEmpty ( post . slug ) ) ; stmt . setTimestamp ( 9 , new Timestamp ( post . modifiedTimestamp ) ) ; stmt . setTimestamp ( 10 , new Timestamp ( post . modifiedTimestamp - offset ) ) ; stmt . setLong ( 11 , post . parentId ) ; stmt . setString ( 12 , Strings . nullToEmpty ( post . guid ) ) ; stmt . setString ( 13 , post . type . toString ( ) . toLowerCase ( ) ) ; stmt . setString ( 14 , post . mimeType != null ? post . mimeType : "" ) ; stmt . setLong ( 15 , post . id ) ; stmt . executeUpdate ( ) ; return post ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt ) ; } }
Updates a post .