1 43 package net.jforum.dao.sqlserver; 44 45 import java.sql.PreparedStatement ; 46 import java.sql.ResultSet ; 47 import java.util.ArrayList ; 48 import java.util.List ; 49 50 import net.jforum.JForumExecutionContext; 51 import net.jforum.entities.Post; 52 import net.jforum.util.preferences.SystemGlobals; 53 54 import org.apache.log4j.Logger; 55 56 60 public class SqlServerPostDAO extends net.jforum.dao.generic.GenericPostDAO 61 { 62 65 public Post selectById(int postId) throws Exception 66 { 67 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.selectById"), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); 68 p.setInt(1, postId); 69 70 ResultSet rs = p.executeQuery(); 71 72 Post post = new Post(); 73 74 if (rs.next()) { 75 post = this.makePost(rs); 76 } 77 78 rs.close(); 79 p.close(); 80 81 return post; 82 } 83 84 87 public List selectAllByTopicByLimit(int topicId, int startFrom, int count) throws Exception 88 { 89 List l = new ArrayList (); 90 91 String top = SystemGlobals.getSql("GenericModel.selectByLimit"); 92 String sql = top + " " + count + " " + 93 SystemGlobals.getSql("PostModel.selectAllByTopicByLimit1") + 94 " " + top + " " + startFrom + " " + 95 SystemGlobals.getSql("PostModel.selectAllByTopicByLimit2"); 96 97 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); 98 Logger.getLogger(this.getClass()).debug(sql); 99 p.setInt(1, topicId); 100 p.setInt(2, topicId); 101 102 ResultSet rs = p.executeQuery(); 103 104 while (rs.next()) { 105 l.add(this.makePost(rs)); 106 } 107 108 rs.close(); 109 p.close(); 110 111 return l; 112 } 113 114 } 115 | Popular Tags |