Search in sources :

Example 61 with Key

use of com.google.appengine.api.datastore.Key in project nomulus by google.

the class EppHistoryVKeyTranslatorFactory method createTranslator.

@Override
SimpleTranslator<EppHistoryVKey, Key> createTranslator() {
    return new SimpleTranslator<EppHistoryVKey, Key>() {

        @Nullable
        @Override
        public EppHistoryVKey loadValue(@Nullable Key datastoreValue) {
            if (datastoreValue == null) {
                return null;
            } else {
                com.googlecode.objectify.Key<?> ofyKey = com.googlecode.objectify.Key.create(datastoreValue);
                String kindPath = EppHistoryVKey.createKindPath(ofyKey);
                if (kindPathToVKeyClass.containsKey(kindPath)) {
                    Class<? extends EppHistoryVKey> vKeyClass = kindPathToVKeyClass.get(kindPath);
                    try {
                        Method createVKeyMethod = vKeyClass.getDeclaredMethod("create", com.googlecode.objectify.Key.class);
                        return (EppHistoryVKey) createVKeyMethod.invoke(null, ofyKey);
                    } catch (NoSuchMethodException e) {
                        throw new IllegalStateException("Missing static method create(com.googlecode.objectify.Key) on " + vKeyClass);
                    } catch (IllegalAccessException | InvocationTargetException e) {
                        throw new IllegalStateException("Error invoking createVKey on " + vKeyClass, e);
                    }
                } else {
                    throw new IllegalStateException("Missing EppHistoryVKey implementation for kind path: " + kindPath);
                }
            }
        }

        @Nullable
        @Override
        public Key saveValue(@Nullable EppHistoryVKey pojoValue) {
            return pojoValue == null ? null : pojoValue.createOfyKey().getRaw();
        }
    };
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) EppHistoryVKey(google.registry.persistence.EppHistoryVKey) Nullable(javax.annotation.Nullable) EppHistoryVKey(google.registry.persistence.EppHistoryVKey) DomainHistoryVKey(google.registry.persistence.DomainHistoryVKey) BillingRecurrenceVKey(google.registry.persistence.BillingVKey.BillingRecurrenceVKey) Key(com.google.appengine.api.datastore.Key) BillingEventVKey(google.registry.persistence.BillingVKey.BillingEventVKey)

Example 62 with Key

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

the class AppEngineCredentialStore method delete.

@Override
public void delete(String userId, Credential credential) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key key = KeyFactory.createKey(KIND, userId);
    datastore.delete(key);
}
Also used : DatastoreService(com.google.appengine.api.datastore.DatastoreService) Key(com.google.appengine.api.datastore.Key)

Example 63 with Key

use of com.google.appengine.api.datastore.Key in project iosched by google.

the class ServingUrlManagerTest method testCreateServingUrl_servingUrlAlreadyExists.

@Test
public void testCreateServingUrl_servingUrlAlreadyExists() throws Exception {
    when(mockDatastoreService.get(any(Key.class))).thenAnswer(new Answer<Entity>() {

        @Override
        public Entity answer(InvocationOnMock invocation) throws Throwable {
            Entity key = new Entity((Key) invocation.getArguments()[0]);
            key.setProperty(ServingUrlManager.SERVING_URL_PROPERTY, SERVING_URL);
            return key;
        }
    });
    assertEquals(SERVING_URL, ServingUrlManager.INSTANCE.createServingUrl(GCS_FILENAME, Optional.<String>absent()));
    verifyZeroInteractions(mockImagesService);
    verify(mockDatastoreService, never()).put(any(Entity.class));
}
Also used : Entity(com.google.appengine.api.datastore.Entity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) Key(com.google.appengine.api.datastore.Key) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 64 with Key

use of com.google.appengine.api.datastore.Key in project siena by mandubian.

the class GaePersistenceManagerAsync method getByKey.

public <T> SienaFuture<T> getByKey(final Class<T> clazz, final Object key) {
    Key gkey = GaeMappingUtils.makeKeyFromId(clazz, key);
    try {
        Future<Entity> future = ds.get(gkey);
        Future<T> wrapped = new SienaFutureWrapper<Entity, T>(future) {

            @Override
            protected T wrap(Entity entity) throws Exception {
                T obj = Util.createObjectInstance(clazz);
                GaeMappingUtils.fillModelAndKey(obj, entity);
                return obj;
            }
        };
        return new SienaFutureContainer<T>(wrapped);
    } catch (Exception e) {
        throw new SienaException(e);
    }
}
Also used : SienaFutureWrapper(siena.core.async.SienaFutureWrapper) Entity(com.google.appengine.api.datastore.Entity) SienaFutureContainer(siena.core.async.SienaFutureContainer) SienaException(siena.SienaException) Key(com.google.appengine.api.datastore.Key) SienaException(siena.SienaException) NotImplementedException(org.apache.commons.lang.NotImplementedException)

Example 65 with Key

use of com.google.appengine.api.datastore.Key in project siena by mandubian.

the class GaePersistenceManagerAsync method update.

@Override
public <T> SienaFuture<Integer> update(Iterable<T> objects) {
    // throw new NotImplementedException("update not implemented for GAE yet");
    List<Entity> entities = new ArrayList<Entity>();
    for (Object obj : objects) {
        Class<?> clazz = obj.getClass();
        ClassInfo info = ClassInfo.getClassInfo(clazz);
        Entity entity = GaeMappingUtils.createEntityInstanceForUpdate(info, obj);
        GaeMappingUtils.fillEntity(obj, entity);
        entities.add(entity);
    }
    Future<List<Key>> future = ds.put(entities);
    Future<Integer> wrapped = new SienaFutureWrapper<List<Key>, Integer>(future) {

        @Override
        protected Integer wrap(List<Key> keys) throws Exception {
            return keys.size();
        }
    };
    return new SienaFutureContainer<Integer>(wrapped);
}
Also used : SienaFutureWrapper(siena.core.async.SienaFutureWrapper) Entity(com.google.appengine.api.datastore.Entity) SienaFutureContainer(siena.core.async.SienaFutureContainer) ArrayList(java.util.ArrayList) QueryResultList(com.google.appengine.api.datastore.QueryResultList) ArrayList(java.util.ArrayList) List(java.util.List) Key(com.google.appengine.api.datastore.Key) ClassInfo(siena.ClassInfo)

Aggregations

Key (com.google.appengine.api.datastore.Key)121 Entity (com.google.appengine.api.datastore.Entity)83 ArrayList (java.util.ArrayList)39 DatastoreService (com.google.appengine.api.datastore.DatastoreService)26 Query (com.google.appengine.api.datastore.Query)23 Test (org.junit.Test)23 ClassInfo (siena.ClassInfo)23 Field (java.lang.reflect.Field)22 EntityNotFoundException (com.google.appengine.api.datastore.EntityNotFoundException)21 HashMap (java.util.HashMap)14 SienaException (siena.SienaException)14 List (java.util.List)13 PreparedQuery (com.google.appengine.api.datastore.PreparedQuery)12 QueryResultList (com.google.appengine.api.datastore.QueryResultList)11 Map (java.util.Map)11 Transaction (com.google.appengine.api.datastore.Transaction)9 SienaFutureContainer (siena.core.async.SienaFutureContainer)9 SienaFutureWrapper (siena.core.async.SienaFutureWrapper)9 FilterPredicate (com.google.appengine.api.datastore.Query.FilterPredicate)7 IOException (java.io.IOException)7