Package org.datanucleus.store.query.cache

Examples of org.datanucleus.store.query.cache.QueryResultsCache


    {
        if (queryCache != null)
        {
            return queryCache;
        }
        QueryResultsCache cache = nucleusContext.getStoreManager().getQueryManager().getQueryResultsCache();
        queryCache = new JDOQueryCache(cache);
        return queryCache;
    }
View Full Code Here


  public void testCacheQueryResults() {
    ds.put(null, newFlightEntity("1", "yar", "bam", 1, 2));
    ds.put(null, newFlightEntity("1", "yam", null, 1, 2));

    QueryResultsCache cache = null;
    try {
      String query = "SELECT FROM " + Flight.class.getName();
      Query q = pm.newQuery(query);
      q.addExtension("datanucleus.query.results.cached", "true");
      try {
        List<Flight> results = (List<Flight>) q.execute();
        Assert.assertEquals("Number of results was wrong", 2, results.size());
      } catch (JDOException jdoe) {
        fail("Threw exception when evaluating query and caching results : " + jdoe.getMessage());
      }
      q.closeAll();
      if (pm.currentTransaction().isActive()) {
        pm.currentTransaction().rollback();
      }
      pm.close();
      cache =
        ((JDOPersistenceManagerFactory)pmf).getNucleusContext().getStoreManager().getQueryManager().getQueryResultsCache();
      assertEquals("Number of entries in the query results cache is wrong", 1, cache.size());

      pm = pmf.getPersistenceManager();
      Query q2 = pm.newQuery(query);
      try {
        List<Flight> results = (List<Flight>) q2.execute();
        Assert.assertEquals("Number of results was wrong", 2, results.size());
      } catch (JDOException jdoe) {
        fail("Threw exception when evaluating query with cached results : " + jdoe.getMessage());
      }
      q2.closeAll();
    } finally {
      // Evict the cached results
      cache.evictAll();
    }
  }
View Full Code Here

TOP

Related Classes of org.datanucleus.store.query.cache.QueryResultsCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.