Package com.google.appengine.api.datastore

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


        assertStoreDoesNotContain(k1.get());
    }

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

        Transaction tx = waitOnFuture(service.beginTransaction(TransactionOptions.Builder.withXG(true)));
        Key key, key2;
        try {
            key = waitOnFuture(service.put(tx, new Entity("AsyncTx")));
            key2 = waitOnFuture(service.put(tx, new Entity("AsyncTx")));
            tx.commit();
        } catch (Exception e) {
            tx.rollback();
            throw e;
        }

        if (key != null && key2 != null) {
            tx = waitOnFuture(service.beginTransaction(TransactionOptions.Builder.withXG(true)));
            try {
                try {
                    try {
                        Assert.assertNotNull(waitOnFuture(service.get(tx, key)));
                        Assert.assertNotNull(waitOnFuture(service.get(tx, Collections.singleton(key2))));
                    } finally {
                        service.delete(tx, key2);
                    }
                } finally {
                    service.delete(tx, Collections.singleton(key));
                }
            } finally {
                tx.rollback();
            }
        }
View Full Code Here


        }
    }

    @Test
    public void testCommitTx() throws Exception {
        AsyncDatastoreService service = DatastoreServiceFactory.getAsyncDatastoreService();
        Transaction tx = waitOnFuture(service.beginTransaction(TransactionOptions.Builder.withDefaults()));
        Key key;
        try {
            Future<Key> fKey = service.put(tx, new Entity("AsyncTx"));
            key = waitOnFuture(fKey);
            waitOnFuture(tx.commitAsync());
        } catch (Exception e) {
            waitOnFuture(tx.rollbackAsync());
            throw e;
View Full Code Here

        }
    }

    @Test
    public void testRollbackTx() throws Exception {
        AsyncDatastoreService service = DatastoreServiceFactory.getAsyncDatastoreService();
        Transaction tx = waitOnFuture(service.beginTransaction(TransactionOptions.Builder.withDefaults()));
        Key key = null;
        try {
            Future<Key> fKey = service.put(tx, new Entity("AsyncTx"));
            key = waitOnFuture(fKey);
        } finally {
            waitOnFuture(tx.rollbackAsync());
        }
View Full Code Here

    protected static WebArchive getAsynchDeployment() {
        return getHelperDeployment().addClass(AsyncTestBase.class);
    }

    protected <T> T inTx(Action<T> action) throws Exception {
        AsyncDatastoreService ads = DatastoreServiceFactory.getAsyncDatastoreService();
        Transaction tx = ads.beginTransaction().get();
        boolean ok = false;
        try {
            T result = action.run(ads);
            ok = true;
            return result;
View Full Code Here

    Entity unemployment_percent = getFREDStat("http://research.stlouisfed.org/fred2/data/UNRATE.txt", "unemployment_percent", unemployment_percent_info);
    entities.add(unemployment_percent);
   
   
    //Add all entities to datastore & Memcache.
    AsyncDatastoreService datastore = DatastoreServiceFactory.getAsyncDatastoreService();
    AsyncMemcacheService memcache = MemcacheServiceFactory.getAsyncMemcacheService();
    for (int i = 0; i < entities.size(); i++) {
      /**
       * We have to make sure that each entity is not null.
       * The Vector could contain null entries, which
       * occurs when there are problems generating
       * their associated information (for instance, an
       * inability to access the API.)
       */
      Entity entity = entities.get(i);
      if (entity != null) {
        /**
         * Copy the data into Memcache as well, for speed.
         */
       
       
        System.out.println(entity);
        datastore.put(entity);
      }//end if entity does not equal null.
    }//Loop through entities list.
   
  }//end doGet
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.