01: /*
02: * DummySelect.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2007, 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;
13:
14: import java.sql.SQLException;
15: import workbench.resource.Settings;
16: import workbench.storage.DataStore;
17: import workbench.util.StringUtil;
18:
19: /**
20: * @author support@sql-workbench.net
21: */
22: public class DummySelect implements DbObject {
23: private TableIdentifier table;
24:
25: public DummySelect(TableIdentifier tbl) {
26: this .table = tbl;
27: }
28:
29: public String getCatalog() {
30: return null;
31: }
32:
33: public String getObjectExpression(WbConnection conn) {
34: return null;
35: }
36:
37: public String getObjectName() {
38: return null;
39: }
40:
41: public String getObjectName(WbConnection conn) {
42: return null;
43: }
44:
45: public String getObjectType() {
46: return "SELECT";
47: }
48:
49: public String getSchema() {
50: return null;
51: }
52:
53: public CharSequence getSource(WbConnection con) throws SQLException {
54: DbMetadata meta = con.getMetadata();
55: String nl = Settings.getInstance()
56: .getInternalEditorLineEnding();
57: DataStore tableDef = meta.getTableDefinition(table);
58:
59: if (tableDef.getRowCount() == 0)
60: return StringUtil.EMPTY_STRING;
61: int colCount = tableDef.getRowCount();
62: if (colCount == 0)
63: return StringUtil.EMPTY_STRING;
64:
65: StringBuilder sql = new StringBuilder(colCount * 80);
66:
67: sql.append("SELECT ");
68: for (int i = 0; i < colCount; i++) {
69: String column = tableDef.getValueAsString(i,
70: DbMetadata.COLUMN_IDX_TABLE_DEFINITION_COL_NAME);
71: if (i > 0) {
72: sql.append(',');
73: sql.append(nl);
74: sql.append(" ");
75: }
76:
77: sql.append(column);
78: }
79: sql.append(nl);
80: sql.append("FROM ");
81: sql.append(table.getTableExpression(con));
82: sql.append(';');
83: sql.append(nl);
84:
85: return sql.toString();
86: }
87:
88: }
|