android - How to map Enum in GreenDAO -


i've started using greendao. how add enum property?

what i've thought of: using addindex property of entity.

private static void main() {      // todo auto-generated method stub     static schema blah;     entity unicorn = blah.addentity("weather");     unicorn.addidproperty();     unicorn.addintproperty("currentairtemp");     unicorn.addindex("shirtsize"); } 

is right way it?

aim: want have reference shirtsize being set: {xs, s, m, l, xl, xxl}

as far know, enums not supported greendao due unstable nature. error-prone component add database logic, since values of enum elements can change.

one option around add int property database , map enum ordinal values field, so:

// add int property entity unicorn.addintproperty("shirtsize");  // create enum static values public enum shirtsize {     xs(1), s(2), m(3), l(4), xl(5), xxl(6);      private final int value;      private shirtsize(int value) {         this.value = value;     }      public int value() {         return value;     } }  // set ordinal value of enum weather.setshirtsize(shirtsize.xl.value()); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -