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

📄 cmsupdatedbprojectid.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * @param type the type of the column from the meta data
     * 
     * @return true if the type is incorrect
     */
    protected boolean checkColumnTypeProjectId(int type) {

        return type == java.sql.Types.INTEGER;
    }

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

        System.out.println(new Exception().getStackTrace()[0].toString());
        if (!dbCon.hasTableOrColumn(HISTORY_PROJECTS_TABLE, null)) {
            String createStatement = readQuery(QUERY_CREATE_HISTORY_PROJECTS_TABLE);
            dbCon.updateSqlStatement(createStatement, null, null);
            transferDataToHistoryTable(dbCon);
        } else {
            System.out.println("table " + HISTORY_PROJECTS_TABLE + " already exists");
        }
    }

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

        System.out.println(new Exception().getStackTrace()[0].toString());
        if (!dbCon.hasTableOrColumn(TEMPORARY_TABLE_NAME, null)) {
            String createStatement = readQuery(QUERY_CREATE_TEMP_TABLE_UUIDS);
            dbCon.updateSqlStatement(createStatement, null, null);
        } else {
            System.out.println("table " + TEMPORARY_TABLE_NAME + " already exists");
        }
    }

    /**
     * Returns the columns for the primary key of the project resources table.<p>
     * 
     * @return the columns for the primary key of the project resources table
     */
    protected String getColumnProjectIdResourcePath() {

        return COLUMN_PROJECT_ID_RESOURCE_PATH;
    }

    /**
     * @see org.opencms.setup.update6to7.A_CmsUpdateDBPart#internalExecute(org.opencms.setup.CmsSetupDb)
     */
    protected void internalExecute(CmsSetupDb dbCon) throws SQLException {

        System.out.println(new Exception().getStackTrace()[0].toString());

        generateUUIDs(dbCon);

        createHistProjectsTable(dbCon);

        Map uuids = getUUIDs(dbCon); // Get the UUIDS

        /*
         * Add the temporary column for the new UUIDs and fill it with data
         */
        for (Iterator it = TABLES_LIST.iterator(); it.hasNext();) {
            String tablename = (String)it.next();

            if (needsUpdating(dbCon, tablename)) {
                addUUIDColumnToTable(dbCon, tablename, TEMP_UUID_COLUMN);
                boolean isInResourcesList = RESOURCES_TABLES_LIST.contains(tablename);
                // Add the new uuids
                Iterator entries = uuids.entrySet().iterator();
                while (entries.hasNext()) {
                    Map.Entry entry = (Map.Entry)entries.next();
                    if (entry.getKey() != null && entry.getValue() != null) {
                        if (isInResourcesList) {
                            fillUUIDSColumn(
                                dbCon,
                                tablename,
                                TEMP_UUID_COLUMN,
                                (String)entry.getValue(),
                                COLUMN_PROJECT_LASTMODIFIED,
                                (String)entry.getKey());
                        } else {
                            fillUUIDSColumn(
                                dbCon,
                                tablename,
                                TEMP_UUID_COLUMN,
                                (String)entry.getValue(),
                                COLUMN_PROJECT_ID,
                                (String)entry.getKey());
                        }
                    }
                }

                /*
                 * In this phase the primary keys or indexes are dropped and the old columns containing the 
                 * old project ids are dropped. After that the temporary columns are renamed and the new
                 * indexes and primary keys are added.
                 */
                if (isInResourcesList) {
                    // fix lost project ids
                    Map replacer = Collections.singletonMap("${tablename}", tablename);
                    List params = Collections.singletonList(CmsUUID.getNullUUID().toString());
                    String query = readQuery(QUERY_UPDATE_NULL_PROJECTID);
                    dbCon.updateSqlStatement(query, replacer, params);

                    // Drop the column PROJECT_LASTMODIFIED
                    dropColumn(dbCon, tablename, COLUMN_PROJECT_LASTMODIFIED);
                    // rename the column TEMP_PROJECT_UUID to PROJECT_LASTMODIFIED
                    renameColumn(dbCon, tablename, COLUMN_TEMP_PROJECT_UUID, COLUMN_PROJECT_LASTMODIFIED);
                } else {
                    // drop the columns
                    dropColumn(dbCon, tablename, COLUMN_PROJECT_ID);

                    // rename the column TEMP_PROJECT_UUID to PROJECT_ID
                    renameColumn(dbCon, tablename, COLUMN_TEMP_PROJECT_UUID, COLUMN_PROJECT_ID);

                    // add the new primary key
                    if (tablename.equals("CMS_PROJECTRESOURCES")) {
                        addPrimaryKey(dbCon, tablename, getColumnProjectIdResourcePath());
                    }
                    if (tablename.equals("CMS_PROJECTS")) {
                        addPrimaryKey(dbCon, tablename, COLUMN_PROJECT_ID);
                    }
                }
            } else {
                System.out.println("table " + tablename + " does not need to be updated");
            }
        }

        CmsSetupDBWrapper db = null;
        boolean update = false;
        try {
            db = dbCon.executeSqlStatement(readQuery(QUERY_SELECT_COUNT_HISTORY_TABLE), null);

            if (db.getResultSet().next()) {
                if (db.getResultSet().getInt("COUNT") <= 0) {
                    update = true;
                }
            }
        } finally {
            if (db != null) {
                db.close();
            }
        }
        if (update) {
            System.out.println("table " + HISTORY_PROJECTS_TABLE + " has no content, create a dummy entry");

            CmsUUID userId = CmsUUID.getNullUUID();
            try {
                db = dbCon.executeSqlStatement(readQuery(QUERY_READ_ADMIN_USER), null);
                if (db.getResultSet().next()) {
                    userId = new CmsUUID(db.getResultSet().getString(1));
                }
            } finally {
                if (db != null) {
                    db.close();
                }
            }
            CmsUUID groupId = CmsUUID.getNullUUID();
            try {
                db = dbCon.executeSqlStatement(readQuery(QUERY_READ_ADMIN_GROUP), null);
                if (db.getResultSet().next()) {
                    groupId = new CmsUUID(db.getResultSet().getString(1));
                }
            } finally {
                if (db != null) {
                    db.close();
                }
            }
            // read publish tag
            int pubTag = 1;
            String query = readQuery(QUERY_READ_MAX_PUBTAG);
            try {
                db = dbCon.executeSqlStatement(query, null);
                if (db.getResultSet().next()) {
                    pubTag = db.getResultSet().getInt(1);
                }
            } finally {
                if (db != null) {
                    db.close();
                }
            }

            List params = new ArrayList();
            params.add(new CmsUUID().toString());
            params.add("updateWizardDummyProject");
            params.add("dummy project just for having an entry");
            params.add(new Integer(1));
            params.add(userId.toString());
            params.add(groupId.toString());
            params.add(groupId.toString());
            params.add(new Long(System.currentTimeMillis()));
            params.add(new Integer(pubTag));
            params.add(new Long(System.currentTimeMillis()));
            params.add(userId.toString());
            params.add(CmsOrganizationalUnit.SEPARATOR);

            query = readQuery(QUERY_INSERT_CMS_HISTORY_TABLE);
            dbCon.updateSqlStatement(query, null, params);
        } else {
            System.out.println("table " + HISTORY_PROJECTS_TABLE + " has content");
        }
    }

    /**
     * Checks if the given table needs an update of the uuids.<p>
     * 
     * @param dbCon the db connection interface
     * @param tablename the table to check
     * 
     * @return true if the project ids are not yet updated, false if nothing needs to be done
     * 
     * @throws SQLException if something goes wrong 
     */
    protected boolean needsUpdating(CmsSetupDb dbCon, String tablename) throws SQLException {

        System.out.println(new Exception().getStackTrace()[0].toString());
        boolean result = true;

        String query = readQuery(QUERY_DESCRIBE_TABLE);
        Map replacer = new HashMap();
        replacer.put(REPLACEMENT_TABLENAME, tablename);
        CmsSetupDBWrapper db = null;

        try {
            db = dbCon.executeSqlStatement(query, replacer);

            while (db.getResultSet().next()) {
                String fieldname = db.getResultSet().getString("Field");
                if (fieldname.equals(COLUMN_PROJECT_ID) || fieldname.equals(COLUMN_PROJECT_LASTMODIFIED)) {
                    try {
                        String fieldtype = db.getResultSet().getString("Type");
                        // If the type is varchar then no update needs to be done.
                        if (fieldtype.indexOf("varchar") > 0) {
                            return false;
                        }

⌨️ 快捷键说明

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