1 21 package net.mlw.vlh.adapter.jdbc.dynabean; 22 23 import java.sql.ResultSet ; 24 import java.sql.SQLException ; 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 import net.mlw.vlh.ValueListInfo; 30 import net.mlw.vlh.adapter.jdbc.AbstractDynaJdbcAdapter; 31 import net.mlw.vlh.adapter.jdbc.dynabean.fix.ResultSetDynaClass; 32 33 import org.apache.commons.beanutils.BasicDynaBean; 34 import org.apache.commons.beanutils.BasicDynaClass; 35 import org.apache.commons.beanutils.DynaBean; 36 import org.apache.commons.beanutils.DynaProperty; 37 import org.apache.commons.logging.Log; 38 import org.apache.commons.logging.LogFactory; 39 40 48 public class DefaultDynaBeanAdapter extends AbstractDynaJdbcAdapter 49 { 50 51 private static final Log LOGGER = LogFactory.getLog(DefaultDynaBeanAdapter.class); 52 53 public List processResultSet(String name, ResultSet result, int numberPerPage, ValueListInfo info) throws SQLException 54 { 55 List list = new ArrayList (); 56 57 ResultSetDynaClass rsdc = new ResultSetDynaClass(result, false, isUseName()); 58 BasicDynaClass bdc = new BasicDynaClass(name, BasicDynaBean.class, rsdc.getDynaProperties()); 59 60 int rowIndex = 0; 61 for (Iterator rows = rsdc.iterator(); rows.hasNext() && rowIndex < numberPerPage; rowIndex++) 62 { 63 try 64 { 65 DynaBean oldRow = (DynaBean) rows.next(); 66 DynaBean newRow = bdc.newInstance(); 67 68 DynaProperty[] properties = oldRow.getDynaClass().getDynaProperties(); 69 for (int i = 0, length = properties.length; i < length; i++) 70 { 71 String propertyName = properties[i].getName(); 72 Object value = oldRow.get(propertyName); 73 newRow.set(propertyName, value); 74 } 75 76 list.add(newRow); 77 } 78 catch (Exception e) 79 { 80 LOGGER.error(e); 81 } 82 } 83 84 return list; 85 } 86 } | Popular Tags |