-1

i developed a small java.lang.reflect.InvocationHandler that intercepts method calls (from a json webservice) and cache the results to a local SQLite db. if there is no internet connection results are read from local cache.

everything works fine; my problem is the following:

every method intercepted can return a different entity, and i save using reflection each entity on a different table. i don't know in advance all the tables i need to create, so every time i create a SQLiteOpenHelper that "create table if not exists {ENTITY_NAME}", and every time i increase the database version by 1 so the method onUpgrade is called.

this works on development environment but i don't like that at all.

someone can recommend a better solution to update the database with new tables?

thank you

Alessandro
  • 303
  • 4
  • 12
  • 1
    can you serialize your entities to a string? that way you can have one table with a type column and the data serialized. – Ran Jul 06 '12 at 15:54
  • i can do but i want to save the single entities and not the full method result, so if i call service.getAllEmployees() with internet connection the objects are cached, and then service.getEmployeeById("1") offline i can read the object from cache. – Alessandro Jul 06 '12 at 16:05

1 Answers1

0

Try mYourDbHelper.getWritableDatabase().execSQL("CREATE TABLE ....") from where you need to create another table

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158