1 package com.explosion.expfmodules.rdbmsconn.dbom;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.sql.ResultSet;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Vector;
28
29 import javax.swing.table.DefaultTableModel;
30
31 /***
32 * This class is the result of merging a result set with a TableModel. It
33 * contains a reference to the result set, a reference to the table model and
34 * also various other information about the data.
35 *
36 * @author Stephen Cowx
37 */
38
39 public class DataSet
40 {
41 private int numberOfRowsUpdated = 0;
42 private int[] longestEntryLengths;
43 private String[] longestEntries;
44 private DefaultTableModel tableModel;
45 private String message = null;
46
47 private ResultSet resultSet = null;
48 private Vector columnNames = new Vector();
49 private HashMap columns = new HashMap();
50 private List errors;
51
52 /***
53 * Construsts an empty dataset
54 *
55 */
56 public DataSet()
57 {
58 }
59
60 /***
61 * Returns the widest value of the given column. In numberOfCharacters
62 */
63 public int getLongestEntryLength(int columnIndex)
64 {
65 return longestEntryLengths[columnIndex];
66 }
67
68 /***
69 * Returns the all of the longest entries per column as an array of Strings
70 */
71 public String[] getLongestEntries()
72 {
73 return longestEntries;
74 }
75
76 /***
77 * @param longestEntries The longestEntries to set.
78 */
79 public void setLongestEntries(String[] longestEntries)
80 {
81 this.longestEntries = longestEntries;
82 }
83
84 /***
85 * Returns the all of the lengths of the widest(longest) entries per column
86 * as an array of ints
87 */
88 public int[] getLongestEntryLengths()
89 {
90 return longestEntryLengths;
91 }
92
93 /***
94 * @param longestEntryLengths The longestEntryLengths to set.
95 */
96 public void setLongestEntryLengths(int[] longestEntryLengths)
97 {
98 this.longestEntryLengths = longestEntryLengths;
99 }
100
101 /***
102 * Returns the message created when this dataset was created.
103 *
104 * @return
105 */
106 public String getMessage()
107 {
108 return this.message;
109 }
110
111 /***
112 * @param message The message to set.
113 */
114 public void setMessage(String message)
115 {
116 this.message = message;
117 }
118
119 /***
120 * returns the result set for this dataset
121 *
122 * @return
123 */
124 public ResultSet getResultSet()
125 {
126 return this.resultSet;
127 }
128
129 /***
130 * @param resultSet The resultSet to set.
131 */
132 public void setResultSet(ResultSet resultSet)
133 {
134 this.resultSet = resultSet;
135 }
136
137 /***
138 * Returns the tabelModel containing the results
139 */
140 public DefaultTableModel getTableModel()
141 {
142 return this.tableModel;
143 }
144
145 /***
146 * @param sets the data of this Dataset. It should be a Vector of vectors;
147 */
148 public void setData(Vector data)
149 {
150 if (data == null)
151 this.tableModel = new DefaultTableModel();
152 else
153 this.tableModel = new DefaultTableModel(data,getColumnNames());
154 }
155
156 /***
157 * Returns the names o fall the columns as a Vector of Strings
158 */
159 public Vector getColumnNames()
160 {
161 return columnNames;
162 }
163
164 /***
165 * Returns the columnAttributes for the named column
166 *
167 * @param columnName
168 * @return
169 */
170 public DataSetColumn getColumn(String columnName)
171 {
172 return (DataSetColumn) columns.get(columnName);
173 }
174
175 /***
176 * Adds the column to this dataSet.
177 *
178 * @param columnName
179 * @param attributes
180 */
181 public void addColumn(DataSetColumn column)
182 {
183 columns.put(column.getColumnName(), column);
184 columnNames.add(column.getColumnName());
185 }
186
187 /***
188 * Returns the numberOfRowsUpdated.
189 * @return
190 */
191 public int getNumberOfRowsUpdated()
192 {
193 return numberOfRowsUpdated;
194 }
195 /***
196 * Sets the numberOfRows that were updated
197 * @param numberOfRowsUpdated
198 */
199 public void setNumberOfRowsUpdated(int numberOfRowsUpdated)
200 {
201 this.numberOfRowsUpdated = numberOfRowsUpdated;
202 }
203
204 /***
205 * This method returns a list of the error nmessages in this result set if there are any
206 * @return
207 */
208 public List getErrors()
209 {
210 return errors;
211 }
212
213 /***
214 * This method allows for errors to be added to this dataset
215 * @param error
216 */
217 public void addError(Throwable error)
218 {
219 if (errors == null)
220 errors = new ArrayList();
221
222 errors.add(error);
223 }
224 }