Source Code Cross Referenced for DbGroupIterator.java in  » Forum » nemesis-forum » org » nemesis » forum » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Forum » nemesis forum » org.nemesis.forum.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * NEMESIS-FORUM.
003:         * Copyright (C) 2002  David Laurent(lithium2@free.fr). All rights reserved.
004:         * 
005:         * Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
006:         * 
007:         * Copyright (C) 2001 Yasna.com. All rights reserved.
008:         * 
009:         * Copyright (C) 2000 CoolServlets.com. All rights reserved.
010:         * 
011:         * NEMESIS-FORUM. is free software; you can redistribute it and/or
012:         * modify it under the terms of the Apache Software License, Version 1.1,
013:         * or (at your option) any later version.
014:         * 
015:         * NEMESIS-FORUM core framework, NEMESIS-FORUM backoffice, NEMESIS-FORUM frontoffice
016:         * application are parts of NEMESIS-FORUM and are distributed under
017:         * same terms of licence.
018:         * 
019:         * 
020:         * NEMESIS-FORUM includes software developed by the Apache Software Foundation (http://www.apache.org/)
021:         * and software developed by CoolServlets.com (http://www.coolservlets.com).
022:         * and software developed by Yasna.com (http://www.yasna.com).
023:         * 
024:         */
025:        package org.nemesis.forum.impl;
026:
027:        import java.sql.Connection;
028:        import java.sql.PreparedStatement;
029:        import java.sql.ResultSet;
030:        import java.sql.SQLException;
031:        import java.util.ArrayList;
032:        import java.util.Iterator;
033:        import java.util.ListIterator;
034:        import java.util.NoSuchElementException;
035:
036:        import org.apache.commons.logging.Log;
037:        import org.apache.commons.logging.LogFactory;
038:        import org.nemesis.forum.Group;
039:        import org.nemesis.forum.ProfileManager;
040:        import org.nemesis.forum.exception.GroupNotFoundException;
041:        import org.nemesis.forum.util.jdbc.DbConnectionManager;
042:
043:        /**
044:         * Iterates through all the groups in the system.
045:         */
046:        public class DbGroupIterator implements  Iterator, ListIterator {
047:            static protected Log log = LogFactory.getLog(DbGroupIterator.class);
048:            /** DATABASE QUERIES **/
049:            private static final String ALL_GROUPS = "SELECT groupID from yazdGroup";
050:
051:            private int currentIndex = -1;
052:            private int[] groups;
053:
054:            private ProfileManager profileManager;
055:
056:            protected DbGroupIterator(ProfileManager profileManager) {
057:                this .profileManager = profileManager;
058:                //We don't know how many results will be returned, so store them
059:                //in an ArrayList.
060:                ArrayList tempGroups = new ArrayList();
061:                Connection con = null;
062:                PreparedStatement pstmt = null;
063:                try {
064:                    con = DbConnectionManager.getConnection();
065:                    pstmt = con.prepareStatement(ALL_GROUPS);
066:                    ResultSet rs = pstmt.executeQuery();
067:                    while (rs.next()) {
068:                        tempGroups.add(new Integer(rs.getInt("groupID")));
069:                    }
070:                } catch (SQLException sqle) {
071:                    log.error("Error in DbGroupIterator:constructor()-", sqle);
072:                } finally {
073:                    try {
074:                        pstmt.close();
075:                    } catch (Exception e) {
076:                        log.error("", e);
077:                    }
078:                    try {
079:                        con.close();
080:                    } catch (Exception e) {
081:                        log.error("", e);
082:                    }
083:                }
084:                groups = new int[tempGroups.size()];
085:                for (int i = 0; i < groups.length; i++) {
086:                    groups[i] = ((Integer) tempGroups.get(i)).intValue();
087:                }
088:            }
089:
090:            protected DbGroupIterator(ProfileManager profileManager,
091:                    int startIndex, int numResults) {
092:                this .profileManager = profileManager;
093:
094:                int[] tempResults = new int[numResults];
095:                //It's very possible that there might not be as many results to get
096:                //as we requested. Therefore, we keep track of how many results we
097:                //get by keeping a count.
098:                int resultCount = 0;
099:
100:                Connection con = null;
101:                PreparedStatement pstmt = null;
102:
103:                try {
104:                    con = DbConnectionManager.getConnection();
105:                    pstmt = con.prepareStatement(ALL_GROUPS);
106:                    ResultSet rs = pstmt.executeQuery();
107:                    //Move to start of index
108:                    for (int i = 0; i < startIndex; i++) {
109:                        rs.next();
110:                    }
111:                    //Now read in desired number of results
112:                    for (int i = 0; i < numResults; i++) {
113:                        if (rs.next()) {
114:                            tempResults[resultCount] = rs.getInt("groupID");
115:                            resultCount++;
116:                        } else {
117:                            break;
118:                        }
119:                    }
120:                } catch (SQLException sqle) {
121:                    log.error("Error in DbGroupIterator:constructor()-", sqle);
122:                } finally {
123:                    try {
124:                        pstmt.close();
125:                    } catch (Exception e) {
126:                        log.error("", e);
127:                    }
128:                    try {
129:                        con.close();
130:                    } catch (Exception e) {
131:                        log.error("", e);
132:                    }
133:                }
134:                groups = new int[resultCount];
135:                for (int i = 0; i < resultCount; i++) {
136:                    groups[i] = tempResults[i];
137:                }
138:            }
139:
140:            /**
141:             * Returns true if there are more groups left to iteratate through.
142:             */
143:            public boolean hasNext() {
144:                return (currentIndex + 1 < groups.length);
145:            }
146:
147:            /**
148:             * Returns the next Group.
149:             */
150:            public Object next() throws NoSuchElementException {
151:                Group group = null;
152:                currentIndex++;
153:                if (currentIndex >= groups.length) {
154:                    throw new java.util.NoSuchElementException();
155:                }
156:                try {
157:                    group = profileManager.getGroup(groups[currentIndex]);
158:                } catch (GroupNotFoundException gnfe) {
159:                    log.error("", gnfe);
160:                }
161:                return group;
162:            }
163:
164:            /**
165:             * For security reasons, the remove operation is not supported. Use
166:             * ProfileManager.deleteGroup() instead.
167:             *
168:             * @see ProfileManager
169:             */
170:            public void remove() {
171:                throw new UnsupportedOperationException();
172:            }
173:
174:            /**
175:             * Returns true if there are more groups left to iterate through backwards.
176:             */
177:            public boolean hasPrevious() {
178:                return (currentIndex > 0);
179:            }
180:
181:            /**
182:             * For security reasons, the add operation is not supported. Use
183:             * ProfileManager instead.
184:             *
185:             * @see ProfileManager
186:             */
187:            public void add(Object o) throws UnsupportedOperationException {
188:                throw new UnsupportedOperationException();
189:            }
190:
191:            /**
192:             * For security reasons, the set operation is not supported. Use
193:             * ProfileManager instead.
194:             *
195:             * @see ProfileManager
196:             */
197:            public void set(Object o) throws UnsupportedOperationException {
198:                throw new UnsupportedOperationException();
199:            }
200:
201:            /**
202:             * Returns the index number that would be returned with a call to next().
203:             */
204:            public int nextIndex() {
205:                return currentIndex + 1;
206:            }
207:
208:            /**
209:             * Returns the previous group.
210:             */
211:            public Object previous() throws java.util.NoSuchElementException {
212:                Group group = null;
213:                currentIndex--;
214:                if (currentIndex < 0) {
215:                    currentIndex++;
216:                    throw new java.util.NoSuchElementException();
217:                }
218:                try {
219:                    group = profileManager.getGroup(groups[currentIndex]);
220:                } catch (GroupNotFoundException gnfe) {
221:                    log.error("", gnfe);
222:                }
223:                return group;
224:            }
225:
226:            /**
227:             * Returns the index number that would be returned with a call to previous().
228:             */
229:            public int previousIndex() {
230:                return currentIndex - 1;
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.