KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > jdbc > NonBatchingBatcher


1 //$Id: NonBatchingBatcher.java,v 1.5 2005/05/09 22:12:48 steveebersole Exp $
2
package org.hibernate.jdbc;
3
4 import java.sql.PreparedStatement JavaDoc;
5 import java.sql.SQLException JavaDoc;
6
7 import org.hibernate.HibernateException;
8 import org.hibernate.StaleStateException;
9
10 /**
11  * An implementation of the <tt>Batcher</tt> interface that does no batching
12  *
13  * @author Gavin King
14  */

15 public class NonBatchingBatcher extends AbstractBatcher {
16
17     public NonBatchingBatcher(ConnectionManager connectionManager) {
18         super( connectionManager );
19     }
20
21     public void addToBatch(int expectedRowCount) throws SQLException JavaDoc, HibernateException {
22         final int rowCount = getStatement().executeUpdate();
23         //negative expected row count means we don't know how many rows to expect
24
if ( expectedRowCount>0 ) {
25             if ( expectedRowCount<rowCount ) {
26                 throw new StaleStateException(
27                         "Unexpected row count: " + rowCount +
28                         " expected: " + expectedRowCount
29                 );
30             }
31             if ( expectedRowCount>rowCount ) {
32                 throw new HibernateException(
33                         "Unexpected row count: " + rowCount +
34                         " expected: " + expectedRowCount
35                 );
36             }
37         }
38     }
39
40     protected void doExecuteBatch(PreparedStatement JavaDoc ps) throws SQLException JavaDoc, HibernateException {
41     }
42
43 }
44
Popular Tags