简体   繁体   中英

Google App Engine - How does datastore initialization work across sessions?

I'm developing my first project for GAE, and I'm wondering about how to go about setting up my connection to the datastore.

Currently, I have the following in the header.jsp, which is included in all pages and includes a reference to a Datastore class that I created.

header.jsp:

<%@ page import="foo.Datastore"%>

<%
    if (Datastore.getDatastore() == null) {
        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        Datastore.setDatastore(datastore);
    }
%>

Datastore.java:

public class Datastore {
    private static DatastoreService ds;

    public static DatastoreService getDatastore() {
        return ds;
    }
    public static void setDatastore(DatastoreService d) {
        ds = d;
    }
}

Will this connect me to the SAME datastore every time I use the application? If so, can you explain how this works? How does DatastoreServiceFactory.getDatastoreService() know which datastore to connect to? Thanks!

您不必指定要连接到哪个数据存储,因为每个应用程序只有一个数据存储。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM