1 package com.quantum.sql;
3 import java.sql.ResultSet;
4 import java.sql.ResultSetMetaData;
5 import java.sql.SQLException;
6 import java.util.ArrayList;
8 import java.util.Vector;
10 import com.quantum.model.Bookmark;
11 import com.quantum.model.Entity;
17 public class SQLMetaDataResults extends SQLResultSetResults {
22 private SQLMetaDataResults(String query, Bookmark bookmark, Entity entity) {
23 super(query, bookmark, entity);
26 static SQLResultSetResults create(Bookmark bookmark, ResultSet set, String query, Entity entity) throws SQLException {
28 SQLMetaDataResults results = new SQLMetaDataResults(query, bookmark, entity);
29 results.parseResultSet(set);
39 * @throws SQLException
41 protected void parseResultSet(ResultSet set) throws SQLException {
43 List columns = new ArrayList();
44 columns.add(new Column("ColumnName", "", 0)); //$NON-NLS-1$
45 columns.add(new Column("Type Name", "", 0)); //$NON-NLS-1$
46 columns.add(new Column("Size", "", 0)); //$NON-NLS-1$
47 columns.add(new Column("Scale", "", 0)); //$NON-NLS-1$
48 columns.add(new Column("Nullable", "", 0)); //$NON-NLS-1$
49 columns.add(new Column("AutoIncrement", "", 0)); //$NON-NLS-1$
50 columns.add(new Column("Type", "", 0)); //$NON-NLS-1$
51 setColumns((Column[]) columns.toArray(new Column[columns.size()]));
53 ResultSetMetaData metaData = set.getMetaData();
55 List rowList = new ArrayList();
56 for (int i = 1; i <= metaData.getColumnCount(); i++) {
57 Vector row = new Vector();
58 row.addElement(metaData.getColumnName(i));
59 row.addElement(metaData.getColumnTypeName(i));
60 int precision = metaData.getPrecision(i);
62 precision = metaData.getColumnDisplaySize(i);
64 int scale = metaData.getScale(i);
66 row.addElement(new Integer(precision));
67 row.addElement(new Integer(scale));
69 int nullable = metaData.isNullable(i);
70 if (nullable == ResultSetMetaData.columnNoNulls) {
71 row.addElement("Not Null"); //$NON-NLS-1$
72 } else if (nullable == ResultSetMetaData.columnNullable) {
73 row.addElement("Nullable"); //$NON-NLS-1$
75 nullable == ResultSetMetaData.columnNullableUnknown) {
76 row.addElement("Nullable"); //$NON-NLS-1$
78 row.addElement("<Error>"); //$NON-NLS-1$
81 (metaData.isAutoIncrement(i)
85 rowList.add(new Row(row));
86 row.addElement(new Integer(metaData.getColumnType(i)));
88 setRows((Row[]) rowList.toArray(new Row[rowList.size()]));
91 public boolean isMetaData() {