Search in sources :

Example 46 with DatastoreService

use of com.google.appengine.api.datastore.DatastoreService in project google-oauth-java-client by googleapis.

the class AppEngineCredentialStore method migrateTo.

/**
 * Migrates to the new format using {@link DataStore} of {@link StoredCredential}.
 *
 * @param credentialDataStore credential data store
 * @since 1.16
 */
public final void migrateTo(DataStore<StoredCredential> credentialDataStore) throws IOException {
    DatastoreService service = DatastoreServiceFactory.getDatastoreService();
    PreparedQuery queryResult = service.prepare(new Query(KIND));
    for (Entity entity : queryResult.asIterable()) {
        StoredCredential storedCredential = new StoredCredential().setAccessToken((String) entity.getProperty("accessToken")).setRefreshToken((String) entity.getProperty("refreshToken")).setExpirationTimeMilliseconds((Long) entity.getProperty("expirationTimeMillis"));
        credentialDataStore.set(entity.getKey().getName(), storedCredential);
    }
}
Also used : Entity(com.google.appengine.api.datastore.Entity) PreparedQuery(com.google.appengine.api.datastore.PreparedQuery) Query(com.google.appengine.api.datastore.Query) StoredCredential(com.google.api.client.auth.oauth2.StoredCredential) DatastoreService(com.google.appengine.api.datastore.DatastoreService) PreparedQuery(com.google.appengine.api.datastore.PreparedQuery)

Example 47 with DatastoreService

use of com.google.appengine.api.datastore.DatastoreService in project appengine-java-standard by GoogleCloudPlatform.

the class TaskQueueTest method testBulkAddImplicitTransactionEnlistment_TaskOptions.

@Test
public void testBulkAddImplicitTransactionEnlistment_TaskOptions() {
    MockQueueBulkAddApiHelper helper = newBasicAddRequest();
    com.google.apphosting.datastore.proto2api.DatastoreV3Pb.Transaction pbTxn = com.google.apphosting.datastore.proto2api.DatastoreV3Pb.Transaction.newBuilder().setHandle(44).setApp(APP).build();
    helper.expectedRequest.getAddRequestBuilder(0).setTransaction(pbTxn);
    Transaction txn = mock(Transaction.class);
    when(txn.getId()).thenReturn("44");
    when(txn.getApp()).thenReturn(APP);
    DatastoreService ds = mock(DatastoreService.class);
    when(ds.getCurrentTransaction(null)).thenReturn(txn);
    Queue q = helper.getQueue(ds);
    q.add(TaskOptions.Builder.withDefaults());
}
Also used : Transaction(com.google.appengine.api.datastore.Transaction) DatastoreService(com.google.appengine.api.datastore.DatastoreService) DatastoreV3Pb(com.google.apphosting.datastore.DatastoreV3Pb) Test(org.junit.Test)

Example 48 with DatastoreService

use of com.google.appengine.api.datastore.DatastoreService in project appengine-java-standard by GoogleCloudPlatform.

the class TaskQueueTest method testBulkAddImplicitTransactionEnlistment_TaskOptions_ExplicitNullTxn.

@Test
public void testBulkAddImplicitTransactionEnlistment_TaskOptions_ExplicitNullTxn() {
    MockQueueBulkAddApiHelper helper = newBasicAddRequest();
    Transaction txn = mock(Transaction.class);
    when(txn.getId()).thenReturn("44");
    when(txn.getApp()).thenReturn(APP);
    DatastoreService ds = mock(DatastoreService.class);
    when(ds.getCurrentTransaction(null)).thenReturn(txn);
    Queue q = helper.getQueue(ds);
    q.add(null, TaskOptions.Builder.withDefaults());
}
Also used : Transaction(com.google.appengine.api.datastore.Transaction) DatastoreService(com.google.appengine.api.datastore.DatastoreService) Test(org.junit.Test)

Example 49 with DatastoreService

use of com.google.appengine.api.datastore.DatastoreService in project appengine-java-standard by GoogleCloudPlatform.

the class TaskQueueIntegrationTest method testBulkAddTransactionalVarArguments.

@Test
public void testBulkAddTransactionalVarArguments() throws Exception {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Transaction txn = datastore.beginTransaction();
    List<TaskHandle> tasks = defaultQueue.add(txn, Arrays.asList(withTaskName(""), withTaskName(""), withTaskName("")));
    txn.commit();
    for (TaskHandle task : tasks) {
        assertThat(task.getName()).startsWith("task");
        assertThat(task.getQueueName()).isEqualTo(defaultQueue.getQueueName());
    }
}
Also used : Transaction(com.google.appengine.api.datastore.Transaction) DatastoreService(com.google.appengine.api.datastore.DatastoreService) Test(org.junit.Test)

Example 50 with DatastoreService

use of com.google.appengine.api.datastore.DatastoreService in project appengine-java-standard by GoogleCloudPlatform.

the class TaskQueueIntegrationTest method testBulkAddTransactionalTaskNullTaskName.

@Test
public void testBulkAddTransactionalTaskNullTaskName() throws Exception {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Transaction txn = datastore.beginTransaction();
    TaskHandle task = defaultQueue.add(txn, withDefaults());
    txn.commit();
    assertThat(task.getName()).startsWith("task");
    assertThat(task.getQueueName()).isEqualTo(defaultQueue.getQueueName());
}
Also used : Transaction(com.google.appengine.api.datastore.Transaction) DatastoreService(com.google.appengine.api.datastore.DatastoreService) Test(org.junit.Test)

Aggregations

DatastoreService (com.google.appengine.api.datastore.DatastoreService)64 Entity (com.google.appengine.api.datastore.Entity)43 Test (org.junit.Test)29 Key (com.google.appengine.api.datastore.Key)25 Query (com.google.appengine.api.datastore.Query)25 Transaction (com.google.appengine.api.datastore.Transaction)15 EntityNotFoundException (com.google.appengine.api.datastore.EntityNotFoundException)6 PreparedQuery (com.google.appengine.api.datastore.PreparedQuery)6 LocalDatastoreService (com.google.appengine.api.datastore.dev.LocalDatastoreService)6 ArrayList (java.util.ArrayList)6 Date (java.util.Date)5 PersistenceManager (javax.jdo.PersistenceManager)5 Filter (com.google.appengine.api.datastore.Query.Filter)4 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)4 FilterPredicate (com.google.appengine.api.datastore.Query.FilterPredicate)3 FilterChain (javax.servlet.FilterChain)3 BlobKey (com.google.appengine.api.blobstore.BlobKey)2 Blob (com.google.appengine.api.datastore.Blob)2 DatastoreServiceConfig (com.google.appengine.api.datastore.DatastoreServiceConfig)2 FetchOptions (com.google.appengine.api.datastore.FetchOptions)2