3

I am using GreenDao in my Android project and i have generated my database schema successfully but I am stuck on one issue. My generated class needs to implement an interface that is not related to db. In the generator I have used the following method:

myEntity.implementsInterface("com.my.app.myinterface");

and then after generation the class has an implementation annotation of this interface in its header but there are no Override methods in the code of course. I tried putting a package with my interface in the generator project but still, methods are never there automatically. Shall I insert them manually within the

// KEEP METHODS - put your custom methods here ... // KEEP METHODS END

section?

1 Answers1

0

According GreenDAO documentation, you don't need to write any method because the classes are overriden on each run (that means each change you do will be erased), if you need an own behaviour you can use Keep Sections :

Keep sections

Entity classes are overwritten on each generator run. To allow adding custom code to your enities, greenDAO has “keep” sections. To enable them, use enableKeepSectionsByDefault() on the schema, or setHasKeepSections(true) on selected entities. Once enabled, three keep sections are generated in the entities:

// KEEP INCLUDES - put your custom includes here
// KEEP INCLUDES END
...
// KEEP FIELDS - put your custom fields here
// KEEP FIELDS END
...
// KEEP METHODS - put your custom methods here
// KEEP METHODS END

Now, you can put your custom code between KEEP […] and KEEP […] END. And don’t touch the KEEP comments. Code inside the keep section is kept during code generation. It’s a good idea to backup or commit your code in case something goes wrong unexpectedly.

Also take a look to this related question.

Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109