Enum best practices

From: Kevin Menard (kmenar..ervprise.com)
Date: Wed Jan 16 2008 - 10:43:32 EST

  • Next message: Michael Gentry: "Re: Enum best practices"

    Hi all,

    I'm looking at a problem that enums look like a good fit for, but I've never
    bothered with Cayenne's enum support. So, I'm looking for some help on best
    practices.

    What I have is an "orders" table that I would like to store an "eval_status"
    value to indicate whether the order is as an evaluation order and at what
    stage of the eval it is.

    Normally, I decompose everything and would have an "eval_status" table with
    various values and set up an FK constraint on an "eval_status_id" column on
    the "orders" table. I don't expect these values to change, but if they do,
    I'd like to be able to do a simple UPDATE statement on the one row.

    In my code, however, I think it would be really nice to be able to use
    expressions such as: if (EvalStatus.CONVERTED == order.getEvalStatus()). It
    seems that this would be much nicer than using a Cayenne DO for the
    comparison.

    Despite all of this, I don't want to be binding the data model too tightly
    to Java. In the past we've used Python to access the DB, so I'd like to
    support that as well as I can.

    The best way I've come up with is if the enum maps its values to the PKs of
    the entries in "eval_status" table. I think this would achieve what I'd
    like, with the downside that referential integrity may be compromised if I
    update one but not the other.

    Is this largely what others are doing? Or, do you just use VARCHAR columns
    and not worry about the normalization of the DB?

    Thanks,
    Kevin



    This archive was generated by hypermail 2.0.0 : Wed Jan 16 2008 - 10:44:07 EST