KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > database > statement > PreparedBatchStatement


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.database.statement;
23
24 import org.dbunit.dataset.ITable;
25 import org.dbunit.dataset.datatype.DataType;
26 import org.dbunit.dataset.datatype.TypeCastException;
27
28 import java.sql.Connection JavaDoc;
29 import java.sql.SQLException JavaDoc;
30
31 /**
32  * @author Manuel Laflamme
33  * @version $Revision: 1.13 $
34  * @since Mar 16, 2002
35 */

36 public class PreparedBatchStatement extends AbstractPreparedBatchStatement
37 {
38     private int _index;
39
40     PreparedBatchStatement(String JavaDoc sql, Connection JavaDoc connection)
41             throws SQLException JavaDoc
42     {
43         super(sql, connection);
44         _index = 0;
45     }
46
47     ////////////////////////////////////////////////////////////////////////////
48
// IPreparedBatchStatement interface
49

50     public void addValue(Object JavaDoc value, DataType dataType)
51             throws TypeCastException, SQLException JavaDoc
52     {
53         // Special NULL handling
54
if (value == null || value == ITable.NO_VALUE)
55         {
56             _statement.setNull(++_index, dataType.getSqlType());
57             return;
58         }
59
60         dataType.setSqlValue(value, ++_index, _statement);
61     }
62
63     public void addBatch() throws SQLException JavaDoc
64     {
65         _statement.addBatch();
66         _index = 0;
67     }
68
69     public int executeBatch() throws SQLException JavaDoc
70     {
71         int[] results = _statement.executeBatch();
72         int result = 0;
73         for (int i = 0; i < results.length; i++)
74         {
75             result += results[i];
76         }
77         return result;
78     }
79
80     public void clearBatch() throws SQLException JavaDoc
81     {
82 // _statement.clearParameters();
83
_statement.clearBatch();
84     }
85 }
86
87
88
89
90
91
92
93
Popular Tags