KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: Batcher.java,v 1.7 2005/05/09 22:12:48 steveebersole Exp $
2
package org.hibernate.jdbc;
3
4 import java.sql.CallableStatement JavaDoc;
5 import java.sql.Connection JavaDoc;
6 import java.sql.PreparedStatement JavaDoc;
7 import java.sql.ResultSet JavaDoc;
8 import java.sql.SQLException JavaDoc;
9
10 import org.hibernate.HibernateException;
11 import org.hibernate.ScrollMode;
12 import org.hibernate.dialect.Dialect;
13
14 /**
15  * Manages <tt>PreparedStatement</tt>s for a session. Abstracts JDBC
16  * batching to maintain the illusion that a single logical batch
17  * exists for the whole session, even when batching is disabled.
18  * Provides transparent <tt>PreparedStatement</tt> caching.
19  *
20  * @see java.sql.PreparedStatement
21  * @see org.hibernate.impl.SessionImpl
22  * @author Gavin King
23  */

24 public interface Batcher {
25     /**
26      * Get a prepared statement for use in loading / querying. If not explicitly
27      * released by <tt>closeQueryStatement()</tt>, it will be released when the
28      * session is closed or disconnected.
29      */

30     public PreparedStatement JavaDoc prepareQueryStatement(String JavaDoc sql, boolean scrollable, ScrollMode scrollMode) throws SQLException JavaDoc, HibernateException;
31     /**
32      * Close a prepared statement opened with <tt>prepareQueryStatement()</tt>
33      */

34     public void closeQueryStatement(PreparedStatement JavaDoc ps, ResultSet JavaDoc rs) throws SQLException JavaDoc;
35     /**
36      * Get a prepared statement for use in loading / querying. If not explicitly
37      * released by <tt>closeQueryStatement()</tt>, it will be released when the
38      * session is closed or disconnected.
39      */

40     public CallableStatement JavaDoc prepareCallableQueryStatement(String JavaDoc sql, boolean scrollable, ScrollMode scrollMode) throws SQLException JavaDoc, HibernateException;
41     
42     
43     /**
44      * Get a non-batchable prepared statement to use for selecting. Does not
45      * result in execution of the current batch.
46      */

47     public PreparedStatement JavaDoc prepareSelectStatement(String JavaDoc sql) throws SQLException JavaDoc, HibernateException;
48
49     /**
50      * Get a non-batchable prepared statement to use for inserting / deleting / updating.
51      * Must be explicitly released by <tt>closeStatement()</tt>
52      */

53     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, boolean useGetGeneratedKeys) throws SQLException JavaDoc, HibernateException;
54     /**
55      * Get a non-batchable prepared statement to use for inserting / deleting / updating.
56      * Must be explicitly released by <tt>closeStatement()</tt>
57      */

58     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql) throws SQLException JavaDoc, HibernateException;
59
60     /**
61      * Get a non-batchable callable statement to use for inserting / deleting / updating.
62      * Must be explicitly released by <tt>closeStatement()</tt>
63      */

64     public CallableStatement JavaDoc prepareCallableStatement(String JavaDoc sql) throws SQLException JavaDoc, HibernateException;
65
66     /**
67      * Close a prepared or callable statement opened using <tt>prepareStatement()</tt> or <tt>prepareCallableStatement()</tt>
68      */

69     public void closeStatement(PreparedStatement JavaDoc ps) throws SQLException JavaDoc;
70     /**
71      * Get a batchable prepared statement to use for inserting / deleting / updating
72      * (might be called many times before a single call to <tt>executeBatch()</tt>).
73      * After setting parameters, call <tt>addToBatch</tt> - do not execute the
74      * statement explicitly.
75      * @see Batcher#addToBatch(int)
76      */

77     public PreparedStatement JavaDoc prepareBatchStatement(String JavaDoc sql) throws SQLException JavaDoc, HibernateException;
78
79     /**
80      * Get a batchable callable statement to use for inserting / deleting / updating
81      * (might be called many times before a single call to <tt>executeBatch()</tt>).
82      * After setting parameters, call <tt>addToBatch</tt> - do not execute the
83      * statement explicitly.
84      * @see Batcher#addToBatch(int)
85      */

86     public CallableStatement JavaDoc prepareBatchCallableStatement(String JavaDoc sql) throws SQLException JavaDoc, HibernateException;
87
88     /**
89      * Add an insert / delete / update to the current batch (might be called multiple times
90      * for single <tt>prepareBatchStatement()</tt>)
91      */

92     public void addToBatch(int expectedRowCount) throws SQLException JavaDoc, HibernateException;
93
94     /**
95      * Execute the batch
96      */

97     public void executeBatch() throws HibernateException;
98
99     /**
100      * Close any query statements that were left lying around
101      */

102     public void closeStatements();
103     /**
104      * Execute the statement and return the result set
105      */

106     public ResultSet JavaDoc getResultSet(PreparedStatement JavaDoc ps) throws SQLException JavaDoc;
107     /**
108      * Execute the statement and return the result set from a callable statement
109      */

110     public ResultSet JavaDoc getResultSet(CallableStatement JavaDoc ps, Dialect dialect) throws SQLException JavaDoc;
111
112     /**
113      * Must be called when an exception occurs
114      * @param sqle the (not null) exception that is the reason for aborting
115      */

116     public void abortBatch(SQLException JavaDoc sqle);
117
118     /**
119      * Cancel the current query statement
120      */

121     public void cancelLastQuery() throws HibernateException;
122
123     public boolean hasOpenResources();
124
125     public String JavaDoc openResourceStatsAsString();
126
127     // TODO : remove these last two as batcher is no longer managing connections
128

129     /**
130      * Obtain a JDBC connection
131      */

132     public Connection JavaDoc openConnection() throws HibernateException;
133     /**
134      * Dispose of the JDBC connection
135      */

136     public void closeConnection(Connection JavaDoc conn) throws HibernateException;
137
138
139 }
140
141
142
143
144
145
146
Popular Tags