gpt4 book ai didi

java - 使用 JDO 从数据存储区存储和检索数据

转载 作者:行者123 更新时间:2023-12-01 10:18:51 25 4
gpt4 key购买 nike

你能帮我解决这个问题吗?在这里,我使用 AJAX 调用通过 JDO 接口(interface)将一些数据存储到数据存储区。我将数据存储到数据存储并立即检索它。检索时有时会返回 NULL 作为响应(它并不总是返回 NULL。仅有时返回 NULL)。你能帮我解决这个问题吗?下面给出的代码用于存储和检索数据

此代码用于存储数据,

public void saveSchedule(String listName, String email, String date, String time, String details, String name)
{

Date hiredate = new Date();
String gmtdate = hiredate.toGMTString();
Schedule schedule = new Schedule();
schedule.setName(name);
schedule.setListName(listName);
schedule.setEmail(email);
schedule.setDate(date);
schedule.setDateGMT(gmtdate);
schedule.setDetails(details);
schedule.setTime(time);
p = PMF.get().getPersistenceManager();
try
{
p.makePersistent(schedule);
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
p.close();
}
}

此代码用于检索数据,

public String savedDataRetrive(String details, String email) {

p = PMF.get().getPersistenceManager();
Query q = p.newQuery(Schedule.class);
q.setFilter("details == '"+details+"' && email == '"+email+"'");
List<Schedule> sch = (List<Schedule>) q.execute();
String data = null;
ObjectMapper n=new ObjectMapper();
try {
data = n.writeValueAsString(sch);

} catch (JsonGenerationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
p.close();
}
return data;
}

最佳答案

数据存储跨多个数据中心复制数据。这为读取和写入提供了高水平的可用性,但是,大多数查询最终是一致的。

Eventual consistency is a consistency model used in distributed computing to achieve high availability that informally guarantees that, if no new updates are made to a given data item, eventually all accesses to that item will return the last updated value.

这很可能是您的查询有时不返回任何内容的原因。

我建议您浏览Structuring Data for Strong Consistency文章。

关于java - 使用 JDO 从数据存储区存储和检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35748317/

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