KickJava   Java API By Example, From Geeks To Geeks.

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


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
12 import org.mvnforum.phpbb2mvnforum.db.PhpbbTopicsWatch;
13 import org.mvnforum.phpbb2mvnforum.db.PhpbbTopicsWatchDAO;
14 import org.mvnforum.util.DBUtils;
15
16 public class PhpbbTopicsWatchDAOImpl implements PhpbbTopicsWatchDAO {
17
18     public Collection JavaDoc getBeansByUserID(int userID)
19         throws DatabaseException {
20         // TODO Auto-generated method stub
21
Connection JavaDoc connection = null;
22         PreparedStatement JavaDoc statement = null;
23         ResultSet JavaDoc resultSet = null;
24         Collection JavaDoc retValue = new ArrayList JavaDoc();
25         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
26         sql.append("SELECT topic_id, user_id, notify_status");
27         sql.append(" FROM " + TABLE_NAME);
28         sql.append(" WHERE user_id=?"); // @todo: uncomment as needed
29
//sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
30
try {
31             connection = DBUtils.getPhpbbConnection();
32             statement = connection.prepareStatement(sql.toString());
33             statement.setInt(1, userID);
34             resultSet = statement.executeQuery();
35             while (resultSet.next()) {
36                 PhpbbTopicsWatch bean = new PhpbbTopicsWatch();
37                 bean.settopic_id(resultSet.getInt("topic_id"));
38                 bean.setuser_id(resultSet.getInt("user_id"));
39                 bean.setnotify_status(resultSet.getInt("notify_status"));
40                 retValue.add(bean);
41             }
42             return retValue;
43         } catch (SQLException JavaDoc sqle) {
44             throw new DatabaseException("Error executing SQL in phpbb_topics_watchDAOImplJDBC.getBeans.");
45         } finally {
46             DBUtils.closeResultSet(resultSet);
47             DBUtils.closeStatement(statement);
48             DBUtils.closeConnection(connection);
49         }
50     }
51
52     public Collection JavaDoc getBeans(int userID, int topicID)
53         throws DatabaseException {
54         // TODO Auto-generated method stub
55
Connection JavaDoc connection = null;
56         PreparedStatement JavaDoc statement = null;
57         ResultSet JavaDoc resultSet = null;
58         Collection JavaDoc retValue = new ArrayList JavaDoc();
59         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
60         sql.append("SELECT topic_id, user_id, notify_status");
61         sql.append(" FROM " + TABLE_NAME);
62         sql.append(" WHERE user_id=? and topic_id=?"); // @todo: uncomment as needed
63
//sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
64
try {
65             connection = DBUtils.getPhpbbConnection();
66             statement = connection.prepareStatement(sql.toString());
67             statement.setInt(1, userID);
68             statement.setInt(2, topicID);
69             resultSet = statement.executeQuery();
70             while (resultSet.next()) {
71                 PhpbbTopicsWatch bean = new PhpbbTopicsWatch();
72                 bean.settopic_id(resultSet.getInt("topic_id"));
73                 bean.setuser_id(resultSet.getInt("user_id"));
74                 bean.setnotify_status(resultSet.getInt("notify_status"));
75                 retValue.add(bean);
76             }
77             return retValue;
78         } catch (SQLException JavaDoc sqle) {
79             sqle.printStackTrace();
80             throw new DatabaseException("Error executing SQL in phpbb_topics_watchDAOImplJDBC.getBeans.");
81         } finally {
82             DBUtils.closeResultSet(resultSet);
83             DBUtils.closeStatement(statement);
84             DBUtils.closeConnection(connection);
85         }
86
87     }
88
89     public Collection JavaDoc getBeansByTopicID(int topicID) throws DatabaseException {
90         // TODO Auto-generated method stub
91
Connection JavaDoc connection = null;
92         PreparedStatement JavaDoc statement = null;
93         ResultSet JavaDoc resultSet = null;
94         Collection JavaDoc retValue = new ArrayList JavaDoc();
95         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
96         sql.append("SELECT topic_id, user_id, notify_status");
97         sql.append(" FROM " + TABLE_NAME);
98         sql.append(" WHERE topic_id=?"); // @todo: uncomment as needed
99
//sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
100
try {
101             connection = DBUtils.getPhpbbConnection();
102             statement = connection.prepareStatement(sql.toString());
103             statement.setInt(1, topicID);
104             resultSet = statement.executeQuery();
105             while (resultSet.next()) {
106                 PhpbbTopicsWatch bean = new PhpbbTopicsWatch();
107                 bean.settopic_id(resultSet.getInt("topic_id"));
108                 bean.setuser_id(resultSet.getInt("user_id"));
109                 bean.setnotify_status(resultSet.getInt("notify_status"));
110                 retValue.add(bean);
111             }
112             return retValue;
113         } catch (SQLException JavaDoc sqle) {
114             throw new DatabaseException("Error executing SQL in phpbb_topics_watchDAOImplJDBC.getBeans.");
115         } finally {
116             DBUtils.closeResultSet(resultSet);
117             DBUtils.closeStatement(statement);
118             DBUtils.closeConnection(connection);
119         }
120     }
121
122 }
123
Popular Tags