📄 transfer.java
字号:
/* Copyrights and Licenses * * This product includes Hypersonic SQL. * Originally developed by Thomas Mueller and the Hypersonic SQL Group. * * Copyright (c) 1995-2000 by 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. * - All advertising materials mentioning features or use of this software must display the * following acknowledgment: "This product includes Hypersonic SQL." * - Products derived from this software may not be called "Hypersonic SQL" nor may * "Hypersonic SQL" appear in their names without prior written permission of the * Hypersonic SQL Group. * - Redistributions of any form whatsoever must retain the following acknowledgment: "This * product includes Hypersonic SQL." * This software is provided "as is" and any expressed 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 its 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 any 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-2002, 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, including earlier * license statements (above) and comply with all above license conditions. * * 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, including earlier * license statements (above) and comply with all above license conditions. * * 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.awt.*;import java.awt.event.*;import java.awt.image.*;import java.applet.*;import java.util.*;import java.sql.*;// 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/** * Utility program (or applet) for transferring tables between different * databases via JDBC. Understands HSQLDB database particularly well. * * @version 1.7.0 */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; final static int SELECT_SOURCE_CATALOG = 1; final static int SELECT_SOURCE_SCHEMA = 2; final static int SELECT_DEST_CATALOG = 3; final static int SELECT_DEST_SCHEMA = 4; final static int SELECT_SOURCE_TABLES = 5; final static int TRFM_TRANSFER = 1; final static int TRFM_DUMP = 2; final static 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 == this.SELECT_SOURCE_CATALOG) { result = sourceDb.getCatalog(); } else if (iSelectionStep == this.SELECT_DEST_CATALOG) { result = targetDb.getCatalog(); } else { Exit(); } if (result.size() > 1) { lTable.setMultipleMode(true); if (iSelectionStep == this.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 == this.SELECT_SOURCE_CATALOG) { sSourceCatalog = (String) result.firstElement(); sSourceSchemas = null; } else { sDestCatalog = (String) result.firstElement(); sDestSchema = null; } } else { if (iSelectionStep == this.SELECT_SOURCE_CATALOG) { sSourceCatalog = null; sSourceSchemas = null; } else { sDestCatalog = null; sDestSchema = null; } } if ((iSelectionStep == this.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 == this.SELECT_SOURCE_SCHEMA) { result = sourceDb.getSchemas(); } else if (iSelectionStep == this.SELECT_DEST_SCHEMA) { result = targetDb.getSchemas(); } else { Exit(); } if (result.size() > 1) { lTable.setMultipleMode(true); if (iSelectionStep == this.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 == this.SELECT_SOURCE_SCHEMA) { sSourceSchemas = new String[1]; sSourceSchemas[0] = (String) result.firstElement(); } else { sDestSchema = (String) result.firstElement(); } } else { if (iSelectionStep == this.SELECT_SOURCE_SCHEMA) { sSourceSchemas = null; } else { sDestSchema = null; } } if (iTransferMode == TRFM_DUMP) { iSelectionStep = this.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); f.show(); String sFileName = f.getFile(); String Path = f.getDirectory(); if ((sFileName == null) || (sFileName.equals(""))) { Exit(); return; } else { sourceDb = new TransferSQLText(Path + sFileName, this); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -