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

📄 cmsdbaccess.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @param subId the sub ID of the contentdefinition.
     * @return Vector the datasets of the contentdefinitions in the channel.
     */
    public Vector readAllByChannel(CmsObject cms, String channelId, int subId) throws CmsException {
        Vector theDataSets = new Vector();
        String statement_key = "readallbychannel_offline";
        if (isOnlineProject(cms)) {
            statement_key = "readallbychannel_online";
        }

        PreparedStatement stmt = null;
        ResultSet res = null;
        Connection conn = null;
        try {
            conn = m_sqlManager.getConnection();
            stmt = m_sqlManager.getPreparedStatement(conn, statement_key);
            stmt.setInt(1, subId);
            stmt.setString(2, channelId);
            res = stmt.executeQuery();
            while (res.next()) {
                CmsMasterDataSet dataset = new CmsMasterDataSet();
                sqlFillValues(res, cms, dataset);
                theDataSets.add(dataset);
            }
        } catch (SQLException exc) {
            throw new CmsLegacyException(CmsLegacyException.C_SQL_ERROR, exc);
        } finally {
            m_sqlManager.closeAll(null, conn, stmt, res);
        }
        return theDataSets;
    }

    /**
     * Delete a dataset from the offline table.<p>
     * 
     * @param cms the CmsObject to get access to cms-ressources.
     * @param content the CmsMasterContent to write to the database.
     * @param dataset the set of data for this contentdefinition.
     */
    public void delete(CmsObject cms, CmsMasterContent content, CmsMasterDataSet dataset) throws CmsException {
        if (isOnlineProject(cms)) {
            // this is the onlineproject - don't write into this project directly
            throw new CmsSecurityException(Messages.get().container(Messages.ERR_SECURITY_NO_MODIFY_IN_ONLINE_PROJECT_0));
        }
        if (dataset.m_versionId != CmsDbUtil.UNKNOWN_ID) {
            // this is not the online row - it was read from history
            // don't delete it!
            throw new CmsLegacySecurityException("Can't delete a backup cd", CmsLegacySecurityException.C_SECURITY_NO_PERMISSIONS);
        }
        // read the lockstate
        readLockstate(dataset, content.getSubId());
        if ((!dataset.m_lockedBy.equals(cms.getRequestContext().currentUser().getId()))) {
            // is not locked by this user
            throw new CmsLegacySecurityException("Not locked by this user", CmsLegacySecurityException.C_SECURITY_NO_PERMISSIONS);
        }
        if (dataset.m_lockedInProject != dataset.m_projectId) {
            // not locked in this project
            throw new CmsLegacySecurityException("Not locked in this project", CmsLegacySecurityException.C_SECURITY_NO_PERMISSIONS);
        }
        if (!content.isWriteable()) {
            // no write access
            throw new CmsLegacySecurityException("Not writeable", CmsLegacySecurityException.C_SECURITY_NO_PERMISSIONS);
        }

        if (dataset.m_state == CmsResource.STATE_NEW) {
            // this is a new line in this project and can be deleted
            String statement_key = "delete_offline";
            PreparedStatement stmt = null;
            Connection conn = null;
            try {
                conn = m_sqlManager.getConnection();
                stmt = m_sqlManager.getPreparedStatement(conn, statement_key);
                stmt.setString(1, dataset.m_masterId.toString());
                stmt.setInt(2, content.getSubId());
                if (stmt.executeUpdate() != 1) {
                    // no line deleted - row wasn't found
                    throw new CmsLegacyException("Row not found: " + dataset.m_masterId + " " + content.getSubId(), CmsLegacyException.C_NOT_FOUND);
                }
                // after deleting the row, we have to delete media and channel rows
                deleteAllMedia(dataset.m_masterId);
                deleteAllChannels(dataset.m_masterId);
            } catch (SQLException exc) {
                throw new CmsLegacyException(CmsLegacyException.C_SQL_ERROR, exc);
            } finally {
                m_sqlManager.closeAll(null, conn, stmt, null);
            }
        } else {
            // set state to deleted and update the line
            dataset.m_state = CmsResource.STATE_DELETED;
            dataset.m_lockedBy = CmsUUID.getNullUUID();
            PreparedStatement stmt = null;
            Connection conn = null;
            try {
                conn = m_sqlManager.getConnection();
                stmt = m_sqlManager.getPreparedStatement(conn, "update_offline");
                int rowcounter = sqlFillValues(stmt, content.getSubId(), dataset);
                stmt.setString(rowcounter++, dataset.m_masterId.toString());
                stmt.setInt(rowcounter++, content.getSubId());
                stmt.executeUpdate();
            } catch (SQLException exc) {
                throw new CmsLegacyException(CmsLegacyException.C_SQL_ERROR, exc);
            } finally {
                m_sqlManager.closeAll(null, conn, stmt, null);
            }
        }
    }

    /**
     * Undelete a prevoiusly deleted contentdefinition.<p>
     * 
     * @param cms the CmsObject to get access to cms resources.
     * @param content the CmsMasterContent to write to the database.
     * @param dataset the set of data for this contentdefinition.
     */
    public void undelete(CmsObject cms, CmsMasterContent content, CmsMasterDataSet dataset) throws CmsException {
        if (isOnlineProject(cms)) {
            // this is the onlineproject - don't write into this project directly
            throw new CmsSecurityException(Messages.get().container(Messages.ERR_SECURITY_NO_MODIFY_IN_ONLINE_PROJECT_0));
        }
        if (dataset.m_versionId != CmsDbUtil.UNKNOWN_ID) {
            // this is not the online row - it was read from history
            // don't delete it!
            throw new CmsLegacySecurityException("Can't undelete a backup cd ", CmsLegacySecurityException.C_SECURITY_NO_PERMISSIONS);
        }
        if (!content.isWriteable()) {
            // no write access
            throw new CmsLegacySecurityException("Not writeable", CmsLegacySecurityException.C_SECURITY_NO_PERMISSIONS);
        }
        // set state to deleted and update the line
        dataset.m_state = CmsResource.STATE_CHANGED;
        dataset.m_lockedBy = cms.getRequestContext().currentUser().getId();
        dataset.m_lockedInProject = cms.getRequestContext().currentProject().getId();
        PreparedStatement stmt = null;
        Connection conn = null;
        try {
            conn = m_sqlManager.getConnection();
            stmt = m_sqlManager.getPreparedStatement(conn, "update_offline");
            int rowcounter = sqlFillValues(stmt, content.getSubId(), dataset);
            stmt.setString(rowcounter++, dataset.m_masterId.toString());
            stmt.setInt(rowcounter++, content.getSubId());
            stmt.executeUpdate();
        } catch (SQLException exc) {
            throw new CmsLegacyException(CmsLegacyException.C_SQL_ERROR, exc);
        } finally {
            m_sqlManager.closeAll(null, conn, stmt, null);
        }
    }

    /**
     * Changes the permissions of the content.<p>
     *
     * @param cms the CmsObject to get access to cms resources.
     * @param content the CmsMasterContent to write to the database.
     * @param dataset the set of data for this contentdefinition.
     */
    public void changePermissions(CmsObject cms, CmsMasterContent content, CmsMasterDataSet dataset) throws CmsException {
        if (isOnlineProject(cms)) {
            // this is the onlineproject - don't write into this project directly
            throw new CmsSecurityException(Messages.get().container(Messages.ERR_SECURITY_NO_MODIFY_IN_ONLINE_PROJECT_0));
        }
        if (dataset.m_versionId != CmsDbUtil.UNKNOWN_ID) {
            // this is not the online row - it was read from history
            // don't delete it!
            throw new CmsLegacySecurityException("Can't change permissions of a backup cd ", CmsLegacySecurityException.C_SECURITY_NO_PERMISSIONS);
        }
        // read the lockstate
        readLockstate(dataset, content.getSubId());
        if (!dataset.m_lockedBy.equals(cms.getRequestContext().currentUser().getId())) {
            // is not locked by this user
            throw new CmsLegacySecurityException("Not locked by this user", CmsLegacySecurityException.C_SECURITY_NO_PERMISSIONS);
        }
        if (dataset.m_lockedInProject != dataset.m_projectId) {
            // not locked in this project
            throw new CmsLegacySecurityException("Not locked in this project", CmsLegacySecurityException.C_SECURITY_NO_PERMISSIONS);
        }
        if (!content.isWriteable()) {
            // no write access
            throw new CmsLegacySecurityException("Not writeable", CmsLegacySecurityException.C_SECURITY_NO_PERMISSIONS);
        }
        if (dataset.m_state != CmsResource.STATE_NEW) {
            dataset.m_state = CmsResource.STATE_CHANGED;
        }
        dataset.m_dateLastModified = System.currentTimeMillis();
        dataset.m_lastModifiedBy = cms.getRequestContext().currentUser().getId();
        // update the line
        PreparedStatement stmt = null;
        Connection conn = null;
        try {
            conn = m_sqlManager.getConnection();
            stmt = m_sqlManager.getPreparedStatement(conn, "update_permissions_offline");
            stmt.setString(1, dataset.m_userId.toString());
            stmt.setString(2, dataset.m_groupId.toString());
            stmt.setInt(3, dataset.m_accessFlags);
            stmt.setInt(4, dataset.m_state);
            stmt.setString(5, dataset.m_lastModifiedBy.toString());
            stmt.setTimestamp(6, new Timestamp(dataset.m_dateLastModified));
            stmt.setString(7, dataset.m_masterId.toString());
            stmt.setInt(8, content.getSubId());
            stmt.executeUpdate();
        } catch (SQLException exc) {
            throw new CmsLegacyException(CmsLegacyException.C_SQL_ERROR, exc);
        } finally {
            m_sqlManager.closeAll(null, conn, stmt, null);
        }
    }

    /**
     * Returns a string representation of this instance.
     * This can be used for debugging.<p>
     * 
     * @return the string representation of this instance.
     */
    public String toString() {
        StringBuffer returnValue = new StringBuffer();
        returnValue.append(this.getClass().getName() + "{");
        returnValue.append("Used db pool=" + m_poolUrl + ";");
        returnValue.append("}");
        return returnValue.toString();
    }

    /**
     * Inserts all values to the statement for insertion and update.<p>
     * 
     * @param stmt the Statement to fill the values to.
     * @param subId the subid of this module.
     * @param dataset the set of data for this contentdefinition.
     * @return the current rowcounter.
     */
    protected int sqlFillValues(PreparedStatement stmt, int subId, CmsMasterDataSet dataset) throws SQLException {
        // columncounter
        int i = 1;
        //// COREDATA ////
        stmt.setString(i++, dataset.m_masterId.toString());
        stmt.setInt(i++, subId);
        stmt.setString(i++, dataset.m_userId.toString());
        stmt.setString(i++, dataset.m_groupId.toString());
        stmt.setInt(i++, dataset.m_lockedInProject);
        stmt.setInt(i++, dataset.m_accessFlags);
        stmt.setInt(i++, dataset.m_state);
        stmt.setString(i++, dataset.m_lockedBy.toString());
        stmt.setString(i++, dataset.m_lastModifiedBy.toString());
        stmt.setTimestamp(i++, new Timestamp(dataset.m_dateCreated));
        stmt.setTimestamp(i++, new Timestamp(dataset.m_dateLastModified));
        //// USERDATA ////
        stmt.setTimestamp(i++, new Timestamp(dataset.m_publicationDate));
        stmt.setTimestamp(i++, new Timestamp(dataset.m_purgeDate));
        stmt.setInt(i++, dataset.m_flags);
        stmt.setInt(i++, dataset.m_feedId);
        stmt.setInt(i++, dataset.m_feedReference);
        if (dataset.m_feedFilename == null) {
            stmt.setNull(i++, Types.VARCHAR);
        } else {
            stmt.setString(i++, dataset.m_feedFilename);
        }
        if (dataset.m_title == null) {
            stmt.setNull(i++, Types.VARCHAR);
        } else {
            stmt.setString(i++, dataset.m_title);
        }
        //// GENERIC DATA ////
        i = sqlSetTextArray(stmt, dataset.m_dataBig, i);
        i = sqlSetTextArray(stmt, dataset.m_dataMedium, i);
        i = sqlSetTextArray(stmt, dataset.m_dataSmall, i);
        i = sqlSetIntArray(stmt, dataset.m_dataInt, i);
        i = sqlSetIntArray(stmt, dataset.m_dataReference, i);
        i = sqlSetDateArray(stmt, dataset.m_dataDate, i);
        return i;
    }

    /**
     * Inserts all values to the statement for insert and update.<p>
     * 
     * @param res the Resultset read the values from.
     * @param cms the CmsObject to get access to cms resources.
     * @param dataset the set of data for this contentdefinition.
     * @return the current rowcounter.
     */
    protected int sqlFillValues(ResultSet res, CmsObject cms, CmsMasterDataSet dataset) throws SQLException {
        // columncounter
        int i = 1;
        //// COREDATA ////
        dataset.m_masterId = new CmsUUID(res.getString(i++));
        // cw/12.02.2004 - subId was not read, but was already defined in data set - need it in search
        dataset.m_subId = res.getInt(i++);
        dataset.m_userId = new CmsUUID(res.getString(i++));
        dataset.m_groupId = new CmsUUID(res.getString(i++));
        dataset.m_lockedInProject = res.getInt(i++);
        // compute project based on the current project and the channels
        dataset.m_projectId = computeProjectId(cms, dataset);
        dataset.m_accessFlags = res.getInt(i++);
        dataset.m_state = res.getInt(i++);
        dataset.m_lockedBy = new CmsUUID(res.getString(i++));

⌨️ 快捷键说明

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