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

📄 sqlstatements.java

📁 数据仓库工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                list.add("");
            }
        } else if (nameSQL.equalsIgnoreCase("CreatePrimary")) {
            list.add("");
            if (incompatibleDBSource) {
                if (k == 0) {
                    list.add("");
                }
            } else if (incompatibleDBTarget) {
                if (k == 0) {
                    list.add("");
                }
            } else {
                if (relationshipsAttributes.getPrimaryKeys().length != 0) {
                    int primaryCount = relationshipsAttributes.getPrimaryKeys().length;
                    for (int i = 0; i < primaryCount; i = i + 2) {
                        String arrayOfPrimaryNames = relationshipsAttributes.getPrimaryKeys()[i + 1];
                        for (int m = i + 2; m < primaryCount; m = m + 2) {
                            if (relationshipsAttributes.getPrimaryKeys()[i].equalsIgnoreCase(relationshipsAttributes.getPrimaryKeys()[m])) {

                                arrayOfPrimaryNames = arrayOfPrimaryNames + "," + relationshipsAttributes.getPrimaryKeys()[m + 1];
                                i = i + 2;
                            } else
                                break;
                        }

                        list.add("ALTER TABLE " + " " + relationshipsAttributes.getTableName() + " " + "ADD CONSTRAINT " + relationshipsAttributes.getPrimaryKeys()[i] + " PRIMARY KEY" + "(" +
                        //relationshipsAttributes.getPrimaryKeys()[i+1]+") ;");
                        arrayOfPrimaryNames + ") ;");
                    }
                } else {
                    list.add("");
                }
            } //end of main else
        } else if (nameSQL.equalsIgnoreCase("CreateIndex")) {
            list.add("");
            if (incompatibleDBSource) {
                if (k == 0) {
                    list.add("");
                }
            } else if (incompatibleDBTarget) {
                if (k == 0) {
                    list.add("");
                }
            } else {
                if (relationshipsAttributes.getIndexVariables().length != 0) {
                    int indexCount = relationshipsAttributes.getIndexVariables().length;
                    for (int i = 0; i < indexCount; i = i + 3) {
                        String arrayOfIndexNames = relationshipsAttributes.getIndexVariables()[i + 2];
                        for (int m = i + 3; m < indexCount; m = m + 3) {
                            if (relationshipsAttributes.getIndexVariables()[i + 1].equalsIgnoreCase(relationshipsAttributes.getIndexVariables()[m + 1])) {
                                arrayOfIndexNames = arrayOfIndexNames + "," + relationshipsAttributes.getIndexVariables()[m + 2];
                                i = i + 3;
                            } else
                                break;
                        }
                        if (relationshipsAttributes.getIndexVariables()[i].equalsIgnoreCase("0") || relationshipsAttributes.getIndexVariables()[i].equalsIgnoreCase("1")) {
                            //unique mey have the value  0 or 1
                            int j = Integer.parseInt(relationshipsAttributes.getIndexVariables()[i]);
                            String unique;
                            if (j == 1)
                                unique = "";
                            else
                                unique = "UNIQUE";
                            list.add("CREATE " + unique + " INDEX " + relationshipsAttributes.getIndexVariables()[i + 1] +
                            //" ON "+tableName+"("+relationshipsAttributes.getIndexVariables()[i+2]+") ;");
                            " ON " + tableName + "(" + arrayOfIndexNames + ") ;");

                        } else if (relationshipsAttributes.getIndexVariables()[i].equalsIgnoreCase("true") || relationshipsAttributes.getIndexVariables()[i].equalsIgnoreCase("false")) {
                            //unique mey have the value true or false
                            String unique;
                            String j = relationshipsAttributes.getIndexVariables()[i];
                            if (j.equalsIgnoreCase("true"))
                                unique = "";
                            else
                                unique = "UNIQUE";
                            list.add("CREATE " + unique + " INDEX " + relationshipsAttributes.getIndexVariables()[i + 1] +
                            //" ON "+tableName+"("+relationshipsAttributes.getIndexVariables()[i+2]+") ;");
                            " ON " + tableName + "(" + arrayOfIndexNames + ") ;");
                        }
                    }
                } else {
                    //relationshipsAttributes.getIndexVariables().length==0
                    list.add("");
                }
            }
        } else if (nameSQL.equalsIgnoreCase("CreateIntegrity")) {
            list.add("");
            if (incompatibleDBSource) {
                if (k == 0) {
                    list.add("");
                }
            } else if (incompatibleDBTarget) {
                if (k == 0) {
                    list.add("");
                }
            } else {
                //TODO ZK added relationshipsAttributes.getForeignVariables().length >= 5 because problems with c-jdbc
                if (relationshipsAttributes.getForeignVariables().length != 0 && relationshipsAttributes.getForeignVariables().length >= 5) {

                    for (int i = 0; i < relationshipsAttributes.getForeignVariables().length; i = i + 5) {

                        list.add("ALTER TABLE " + relationshipsAttributes.getForeignVariables()[i] + " ADD CONSTRAINT " + relationshipsAttributes.getForeignVariables()[i + 1] + " FOREIGN KEY (" + relationshipsAttributes.getForeignVariables()[i + 2] + ")" + " REFERENCES " + relationshipsAttributes.getForeignVariables()[i + 3] + " (" + relationshipsAttributes.getForeignVariables()[i + 4] + ") ;");
                    }
                } else {
                    list.add("");
                }
            }
        } else if (nameSQL.equalsIgnoreCase("DropTables")) {
            list.add("");
            list.add("DROP TABLE " + tableName + " ;");
            list.add("");
        } else if (nameSQL.equalsIgnoreCase("DropIntegrity")) {
            //TODO ZK added relationshipsAttributes.getForeignVariables().length >= 2 because problems with c-jdbc
            if (relationshipsAttributes.getForeignVariables().length != 0 && relationshipsAttributes.getForeignVariables().length >= 2) {

                for (int i = 0; i < relationshipsAttributes.getForeignVariables().length; i = i + 5) {
                    list.add("");
                    list.add("ALTER TABLE " + relationshipsAttributes.getForeignVariables()[i] + " DROP CONSTRAINT " + relationshipsAttributes.getForeignVariables()[i + 1] + " ;");
                    list.add("");
                }

            } else {
                list.add("");
            }

        }
        this.logger.write("full", "SqlStatements is finished.");
    }

    /**
     * This method sets the value of list patameter.
     * @param create_Stream is the value of parameter.
     */
    public void setCreateStream(String[] create_Stream) {
        list = Arrays.asList(create_Stream);
    }

    /**
     * This method read the value of list patameter.
     * @return value of parameter.
     */
    public String[] getCreateStream() {
        String[] ret = new String[list.size()];
        list.toArray(ret);
        return ret;
    }

    //  /**
    //   * This method check the type of named data type.
    //   * @param type is data type which we wont to check.
    //   * @return true or false.
    //   */
    //  private boolean checkType(String type) {
    //    for (int i = 0; i < uncompatibileTypes.length; i++) {
    //      if (type.toLowerCase().endsWith(uncompatibileTypes[i])) {
    //        this.incompatible = true;
    //        break;
    //      }
    //      else {
    //        this.incompatible = false;
    //      }
    //    }
    //    return incompatible;
    //  }

    private boolean checkDBTypeTarget(String type) {
        for (int i = 0; i < targetDBWithoutAlterTable.length; i++) {
            if (type.equalsIgnoreCase(targetDBWithoutAlterTable[i])) {
                this.incompatibleDBTarget = true;
                break;
            } else {
                this.incompatibleDBTarget = false;
            }
        }
        return incompatibleDBTarget;
    }

    private boolean checkDBTypeSource(String type) {
        for (int i = 0; i < targetDBWithoutAlterTable.length; i++) {
            if (type.equalsIgnoreCase(targetDBWithoutAlterTable[i])) {
                this.incompatibleDBSource = true;
                break;
            } else {
                this.incompatibleDBSource = false;
            }
        }
        return incompatibleDBSource;
    }

    /**
    			* This method will set logger object
    			* @param logger
    			*/
    private void setLogger() {
        this.logger = StandardLogger.getCentralLogger();
    }
}

⌨️ 快捷键说明

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