01: /*
02: * ExportJobEntry.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.db.exporter;
13:
14: import java.sql.SQLException;
15: import workbench.db.ColumnIdentifier;
16: import workbench.db.TableIdentifier;
17: import workbench.db.WbConnection;
18: import workbench.storage.ResultInfo;
19:
20: /**
21: *
22: * @author support@sql-workbench.net
23: */
24: public class ExportJobEntry {
25: private ResultInfo resultInfo;
26: private String outputFileName;
27: private String query;
28:
29: public ExportJobEntry(String outputfile, TableIdentifier table,
30: WbConnection con) throws SQLException {
31: resultInfo = new ResultInfo(table, con);
32: outputFileName = outputfile;
33: StringBuilder sql = new StringBuilder(100);
34: sql.append("SELECT ");
35: ColumnIdentifier[] cols = resultInfo.getColumns();
36: if (cols.length == 0)
37: throw new SQLException("Table '"
38: + table.getTableExpression() + "' not found!");
39: for (int i = 0; i < cols.length; i++) {
40: if (i > 0)
41: sql.append(',');
42: sql.append(cols[i].getColumnName());
43: }
44: sql.append(" FROM ");
45: resultInfo.setUpdateTable(table);
46: sql.append(table.getTableExpression(con));
47: this .query = sql.toString();
48: }
49:
50: public String getOutputFile() {
51: return outputFileName;
52: }
53:
54: public String getTableName() {
55: if (resultInfo != null) {
56: return resultInfo.getUpdateTable().getTableName();
57: } else {
58: return null;
59: }
60: }
61:
62: public String getQuerySql() {
63: return query;
64: }
65:
66: public ResultInfo getResultInfo() {
67: return resultInfo;
68: }
69: }
|