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

📄 cmsupdatedbprojectid.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    } catch (SQLException e) {
                        result = true;
                    }
                }
            }
        } finally {
            if (db != null) {
                db.close();
            }
        }
        return result;
    }

    /**
     * Transfers the data from the CMS_BACKUP_PROJECTS to the CMS_HISTORY_PROJECTS table.<p>
     * 
     * The datetime type for the column PROJECT_PUBLISHDATE is converted to the new long value.<p>
     * 
     * @param dbCon the db connection interface
     * 
     * @throws SQLException if something goes wrong
     */
    protected void transferDataToHistoryTable(CmsSetupDb dbCon) throws SQLException {

        if (!isKeepHistory()) {
            return;
        }
        System.out.println(new Exception().getStackTrace()[0].toString());
        // Get the data from the CMS_BACKUP table
        String query = readQuery(QUERY_SELECT_DATA_FROM_BACKUP_PROJECTS);
        CmsSetupDBWrapper db = null;
        try {
            db = dbCon.executeSqlStatement(query, null);

            String insertQuery = readQuery(QUERY_INSERT_CMS_HISTORY_TABLE);
            while (db.getResultSet().next()) {
                // Add the values to be inserted into the CMS_HISTORY_PROJECTS table
                List params = new ArrayList();
                params.add(db.getResultSet().getString("PROJECT_UUID"));
                params.add(db.getResultSet().getString("PROJECT_NAME"));
                params.add(db.getResultSet().getString("PROJECT_DESCRIPTION"));
                params.add(new Integer(db.getResultSet().getInt("PROJECT_TYPE")));
                params.add(db.getResultSet().getString("USER_ID"));
                params.add(db.getResultSet().getString("GROUP_ID"));
                params.add(db.getResultSet().getString("MANAGERGROUP_ID"));
                params.add(new Long(db.getResultSet().getLong("DATE_CREATED")));
                params.add(new Integer(db.getResultSet().getInt("PUBLISH_TAG")));
                Date date = db.getResultSet().getDate("PROJECT_PUBLISHDATE");
                params.add(new Long(date.getTime()));
                params.add(db.getResultSet().getString("PROJECT_PUBLISHED_BY"));
                params.add(db.getResultSet().getString("PROJECT_OU"));

                dbCon.updateSqlStatement(insertQuery, null, params);
            }
        } finally {
            if (db != null) {
                db.close();
            }
        }

    }

    /**
     * Drops the column of the given table.<p>
     * 
     * @param dbCon the db connection interface
     * @param tablename the table in which the columns shall be dropped
     * @param column the column to drop
     * 
     * @throws SQLException if something goes wrong 
     */
    private void dropColumn(CmsSetupDb dbCon, String tablename, String column) throws SQLException {

        System.out.println(new Exception().getStackTrace()[0].toString());
        if (dbCon.hasTableOrColumn(tablename, column)) {
            String query = readQuery(QUERY_DROP_COLUMN);
            Map replacer = new HashMap();
            replacer.put(REPLACEMENT_TABLENAME, tablename);
            replacer.put(REPLACEMENT_COLUMN, column);
            dbCon.updateSqlStatement(query, replacer, null);
        } else {
            System.out.println("column " + column + " in table " + tablename + " does not exist");
        }
    }

    /**
     * Updates the given table with the new UUID value.<p>
     * 
     * @param dbCon the db connection interface
     * @param tablename the table to update
     * @param column the column to update
     * @param newvalue the new value to insert
     * @param oldid the old id to compare the old value to
     * @param tempValue the old value in the temporary table
     * 
     * @throws SQLException if something goes wrong
     */
    private void fillUUIDSColumn(
        CmsSetupDb dbCon,
        String tablename,
        String column,
        String newvalue,
        String oldid,
        String tempValue) throws SQLException {

        System.out.println(new Exception().getStackTrace()[0].toString());
        if (dbCon.hasTableOrColumn(tablename, column)) {
            String query = readQuery(QUERY_TRANSFER_UUID);
            Map replacer = new HashMap();
            replacer.put(REPLACEMENT_TABLENAME, tablename);
            replacer.put(REPLACEMENT_COLUMN, column);
            replacer.put(REPLACEMENT_OLDID, oldid);
            List params = new ArrayList();
            params.add(newvalue);
            params.add(new Integer(tempValue)); // Change type to integer

            dbCon.updateSqlStatement(query, replacer, params);
        } else {
            System.out.println("column " + column + " in table " + tablename + " does not exists");
        }
    }

    /**
     * Generates the new UUIDs for the project ids.<p>
     * The new uuids are stored in the temporary table.<p>
     * 
     * @param dbCon the db connection interface
     * 
     * @throws SQLException if something goes wrong 
     */
    private void generateUUIDs(CmsSetupDb dbCon) throws SQLException {

        System.out.println(new Exception().getStackTrace()[0].toString());
        String query = readQuery(QUERY_GET_PROJECT_IDS);

        CmsSetupDBWrapper db = null;
        try {
            db = dbCon.executeSqlStatement(query, null);
            ResultSetMetaData metaData = db.getResultSet().getMetaData();
            // Check the type of the column if it is integer, then create the new uuids
            int columnType = metaData.getColumnType(1);
            if (checkColumnTypeProjectId(columnType)) {
                if (!dbCon.hasTableOrColumn(TEMPORARY_TABLE_NAME, null)) {
                    createTempTable(dbCon);

                    String updateQuery = readQuery(QUERY_INSERT_UUIDS);
                    List params = new ArrayList();
                    // Get the project id and insert it with a new uuid into the temp table
                    boolean hasNullId = false;
                    while (db.getResultSet().next()) {
                        int id = db.getResultSet().getInt("PROJECT_ID");
                        params.add(new Integer(id)); // Add the number
                        CmsUUID uuid = new CmsUUID();

                        // Check for 0 project id
                        if (id == 0) {
                            hasNullId = true;
                            uuid = CmsUUID.getNullUUID();
                        }
                        // Check for the online project
                        if (id == 1) {
                            uuid = CmsProject.ONLINE_PROJECT_ID;
                        }
                        params.add(uuid.toString()); // Add the uuid

                        // Insert the values to the temp table
                        dbCon.updateSqlStatement(updateQuery, null, params);

                        params.clear();
                    }

                    // If no project id with value 0 was found 
                    if (!hasNullId) {
                        params.add(new Integer(0));
                        params.add(CmsUUID.getNullUUID().toString());
                        dbCon.updateSqlStatement(updateQuery, null, params);
                    }
                } else {
                    System.out.println("table " + TEMPORARY_TABLE_NAME + " already exists");
                }
            }
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }

    /**
     * Gets the UUIDs from the temporary table TEMP_CMS_UUIDS.<p>
     *  
     * @param dbCon the db connection interface
     * 
     * @return a map with the old project ids and the new uuids
     * 
     * @throws SQLException if something goes wrong 
     */
    private Map getUUIDs(CmsSetupDb dbCon) throws SQLException {

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

        String query = readQuery(QUERY_GET_UUIDS);
        CmsSetupDBWrapper db = null;
        try {
            db = dbCon.executeSqlStatement(query, null);
            while (db.getResultSet().next()) {
                String key = Integer.toString(db.getResultSet().getInt(COLUMN_PROJECT_ID));
                String value = db.getResultSet().getString(COLUMN_PROJECT_UUID);

                result.put(key, value);
            }
        } finally {
            if (db != null) {
                db.close();
            }
        }
        return result;
    }

    /**
     * Renames the column of the given table the new name.<p>
     * 
     * @param dbCon the db connection interface
     * @param tablename the table in which the column shall be renamed
     * @param oldname the old name of the column
     * @param newname the new name of the column
     * 
     * @throws SQLException if something goes wrong
     */
    private void renameColumn(CmsSetupDb dbCon, String tablename, String oldname, String newname) throws SQLException {

        System.out.println(new Exception().getStackTrace()[0].toString());
        if (dbCon.hasTableOrColumn(tablename, oldname)) {
            String query = readQuery(QUERY_RENAME_COLUMN);
            Map replacer = new HashMap();
            replacer.put(REPLACEMENT_TABLENAME, tablename);
            replacer.put(REPLACEMENT_COLUMN, oldname);
            replacer.put(REPLACEMENT_NEW_COLUMN, newname);

            dbCon.updateSqlStatement(query, replacer, null);
        } else {
            System.out.println("column " + oldname + " in table " + tablename + " not found exists");
        }
    }
}

⌨️ 快捷键说明

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