3

I'm considering to use db4o in my android project to store objects but my concern is if in the future I want to change one of the objects attributes how do i deal with the existing data of that object in the db4o file? I know in sqlite3 environment this can be done by altering the table structure in the onUpgrade() method, so how does db4o deal with this?

AdamSharp
  • 55
  • 3

1 Answers1

2

in db4o it really depends on what the changes are.

  • Adding field: You just add it. The new field will have the default value of that type. (null for references, 0 for numbers)
  • Removing a field: db4o will just ignore the removed field. You can access the old data of the removed field. As soon as you update the object the value of the old field will be removed.
  • Renaming fields and classes can be done with this call.
  • Changing the type of a field. That's like adding a new field. You need to copy the values over yourself. See here.
  • Adding interfaces has no effect on db4o.
  • Removing a type from the inheritance hirarchy: Not supported.

In general, take a look here.

Gamlor
  • 12,978
  • 7
  • 43
  • 70
  • 1
    "Removing a type from the inheritance hirarchy: Not supported." Yes, not supported by db4o itself. One way to get around this is to dump the old database using something like xstream and write a custom migration script to read the dumped objects into a new database. If you don't have many stored types, this can be a quick fix. – Sam Stainsby Jun 22 '11 at 05:07
  • @Sam Stainsby: Good tip. Yes it's not supported, you have to work around the limitation. – Gamlor Jun 22 '11 at 06:54
  • The changes mentioned by Gamlor will take effect automatically as long as you make sure that your refactored classes are using the same fully qualified name and that your app package declared in the manifest is the same (this last one is important if you stored the db4o db in the data directory of the app) – German Jun 22 '11 at 09:18