@Test public void testGet() throws DatabaseObjectNotFound { Datastore datastore = getService(); KeyFactory keyFactory = datastore.newKeyFactory().setKind("Foo"); Key key = keyFactory.newKey("myid"); Entity.Builder builder = Entity.newBuilder(key); builder.set("longVal", 1564094282994L); builder.set("byteVal", Blob.copyFrom("abcd".getBytes())); builder.set("stringList", "hello", "hi"); Entity entity = builder.build(); datastore.put(entity); CloudDatastoreBackend backend = new CloudDatastoreBackend(); Foo foo = (Foo) backend.get(Foo.class, "myid"); assertEquals("myid", foo.getId()); assertEquals(1564094282994L, foo.getLongVal().longValue()); assertArrayEquals("abcd".getBytes(), foo.getByteVal()); assertEquals(List.of("hello", "hi"), foo.getStringList()); }
@Override public Model get(Class modelClass, String objectId) throws DatabaseObjectNotFound { Datastore datastore = getService(); KeyFactory keyFactory = datastore.newKeyFactory().setKind(modelClass.getSimpleName()); Key key = keyFactory.newKey(objectId); Entity entity = datastore.get(key); if (entity == null) { throw new DatabaseObjectNotFound( String.format("%s object not found: %s", modelClass.getSimpleName(), objectId)); } return convertEntityToModel(entity, modelClass); }
CloudDatastoreBackend extends AbstractDatabaseBackend { @Override public Model get(Class modelClass, String objectId) throws DatabaseObjectNotFound { Datastore datastore = getService(); KeyFactory keyFactory = datastore.newKeyFactory().setKind(modelClass.getSimpleName()); Key key = keyFactory.newKey(objectId); Entity entity = datastore.get(key); if (entity == null) { throw new DatabaseObjectNotFound( String.format("%s object not found: %s", modelClass.getSimpleName(), objectId)); } return convertEntityToModel(entity, modelClass); } }
CloudDatastoreBackend extends AbstractDatabaseBackend { @Override public Model get(Class modelClass, String objectId) throws DatabaseObjectNotFound { Datastore datastore = getService(); KeyFactory keyFactory = datastore.newKeyFactory().setKind(modelClass.getSimpleName()); Key key = keyFactory.newKey(objectId); Entity entity = datastore.get(key); if (entity == null) { throw new DatabaseObjectNotFound( String.format("%s object not found: %s", modelClass.getSimpleName(), objectId)); } return convertEntityToModel(entity, modelClass); }  }
CloudDatastoreBackend extends AbstractDatabaseBackend { @Override public Model get(Class modelClass, String objectId) throws DatabaseObjectNotFound { Datastore datastore = getService(); KeyFactory keyFactory = datastore.newKeyFactory().setKind(modelClass.getSimpleName()); Key key = keyFactory.newKey(objectId); Entity entity = datastore.get(key); if (entity == null) { throw new DatabaseObjectNotFound( String.format("%s object not found: %s", modelClass.getSimpleName(), objectId)); } return convertEntityToModel(entity, modelClass); }  @Override List<Model> getAll(Class modelClass); @Override Model get(Class modelClass, String objectId); void save(Model model); @Override void delete(Model model); @Override int deleteExpiredItems(Class modelClass, String field, Long cutoffTime, Integer numItems); @Override void initializeDatabase(); @Override CheckResult checkConnection(); }
CloudDatastoreBackend extends AbstractDatabaseBackend { @Override public Model get(Class modelClass, String objectId) throws DatabaseObjectNotFound { Datastore datastore = getService(); KeyFactory keyFactory = datastore.newKeyFactory().setKind(modelClass.getSimpleName()); Key key = keyFactory.newKey(objectId); Entity entity = datastore.get(key); if (entity == null) { throw new DatabaseObjectNotFound( String.format("%s object not found: %s", modelClass.getSimpleName(), objectId)); } return convertEntityToModel(entity, modelClass); }  @Override List<Model> getAll(Class modelClass); @Override Model get(Class modelClass, String objectId); void save(Model model); @Override void delete(Model model); @Override int deleteExpiredItems(Class modelClass, String field, Long cutoffTime, Integer numItems); @Override void initializeDatabase(); @Override CheckResult checkConnection();  }