1 61 62 package org.apache.commons.dbutils; 63 64 import java.lang.reflect.InvocationHandler ; 65 import java.lang.reflect.Method ; 66 import java.sql.ResultSetMetaData ; 67 68 74 public class MockResultSetMetaData implements InvocationHandler { 75 76 private String [] columnNames = null; 77 78 88 public static ResultSetMetaData create(String [] columnNames) { 89 return ProxyFactory.instance().createResultSetMetaData( 90 new MockResultSetMetaData(columnNames)); 91 } 92 93 public MockResultSetMetaData(String [] columnNames) { 94 super(); 95 this.columnNames = columnNames; 96 97 } 98 99 public Object invoke(Object proxy, Method method, Object [] args) 100 throws Throwable { 101 102 String methodName = method.getName(); 103 104 if (methodName.equals("getColumnCount")) { 105 return new Integer (this.columnNames.length); 106 107 } else if ( 108 methodName.equals("getColumnName") 109 || methodName.equals("getColumnLabel")) { 110 111 int col = ((Integer ) args[0]).intValue() - 1; 112 return this.columnNames[col]; 113 114 } else { 116 Class returnType = method.getReturnType(); 117 118 if (returnType.equals(String .class)) { 119 return ""; 120 121 } else if (returnType.equals(Integer.TYPE)) { 122 return new Integer (0); 123 124 } else { 125 return Boolean.FALSE; 126 } 127 } 128 } 129 } | Popular Tags |