01: /*
02: * Copyright (C) 2005 Rob Manning
03: * manningr@users.sourceforge.net
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19: package net.sourceforge.squirrel_sql.plugins.dbcopy;
20:
21: import java.util.ResourceBundle;
22:
23: import net.sourceforge.squirrel_sql.client.ApplicationArguments;
24: import net.sourceforge.squirrel_sql.client.plugin.IPlugin;
25: import net.sourceforge.squirrel_sql.client.plugin.MockPlugin;
26: import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.DBCopyPreferenceBean;
27: import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.PreferencesManager;
28:
29: /**
30: * A description of this class goes here...
31: */
32:
33: public class CopyExecutorTestRunner {
34:
35: private SessionInfoProvider prov = null;
36:
37: private CopyExecutor copyExecutor = null;
38:
39: private MockCopyTableListener listener = null;
40:
41: private MockUICallbacks uiCallbacks = null;
42:
43: private static DBCopyPreferenceBean prefs = null;
44:
45: /**
46: *
47: *
48: */
49: public CopyExecutorTestRunner(SessionInfoProvider provider) {
50: prov = provider;
51: copyExecutor = new CopyExecutor(prov);
52: listener = new MockCopyTableListener();
53: //listener.setShowSqlStatements(true);
54: uiCallbacks = new MockUICallbacks();
55: copyExecutor.addListener(listener);
56: copyExecutor.setPref(uiCallbacks);
57: }
58:
59: public void run() {
60: copyExecutor.execute();
61: }
62:
63: /**
64: * @param args
65: */
66: public static void main(String[] args) throws Exception {
67: String props = args[0];
68: boolean dropOnly = getDropOnly();
69: ApplicationArguments.initialize(new String[0]);
70: ResourceBundle bundle = ResourceBundle.getBundle(props);
71: String prefsDir = bundle.getString("prefsDir");
72: System.out.println("Reading preferences from prefs.xml in "
73: + prefsDir);
74: IPlugin plugin = new MockPlugin(prefsDir);
75: PreferencesManager.initialize(plugin);
76: prefs = PreferencesManager.getPreferences();
77: System.out.println("Copying primary keys: "
78: + prefs.isCopyPrimaryKeys());
79:
80: MockSessionInfoProvider provider = new MockSessionInfoProvider(
81: args[0], dropOnly);
82: CopyExecutorTestRunner runner = new CopyExecutorTestRunner(
83: provider);
84: runner.run();
85: }
86:
87: private static boolean getDropOnly() {
88: boolean result = false;
89: String dropOnly = System.getProperty("dropOnly");
90: if (dropOnly != null) {
91: if ("true".equalsIgnoreCase(dropOnly)) {
92: System.out
93: .println("Skipping copy; will only drop tables in destination database");
94: result = true;
95: }
96: }
97: return result;
98: }
99: }
|