Google App Engine - 使用Objectify在本地连接到远程数据存储 [英] Google App Engine - Connect to remote datastore locally using Objectify
问题描述
我到处寻找并浪费了很多时间,我认为这很可能非常简单。我在这里先向您的帮助表示感谢。我有一个使用用Java编写的云数据存储区的谷歌应用程序引擎应用程序。我有一个实体类如下:
@Entity
public class Student {
@Id private Long studentId;
@Index私人联赛联赛;
@Index private String year;
private String firstName;
private String lastName;
...
}
我有1K个学生的csv文件。我需要将这些信息上传到云数据存储区。我也一般想与我的远程数据存储进行本地交互以进行测试等。我希望能够执行以下操作(行是csv文件的一行,我将处理它)。 (行列:Iterator< Row>){
Student student = new Student(row);
$ b
ofy()。save()。entity(student).now();
}
此代码应该在我的本地机器上运行并将实体保存到云数据存储区。
我可以按照
的方法使用GCD JSON连接到数据存储区 https ://github.com/JavaMonday/gcd-json-java 然而,这不允许使用物化。我的应用程序依赖于客观化并需要以这种方式进行填充。有没有人有线索如何一般连接和填充允许客观化/ Java的数据存储?如果您需要从本地机器连接到远程数据存储,我认为您需要使用Remote API:
Java SDK包含一个名为Remote API的库,它允许
从任何Java应用程序透明地访问App Engine服务。
例如,您可以使用Remote API从本地计算机上运行的应用程序访问生产数据存储
。
这适用于Objectify使用的Datastore API。所以你很好去。
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!
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.
这篇关于Google App Engine - 使用Objectify在本地连接到远程数据存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!