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);
}
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations