我有一个使用 Java 编写的云数据存储的 Google 应用程序引擎应用程序。我有一个实体类如下:
@Entity
public class Student {
@Id private Long studentId;
@Index private League league;
@Index private String year;
private String firstName;
private String lastName;
...
}
我有一个包含 1K 名学生的 csv 文件。我需要将此信息上传到云数据存储中。我通常还想在本地与远程数据存储进行交互以进行测试等。我希望能够执行以下操作(行是 csv 文件的一行,我将处理它)。
for ( Row row : Iterator<Row> ){
Student student = new Student(row);
ofy().save().entity(student).now();
}
此代码应该在我的本地计算机上运行并将实体保存到云数据存储中。 我可以按照以下方法使用 GCD JSON 连接到数据存储 https://github.com/JavaMonday/gcd-json-java
但是,这不允许使用 objectify。我的应用程序依赖于 objectify 并且需要以这种方式填充。有谁知道如何一般连接和填充允许 objectify/Java 的数据存储吗?
最佳答案
如果您需要从本地计算机连接到远程数据存储,我认为您需要使用远程 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.
这适用于 Objectify 使用的数据存储 API。那么你就可以开始了。
关于java - Google App Engine - 使用 Objectify 在本地连接到远程数据存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27762240/