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();
}
};
}
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);
}
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));
}
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);
}
}
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);
}
Aggregations