cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <mgen...@masslight.net>
Subject Re: Updating totals in a multi-user environment
Date Thu, 30 Oct 2014 17:21:03 GMT
Hi Mark,

In general I don't like storing data that is easily calculated from
the DB itself.  (Although I've made exceptions when it was
computationally expensive and impractical to do the calculation.)

Some options you could try:

* Fetch a fresh order and then: order.getPackages().size().
* Fetch fresh packages that match the order and size() them.
* Do a count(*) on the package count (this is the option I'd use,
because the first two are slower/wasteful).

If you need help on how to do a count(*), we can help you.  I have a
set of utilities that make that easier (works in 3.0.2, haven't tried
3.1 yet).

mrg



On Thu, Oct 30, 2014 at 12:09 PM, Mark Stobbe <markstobbe85@gmail.com> wrote:
> Hi Michael,
>
> I would like to display the count in a table for a whole bunch of orders.
> In theory I could use a "group by"-query to get the numbers I need and with
> proper configured indices this should be fairly quick, I guess.
>
> Is there a more transparent way of doing things, e.g. using lifecycle
> listeners, datachannel filters and such?
>
> Mark
>
> On Thu, Oct 30, 2014 at 4:15 PM, Michael Gentry <mgentry@masslight.net>
> wrote:
>
>> Hi Mark,
>>
>> Is there a performance reason why you don't just do a count on the
>> packages that match the order?
>>
>> mrg
>>
>>
>> On Thu, Oct 30, 2014 at 11:00 AM, Mark Stobbe <markstobbe85@gmail.com>
>> wrote:
>> > Hi all,
>> >
>> > I was wondering what is the best way to update totals in a multi-user
>> > environment. For example, let's say we have an Order which can have one
>> or
>> > more Packages associated and we want to maintain a total package count on
>> > the Order entity. How would you update this value when the user has the
>> > option to add/remove packages.
>> >
>> > So the entities looks like:
>> >
>> > *Order*
>> > --------
>> > id : bigint
>> > orderNumber : varchar
>> > nrOfPackages : int
>> >
>> > *Package*
>> > ------------
>> > id : bigint
>> > packageNumber : varchar
>> > *fk_order : bigint*
>> >
>> > What do you guys use to solve this?
>> > Mark
>>

Mime
View raw message