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

📄 cmsdbaccess.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     */
    protected boolean checkAccess(CmsObject cms, CmsMasterContent content, boolean viewonly) {
        if(!content.isReadable()) {
            // was not readable
            return false;
        } else if(viewonly) {
            // additional check for v-Flags
            return content.isVisible();
        } else {
            // was readable - return true
            return true;
        }
    }

    /**
     * Returns true, if this is the onlineproject
     * @param cms - the CmsObject to get access to cms-ressources.
     * @returns true, if this is the onlineproject, else returns false
     */
    protected boolean isOnlineProject(CmsObject cms) {
        boolean retValue = false;
        try {
             if(cms.getRequestContext().currentProject().equals(cms.onlineProject())) {
                // yes, this is the onlineproject!
                retValue = true;
             }
        } catch(CmsException exc) {
            // ignore the exception
        }
        return retValue;
    }

    /**
     * Deletes all media lines for one master.
     * @param masterId - the masterId to delete the media for
     * @throws SQLException if an sql-error occur
     */
    protected void deleteAllMedia(int masterId) throws SQLException {
        String statement_key = "delete_all_media_offline";
        PreparedStatement stmnt = null;
        Connection con = null;
        try {
            con = DriverManager.getConnection(m_poolName);
            stmnt = sqlPrepare(con, statement_key);
            stmnt.setInt(1, masterId);
            stmnt.executeUpdate();
        } finally {
            sqlClose(con, stmnt, null);
        }
    }

    /**
     * Deletes all channel lines for one master.
     * @param masterId - the masterId to delete the media for
     * @throws SQLException if an sql-error occur
     */
    protected void deleteAllChannels(int masterId) throws SQLException {
        String statement_key = "delete_all_channel_offline";
        PreparedStatement stmnt = null;
        Connection con = null;
        try {
            con = DriverManager.getConnection(m_poolName);
            stmnt = sqlPrepare(con, statement_key);
            stmnt.setInt(1, masterId);
            stmnt.executeUpdate();
        } finally {
            sqlClose(con, stmnt, null);
        }
    }

    /**
     * TODO: write header here
     */
    protected void updateMedia(int masterId, Vector mediaToAdd,
                               Vector mediaToUpdate, Vector mediaToDelete)
        throws SQLException, CmsException {
        // add new media
        PreparedStatement stmnt = null;
        Connection con = null;
        try {
            con = DriverManager.getConnection(m_poolName);
            stmnt = sqlPrepare(con, "insert_media_offline");
            for(int i = 0; i < mediaToAdd.size(); i++) {
                CmsMasterMedia media = (CmsMasterMedia) mediaToAdd.get(i);
                media.setId(CmsIdGenerator.nextId(m_poolName, "CMS_MODULE_MEDIA"));
                media.setMasterId(masterId);
                sqlFillValues(stmnt, media);
                stmnt.executeUpdate();
            }
        } finally {
            sqlClose(con, stmnt, null);
        }

        // update existing media
        stmnt = null;
        con = null;
        try {
            con = DriverManager.getConnection(m_poolName);
            stmnt = sqlPrepare(con, "update_media_offline");
            for(int i = 0; i < mediaToUpdate.size(); i++) {
                CmsMasterMedia media = (CmsMasterMedia) mediaToUpdate.get(i);
                media.setMasterId(masterId);
                int rowCounter = sqlFillValues(stmnt, media);
                stmnt.setInt(rowCounter++, media.getId());
                stmnt.setInt(rowCounter++, masterId);
                stmnt.executeUpdate();
            }
        } finally {
            sqlClose(con, stmnt, null);
        }
        // delete unneeded media
        stmnt = null;
        con = null;
        try {
            con = DriverManager.getConnection(m_poolName);
            stmnt = sqlPrepare(con, "delete_media_offline");
            for(int i = 0; i < mediaToDelete.size(); i++) {
                CmsMasterMedia media = (CmsMasterMedia) mediaToDelete.get(i);
                stmnt.setInt(1, media.getId());
                stmnt.setInt(2, masterId);
                stmnt.executeUpdate();
            }
        } finally {
            sqlClose(con, stmnt, null);
        }
    }

    /**
     * TODO: write header here
     */
    protected void updateChannels(CmsObject cms, int masterId, Vector channelToAdd,
        Vector channelToDelete) throws SQLException {
        // add new channel
        PreparedStatement stmnt = null;
        Connection con = null;
        try {
            con = DriverManager.getConnection(m_poolName);
            stmnt = sqlPrepare(con, "insert_channel_offline");
            for(int i = 0; i < channelToAdd.size(); i++) {
                try {
                    stmnt.setInt(1, masterId);
                    cms.setContextToCos();
                    stmnt.setInt(2, Integer.parseInt(cms.readProperty(channelToAdd.get(i)+"",
                        I_CmsConstants.C_PROPERTY_CHANNELID)));
                    cms.setContextToVfs();
                    // stmnt.setInt(2, Integer.parseInt(cms.readProperty(C_COS_PREFIX + channelToAdd.get(i),
                    //    I_CmsConstants.C_PROPERTY_CHANNELID)));
                    stmnt.executeUpdate();
                } catch(CmsException exc) {
                    // no channel found - write to logfile
                    if(CmsBase.isLogging()) {
                        CmsBase.log(CmsBase.C_MODULE_DEBUG, "[CmsDbAccess] Couldn't find channel " + channelToAdd.get(i) + " errormessage: " + exc.getMessage());
                    }
                }
            }
        } finally {
            sqlClose(con, stmnt, null);
        }

        // delete unneeded channel
        stmnt = null;
        con = null;
        try {
            con = DriverManager.getConnection(m_poolName);
            stmnt = sqlPrepare(con, "delete_channel_offline");
            for(int i = 0; i < channelToDelete.size(); i++) {
                try {
                    stmnt.setInt(1, masterId);
                    cms.setContextToCos();
                    stmnt.setInt(2, Integer.parseInt(cms.readProperty(channelToDelete.get(i)+"",
                         I_CmsConstants.C_PROPERTY_CHANNELID)));
                    cms.setContextToVfs();
                    // stmnt.setInt(2, Integer.parseInt(cms.readProperty(C_COS_PREFIX + channelToDelete.get(i),
                    //     I_CmsConstants.C_PROPERTY_CHANNELID)));
                    stmnt.executeUpdate();
                } catch(CmsException exc) {
                    // no channel found - write to logfile
                    if(CmsBase.isLogging()) {
                        CmsBase.log(CmsBase.C_MODULE_DEBUG, "[CmsDbAccess] Couldn't find channel " + channelToAdd.get(i) + " errormessage: " + exc.getMessage());
                    }
                }
            }
        } finally {
            sqlClose(con, stmnt, null);
        }
    }

    /**
     * TODO: write header here
     */
    protected int sqlFillValues(PreparedStatement stmnt, CmsMasterMedia media)
        throws SQLException {
        int i = 1;
        stmnt.setInt(i++, media.getId());
        stmnt.setInt(i++, media.getMasterId());
        stmnt.setInt(i++, media.getPosition());
        stmnt.setInt(i++, media.getWidth());
        stmnt.setInt(i++, media.getHeight());
        stmnt.setInt(i++, media.getSize());
        stmnt.setString(i++, media.getMimetype());
        stmnt.setInt(i++, media.getType());
        stmnt.setString(i++, media.getTitle());
        stmnt.setString(i++, media.getName());
        stmnt.setString(i++, media.getDescription());
        stmnt.setBinaryStream(i++, new ByteArrayInputStream(media.getMedia()), media.getMedia().length);
        //stmnt.setBytes(i++, media.getMedia());
        return i;
    }

    /**
     * Returns a vector with all version of a master in the backup
     *
     * @param cms The CmsObject
     * @param masterId The id of the master
     * @param subId The sub_id
     * @return Vector A vector with all versions of the master
     */
    public Vector getHistory(CmsObject cms, Class contentDefinitionClass, int masterId, int subId) throws CmsException{
        Vector retVector = new Vector();
        Vector allBackup = new Vector();
        PreparedStatement stmnt = null;
        ResultSet res = null;
        Connection con = null;
        try {
            con = DriverManager.getConnection(m_backupPoolName);
            stmnt = sqlPrepare(con, "read_all_backup");
            stmnt.setInt(1, masterId);
            stmnt.setInt(2, subId);
            // gets all versions of the master in the backup table
            res = stmnt.executeQuery();
            while(res.next()) {
                CmsMasterDataSet dataset = new CmsMasterDataSet();
                sqlFillValues(res, cms, dataset);
                dataset.m_versionId = res.getInt("VERSION_ID");
                dataset.m_userName = res.getString("USER_NAME");
                dataset.m_groupName = res.getString("GROUP_NAME");
                dataset.m_lastModifiedByName = res.getString("LASTMODIFIED_BY_NAME");
                allBackup.add(dataset);
            }
            retVector = createVectorOfCd(allBackup, contentDefinitionClass, cms);
        } catch (SQLException e){
            throw new CmsException(CmsException.C_SQL_ERROR, e);
        } finally {
            sqlClose(con, stmnt, res);
        }
        return retVector;
    }

    /**
     * Returns the version of a master in the backup
     *
     * @param cms The CmsObject
     * @param contentDefinitionClass The class of the content definition
     * @param masterId The id of the master
     * @param subId The sub_id
     * @param versionId The version id
     * @return CmsMasterContent A content definition of the version
     */
    public CmsMasterContent getVersionFromHistory(CmsObject cms, Class contentDefinitionClass,
                                                  int masterId, int subId, int versionId) throws CmsException{
        CmsMasterContent content = null;
        CmsMasterDataSet dataset = this.getVersionFromHistory(cms, masterId, subId, versionId);
        Constructor constructor;
        try { // to get the constructor to create an empty contentDefinition
            constructor = contentDefinitionClass.getConstructor(new Class[]{CmsObject.class, CmsMasterDataSet.class});
        } catch(NoSuchMethodException exc) {
            if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && CmsBase.isLogging()) {
                CmsBase.log(I_CmsLogChannels.C_MODULE_DEBUG, "[CmsDbAccess] Cannot locate constructor: " + exc.getMessage());
            }
            // canno't fill the vector - missing constructor
            return content;
        }
        // create content definition for each dataset
        if (dataset != null){
            try { // to invoce the constructor to get a new empty instance
                content = (CmsMasterContent)constructor.newInstance(new Object[]{cms, dataset});
            } catch(Exception exc) {
                if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && CmsBase.isLogging()) {
                    CmsBase.log(I_CmsLogChannels.C_MODULE_DEBUG, "[CmsDbAccess] Cannot invoce constructor: " + exc.getMessage());
                }
            }
        }
        return content;
    }

    /**
     * Returns the version of a master in the backup
     *
     * @param cms The CmsObject
     * @param masterId The id of the master
     * @param subId The sub_id
     * @param versionId The version id
     * @return Vector A vector with all versions of the master
     */
    public CmsMasterDataSet getVersionFromHistory(CmsObject cms, int masterId, int subId, int versionId) throws CmsException{
        CmsMasterDataSet dataset = new CmsMasterDataSet();
        PreparedStatement stmnt = null;
        ResultSet res = null;
        Connection con = null;
        try {
            con = DriverManager.getConnection(m_back

⌨️ 快捷键说明

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