01: /*
02: *
03: * The DbUnit Database Testing Framework
04: * Copyright (C)2002-2004, DbUnit.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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.slf4j.Logger;
25: import org.slf4j.LoggerFactory;
26:
27: import org.dbunit.dataset.ITable;
28: import org.dbunit.dataset.datatype.DataType;
29: import org.dbunit.dataset.datatype.TypeCastException;
30:
31: import java.sql.Connection;
32: import java.sql.SQLException;
33:
34: /**
35: * @author Manuel Laflamme
36: * @version $Revision: 554 $
37: * @since Mar 16, 2002
38: */
39: public class PreparedBatchStatement extends
40: AbstractPreparedBatchStatement {
41:
42: /**
43: * Logger for this class
44: */
45: private static final Logger logger = LoggerFactory
46: .getLogger(PreparedBatchStatement.class);
47:
48: private int _index;
49:
50: PreparedBatchStatement(String sql, Connection connection)
51: throws SQLException {
52: super (sql, connection);
53: _index = 0;
54: }
55:
56: ////////////////////////////////////////////////////////////////////////////
57: // IPreparedBatchStatement interface
58:
59: public void addValue(Object value, DataType dataType)
60: throws TypeCastException, SQLException {
61: logger.debug("addValue(value=" + value + ", dataType="
62: + dataType + ") - start");
63:
64: // Special NULL handling
65: if (value == null || value == ITable.NO_VALUE) {
66: _statement.setNull(++_index, dataType.getSqlType());
67: return;
68: }
69:
70: dataType.setSqlValue(value, ++_index, _statement);
71: }
72:
73: public void addBatch() throws SQLException {
74: logger.debug("addBatch() - start");
75:
76: _statement.addBatch();
77: _index = 0;
78: }
79:
80: public int executeBatch() throws SQLException {
81: logger.debug("executeBatch() - start");
82:
83: int[] results = _statement.executeBatch();
84: int result = 0;
85: for (int i = 0; i < results.length; i++) {
86: result += results[i];
87: }
88: return result;
89: }
90:
91: public void clearBatch() throws SQLException {
92: logger.debug("clearBatch() - start");
93:
94: // _statement.clearParameters();
95: _statement.clearBatch();
96: }
97: }
|