@Override public Entity get(Key key) throws EntityNotFoundException { return datastore.get(key); }
@Override public Map<Key, Entity> call() { return dataStore.get(null, keys); } });
@Override public Entity call() throws EntityNotFoundException { return dataStore.get(null, key); } });
Key key = KeyFactory.createKey("User", id); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); User user = datastore.get(key);
// When getting session from datastore DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Key sessionKey = KeyFactory.createKey("_ah_SESSION", sessionId); Entity sessionEntity = datastore.get(sessionKey); byte[] sessionBytes = sessionEntity.getProperty("_values"); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(sessionBytes); ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); Map<?, ?> sessionMap = (Map) objectInputStream.readObject(); FooBar restoredFooBar = (FooBar) sessionMap.get("fooBar");
public Entity get(Key key) throws EntityNotFoundException { try { return inner.get(key); } catch (IllegalArgumentException e) { throw wrapIllegalArgumentException(e); } catch (DatastoreFailureException e) { throw wrapDatastoreFailureException(e); } }
public Entity get(Transaction transaction, Key key) throws EntityNotFoundException { try { return inner.get(transaction, key); } catch (IllegalArgumentException e) { throw wrapIllegalArgumentException(e); } catch (DatastoreFailureException e) { throw wrapDatastoreFailureException(e); } }
public Map<Key, Entity> get(Iterable<Key> keyIterable) { try { return inner.get(keyIterable); } catch (IllegalArgumentException e) { throw wrapIllegalArgumentException(e); } catch (DatastoreFailureException e) { throw wrapDatastoreFailureException(e); } }
public Map<Key, Entity> get(Transaction transaction, Iterable<Key> keyIterable) { try { return inner.get(transaction, keyIterable); } catch (IllegalArgumentException e) { throw wrapIllegalArgumentException(e); } catch (DatastoreFailureException e) { throw wrapDatastoreFailureException(e); } }
public static LeanAccount getAccount(long accountID) { if (accountID <= 0) return null; Entity accountEntity; try { accountEntity = datastore.get(KeyFactory.createKey(accountsKind, accountID)); } catch (EntityNotFoundException e) { return null; } return toLeanAccount(accountEntity); }
DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); Entity e = new Entity("data"); e.setProperty("jsonString", "myValue"); Key key = ds.put(e); Entity entity = ds.get(key); System .out.println(entity);
protected void assertStoreDoesNotContain(Key key) throws EntityNotFoundException { try { Entity storedEntity = service.get(key); Assert.fail("expected the datastore not to contain anything under key " + key + ", but it contained the entity " + storedEntity); } catch (EntityNotFoundException e) { // pass } }
@SuppressWarnings("unchecked") @Override public <T> T fetch(IdRef<T> id) { try { Key key = IdRefToKey.toKey(r, id); Entity entity = datastore().get(key); return (T) toObject.convert(id.getModel(), entity); } catch (EntityNotFoundException e) { return null; } }
private Entity getTestDataEntity() throws EntityNotFoundException { DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); return datastore.get(KeyFactory.createKey(ENTITY_KIND, ENTITY_NAME)); } }
@Test(expected = EntityNotFoundException.class) public void getThrowsNotFoundExceptionWhenKeyIsNotFound() throws Exception { Key nonExistingKey = KeyFactory.createKey("NonExistingKey", 1); service.get(nonExistingKey); }
protected void assertStoreContains(Entity entity) throws EntityNotFoundException { Entity lookup = service.get(entity.getKey()); Assert.assertNotNull(lookup); Assert.assertEquals(entity, lookup); }
@Test public void batchGetReturnsOnlyExistingKeysInMap() throws Exception { Key existingKey = KeyFactory.createKey("batch", "existing"); Key nonExistingKey = KeyFactory.createKey("batch", "nonExisting"); service.put(new Entity(existingKey)); Map<Key, Entity> map = service.get(Arrays.asList(existingKey, nonExistingKey)); assertEquals(1, map.size()); assertTrue(map.containsKey(existingKey)); }
@Test public void testEntityGainsNoAdditionalPropertiesWhenStored() throws Exception { clearData(kindName); Entity entity = new Entity(kindName); Key key = service.put(entity); entity = service.get(key); assertEquals(Collections.<String, Object>emptyMap(), entity.getProperties()); } }
@Test @WithinNamespace({ "", "Ns1" }) public void testSmoke() throws Exception { final DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); Key key = ds.put(new Entity("NsTest")); try { Assert.assertNotNull(ds.get(key)); } finally { ds.delete(key); } } }
@Test public void test() throws Exception { EmbeddedEntity embedded = new EmbeddedEntity(); embedded.setProperty("string", "foo"); Entity entity = createTestEntity(); entity.setProperty("embedded", embedded); Key key = service.put(entity); Entity storedEntity = service.get(key); EmbeddedEntity storedEmbedded = (EmbeddedEntity) storedEntity.getProperty("embedded"); assertEquals(embedded, storedEmbedded); } }