1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.beanutils;
20
21
22 import java.lang.reflect.InvocationHandler;
23 import java.lang.reflect.Method;
24 import java.lang.reflect.Proxy;
25 import java.sql.ResultSetMetaData;
26 import java.sql.SQLException;
27 import java.sql.Types;
28
29
30
31
32
33
34
35
36
37
38 public class TestResultSetMetaData implements InvocationHandler {
39
40
41
42
43
44
45
46
47 protected String metadata[][] = {
48 { "bigDecimalProperty", java.math.BigDecimal.class.getName() },
49 { "booleanProperty", Boolean.class.getName() },
50 { "byteProperty", Byte.class.getName() },
51 { "dateProperty", java.sql.Date.class.getName() },
52 { "doubleProperty", Double.class.getName() },
53 { "floatProperty", Float.class.getName() },
54 { "intProperty", Integer.class.getName() },
55 { "longProperty", Long.class.getName() },
56 { "nullProperty", String.class.getName() },
57 { "shortProperty", Short.class.getName() },
58 { "stringProperty", String.class.getName() },
59 { "timeProperty", java.sql.Time.class.getName() },
60 { "timestampProperty", java.sql.Timestamp.class.getName() },
61 };
62
63
64
65
66
67
68
69 public static ResultSetMetaData createProxy() {
70 return TestResultSetMetaData.createProxy(new TestResultSetMetaData());
71 }
72
73
74
75
76
77
78 public static ResultSetMetaData createProxy(final InvocationHandler invocationHandler) {
79 final ClassLoader classLoader = ResultSetMetaData.class.getClassLoader();
80 final Class<?>[] interfaces = new Class[] { ResultSetMetaData.class };
81 return (ResultSetMetaData)Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
82 }
83
84
85
86
87
88
89
90
91
92
93 public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
94 final String methodName = method.getName();
95 if ("getColumnClassName".equals(methodName)) {
96 return getColumnClassName(((Integer)args[0]).intValue());
97 } if ("getColumnCount".equals(methodName)) {
98 return new Integer(getColumnCount());
99 } if ("getColumnName".equals(methodName)) {
100 return getColumnName(((Integer)args[0]).intValue());
101 } if ("getColumnType".equals(methodName)) {
102 return getColumnType(((Integer)args[0]).intValue());
103 }
104
105 throw new UnsupportedOperationException(methodName + " not implemented");
106 }
107
108
109
110
111 public String getColumnClassName(final int columnIndex) throws SQLException {
112 return (metadata[columnIndex - 1][1]);
113 }
114
115
116 public int getColumnCount() throws SQLException {
117 return (metadata.length);
118 }
119
120 public String getColumnName(final int columnIndex) throws SQLException {
121 return (metadata[columnIndex - 1][0]);
122 }
123
124
125 public Integer getColumnType(final int columnIndex) throws SQLException {
126 final String columnName = getColumnName(columnIndex);
127 int sqlType = Types.OTHER;
128 if (columnName.equals("bigDecimalProperty")) {
129 sqlType = Types.DECIMAL;
130
131
132
133 } else if (columnName.equals("byteProperty")) {
134 sqlType = Types.TINYINT;
135 } else if (columnName.equals("dateProperty")) {
136 sqlType = Types.DATE;
137 } else if (columnName.equals("doubleProperty")) {
138 sqlType = Types.DOUBLE;
139 } else if (columnName.equals("floatProperty")) {
140 sqlType = Types.FLOAT;
141 } else if (columnName.equals("intProperty")) {
142 sqlType = Types.INTEGER;
143 } else if (columnName.equals("longProperty")) {
144 sqlType = Types.BIGINT;
145 } else if (columnName.equals("nullProperty")) {
146 sqlType = Types.VARCHAR;
147 } else if (columnName.equals("shortProperty")) {
148 sqlType = Types.SMALLINT;
149 } else if (columnName.equals("stringProperty")) {
150 sqlType = Types.VARCHAR;
151 } else if (columnName.equals("timeProperty")) {
152 sqlType = Types.TIME;
153 } else if (columnName.equals("timestampProperty")) {
154 sqlType = Types.TIMESTAMP;
155 } else {
156 sqlType = Types.OTHER;
157 }
158 return new Integer(sqlType);
159 }
160
161
162
163
164
165 public String getCatalogName(final int columnIndex) throws SQLException {
166 throw new UnsupportedOperationException();
167 }
168
169
170 public int getColumnDisplaySize(final int columnIndex) throws SQLException {
171 throw new UnsupportedOperationException();
172 }
173
174
175 public String getColumnLabel(final int columnIndex) throws SQLException {
176 throw new UnsupportedOperationException();
177 }
178
179
180 public String getColumnTypeName(final int columnIndex) throws SQLException {
181 throw new UnsupportedOperationException();
182 }
183
184
185 public int getPrecision(final int columnIndex) throws SQLException {
186 throw new UnsupportedOperationException();
187 }
188
189
190 public int getScale(final int columnIndex) throws SQLException {
191 throw new UnsupportedOperationException();
192 }
193
194
195 public String getSchemaName(final int columnIndex) throws SQLException {
196 throw new UnsupportedOperationException();
197 }
198
199
200 public String getTableName(final int columnIndex) throws SQLException {
201 throw new UnsupportedOperationException();
202 }
203
204
205 public boolean isAutoIncrement(final int columnIndex) throws SQLException {
206 throw new UnsupportedOperationException();
207 }
208
209
210 public boolean isCaseSensitive(final int columnIndex) throws SQLException {
211 throw new UnsupportedOperationException();
212 }
213
214
215 public boolean isCurrency(final int columnIndex) throws SQLException {
216 throw new UnsupportedOperationException();
217 }
218
219
220 public boolean isDefinitelyWritable(final int columnIndex) throws SQLException {
221 throw new UnsupportedOperationException();
222 }
223
224
225 public int isNullable(final int columnIndex) throws SQLException {
226 throw new UnsupportedOperationException();
227 }
228
229
230 public boolean isReadOnly(final int columnIndex) throws SQLException {
231 throw new UnsupportedOperationException();
232 }
233
234
235 public boolean isSearchable(final int columnIndex) throws SQLException {
236 throw new UnsupportedOperationException();
237 }
238
239
240 public boolean isSigned(final int columnIndex) throws SQLException {
241 throw new UnsupportedOperationException();
242 }
243
244
245 public boolean isWritable(final int columnIndex) throws SQLException {
246 throw new UnsupportedOperationException();
247 }
248
249
250 }