// // Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License // as published by the Free Software Foundation; either version 2.1 of // the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // $Id: ThreadedMessage.pdl 287 2005-02-22 00:29:02Z sskracic $ // $DateTime: 2004/08/16 18:10:38 $ model com.arsdigita.messaging; object type ThreadedMessage extends Message { BigDecimal[0..1] root = messages.root_id INTEGER; String[0..1] sortKey = messages.sort_key VARCHAR(300); insert { do { update messages set root_id = :root, sort_key = :sortKey where message_id = :id } } } // Used for sort key generation when we need to lookup the current // maximum. The only way to use this right now is to execute the // query and select the first element. This should always be used in // conjunction with a filter that limits the number of sort_keys // selected, and therefore should execute reasonably fast. query maxSortKey { BigDecimal root; BigDecimal inReplyTo; String sortKey; BigDecimal sortSize; do { select root_id, sort_key, in_reply_to, length(sort_key) as sort_size from messages order by sort_key desc } map { root = root_id; inReplyTo = in_reply_to; sortKey = sort_key; sortSize = sort_size; } }