01: /*
02: * DataStoreExporter.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.dialogs.export;
13:
14: import java.awt.Component;
15: import workbench.db.exporter.DataExporter;
16: import workbench.log.LogMgr;
17: import workbench.storage.DataStore;
18:
19: /**
20: * @author support@sql-workbench.net
21: */
22: public class DataStoreExporter {
23: private DataStore source;
24: private Component caller;
25: private ExportFileDialog dialog;
26:
27: public DataStoreExporter(DataStore source, Component caller) {
28: this .caller = caller;
29: this .source = source;
30: }
31:
32: public void saveAs() {
33: boolean insert = (this .source != null && this .source
34: .canSaveAsSqlInsert());
35: boolean update = (source != null && source.hasPkColumns());
36: this .dialog = new ExportFileDialog(this .caller, source
37: .getResultInfo());
38: this .dialog.setIncludeSqlInsert(insert);
39: this .dialog.setIncludeSqlUpdate(update);
40: this .dialog.setIncludeSqlDeleteInsert(insert && update);
41: this .dialog.setSelectDirectoryOnly(false);
42:
43: boolean selected = dialog.selectOutput();
44: if (selected) {
45: writeFile();
46: }
47: }
48:
49: public DataStore getSource() {
50: return source;
51: }
52:
53: public void setSource(DataStore source) {
54: this .source = source;
55: }
56:
57: private void writeFile() {
58: if (this .source == null)
59: return;
60: DataExporter exporter = new DataExporter(this .source
61: .getOriginalConnection());
62: exporter.setColumnsToExport(this .dialog.getColumnsToExport());
63: dialog.setExporterOptions(exporter);
64: try {
65: exporter.startExport(this .source);
66: } catch (Exception e) {
67: LogMgr.logError("DataStoreExporter.writeFile()",
68: "Error writing export file", e);
69: }
70: }
71:
72: }
|