简体   繁体   English

appengine数据存储区更改实体属性

[英]appengine datastore change entities property

I would like to change the entity property from String to long. 我想将实体属性从String更改为long。 I have seen Nick answering similar problem in Change IntegerProperty to FloatProperty of existing AppEngine DataStore but I am writing in Java and need some code example since I don't know anything about the mapreduce. 我已经看到尼克在将现有AppEngine DataStore的IntegerProperty更改为FloatProperty中回答了类似的问题,但是我正在用Java编写并且需要一些代码示例,因为我对mapreduce一无所知。

eg we want to change userId from String to Long of this class . 例如,我们想将userId从String更改为此类的 Long。

I also would like to get advice on my thinking of storing date in long instead of String so that the time information can be consumed readily from android, GWT and more(over Rest Json or RPC). 我还想就长存储日期而不是String的想法获得建议,以便可以轻松地从android,GWT等(通过Rest Json或RPC)消耗时间信息。 Right now, GWT does not have Jodatime and it has limited support of Java.util.Date and parsing. 目前,GWT还没有Jodatime,并且它对Java.util.Date和解析的支持有限。

What is your persistence interface? 你的持久化界面是什么? JDO (mine), JPA, Objectify, Twig, raw GAE/J API? JDO(mine),JPA,Objectify,Twig,原始GAE / J API? I don't think that many people can give you a code example without knowing this. 我认为没有人会在不知情的情况下为您提供代码示例。

Also, please give the code extract of your existing (an underlying date-time, I presume) persistent entity including the data member you talk about. 另外,请提供您现有的(我认为是基础日期时间)持久实体的代码摘录,其中包括您所讨论的数据成员。

If you really want to convert from String to Long, I can't see any other choice except to write a conversion snippet using raw GAE, eg: 如果您真的想从String转换为Long,除了使用原始GAE编写转换代码段,我看不到其他选择,例如:

import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query;

Query q = new Query (Task.class.getName());
PreparedQuery pq = DatastoreServiceFactory.getDatastoreService ().prepare (q);
for (Entity entity : pq.asIterable ())
{
    String orig = entity.getProperty ("userId").toString ();
    entity.removeProperty ("userId");
    entity.setProperty ("userId", Long.parseLong (orig));
}

Your class is using JPA not JDO. 您的课程使用的是JPA,而不是JDO。 The latest version (v2.x) of the GAE JPA plugin allows persistence of (java.util.)Date as Long or String. GAE JPA插件的最新版本(v2.x)允许(java.util。)Date持久化为Long或String。 This wouldn't cater for your migration of data (see the reply by Jonathan for that) but would allow you to persist future Date fields as Long. 这不能满足您的数据迁移需求(请参阅Jonathan的答复),但可以让您将将来的Date字段保留为Long。 IIRC you can specify the "jdbcType" (DataNucleus extension annotation) as INTEGER would trigger that. 在IIRC中,您可以指定“ jdbcType”(DataNucleus扩展注释),因为INTEGER会触发它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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