• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java AsyncDatastoreService类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中com.google.appengine.api.datastore.AsyncDatastoreService的典型用法代码示例。如果您正苦于以下问题:Java AsyncDatastoreService类的具体用法?Java AsyncDatastoreService怎么用?Java AsyncDatastoreService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

AsyncDatastoreService类属于com.google.appengine.api.datastore包,在下文中一共展示了AsyncDatastoreService类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: initOfyOnce

点赞 3

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
/**
 * Performs static initialization for Objectify to register types and do other setup.
 *
 * <p>This method is non-idempotent, so it should only be called exactly once, which is achieved
 * by calling it from this class's static initializer block.
 */
private static void initOfyOnce() {
  // Set an ObjectifyFactory that uses our extended ObjectifyImpl.
  // The "false" argument means that we are not using the v5-style Objectify embedded entities.
  com.googlecode.objectify.ObjectifyService.setFactory(new ObjectifyFactory(false) {
    @Override
    public Objectify begin() {
      return new SessionKeyExposingObjectify(this);
    }

    @Override
    protected AsyncDatastoreService createRawAsyncDatastoreService(DatastoreServiceConfig cfg) {
      // In the unit test environment, wrap the Datastore service in a proxy that can be used to
      // examine the number of requests sent to Datastore.
      AsyncDatastoreService service = super.createRawAsyncDatastoreService(cfg);
      return RegistryEnvironment.get().equals(RegistryEnvironment.UNITTEST)
          ? new RequestCapturingAsyncDatastoreService(service)
          : service;
    }});

  // Translators must be registered before any entities can be registered.
  registerTranslators();
  registerEntityClasses(EntityClasses.ALL_CLASSES);
}
 

开发者ID:google,
项目名称:nomulus,
代码行数:30,
代码来源:ObjectifyService.java

示例2: testMiscOps

点赞 3

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
@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());

        String appId = tx.getApp();
        Assert.assertNotNull(appId);
        Assert.assertEquals(appId, tx.getApp());
    } finally {
        tx.rollback();
    }
}
 

开发者ID:GoogleCloudPlatform,
项目名称:appengine-tck,
代码行数:25,
代码来源:TransactionsTest.java

示例3: inTx

点赞 3

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
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;
    } finally {
        if (ok)
            tx.commitAsync();
        else
            tx.rollbackAsync();

        sync(); // wait for tx to finish
    }
}
 

开发者ID:GoogleCloudPlatform,
项目名称:appengine-tck,
代码行数:18,
代码来源:AsyncTestBase.java

示例4: testCRUD

点赞 3

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
@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);
}
 

开发者ID:GoogleCloudPlatform,
项目名称:appengine-tck,
代码行数:23,
代码来源:AsyncTest.java

示例5: testCommitTx

点赞 3

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
@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;
    }

    if (key != null) {
        Assert.assertNotNull(getSingleEntity(service, key));
    }
}
 

开发者ID:GoogleCloudPlatform,
项目名称:appengine-tck,
代码行数:19,
代码来源:AsyncTest.java

示例6: testRollbackTx

点赞 3

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
@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());
    }

    if (key != null) {
        Assert.assertNull(getSingleEntity(service, key));
    }
}
 

开发者ID:GoogleCloudPlatform,
项目名称:appengine-tck,
代码行数:17,
代码来源:AsyncTest.java

示例7: putBlobsAsync

点赞 3

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
@Override
public void putBlobsAsync(Map<I_BlobKey, I_Blob> values) throws BlobException
{
	List<Entity> entities = createEntitiesForPut(values);
	
	AsyncDatastoreService datastore = DatastoreServiceFactory.getAsyncDatastoreService();
	Transaction currentTransaction = m_blobTxnMngr.getCurrentTransaction(datastore);
	
	if( currentTransaction != null )
	{
		throw new BlobException("Can't do async multi-put within a blob transaction.");
	}
	
	try
	{
		datastore.put(entities);
	}
	catch(Exception e)
	{
		throw new BlobException("Error occurred while putting blob batch.", e);
	}
}
 

开发者ID:dougkoellmer,
项目名称:swarm,
代码行数:23,
代码来源:BlobManager_Persistent.java

示例8: deleteBlobAsync

点赞 3

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
@Override
public void deleteBlobAsync(I_BlobKey keySource, Class<? extends I_Blob> blobType) throws BlobException
{
	AsyncDatastoreService datastore = DatastoreServiceFactory.getAsyncDatastoreService();
	
	Transaction currentTransaction = m_blobTxnMngr.getCurrentTransaction(datastore);
	
	if( currentTransaction != null )
	{
		throw new BlobException("Can't delete within transaction.");
	}
	
	I_Blob blobTemplate = m_templateMngr.getTemplate(blobType);
	
	Key keyObject = KeyFactory.createKey(blobTemplate.getKind(), keySource.createBlobKey(blobTemplate));

	try
	{
		datastore.delete(keyObject);
	}
	catch(Exception e)
	{
		throw new BlobException("Unknown error occurred while deleting blob (async).", e);
	}
}
 

开发者ID:dougkoellmer,
项目名称:swarm,
代码行数:26,
代码来源:BlobManager_Persistent.java

示例9: deleteBlobsAsync

点赞 3

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
@Override
public void deleteBlobsAsync(Map<I_BlobKey, Class<? extends I_Blob>> values) throws BlobException
{
	AsyncDatastoreService datastore = DatastoreServiceFactory.getAsyncDatastoreService();
	
	Transaction currentTransaction = m_blobTxnMngr.getCurrentTransaction(datastore);
	
	if( currentTransaction != null )
	{
		throw new BlobException("Can't delete within transaction.");
	}
	
	List<Key> keys = createKeysForBatchDelete(values);
	
	try
	{
		datastore.delete(keys);
	}
	catch(Exception e)
	{
		throw new BlobException("Unknown error occurred while deleting blobs (async).", e);
	}
}
 

开发者ID:dougkoellmer,
项目名称:swarm,
代码行数:24,
代码来源:BlobManager_Persistent.java

示例10: testBeginTx

点赞 2

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
@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();
        }
    }
}
 

开发者ID:GoogleCloudPlatform,
项目名称:appengine-tck,
代码行数:34,
代码来源:AsyncTest.java

示例11: testFutureCancel

点赞 2

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
@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());
}
 

开发者ID:GoogleCloudPlatform,
项目名称:appengine-tck,
代码行数:14,
代码来源:AsyncServiceTest.java

示例12: putBlobAsync

点赞 2

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
@Override
public void putBlobAsync(I_BlobKey keySource, I_Blob blob) throws BlobException
{
	AsyncDatastoreService datastore = DatastoreServiceFactory.getAsyncDatastoreService();
	
	Transaction currentTransaction = m_blobTxnMngr.getCurrentTransaction(datastore);
	
	if( currentTransaction != null )
	{
		throw new BlobException("Blob manager does not support transactions for async puts.");
	}
	
	Entity entity = createEntityForPut(keySource, blob);
	
	try
	{
		datastore.put(entity);
	}
	catch(ConcurrentModificationException concurrencyException)
	{
		throw concurrencyException;
	}
	catch(Exception e)
	{
		throw new BlobException("Some error occured while putting blob.", e);
	}
}
 

开发者ID:dougkoellmer,
项目名称:swarm,
代码行数:28,
代码来源:BlobManager_Persistent.java

示例13: RequestCapturingAsyncDatastoreService

点赞 2

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
RequestCapturingAsyncDatastoreService(AsyncDatastoreService delegate) {
  this.delegate = delegate;
}
 

开发者ID:google,
项目名称:nomulus,
代码行数:4,
代码来源:RequestCapturingAsyncDatastoreService.java

示例14: getInstance

点赞 2

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
@Deprecated
public static AsyncDatastoreService getInstance() {
  return DatastoreServiceFactory.getAsyncDatastoreService();
}
 

开发者ID:csavelief,
项目名称:gwt-sandbox,
代码行数:5,
代码来源:LowLevelDataStore2Async.java

示例15: getSingleEntity

点赞 2

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
protected Entity getSingleEntity(AsyncDatastoreService ds, Key key) {
    Map<Key, Entity> map = waitOnFuture(ds.get(Collections.singleton(key)));
    return (map.isEmpty() ? null : map.values().iterator().next());
}
 

开发者ID:GoogleCloudPlatform,
项目名称:appengine-tck,
代码行数:5,
代码来源:DatastoreHelperTestBase.java

示例16: run

点赞 1

import com.google.appengine.api.datastore.AsyncDatastoreService; //导入依赖的package包/类
T run(AsyncDatastoreService ads) throws Exception; 

开发者ID:GoogleCloudPlatform,
项目名称:appengine-tck,
代码行数:2,
代码来源:AsyncTestBase.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)