Re: Computed Attributes

From: Joshua Pyle (joshua.t.pyl..mail.com)
Date: Thu Feb 16 2006 - 12:57:13 EST

  • Next message: Joshua Pyle: "Re: Computed Attributes"

    Maybe I'm over simplifying but if I need an attribute on a cayenne
    object I just create the appropriate getter and perform whatever calcs
    needed in that getter. In the example I provide I'm just formatting a
    date but I could also run another query loop through the results and
    spit out a sum. I could even execute a SQLTemplate query.

    public class User extends _User{
        public String getEntryDateString{
            Date toFormat = this.getEntryDate();
            if( toFormat == null ){
                return "";
            }else{
                return Util.SIMPLE_DATE.format( toFormat );
            }
        }

        public Double getComplexThingy{
            Double toReturn = new Double(0.0);
            // TODO loop through a List of object and perform a complex calculation
            return toReturn;
        }
    }

    I have yet to find a situation where this does not cover even my most
    unusually needs.

    Joshua T. Pyle

    On 2/16/06, Jürgen Saar <Juerge..saar.org> wrote:
    > I discussed this some time ago ...
    >
    > For my point of view it would be helpful having ObjAttributes
    > with no DbAttribute. As far as I know, this is handled by cayenne,
    > like in WebObject, with getters in the BusinessObject.
    > For abstract access types, like jxpath, this is OK, but
    > if a new member enters the team, it would be helpful to
    > have all Business-Attributes shown in the data-modeler.
    > Even tools like ant, could easier do their job controlled
    > by the repository.
    >
    > To have that kind of transient attributes would help me a lot.
    >
    >
    > ---Juergen---
    >
    > 2006/2/15, Bruce Alspaugh <compulinklt..mail.com>:
    > >
    > > I would like to be able to add a computed field to my displays that would be
    > > based on the other attributes in that table row. For example, a line total
    > > that is the item price times the item count plus the tax and shipping for
    > > that item. I'm probably making this way too complicated.
    > >
    > > When I use the DVModeler, I noticed that my only options are "nocalc" and
    > > "lookup." It would be handy to have a "calc" option for computed fields
    > > where I could put the formula in. I suppose I could use Cayenne Modeler to
    > > generate the base Java classes, and then add the attribute to the derived
    > > class. The problem is that since it was added by hand, the computed field
    > > is not in the XML generated by the Modeler, which means it won't be picked
    > > up by the DVModeler and I can't add it to a DataView.
    > >
    > > If I could add a user-defined ObjAttribute in the Modeler, it could generate
    > > a "stub" for it when I generate Java classes that I could fill in by hand. I
    > > could then add formatting, caption, etc. in DVModeler.
    > >
    > > What is the recommended way to handle this?
    > >
    > > Bruce
    >
    > __________________________________________________________________________
    > Erweitern Sie FreeMail zu einem noch leistungsstarkeren E-Mail-Postfach!
    > Mehr Infos unter http://freemail.web.de/home/landingpad/?mc=021131
    >
    >

    --
    Joshua T. Pyle
    Go has always existed.
    



    This archive was generated by hypermail 2.0.0 : Thu Feb 16 2006 - 12:57:15 EST