你能帮我解决这个问题吗?在这里,我通过使用AJAX调用的JDO接口将一些数据存储到数据存储中。我正在将数据存储到数据存储,并立即检索它。在检索时,有时它会返回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;
}发布于 2016-03-02 21:58:15
数据存储区跨多个数据中心复制数据。这为读写提供了高级别的可用性,然而,大多数查询最终都是一致的。
最终一致性是分布式计算中用于实现高可用性的一致性模型,它非正式地保证,如果没有对给定数据项进行新的更新,则最终对该数据项的所有访问都将返回上次更新的值。
这很可能是查询有时不返回任何内容的原因。
我建议你去看看Structuring Data for Strong Consistency的文章。
发布于 2016-03-02 21:23:11
下面是一个很有用的例子:
https://github.com/mattburns/OddPrints/blob/master/op-gae/src/com/oddprints/servlets/Edit.java#L89
@GET
@Path("/basic/sample")
@Produces(MediaType.TEXT_HTML)
public Viewable loadBasicSample(@Context HttpServletRequest req)
throws FileUploadException, IOException, URISyntaxException {
return viewSampleImage(req, Settings.SAMPLE_PHOTO_BLOB_KEY,
Settings.SAMPLE_PHOTO_BLOB_SIZE, new URL(
"http://www.oddprints.com/images/sample.jpg"));
}
Viewable viewSampleImage(HttpServletRequest req, Settings blobKeySetting,
Settings blobSizeSetting, URL image) throws MalformedURLException,
IOException {
String blobKeyString = ApplicationSetting.getSetting(blobKeySetting);
if (blobKeyString == null) {
InputStream imgStream = image.openStream();
byte[] bytes = IOUtils.toByteArray(imgStream);
BlobKey blobKey = ImageBlobStore.INSTANCE.writeImageData(bytes);
blobKeyString = blobKey.getKeyString();
ApplicationSetting.putSetting(blobKeySetting, blobKeyString);
ApplicationSetting.putSetting(blobSizeSetting, "" + bytes.length);
}
String blobSize = ApplicationSetting.getSetting(blobSizeSetting);
req.getSession().setAttribute("blobKeyString", blobKeyString);
req.getSession().setAttribute("blobSize", blobSize);
req.getSession().setAttribute("basicMode", Boolean.TRUE);
return viewBasic(req);
}发布于 2016-03-04 23:28:34
我建议使用memcache,这样获取速度会更快,返回的空对象也会更少。
https://stackoverflow.com/questions/35748317
复制相似问题