1 package org.mvnforum.phpbb2mvnforum.db.jdbc; 2 3 import java.sql.Connection ; 4 import java.sql.PreparedStatement ; 5 import java.sql.ResultSet ; 6 import java.sql.SQLException ; 7 import java.util.ArrayList ; 8 import java.util.Collection ; 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 getBeansByUserID(int userID) 19 throws DatabaseException { 20 Connection connection = null; 22 PreparedStatement statement = null; 23 ResultSet resultSet = null; 24 Collection retValue = new ArrayList (); 25 StringBuffer sql = new StringBuffer (512); 26 sql.append("SELECT topic_id, user_id, notify_status"); 27 sql.append(" FROM " + TABLE_NAME); 28 sql.append(" WHERE user_id=?"); 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 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 getBeans(int userID, int topicID) 53 throws DatabaseException { 54 Connection connection = null; 56 PreparedStatement statement = null; 57 ResultSet resultSet = null; 58 Collection retValue = new ArrayList (); 59 StringBuffer sql = new StringBuffer (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=?"); 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 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 getBeansByTopicID(int topicID) throws DatabaseException { 90 Connection connection = null; 92 PreparedStatement statement = null; 93 ResultSet resultSet = null; 94 Collection retValue = new ArrayList (); 95 StringBuffer sql = new StringBuffer (512); 96 sql.append("SELECT topic_id, user_id, notify_status"); 97 sql.append(" FROM " + TABLE_NAME); 98 sql.append(" WHERE topic_id=?"); 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 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 |