在 Google App Engine 中重构包含 JDO @PersistenceCapable 类的包

发布于 2024-09-10 17:42:01 字数 198 浏览 6 评论 0原文

我在包中有一组具有 JDO 持久性的类需要重构。

我知道如果您更改类名,那么您需要更新“BigTables”对象。但是,如果我更改java对象所属的包,这是否意味着“BigTables”中的数据对象需要以某种方式更新?

即 com.example.test.Person -> com.example.blah.Person

I have a set of JDO persistence capable classes in packages that need to be refactored.

I know if you change the class name then you need to update the "BigTables" objects. However, if I change the package the java objects belong to, will this mean the data objects in "BigTables" need to be somehow updated?

ie com.example.test.Person -> com.example.blah.Person

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听风吹 2024-09-17 17:42:01

官方文档中的对象字段和实体属性。以下是重构规则的结果:

  • 向类添加新的可为空字段将导致所有现有实体的该字段为空。
  • 添加新的集合或数组字段将导致所有现有实体的该字段的集合或数组为空。
  • 添加新的不可为 null 的字段将导致在尝试加载现有实体时引发异常。
  • 删除字段不会导致错误;现有实体将保留旧字段,直到再次加载并保存它们。
  • 更改字段的类型将导致 App Engine 尝试将旧值转换为新数据类型;如果强制转换无效,则会抛出异常。数字类型是一个例外;在这种情况下,该值将被转换而不是强制转换,并且溢出不会导致异常。

如果您需要进行上述简单修改无法实现的重构,您可能需要使用 App Engine MapReduce 库

A little of this is documented in the official docs under Object Fields and Entity Properties. Here's the upshot in terms of refactoring rules:

  • Adding a new nullable field to your class will result in all existing entities having null for that field.
  • Adding a new collection or array field will result in an all existing entities having an empty collection or array for that field.
  • Adding a new non-nullable field will result in an exception being thrown when you attempt to load existing entities.
  • Deleting a field will not cause an error; existing entities will retain the old field until they are loaded and saved again.
  • Changing the type of a field will cause App Engine to attempt to cast old values to the new datatype; an exception will be thrown if the cast is invalid. An exception is numeric types; in this case the value is converted rather than cast, and overflows do not cause an exception.

If you need to do refactoring that can't be achieved with simple modifications as described above, you probably want to use the App Engine mapreduce library.

以歌曲疗慰 2024-09-17 17:42:01

我假设情况是这样的:

我有一个类“com.peter.Foo”,我一直使用JDO坚持使用,并且我想将其更改为“com.nick.Foo”,将我所有现有的Foo实体需要更新吗?换句话说,JDO 在将 java 类映射到数据存储 Kind 时是否使用包名称?

AFAIK,appengine 中的 JDO 工具仅使用类名。之所以这么说,是因为当我查看管理控制台时,数据查看器和数据存储统计信息仅通过类名称引用我的实体。因此,如果您保持类名相同并且仅更改包名称,那么您的实体应该没问题。

I am assuming the situation is like this:

I have a class "com.peter.Foo" that I've been persisting using JDO, and I want to change it to "com.nick.Foo", will all my existing Foo entities need to be updated? In other words, does JDO use the package names when mapping a java class to a datastore Kind?

AFAIK, the JDO tools in appengine only use the class name. Is say this because when I look in the Admin console, both the dataviewer and datastore stats refer to my entities only by the class name. Therefore, if you keep your class names the same and only change the package names, your entities should be fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文