开发者

Refactoring packages containing JDO @PersistenceCapable classes in Google App Engine

开发者 https://www.devze.com 2023-01-07 20:23 出处:网络
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

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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号