1 25 26 29 package net.killingar.forum.internal.caches; 30 31 import net.killingar.forum.internal.IDItem; 32 import net.killingar.forum.internal.PollAlternative; 33 34 import java.sql.Connection ; 35 import java.sql.PreparedStatement ; 36 import java.sql.ResultSet ; 37 import java.sql.SQLException ; 38 39 public class PollAlternativesCache extends AbstractIDItemCache 40 { 41 public synchronized PollAlternative getPollAlternative(long pollID) throws SQLException 42 { 43 return (PollAlternative)get(pollID); 44 } 45 46 protected IDItem getObjectFromRow(ResultSet result) throws SQLException 47 { 48 return new PollAlternative( 49 result.getLong(1), 50 result.getLong(2), 51 result.getString(3), 52 result.getString(4), 53 result.getLong(5)); 54 } 55 56 protected PreparedStatement createStatement(Connection c) throws SQLException 57 { 58 PreparedStatement statement = c.prepareStatement( 59 "select "+ 60 "PollAlternatives.ID, "+ 61 "PollAlternatives.Poll, "+ 62 "PollAlternatives.Alternative, "+ 63 "PollAlternatives.Color, "+ 64 "count(PollAnswers.Reply) "+ 65 "from "+ 66 "PollAlternatives "+ 67 "left join PollAnswers on PollAlternatives.ID = PollAnswers.Reply "+ 68 "where "+ 69 "PollAlternatives.LastChanged > ? "+ 70 "group by "+ 71 "PollAlternatives.ID "); 72 73 statement.setTimestamp(1, latestUpdate); 74 75 return statement; 76 } 77 } 78 | Popular Tags |