androidgoogle-cloud-platformgoogle-app-enginegoogle-cloud-endpoints

GAE Endpoint, Objectify and Android - Where are my data being saved?


I'm developing an app on Android, and I'm trying to save some data on the Google Cloud Datastore. I've implemented a Google App Engine Endpoint and set up Objectify on it, then I've deployed to the App Engine.

Finally I've made up some AsyncTask in my android project to communicate with the API.

The communication works, and no error message are displayed in my log, but when I do (in the App Engine Endpoint)

Car car = new Car("black","1200","2016");
ofy().save().entity(car).now();

it is executed correctly but then I go to my Datastore console,and it doesn't have any entity in it.

Same, if I do

List<Car> cars = ofy().load().type(Car.class).list();

I always get a null result.

So where are my data saved?

UPDATE

Previously I have wrote the Objectify code in my Endpoint Api class (MyEndpoint.java) , now I'm trying to just rely on Android Endpoint Auto-generation, so I've created a new model (@Entity) and used "Generate Cloud Endpoint from java class" built in Android Studio, so now I have a new CarEndpoint. It contains insert and list api methods (and more).

So from the app code, in the AsyncTask, I'm doing the following:

    Car car = new Car();
    car.setYear("2016");
    car.setCC("1200");
    car.setColor("black");
    try {
        carApi.insert(car).execute();
    } catch (IOException e) {
        e.printStackTrace();
    }

It gets executed and no error are thrown. This is the log:

 I/System.out: open:https://app-backend.appspot.com/_ah/api/carApi/v1/car
 I/System.out: [CDS]rx timeout:1
 I/System.out: [CDS]rx timeout:1
 I/System.out: [CDS]rx timeout:20000
 I/System.out: [CDS]rx timeout:20000
 I/System.out: [CDS]rx timeout:20000
 I/System.out: [CDS]rx timeout:20000
 I/System.out: [OkHttp] sendRequest<<

But again, in my Datastore console, no new objects are being created.

So again, where are my object being saved?

UPDATE 2

I've still not found where the data are saved, but after my update, I can now retrieve data using the list API method (autogenerated).

To have a easy way to use your API method from a backend, you can use the APIs Explorer . You can access it using a browser at the address

https://app-backend.appspot.com/

and click on the top menu on the "GC Endpoint API Explorer" menu item.

It seems like the data are stored internally at the API. Can I see them with the Google Datastore Console?


Solution

  • Yes you should be able to see your entities through the Cloud console: through the Console Menu (click on hamburger on the top left corner) choose "Datastore" under the "STORAGE" group and the first page of this Datastore "area" is named "Entities". From there you can query by kind or by GQL.

    Also, you could have a look at https://cloud.google.com/appengine/docs/java/console/managing-datastore