Android - GreenDao create/use entity and Dao class for existing sqlite database. Use greenDao with existing db

1.3k views Asked by At

I have an existing sqlite db schema (about 30 table) which I have to import into my Android project. I'd like to use greenDao in my code but I don't know how it's possible if I have already sqlite db created. Is it possible to work with greenDao even if I haven't my pojo/entity class generated by greenDao Generator? Could I generate them manually? I think I need also DaoMaster and DaoSession!??!

Thank you very much.

1

There are 1 answers

1
Jofre Mateu On

I've never done it, but theoretically, yes you can.

From greenDao FAQ page:

Can I use existing entity classes? Can I skip entity generation? Yes. In your generator project, call setSkipGeneration(true) on entities you do not want to generate. Like this, you have the most possible control over your entities at the cost of manual maintenance. However, this is considered advanced usage and should be reserved for special cases only: the recommended way is to generate entities and use “keep sections” to inject custom code into them. If you choose to skip entity generation, you must either provide a constructor with all property fields in the order they were added in the generator project. Or alternatively, call setConstructors(false) on entities to make greenDAO use setters instead of the constructor to create entities.

I understand that you have to implement the generator project normally but skype de generation of the entities. This should generate the DaoMaster and DaoSession only.