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

📄 transfer.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* Copyright (c) 1995-2000, The Hypersonic SQL Group. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the Hypersonic SQL Group nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE HYPERSONIC SQL GROUP, * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals  * on behalf of the Hypersonic SQL Group. * * * For work added by the HSQL Development Group: * * Copyright (c) 2001-2005, The HSQL Development Group * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the HSQL Development Group nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */package org.hsqldb.util;import java.applet.Applet;import java.util.Enumeration;import java.util.Vector;import java.awt.BorderLayout;import java.awt.Button;import java.awt.Checkbox;import java.awt.Component;import java.awt.Dimension;import java.awt.FileDialog;import java.awt.Font;import java.awt.Frame;import java.awt.GridLayout;import java.awt.Image;import java.awt.ItemSelectable;import java.awt.Label;import java.awt.Menu;import java.awt.MenuBar;import java.awt.MenuItem;import java.awt.Panel;import java.awt.SystemColor;import java.awt.TextField;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import java.awt.image.MemoryImageSource;// fredt@users 20011220 - patch 481239 by xponsard@users - enhancements// enhancements to support saving and loading of transfer settings,// transfer of blobs, and catalog and schema names in source db// changes by fredt to allow saving and loading of transfer settings// fredt@users 20020215 - patch 516309 by Nicolas Bazin - enhancements// sqlbob@users 20020401 - patch 1.7.0 - reengineering// nicolas BAZIN 20020430 - add Catalog selection, correct a bug preventing table//    edition, change double quotes to simple quotes for default values of CHAR type// lonbinder@users 20030426 - correct bug in prefs load/save// fredt@users 20040508 - patch 1.7.2 - bug fixes/** *  Utility program (or applet) for transferring tables between different *  databases via JDBC. Understands HSQLDB database particularly well. * * @author Thomas Mueller (Hypersonic SQL Group)  * @version 1.7.2  * @since Hypersonic SQL */public class Transfer extends Appletimplements WindowListener, ActionListener, ItemListener, Traceable {    Frame            fMain;    Image            imgEmpty;    DataAccessPoint  sourceDb;    DataAccessPoint  targetDb;    TransferTable    tCurrent;    int              iMaxRows;    int              iSelectionStep;    Vector           tTable;    java.awt.List    lTable;    String[]         sSourceSchemas;    String           sSourceCatalog, sDestSchema, sDestCatalog;    TextField tSourceTable, tDestTable, tDestDropIndex, tDestCreateIndex;    TextField        tDestDrop, tDestCreate, tDestDelete, tDestAlter;    TextField        tSourceSelect, tDestInsert;    Checkbox         cTransfer, cDrop, cCreate, cDelete, cInsert, cAlter;    Checkbox         cCreateIndex, cDropIndex;    Checkbox         cFKForced, cIdxForced;    Button           bStart, bContinue;    TextField        tMessage;    int              iTransferMode;    static boolean   bMustExit;    int              CurrentTransfer, CurrentAlter;    static final int SELECT_SOURCE_CATALOG = 1;    static final int SELECT_SOURCE_SCHEMA  = 2;    static final int SELECT_DEST_CATALOG   = 3;    static final int SELECT_DEST_SCHEMA    = 4;    static final int SELECT_SOURCE_TABLES  = 5;    static final int TRFM_TRANSFER         = 1;    static final int TRFM_DUMP             = 2;    static final int TRFM_RESTORE          = 3;    /**     * Method declaration     *     *     * @param s     */    public void trace(String s) {        if ((s != null) &&!s.equals("")) {            tMessage.setText(s);            if (TRACE) {                System.out.println(s);            }        }    }    /**     * Method declaration     *     */    public void init() {        Transfer m = new Transfer();        m._main(null);    }    /**     * Method declaration     *     */    public static void work(String[] arg) {        Transfer m = new Transfer();        m._main(arg);    }    /**     * Method declaration     *     *     * @param arg     */    public static void main(String[] arg) {        System.getProperties().put("sun.java2d.noddraw", "true");        bMustExit = true;        work(arg);    }    private boolean CatalogToSelect() {        Vector result = null;        try {            lTable.removeAll();            if (iSelectionStep == Transfer.SELECT_SOURCE_CATALOG) {                result = sourceDb.getCatalog();            } else if (iSelectionStep == Transfer.SELECT_DEST_CATALOG) {                result = targetDb.getCatalog();            } else {                Exit();            }            if (result.size() > 1) {                lTable.setMultipleMode(true);                if (iSelectionStep == Transfer.SELECT_SOURCE_CATALOG) {                    bStart.setLabel("Select Catalog: Source");                } else {                    bStart.setLabel("Select Catalog: Destination");                }                bStart.invalidate();                bStart.setEnabled(true);                for (Enumeration e =                        result.elements(); e.hasMoreElements(); ) {                    lTable.add(e.nextElement().toString());                }                lTable.repaint();                trace("Select correct Catalog");            } else {                if (result.size() == 1) {                    if (iSelectionStep == Transfer.SELECT_SOURCE_CATALOG) {                        sSourceCatalog = (String) result.firstElement();                        sSourceSchemas = null;                    } else {                        sDestCatalog = (String) result.firstElement();                        sDestSchema  = null;                    }                } else {                    if (iSelectionStep == Transfer.SELECT_SOURCE_CATALOG) {                        sSourceCatalog = null;                        sSourceSchemas = null;                    } else {                        sDestCatalog = null;                        sDestSchema  = null;                    }                }                if ((iSelectionStep == Transfer.SELECT_DEST_CATALOG)                        && (sDestCatalog != null)) {                    try {                        targetDb.setCatalog(sDestCatalog);                    } catch (Exception ex) {                        trace("Catalog " + sSourceCatalog                              + " could not be selected in the target database");                        sSourceCatalog = null;                    }                }                iSelectionStep++;                ProcessNextStep();                return false;            }        } catch (Exception exp) {            lTable.removeAll();            trace("Exception reading catalog: " + exp);            exp.printStackTrace();        }        return (lTable.getItemCount() > 0);    }    private boolean SchemaToSelect() {        Vector result = null;        try {            lTable.removeAll();            if (iSelectionStep == Transfer.SELECT_SOURCE_SCHEMA) {                result = sourceDb.getSchemas();            } else if (iSelectionStep == Transfer.SELECT_DEST_SCHEMA) {                result = targetDb.getSchemas();            } else {                Exit();            }            if (result.size() > 1) {                lTable.setMultipleMode(true);                if (iSelectionStep == Transfer.SELECT_SOURCE_SCHEMA) {                    bStart.setLabel("Select Schema: Source");                } else {                    bStart.setLabel("Select Schema: Destination");                }                bStart.invalidate();                bStart.setEnabled(true);                for (Enumeration e =                        result.elements(); e.hasMoreElements(); ) {                    lTable.add(e.nextElement().toString());                }                lTable.repaint();                trace("Select correct Schema or load Settings file");            } else {                if (result.size() == 1) {                    if (iSelectionStep == Transfer.SELECT_SOURCE_SCHEMA) {                        sSourceSchemas    = new String[1];                        sSourceSchemas[0] = (String) result.firstElement();                    } else {                        sDestSchema = (String) result.firstElement();                    }                } else {                    if (iSelectionStep == Transfer.SELECT_SOURCE_SCHEMA) {                        sSourceSchemas = null;                    } else {                        sDestSchema = null;                    }                }                if (iTransferMode == TRFM_DUMP) {                    iSelectionStep = Transfer.SELECT_SOURCE_TABLES;                } else {                    iSelectionStep++;                }                ProcessNextStep();                return false;            }        } catch (Exception exp) {            lTable.removeAll();            trace("Exception reading schemas: " + exp);            exp.printStackTrace();        }        return (lTable.getItemCount() > 0);    }    /**     * Method declaration     *     */    void _main(String[] arg) {        /*         ** What function is asked from the transfer tool?         */        iTransferMode = TRFM_TRANSFER;        if ((arg != null) && (arg.length > 0)) {            if ((arg[0].toLowerCase().equals("-r"))                    || (arg[0].toLowerCase().equals("--restore"))) {                iTransferMode = TRFM_RESTORE;            } else if ((arg[0].toLowerCase().equals("-d"))                       || (arg[0].toLowerCase().equals("--dump"))) {                iTransferMode = TRFM_DUMP;            }        }        fMain = new Frame("HSQL Transfer Tool");        imgEmpty = createImage(new MemoryImageSource(2, 2, new int[4 * 4], 2,                2));        fMain.setIconImage(imgEmpty);        fMain.addWindowListener(this);        fMain.setSize(640, 480);        fMain.add("Center", this);        MenuBar  bar    = new MenuBar();        String[] extras = {            "Insert 10 rows only", "Insert 1000 rows only", "Insert all rows",            "-", "Load Settings...", "Save Settings...", "-", "Exit"        };        Menu menu = new Menu("Options");        addMenuItems(menu, extras);        bar.add(menu);        fMain.setMenuBar(bar);        initGUI();        Dimension d    = Toolkit.getDefaultToolkit().getScreenSize();        Dimension size = fMain.getSize();        // (ulrivo): full size on screen with less than 640 width        if (d.width >= 640) {            fMain.setLocation((d.width - size.width) / 2,                              (d.height - size.height) / 2);        } else {            fMain.setLocation(0, 0);            fMain.setSize(d);        }        fMain.setVisible(true);        CurrentTransfer = CurrentAlter = 0;        try {            if ((iTransferMode == TRFM_DUMP)                    || (iTransferMode == TRFM_TRANSFER)) {                sourceDb = new TransferDb(                    ConnectionDialog.createConnection(                        fMain, "Source Database"), this);                if (!sourceDb.isConnected()) {                    Exit();                    return;                }            } else {                FileDialog f = new FileDialog(fMain, "Restore FileName",                                              FileDialog.LOAD);

⌨️ 快捷键说明

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