[英]Google App Engine - How does datastore initialization work across sessions?
我正在為GAE開發第一個項目,並且想知道如何建立與數據存儲的連接。
當前,header.jsp中包含以下內容,該內容包含在所有頁面中,並且包含對我創建的Datastore類的引用。
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;
}
}
每次我使用該應用程序時,都會將我連接到SAME數據存儲嗎? 如果是這樣,您能解釋一下它是如何工作的嗎? DatastoreServiceFactory.getDatastoreService()
如何知道要連接到哪個數據存儲區? 謝謝!
您不必指定要連接到哪個數據存儲,因為每個應用程序只有一個數據存儲。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.