Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.AsyncDatastoreService


   * Ignores the default memcacheService for this factory; that is set when you construct
   * your EntityMemcache.
   */
  public static CachingAsyncDatastoreService getAsyncDatastoreService(EntityMemcache em)
  {
    AsyncDatastoreService ads = DatastoreServiceFactory.getAsyncDatastoreService();
    return new CachingAsyncDatastoreService(ads, em);
  }
View Full Code Here


   * Ignores the default memcacheService for this factory; that is set when you construct
   * your EntityMemcache.
   */
  public static CachingAsyncDatastoreService getAsyncDatastoreService(DatastoreServiceConfig cfg, EntityMemcache em)
  {
    AsyncDatastoreService ads = DatastoreServiceFactory.getAsyncDatastoreService(cfg);
    return new CachingAsyncDatastoreService(ads, em);
  }
View Full Code Here

  /** This seemed to be an issue related to the listenable but apparently not */
  @Test
  public void testSimpleAsyncGetWithDatastore() throws Exception
  {
    AsyncDatastoreService ads = DatastoreServiceFactory.getAsyncDatastoreService();
   
    Entity ent = new Entity("thing");
    ent.setUnindexedProperty("foo", "bar");
   
    // Without the null txn (ie, using implicit transactions) we get a "handle 0 not found" error
    Future<Key> fut = ads.put(null, ent);
    fut.get();
  }
View Full Code Here

 
  /** Some weird race condition on listenable future */
  @Test
  public void testRaceCondition() throws Exception
  {
    AsyncDatastoreService ads = DatastoreServiceFactory.getAsyncDatastoreService();
   
    for (int i=0; i<100; i++)
    {
      final int which = i;
      final Entity ent = new Entity("thing");
      ent.setUnindexedProperty("foo", "bar" + i);
     
      @SuppressWarnings("unused")
      TriggerFuture<Key> fut = new TriggerFuture<Key>(ads.put(null, ent)) {
        @Override
        protected void trigger()
        {
          // This magic line makes the key get updated.  Without this line,
          // we get what looks like some sort of race condition - the error
View Full Code Here

  @Override
  public void save(Page p) {
    String identity = HttpCookies.getCookieValue(
        this.perThreadRequest.get(), "identity");

    AsyncDatastoreService datastore = DatastoreServiceFactory
        .getAsyncDatastoreService();

    // start the query to get the original page
    Page oldPage = new Page();
    Future<Entity> oldPageFuture;
    {
      oldPageFuture = datastore.get(KeyFactory.createKey(
          Page.class.getSimpleName(), p.getName()));

    }

    try {
      Date now = new Date();
      // create the page entity
      {
        Entity page = new Entity(KeyFactory.createKey(Page.PAGE,
            URLDecoder.decode(p.getName(), "UTF-8")));

        // ... set properties ...
        page.setProperty(Page.CONTENT, new Text(p.getContent()));
        // page.setProperty(Page.STYLE, new Text(p.getStyle()));
        page.setProperty(Page.REMOTE_IP, getThreadLocalRequest()
            .getRemoteAddr());
        page.setProperty(Page.DATE, now);
        page.setProperty(Page.USER, identity);

        try {
          // block on retrieving previous version
          Entity e = oldPageFuture.get();
          oldPage = new Page(e.getKey().getName(),
              ((Text) e.getProperty(Page.CONTENT)).getValue());
        } catch (InterruptedException e) {
          e.printStackTrace();
        } catch (ExecutionException e) {
          e.printStackTrace();
        }
        datastore.put(page);
      }
      // create the pagehistory entity
      {
        Entity history = new Entity(
            KeyFactory.createKey(
                Page.PAGEHISTORY,
                URLDecoder.decode(p.getName(), "UTF-8")
                    + now.getTime()));

        // ... set properties ...
        history.setProperty(Page.NAME,
            URLDecoder.decode(p.getName(), "UTF-8"));
        history.setProperty(Page.CONTENT, new Text(p.getContent()));
        // history.setProperty(Page.STYLE, new Text(p.getStyle()));
        history.setProperty(Page.REMOTE_IP, getThreadLocalRequest()
            .getRemoteAddr());
        history.setProperty(Page.DATE, now);
        history.setProperty(Page.UPDATE, p.isUpdate());
        history.setProperty(Page.USER, identity);

        // create the diff
        diff_match_patch dmp = new diff_match_patch();
        // create the diff
        LinkedList<Diff> diffs = dmp.diff_main(oldPage.getContent(),
            p.getContent());
        // make the diff human readable
        dmp.diff_cleanupSemantic(diffs);
        // convert the diff to html
        String diff = dmp.diff_prettyHtml(diffs);

        history.setProperty(Page.DIFF, new Text(diff));

        datastore.put(history);
      }

      try {
        Cache cache = CacheManager.getInstance().getCacheFactory()
            .createCache(Collections.emptyMap());
View Full Code Here

  public void clear() {
    localCache.clear();
    globalCache.clearAll();
    // clear resetDate of all namespaces
    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
    AsyncDatastoreService asyncDs = DatastoreServiceFactory.getAsyncDatastoreService();
    Query q = new Query(Entities.NAMESPACE_METADATA_KIND);
    List<String> results = new ArrayList<String>();
    for (Entity e : ds.prepare(q).asIterable()) {
        results.add(Entities.getNamespaceFromNamespaceKey(e.getKey()));
    }
    String bak = NamespaceManager.get();
    try {
        FetchOptions opt = FetchOptions.Builder.withOffset(0);
        for(String ns: results) {
            NamespaceManager.set(ns);
            q = new Query(RESET_DATE_KIND).setKeysOnly();
            List<Entity> entities = ds.prepare(q).asList(opt);
            List<Key> keys = new ArrayList<Key>(entities.size());
            for (Entity entity: entities) {
                keys.add(entity.getKey());
            }
            asyncDs.delete(keys);
        }
    } finally {
        NamespaceManager.set(bak);
    }
    return;
View Full Code Here

      Date date = new Date();
        // datastore
        Key key = KeyFactory.createKey(RESET_DATE_KIND, keyname);
        Entity entity = new Entity(key);
        entity.setProperty(RESET_DATE_PROP, date);
        AsyncDatastoreService ds = DatastoreServiceFactory.getAsyncDatastoreService();
        ds.put(entity);
        // cache
        put(KEY_RESET_DATE + keyname, date);
        logger.debug("put reset date for : " + keyname);
       
        return;
View Full Code Here

        }
    }

    @Test
    public void testMiscOps() throws Exception {
        AsyncDatastoreService service = DatastoreServiceFactory.getAsyncDatastoreService();

        DatastoreAttributes attributes = waitOnFuture(service.getDatastoreAttributes());
        Assert.assertNotNull(attributes);
        Assert.assertNotNull(attributes.getDatastoreType());

        Map<Index, Index.IndexState> indexes = waitOnFuture(service.getIndexes());
        Assert.assertNotNull(indexes);

        Transaction tx = waitOnFuture(service.beginTransaction());
        try {
            String txId = tx.getId();
            Assert.assertNotNull(txId);
            Assert.assertEquals(txId, tx.getId());
View Full Code Here

    }

    @Test
    public void testFutureCancel() {
        clearData();
        AsyncDatastoreService asyncService = DatastoreServiceFactory.getAsyncDatastoreService();
        Entity newRec = new Entity(ASYNC_ENTITY);
        newRec.setProperty("count", -1);
        newRec.setProperty("timestamp", new Date());
        Future<Key> future = asyncService.put(newRec);
        future.cancel(true);

        // The actual call may already succeeded, so just verify that cancel has been called.
        assertTrue(future.isCancelled());
    }
View Full Code Here

        return getAsynchDeployment();
    }

    @Test
    public void testCRUD() throws Exception {
        AsyncDatastoreService service = DatastoreServiceFactory.getAsyncDatastoreService();

        Entity e1 = new Entity("ASYNC");
        e1.setProperty("foo", "bar");

        Future<Key> k1 = service.put(e1);
        Assert.assertNotNull(k1);

        Key key = k1.get();
        Assert.assertNotNull(key);
        Future<Entity> fe1 = service.get(key);
        Assert.assertNotNull(fe1);
        Assert.assertEquals(e1, fe1.get());

        Future<Void> fd1 = service.delete(key);
        Assert.assertNotNull(fd1);
        fd1.get();

        assertStoreDoesNotContain(key);
    }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.datastore.AsyncDatastoreService

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.