KickJava   Java API By Example, From Geeks To Geeks.

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


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.PhpbbAuthAccess;
13 import org.mvnforum.phpbb2mvnforum.db.PhpbbAuthAccessDAO;
14 import org.mvnforum.util.DBUtils;
15
16 public class PhpbbAuthAccessDAOImpl implements PhpbbAuthAccessDAO {
17
18     public Collection JavaDoc getBeans()
19         throws DatabaseException {
20         Connection JavaDoc connection = null;
21         PreparedStatement JavaDoc statement = null;
22         ResultSet JavaDoc resultSet = null;
23         Collection JavaDoc retValue = new ArrayList JavaDoc();
24         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
25         sql
26                 .append("SELECT group_id, forum_id, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote, auth_pollcreate, auth_attachments, auth_mod");
27         sql.append(" FROM " + TABLE_NAME);
28         //sql.append(" WHERE "); // @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             resultSet = statement.executeQuery();
34             while (resultSet.next()) {
35                 PhpbbAuthAccess bean = new PhpbbAuthAccess();
36                 bean.setgroup_id(resultSet.getInt("group_id"));
37                 bean.setforum_id(resultSet.getInt("forum_id"));
38                 bean.setauth_view(resultSet.getInt("auth_view"));
39                 bean.setauth_read(resultSet.getInt("auth_read"));
40                 bean.setauth_post(resultSet.getInt("auth_post"));
41                 bean.setauth_reply(resultSet.getInt("auth_reply"));
42                 bean.setauth_edit(resultSet.getInt("auth_edit"));
43                 bean.setauth_delete(resultSet.getInt("auth_delete"));
44                 bean.setauth_sticky(resultSet.getInt("auth_sticky"));
45                 bean.setauth_announce(resultSet.getInt("auth_announce"));
46                 bean.setauth_vote(resultSet.getInt("auth_vote"));
47                 bean.setauth_pollcreate(resultSet.getInt("auth_pollcreate"));
48                 bean.setauth_attachments(resultSet.getInt("auth_attachments"));
49                 bean.setauth_mod(resultSet.getInt("auth_mod"));
50                 retValue.add(bean);
51             }
52             return retValue;
53         } catch (SQLException JavaDoc sqle) {
54             throw new DatabaseException("Error executing SQL in phpbb_auth_accessDAOImplJDBC.getBeans.");
55         } finally {
56             DBUtils.closeResultSet(resultSet);
57             DBUtils.closeStatement(statement);
58             DBUtils.closeConnection(connection);
59         }
60     }
61
62     public Collection JavaDoc getBeansByForumID(int forumId) throws DatabaseException {
63         // TODO Auto-generated method stub
64
Connection JavaDoc connection = null;
65         PreparedStatement JavaDoc statement = null;
66         ResultSet JavaDoc resultSet = null;
67         Collection JavaDoc retValue = new ArrayList JavaDoc();
68         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(512);
69         sql
70                 .append("SELECT group_id, forum_id, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote, auth_pollcreate, auth_attachments, auth_mod");
71         sql.append(" FROM " + TABLE_NAME);
72         sql.append(" WHERE forum_id=?");
73         try {
74             connection = DBUtils.getPhpbbConnection();
75             statement = connection.prepareStatement(sql.toString());
76             statement.setInt(1, forumId);
77             resultSet = statement.executeQuery();
78             while (resultSet.next()) {
79                 PhpbbAuthAccess bean = new PhpbbAuthAccess();
80                 bean.setgroup_id(resultSet.getInt("group_id"));
81                 bean.setforum_id(resultSet.getInt("forum_id"));
82                 bean.setauth_view(resultSet.getInt("auth_view"));
83                 bean.setauth_read(resultSet.getInt("auth_read"));
84                 bean.setauth_post(resultSet.getInt("auth_post"));
85                 bean.setauth_reply(resultSet.getInt("auth_reply"));
86                 bean.setauth_edit(resultSet.getInt("auth_edit"));
87                 bean.setauth_delete(resultSet.getInt("auth_delete"));
88                 bean.setauth_sticky(resultSet.getInt("auth_sticky"));
89                 bean.setauth_announce(resultSet.getInt("auth_announce"));
90                 bean.setauth_vote(resultSet.getInt("auth_vote"));
91                 bean.setauth_pollcreate(resultSet.getInt("auth_pollcreate"));
92                 bean.setauth_attachments(resultSet.getInt("auth_attachments"));
93                 bean.setauth_mod(resultSet.getInt("auth_mod"));
94                 retValue.add(bean);
95             }
96             return retValue;
97         } catch (SQLException JavaDoc sqle) {
98             throw new DatabaseException("Error executing SQL in phpbb_auth_accessDAOImplJDBC.getBeans.");
99         } finally {
100             DBUtils.closeResultSet(resultSet);
101             DBUtils.closeStatement(statement);
102             DBUtils.closeConnection(connection);
103         }
104     }
105 }
106
Popular Tags