views:

44

answers:

2

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

+1  A: 

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.

Nick Johnson
I think the crux of the OP's question is more about what happens when you change the package of a class.
Peter Recore
Helpful information, but not what i was asking (:
corydoras
+1  A: 

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.

Peter Recore
Thanks. I will test it out and report back, in case other people have the same question.
corydoras
If the admin console shows only the class name, then you're correct: JDO only has that to operate on. Changing the package will not affect deserialization.
Nick Johnson