예제 #1
1
  /**
   * 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;
  }
예제 #2
0
  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);
    }
  }
예제 #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();
 }
예제 #5
0
 public <T> T getArbitrary(Class<T> classObj) {
   PersistenceManager pm = pmf.getPersistenceManager();
   try {
     Extent<T> result = pm.getExtent(classObj, false);
     return result.iterator().next();
   } catch (Throwable e) {
     LOG.warning(e);
   } finally {
     pm.close();
   }
   return null;
 }
예제 #6
0
 private void loadMappings() {
   PersistenceManager pm = JdoUtil.currentPm();
   Extent<Mapping> extent = pm.getExtent(Mapping.class);
   Iterator<Mapping> itr = extent.iterator();
   while (itr.hasNext()) {
     Mapping mapping = itr.next();
     pm.makeTransient(mapping);
     //			System.out.println("json:"+mapping.toJson());
     if (mapping.setup() == false) { // TODO mapping.setupがfalseで復帰したらすべてrollbackすべき?
       logger.error("fail to mapping setup.id:" + mapping.getId() + ":note:" + mapping.getNotes());
       continue;
     }
     loadMapping(mapping);
   }
 }
예제 #7
0
  /** Test import of ZooDB 0.3 xml files. */
  @Test
  public void testImport0_3() {
    String path = Test_014_XmlImportExport.class.getResource("XmlComplexTest.xml").getPath();

    // import to DB
    TestTools.defineSchema(TestSerializer.class, TestSuper.class, DBLargeVector.class);
    ZooXmlImport.main(new String[] {TestTools.getDbName(), path});

    // check target
    PersistenceManager pm2 = TestTools.openPM();
    pm2.currentTransaction().begin();

    // Check for content in target
    Extent<TestSerializer> ext = pm2.getExtent(TestSerializer.class);
    TestSerializer ts2 = ext.iterator().next();
    ts2.check(false);
    pm2.currentTransaction().rollback();
    TestTools.closePM();
  }