KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > operation > TruncateTableOperation


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.dbunit.DatabaseUnitException;
25 import org.dbunit.database.DatabaseConfig;
26 import org.dbunit.database.IDatabaseConnection;
27 import org.dbunit.dataset.IDataSet;
28
29 import java.sql.SQLException JavaDoc;
30
31 /**
32  * Truncate tables present in the specified dataset. If the dataset does not
33  * contains a particular table, but that table exists in the database,
34  * the database table is not affected. Table are truncated in
35  * reverse sequence.
36  * <p>
37  * This operation has the same effect of as {@link DeleteAllOperation}.
38  * TruncateTableOperation is faster, and it is non-logged, meaning it cannot be
39  * rollback. DeleteAllOperation is more portable because not all database vendor
40  * support TRUNCATE_TABLE TABLE statement.
41  *
42  * @author Manuel Laflamme
43  * @since Apr 10, 2003
44  * @version $Revision: 1.3 $
45  * @see DeleteAllOperation
46  */

47 public class TruncateTableOperation extends DeleteAllOperation
48 {
49     TruncateTableOperation()
50     {
51     }
52
53     ////////////////////////////////////////////////////////////////////////////
54
// DeleteAllOperation class
55

56     protected String JavaDoc getDeleteAllCommand()
57     {
58         return "truncate table ";
59     }
60
61     ////////////////////////////////////////////////////////////////////////////
62
// DatabaseOperation class
63

64     public void execute(IDatabaseConnection connection, IDataSet dataSet)
65             throws DatabaseUnitException, SQLException JavaDoc
66     {
67         // Patch to make it work with MS SQL Server
68
DatabaseConfig config = connection.getConfig();
69         boolean oldValue = config.getFeature(DatabaseConfig.FEATURE_BATCHED_STATEMENTS);
70         try
71         {
72             config.setFeature(DatabaseConfig.FEATURE_BATCHED_STATEMENTS, false);
73             super.execute(connection, dataSet);
74         }
75         finally
76         {
77             config.setFeature(DatabaseConfig.FEATURE_BATCHED_STATEMENTS, oldValue);
78         }
79     }
80 }
81
82
83
84
85
86
87
88
Popular Tags