I have an Android app that is stored in the cloud using the Google App Engine. I am using Cloud Endpoints. My problem is that I canโt send data from the server to my client (Android device), or rather, I donโt know yet how to do it.
So far, I have managed to insert data into the data warehouse by creating an endpoint and calling the method that is responsible for adding a record to the database (which is located on the server side in myProject - AppEngine) using the following code (on the client): \
Noteendpoint.Builder endpointBuilder = new Noteendpoint.Builder( AndroidHttp.newCompatibleTransport(), new JacksonFactory(), new HttpRequestInitializer() { public void initialize(HttpRequest httpRequest) { } }); Noteendpoint endpoint = CloudEndpointUtils.updateBuilder( endpointBuilder).build(); try {
But I do not see a way to retrieve data from the data warehouse and display it on the server side. I tried to do the same thing, create an endpoint that would call a method that retrieves all the records in the database (the method that is on the server), but my application crashes.
The code for the method that retrieves data from the data warehouse is as follows:
public CollectionResponse<Note> listNote( @Nullable @Named("cursor") String cursorString, @Nullable @Named("limit") Integer limit) { EntityManager mgr = null; Cursor cursor = null; List<Note> execute = null; try { mgr = getEntityManager(); Query query = mgr.createQuery("select from Note as Note"); if (cursorString != null && cursorString != "") { cursor = Cursor.fromWebSafeString(cursorString); query.setHint(JPACursorHelper.CURSOR_HINT, cursor); } if (limit != null) { query.setFirstResult(0); query.setMaxResults(limit); } execute = (List<Note>) query.getResultList(); cursor = JPACursorHelper.getCursor(execute); if (cursor != null) cursorString = cursor.toWebSafeString(); // Tight loop for fetching all entities from datastore and accomodate // for lazy fetch. for (Note obj : execute) ; } finally { mgr.close(); } return CollectionResponse.<Note> builder().setItems(execute) .setNextPageToken(cursorString).build(); }
You see, the return type is the response of the collection. You have access to this type of data after performing the following import:
import com.google.api.server.spi.response.CollectionResponse;
I assumed that this is a data type specific to the server side, so I have no idea how I can pass it to a List, ArrayList or any other type of collection that can be used on the client side.
How can I do it? Since adding data was so simple and so straightforward, I assumed that the data would be received in the same way, but apparently I was missing something substantial for this issue.
Thank you in advance!