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

📄 cmsdbaccess.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        addUserToGroup(admin.getId(), administrators.getId());
        writeTaskType(1, 0, "../taskforms/adhoc.asp", "Ad-Hoc", "30308", 1, 1);
        // create the online project
        CmsTask task = createTask(0, 0, 1, // standart project type,
                    admin.getId(), admin.getId(), administrators.getId(), C_PROJECT_ONLINE, new java.sql.Timestamp(new java.util.Date().getTime()), new java.sql.Timestamp(new java.util.Date().getTime()), C_TASK_PRIORITY_NORMAL);
        CmsProject online = createProject(admin, guests, projectleader, task, C_PROJECT_ONLINE, "the online-project", C_FLAG_ENABLED, C_PROJECT_TYPE_NORMAL);

        // create the root-folder for the online project
        int siteRootId = 0;
        CmsFolder rootFolder = createFolder(admin, online, C_UNKNOWN_ID, C_UNKNOWN_ID, C_ROOT, 0);
        rootFolder.setGroupId(users.getId());
        rootFolder.setState(C_STATE_UNCHANGED);
        writeFolder(online, rootFolder, false);
        rootFolder = createFolder(admin, online, rootFolder.getResourceId(), C_UNKNOWN_ID, C_DEFAULT_SITE+C_ROOT, 0);
        rootFolder.setGroupId(users.getId());
        rootFolder.setState(C_STATE_UNCHANGED);
        writeFolder(online, rootFolder, false);
        siteRootId = rootFolder.getResourceId();
        rootFolder = createFolder(admin, online, siteRootId, C_UNKNOWN_ID, C_DEFAULT_SITE+C_ROOTNAME_VFS+C_ROOT, 0);
        rootFolder.setGroupId(users.getId());
        rootFolder.setState(C_STATE_UNCHANGED);
        writeFolder(online, rootFolder, false);
        rootFolder = createFolder(admin, online, siteRootId, C_UNKNOWN_ID, C_DEFAULT_SITE+C_ROOTNAME_COS+C_ROOT, 0);
        rootFolder.setGroupId(users.getId());
        rootFolder.setState(C_STATE_UNCHANGED);
        writeFolder(online, rootFolder, false);
        // create the setup project
        task = createTask(0, 0, 1, admin.getId(), admin.getId(), administrators.getId(),
                                    "_setupProject", new java.sql.Timestamp(new java.util.Date().getTime()),
                                    new java.sql.Timestamp(new java.util.Date().getTime()),
                                    C_TASK_PRIORITY_NORMAL);

        CmsProject setup = createProject(admin, administrators, administrators, task, "_setupProject",
                                           "the project for setup", C_FLAG_ENABLED, C_PROJECT_TYPE_TEMPORARY);

        // create the root-folder for the offline project
        rootFolder = createFolder(admin, setup, C_UNKNOWN_ID, C_UNKNOWN_ID, C_ROOT, 0);
        rootFolder.setGroupId(users.getId());
        rootFolder.setState(C_STATE_UNCHANGED);
        writeFolder(setup, rootFolder, false);
        rootFolder = createFolder(admin, setup, rootFolder.getResourceId(), C_UNKNOWN_ID, C_DEFAULT_SITE+C_ROOT, 0);
        rootFolder.setGroupId(users.getId());
        rootFolder.setState(C_STATE_UNCHANGED);
        writeFolder(setup, rootFolder, false);
        siteRootId = rootFolder.getResourceId();
        rootFolder = createFolder(admin, setup, siteRootId, C_UNKNOWN_ID, C_DEFAULT_SITE+C_ROOTNAME_VFS+C_ROOT, 0);
        rootFolder.setGroupId(users.getId());
        rootFolder.setState(C_STATE_UNCHANGED);
        writeFolder(setup, rootFolder, false);
        rootFolder = createFolder(admin, setup, siteRootId, C_UNKNOWN_ID, C_DEFAULT_SITE+C_ROOTNAME_COS+C_ROOT, 0);
        rootFolder.setGroupId(users.getId());
        rootFolder.setState(C_STATE_UNCHANGED);
        writeFolder(setup, rootFolder, false);
    }

    /**
     * Finds an agent for a given role (group).
     * @param roleId The Id for the role (group).
     *
     * @return A vector with the tasks
     *
     * @throws CmsException Throws CmsException if something goes wrong.
     */
    protected int findAgent(int roleid)
        throws CmsException {
        return super.findAgent(roleid);
    }

/**
 * retrieve the correct instance of the queries holder.
 * This method should be overloaded if other query strings should be used.
 */
protected com.opencms.file.genericSql.CmsQueries getQueries()
{
    return new com.opencms.file.mySql.CmsQueries();
}

/**
 * Reads a file from the Cms.<BR/>
 *
 * @param projectId The Id of the project in which the resource will be used.
 * @param onlineProjectId The online projectId of the OpenCms.
 * @param filename The complete name of the new file (including pathinformation).
 *
 * @return file The read file.
 *
 * @throws CmsException Throws CmsException if operation was not succesful
 */
public CmsFile readFile(int projectId, int onlineProjectId, String filename) throws CmsException {
    CmsFile file = null;
    PreparedStatement statement = null;
    ResultSet res = null;
    Connection con = null;
    String usedPool;
    String usedStatement;
    if (projectId == onlineProjectId){
        usedPool = m_poolNameOnline;
        usedStatement = "_ONLINE";
    } else {
        usedPool = m_poolName;
        usedStatement = "";
    }
    try {
        con = DriverManager.getConnection(usedPool);
        statement = con.prepareStatement(m_cq.get("C_FILES_READ"+usedStatement));
        statement.setString(1, filename);
        statement.setInt(2, projectId);
        res = statement.executeQuery();
        if (res.next()) {
            int resId = res.getInt(m_cq.get("C_RESOURCES_RESOURCE_ID"));
            int parentId = res.getInt(m_cq.get("C_RESOURCES_PARENT_ID"));
            int resType = res.getInt(m_cq.get("C_RESOURCES_RESOURCE_TYPE"));
            int resFlags = res.getInt(m_cq.get("C_RESOURCES_RESOURCE_FLAGS"));
            int userId = res.getInt(m_cq.get("C_RESOURCES_USER_ID"));
            int groupId = res.getInt(m_cq.get("C_RESOURCES_GROUP_ID"));
            int fileId = res.getInt(m_cq.get("C_RESOURCES_FILE_ID"));
            int accessFlags = res.getInt(m_cq.get("C_RESOURCES_ACCESS_FLAGS"));
            int state = res.getInt(m_cq.get("C_RESOURCES_STATE"));
            int lockedBy = res.getInt(m_cq.get("C_RESOURCES_LOCKED_BY"));
            int launcherType = res.getInt(m_cq.get("C_RESOURCES_LAUNCHER_TYPE"));
            String launcherClass = res.getString(m_cq.get("C_RESOURCES_LAUNCHER_CLASSNAME"));
            long created = SqlHelper.getTimestamp(res, m_cq.get("C_RESOURCES_DATE_CREATED")).getTime();
            long modified = SqlHelper.getTimestamp(res, m_cq.get("C_RESOURCES_DATE_LASTMODIFIED")).getTime();
            int modifiedBy = res.getInt(m_cq.get("C_RESOURCES_LASTMODIFIED_BY"));
            int resSize = res.getInt(m_cq.get("C_RESOURCES_SIZE"));
            byte[] content = res.getBytes(m_cq.get("C_RESOURCES_FILE_CONTENT"));
            int resProjectId = res.getInt(m_cq.get("C_RESOURCES_PROJECT_ID"));
            int lockedInProject = res.getInt("LOCKED_IN_PROJECT");
            file = new CmsFile(resId, parentId, fileId, filename, resType, resFlags, userId,
                               groupId, resProjectId, accessFlags, state, lockedBy, launcherType,
                               launcherClass, created, modified, modifiedBy, content, resSize, lockedInProject);
            // check if this resource is marked as deleted
            if (file.getState() == C_STATE_DELETED) {
                throw new CmsException("["+this.getClass().getName()+"] "+file.getAbsolutePath(),CmsException.C_RESOURCE_DELETED);
            }
        } else {
            throw new CmsException("[" + this.getClass().getName() + "] " + filename, CmsException.C_NOT_FOUND);
        }
    } catch (SQLException e) {
        throw new CmsException("[" + this.getClass().getName() + "] " + e.getMessage(), CmsException.C_SQL_ERROR, e);
    } catch (CmsException ex) {
        throw ex;
    } catch (Exception exc) {
        throw new CmsException("readFile " + exc.getMessage(), CmsException.C_UNKNOWN_EXCEPTION, exc);
    } finally {
            // close all db-resources
            if(res != null) {
                 try {
                     res.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
            if(statement != null) {
                 try {
                     statement.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
            if(con != null) {
                 try {
                     con.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
    }
    return file;
}

/**
 * Reads a file from the Cms.<BR/>
 *
 * @param projectId The Id of the project in which the resource will be used.
 * @param onlineProjectId The online projectId of the OpenCms.
 * @param filename The complete name of the new file (including pathinformation).
 *
 * @return file The read file.
 *
 * @throws CmsException Throws CmsException if operation was not succesful
 */
public CmsFile readFile(int projectId, int onlineProjectId, String filename, boolean includeDeleted) throws CmsException {
    CmsFile file = null;
    PreparedStatement statement = null;
    ResultSet res = null;
    Connection con = null;
    String usedPool;
    String usedStatement;
    if (projectId == onlineProjectId){
        usedPool = m_poolNameOnline;
        usedStatement = "_ONLINE";
    } else {
        usedPool = m_poolName;
        usedStatement = "";
    }
    try {
        con = DriverManager.getConnection(usedPool);
        statement = con.prepareStatement(m_cq.get("C_FILES_READ"+usedStatement));
        statement.setString(1, filename);
        statement.setInt(2, projectId);
        res = statement.executeQuery();
        if (res.next()) {
            int resId = res.getInt(m_cq.get("C_RESOURCES_RESOURCE_ID"));
            int parentId = res.getInt(m_cq.get("C_RESOURCES_PARENT_ID"));
            int resType = res.getInt(m_cq.get("C_RESOURCES_RESOURCE_TYPE"));
            int resFlags = res.getInt(m_cq.get("C_RESOURCES_RESOURCE_FLAGS"));
            int userId = res.getInt(m_cq.get("C_RESOURCES_USER_ID"));
            int groupId = res.getInt(m_cq.get("C_RESOURCES_GROUP_ID"));
            int fileId = res.getInt(m_cq.get("C_RESOURCES_FILE_ID"));
            int accessFlags = res.getInt(m_cq.get("C_RESOURCES_ACCESS_FLAGS"));
            int state = res.getInt(m_cq.get("C_RESOURCES_STATE"));
            int lockedBy = res.getInt(m_cq.get("C_RESOURCES_LOCKED_BY"));
            int launcherType = res.getInt(m_cq.get("C_RESOURCES_LAUNCHER_TYPE"));
            String launcherClass = res.getString(m_cq.get("C_RESOURCES_LAUNCHER_CLASSNAME"));
            long created = SqlHelper.getTimestamp(res, m_cq.get("C_RESOURCES_DATE_CREATED")).getTime();
            long modified = SqlHelper.getTimestamp(res, m_cq.get("C_RESOURCES_DATE_LASTMODIFIED")).getTime();
            int modifiedBy = res.getInt(m_cq.get("C_RESOURCES_LASTMODIFIED_BY"));
            int resSize = res.getInt(m_cq.get("C_RESOURCES_SIZE"));
            byte[] content = res.getBytes(m_cq.get("C_RESOURCES_FILE_CONTENT"));
            int resProjectId = res.getInt(m_cq.get("C_RESOURCES_PROJECT_ID"));
            int lockedInProject = res.getInt("LOCKED_IN_PROJECT");
            file = new CmsFile(resId, parentId, fileId, filename, resType, resFlags, userId,
                               groupId, resProjectId, accessFlags, state, lockedBy, launcherType,
                               launcherClass, created, modified, modifiedBy, content, resSize, lockedInProject);
            // check if this resource is marked as deleted
            if (file.getState() == C_STATE_DELETED &&!includeDeleted) {
                throw new CmsException("["+this.getClass().getName()+"] "+file.getAbsolutePath(),CmsException.C_RESOURCE_DELETED);
            }
        } else {
            throw new CmsException("[" + this.getClass().getName() + "] " + filename, CmsException.C_NOT_FOUND);
        }
    } catch (SQLException e) {
        throw new CmsException("[" + this.getClass().getName() + "] " + e.getMessage(), CmsException.C_SQL_ERROR, e);
    } catch (CmsException ex) {
        throw ex;
    } catch (Exception exc) {
        throw new CmsException("readFile " + exc.getMessage(), CmsException.C_UNKNOWN_EXCEPTION, exc);
    } finally {
            // close all db-resources
            if(res != null) {
                 try {
                     res.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
            if(statement != null) {
                 try {
                     statement.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
            if(con != null) {
                 try {
                     con.close();
                 } catch(SQLException exc) {
                     // nothing to do here
                 }
            }
    }
    return file;
}

    /**
     * Creates a new task.<p>
     * 
     * MySQL 4 does not support the SQL from the generic driver, so that's
     * why we have that special implementation here. 
     * This was tested with MySQL 4.0.10. 
     * 
     * @param rootId id of the root task project
     * @param parentId id of the parent task
     * @param tasktype type of the task
     * @param ownerId id of the owner
     * @param agentId id of the agent
     * @param roleId id of the role
     * @param taskname name of the task
     * @param wakeuptime time when the task will be wake up
     * @param timeout time when the task times out
     * @param priority priority of the task
     *

⌨️ 快捷键说明

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