/[projects]/android/MarketStats/src/dk/thoerup/marketstats/ShowStats.java
ViewVC logotype

Diff of /android/MarketStats/src/dk/thoerup/marketstats/ShowStats.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 951 by torben, Mon Jul 5 08:27:01 2010 UTC revision 952 by torben, Mon Jul 5 08:43:30 2010 UTC
# Line 57  public class ShowStats extends HttpServl Line 57  public class ShowStats extends HttpServl
57                  memcache = null;                  memcache = null;
58          }          }
59    
60          protected AppBean doLookup(String query) throws IOException {          protected AppBean lookupApp(String query) throws IOException {
61                                    
62    
63                  String key = "marketstats:" + query.replace(' ', '_');                  String key = "marketstats:" + query.replace(' ', '_');
# Line 65  public class ShowStats extends HttpServl Line 65  public class ShowStats extends HttpServl
65                  AppBean response = (AppBean) memcache.get(key);                  AppBean response = (AppBean) memcache.get(key);
66    
67                  if (response == null) {                  if (response == null) {
68                          response = doLookupWorker(query);                          response = lookupAppWorker(query);
69                          if (response != null) {                          if (response != null) {
70                                  memcache.set(key, APP_TIMEOUT, response);                                  memcache.set(key, APP_TIMEOUT, response);
71                          }                          }
72                  }                  }
73                  return response;                  return response;
74          }          }
75    
76            protected AppBean lookupAppWorker(String query) {
77                    final StringBuilder sb = new StringBuilder();
78    
79    
80                    MarketSession session = new MarketSession();
81                    session.login(login,password);
82    
83    
84                    AppsRequest appsRequest = AppsRequest.newBuilder()
85                    .setQuery(query)
86                    .setStartIndex(0)
87                    .setEntriesCount(1)
88                    .setWithExtendedInfo(true)
89                    .build();
90                    
91                    AppsCallback appsCb = new AppsCallback();
92                    session.append(appsRequest, appsCb);
93                    session.flush();
94                    
95                    return appsCb.getResult();
96            }      
97                    
98          CommentsRequest buildCommentRequest(String appId, int start, int count) {          CommentsRequest buildCommentRequest(String appId, int start, int count) {
99                  CommentsRequest commentsRequest = CommentsRequest.newBuilder()                  CommentsRequest commentsRequest = CommentsRequest.newBuilder()
# Line 122  public class ShowStats extends HttpServl Line 144  public class ShowStats extends HttpServl
144          }          }
145    
146                    
   
         protected AppBean doLookupWorker(String query) {  
                 final StringBuilder sb = new StringBuilder();  
   
   
                 MarketSession session = new MarketSession();  
                 session.login(login,password);  
   
   
                 AppsRequest appsRequest = AppsRequest.newBuilder()  
                 .setQuery(query)  
                 .setStartIndex(0)  
                 .setEntriesCount(1)  
                 .setWithExtendedInfo(true)  
                 .build();  
                   
                 AppsCallback appsCb = new AppsCallback();  
                 session.append(appsRequest, appsCb);  
                 session.flush();  
                   
                 return appsCb.getResult();  
         }  
147                    
148            @SuppressWarnings("unchecked")
149          public ArrayList<CommentBean> getComments(AppBean app) {                          public ArrayList<CommentBean> getComments(AppBean app) {                
150                  String key = "marketstats:comments:" + app.getId();                  String key = "marketstats:comments:" + app.getId();
151                  ArrayList<CommentBean>  comments =  (ArrayList<CommentBean>) memcache.get(key);                  ArrayList<CommentBean>  comments =  (ArrayList<CommentBean>) memcache.get(key);
# Line 159  public class ShowStats extends HttpServl Line 160  public class ShowStats extends HttpServl
160          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
161                  String query = request.getParameter("query");                  String query = request.getParameter("query");
162                                    
163                  AppBean app = doLookup(query);                  AppBean app = lookupApp(query);
164                  if (app != null) {                  if (app != null) {
165                          request.setAttribute("app", app);                          request.setAttribute("app", app);
166                                    

Legend:
Removed from v.951  
changed lines
  Added in v.952

  ViewVC Help
Powered by ViewVC 1.1.20