⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forumdao.java

📁 jGossip是一个简单而功能强大的Java论坛软件(消息板)
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @throws SQLException
     *             DOCUMENT ME!
     */
    public void deleteMessage(ProcessMessageForm form) throws SQLException {
        Connection connection = this.dataSource.getConnection();
        PreparedStatement st = connection.prepareStatement(dbDriver
                .getQueries().getForumQueries().getSql_DELETE_MESSAGE());
        ResultSet rs = null;

        try {
            //			delete the message...
            st.setInt(1, Integer.parseInt(form.getMid()));
            st.execute();

            st = connection.prepareStatement(dbDriver.getQueries()
                    .getForumQueries().getSql_GET_THREAD_LAST_INTIME());
            st.setInt(1, Integer.parseInt(form.getTid()));
            rs = st.executeQuery();

            if (rs.next()) {
                updateThreadIntime(form.getTid(), rs.getTimestamp(1));
            } else { //erase thread if this is the last message in thread...
                deleteThread(form.getTid());
            }
        } finally {
            if (rs != null) {
                rs.close();
            }

            st.close();
            connection.close();
        }
    }

    /**
     * DOCUMENT ME!
     * 
     * @param tid
     * 
     * @throws SQLException
     *             DOCUMENT ME!
     */
    public void deleteThread(String tid) throws SQLException {
        deleteThread(tid, false);
    }

    /**
     * DOCUMENT ME!
     * 
     * @param tid
     *            DOCUMENT ME!
     * @param clear
     *            DOCUMENT ME!
     * 
     * @throws SQLException
     *             DOCUMENT ME!
     */
    public void deleteThread(String tid, boolean clear) throws SQLException {
        Connection connection = this.dataSource.getConnection();
        int id = Integer.parseInt(tid);
        PreparedStatement st = connection.prepareStatement(dbDriver
                .getQueries().getForumQueries().getSql_DELETE_THREAD());

        try {
            st.setInt(1, id);
            st.execute();

            if (clear) { //DELETE ALL MESSAGES FROM THREAD
                st = connection.prepareStatement(dbDriver.getQueries()
                        .getForumQueries().getSql_DELETE_THREAD_MESSAGES());
                st.setInt(1, id);
                st.execute();
            }

            st = connection.prepareStatement(dbDriver.getQueries()
                    .getForumQueries().getSql_DELETE_THREAD_SUBSCRIPTIONS());
            st.setInt(1, id);
            st.execute();
        } finally {
            st.close();
            connection.close();
        }
    }

    /**
     * DOCUMENT ME!
     * 
     * @param fid
     * @param uid
     * 
     * @throws SQLException
     *             DOCUMENT ME!
     */
    public void dropMod(String fid, String uid) throws SQLException {
        Connection connection = this.dataSource.getConnection();
        String queryString = (dbDriver.getQueries().getForumQueries()
                .getSql_DROP_USER_MOD());
        PreparedStatement st = connection.prepareStatement(queryString);

        try {
            st.setString(1, uid);
            st.setInt(2, Integer.parseInt(fid));
            st.execute();
        } finally {
            st.close();
            connection.close();
        }
    }

    /**
     * DOCUMENT ME!
     * 
     * @param user
     * @param recordsData
     * @param form
     * 
     * @throws InstantiationException
     *             DOCUMENT ME!
     * @throws IllegalAccessException
     *             DOCUMENT ME!
     * @throws InvocationTargetException
     *             DOCUMENT ME!
     * @throws NoSuchMethodException
     *             DOCUMENT ME!
     * @throws SQLException
     *             DOCUMENT ME!
     */
    public void fillMessagesList(User user, RecordsData recordsData,
            ProcessTopicForm form) throws InstantiationException,
            IllegalAccessException, InvocationTargetException,
            NoSuchMethodException, SQLException {
        Connection connection = this.dataSource.getConnection();
        PreparedStatement st = connection.prepareStatement(dbDriver
                .getQueries().getForumQueries().getSql_GET_THREAD_MESSAGES());
        ResultSet rs = null;

        try {
            int currBlock = Integer.parseInt(form.getBlock());
            int tid = Integer.parseInt(form.getTid());
            st.setInt(1, tid);
            st.setInt(2, currBlock);
            st.setInt(3, user.getSettings().getMes_per_page());
            rs = (ResultSet) st.executeQuery();
            recordsData.fillRecords(rs, Mapping.getInstance().MessageMapping,
                    Message.class);
            recordsData.setBlockSize(user.getSettings().getMes_per_page());
            recordsData.setCurrBlock(currBlock);
            recordsData.setRecordsCount(countThreadMessages(tid));
        } finally {
            if (rs != null) {
                rs.close();
            }

            st.close();
            connection.close();
        }
    }

    /**
     * DOCUMENT ME!
     * 
     * @param user
     * @param recordsData
     * @param form
     * 
     * @throws InstantiationException
     *             DOCUMENT ME!
     * @throws IllegalAccessException
     *             DOCUMENT ME!
     * @throws InvocationTargetException
     *             DOCUMENT ME!
     * @throws NoSuchMethodException
     *             DOCUMENT ME!
     * @throws SQLException
     *             DOCUMENT ME!
     */
    public void fillThreadList(User user, RecordsData recordsData,
            ProcessForumForm form) throws InstantiationException,
            IllegalAccessException, InvocationTargetException,
            NoSuchMethodException, SQLException {
        Connection connection = this.dataSource.getConnection();
        PreparedStatement st = connection.prepareStatement(dbDriver
                .getQueries().getForumQueries().getSql_GET_THREADS());
        ResultSet rs = null;

        try {
            int currBlock = Integer.parseInt(form.getBlock());
            st.setInt(1, Integer.parseInt(form.getFid()));
            st.setInt(2, currBlock);
            st.setInt(3, user.getSettings().getMes_per_page());
            rs = (ResultSet) st.executeQuery();
            recordsData.fillRecords(rs, Mapping.getInstance().TreadMapping,
                    Topic.class);

            Iterator it = recordsData.getRecords().iterator();
            st = connection.prepareStatement(dbDriver.getQueries()
                    .getForumQueries().getSql_GET_THREAD_LAST_MESS());

            while (it.hasNext()) {
                setLastMessage((Topic) it.next(), st);
            }

            st = connection.prepareStatement(dbDriver.getQueries()
                    .getForumQueries().getSql_COUNT_THREADS());
            recordsData.setRecordsCount(countForumTopics(Integer.parseInt(form
                    .getFid()), st));
            recordsData.setBlockSize(user.getSettings().getMes_per_page());

            recordsData.setCurrBlock(currBlock);
        } finally {
            if (rs != null) {
                rs.close();
            }

            st.close();
            connection.close();
        }
    }

    /**
     * DOCUMENT ME!
     * 
     * @param forumid
     *            DOCUMENT ME!
     * 
     * @return DOCUMENT ME!
     * 
     * @throws SQLException
     *             DOCUMENT ME!
     */
    public Forum getForumInfo(int forumid) throws SQLException {
        Connection connection = this.dataSource.getConnection();
        PreparedStatement st = connection.prepareStatement(dbDriver
                .getQueries().getForumQueries().getSql_FORUM_INFO());
        ResultSet rs = null;
        Forum _forum = new Forum();

        try {
            st.setInt(1, forumid);
            rs = (ResultSet) st.executeQuery();

            if (rs.next()) {
                _forum.setLocked(rs.getInt("locked"));
                _forum.setTitle(rs.getString("forumtitle"));
                _forum.setDescription(rs.getString("forumdesc"));
                _forum.setSort(rs.getString("forum_sort"));
                _forum.setGroupid(rs.getInt("groupid"));
            }

            return _forum;
        } finally {
            if (rs != null) {
                rs.close();
            }

            st.close();
            connection.close();
        }
    }

    /**
     * DOCUMENT ME!
     * 
     * @param group
     *            DOCUMENT ME!
     * @param userStatus
     *            DOCUMENT ME!
     * @param messages
     *            DOCUMENT ME!
     * 
     * @throws SQLException
     *             DOCUMENT ME!
     */
    public void getForums(Group group, int userStatus)
            throws NumberFormatException, SQLException, ConfiguratorException {
        getForums(group, userStatus, true);
    }

    /**
     * DOCUMENT ME!
     * 
     * @param group
     *            DOCUMENT ME!
     * @param userStatus
     *            DOCUMENT ME!
     * @param messages
     *            DOCUMENT ME!
     * @param filled
     *            DOCUMENT ME!
     * 
     * @throws SQLException
     *             DOCUMENT ME!
     */
    public void getForums(Group group, int userStatus, boolean filled)
            throws SQLException, NumberFormatException, ConfiguratorException {
        String queryString = ((userStatus < Integer.parseInt(Configurator
                .getInstance().get(IConst.CONFIG.INVADER1))) ? dbDriver
                .getQueries().getForumQueries().getSql_GET_FORUMS() : dbDriver
                .getQueries().getForumQueries().getSql_GET_ALL_FORUMS());
        Connection connection = this.dataSource.getConnection();
        PreparedStatement st = connection.prepareStatement(queryString);
        PreparedStatement st2 = connection.prepareStatement(dbDriver
                .getQueries().getForumQueries().getSql_GET_LAST_MESS());
        PreparedStatement st3 = connection.prepareStatement(dbDriver
                .getQueries().getForumQueries().getSql_COUNT_THREADS());
        ResultSet rs = null;

        try {
            st.setInt(1, group.getGroupid());
            rs = (ResultSet) st.executeQuery();

            while (rs.next()) {
                Forum forum = new Forum();
                forum.setDescription(rs.getString("forumdesc"));
                forum.setForumid(rs.getInt("forumid"));
                forum.setLocked(rs.getInt("locked"));
                forum.setTitle(rs.getString("forumtitle"));

                if (filled) {
                    forum.setThreadsCount(countForumTopics(forum.getForumid(),
                            st3));
                    setLastMessage(forum, st2);
                }

                group.addForum(forum);
            }
        } finally {
            if (rs != null) {
                rs.close();
            }

            st3.close();
            st2.close();
            st.close();
            connection.close();
        }
    }

    /**
     * DOCUMENT ME!
     * 
     * @return 
     * @throws SQLException
     *             DOCUMENT ME!
     */
    public ArrayList getForumsForMod() throws SQLException {
        Connection connection = this.dataSource.getConnection();
        PreparedStatement st = connection.prepareStatement(dbDriver
                .getQueries().getForumQueries().getSql_GET_FORUMS_FOR_MOD());
        ResultSet rs = null;
        ArrayList forumsForMod = new ArrayList();

        try {
            rs = st.executeQuery();

            int gid = -1;

            while (rs.next()) {
                if (rs.getInt("gid") != gid) {
                    gid = rs.getInt("gid");

                    Forum f = new Forum();
                    f.setTitle(IConst.JSP.OPTIONS_SEPERATOR);
                    forumsForMod.add(f);
                }

                Forum f = new Forum();
                f.setForumid(rs.getInt("fid"));
                f.setTitle(rs.getString("forumtitle"));
                forumsForMod.add(f);
            }
        } finally {
            if (rs != null) {
                rs.close();
            }

            st.close();
            connection.close();
        }

        return forumsForMod;
    }

    /**
     * DOCUMENT ME!
     * 
     * @param recordsData
     * 
     * @throws InstantiationException
     *             DOCUMENT ME!
     * @throws IllegalAccessException
     *             DOCUMENT ME!
     * @throws InvocationTargetException
     *             DOCUMENT ME!
     * @throws NoSuchMethodException
     *             DOCUMENT ME!
     * @throws SQLException
     *             DOCUMENT ME!
     */
    public void getGroupList(RecordsData recordsData)
            throws InstantiationException, IllegalAccessException,
            InvocationTargetException, NoSuchMethodException, SQLException {
        Connection connection = this.dataSource.getConnection();

        PreparedStatement st = connection.prepareStatement(dbDriver
                .getQueries().getForumQueries().getSql_GET_GROUP_LIST());
        ResultSet rs = null;

        try {
            rs = st.executeQuery();
            recordsData.fillRecords(rs, Mapping.getInstance().GroupMapping,
                    Group.class);
        } finally {
            if (rs != null) {
                rs.close();
            }

            st.close();
            connection.close();
        }
    }

    /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -