gpt4 book ai didi

java - 在 App Engine Java Servlet 中查询数据存储区统计信息时出现 NullpointerException

转载 作者:行者123 更新时间:2023-12-02 04:49:04 25 4
gpt4 key购买 nike

在我的应用程序的 Servlet 中,我想控制其数据存储区是否为空(我第一次运行 servlet 时它将为空,但现在情况并非如此,因为我已经填充了它并使其持久化)在继续其余代码之前。在此Datastore Docs我发现了一种查询数据存储并获取不同类型统计信息的方法。但是在执行时:

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Entity globalStat = datastore.prepare(new Query("__Stat_Total__")).asSingleEntity();
Long totalBytes = (Long) globalStat.getProperty("bytes");
Long totalEntities = (Long) globalStat.getProperty("count");

我得到一个NullPointerException当我尝试存储两个 Long 变量时。为什么是Entity globalStat查询后对象为空?

编辑 1:附加信息

我正在尝试在使用 List<Entity> 填充数据存储区统计信息后获取数据存储区统计信息。实体数量:

public class MyServlet extends HttpServlet {
ArrayList<Tour> m_tours = new ArrayList<Tour>();
Key tourKey;
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

//.... some code
private DatastoreService populateDatastore(){
//... some other code ...
List<Entity> List = Arrays.asList(tour,tour1,tour2,tour3,
tour4,tour5,tour6,tour7,tour8);
datastore.put(List);
Entity globalStat = datastore.prepare(
new Query("__Stat_Total__")).asSingleEntity();

try{
Long totalEntities = (Long) globalStat.getProperty("count");
Long totalBytes = (Long) globalStat.getProperty("bytes");
}catch (NullPointerException e){
e.printStackTrace();
}`
}
}

这表明实体全局统计对象在调试工具中仍然显示为空:

Entity globalstat

怎么会new Query("__Stat_Total__")).asSingleEntity();当我刚刚用多个实体填充数据存储区时不会产生任何结果?

最佳答案

ANSWER: as reported here: Using App Engine Datastore Low Level API with Java, "Stat_Total" and "Stat_Kind" don't work in a local development server. They only work when deployed in App Engine Server.

关于java - 在 App Engine Java Servlet 中查询数据存储区统计信息时出现 NullpointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29416865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com