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

📄 createtablescriptsgenerator.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        int l_size = sepLength - column.getColumnName().length();                                                for (int m = 0; m < l_size; m++) {                            sb_spaces_2.append(SPACE);                        }                        sb.append(column.getColumnName()).                           append(sb_spaces_2).                           append(column.getFormattedDataType());                                                sb.append(column.isRequired() ? NOT_NULL : EMPTY);                                                if (column.isKey() && includeConstraints) {                                                        Vector ccv = column.getColumnConstraintsVector();                                                        for (int a = 0, b = ccv.size(); a < b; a++) {                                columnConstraints.add(ccv.elementAt(a));                            }                                                     }                                                 if (j != cda.length - 1) {                            sb.append(COMMA).append(NEW_LINE);                        }                                                sb_spaces_2.setLength(0);                    }                                         int v_size = columnConstraints.size();                                        if (v_size > 0) {                                                if (useCreateForConstraints) {                            sb.append(COMMA).append(NEW_LINE);                                                        ColumnConstraint cc = null;                            for (int j = 0; j < v_size; j++) {                                cc = (ColumnConstraint)columnConstraints.get(j);                                sb.append(spaces_1).append(CONSTRAINT).                                append(cc.getName()).append(SPACE).                                append(cc.getTypeName()).append(KEY).                                append(B_OPEN).append(cc.getColumn()).                                append(B_CLOSE);                                                                if (cc.getType() == ColumnConstraint.FOREIGN_KEY) {                                    sb.append(REFERENCES);                                                                        if (cc.hasSchema())                                        sb.append(cc.getRefSchema()).append(DOT);                                                                        sb.append(cc.getRefTable()).append(B_OPEN).                                    append(cc.getRefColumn()).append(B_CLOSE);                                }                                                                 cc = null;                                                                if (j < v_size -1)                                    sb.append(COMMA).append(NEW_LINE);                                                            }                                                     }                                                 else if (useAlterForConstraints) {                            int type = -1;                            ColumnConstraint cc = null;                                                        for (int j = 0; j < v_size; j++) {                                cc = (ColumnConstraint)columnConstraints.get(j);                                type = cc.getType();                                                                if (type == ColumnConstraint.FOREIGN_KEY) {                                                                        fKeys.append(ALTER_TABLE).append(cc.getTable()).                                          append(ADD).append(CONSTRAINT).                                          append(cc.getName()).append(SPACE).                                          append(cc.getTypeName()).append(KEY).                                          append(B_OPEN).append(cc.getColumn()).                                          append(B_CLOSE).append(REFERENCES);                                                                        //                                  if (cc.hasSchema())                                    //                                    fKeys.append(cc.getSchema()).append(DOT);                                                                        fKeys.append(cc.getRefTable()).append(B_OPEN).                                    append(cc.getRefColumn()).append(B_CLOSE).                                    append(SEMI_COLON).append(NEW_LINE);                                }                                                                 else if (type == ColumnConstraint.PRIMARY_KEY) {                                                                        pKeys.append(ALTER_TABLE).append(cc.getTable()).                                    append(ADD).append(CONSTRAINT).                                    append(cc.getName()).append(SPACE).                                    append(cc.getTypeName()).append(KEY).                                    append(B_OPEN).append(cc.getColumn()).                                    append(B_CLOSE).append(SEMI_COLON).append(NEW_LINE);                                }                                                                 cc = null;                                                            }                                                     }                                             }                                         sb.append(B_CLOSE).append(SEMI_COLON).                    append(NEW_LINE).append(NEW_LINE);                                        spaces_1 = null;                                    } else {                    sb.append(B_CLOSE).append(SEMI_COLON).                    append(NEW_LINE).append(NEW_LINE);                }                                 writer.println(sb.toString());                sb_script.append(sb).append(NEW_LINE);                                sb.setLength(0);                sb_spaces_1.setLength(0);                columnConstraints.clear();                                cda = null;                tableName = null;                                progDialog.setStatus(i+1);            }                         if (fKeys != null && pKeys != null) {                pKeys.append(NEW_LINE).                      append(NEW_LINE).                      append(fKeys);                writer.println(pKeys.toString());                sb_script.append(pKeys);            }                         sb = null;            pKeys = null;            fKeys = null;            sb_spaces_1 = null;            sb_spaces_2 = null;            initialSpaces = null;            columnConstraints = null;                        result.put("Done", file.getName());            result.put("script", sb_script.toString());            sb_script = null;            return result;                    }                 catch (IOException e) {            result.put("Failed", e);            return result;        }                 catch (InterruptedException e) {            result.put("cancelled", EMPTY);            return result;        }                 finally {            if (writer != null) {                writer.close();                writer = null;            }        }             }        public void cancelTransfer() {        if (worker != null) {            worker.interrupt();        }    }        private int getSpaceLength(ColumnData[] cda) {        int spaces = 0;        // spaces between end of column name and data type name        for (int i = 0; i < cda.length; i++) {            spaces = Math.max(spaces, cda[i].getColumnName().length());        }         return spaces;    }        class ProgressDialog extends JDialog                                  implements ActionListener {                private JProgressBar transferProg;        private JButton cancButton;        private int max;                public ProgressDialog(int tables) {            super(GUIUtilities.getParentFrame(), "Progress", false);            max = tables;            transferProg = new JProgressBar(1, max);            transferProg.setPreferredSize(new Dimension(230, 20));                        cancButton = new JButton("Cancel");            cancButton.addActionListener(this);                        JPanel base = new JPanel(new GridBagLayout());                        GridBagConstraints gbc = new GridBagConstraints();            Insets ins = new Insets(10,10,10,10);            gbc.insets = ins;            gbc.anchor = GridBagConstraints.NORTHWEST;            gbc.fill = GridBagConstraints.HORIZONTAL;            base.add(new JLabel("Generating SQL script..."), gbc);            gbc.gridy = 1;            gbc.insets.top = 0;            gbc.anchor = GridBagConstraints.CENTER;            base.add(transferProg, gbc);            gbc.insets.bottom = 10;            gbc.fill = GridBagConstraints.NONE;            gbc.gridy = 2;            base.add(cancButton, gbc);                        getContentPane().setLayout(new BorderLayout());            getContentPane().add(base, BorderLayout.CENTER);                        setResizable(false);                        pack();            setLocation(GUIUtilities.getLocationForDialog(getSize()));            setVisible(true);                    }                public void actionPerformed(ActionEvent e) {            cancelTransfer();         }        public void setStatus(int value) {                        if (value == -1)                setProgressStatus(max+1);            else                setProgressStatus(value);        }                private void setProgressStatus(final int status) {            Runnable setProgressBarValue = new Runnable() {                public void run() {                    transferProg.setValue(status);                }            };                        setProgressBarValue.run();                    }            } // ProgressDialog        }

⌨️ 快捷键说明

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