@@ -0,0 +1,3197 @@
+//%0A// $Id$%0A//%0A// Narya library - tools for developing networked games%0A// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved%0A// http://www.threerings.net/code/narya/%0A//%0A// This library is free software; you can redistribute it and/or modify it%0A// under the terms of the GNU Lesser General Public License as published%0A// by the Free Software Foundation; either version 2.1 of the License, or%0A// (at your option) any later version.%0A//%0A// This library is distributed in the hope that it will be useful,%0A// but WITHOUT ANY WARRANTY; without even the implied warranty of%0A// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A// Lesser General Public License for more details.%0A//%0A// You should have received a copy of the GNU Lesser General Public%0A// License along with this library; if not, write to the Free Software%0A// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA%0A%0Apackage com.threerings.presents.util;%0A%0Aimport com.samskivert.io.PersistenceException;%0Aimport com.samskivert.util.Invoker;%0A%0Aimport com.threerings.presents.Log;%0Aimport com.threerings.presents.client.InvocationService;%0Aimport com.threerings.presents.data.InvocationCodes;%0A%0A/**%0A * Simplifies a common pattern which is to post an %7B@link Invoker%7D unit which%0A * does some database operation and then calls back to an %7B@link%0A * InvocationService.InvocationListener%7D of some sort. If the database operation%0A * fails, the error will be logged and the result listener will be replied to%0A * with %7B@link InvocationCodes#INTERNAL_ERROR%7D.%0A */%0Apublic abstract class PersistingUnit extends Invoker.Unit%0A%7B%0A    public PersistingUnit (InvocationService.InvocationListener listener)%0A    %7B%0A        _listener = listener;%0A    %7D%0A%0A    /**%0A     * This method is where the unit performs its persistent actions. Any%0A     * persistence exception will be caught and logged along with the output%0A     * from %7B@link #getFailureMessage%7D, if any.%0A     */%0A    public abstract void invokePersistent ()%0A        throws PersistenceException;%0A%0A    /**%0A     * Handles the success case, which by default is to do nothing.%0A     */%0A    public void handleSuccess ()%0A    %7B%0A    %7D%0A%0A    /**%0A     * Handles the failure case by logging the error and reporting an internal%0A     * error to the listener.%0A     */%0A    public void handleFailure (PersistenceException error)%0A    %7B%0A        Log.warning(getFailureMessage());%0A        Log.logStackTrace(error);%0A        _listener.requestFailed(InvocationCodes.INTERNAL_ERROR);%0A    %7D%0A%0A    /**%0A     * Provides a custom failure message in the event that the persistent%0A     * action fails. This will be logged along with the exception.%0A     */%0A    public String getFailureMessage ()%0A    %7B%0A        return this + %22 failed.%22;%0A    %7D%0A%0A    public boolean invoke ()%0A    %7B%0A        try %7B%0A            invokePersistent();%0A        %7D catch (PersistenceException pe) %7B%0A            _error = pe;%0A        %7D%0A        return true;%0A    %7D%0A%0A    public void handleResult ()%0A    %7B%0A        if (_error != null) %7B%0A            handleFailure(_error);%0A        %7D else %7B%0A            handleSuccess();%0A        %7D%0A    %7D%0A%0A    protected InvocationService.InvocationListener _listener;%0A    protected PersistenceException _error;%0A%7D%0A

Codified a common pattern into a helper class.