示例#1
0
 @Override
 protected PreparedStatement getDeleteStatement(Vote vote) throws SQLException {
   PreparedStatement statement = getConnection().prepareStatement(DELETE_QUERY);
   try {
     statement.setLong(1, vote.getId());
     return statement;
   } catch (SQLException e) {
     statement.close();
     throw e;
   }
 }
示例#2
0
 @Override
 protected PreparedStatement getUpdateStatement(Vote vote) throws SQLException {
   validate(vote);
   PreparedStatement statement = getConnection().prepareStatement(UPDATE_QUERY);
   try {
     User author = vote.getAuthor();
     if (author == null) {
       statement.setNull(1, Types.INTEGER);
     } else {
       statement.setLong(1, author.getId());
     }
     statement.setLong(2, vote.getAnswer().getId());
     statement.setTimestamp(3, DatabaseUtil.dateToTimestamp(vote.getCreationDate()));
     statement.setLong(4, vote.getId());
     return statement;
   } catch (SQLException e) {
     statement.close();
     throw e;
   }
 }