Google App Engine - 更改持久类的包
我的 GWT 应用程序部署在 Google App Engine for Java 上。我在应用程序引擎数据存储区中保留了一个类的实例。现在我想将该类移动到不同的包中,但这会导致反序列化现有对象时出现问题。
那么,有没有办法可以将类移动到新包中?如果这有助于我实现我的目标,我不介意更新现有对象。
谢谢。
My GWT app is deployed on Google App Engine for Java. I have persisted instances of a class in the app engine datastore. Now I want to move that class to a different package, but it leads to problems in deserializing the existing objects.
So, is there a way I can move the class to a new package? I don't mind updating the existing objects if that helps me achieve my goal.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是我将 my.package.Clazz 移动到 my.new.package.Clazz 的方法。基本思想是通过第三个“临时”类(本例中为 TempClazz)进行迁移:
创建新类 my.package.TempClazz (不要简单地重命名 Clazz)
现在部署到 GAE 并运行辅助方法以将 Clazz 实体复制到 TempClazz 实体。
如果有效的话。删除 Clazz 实体。
接下来,基本上重复该过程,只不过这次您实际上将 my.package.Clazz 重构为新包 my.new.package.Clazz。所以此时你将有两个类:my.package.TempClazz 和 my.new.package.Clazz。
剩下要做的就是再次从数据存储中读取 TempClazz 并将每个内容复制到 Clazz 实体中。
剩下
相当投入。也许有人知道更简单的方法?
This is how I would move my.package.Clazz to my.new.package.Clazz. The basic idea is to do the migration via a third "temporary" class (TempClazz in this case):
create new class my.package.TempClazz (do NOT simply rename Clazz)
create a helper method that will read all existing Clazz entities from the datastore, then copy the data into the new TempClazz instance and store the TempClazz entities in the datastore.
now deploy to GAE and run the helper method to copy your Clazz entities to TempClazz entities.
if that worked. Delete Clazz-entities.
next, basically repeat the process, except that this time you actually refactor my.package.Clazz into the new package my.new.package.Clazz. So at this point you will have two classes: my.package.TempClazz and my.new.package.Clazz.
all that's left to do is again to read TempClazz from the datastore and copy each into a Clazz-entity.
Pretty involved. Maybe someone knows an easier way?