Google App Engine - Connect to remote datastore locally using Objectify

女生的网名这么多〃 提交于 2020-01-07 05:57:08

问题


I've looked everywhere and wasted a lot of time on something that I think is probably very simple. Thanks for the help in advance. I have a google app engine app using the cloud datastore written in Java. I have an entity class as follows:

@Entity 
public class Student {

    @Id private Long studentId;
    @Index private League league;
    @Index private String year;
    private String firstName;
    private String lastName;
    ...
}

I have a csv file of 1K students. I need to upload this info into the cloud datastore. I also generally want to interact locally with my remote datastore for testing etc. I want to be able to do the following (row is a row of the csv file, i'll handle that).

for ( Row row : Iterator<Row> ){
   Student student = new Student(row);
   ofy().save().entity(student).now();
}

This code should run on my local machine and save entities to the cloud datastore. I can connect to the datastore using the GCD JSON following the methodology at https://github.com/JavaMonday/gcd-json-java

However, this doesn't allow for the use of objectify. My app relies on objectify and need to populate in that manner. Does anyone have a clue how to generically connect and populate the datastore that allows objectify/Java? Thanks!


回答1:


If you need to connect to remote datastore from local machine, I think you need to use the Remote API: https://cloud.google.com/appengine/docs/java/tools/remoteapi

The Java SDK includes a library called Remote API that lets you transparently access App Engine services from any Java application. For example, you can use Remote API to access a production datastore from an app running on your local machine.

This works for Datastore API, which are used by Objectify. So you're good to go.



来源:https://stackoverflow.com/questions/27762240/google-app-engine-connect-to-remote-datastore-locally-using-objectify

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!