/**
   * Retrieves the access token used for interacting with Twitter.
   *
   * @return
   */
  public static AccessToken getAccessToken() {
    // Try to grab the token from the cache.
    StoredAccessToken storedToken = (StoredAccessToken) cache.get(ACCESS_TOKEN_KEY);

    if (storedToken != null) {
      return storedToken.getAccessToken();
    }

    // Now try to grab it from the datastore
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Extent<StoredAccessToken> extent = pm.getExtent(StoredAccessToken.class, false);

    try {
      Iterator<StoredAccessToken> itr = extent.iterator();
      storedToken = itr.next();

      // If the token was found, cache it and return.
      if (storedToken != null) {
        cache.put(ACCESS_TOKEN_KEY, storedToken);
        return storedToken.getAccessToken();
      }
    } finally {
      extent.closeAll();
      pm.close();
    }

    return null;
  }
  protected static StorageStats getStorageStats() {
    // Try to grab the token from the cache.
    StorageStats stats = (StorageStats) cache.get(STORAGE_STATS_KEY);

    if (stats != null) {
      return stats;
    }

    // Now try to grab it from the datastore
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Extent<StorageStats> extent = pm.getExtent(StorageStats.class, false);

    try {
      Iterator<StorageStats> itr = extent.iterator();

      if (itr.hasNext()) {
        stats = itr.next();
      } else {
        stats = new StorageStats();
        pm.makePersistent(stats);
      }

      return stats;
    } finally {
      extent.closeAll();
      pm.close();

      cache.put(STORAGE_STATS_KEY, stats);
    }
  }
Exemple #3
0
 public void delete() {
   begin();
   Extent extent = db().getExtent(JB4.class, false);
   Iterator it = extent.iterator();
   while (it.hasNext()) {
     db().deletePersistent(it.next());
     addToCheckSum(5);
   }
   extent.closeAll();
   commit();
 }
 protected void readExtent(Class<?> clazz) {
   Extent<?> extent = db().getExtent(clazz, false);
   Iterator<?> itr = extent.iterator();
   while (itr.hasNext()) {
     Object o = itr.next();
     if (o instanceof CheckSummable) {
       addToCheckSum(((CheckSummable) o).checkSum());
     }
   }
   extent.closeAll();
 }