I am reluctant to add a standard option for persisting of what can be considered a custom class. But I am not sure why this is even needed? You can code your enums as Java enums with custom properties, and do not use Cayenne-provided EnumExtendedType, installing your own instead. E.g.:

public enum Color {

    BLACK("000000"), WHITE("FFFFFF");

    private final String dbCode;

    private Color(String dbCode) {
        this.dbCode = dbCode;
    }

    public String getDbCode() {
        return dbCode;
    }
}

public class ColorType implements ExtendedType {

    public String getClassName() {
        return Color.class.getName();
    }

    public void setJdbcObject(
            PreparedStatement statement,
            Object value,
            int pos,
            int type,
            int precision) throws Exception {

        if (value instanceof MyEnumType) {

            Color e = (Color) value;
            statement.setString(pos, e.getDbCode());
        }
        else {
            statement.setNull(pos, type);
        }
    }
    ....
}





On Aug 9, 2007, at 1:42 PM, Michael Gentry wrote:

Uhm ... that's why I wanted it in the modeler and supported by Cayenne
natively.  (Or easier to support, even if not in the modeler.)

:-)

I'm positive this feature would be useful to others.  My current
approach is complicated to set up and easy to miss registering one of
your types (although you blow up quickly enough) or an actual
enumerated value (which is harder to catch).  If it could be
simplified, it could be much more useful to everyone.

Thanks,

/dev/mrg


On 8/9/07, Andrus Adamchik <[EMAIL PROTECTED]> wrote:
I see what you are saying. I guess for your case you can keep using
custom ExtendedType (only based on JDK 1.5 enums).

Andrus


Reply via email to