Search in sources :

Example 1 with PollOption

use of net.jforum.entities.PollOption in project jforum2 by rafaelsteil.

the class GenericPollDAO method updatePollOptions.

protected void updatePollOptions(int pollId, List options) throws SQLException {
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PollModel.updatePollOption"));
        for (Iterator iter = options.iterator(); iter.hasNext(); ) {
            PollOption o = (PollOption) iter.next();
            p.setString(1, o.getText());
            p.setInt(2, o.getId());
            p.setInt(3, pollId);
            p.executeUpdate();
        }
    } finally {
        DbUtils.close(p);
    }
}
Also used : Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) PollOption(net.jforum.entities.PollOption)

Example 2 with PollOption

use of net.jforum.entities.PollOption in project jforum2 by rafaelsteil.

the class GenericPollDAO method makePollOption.

protected PollOption makePollOption(ResultSet rs) throws SQLException {
    PollOption option = new PollOption();
    option.setPollId(rs.getInt("vote_id"));
    option.setId(rs.getInt("vote_option_id"));
    option.setText(rs.getString("vote_option_text"));
    option.setVoteCount(rs.getInt("vote_result"));
    return option;
}
Also used : PollOption(net.jforum.entities.PollOption)

Example 3 with PollOption

use of net.jforum.entities.PollOption in project jforum2 by rafaelsteil.

the class PollCommon method fillPollFromRequest.

public static Poll fillPollFromRequest() {
    RequestContext request = JForumExecutionContext.getRequest();
    String label = request.getParameter("poll_label");
    if (label == null || label.length() == 0) {
        return null;
    }
    Poll poll = new Poll();
    poll.setStartTime(new Date());
    poll.setLabel(label);
    int count = request.getIntParameter("poll_option_count");
    for (int i = 0; i <= count; i++) {
        String option = request.getParameter("poll_option_" + i);
        if (option == null) {
            continue;
        }
        option = option.trim();
        if (option.length() > 0) {
            PollOption po = new PollOption();
            po.setId(i);
            po.setText(option);
            poll.addOption(po);
        }
    }
    String pollLength = request.getParameter("poll_length");
    if (pollLength != null && pollLength.length() > 0) {
        poll.setLength(Integer.parseInt(pollLength));
    }
    return poll;
}
Also used : Poll(net.jforum.entities.Poll) PollOption(net.jforum.entities.PollOption) RequestContext(net.jforum.context.RequestContext) Date(java.util.Date)

Example 4 with PollOption

use of net.jforum.entities.PollOption in project jforum2 by rafaelsteil.

the class GenericPollDAO method addNewPollOptions.

protected void addNewPollOptions(int pollId, List options) {
    Connection connection = JForumExecutionContext.getConnection();
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = connection.prepareStatement(SystemGlobals.getSql("PollModel.selectMaxVoteId"));
        p.setInt(1, pollId);
        rs = p.executeQuery();
        rs.next();
        int optionId = rs.getInt(1);
        rs.close();
        rs = null;
        p.close();
        p = null;
        p = connection.prepareStatement(SystemGlobals.getSql("PollModel.addNewPollOption"));
        for (Iterator iter = options.iterator(); iter.hasNext(); ) {
            PollOption option = (PollOption) iter.next();
            p.setInt(1, pollId);
            p.setInt(2, ++optionId);
            p.setString(3, option.getText());
            p.executeUpdate();
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) PollOption(net.jforum.entities.PollOption) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 5 with PollOption

use of net.jforum.entities.PollOption in project jforum2 by rafaelsteil.

the class GenericPollDAO method deletePollOptions.

protected void deletePollOptions(int pollId, List deleted) throws SQLException {
    Connection connection = JForumExecutionContext.getConnection();
    PreparedStatement options = null;
    try {
        options = connection.prepareStatement(SystemGlobals.getSql("PollModel.deletePollOption"));
        for (Iterator iter = deleted.iterator(); iter.hasNext(); ) {
            PollOption o = (PollOption) iter.next();
            // Option
            options.setInt(1, pollId);
            options.setInt(2, o.getId());
            options.executeUpdate();
        }
    } finally {
        DbUtils.close(options);
    }
}
Also used : Connection(java.sql.Connection) Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) PollOption(net.jforum.entities.PollOption)

Aggregations

PollOption (net.jforum.entities.PollOption)5 PreparedStatement (java.sql.PreparedStatement)3 Iterator (java.util.Iterator)3 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 RequestContext (net.jforum.context.RequestContext)1 Poll (net.jforum.entities.Poll)1 DatabaseException (net.jforum.exceptions.DatabaseException)1