0

I have a Repository, LocalDataSource, ContentProvider and Sqlite Database like in this architecture : https://github.com/googlesamples/android-architecture/tree/todo-mvp-contentproviders/

Objects have identifiers values (not necessary int type, herited from reading an API). Some objects have a combinaison of multiple values as identifier.

What is the best implementation in terms of readability, maintenability ? (I have no problem of data integrity)

Choice 1 :

  • Database has a (local) id primary key autoincrement
  • Content provider use this id during insert (with check if already exist), update and delete operations
  • Repository and LocalDataSource implements the logic of identifiers values

In this choice, the complexity is on repository.

Choice 2 :

  • Database have the real id of data as primary key (and sometimes foreign key).
  • Content provider use the real id of data during insert (with check if already exist), update and delete operations.
  • Repository and LocalDataSource implements a simple logic of insert, update delete.

In this choice, the complexity is on content provider.

compte14031879
  • 1,531
  • 14
  • 27
  • The choice 2 involves the use of string as primary key. For some people, use a string as primary key is a bad practice : http://stackoverflow.com/questions/23157411/using-text-as-a-primary-key-in-sqlite-table-bad And for others, it's ok, especially when it's an UUID/GUID : http://stackoverflow.com/questions/17277735/using-uuids-in-sqlite I am confused... – compte14031879 Oct 25 '16 at 09:57
  • An beginning of answer about the performance : http://stackoverflow.com/questions/14184861/android-use-uuid-as-primary-key-in-sqlite – compte14031879 Oct 25 '16 at 10:06

0 Answers0