Thanks, and back to enums

From: Todd O'Bryan (toddobrya..ac.com)
Date: Sun Apr 04 2004 - 22:35:33 EDT

  • Next message: Mike Kienenberger: "Re: Thanks, and back to enums"

    Big thank yous to everyone who answered my previous questions. I'm
    actually getting some code written, which feels good...

    Is there an easier way to get a unique object than getting a list, and
    getting the first item in it?

    In particular, I followed Todd Blanchard's advice to set up an enum as
    a table/class with an auto-generated PK and a value field.

    In particular, this is my Role object, and now to get a Role I have to
    do something like:

    DataContext dc; // is correctly set
    Role role = (Role) dc.performQuery(
            new SelectQuery(Role.class,
                    ExpressionFactory.matchExp("value", "admin"))).get(0);

    Should I create a static getRole(String value) method in the Role
    object? If so, should I pass in the DataContext, since I'm creating one
    per Tapestry Visit object (aka HttpSession, kinda) and don't want the
    overhead of making a bunch?

    Is there a shortcut for fetching objects based on what should be a
    unique key (like "admin" in this case, or a user's login)? That would
    be really nice. Something like

    dc.fetch(Role.class, "value", "admin") which returned the object would
    be cool.
    It could also throw an exception if the object wasn't unique.

    Or maybe someone's suggested something similar before and there are
    good reasons not to do it. Or maybe I'm missing something.

    Thanks,
    Todd



    This archive was generated by hypermail 2.0.0 : Sun Apr 04 2004 - 22:35:40 EDT