DatabaseOperation.java

  1. /*
  2.  *
  3.  * The DbUnit Database Testing Framework
  4.  * Copyright (C)2002-2004, DbUnit.org
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Lesser General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2.1 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Lesser General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Lesser General Public
  17.  * License along with this library; if not, write to the Free Software
  18.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  *
  20.  */

  21. package org.dbunit.operation;

  22. import org.dbunit.DatabaseUnitException;
  23. import org.dbunit.database.IDatabaseConnection;
  24. import org.dbunit.dataset.IDataSet;

  25. import java.sql.SQLException;

  26. /**
  27.  * Defines the interface contract for operations performed on the database.
  28.  *
  29.  * @author Manuel Laflamme
  30.  * @version $Revision$
  31.  * @since Feb 18, 2002
  32.  */
  33. public abstract class DatabaseOperation
  34. {
  35.     /** @see DummyOperation */
  36.     public static final DatabaseOperation NONE = new DummyOperation();
  37.     /** @see UpdateOperation */
  38.     public static final DatabaseOperation UPDATE = new UpdateOperation();
  39.     /** @see InsertOperation */
  40.     public static final DatabaseOperation INSERT = new InsertOperation();
  41.     /** @see RefreshOperation */
  42.     public static final DatabaseOperation REFRESH = new RefreshOperation();
  43.     /** @see DeleteOperation */
  44.     public static final DatabaseOperation DELETE = new DeleteOperation();
  45.     /** @see DeleteAllOperation */
  46.     public static final DatabaseOperation DELETE_ALL = new DeleteAllOperation();
  47.     /** @see TruncateTableOperation */
  48.     public static final DatabaseOperation TRUNCATE_TABLE = new TruncateTableOperation();
  49.     /**
  50.      * @see DeleteAllOperation
  51.      * @see InsertOperation
  52.      * @see CompositeOperation
  53.      */
  54.     public static final DatabaseOperation CLEAN_INSERT = new CompositeOperation(
  55.             DELETE_ALL, INSERT);

  56.     /** @see TransactionOperation */
  57.     public static final DatabaseOperation TRANSACTION(DatabaseOperation operation) {
  58.         return new TransactionOperation(operation);
  59.     }

  60.     /** @see CloseConnectionOperation */
  61.     public static final DatabaseOperation CLOSE_CONNECTION(DatabaseOperation operation) {
  62.         return new CloseConnectionOperation(operation);
  63.     }

  64.     /**
  65.      * Executes this operation on the specified database using the specified
  66.      * dataset contents.
  67.      *
  68.      * @param connection the database connection.
  69.      * @param dataSet the dataset to be used by this operation.
  70.      */
  71.     public abstract void execute(IDatabaseConnection connection,
  72.             IDataSet dataSet) throws DatabaseUnitException, SQLException;

  73.     private static class DummyOperation extends DatabaseOperation
  74.     {
  75.         @Override
  76.         public void execute(IDatabaseConnection connection, IDataSet dataSet)
  77.         {
  78.         }
  79.     }
  80. }