IOperationListener.java

  1. /*
  2.  *
  3.  * The DbUnit Database Testing Framework
  4.  * Copyright (C)2002-2009, 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;

  22. import org.dbunit.database.DatabaseConfig;
  23. import org.dbunit.database.IDatabaseConnection;
  24. import org.slf4j.Logger;
  25. import org.slf4j.LoggerFactory;

  26. /**
  27.  * Listener for {@link IDatabaseConnection} events.
  28.  * @author gommma (gommma AT users.sourceforge.net)
  29.  * @author Last changed by: $Author$
  30.  * @version $Revision$ $Date$
  31.  * @since 2.4.4
  32.  */
  33. public interface IOperationListener {

  34.     /**
  35.      * Is invoked immediately after a connection was newly created or an existing
  36.      * connection is retrieved to do some work on it. It should be used to initialize the
  37.      * {@link DatabaseConfig} of the connection with user defined parameters.
  38.      * @param connection The database connection
  39.      * @since 2.4.4
  40.      */
  41.     public void connectionRetrieved(IDatabaseConnection connection);
  42.     /**
  43.      * Notification of the completion of the {@link IDatabaseTester#onSetup()} method.
  44.      * Should close the given connection if desired.
  45.      * @param connection The database connection
  46.      * @since 2.4.4
  47.      */
  48.     public void operationSetUpFinished(IDatabaseConnection connection);
  49.     /**
  50.      * Notification of the completion of the {@link IDatabaseTester#onTearDown()} method
  51.      * Should close the given connection if desired.
  52.      * @param connection The database connection
  53.      * @since 2.4.4
  54.      */
  55.     public void operationTearDownFinished(IDatabaseConnection connection);

  56.    
  57.    
  58.     /**
  59.      * Simple implementation of the {@link IOperationListener} that does <b>not</b> close
  60.      * the database connection after setUp and tearDown.
  61.      * Can be used via {@link IDatabaseTester#setOperationListener(IOperationListener)} to avoid that connections are closed.
  62.      * @since 2.4.5
  63.      */
  64.     public static final IOperationListener NO_OP_OPERATION_LISTENER = new IOperationListener()
  65.     {
  66.         private final Logger logger = LoggerFactory.getLogger(IDatabaseTester.class);
  67.        
  68.         public void connectionRetrieved(IDatabaseConnection connection) {
  69.             logger.trace("connectionCreated(connection={}) - start", connection);
  70.         }
  71.         public void operationSetUpFinished(IDatabaseConnection connection) {
  72.             logger.trace("operationSetUpDone(connection={}) - start", connection);
  73.         }
  74.         public void operationTearDownFinished(IDatabaseConnection connection) {
  75.             logger.trace("operationTearDownDone(connection={}) - start", connection);
  76.         }
  77.     };

  78. }