KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > list > RecordsData


1 /*
2  * $$Id: RecordsData.java,v 1.3 2005/06/07 12:32:35 bel70 Exp $$
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitry Belov <bel@jresearch.org>
23  *
24  * ***** END LICENSE BLOCK ***** */

25 /*
26  * Created on Jul 13, 2003
27  *
28  */

29 package org.jresearch.gossip.list;
30
31 import java.lang.reflect.InvocationTargetException JavaDoc;
32 import java.sql.ResultSet JavaDoc;
33 import java.sql.SQLException JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.util.Set JavaDoc;
38
39 import org.apache.commons.beanutils.PropertyUtils;
40 import org.jresearch.gossip.dao.drivers.DbDriver;
41
42 /**
43  * DOCUMENT ME!
44  *
45  * @author Bel
46  */

47 public class RecordsData {
48     private ArrayList JavaDoc records;
49
50     private int recordsCount;
51
52     private int currBlock;
53
54     private int blockSize;
55
56     /**
57      * DOCUMENT ME!
58      *
59      * @return
60      */

61     public int getCurrBlock() {
62         return currBlock;
63     }
64
65     /**
66      * DOCUMENT ME!
67      *
68      * @return DOCUMENT ME!
69      */

70     public int getCurrentPage() {
71         return Math.round(currBlock / blockSize) + 1;
72     }
73
74     /**
75      * DOCUMENT ME!
76      *
77      * @return DOCUMENT ME!
78      */

79     public boolean isLastBlock() {
80         return ((recordsCount - currBlock) <= blockSize);
81     }
82
83     /**
84      * DOCUMENT ME!
85      *
86      * @return DOCUMENT ME!
87      */

88     public boolean isHaveSplit() {
89         return (recordsCount > blockSize);
90     }
91
92     /**
93      * DOCUMENT ME!
94      *
95      * @return
96      */

97     public ArrayList JavaDoc getRecords() {
98         return records;
99     }
100
101     /**
102      * DOCUMENT ME!
103      *
104      * @return
105      */

106     public int getRecordsCount() {
107         return recordsCount;
108     }
109
110     /**
111      * DOCUMENT ME!
112      *
113      * @param i
114      */

115     public void setCurrBlock(int i) {
116         currBlock = i;
117     }
118
119     /**
120      * DOCUMENT ME!
121      *
122      * @param i
123      */

124     public void setRecordsCount(int i) {
125         recordsCount = i;
126     }
127
128     /**
129      * DOCUMENT ME!
130      *
131      * @param rs
132      * DOCUMENT ME!
133      * @param mapping
134      * DOCUMENT ME!
135      * @param klass
136      * DOCUMENT ME!
137      *
138      * @throws InstantiationException
139      * DOCUMENT ME!
140      * @throws IllegalAccessException
141      * DOCUMENT ME!
142      * @throws InvocationTargetException
143      * DOCUMENT ME!
144      * @throws NoSuchMethodException
145      * DOCUMENT ME!
146      * @throws SQLException
147      * DOCUMENT ME!
148      */

149     public void fillRecords(ResultSet JavaDoc rs, HashMap JavaDoc mapping, java.lang.Class JavaDoc klass)
150             throws InstantiationException JavaDoc, IllegalAccessException JavaDoc,
151             InvocationTargetException JavaDoc, NoSuchMethodException JavaDoc, SQLException JavaDoc {
152         Set JavaDoc keys = mapping.keySet();
153         this.records = new ArrayList JavaDoc();
154
155         DbDriver dvDriver = DbDriver.getInstance();
156
157         while (rs.next()) {
158             Object JavaDoc item = klass.newInstance();
159             Iterator JavaDoc it = keys.iterator();
160
161             while (it.hasNext()) {
162                 String JavaDoc key = (String JavaDoc) it.next();
163                 PropertyUtils.setProperty(item, key, dvDriver.mapObjectType(rs
164                         .getObject((String JavaDoc) mapping.get(key))));
165             }
166
167             this.records.add(item);
168         }
169     }
170
171     /**
172      * DOCUMENT ME!
173      *
174      * @return
175      */

176     public int getBlockSize() {
177         return blockSize;
178     }
179
180     /**
181      * DOCUMENT ME!
182      *
183      * @param i
184      */

185     public void setBlockSize(int i) {
186         blockSize = i;
187     }
188 }
189
Popular Tags