use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericTopicDAO method getMaxPostId.
/**
* @see net.jforum.dao.TopicDAO#autoSetLastPostId(int)
*/
public int getMaxPostId(int topicId) {
int id = -1;
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.getMaxPostId"));
p.setInt(1, topicId);
rs = p.executeQuery();
if (rs.next()) {
id = rs.getInt("post_id");
}
return id;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericTopicDAO method newMessages.
private List newMessages(List topicIds) {
if (topicIds.size() == 0) {
return new ArrayList();
}
PreparedStatement p = null;
try {
String sql = SystemGlobals.getSql("TopicModel.selectForNewMessages");
StringBuffer sb = new StringBuffer();
for (Iterator iter = topicIds.iterator(); iter.hasNext(); ) {
sb.append(iter.next()).append(',');
}
sb.append("-1");
sql = sql.replaceAll(":topicIds:", sb.toString());
p = JForumExecutionContext.getConnection().prepareStatement(sql);
return this.fillTopicsData(p);
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericTopicDAO method deleteByForum.
/**
* @see net.jforum.dao.TopicDAO#deleteByForum(int)
*/
public void deleteByForum(int forumId) {
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.deleteByForum"));
p.setInt(1, forumId);
rs = p.executeQuery();
List topics = new ArrayList();
while (rs.next()) {
Topic t = new Topic();
t.setId(rs.getInt("topic_id"));
t.setForumId(forumId);
topics.add(t);
}
this.deleteTopics(topics, false);
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericTopicDAO method selectTopicTitlesByIds.
/**
* @see net.jforum.dao.TopicDAO#selectTopicTitlesByIds(java.util.Collection)
*/
public List selectTopicTitlesByIds(Collection idList) {
List l = new ArrayList();
String sql = SystemGlobals.getSql("TopicModel.selectTopicTitlesByIds");
StringBuffer sb = new StringBuffer(idList.size() * 2);
for (Iterator iter = idList.iterator(); iter.hasNext(); ) {
sb.append(iter.next()).append(",");
}
int len = sb.length();
sql = sql.replaceAll(":ids:", len > 0 ? sb.toString().substring(0, len - 1) : "0");
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(sql);
rs = p.executeQuery();
while (rs.next()) {
Map m = new HashMap();
m.put("id", new Integer(rs.getInt("topic_id")));
m.put("title", rs.getString("topic_title"));
l.add(m);
}
return l;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
use of net.jforum.exceptions.DatabaseException 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);
}
}
Aggregations