KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mvnforum > phpbb2mvnforum > db > jdbc > PhpbbTopicsDAOImpl


1 package org.mvnforum.phpbb2mvnforum.db.jdbc;
2
3 import java.sql.Connection JavaDoc;
4 import java.sql.PreparedStatement JavaDoc;
5 import java.sql.ResultSet JavaDoc;
6 import java.sql.SQLException JavaDoc;
7 import java.util.ArrayList JavaDoc;
8 import java.util.Collection JavaDoc;
9
10 import net.myvietnam.mvncore.exception.DatabaseException;
11 import net.myvietnam.mvncore.exception.ObjectNotFoundException;
12
13 import org.mvnforum.phpbb2mvnforum.db.PhpbbTopics;
14 import org.mvnforum.phpbb2mvnforum.db.PhpbbTopicsDAO;
15 import org.mvnforum.util.DBUtils;
16
17 public class PhpbbTopicsDAOImpl implements PhpbbTopicsDAO {
18     
19     /*
20      * Included columns: topic_id, forum_id, topic_title, topic_poster, topic_time,
21      * topic_views, topic_replies, topic_status, topic_vote, topic_type,
22      * topic_first_post_id, topic_last_post_id, topic_moved_id
23      * Excluded columns:
24      */

25     public Collection JavaDoc getBeans() throws DatabaseException {
26
27         Connection JavaDoc connection = null;
28         PreparedStatement JavaDoc statement = null;
29         ResultSet JavaDoc resultSet = null;
30         Collection JavaDoc retValue = new ArrayList JavaDoc();
31         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
32         sql.append("SELECT topic_id, forum_id, topic_title, topic_poster, topic_time, topic_views, topic_replies, topic_status, topic_vote, topic_type, topic_first_post_id, topic_last_post_id, topic_moved_id");
33         sql.append(" FROM " + TABLE_NAME);
34         //sql.append(" WHERE "); // @todo: uncomment as needed
35
//sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
36
try {
37             connection = DBUtils.getPhpbbConnection();
38             statement = connection.prepareStatement(sql.toString());
39             resultSet = statement.executeQuery();
40             while (resultSet.next()) {
41                 PhpbbTopics bean = new PhpbbTopics();
42                 bean.settopic_id(resultSet.getInt("topic_id"));
43                 bean.setforum_id(resultSet.getInt("forum_id"));
44                 bean.settopic_title(resultSet.getString("topic_title"));
45                 bean.settopic_poster(resultSet.getInt("topic_poster"));
46                 bean.settopic_time(resultSet.getInt("topic_time"));
47                 bean.settopic_views(resultSet.getInt("topic_views"));
48                 bean.settopic_replies(resultSet.getInt("topic_replies"));
49                 bean.settopic_status(resultSet.getInt("topic_status"));
50                 bean.settopic_vote(resultSet.getInt("topic_vote"));
51                 bean.settopic_type(resultSet.getInt("topic_type"));
52                 bean.settopic_first_post_id(resultSet.getInt("topic_first_post_id"));
53                 bean.settopic_last_post_id(resultSet.getInt("topic_last_post_id"));
54                 bean.settopic_moved_id(resultSet.getInt("topic_moved_id"));
55                 retValue.add(bean);
56             }
57             return retValue;
58         } catch(SQLException JavaDoc sqle) {
59             throw new DatabaseException("Error executing SQL in phpbb_topicsDAOImplJDBC.getBeans.");
60         } finally {
61             DBUtils.closeResultSet(resultSet);
62             DBUtils.closeStatement(statement);
63             DBUtils.closeConnection(connection);
64         }
65     }
66
67     public Collection JavaDoc getBeansByForumID(int forumID)
68         throws DatabaseException {
69         // TODO Auto-generated method stub
70
Connection JavaDoc connection = null;
71         PreparedStatement JavaDoc statement = null;
72         ResultSet JavaDoc resultSet = null;
73         Collection JavaDoc retValue = new ArrayList JavaDoc();
74         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
75         sql.append("SELECT topic_id, forum_id, topic_title, topic_poster, topic_time, topic_views, topic_replies, topic_status, topic_vote, topic_type, topic_first_post_id, topic_last_post_id, topic_moved_id");
76         sql.append(" FROM " + TABLE_NAME);
77         sql.append(" WHERE forum_id = ?");
78         //sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
79
try {
80             connection = DBUtils.getPhpbbConnection();
81             statement = connection.prepareStatement(sql.toString());
82             statement.setInt(1, forumID);
83             resultSet = statement.executeQuery();
84             while (resultSet.next()) {
85                 PhpbbTopics bean = new PhpbbTopics();
86                 bean.settopic_id(resultSet.getInt("topic_id"));
87                 bean.setforum_id(resultSet.getInt("forum_id"));
88                 bean.settopic_title(resultSet.getString("topic_title"));
89                 bean.settopic_poster(resultSet.getInt("topic_poster"));
90                 bean.settopic_time(resultSet.getInt("topic_time"));
91                 bean.settopic_views(resultSet.getInt("topic_views"));
92                 bean.settopic_replies(resultSet.getInt("topic_replies"));
93                 bean.settopic_status(resultSet.getInt("topic_status"));
94                 bean.settopic_vote(resultSet.getInt("topic_vote"));
95                 bean.settopic_type(resultSet.getInt("topic_type"));
96                 bean.settopic_first_post_id(resultSet.getInt("topic_first_post_id"));
97                 bean.settopic_last_post_id(resultSet.getInt("topic_last_post_id"));
98                 bean.settopic_moved_id(resultSet.getInt("topic_moved_id"));
99                 retValue.add(bean);
100             }
101             return retValue;
102         } catch(SQLException JavaDoc sqle) {
103             throw new DatabaseException("Error executing SQL in phpbb_topicsDAOImplJDBC.getBeans.");
104         } finally {
105             DBUtils.closeResultSet(resultSet);
106             DBUtils.closeStatement(statement);
107             DBUtils.closeConnection(connection);
108         }
109     }
110
111     public PhpbbTopics getBeans(int topicID) throws ObjectNotFoundException, DatabaseException {
112         // TODO Auto-generated method stub
113
Connection JavaDoc connection = null;
114             PreparedStatement JavaDoc statement = null;
115             ResultSet JavaDoc resultSet = null;
116             StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
117             sql.append("SELECT topic_id, forum_id, topic_title, topic_poster, topic_time, topic_views, topic_replies, topic_status, topic_vote, topic_type, topic_first_post_id, topic_last_post_id, topic_moved_id");
118             sql.append(" FROM " + TABLE_NAME);
119             sql.append(" WHERE topic_id = ?");
120             try {
121                 connection = DBUtils.getPhpbbConnection();
122                 statement = connection.prepareStatement(sql.toString());
123                 statement.setInt(1, topicID);
124                 resultSet = statement.executeQuery();
125                 if(!resultSet.next()) {
126                     throw new ObjectNotFoundException("Cannot find the row in table phpbb_topics where primary key = (" + topicID + ").");
127                 }
128
129                 PhpbbTopics bean = new PhpbbTopics();
130                 // @todo: uncomment the following line(s) as needed
131
//bean.settopic_id(topic_id);
132
bean.settopic_id(resultSet.getInt("topic_id"));
133                 bean.setforum_id(resultSet.getInt("forum_id"));
134                 bean.settopic_title(resultSet.getString("topic_title"));
135                 bean.settopic_poster(resultSet.getInt("topic_poster"));
136                 bean.settopic_time(resultSet.getInt("topic_time"));
137                 bean.settopic_views(resultSet.getInt("topic_views"));
138                 bean.settopic_replies(resultSet.getInt("topic_replies"));
139                 bean.settopic_status(resultSet.getInt("topic_status"));
140                 bean.settopic_vote(resultSet.getInt("topic_vote"));
141                 bean.settopic_type(resultSet.getInt("topic_type"));
142                 bean.settopic_first_post_id(resultSet.getInt("topic_first_post_id"));
143                 bean.settopic_last_post_id(resultSet.getInt("topic_last_post_id"));
144                 bean.settopic_moved_id(resultSet.getInt("topic_moved_id"));
145                 return bean;
146             } catch(SQLException JavaDoc sqle) {
147                 throw new DatabaseException("Error executing SQL in phpbb_topicsDAOImplJDBC.getBean(pk).");
148             } finally {
149                 DBUtils.closeResultSet(resultSet);
150                 DBUtils.closeStatement(statement);
151                 DBUtils.closeConnection(connection);
152             }
153         }
154 }
155
Popular Tags