1 25 29 package org.jresearch.gossip.list; 30 31 import java.lang.reflect.InvocationTargetException ; 32 import java.sql.ResultSet ; 33 import java.sql.SQLException ; 34 import java.util.ArrayList ; 35 import java.util.HashMap ; 36 import java.util.Iterator ; 37 import java.util.Set ; 38 39 import org.apache.commons.beanutils.PropertyUtils; 40 import org.jresearch.gossip.dao.drivers.DbDriver; 41 42 47 public class RecordsData { 48 private ArrayList records; 49 50 private int recordsCount; 51 52 private int currBlock; 53 54 private int blockSize; 55 56 61 public int getCurrBlock() { 62 return currBlock; 63 } 64 65 70 public int getCurrentPage() { 71 return Math.round(currBlock / blockSize) + 1; 72 } 73 74 79 public boolean isLastBlock() { 80 return ((recordsCount - currBlock) <= blockSize); 81 } 82 83 88 public boolean isHaveSplit() { 89 return (recordsCount > blockSize); 90 } 91 92 97 public ArrayList getRecords() { 98 return records; 99 } 100 101 106 public int getRecordsCount() { 107 return recordsCount; 108 } 109 110 115 public void setCurrBlock(int i) { 116 currBlock = i; 117 } 118 119 124 public void setRecordsCount(int i) { 125 recordsCount = i; 126 } 127 128 149 public void fillRecords(ResultSet rs, HashMap mapping, java.lang.Class klass) 150 throws InstantiationException , IllegalAccessException , 151 InvocationTargetException , NoSuchMethodException , SQLException { 152 Set keys = mapping.keySet(); 153 this.records = new ArrayList (); 154 155 DbDriver dvDriver = DbDriver.getInstance(); 156 157 while (rs.next()) { 158 Object item = klass.newInstance(); 159 Iterator it = keys.iterator(); 160 161 while (it.hasNext()) { 162 String key = (String ) it.next(); 163 PropertyUtils.setProperty(item, key, dvDriver.mapObjectType(rs 164 .getObject((String ) mapping.get(key)))); 165 } 166 167 this.records.add(item); 168 } 169 } 170 171 176 public int getBlockSize() { 177 return blockSize; 178 } 179 180 185 public void setBlockSize(int i) { 186 blockSize = i; 187 } 188 } 189 | Popular Tags |