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

📄 cmsupdatedbcmsusers.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        db.close();
                    }
                }

                // add the column USER_DATECREATED
                addUserDateCreated(dbCon);

                // remove the unnecessary columns from CMS_USERS
                removeUnnecessaryColumns(dbCon);

            } else {
                System.out.println("table " + CHECK_CMS_USERDATA + " already exists");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * Adds the new column USER_DATECREATED to the CMS_USERS table.<p> 
     * 
     * @param dbCon the db connection interface
     * 
     * @throws SQLException if something goes wrong 
     */
    protected void addUserDateCreated(CmsSetupDb dbCon) throws SQLException {

        System.out.println(new Exception().getStackTrace()[0].toString());
        // Add the column to the table if necessary
        if (!dbCon.hasTableOrColumn(CMS_USERS_TABLE, USER_DATECREATED)) {
            String addUserDateCreated = readQuery(QUERY_ADD_USER_DATECREATED_COLUMN);
            dbCon.updateSqlStatement(addUserDateCreated, null, null);

            String setUserDateCreated = readQuery(QUERY_SET_USER_DATECREATED);
            List param = new ArrayList();
            // Set the creation date to the current time
            param.add(new Long(System.currentTimeMillis()));

            dbCon.updateSqlStatement(setUserDateCreated, null, param);
        } else {
            System.out.println("column " + USER_DATECREATED + " in table " + CMS_USERS_TABLE + " already exists");
        }
    }

    /**
     * Adds all webusers to the new previously created webusers group.<p>
     * 
     * @param dbCon the db connection interface
     * @param id the id of the new webusers group
     * 
     * @throws SQLException if something goes wrong 
     */
    protected void addWebusersToGroup(CmsSetupDb dbCon, CmsUUID id) throws SQLException {

        String sql = readQuery(QUERY_ADD_WEBUSERS_TO_GROUP);
        Map replacements = new HashMap();
        replacements.put("${GROUP_ID}", id.toString());
        dbCon.updateSqlStatement(sql, replacements, null);
    }

    /**
     * Checks if the CMS_USERDATA table exists.<p> 
     * 
     * @param dbCon the db connection interface
     * 
     * @return true if it exists, false if not.
     */
    protected boolean checkUserDataTable(CmsSetupDb dbCon) {

        System.out.println(new Exception().getStackTrace()[0].toString());
        return dbCon.hasTableOrColumn(CHECK_CMS_USERDATA, null);
    }

    /**
     * Creates the CMS_USERDATA table if it does not exist yet.<p>
     *  
     * @param dbCon the db connection interface
     * 
     * @throws SQLException if soemthing goes wrong
     */
    protected void createUserDataTable(CmsSetupDb dbCon) throws SQLException {

        System.out.println(new Exception().getStackTrace()[0].toString());
        String createStatement = readQuery(QUERY_CREATE_TABLE_USERDATA);
        dbCon.updateSqlStatement(createStatement, null, null);
    }

    /**
     * creates a new group for the webusers.<p>
     * 
     * @param dbCon the db connection interface
     * 
     * @return the id of the new generated group
     * 
     * @throws SQLException if something goes wrong 
     */
    protected CmsUUID createWebusersGroup(CmsSetupDb dbCon) throws SQLException {

        String sql = readQuery(QUERY_CREATE_WEBUSERS_GROUP);
        List params = new ArrayList();
        CmsUUID id = new CmsUUID();
        params.add(id.toString());
        params.add(CmsUUID.getNullUUID().toString());
        params.add("allWebusersFromUpgrade6to7");
        params.add("This group was created by the OpenCms Upgrade Wizard to facilitate the handling of former called WebUsers, can be deleted if needed.");
        params.add(new Integer(0));
        params.add("/");
        dbCon.updateSqlStatement(sql, null, params);
        return id;
    }

    /**
     * Removes the columns USER_INFO, USER_ADDRESS, USER_DESCRIPTION and USER_TYPE from the CMS_USERS table.<p>
     * 
     * @param dbCon the db connection interface
     * 
     * @throws SQLException if something goes wrong 
     */
    protected void removeUnnecessaryColumns(CmsSetupDb dbCon) throws SQLException {

        System.out.println(new Exception().getStackTrace()[0].toString());
        // Get the sql queries to drop the columns
        String dropUserInfo = readQuery(QUERY_DROP_USER_INFO_COLUMN);
        String dropUserAddress = readQuery(QUERY_DROP_USER_ADDRESS_COLUMN);
        String dropUserDescription = readQuery(QUERY_DROP_USER_DESCRIPTION_COLUMN);
        String dropUserType = readQuery(QUERY_DROP_USER_TYPE_COLUMN);

        // execute the queries to drop the columns, if they exist
        if (dbCon.hasTableOrColumn(CMS_USERS_TABLE, USER_INFO)) {
            dbCon.updateSqlStatement(dropUserInfo, null, null);
        } else {
            System.out.println("no column " + USER_INFO + " in table " + CMS_USERS_TABLE + " found");
        }
        if (dbCon.hasTableOrColumn(CMS_USERS_TABLE, USER_ADDRESS)) {
            dbCon.updateSqlStatement(dropUserAddress, null, null);
        } else {
            System.out.println("no column " + USER_ADDRESS + " in table " + CMS_USERS_TABLE + " found");
        }
        if (dbCon.hasTableOrColumn(CMS_USERS_TABLE, USER_DESCRIPTION)) {
            dbCon.updateSqlStatement(dropUserDescription, null, null);
        } else {
            System.out.println("no column " + USER_DESCRIPTION + " in table " + CMS_USERS_TABLE + " found");
        }
        if (dbCon.hasTableOrColumn(CMS_USERS_TABLE, USER_TYPE)) {
            dbCon.updateSqlStatement(dropUserType, null, null);
        } else {
            System.out.println("no column " + USER_TYPE + " in table " + CMS_USERS_TABLE + " found");
        }
    }

    /**
     * Writes the additional user infos to the database.<p>
     * 
     * @param dbCon the db connection interface
     * @param id the user id
     * @param additionalInfo the additional info of the user
     */
    protected void writeAdditionalUserInfo(CmsSetupDb dbCon, String id, Map additionalInfo) {

        Iterator entries = additionalInfo.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry)entries.next();
            if (entry.getKey() != null && entry.getValue() != null) {
                // Write the additional user information to the database
                writeUserInfo(dbCon, id, (String)entry.getKey(), entry.getValue());
            }
        }
    }

    /**
     * Writes one set of additional user info (key and its value) to the CMS_USERDATA table.<p>
     * 
     * @param dbCon the db connection interface
     * @param id the user id 
     * @param key the data key
     * @param value the data value
     */
    protected void writeUserInfo(CmsSetupDb dbCon, String id, String key, Object value) {

        String query = readQuery(QUERY_INSERT_CMS_USERDATA);

        try {
            // Generate the list of parameters to add into the user info table
            List params = new ArrayList();
            params.add(id);
            params.add(key);
            params.add(value);
            params.add(value.getClass().getName());

            dbCon.updateSqlStatement(query, null, params);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

⌨️ 快捷键说明

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