1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.dbutils;
18
19 import java.lang.reflect.InvocationHandler;
20 import java.lang.reflect.Method;
21 import java.sql.ResultSetMetaData;
22
23
24
25
26
27 public class MockResultSetMetaData implements InvocationHandler {
28
29 private String[] columnNames = null;
30
31
32
33
34
35
36
37
38
39
40
41 public static ResultSetMetaData create(String[] columnNames) {
42 return ProxyFactory.instance().createResultSetMetaData(
43 new MockResultSetMetaData(columnNames));
44 }
45
46 public MockResultSetMetaData(String[] columnNames) {
47 super();
48 this.columnNames = columnNames;
49
50 }
51
52 public Object invoke(Object proxy, Method method, Object[] args)
53 throws Throwable {
54
55 String methodName = method.getName();
56
57 if (methodName.equals("getColumnCount")) {
58 return new Integer(this.columnNames.length);
59
60 } else if (
61 methodName.equals("getColumnName")
62 || methodName.equals("getColumnLabel")) {
63
64 int col = ((Integer) args[0]).intValue() - 1;
65 return this.columnNames[col];
66
67 } else if (methodName.equals("hashCode")) {
68 return new Integer(System.identityHashCode(proxy));
69
70 } else if (methodName.equals("toString")) {
71 return "MockResultSetMetaData " + System.identityHashCode(proxy);
72
73 } else if (methodName.equals("equals")) {
74 return new Boolean(proxy == args[0]);
75
76 } else {
77 throw new UnsupportedOperationException("Unsupported method: " + methodName);
78 }
79 }
80 }