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
23 import org.dbunit.database.DatabaseConfig;
24 import org.dbunit.database.IDatabaseConnection;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29 * Listener for {@link IDatabaseConnection} events.
30 * @author gommma (gommma AT users.sourceforge.net)
31 * @author Last changed by: $Author$
32 * @version $Revision$ $Date$
33 * @since 2.4.4
34 */
35 public interface IOperationListener {
36
37 /**
38 * Is invoked immediately after a connection was newly created or an existing
39 * connection is retrieved to do some work on it. It should be used to initialize the
40 * {@link DatabaseConfig} of the connection with user defined parameters.
41 * @param connection The database connection
42 * @since 2.4.4
43 */
44 public void connectionRetrieved(IDatabaseConnection connection);
45 /**
46 * Notification of the completion of the {@link IDatabaseTester#onSetup()} method.
47 * Should close the given connection if desired.
48 * @param connection The database connection
49 * @since 2.4.4
50 */
51 public void operationSetUpFinished(IDatabaseConnection connection);
52 /**
53 * Notification of the completion of the {@link IDatabaseTester#onTearDown()} method
54 * Should close the given connection if desired.
55 * @param connection The database connection
56 * @since 2.4.4
57 */
58 public void operationTearDownFinished(IDatabaseConnection connection);
59
60
61
62 /**
63 * Simple implementation of the {@link IOperationListener} that does <b>not</b> close
64 * the database connection after setUp and tearDown.
65 * Can be used via {@link IDatabaseTester#setOperationListener(IOperationListener)} to avoid that connections are closed.
66 * @since 2.4.5
67 */
68 public static final IOperationListener NO_OP_OPERATION_LISTENER = new IOperationListener()
69 {
70 private final Logger logger = LoggerFactory.getLogger(IDatabaseTester.class);
71
72 public void connectionRetrieved(IDatabaseConnection connection) {
73 logger.trace("connectionCreated(connection={}) - start", connection);
74 }
75 public void operationSetUpFinished(IDatabaseConnection connection) {
76 logger.trace("operationSetUpDone(connection={}) - start", connection);
77 }
78 public void operationTearDownFinished(IDatabaseConnection connection) {
79 logger.trace("operationTearDownDone(connection={}) - start", connection);
80 }
81 };
82
83 }