📄 forumdao.java
字号:
* DOCUMENT ME!
*
* @param userStatus
* DOCUMENT ME!
* @param messages
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*
* @throws SQLException
* DOCUMENT ME!
*/
public ArrayList getGroups(int userStatus, MessageResources messages)
throws NumberFormatException, SQLException, ConfiguratorException {
return getGroups(userStatus, true);
}
/**
* DOCUMENT ME!
*
* @param userStatus
* DOCUMENT ME!
* @param messages
* DOCUMENT ME!
* @param filled
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*
* @throws SQLException
* DOCUMENT ME!
*/
public ArrayList getGroups(int userStatus, boolean filled)
throws NumberFormatException, SQLException, ConfiguratorException {
Connection connection = this.dataSource.getConnection();
PreparedStatement st = connection.prepareStatement(dbDriver
.getQueries().getForumQueries().getSql_GET_GROUPS());
ResultSet rs = null;
try {
ArrayList groups = new ArrayList();
rs = (ResultSet) st.executeQuery();
while (rs.next()) {
Group gr = new Group();
gr.setGroupid(rs.getInt("groupid"));
gr.setName(rs.getString("group_name"));
getForums(gr, userStatus, filled);
groups.add(gr);
}
return groups;
} finally {
if (rs != null) {
rs.close();
}
st.close();
connection.close();
}
}
/**
* Returns java.util.List collection populated with
* org.jresearch.gossip.beans.forum.LastTopic objects.
*
* @param maxCount
* @param since
*
* @return
* @throws SQLException
* @throws IllegalArgumentException
* DOCUMENT ME!
*/
public List getLastTopics(int maxCount, Date since) throws SQLException {
if (null == since) { throw new IllegalArgumentException(); }
java.sql.Date dateSince = new java.sql.Date(since.getTime());
ArrayList topics = new ArrayList();
Connection connection = this.dataSource.getConnection();
PreparedStatement st = connection.prepareStatement(dbDriver
.getQueries().getForumQueries().getSql_GET_LAST_TOPICS());
PreparedStatement st2 = connection.prepareStatement(dbDriver
.getQueries().getForumQueries().getSql_GET_ROOT_MESS());
ResultSet rs = null;
try {
st.setTimestamp(1, new Timestamp(dateSince.getTime()));
st.setInt(2, maxCount);
rs = (ResultSet) st.executeQuery();
while (rs.next()) {
LastTopic topic = new LastTopic();
topic.setForumid(rs.getInt("fid"));
topic.setThreadid(rs.getInt("tid"));
topic.setLocked(rs.getInt("locked"));
topic.setSortby(rs.getInt("sortby"));
topic.setMessagesCount(rs.getLong("tot_mes"));
topic.setForumName(rs.getString("forumtitle"));
setRootMessage(topic, st2);
topics.add(topic);
}
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
}
}
st2.close();
st.close();
connection.close();
}
return topics;
}
/**
* Returns java.util.List collection populated with
* org.jresearch.gossip.beans.forum.NewTopic objects.
*
* @param fid
* @param maxCount
* @param since
*
* @return DOCUMENT ME!
*
* @throws SQLException
* @throws IllegalArgumentException
* DOCUMENT ME!
*/
public List getLastTopics(int fid, int maxCount, Date since)
throws SQLException {
if (null == since) { throw new IllegalArgumentException(); }
java.sql.Date dateSince = new java.sql.Date(since.getTime());
ArrayList topics = new ArrayList();
Connection connection = this.dataSource.getConnection();
PreparedStatement st = connection.prepareStatement(dbDriver
.getQueries().getForumQueries()
.getSql_GET_LAST_TOPICS_IN_FORUM());
PreparedStatement st2 = connection.prepareStatement(dbDriver
.getQueries().getForumQueries().getSql_GET_ROOT_MESS());
ResultSet rs = null;
try {
st.setInt(1, fid);
st.setTimestamp(2, new Timestamp(dateSince.getTime()));
st.setInt(3, maxCount);
rs = (ResultSet) st.executeQuery();
while (rs.next()) {
LastTopic topic = new LastTopic();
topic.setForumid(rs.getInt("fid"));
topic.setThreadid(rs.getInt("tid"));
topic.setLocked(rs.getInt("locked"));
topic.setMessagesCount(rs.getLong("tot_mes"));
topic.setForumName(rs.getString("forumtitle"));
setRootMessage(topic, st2);
topics.add(topic);
}
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
}
}
st2.close();
st.close();
connection.close();
}
return topics;
}
/**
* DOCUMENT ME!
*
* @param mid
*
* @return
* @throws SQLException
* DOCUMENT ME!
*/
public Message getMessage(String mid) throws SQLException {
Connection connection = this.dataSource.getConnection();
PreparedStatement st = connection.prepareStatement(dbDriver
.getQueries().getForumQueries().getSql_GET_MESSAGE());
Message mess = null;
ResultSet rs = null;
try {
st.setInt(1, Integer.parseInt(mid));
rs = st.executeQuery();
if (rs.next()) {
mess = new Message();
mess.setCentents(rs.getString("centents"));
mess.setHeading(rs.getString("heading"));
mess.setId(rs.getInt("id"));
mess.setIntime(rs.getDate("intime"));
mess.setIp(rs.getString("ip"));
mess.setSender(rs.getString("sender"));
}
} finally {
if (rs != null) {
rs.close();
}
st.close();
connection.close();
}
return mess;
}
/**
* DOCUMENT ME!
*
* @param uid
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*
* @throws SQLException
* DOCUMENT ME!
*/
public int getMessCount(String uid) throws SQLException {
Connection connection = this.dataSource.getConnection();
PreparedStatement st = connection.prepareStatement(dbDriver
.getQueries().getForumQueries().getSql_GET_USER_MESS_COUNT());
ResultSet rs = null;
int count = 0;
try {
st.setString(1, uid);
rs = st.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
} finally {
if (rs != null) {
rs.close();
}
st.close();
connection.close();
}
return count;
}
/**
* DOCUMENT ME!
*
* @param tid
*
* @return
* @throws SQLException
* DOCUMENT ME!
*/
public Topic getThreadInfo(int tid) throws SQLException {
Connection connection = this.dataSource.getConnection();
PreparedStatement st = connection.prepareStatement(dbDriver
.getQueries().getForumQueries().getSql_THREAD_INFO());
ResultSet rs = null;
Topic _thread = new Topic();
try {
st.setInt(1, tid);
rs = (ResultSet) st.executeQuery();
if (rs.next()) {
_thread.setLocked(rs.getInt("locked"));
}
return _thread;
} finally {
if (rs != null) {
rs.close();
}
st.close();
connection.close();
}
}
/**
* DOCUMENT ME!
*
* @param tid
*
* @return
* @throws SQLException
* DOCUMENT ME!
*/
public String getThreadSubject(String tid) throws SQLException {
Connection connection = this.dataSource.getConnection();
PreparedStatement st = connection.prepareStatement(dbDriver
.getQueries().getForumQueries().getSql_GET_THREAD_SUBJ());
ResultSet rs = null;
String subject = "";
try {
st.setInt(1, Integer.parseInt(tid));
rs = st.executeQuery();
if (rs.next()) {
subject = rs.getString(1);
}
} finally {
if (rs != null) {
rs.close();
}
st.close();
connection.close();
}
return subject;
}
/**
* DOCUMENT ME!
*
* @param login
*
* @return
* @throws SQLException
* DOCUMENT ME!
*/
public ArrayList getUserModForums(String login) throws SQLException {
Connection connection = this.dataSource.getConnection();
PreparedStatement st = connection.prepareStatement(dbDriver
.getQueries().getForumQueries().getSql_GET_USER_MOD_FORUMS());
ResultSet rs = null;
ArrayList userModForums = new ArrayList();
try {
st.setString(1, login);
rs = st.executeQuery();
while (rs.next()) {
Forum f = new Forum();
f.setForumid(rs.getInt("forumid"));
f.setTitle(rs.getString("forumtitle"));
userModForums.add(f);
}
} finally {
if (rs != null) {
rs.close();
}
st.close();
connection.close();
}
return userModForums;
}
/**
* DOCUMENT ME!
*
* @param fid
* DOCUMENT ME!
*
* @return
* @throws SQLException
* DOCUMENT ME!
*/
public String insertNewThread(String fid) throws SQLException {
Connection connection = this.dataSource.getConnection();
PreparedStatement st = connection.prepareStatement(dbDriver
.getQueries().getForumQueries().getSql_INSERT_THREAD());
try {
int tid = ((Integer) keyGen
.generateKey(
IKeyGenConst.KEY_NAMES[IKeyGenConst.KEY_THREAD],
connection)).intValue();
st.setInt(1, Integer.parseInt(fid));
st.setInt(2, tid);
st.execute();
return String.valueOf(tid);
} finally {
st.close();
connection.close();
}
}
/**
* DOCUMENT ME!
*
* @param uid
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*
* @throws SQLException
* DOCUMENT ME!
*/
public boolean isUserMod(String uid) throws SQLException {
Connection connection = this.dataSource.getConnection();
PreparedStatement st = connection.prepareStatement(dbDriver
.getQueries().getForumQueries().getSql_IS_USER_MOD());
ResultSet rs = null;
boolean modFlag = false;
try {
st.setString(1, uid);
rs = st.executeQuery();
modFlag = rs.next();
} finally {
if (rs != null) {
rs.close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -