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

📄 transfer.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            f.show();            String file = f.getDirectory() + f.getFile();            if (file != null) {                LoadPrefs(file);                displayTable(tCurrent);            }        } else if (s.equals("Save Settings...")) {            FileDialog f = new FileDialog(fMain, "Save Settings",                                          FileDialog.SAVE);            f.show();            String file = f.getDirectory() + f.getFile();            if (file != null) {                SavePrefs(file);            }        } else if (s.equals("Exit")) {            windowClosing(null);        }    }    /**     * Method declaration     *     *     * @param e     */    public void windowActivated(WindowEvent e) {}    /**     * Method declaration     *     *     * @param e     */    public void windowDeactivated(WindowEvent e) {}    /**     * Method declaration     *     *     * @param e     */    public void windowClosed(WindowEvent e) {}    private void cleanup() {        try {            if (sourceDb != null) {                sourceDb.close();            }            if (targetDb != null) {                targetDb.close();            }        } catch (Exception e) {}    }    /**     * Method declaration     *     *     * @param ev     */    public void windowClosing(WindowEvent ev) {        fMain.dispose();        if (bMustExit) {            System.exit(0);        }    }    /**     * Method declaration     *     *     * @param e     */    public void windowDeiconified(WindowEvent e) {}    /**     * Method declaration     *     *     * @param e     */    public void windowIconified(WindowEvent e) {}    /**     * Method declaration     *     *     * @param e     */    public void windowOpened(WindowEvent e) {}    /**     * Method declaration     *     */    private void initGUI() {        Font fFont = new Font("Dialog", Font.PLAIN, 12);        setLayout(new BorderLayout());        Panel p = new Panel();        p.setBackground(SystemColor.control);        p.setLayout(new GridLayout(16, 1));        tSourceTable = new TextField();        tSourceTable.setEnabled(false);        tDestTable = new TextField();        tDestTable.addActionListener(this);        tDestDrop = new TextField();        tDestDrop.addActionListener(this);        tDestCreate = new TextField();        tDestCreate.addActionListener(this);        tDestDelete = new TextField();        tDestDelete.addActionListener(this);        tDestCreateIndex = new TextField();        tDestCreateIndex.addActionListener(this);        tDestDropIndex = new TextField();        tDestDropIndex.addActionListener(this);        tSourceSelect = new TextField();        tSourceSelect.addActionListener(this);        tDestInsert = new TextField();        tDestInsert.addActionListener(this);        tDestAlter = new TextField();        tDestAlter.addActionListener(this);        cTransfer = new Checkbox("Transfer to destination table", true);        cTransfer.addItemListener(this);        cDrop = new Checkbox("Drop destination table (ignore error)", true);        cDrop.addItemListener(this);        cCreate = new Checkbox("Create destination table", true);        cCreate.addItemListener(this);        cDropIndex = new Checkbox("Drop destination index (ignore error)",                                  true);        cDropIndex.addItemListener(this);        cIdxForced = new Checkbox("force Idx_ prefix for indexes names",                                  false);        cIdxForced.addItemListener(this);        cCreateIndex = new Checkbox("Create destination index", true);        cCreateIndex.addItemListener(this);        cDelete = new Checkbox("Delete rows in destination table", true);        cDelete.addItemListener(this);        cInsert = new Checkbox("Insert into destination", true);        cInsert.addItemListener(this);        cFKForced = new Checkbox("force FK_ prefix for foreign key names",                                 false);        cFKForced.addItemListener(this);        cAlter = new Checkbox("Alter destination table", true);        cAlter.addItemListener(this);        p.add(createLabel("Source table"));        p.add(tSourceTable);        p.add(cTransfer);        p.add(tDestTable);        p.add(cDrop);        p.add(tDestDrop);        p.add(cCreate);        p.add(tDestCreate);        p.add(cDropIndex);        p.add(tDestDropIndex);        p.add(cCreateIndex);        p.add(tDestCreateIndex);        p.add(cDelete);        p.add(tDestDelete);        p.add(cAlter);        p.add(tDestAlter);        p.add(createLabel("Select source records"));        p.add(tSourceSelect);        p.add(cInsert);        p.add(tDestInsert);        p.add(createLabel(""));        p.add(createLabel(""));        p.add(cIdxForced);        p.add(cFKForced);        p.add(createLabel(""));        p.add(createLabel(""));        if (iTransferMode == TRFM_TRANSFER) {            bStart    = new Button("Start Transfer");            bContinue = new Button("Continue Transfer");            bContinue.setEnabled(false);        } else if (iTransferMode == Transfer.TRFM_DUMP) {            bStart = new Button("Start Dump");        } else if (iTransferMode == Transfer.TRFM_RESTORE) {            bStart = new Button("Start Restore");        }        bStart.addActionListener(this);        p.add(bStart);        if (iTransferMode == TRFM_TRANSFER) {            bContinue.addActionListener(this);            p.add(bContinue);        }        bStart.setEnabled(false);        fMain.add("Center", createBorderPanel(p));        lTable = new java.awt.List(10);        lTable.addItemListener(this);        fMain.add("West", createBorderPanel(lTable));        tMessage = new TextField();        Panel pMessage = createBorderPanel(tMessage);        fMain.add("South", pMessage);    }    /**     * Method declaration     *     *     * @param center     *     * @return     */    private Panel createBorderPanel(Component center) {        Panel p = new Panel();        p.setBackground(SystemColor.control);        p.setLayout(new BorderLayout());        p.add("Center", center);        p.add("South", createLabel(""));        p.add("East", createLabel(""));        p.add("West", createLabel(""));        p.setBackground(SystemColor.control);        return p;    }    /**     * Method declaration     *     *     * @param s     *     * @return     */    private Label createLabel(String s) {        Label l = new Label(s);        l.setBackground(SystemColor.control);        return l;    }    private void SavePrefs(String f) {        saveTable();        TransferCommon.savePrefs(f, sourceDb, targetDb, this, tTable);    }    private void LoadPrefs(String f) {        TransferTable t;        trace("Parsing Settings file");        bStart.setEnabled(false);        if (iTransferMode == TRFM_TRANSFER) {            bContinue.setEnabled(false);        }        tTable = TransferCommon.loadPrefs(f, sourceDb, targetDb, this);        iSelectionStep = SELECT_SOURCE_TABLES;        lTable.removeAll();        for (int i = 0; i < tTable.size(); i++) {            t = (TransferTable) tTable.elementAt(i);            lTable.add(t.Stmts.sSourceTable);        }        t = (TransferTable) tTable.elementAt(0);        displayTable(t);        lTable.select(0);        updateEnabled(true);        lTable.invalidate();        if (iTransferMode == TRFM_TRANSFER) {            bStart.setLabel("Start Transfer");            trace("Edit definitions and press [Start Transfer]");        } else if (iTransferMode == TRFM_DUMP) {            bStart.setLabel("Start Dump");            trace("Edit definitions and press [Start Dump]");        } else if (iTransferMode == TRFM_RESTORE) {            bStart.setLabel("Start Restore");            trace("Edit definitions and press [Start Restore]");        }        bStart.invalidate();        if (iTransferMode == TRFM_TRANSFER) {            bContinue.setEnabled(false);        }    }    /**     * Method declaration     *     */    private void transfer() {        saveTable();        updateEnabled(false);        trace("Start Transfer");        int           TransferIndex = CurrentTransfer;        int           AlterIndex    = CurrentAlter;        TransferTable t             = null;        long          startTime, stopTime;        startTime = System.currentTimeMillis();        try {            for (int i = TransferIndex; i < tTable.size(); i++) {                CurrentTransfer = i;                t               = (TransferTable) tTable.elementAt(i);                lTable.select(i);                displayTable(t);                t.transferStructure();                t.transferData(iMaxRows);            }            for (int i = AlterIndex; i < tTable.size(); i++) {                CurrentAlter = i;                t            = (TransferTable) tTable.elementAt(i);                lTable.select(i);                displayTable(t);                t.transferAlter();            }            stopTime = System.currentTimeMillis();            trace("Transfer finished successfully in: "                  + (stopTime - startTime) / 1000.00 + " sec");            if (iTransferMode == TRFM_TRANSFER) {                bContinue.setLabel("Quit");                bContinue.setEnabled(true);                bContinue.invalidate();            } else {                bStart.setLabel("Quit");                bStart.setEnabled(true);                bStart.invalidate();            }        } catch (Exception e) {            String last = tMessage.getText();            trace("Transfer stopped - " + last + " /  / Error: "                  + e.getMessage());            e.printStackTrace();        }        if (iTransferMode == TRFM_TRANSFER) {            bContinue.setEnabled((CurrentAlter < tTable.size()));        }        updateEnabled(true);        System.gc();    }    protected void Exit() {        cleanup();        fMain.dispose();        if (bMustExit) {            System.exit(0);        }    }}

⌨️ 快捷键说明

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