示例#1
0
  private void persistNewsData(NodeList titles, NodeList links, NodeList descriptions) {
    // Persists news data feed.
    // Also clears out previously persisted news feed data

    PersistenceManager pm = PMF.get().getPersistenceManager();
    javax.jdo.Query query = pm.newQuery(NewsItem.class);
    Long res = query.deletePersistentAll();

    System.out.println("Datastore deleted  " + res + "records");

    pm = PMF.get().getPersistenceManager();

    try {
      for (int i = 1; i < titles.getLength(); i++) {
        NewsItem ni = new NewsItem();
        ni.setTitle(titles.item(i).getTextContent());
        ni.setLink(links.item(i).getTextContent());
        if (descriptions.item(i) != null) {
          ni.setDescription(new Text(descriptions.item(i).getTextContent()));
        }
        pm.makePersistent(ni);
      }
    } finally {
      pm.close();
    }
  }
示例#2
0
 protected void HandleRequest(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   PersistenceManager pm = PMF.getManager();
   Query query = pm.newQuery(MediumData.class);
   query.deletePersistentAll();
   response.getWriter().format("table.medium deleteAll %s", new Object[] {ActionStatus.SUCCESS});
 }
示例#3
0
  /**
   * Saves the access token required by twitter.
   *
   * @param accessToken
   */
  public static void setAccessToken(AccessToken accessToken) {
    StoredAccessToken storedToken = new StoredAccessToken(accessToken);

    // Add the token to the cache.
    cache.put(ACCESS_TOKEN_KEY, storedToken);

    // Now persist it from the datastore
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Query delQuery = pm.newQuery(StoredAccessToken.class);

    try {
      delQuery.deletePersistentAll();
      pm.makePersistent(storedToken);
    } finally {
      delQuery.closeAll();
      pm.close();
    }
  }