//
// $Id$
//
// samskivert library - useful routines for java programs
// Copyright (C) 2001-2007 Michael Bayne
// 
// 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

package com.samskivert.jdbc;

import com.samskivert.io.PersistenceException;
import com.samskivert.util.Invoker;

/**
 * Extends the {@link com.samskivert.util.Invoker.Unit} and specializes it for doing database
 * repository manipulation.
 */
public abstract class RepositoryUnit extends Invoker.Unit
{
    /** The default constructor. */
    public RepositoryUnit ()
    {
    }

    /**
     * Create a RepositoryUnit which will report the supplied name in {@link #toString}.
     */
    public RepositoryUnit (String name)
    {
        super(name);
    }

    // from abstract Invoker.Unit
    public boolean invoke ()
    {
        try {
            invokePersist();
        } catch (Exception pe) {
            _error = pe;
        }
        return true;
    }

    @Override // from Invoker.Unit
    public void handleResult ()
    {
        if (_error != null) {
            handleFailure(_error);
        } else {
            handleSuccess();
        }
    }

    /**
     * Called to perform our persistent actions.
     */
    public abstract void invokePersist ()
        throws Exception;

    /**
     * Called if our persistent actions have succeeded, back on the non-invoker thread.
     */
    public abstract void handleSuccess ();

    /**
     * Called if our persistent actions failed, back on the non-invoker thread.  Note that this may
     * be either an {@link Exception} thrown by {@link #invokePersist} or a {@link
     * RuntimeException} thrown by same.
     */
    public abstract void handleFailure (Exception pe);

    protected Exception _error;
}

@@ -875,16 +875,76 @@
 .jdbc;%0A%0A
+import java.util.logging.Level;%0A%0Aimport com.samskivert.Log;%0A
 import c
@@ -2388,16 +2388,91 @@
 by same.
+ The default implementation logs an error message and a%0A     * stack trace.
 %0A     */
@@ -2479,33 +2479,24 @@
 %0A    public 
-abstract 
 void handleF
@@ -2516,17 +2516,287 @@
 tion pe)
-;
+%0A    %7B%0A        Log.log.log(Level.WARNING, getFailureMessage(), pe);%0A    %7D%0A%0A    /**%0A     * Returns the error message to be logged if %7B@link #invokePersist%7D throws an exception.%0A     */%0A    protected String getFailureMessage ()%0A    %7B%0A        return this + %22 failed.%22;%0A    %7D
 %0A%0A    pr

Add a default handleFailure() implementation like PersistingUnit.