1

I am working on a project in which I have a singleton class which hold most frequently used objects. Now I want to create a DB using any good ORM library.

Is it possible?

If I update or delete an object in singleton, it should also update or delete in DB respectively, without writing any query or calling any ORM library method explicitly. Which ORM library support this feature? if possible please provide any tutorial link

If this is not possible, does that mean I have to update object in singleton and DB separately each time, which feels kind of bad practice.

  • Would any little update to an object trigger persistence or you also want some transactional semantics whereby an app specified consistent set of (delete, update, insert) operations are reflected in the database together? If later, you would perhaps need some additional call to signal persistence. – Damodar Periwal Apr 16 '16 at 22:25

2 Answers2

1

Try Realm, it's capable of what you want to achieve. https://realm.io/docs/java/latest/

filipproch
  • 725
  • 6
  • 15
  • Thanks @jacktech24, Realm is close to what I need. but it is still in beta –  Apr 16 '16 at 09:08
  • Yes in beta but already used in production by large companies and I am using it too for more than half a year with no problems – filipproch Apr 16 '16 at 09:10
  • Realm is not just a library like ORMLite or GrrenDAO, it is a complete solution which create its own DB file. I am little concerned about that because I haven't used it before and don't know about its pros & cons and performance –  Apr 16 '16 at 09:13
  • Performance is slightly better and storage space used is less than sqlite. You can read comparison with sqlite solutions on the Internet. From my real usages, it was much better at handling migrations and absolute best at propagation of changes and memory usage (it does lazy loading), and can be most of the time used on UI thread for read operations as its blazingly fast – filipproch Apr 16 '16 at 09:28
  • From SQLite orm frameworks, I was using DBFlow but the notification / propagation of changes isn't that easy and good – filipproch Apr 16 '16 at 09:29
  • worst draw back of realm is, user have to close all realm reference, otherwise app can crash unexpectedly. It does not clear memory like garbage collector –  Sep 01 '16 at 11:50
  • http://stackoverflow.com/questions/33384913/unrecoverable-error-mremap-failed-out-of-memory-in-io-realm-internal-shared –  Sep 01 '16 at 11:56
  • I don't think that's a problem, if you write your app right there is no additional overhead, it all depends on how much you are aware of what you are doing and how it behaves, we use realm in production on all apps without any problems and we estimated it saved us a lot of time – filipproch Sep 02 '16 at 18:42
0

It can be done using Android's Room Persistence Library in conjunction with Architecture Components.