Search in sources :

Example 81 with Timestamp

use of java.sql.Timestamp in project jforum2 by rafaelsteil.

the class GenericSummaryDAO method selectLastPosts.

/**
	 * @see net.jforum.dao.SummaryDAO#selectById(Date, Date)
	 */
public List selectLastPosts(Date firstDate, Date lastDate) {
    String query = SystemGlobals.getSql("SummaryDAO.selectPosts");
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(query);
        p.setTimestamp(1, new Timestamp(firstDate.getTime()));
        p.setTimestamp(2, new Timestamp(lastDate.getTime()));
        List posts = new ArrayList();
        rs = p.executeQuery();
        while (rs.next()) {
            posts.add(this.fillPost(rs));
        }
        return posts;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) Timestamp(java.sql.Timestamp) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 82 with Timestamp

use of java.sql.Timestamp in project jforum2 by rafaelsteil.

the class GenericSummaryDAO method fillPost.

private Post fillPost(ResultSet rs) throws SQLException {
    Post post = new Post();
    post.setId(rs.getInt("post_id"));
    post.setTopicId(rs.getInt("topic_id"));
    post.setForumId(rs.getInt("forum_id"));
    post.setUserId(rs.getInt("user_id"));
    Timestamp postTime = rs.getTimestamp("post_time");
    post.setTime(postTime);
    post.setSubject(rs.getString("post_subject"));
    post.setText(rs.getString("post_text"));
    post.setPostUsername(rs.getString("username"));
    SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
    post.setFormatedTime(df.format(postTime));
    post.setKarma(DataAccessDriver.getInstance().newKarmaDAO().getPostKarma(post.getId()));
    return post;
}
Also used : Post(net.jforum.entities.Post) Timestamp(java.sql.Timestamp) SimpleDateFormat(java.text.SimpleDateFormat)

Example 83 with Timestamp

use of java.sql.Timestamp in project jforum2 by rafaelsteil.

the class GenericTopicDAO method addNew.

/**
	 * @see net.jforum.dao.TopicDAO#addNew(net.jforum.entities.Topic)
	 */
public int addNew(Topic topic) {
    PreparedStatement p = null;
    try {
        p = this.getStatementForAutoKeys("TopicModel.addNew");
        p.setInt(1, topic.getForumId());
        p.setString(2, topic.getTitle());
        p.setInt(3, topic.getPostedBy().getId());
        p.setTimestamp(4, new Timestamp(topic.getTime().getTime()));
        p.setInt(5, topic.getFirstPostId());
        p.setInt(6, topic.getLastPostId());
        p.setInt(7, topic.getType());
        p.setInt(8, topic.isModerated() ? 1 : 0);
        this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("TopicModel.lastGeneratedTopicId"));
        int topicId = this.executeAutoKeysQuery(p);
        topic.setId(topicId);
        return topicId;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 84 with Timestamp

use of java.sql.Timestamp in project jforum2 by rafaelsteil.

the class GenericKarmaDAO method getMostRatedUserByPeriod.

/**
	 * 
	 * @param sql String
	 * @param firstPeriod Date
	 * @param lastPeriod Date
	 * @return List
	 */
protected List getMostRatedUserByPeriod(String sql, Date firstPeriod, Date lastPeriod) {
    if (firstPeriod.after(lastPeriod)) {
        throw new DatabaseException("First Date needs to be before the Last Date");
    }
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(sql);
        p.setTimestamp(1, new Timestamp(firstPeriod.getTime()));
        p.setTimestamp(2, new Timestamp(lastPeriod.getTime()));
        rs = p.executeQuery();
        return this.fillUser(rs);
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException) Timestamp(java.sql.Timestamp)

Example 85 with Timestamp

use of java.sql.Timestamp in project jforum2 by rafaelsteil.

the class GenericPostDAO method addNewPost.

protected void addNewPost(Post post) {
    PreparedStatement p = null;
    try {
        p = this.getStatementForAutoKeys("PostModel.addNewPost");
        p.setInt(1, post.getTopicId());
        p.setInt(2, post.getForumId());
        p.setLong(3, post.getUserId());
        p.setTimestamp(4, new Timestamp(post.getTime().getTime()));
        p.setString(5, post.getUserIp());
        p.setInt(6, post.isBbCodeEnabled() ? 1 : 0);
        p.setInt(7, post.isHtmlEnabled() ? 1 : 0);
        p.setInt(8, post.isSmiliesEnabled() ? 1 : 0);
        p.setInt(9, post.isSignatureEnabled() ? 1 : 0);
        p.setInt(10, post.isModerationNeeded() ? 1 : 0);
        this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("PostModel.lastGeneratedPostId"));
        int postId = this.executeAutoKeysQuery(p);
        post.setId(postId);
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) DatabaseException(net.jforum.exceptions.DatabaseException)

Aggregations

Timestamp (java.sql.Timestamp)1539 PreparedStatement (java.sql.PreparedStatement)265 Test (org.junit.Test)245 SQLException (java.sql.SQLException)236 ResultSet (java.sql.ResultSet)209 BigDecimal (java.math.BigDecimal)204 Date (java.util.Date)165 Date (java.sql.Date)122 Connection (java.sql.Connection)117 ArrayList (java.util.ArrayList)109 Calendar (java.util.Calendar)76 Test (org.testng.annotations.Test)71 GregorianCalendar (java.util.GregorianCalendar)68 Time (java.sql.Time)65 SimpleDateFormat (java.text.SimpleDateFormat)62 Change (com.google.gerrit.reviewdb.client.Change)59 IOException (java.io.IOException)51 BaseTest (util.BaseTest)49 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)45 Properties (java.util.Properties)41