greenrobot/greenDAO — pull request #65 by emmby (2012-12-24 02:18:18+00:00)
Title: Add the ability to generate getters that accept a default value to retur...

...n in the case where the underlying db value is null.

Sometimes it can be clumsy to check for null values when using entity objects. GreenDAO provides a way to assert that some entity fields are non-null, but in the cases where we cannot guarantee that a field is non-null, it can be clumsy and verbose to have to check for null before using a field.

This pull request provides an optional getter method for every getter that will return a specified defaultValue if the underlying value is null. This additional method is only generated if Schema.enableDefaultValueGetters is explicitly set to true (it defaults to false).

So for example, if you have a Person entity that has an "isRobot" boolean field, you could call '''isRobot(false)''' to get the value of the isRobot field, but return false if there is no value in the database. This is different than using the generated isRobot() field, which would return null and result in a NullPointerException if you tried to use it without proper null checks.

This feature is disabled by default and only enabled for users who want it.