1 16 17 18 package org.apache.commons.beanutils; 19 20 21 import java.io.Serializable ; 22 import java.sql.ResultSet ; 23 import java.sql.SQLException ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 28 67 68 public class RowSetDynaClass extends JDBCDynaClass implements DynaClass, Serializable { 69 70 71 73 78 protected int limit = -1; 79 80 85 protected List rows = new ArrayList (); 86 87 89 90 102 public RowSetDynaClass(ResultSet resultSet) throws SQLException { 103 104 this(resultSet, true, -1); 105 106 } 107 108 124 public RowSetDynaClass(ResultSet resultSet, int limit) throws SQLException { 125 126 this(resultSet, true, limit); 127 128 } 129 130 131 149 public RowSetDynaClass(ResultSet resultSet, boolean lowerCase) 150 throws SQLException { 151 this(resultSet, lowerCase, -1); 152 153 } 154 155 176 public RowSetDynaClass(ResultSet resultSet, boolean lowerCase, int limit) 177 throws SQLException { 178 179 if (resultSet == null) { 180 throw new NullPointerException (); 181 } 182 this.lowerCase = lowerCase; 183 this.limit = limit; 184 introspect(resultSet); 185 copy(resultSet); 186 187 } 188 189 200 public List getRows() { 201 202 return (this.rows); 203 204 } 205 206 207 209 210 221 protected void copy(ResultSet resultSet) throws SQLException { 222 223 int cnt = 0; 224 while (resultSet.next() && (limit < 0 || cnt++ < limit) ) { 225 DynaBean bean = createDynaBean(); 226 for (int i = 0; i < properties.length; i++) { 227 String name = properties[i].getName(); 228 bean.set(name, resultSet.getObject(name)); 229 } 230 rows.add(bean); 231 } 232 233 } 234 235 236 240 protected DynaBean createDynaBean() { 241 242 return (new BasicDynaBean(this)); 243 244 } 245 246 247 } 248 | Popular Tags |