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
22 package org.dbunit.operation;
23
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 import org.dbunit.DatabaseUnitException;
28 import org.dbunit.database.IDatabaseConnection;
29 import org.dbunit.dataset.IDataSet;
30
31 import java.sql.SQLException;
32 import java.util.Arrays;
33
34 /**
35 * This class is a composite that combines multiple database operation in a
36 * single one.
37 *
38 * @author Manuel Laflamme
39 * @version $Revision$
40 * @since Feb 18, 2002
41 */
42 public class CompositeOperation extends DatabaseOperation
43 {
44
45 /**
46 * Logger for this class
47 */
48 private static final Logger logger = LoggerFactory.getLogger(CompositeOperation.class);
49
50 private final DatabaseOperation[] _actions;
51
52 /**
53 * Creates a new composite operation combining the two specified operations.
54 */
55 public CompositeOperation(DatabaseOperation action1, DatabaseOperation action2)
56 {
57 _actions = new DatabaseOperation[]{action1, action2};
58 }
59
60 /**
61 * Creates a new composite operation combining the specified operations.
62 */
63 public CompositeOperation(DatabaseOperation[] actions)
64 {
65 _actions = actions;
66 }
67
68 ////////////////////////////////////////////////////////////////////////////
69 // DatabaseOperation class
70
71 public void execute(IDatabaseConnection connection, IDataSet dataSet)
72 throws DatabaseUnitException, SQLException
73 {
74 logger.debug("execute(connection={}, , dataSet={}) - start", connection, dataSet);
75
76 for (int i = 0; i < _actions.length; i++)
77 {
78 DatabaseOperation action = _actions[i];
79 action.execute(connection, dataSet);
80 }
81 }
82
83 public String toString()
84 {
85 final StringBuilder sb = new StringBuilder();
86 sb.append(getClass().getName()).append("[");
87 sb.append("_actions=").append(this._actions==null ? "null" : Arrays.asList(this._actions).toString());
88 sb.append("]");
89 return sb.toString();
90 }
91 }
92
93
94
95
96