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

📄 threaddaojdo.java

📁 Chinaxp 论坛源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        } catch (IllegalAccessException e) {            throw new DAOException(e);        } catch (InvocationTargetException e) {            throw new DAOException(e);        }finally{            pManager.close();        }        return result;    }    /**     *  Get the top-level threads count under the given category from start index     *     *  @param category - The category     *  @return int - The top-level threads count under a category     */    public int findCountByCategory(int category) throws DAOException {        final PersistenceManager pManager = pmf.getPersistenceManager();        final Query query                = pManager.newQuery(PersistentThread.class, "category == " + category + " && parent_id == -1 " );        final Collection persistentCollection                = (Collection) query.execute();        int result = persistentCollection.size();        pManager.close();        return result;    }    /**     * update Thread from DB     */    public void updateThread(org.redsoft.forum.dao.Thread thread) throws ThreadNotFoundException, DAOException {        Validation.validateNotNull(thread);        final PersistenceManager pManager = pmf.getPersistenceManager();        final PersistentThread persistentThread                = findPersistentThread(pManager, thread.getId());        if (persistentThread == null) {            pManager.close();            throw new ThreadNotFoundException(thread.getId() + "");        } else {            try {                pManager.currentTransaction().begin();                BeanUtils.copyProperties(persistentThread, thread);                pManager.currentTransaction().commit();            } catch (IllegalAccessException e) {                throw new DAOException(e);            } catch (InvocationTargetException e) {                throw new DAOException(e);            } finally {                pManager.close();            }        }    }    /**     * Update the click count     */    public void updateClick(long id) throws DAOException {        final PersistenceManager pManager = pmf.getPersistenceManager();        final PersistentThread persistentThread                = findPersistentThread(pManager, id);        pManager.currentTransaction().begin();        persistentThread.setClick(persistentThread.getClick() + 1);        pManager.currentTransaction().commit();        pManager.close();    }    /**     * Add a thread to column     * @param threadId     * @throws ThreadNotFoundException     * @throws DAOException     */    public void addColumnThread(long threadId) throws ThreadNotFoundException, DAOException {        final PersistenceManager pManager = pmf.getPersistenceManager();        final PersistentThread persistentThread                = findPersistentThread(pManager, threadId);        pManager.currentTransaction().begin();        persistentThread.setColumnThread(true);        pManager.currentTransaction().commit();        pManager.close();    }    /**     * Remove a thread from column     * @param threadId     * @throws ThreadNotFoundException     * @throws DAOException     */    public void removeColumnThread(long threadId) throws ThreadNotFoundException, DAOException {        final PersistenceManager pManager = pmf.getPersistenceManager();        final PersistentThread persistentThread                = findPersistentThread(pManager, threadId);        pManager.currentTransaction().begin();        persistentThread.setColumnThread(false);        pManager.currentTransaction().commit();        pManager.close();    }    /**     *  Get a list of thread by given the user Id from startIndex to endIndex     *  startIndex included, endIndex exclulded     *  @return Collection -- a list of PersistentThread Object which user id is the same as given     *  @exception DAOException     * @param userId     * @param startIndex should be greater than zero     * @param endIndex     * @return     * @throws DAOException     */    public Collection findByUserId(String userId, int startIndex, int endIndex) throws DAOException {        final PersistenceManager pManager = pmf.getPersistenceManager();        final ArrayList result = new ArrayList();        final Query query                = pManager.newQuery(PersistentThread.class);        query.declareParameters("String value");        query.setFilter("author==value");        query.setOrdering("timeStamp descending");        final Collection persistentCollection                = (Collection) query.execute(userId);        final Iterator iterator = persistentCollection.iterator();        int index = 0;        while (iterator.hasNext() && index <= endIndex) {            index++;            if (index < startIndex) continue;            final PersistentThread persistentThread                    = (PersistentThread) iterator.next();            final org.redsoft.forum.dao.Thread thread = new org.redsoft.forum.dao.Thread();            try {                BeanUtils.copyProperties(thread, persistentThread);                result.add(thread);            } catch (IllegalAccessException e) {                throw new DAOException(e);            } catch (InvocationTargetException e) {                throw new DAOException(e);            }        }        pManager.close();        return result;    }    /**     *  Remove a new thread from the DB     */    public void removeThread(long threadID) throws DAOException {        final PersistenceManager pManager = pmf.getPersistenceManager();        final PersistentThread persistentThread                = findPersistentThread(pManager, threadID);        if (persistentThread != null) {            pManager.currentTransaction().begin();            if (persistentThread.getParent_id() != -1) {                final PersistentThread parentThread                        = findPersistentThread(pManager, persistentThread.getParent_id());                if (parentThread != null)                    parentThread.setReply(parentThread.getReply() - 1);            }            pManager.deletePersistent(persistentThread);            pManager.currentTransaction().commit();        }        pManager.close();    }    /**     * Find all threads posted later than <code>time</code>     * (compare timestamp field of threads table in db with time)     *     * @param time  time in milliseconds     *              use System.currentTimeMillis() to get current time     *              if time==0, return all threads     * @return      all threads found     * @exception   DAOException when querying db     *     */    public Collection findThreadsPostedLaterThan(long time) throws DAOException {        final PersistenceManager pManager = pmf.getPersistenceManager();        final ArrayList result = new ArrayList();        final Query query                = pManager.newQuery(PersistentThread.class, "timeStamp >=" + time);        query.setOrdering("timeStamp descending");        final Collection persistentCollection                = (Collection) query.execute();        final Iterator iterator = persistentCollection.iterator();        while (iterator.hasNext()) {            final PersistentThread persistentThread                    = (PersistentThread) iterator.next();            final org.redsoft.forum.dao.Thread thread = new org.redsoft.forum.dao.Thread();            try {                BeanUtils.copyProperties(thread, persistentThread);                result.add(thread);            } catch (IllegalAccessException e) {                throw new DAOException(e);            } catch (InvocationTargetException e) {                throw new DAOException(e);            }        }        pManager.close();        return result;    }    public Collection findColumnThreadsByAccountId(String userId) throws DAOException {        final PersistenceManager pManager = pmf.getPersistenceManager();        final ArrayList result = new ArrayList();        final Query query                = pManager.newQuery(PersistentThread.class);        query.declareParameters("String userIdValue");        query.setFilter("author == userIdValue && columnThread == true");        query.setOrdering("timeStamp descending");        final Collection persistentCollection                = (Collection) query.execute(userId);        final Iterator iterator = persistentCollection.iterator();        while (iterator.hasNext()) {            final PersistentThread persistentThread                    = (PersistentThread) iterator.next();            final org.redsoft.forum.dao.Thread thread = new org.redsoft.forum.dao.Thread();            try {                BeanUtils.copyProperties(thread, persistentThread);                result.add(thread);            } catch (IllegalAccessException e) {                throw new DAOException(e);            } catch (InvocationTargetException e) {                throw new DAOException(e);            }        }        pManager.close();        return result;    }    public int findCountByUserId(String userId) throws DAOException {        final PersistenceManager pManager = pmf.getPersistenceManager();        final Query query                = pManager.newQuery(PersistentThread.class);        query.declareParameters("String userIdValue");        query.setFilter("author == userIdValue");        final Collection persistentCollection                = (Collection) query.execute(userId);        int result = persistentCollection.size();        pManager.close();        return result;    }}

⌨️ 快捷键说明

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