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

📄 bitstreaminfodao.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    e);            throw new RuntimeException("Problem inserting missing bitstreams. "                    + e.getMessage(), e);        }        finally        {            cleanup(stmt, conn);        }    }    /**     * Deletes the bitstream from the most_recent_checksum table if it exist.     *      * @param id     *            the bitstream id.     *      * @return number of records deleted     */    protected int deleteBitstreamInfo(int id, Connection conn)    {        PreparedStatement stmt = null;        int numDeleted = 0;        try        {            stmt = conn.prepareStatement(DELETE_BITSTREAM_INFO);            stmt.setInt(1, id);            numDeleted = stmt.executeUpdate();            if (numDeleted > 1)            {                conn.rollback();                throw new IllegalStateException(                        "Too many rows deleted! Number of rows deleted: "                                + numDeleted                                + " only one row should be deleted for bitstream id "                                + id);            }        }        catch (SQLException e)        {            LOG.error("Problem deleting bitstream. " + e.getMessage(), e);            throw new RuntimeException("Problem deleting bitstream. "                    + e.getMessage(), e);        }        finally        {            cleanup(stmt);        }        return numDeleted;    }    public int deleteBitstreamInfoWithHistory(int id)    {        Connection conn = null;        int numDeleted = 0;        try        {            conn = DatabaseManager.getConnection();            deleteBitstreamInfo(id, conn);            checksumHistoryDAO.deleteHistoryForBitstreamInfo(id, conn);            conn.commit();        }        catch (SQLException e)        {            LOG.error("Problem deleting bitstream. " + e.getMessage(), e);            throw new RuntimeException("Problem deleting bitstream. "                    + e.getMessage(), e);        }        finally        {            cleanup(conn);        }        return numDeleted;    }    /**     * Get the oldest bitstream in the most recent checksum table. If more than     * one found the first one in the result set is returned.     *      * @return the bitstream id or -1 if the no bitstreams are found     *      */    public int getOldestBitstream()    {        Connection conn = null;        PreparedStatement prepStmt = null;        ResultSet rs = null;        try        {            conn = DatabaseManager.getConnection();            prepStmt = conn.prepareStatement(GET_OLDEST_BITSTREAM);            rs = prepStmt.executeQuery();            if (rs.next())            {                return rs.getInt(1);            }            else            {                return SENTINEL;            }        }        catch (SQLException e)        {            LOG.error("Problem with get oldest bitstream " + e.getMessage(), e);            throw new RuntimeException("Oldest bitstream error. "                    + e.getMessage(), e);        }        finally        {            cleanup(prepStmt, conn);        }    }    /**     * Returns the oldest bistream that in the set of bitstreams that are less     * than the specified date. If no bitstreams are found -1 is returned.     *      * @param lessThanDate     * @return id of olded bitstream or -1 if not bistreams are found     */    public int getOldestBitstream(Timestamp lessThanDate)    {        Connection conn = null;        PreparedStatement prepStmt = null;        ResultSet rs = null;        try        {            conn = DatabaseManager.getConnection();            prepStmt = conn.prepareStatement(GET_OLDEST_BITSTREAM_DATE);            prepStmt.setTimestamp(1, lessThanDate);            rs = prepStmt.executeQuery();            if (rs.next())            {                return rs.getInt(1);            }            else            {                return SENTINEL;            }        }        catch (SQLException e)        {            LOG.error("get oldest bitstream less than date " + e.getMessage(),                    e);            throw new RuntimeException("get oldest bitstream less than date. "                    + e.getMessage(), e);        }        finally        {            cleanup(prepStmt, conn);        }    }    /**     * Get the bitstream ids for a given Item     *      * @param itemId     * @return the list of bitstream ids for this item     */    public List getItemBitstreams(int itemId)    {        List ids = new ArrayList();        Connection conn = null;        PreparedStatement ps = null;        ResultSet rs = null;        try        {            conn = DatabaseManager.getConnection();            ps = conn.prepareStatement(ITEM_BITSTREAMS);            ps.setInt(1, itemId);            rs = ps.executeQuery();            while (rs.next())            {                ids.add(new Integer(rs.getInt(1)));            }        }        catch (SQLException e)        {            LOG.error("get item bitstreams " + e.getMessage(), e);            throw new RuntimeException(                    "get item bitstreams. " + e.getMessage(), e);        }        finally        {            cleanup(ps, conn, rs);        }        return ids;    }    /**     * Get the bitstream ids for a given collection     *      * @param itemId     * @return the list of bitstream ids for this item     */    public List getCollectionBitstreams(int collectionId)    {        List ids = new ArrayList();        Connection conn = null;        PreparedStatement ps = null;        ResultSet rs = null;        try        {            conn = DatabaseManager.getConnection();            ps = conn.prepareStatement(COLLECTION_BITSTREAMS);            ps.setInt(1, collectionId);            rs = ps.executeQuery();            while (rs.next())            {                ids.add(new Integer(rs.getInt(1)));            }        }        catch (SQLException e)        {            LOG.error("get item bitstreams " + e.getMessage(), e);            throw new RuntimeException(                    "get item bitstreams. " + e.getMessage(), e);        }        finally        {            cleanup(ps, conn, rs);        }        return ids;    }    /**     * Get the bitstream ids for a given community     *      * @param itemId     * @return the list of bitstream ids for this item     */    public List getCommunityBitstreams(int communityId)    {        List ids = new ArrayList();        Connection conn = null;        PreparedStatement ps = null;        ResultSet rs = null;        try        {            conn = DatabaseManager.getConnection();            ps = conn.prepareStatement(COMMUNITY_BITSTREAMS);            ps.setInt(1, communityId);            rs = ps.executeQuery();            while (rs.next())            {                ids.add(new Integer(rs.getInt(1)));            }        }        catch (SQLException e)        {            LOG.error("get item bitstreams " + e.getMessage(), e);            throw new RuntimeException(                    "get item bitstreams. " + e.getMessage(), e);        }        finally        {            cleanup(ps, conn, rs);        }        return ids;    }}

⌨️ 快捷键说明

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