1 4 package org.mvnforum.phpbb2mvnforum.db.jdbc; 5 6 import java.sql.Connection ; 7 import java.sql.PreparedStatement ; 8 import java.sql.ResultSet ; 9 import java.sql.SQLException ; 10 import java.util.ArrayList ; 11 import java.util.Collection ; 12 13 import net.myvietnam.mvncore.exception.DatabaseException; 14 15 import org.mvnforum.phpbb2mvnforum.db.PhpbbForum; 16 import org.mvnforum.phpbb2mvnforum.db.PhpbbForumDAO; 17 import org.mvnforum.util.DBUtils; 18 19 20 public class PhpbbForumDAOImpl implements PhpbbForumDAO{ 21 22 30 public Collection getBeans() throws DatabaseException { 31 32 Connection connection = null; 33 PreparedStatement statement = null; 34 ResultSet resultSet = null; 35 Collection retValue = new ArrayList (); 36 StringBuffer sql = new StringBuffer (512); 37 sql.append("SELECT forum_id, cat_id, forum_name, forum_desc, forum_status, forum_order, forum_posts, forum_topics, forum_last_post_id, prune_next, prune_enable, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote, auth_pollcreate, auth_attachments"); 38 sql.append(" FROM " + TABLE_NAME); 39 try { 42 connection = DBUtils.getPhpbbConnection(); 43 statement = connection.prepareStatement(sql.toString()); 44 resultSet = statement.executeQuery(); 45 while (resultSet.next()) { 46 PhpbbForum bean = new PhpbbForum(); 47 bean.setforum_id(resultSet.getInt("forum_id")); 48 bean.setcat_id(resultSet.getInt("cat_id")); 49 bean.setforum_name(resultSet.getString("forum_name")); 50 bean.setforum_desc(resultSet.getString("forum_desc")); 51 bean.setforum_status(resultSet.getInt("forum_status")); 52 bean.setforum_order(resultSet.getInt("forum_order")); 53 bean.setforum_posts(resultSet.getInt("forum_posts")); 54 bean.setforum_topics(resultSet.getInt("forum_topics")); 55 bean.setforum_last_post_id(resultSet.getInt("forum_last_post_id")); 56 bean.setprune_next(resultSet.getInt("prune_next")); 57 bean.setprune_enable(resultSet.getInt("prune_enable")); 58 bean.setauth_view(resultSet.getInt("auth_view")); 59 bean.setauth_read(resultSet.getInt("auth_read")); 60 bean.setauth_post(resultSet.getInt("auth_post")); 61 bean.setauth_reply(resultSet.getInt("auth_reply")); 62 bean.setauth_edit(resultSet.getInt("auth_edit")); 63 bean.setauth_delete(resultSet.getInt("auth_delete")); 64 bean.setauth_sticky(resultSet.getInt("auth_sticky")); 65 bean.setauth_announce(resultSet.getInt("auth_announce")); 66 bean.setauth_vote(resultSet.getInt("auth_vote")); 67 bean.setauth_pollcreate(resultSet.getInt("auth_pollcreate")); 68 bean.setauth_attachments(resultSet.getInt("auth_attachments")); 69 retValue.add(bean); 70 } 71 return retValue; 72 } catch(SQLException sqle) { 73 throw new DatabaseException("Error executing SQL in phpbb_forumsDAOImplJDBC.getBeans."); 74 } finally { 75 DBUtils.closeResultSet(resultSet); 76 DBUtils.closeStatement(statement); 77 DBUtils.closeConnection(connection); 78 } 79 } 80 81 public Collection getBeansByCategoryID(int categoryID) throws DatabaseException { 82 Connection connection = null; 84 PreparedStatement statement = null; 85 ResultSet resultSet = null; 86 Collection retValue = new ArrayList (); 87 StringBuffer sql = new StringBuffer (512); 88 sql.append("SELECT forum_id, cat_id, forum_name, forum_desc, forum_status, forum_order, forum_posts, forum_topics, forum_last_post_id, prune_next, prune_enable, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote, auth_pollcreate, auth_attachments"); 89 sql.append(" FROM " + TABLE_NAME); 90 sql.append(" WHERE cat_id = ?"); try { 93 connection = DBUtils.getPhpbbConnection(); 94 statement = connection.prepareStatement(sql.toString()); 95 statement.setInt(1, categoryID); 96 resultSet = statement.executeQuery(); 97 while (resultSet.next()) { 99 PhpbbForum bean = new PhpbbForum(); 100 bean.setforum_id(resultSet.getInt("forum_id")); 101 bean.setcat_id(resultSet.getInt("cat_id")); 102 bean.setforum_name(resultSet.getString("forum_name")); 103 bean.setforum_desc(resultSet.getString("forum_desc")); 104 bean.setforum_status(resultSet.getInt("forum_status")); 105 bean.setforum_order(resultSet.getInt("forum_order")); 106 bean.setforum_posts(resultSet.getInt("forum_posts")); 107 bean.setforum_topics(resultSet.getInt("forum_topics")); 108 bean.setforum_last_post_id(resultSet.getInt("forum_last_post_id")); 109 bean.setprune_next(resultSet.getInt("prune_next")); 110 bean.setprune_enable(resultSet.getInt("prune_enable")); 111 bean.setauth_view(resultSet.getInt("auth_view")); 112 bean.setauth_read(resultSet.getInt("auth_read")); 113 bean.setauth_post(resultSet.getInt("auth_post")); 114 bean.setauth_reply(resultSet.getInt("auth_reply")); 115 bean.setauth_edit(resultSet.getInt("auth_edit")); 116 bean.setauth_delete(resultSet.getInt("auth_delete")); 117 bean.setauth_sticky(resultSet.getInt("auth_sticky")); 118 bean.setauth_announce(resultSet.getInt("auth_announce")); 119 bean.setauth_vote(resultSet.getInt("auth_vote")); 120 bean.setauth_pollcreate(resultSet.getInt("auth_pollcreate")); 121 bean.setauth_attachments(resultSet.getInt("auth_attachments")); 122 retValue.add(bean); 123 } 124 return retValue; 125 } catch(SQLException sqle) { 126 sqle.printStackTrace(); 127 throw new DatabaseException("Error executing SQL in phpbb_forumsDAOImplJDBC.getBeans."); 128 } finally { 129 DBUtils.closeResultSet(resultSet); 130 DBUtils.closeStatement(statement); 131 DBUtils.closeConnection(connection); 132 } 133 } 134 } 135 | Popular Tags |