1 60 61 package org.apache.commons.dbutils.wrappers; 62 63 import java.lang.reflect.InvocationHandler ; 64 import java.lang.reflect.Method ; 65 import java.sql.ResultSet ; 66 67 import org.apache.commons.dbutils.ProxyFactory; 68 69 94 public class StringTrimmedResultSet implements InvocationHandler { 95 96 99 private static final ProxyFactory factory = ProxyFactory.instance(); 100 101 110 public static ResultSet wrap(ResultSet rs) { 111 return factory.createResultSet(new StringTrimmedResultSet(rs)); 112 } 113 114 117 private final ResultSet rs; 118 119 123 public StringTrimmedResultSet(ResultSet rs) { 124 super(); 125 this.rs = rs; 126 } 127 128 136 public Object invoke(Object proxy, Method method, Object [] args) 137 throws Throwable { 138 139 Object result = method.invoke(this.rs, args); 140 141 if (method.getName().equals("getObject") 142 || method.getName().equals("getString")) { 143 144 if (result instanceof String ) { 145 result = ((String ) result).trim(); 146 } 147 } 148 149 return result; 150 } 151 152 } 153 | Popular Tags |