KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hsqldb > util > Transfer


1 /* Copyright (c) 1995-2000, The Hypersonic SQL Group.
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of the Hypersonic SQL Group nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE HYPERSONIC SQL GROUP,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * This software consists of voluntary contributions made by many individuals
31  * on behalf of the Hypersonic SQL Group.
32  *
33  *
34  * For work added by the HSQL Development Group:
35  *
36  * Copyright (c) 2001-2005, The HSQL Development Group
37  * All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions are met:
41  *
42  * Redistributions of source code must retain the above copyright notice, this
43  * list of conditions and the following disclaimer.
44  *
45  * Redistributions in binary form must reproduce the above copyright notice,
46  * this list of conditions and the following disclaimer in the documentation
47  * and/or other materials provided with the distribution.
48  *
49  * Neither the name of the HSQL Development Group nor the names of its
50  * contributors may be used to endorse or promote products derived from this
51  * software without specific prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
54  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
57  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
58  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
59  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
60  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
61  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64  */

65
66
67 package org.hsqldb.util;
68
69 import java.applet.Applet JavaDoc;
70 import java.util.Enumeration JavaDoc;
71 import java.util.Vector JavaDoc;
72
73 import java.awt.BorderLayout JavaDoc;
74 import java.awt.Button JavaDoc;
75 import java.awt.Checkbox JavaDoc;
76 import java.awt.Component JavaDoc;
77 import java.awt.Dimension JavaDoc;
78 import java.awt.FileDialog JavaDoc;
79 import java.awt.Font JavaDoc;
80 import java.awt.Frame JavaDoc;
81 import java.awt.GridLayout JavaDoc;
82 import java.awt.Image JavaDoc;
83 import java.awt.ItemSelectable JavaDoc;
84 import java.awt.Label JavaDoc;
85 import java.awt.Menu JavaDoc;
86 import java.awt.MenuBar JavaDoc;
87 import java.awt.MenuItem JavaDoc;
88 import java.awt.Panel JavaDoc;
89 import java.awt.SystemColor JavaDoc;
90 import java.awt.TextField JavaDoc;
91 import java.awt.Toolkit JavaDoc;
92 import java.awt.event.ActionEvent JavaDoc;
93 import java.awt.event.ActionListener JavaDoc;
94 import java.awt.event.ItemEvent JavaDoc;
95 import java.awt.event.ItemListener JavaDoc;
96 import java.awt.event.WindowEvent JavaDoc;
97 import java.awt.event.WindowListener JavaDoc;
98 import java.awt.image.MemoryImageSource JavaDoc;
99
100 // fredt@users 20011220 - patch 481239 by xponsard@users - enhancements
101
// enhancements to support saving and loading of transfer settings,
102
// transfer of blobs, and catalog and schema names in source db
103
// changes by fredt to allow saving and loading of transfer settings
104
// fredt@users 20020215 - patch 516309 by Nicolas Bazin - enhancements
105
// sqlbob@users 20020401 - patch 1.7.0 - reengineering
106
// nicolas BAZIN 20020430 - add Catalog selection, correct a bug preventing table
107
// edition, change double quotes to simple quotes for default values of CHAR type
108
// lonbinder@users 20030426 - correct bug in prefs load/save
109
// fredt@users 20040508 - patch 1.7.2 - bug fixes
110

111 /**
112  * Utility program (or applet) for transferring tables between different
113  * databases via JDBC. Understands HSQLDB database particularly well.
114  *
115  * @author Thomas Mueller (Hypersonic SQL Group)
116   * @version 1.7.2
117   * @since Hypersonic SQL
118  */

119 public class Transfer extends Applet JavaDoc
120 implements WindowListener JavaDoc, ActionListener JavaDoc, ItemListener JavaDoc, Traceable {
121
122     Frame JavaDoc fMain;
123     Image JavaDoc imgEmpty;
124     DataAccessPoint sourceDb;
125     DataAccessPoint targetDb;
126     TransferTable tCurrent;
127     int iMaxRows;
128     int iSelectionStep;
129     Vector JavaDoc tTable;
130     java.awt.List JavaDoc lTable;
131     String JavaDoc[] sSourceSchemas;
132     String JavaDoc sSourceCatalog, sDestSchema, sDestCatalog;
133     TextField JavaDoc tSourceTable, tDestTable, tDestDropIndex, tDestCreateIndex;
134     TextField JavaDoc tDestDrop, tDestCreate, tDestDelete, tDestAlter;
135     TextField JavaDoc tSourceSelect, tDestInsert;
136     Checkbox JavaDoc cTransfer, cDrop, cCreate, cDelete, cInsert, cAlter;
137     Checkbox JavaDoc cCreateIndex, cDropIndex;
138     Checkbox JavaDoc cFKForced, cIdxForced;
139     Button JavaDoc bStart, bContinue;
140     TextField JavaDoc tMessage;
141     int iTransferMode;
142     static boolean bMustExit;
143     int CurrentTransfer, CurrentAlter;
144     static final int SELECT_SOURCE_CATALOG = 1;
145     static final int SELECT_SOURCE_SCHEMA = 2;
146     static final int SELECT_DEST_CATALOG = 3;
147     static final int SELECT_DEST_SCHEMA = 4;
148     static final int SELECT_SOURCE_TABLES = 5;
149     static final int TRFM_TRANSFER = 1;
150     static final int TRFM_DUMP = 2;
151     static final int TRFM_RESTORE = 3;
152
153     /**
154      * Method declaration
155      *
156      *
157      * @param s
158      */

159     public void trace(String JavaDoc s) {
160
161         if ((s != null) &&!s.equals("")) {
162             tMessage.setText(s);
163
164             if (TRACE) {
165                 System.out.println(s);
166             }
167         }
168     }
169
170     /**
171      * Method declaration
172      *
173      */

174     public void init() {
175
176         Transfer m = new Transfer();
177
178         m._main(null);
179     }
180
181     /**
182      * Method declaration
183      *
184      */

185     public static void work(String JavaDoc[] arg) {
186
187         Transfer m = new Transfer();
188
189         m._main(arg);
190     }
191
192     /**
193      * Method declaration
194      *
195      *
196      * @param arg
197      */

198     public static void main(String JavaDoc[] arg) {
199
200         System.getProperties().put("sun.java2d.noddraw", "true");
201
202         bMustExit = true;
203
204         work(arg);
205     }
206
207     private boolean CatalogToSelect() {
208
209         Vector JavaDoc result = null;
210
211         try {
212             lTable.removeAll();
213
214             if (iSelectionStep == Transfer.SELECT_SOURCE_CATALOG) {
215                 result = sourceDb.getCatalog();
216             } else if (iSelectionStep == Transfer.SELECT_DEST_CATALOG) {
217                 result = targetDb.getCatalog();
218             } else {
219                 Exit();
220             }
221
222             if (result.size() > 1) {
223                 lTable.setMultipleMode(true);
224
225                 if (iSelectionStep == Transfer.SELECT_SOURCE_CATALOG) {
226                     bStart.setLabel("Select Catalog: Source");
227                 } else {
228                     bStart.setLabel("Select Catalog: Destination");
229                 }
230
231                 bStart.invalidate();
232                 bStart.setEnabled(true);
233
234                 for (Enumeration JavaDoc e =
235                         result.elements(); e.hasMoreElements(); ) {
236                     lTable.add(e.nextElement().toString());
237                 }
238
239                 lTable.repaint();
240                 trace("Select correct Catalog");
241             } else {
242                 if (result.size() == 1) {
243                     if (iSelectionStep == Transfer.SELECT_SOURCE_CATALOG) {
244                         sSourceCatalog = (String JavaDoc) result.firstElement();
245                         sSourceSchemas = null;
246                     } else {
247                         sDestCatalog = (String JavaDoc) result.firstElement();
248                         sDestSchema = null;
249                     }
250                 } else {
251                     if (iSelectionStep == Transfer.SELECT_SOURCE_CATALOG) {
252                         sSourceCatalog = null;
253                         sSourceSchemas = null;
254                     } else {
255                         sDestCatalog = null;
256                         sDestSchema = null;
257                     }
258                 }
259
260                 if ((iSelectionStep == Transfer.SELECT_DEST_CATALOG)
261                         && (sDestCatalog != null)) {
262                     try {
263                         targetDb.setCatalog(sDestCatalog);
264                     } catch (Exception JavaDoc ex) {
265                         trace("Catalog " + sSourceCatalog
266                               + " could not be selected in the target database");
267
268                         sSourceCatalog = null;
269                     }
270                 }
271
272                 iSelectionStep++;
273
274                 ProcessNextStep();
275
276                 return false;
277             }
278         } catch (Exception JavaDoc exp) {
279             lTable.removeAll();
280             trace("Exception reading catalog: " + exp);
281             exp.printStackTrace();
282         }
283
284         return (lTable.getItemCount() > 0);
285     }
286
287     private boolean SchemaToSelect() {
288
289         Vector JavaDoc result = null;
290
291         try {
292             lTable.removeAll();
293
294             if (iSelectionStep == Transfer.SELECT_SOURCE_SCHEMA) {
295                 result = sourceDb.getSchemas();
296             } else if (iSelectionStep == Transfer.SELECT_DEST_SCHEMA) {
297                 result = targetDb.getSchemas();
298             } else {
299                 Exit();
300             }
301
302             if (result.size() > 1) {
303                 lTable.setMultipleMode(true);
304
305                 if (iSelectionStep == Transfer.SELECT_SOURCE_SCHEMA) {
306                     bStart.setLabel("Select Schema: Source");
307                 } else {
308                     bStart.setLabel("Select Schema: Destination");
309                 }
310
311                 bStart.invalidate();
312                 bStart.setEnabled(true);
313
314                 for (Enumeration JavaDoc e =
315                         result.elements(); e.hasMoreElements(); ) {
316                     lTable.add(e.nextElement().toString());
317                 }
318
319                 lTable.repaint();
320                 trace("Select correct Schema or load Settings file");
321             } else {
322                 if (result.size() == 1) {
323                     if (iSelectionStep == Transfer.SELECT_SOURCE_SCHEMA) {
324                         sSourceSchemas = new String JavaDoc[1];
325                         sSourceSchemas[0] = (String JavaDoc) result.firstElement();
326                     } else {
327                         sDestSchema = (String JavaDoc) result.firstElement();
328                     }
329                 } else {
330                     if (iSelectionStep == Transfer.SELECT_SOURCE_SCHEMA) {
331                         sSourceSchemas = null;
332                     } else {
333                         sDestSchema = null;
334                     }
335                 }
336
337                 if (iTransferMode == TRFM_DUMP) {
338                     iSelectionStep = Transfer.SELECT_SOURCE_TABLES;
339                 } else {
340                     iSelectionStep++;
341                 }
342
343                 ProcessNextStep();
344
345                 return false;
346             }
347         } catch (Exception JavaDoc exp) {
348             lTable.removeAll();
349             trace("Exception reading schemas: " + exp);
350             exp.printStackTrace();
351         }
352
353         return (lTable.getItemCount() > 0);
354     }
355
356     /**
357      * Method declaration
358      *
359      */

360     void _main(String JavaDoc[] arg) {
361
362         /*
363          ** What function is asked from the transfer tool?
364          */

365         iTransferMode = TRFM_TRANSFER;
366
367         if ((arg != null) && (arg.length > 0)) {
368             if ((arg[0].toLowerCase().equals("-r"))
369                     || (arg[0].toLowerCase().equals("--restore"))) {
370                 iTransferMode = TRFM_RESTORE;
371             } else if ((arg[0].toLowerCase().equals("-d"))
372                        || (arg[0].toLowerCase().equals("--dump"))) {
373                 iTransferMode = TRFM_DUMP;
374             }
375         }
376
377         fMain = new Frame JavaDoc("HSQL Transfer Tool");
378         imgEmpty = createImage(new MemoryImageSource JavaDoc(2, 2, new int[4 * 4], 2,
379                 2));
380
381         fMain.setIconImage(imgEmpty);
382         fMain.addWindowListener(this);
383         fMain.setSize(640, 480);
384         fMain.add("Center", this);
385
386         MenuBar JavaDoc bar = new MenuBar JavaDoc();
387         String JavaDoc[] extras = {
388             "Insert 10 rows only", "Insert 1000 rows only", "Insert all rows",
389             "-", "Load Settings...", "Save Settings...", "-", "Exit"
390         };
391         Menu JavaDoc menu = new Menu JavaDoc("Options");
392
393         addMenuItems(menu, extras);
394         bar.add(menu);
395         fMain.setMenuBar(bar);
396         initGUI();
397
398         Dimension JavaDoc d = Toolkit.getDefaultToolkit().getScreenSize();
399         Dimension JavaDoc size = fMain.getSize();
400
401         // (ulrivo): full size on screen with less than 640 width
402
if (d.width >= 640) {
403             fMain.setLocation((d.width - size.width) / 2,
404                               (d.height - size.height) / 2);
405         } else {
406             fMain.setLocation(0, 0);
407             fMain.setSize(d);
408         }
409
410         fMain.setVisible(true);
411
412         CurrentTransfer = CurrentAlter = 0;
413
414         try {
415             if ((iTransferMode == TRFM_DUMP)
416                     || (iTransferMode == TRFM_TRANSFER)) {
417                 sourceDb = new TransferDb(
418                     ConnectionDialog.createConnection(
419                         fMain, "Source Database"), this);
420
421                 if (!sourceDb.isConnected()) {
422                     Exit();
423
424                     return;
425                 }
426             } else {
427                 FileDialog JavaDoc f = new FileDialog JavaDoc(fMain, "Restore FileName",
428                                               FileDialog.LOAD);
429
430                 f.show();
431
432                 String JavaDoc sFileName = f.getFile();
433                 String JavaDoc Path = f.getDirectory();
434
435                 if ((sFileName == null) || (sFileName.equals(""))) {
436                     Exit();
437
438                     return;
439                 } else {
440                     sourceDb = new TransferSQLText(Path + sFileName, this);
441                 }
442             }
443
444             if ((iTransferMode == TRFM_RESTORE)
445                     || (iTransferMode == TRFM_TRANSFER)) {
446                 targetDb = new TransferDb(
447                     ConnectionDialog.createConnection(
448                         fMain, "Target Database"), this);
449
450                 if (!targetDb.isConnected()) {
451                     Exit();
452
453                     return;
454                 }
455             } else {
456                 FileDialog JavaDoc f = new FileDialog JavaDoc(fMain, "Dump FileName",
457                                               FileDialog.SAVE);
458
459                 f.show();
460
461                 String JavaDoc sFileName = f.getFile();
462                 String JavaDoc Path = f.getDirectory();
463
464                 if ((sFileName == null) || (sFileName.equals(""))) {
465                     Exit();
466
467                     return;
468                 } else {
469                     targetDb = new TransferSQLText(Path + sFileName, this);
470                 }
471             }
472         } catch (Exception JavaDoc e) {
473             Exit();
474             e.printStackTrace();
475
476             return;
477         }
478
479         if ((iTransferMode == TRFM_DUMP)
480                 || (iTransferMode == TRFM_TRANSFER)) {
481             iSelectionStep = SELECT_SOURCE_CATALOG;
482             sSourceCatalog = null;
483         } else {
484             iSelectionStep = SELECT_DEST_CATALOG;
485             sDestCatalog = null;
486         }
487
488         ProcessNextStep();
489         fMain.show();
490
491         return;
492     }
493
494     private void RefreshMainDisplay() {
495
496         lTable.removeAll();
497         lTable.repaint();
498
499         try {
500             tTable = sourceDb.getTables(sSourceCatalog, sSourceSchemas);
501
502             for (int i = 0; i < tTable.size(); i++) {
503                 TransferTable t = (TransferTable) tTable.elementAt(i);
504
505                 t.setDest(sDestSchema, targetDb);
506                 t.extractTableStructure(sourceDb, targetDb);
507                 lTable.add(t.Stmts.sSourceTable);
508                 lTable.select(i);
509                 displayTable(t);
510             }
511
512             bStart.setEnabled(true);
513
514             if (iTransferMode == TRFM_TRANSFER) {
515                 trace("Edit definitions and press [Start Transfer]");
516             } else if (iTransferMode == TRFM_DUMP) {
517                 trace("Edit definitions and press [Start Dump]");
518             }
519         } catch (Exception JavaDoc e) {
520             trace("Exception reading source tables: " + e);
521             e.printStackTrace();
522         }
523
524         fMain.show();
525     }
526
527     /**
528      * Method declaration
529      *
530      *
531      * @param f
532      * @param m
533      */

534     private void addMenuItems(Menu JavaDoc f, String JavaDoc[] m) {
535
536         for (int i = 0; i < m.length; i++) {
537             if (m[i].equals("-")) {
538                 f.addSeparator();
539             } else {
540                 MenuItem JavaDoc item = new MenuItem JavaDoc(m[i]);
541
542                 item.addActionListener(this);
543                 f.add(item);
544             }
545         }
546     }
547
548     /**
549      * Method declaration
550      *
551      *
552      * @param e
553      */

554     public void itemStateChanged(ItemEvent JavaDoc e) {
555
556         ItemSelectable JavaDoc item = e.getItemSelectable();
557
558         if (item == lTable) {
559             if (iSelectionStep == SELECT_SOURCE_TABLES) {
560                 String JavaDoc table = lTable.getSelectedItem();
561                 int selected = ((Integer JavaDoc) e.getItem()).intValue();
562
563                 for (int i = 0; i < tTable.size(); i++) {
564                     TransferTable t = (TransferTable) tTable.elementAt(i);
565
566                     if (t == null) {
567                         continue;
568                     }
569
570                     if (i == selected) {
571                         saveTable();
572                         displayTable(t);
573                         updateEnabled(true);
574                     }
575                 }
576             }
577         } else {
578
579             // it must be a checkbox
580
saveTable();
581             updateEnabled(true);
582         }
583     }
584
585     /**
586      * Method declaration
587      *
588      */

589     private void saveTable() {
590
591         if (tCurrent == null) {
592             return;
593         }
594
595         TransferTable t = tCurrent;
596
597         t.Stmts.sSourceTable = tSourceTable.getText();
598         t.Stmts.sDestTable = tDestTable.getText();
599         t.Stmts.sDestDrop = tDestDrop.getText();
600         t.Stmts.sDestCreateIndex = tDestCreateIndex.getText();
601         t.Stmts.sDestDropIndex = tDestDropIndex.getText();
602         t.Stmts.sDestCreate = tDestCreate.getText();
603         t.Stmts.sDestDelete = tDestDelete.getText();
604         t.Stmts.sSourceSelect = tSourceSelect.getText();
605         t.Stmts.sDestInsert = tDestInsert.getText();
606         t.Stmts.sDestAlter = tDestAlter.getText();
607
608         //
609
t.Stmts.bTransfer = cTransfer.getState();
610         t.Stmts.bDrop = cDrop.getState();
611         t.Stmts.bCreate = cCreate.getState();
612         t.Stmts.bDelete = cDelete.getState();
613         t.Stmts.bInsert = cInsert.getState();
614         t.Stmts.bAlter = cAlter.getState();
615         t.Stmts.bCreateIndex = cCreateIndex.getState();
616         t.Stmts.bDropIndex = cDropIndex.getState();
617
618         if (!t.Stmts.bTransfer) {
619             t.Stmts.bInsert = false;
620
621             cInsert.setState(false);
622         }
623
624         boolean reparsetable = ((t.Stmts.bFKForced != cFKForced.getState())
625                                 || (t.Stmts.bIdxForced
626                                     != cIdxForced.getState()));
627
628         t.Stmts.bFKForced = cFKForced.getState();
629         t.Stmts.bIdxForced = cIdxForced.getState();
630
631         if (reparsetable) {
632             try {
633                 sourceDb.getTableStructure(t, targetDb);
634             } catch (Exception JavaDoc e) {
635                 trace("Exception reading source tables: " + e);
636                 e.printStackTrace();
637             }
638         }
639     }
640
641     /**
642      * Method declaration
643      *
644      *
645      * @param t
646      */

647     private void displayTable(TransferTable t) {
648
649         tCurrent = t;
650
651         if (t == null) {
652             return;
653         }
654
655         tSourceTable.setText(t.Stmts.sSourceTable);
656         tDestTable.setText(t.Stmts.sDestTable);
657         tDestDrop.setText(t.Stmts.sDestDrop);
658         tDestCreateIndex.setText(t.Stmts.sDestCreateIndex);
659         tDestDropIndex.setText(t.Stmts.sDestDropIndex);
660         tDestCreate.setText(t.Stmts.sDestCreate);
661         tDestDelete.setText(t.Stmts.sDestDelete);
662         tSourceSelect.setText(t.Stmts.sSourceSelect);
663         tDestInsert.setText(t.Stmts.sDestInsert);
664         tDestAlter.setText(t.Stmts.sDestAlter);
665         cTransfer.setState(t.Stmts.bTransfer);
666         cDrop.setState(t.Stmts.bDrop);
667         cCreate.setState(t.Stmts.bCreate);
668         cDropIndex.setState(t.Stmts.bDropIndex);
669         cCreateIndex.setState(t.Stmts.bCreateIndex);
670         cDelete.setState(t.Stmts.bDelete);
671         cInsert.setState(t.Stmts.bInsert);
672         cAlter.setState(t.Stmts.bAlter);
673         cFKForced.setState(t.Stmts.bFKForced);
674         cIdxForced.setState(t.Stmts.bIdxForced);
675     }
676
677     /**
678      * Method declaration
679      *
680      *
681      * @param and
682      */

683     private void updateEnabled(boolean and) {
684
685         boolean b = cTransfer.getState();
686
687         tDestTable.setEnabled(and && b);
688         tDestDrop.setEnabled(and && b && cDrop.getState());
689         tDestCreate.setEnabled(and && b && cCreate.getState());
690         tDestDelete.setEnabled(and && b && cDelete.getState());
691         tDestCreateIndex.setEnabled(and && b && cCreateIndex.getState());
692         tDestDropIndex.setEnabled(and && b && cDropIndex.getState());
693         tSourceSelect.setEnabled(and && b);
694         tDestInsert.setEnabled(and && b && cInsert.getState());
695         tDestAlter.setEnabled(and && b && cAlter.getState());
696         cDrop.setEnabled(and && b);
697         cCreate.setEnabled(and && b);
698         cDelete.setEnabled(and && b);
699         cCreateIndex.setEnabled(and && b);
700         cDropIndex.setEnabled(and && b);
701         cInsert.setEnabled(and && b);
702         cAlter.setEnabled(and && b);
703         cFKForced.setEnabled(cAlter.getState());
704         cIdxForced.setEnabled(cCreateIndex.getState());
705         bStart.setEnabled(and);
706
707         if (iTransferMode == TRFM_TRANSFER) {
708             bContinue.setEnabled(and);
709         }
710     }
711
712     /**
713      * Method ProcessNextStep
714      */

715     private void ProcessNextStep() {
716
717         switch (iSelectionStep) {
718
719             case SELECT_SOURCE_CATALOG :
720             case SELECT_DEST_CATALOG :
721                 if (CatalogToSelect()) {
722                     fMain.show();
723
724                     return;
725                 }
726                 break;
727
728             case SELECT_DEST_SCHEMA :
729             case SELECT_SOURCE_SCHEMA :
730                 if (SchemaToSelect()) {
731                     fMain.show();
732
733                     return;
734                 }
735                 break;
736
737             case SELECT_SOURCE_TABLES :
738                 if (iTransferMode == TRFM_TRANSFER) {
739                     bStart.setLabel("Start Transfer");
740                 } else if (iTransferMode == TRFM_DUMP) {
741                     bStart.setLabel("Start Dump");
742                 } else if (iTransferMode == TRFM_RESTORE) {
743                     bStart.setLabel("Start Restore");
744                 }
745
746                 bStart.invalidate();
747                 bStart.setEnabled(false);
748                 lTable.setMultipleMode(false);
749                 RefreshMainDisplay();
750                 break;
751
752             default :
753                 break;
754         }
755     }
756
757     /**
758      * Method declaration
759      *
760      *
761      * @param ev
762      */

763     public void actionPerformed(ActionEvent JavaDoc ev) {
764
765         if (ev.getSource() instanceof TextField JavaDoc) {
766             saveTable();
767
768             return;
769         }
770
771         String JavaDoc s = ev.getActionCommand();
772         MenuItem JavaDoc i = new MenuItem JavaDoc();
773
774         if (s == null) {
775             if (ev.getSource() instanceof MenuItem JavaDoc) {
776                 i = (MenuItem JavaDoc) ev.getSource();
777                 s = i.getLabel();
778             }
779         }
780
781         if (s == null) {}
782
783         if (s.equals("Start Transfer") || s.equals("ReStart Transfer")) {
784             bStart.setLabel("ReStart Transfer");
785             bStart.invalidate();
786
787             CurrentTransfer = 0;
788             CurrentAlter = 0;
789
790             transfer();
791         } else if (s.equals("Continue Transfer")) {
792             transfer();
793         } else if (s.equals("Start Dump") || s.equals("Start Restore")) {
794             CurrentTransfer = 0;
795             CurrentAlter = 0;
796
797             transfer();
798         } else if (s.equals("Quit")) {
799             Exit();
800         } else if (s.indexOf("Select Schema") >= 0) {
801             String JavaDoc[] selection = lTable.getSelectedItems();
802
803             if ((selection == null) || (selection.length == 0)) {
804                 return;
805             }
806
807             if (iSelectionStep == Transfer.SELECT_SOURCE_SCHEMA) {
808                 sSourceSchemas = selection;
809             } else {
810                 sDestSchema = selection[0];
811             }
812
813             if (iTransferMode == TRFM_DUMP) {
814                 iSelectionStep = Transfer.SELECT_SOURCE_TABLES;
815             } else {
816                 iSelectionStep++;
817             }
818
819             ProcessNextStep();
820         } else if (s.indexOf("Select Catalog") >= 0) {
821             String JavaDoc selection = lTable.getSelectedItem();
822
823             if ((selection == null) || (selection.equals(""))) {
824                 return;
825             }
826
827             if (iSelectionStep == Transfer.SELECT_SOURCE_CATALOG) {
828                 sSourceCatalog = selection;
829                 sSourceSchemas = null;
830             } else {
831                 sDestCatalog = selection;
832                 sDestSchema = null;
833
834                 try {
835                     targetDb.setCatalog(sDestCatalog);
836                 } catch (Exception JavaDoc ex) {
837                     trace("Catalog " + sDestCatalog
838 <