KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > hibernate > HibernateOperations


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.orm.hibernate;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23
24 import net.sf.hibernate.LockMode;
25 import net.sf.hibernate.ReplicationMode;
26 import net.sf.hibernate.type.Type;
27
28 import org.springframework.dao.DataAccessException;
29
30 /**
31  * Interface that specifies a basic set of Hibernate operations,
32  * implemented by {@link HibernateTemplate}. Not often used, but a useful
33  * option to enhance testability, as it can easily be mocked or stubbed.
34  *
35  * <p>Defines <code>HibernateTemplate</code>'s data access methods that
36  * mirror various {@link net.sf.hibernate.Session} methods. Users are
37  * strongly encouraged to read the Hibernate <code>Session</code> javadocs
38  * for details on the semantics of those methods.
39  *
40  * <p>Note that operations that return an {@link java.util.Iterator} (i.e.
41  * <code>iterate(..)</code>) are supposed to be used within Spring-driven
42  * or JTA-driven transactions (with {@link HibernateTransactionManager},
43  * {@link org.springframework.transaction.jta.JtaTransactionManager},
44  * or EJB CMT). Else, the <code>Iterator</code> won't be able to read
45  * results from its {@link java.sql.ResultSet} anymore, as the underlying
46  * Hibernate <code>Session</code> will already have been closed.
47  *
48  * <p>Note that lazy loading will just work with an open Hibernate
49  * <code>Session</code>, either within a transaction or within
50  * {@link org.springframework.orm.hibernate.support.OpenSessionInViewFilter}/
51  * {@link org.springframework.orm.hibernate.support.OpenSessionInViewInterceptor}.
52  * Furthermore, some operations just make sense within transactions,
53  * for example: <code>contains</code>, <code>evict</code>, <code>lock</code>,
54  * <code>flush</code>, <code>clear</code>.
55  *
56  * @author Juergen Hoeller
57  * @since 05.02.2004
58  * @see HibernateTemplate
59  * @see net.sf.hibernate.Session
60  * @see HibernateTransactionManager
61  * @see org.springframework.transaction.jta.JtaTransactionManager
62  * @see org.springframework.orm.hibernate.support.OpenSessionInViewFilter
63  * @see org.springframework.orm.hibernate.support.OpenSessionInViewInterceptor
64  */

65 public interface HibernateOperations {
66
67     /**
68      * Execute the action specified by the given action object within a Session.
69      * Application exceptions thrown by the action object get propagated to the
70      * caller (can only be unchecked). Hibernate exceptions are transformed into
71      * appropriate DAO ones. Allows for returning a result object, i.e. a domain
72      * object or a collection of domain objects.
73      * <p>Note: Callback code is not supposed to handle transactions itself!
74      * Use an appropriate transaction manager like HibernateTransactionManager.
75      * Generally, callback code must not touch any Session lifecycle methods,
76      * like close, disconnect, or reconnect, to let the template do its work.
77      * @param action callback object that specifies the Hibernate action
78      * @return a result object returned by the action, or <code>null</code>
79      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
80      * @see HibernateTransactionManager
81      * @see org.springframework.dao
82      * @see org.springframework.transaction
83      * @see net.sf.hibernate.Session
84      */

85     Object JavaDoc execute(HibernateCallback action) throws DataAccessException;
86
87     /**
88      * Execute the specified action assuming that the result object is a List.
89      * This is a convenience method for executing Hibernate find calls or
90      * queries within an action.
91      * @param action calback object that specifies the Hibernate action
92      * @return a List result returned by the action, or <code>null</code>
93      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
94      */

95     List JavaDoc executeFind(HibernateCallback action) throws DataAccessException;
96
97
98     //-------------------------------------------------------------------------
99
// Convenience methods for loading individual objects
100
//-------------------------------------------------------------------------
101

102     /**
103      * Return the persistent instance of the given entity class
104      * with the given identifier, or <code>null</code> if not found.
105      * <p>This method is a thin wrapper around
106      * {@link net.sf.hibernate.Session#get(Class, java.io.Serializable)} for convenience.
107      * For an explanation of the exact semantics of this method, please do refer to
108      * the Hibernate API documentation in the first instance.
109      * @param entityClass a persistent class
110      * @param id an identifier of the persistent instance
111      * @return the persistent instance, or <code>null</code> if not found
112      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
113      * @see net.sf.hibernate.Session#get(Class, java.io.Serializable)
114      */

115     Object JavaDoc get(Class JavaDoc entityClass, Serializable JavaDoc id) throws DataAccessException;
116
117     /**
118      * Return the persistent instance of the given entity class
119      * with the given identifier, or <code>null</code> if not found.
120      * <p>Obtains the specified lock mode if the instance exists.
121      * <p>This method is a thin wrapper around
122      * {@link net.sf.hibernate.Session#get(Class, java.io.Serializable, net.sf.hibernate.LockMode)} for convenience.
123      * For an explanation of the exact semantics of this method, please do refer to
124      * the Hibernate API documentation in the first instance.
125      * @param entityClass a persistent class
126      * @param id an identifier of the persistent instance
127      * @param lockMode the lock mode to obtain
128      * @return the persistent instance, or <code>null</code> if not found
129      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
130      * @see net.sf.hibernate.Session#get(Class, java.io.Serializable, net.sf.hibernate.LockMode)
131      */

132     Object JavaDoc get(Class JavaDoc entityClass, Serializable JavaDoc id, LockMode lockMode)
133             throws DataAccessException;
134
135     /**
136      * Return the persistent instance of the given entity class
137      * with the given identifier, throwing an exception if not found.
138      * <p>This method is a thin wrapper around
139      * {@link net.sf.hibernate.Session#load(Class, java.io.Serializable)} for convenience.
140      * For an explanation of the exact semantics of this method, please do refer to
141      * the Hibernate API documentation in the first instance.
142      * @param entityClass a persistent class
143      * @param id an identifier of the persistent instance
144      * @return the persistent instance
145      * @throws org.springframework.orm.ObjectRetrievalFailureException if not found
146      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
147      * @see net.sf.hibernate.Session#load(Class, java.io.Serializable)
148      */

149     Object JavaDoc load(Class JavaDoc entityClass, Serializable JavaDoc id) throws DataAccessException;
150
151     /**
152      * Return the persistent instance of the given entity class
153      * with the given identifier, throwing an exception if not found.
154      * Obtains the specified lock mode if the instance exists.
155      * <p>This method is a thin wrapper around
156      * {@link net.sf.hibernate.Session#load(Class, java.io.Serializable, net.sf.hibernate.LockMode)} for convenience.
157      * For an explanation of the exact semantics of this method, please do refer to
158      * the Hibernate API documentation in the first instance.
159      * @param entityClass a persistent class
160      * @param id an identifier of the persistent instance
161      * @param lockMode the lock mode to obtain
162      * @return the persistent instance
163      * @throws org.springframework.orm.ObjectRetrievalFailureException if not found
164      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
165      * @see net.sf.hibernate.Session#load(Class, java.io.Serializable)
166      */

167     Object JavaDoc load(Class JavaDoc entityClass, Serializable JavaDoc id, LockMode lockMode)
168             throws DataAccessException;
169
170     /**
171      * Return all persistent instances of the given entity class.
172      * Note: Use queries or criteria for retrieving a specific subset.
173      * @param entityClass a persistent class
174      * @return a List containing 0 or more persistent instances
175      * @throws org.springframework.dao.DataAccessException if there is a Hibernate error
176      * @see net.sf.hibernate.Session#createCriteria
177      */

178     List JavaDoc loadAll(Class JavaDoc entityClass) throws DataAccessException;
179
180     /**
181      * Load the persistent instance with the given identifier
182      * into the given object, throwing an exception if not found.
183      * @param entity the object (of the target class) to load into
184      * @param id an identifier of the persistent instance
185      * @throws org.springframework.orm.ObjectRetrievalFailureException if not found
186      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
187      * @see net.sf.hibernate.Session#load(Object, java.io.Serializable)
188      */

189     void load(Object JavaDoc entity, Serializable JavaDoc id) throws DataAccessException;
190
191     /**
192      * Re-read the state of the given persistent instance.
193      * @param entity the persistent instance to re-read
194      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
195      * @see net.sf.hibernate.Session#refresh(Object)
196      */

197     void refresh(Object JavaDoc entity) throws DataAccessException;
198
199     /**
200      * Re-read the state of the given persistent instance.
201      * Obtains the specified lock mode for the instance.
202      * @param entity the persistent instance to re-read
203      * @param lockMode the lock mode to obtain
204      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
205      * @see net.sf.hibernate.Session#refresh(Object, net.sf.hibernate.LockMode)
206      */

207     void refresh(Object JavaDoc entity, LockMode lockMode) throws DataAccessException;
208
209     /**
210      * Check whether the given object is in the Session cache.
211      * @param entity the persistence instance to check
212      * @return whether the given object is in the Session cache
213      * @throws org.springframework.dao.DataAccessException if there is a Hibernate error
214      * @see net.sf.hibernate.Session#contains
215      */

216     boolean contains(Object JavaDoc entity) throws DataAccessException;
217
218     /**
219      * Remove the given object from the Session cache.
220      * @param entity the persistent instance to evict
221      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
222      * @see net.sf.hibernate.Session#evict
223      */

224     void evict(Object JavaDoc entity) throws DataAccessException;
225
226     /**
227      * Force initialization of a Hibernate proxy or persistent collection.
228      * @param proxy a proxy for a persistent object or a persistent collection
229      * @throws DataAccessException if we can't initialize the proxy, for example
230      * because it is not associated with an active Session
231      * @see net.sf.hibernate.Hibernate#initialize
232      */

233     void initialize(Object JavaDoc proxy) throws DataAccessException;
234
235
236     //-------------------------------------------------------------------------
237
// Convenience methods for storing individual objects
238
//-------------------------------------------------------------------------
239

240     /**
241      * Obtain the specified lock level upon the given object, implicitly
242      * checking whether the corresponding database entry still exists
243      * (throwing an OptimisticLockingFailureException if not found).
244      * @param entity the persistent instance to lock
245      * @param lockMode the lock mode to obtain
246      * @throws org.springframework.orm.ObjectOptimisticLockingFailureException if not found
247      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
248      * @see HibernateOptimisticLockingFailureException
249      * @see net.sf.hibernate.Session#lock(Object, net.sf.hibernate.LockMode)
250      */

251     void lock(Object JavaDoc entity, LockMode lockMode) throws DataAccessException;
252
253     /**
254      * Persist the given transient instance.
255      * @param entity the transient instance to persist
256      * @return the generated identifier
257      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
258      * @see net.sf.hibernate.Session#save(Object)
259      */

260     Serializable JavaDoc save(Object JavaDoc entity) throws DataAccessException;
261
262     /**
263      * Persist the given transient instance with the given identifier.
264      * @param entity the transient instance to persist
265      * @param id the identifier to assign
266      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
267      * @see net.sf.hibernate.Session#save(Object, java.io.Serializable)
268      */

269     void save(Object JavaDoc entity, Serializable JavaDoc id) throws DataAccessException;
270
271     /**
272      * Update the given persistent instance.
273      * @param entity the persistent instance to update
274      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
275      * @see net.sf.hibernate.Session#update(Object)
276      */

277     void update(Object JavaDoc entity) throws DataAccessException;
278
279     /**
280      * Update the given persistent instance.
281      * <p>Obtains the specified lock mode if the instance exists, implicitly
282      * checking whether the corresponding database entry still exists
283      * (throwing an OptimisticLockingFailureException if not found).
284      * @param entity the persistent instance to update
285      * @param lockMode the lock mode to obtain
286      * @throws org.springframework.orm.ObjectOptimisticLockingFailureException if not found
287      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
288      * @see HibernateOptimisticLockingFailureException
289      * @see net.sf.hibernate.Session#update(Object)
290      */

291     void update(Object JavaDoc entity, LockMode lockMode) throws DataAccessException;
292
293     /**
294      * Save or update the given persistent instance,
295      * according to its id (matching the configured "unsaved-value"?).
296      * @param entity the persistent instance to save or update
297      * (to be associated with the Hibernate Session)
298      * @throws DataAccessException in case of Hibernate errors
299      * @see net.sf.hibernate.Session#saveOrUpdate(Object)
300      */

301     void saveOrUpdate(Object JavaDoc entity) throws DataAccessException;
302
303     /**
304      * Save or update all given persistent instances,
305      * according to its id (matching the configured "unsaved-value"?).
306      * @param entities the persistent instances to save or update
307      * (to be associated with the Hibernate Session)
308      * @throws DataAccessException in case of Hibernate errors
309      * @see net.sf.hibernate.Session#saveOrUpdate(Object)
310      */

311     void saveOrUpdateAll(Collection JavaDoc entities) throws DataAccessException;
312
313     /**
314      * Save or update the contents of given persistent object,
315      * according to its id (matching the configured "unsaved-value"?).
316      * Will copy the contained fields to an already loaded instance
317      * with the same id, if appropriate.
318      * @param entity the persistent object to save or update
319      * (<i>not</i> necessarily to be associated with the Hibernate Session)
320      * @return the actually associated persistent object
321      * (either an already loaded instance with the same id, or the given object)
322      * @throws DataAccessException in case of Hibernate errors
323      * @see net.sf.hibernate.Session#saveOrUpdateCopy(Object)
324      */

325     Object JavaDoc saveOrUpdateCopy(Object JavaDoc entity) throws DataAccessException;
326
327     /**
328      * Persist the state of the given detached instance according to the
329      * given replication mode, reusing the current identifier value.
330      * @param entity the persistent object to replicate
331      * @throws DataAccessException in case of Hibernate errors
332      * @see net.sf.hibernate.Session#replicate(Object, net.sf.hibernate.ReplicationMode)
333      */

334     void replicate(Object JavaDoc entity, ReplicationMode replicationMode) throws DataAccessException;
335
336     /**
337      * Delete the given persistent instance.
338      * @param entity the persistent instance to delete
339      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
340      * @see net.sf.hibernate.Session#delete(Object)
341      */

342     void delete(Object JavaDoc entity) throws DataAccessException;
343
344     /**
345      * Delete the given persistent instance.
346      * <p>Obtains the specified lock mode if the instance exists, implicitly
347      * checking whether the corresponding database entry still exists
348      * (throwing an OptimisticLockingFailureException if not found).
349      * @param entity the persistent instance to delete
350      * @param lockMode the lock mode to obtain
351      * @throws org.springframework.orm.ObjectOptimisticLockingFailureException if not found
352      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
353      * @see HibernateOptimisticLockingFailureException
354      * @see net.sf.hibernate.Session#delete(Object)
355      */

356     void delete(Object JavaDoc entity, LockMode lockMode) throws DataAccessException;
357
358     /**
359      * Delete all given persistent instances.
360      * <p>This can be combined with any of the find methods to delete by query
361      * in two lines of code, similar to Session's delete by query methods.
362      * @param entities the persistent instances to delete
363      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
364      * @see net.sf.hibernate.Session#delete(String)
365      */

366     void deleteAll(Collection JavaDoc entities) throws DataAccessException;
367
368     /**
369      * Flush all pending saves, updates and deletes to the database.
370      * <p>Only invoke this for selective eager flushing, for example when JDBC code
371      * needs to see certain changes within the same transaction. Else, it's preferable
372      * to rely on auto-flushing at transaction completion.
373      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
374      * @see net.sf.hibernate.Session#flush
375      */

376     void flush() throws DataAccessException;
377
378     /**
379      * Remove all objects from the Session cache, and cancel all pending saves,
380      * updates and deletes.
381      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
382      * @see net.sf.hibernate.Session#clear
383      */

384     void clear() throws DataAccessException;
385
386
387     //-------------------------------------------------------------------------
388
// Convenience finder methods for HQL strings
389
//-------------------------------------------------------------------------
390

391     /**
392      * Execute an HQL query.
393      * @param queryString a query expressed in Hibernate's query language
394      * @return a List containing the results of the query execution
395      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
396      * @see net.sf.hibernate.Session#find(String)
397      * @see net.sf.hibernate.Session#createQuery
398      */

399     List JavaDoc find(String JavaDoc queryString) throws DataAccessException;
400
401     /**
402      * Execute an HQL query, binding one value to a "?" parameter in
403      * the query string.
404      * @param queryString a query expressed in Hibernate's query language
405      * @param value the value of the parameter
406      * @return a List containing the results of the query execution
407      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
408      * @see net.sf.hibernate.Session#find(String, Object, net.sf.hibernate.type.Type)
409      * @see net.sf.hibernate.Session#createQuery
410      */

411     List JavaDoc find(String JavaDoc queryString, Object JavaDoc value) throws DataAccessException;
412
413     /**
414      * Execute an HQL query, binding one value to a "?" parameter of the
415      * given type in the query string.
416      * @param queryString a query expressed in Hibernate's query language
417      * @param value the value of the parameter
418      * @param type Hibernate type of the parameter (or <code>null</code>)
419      * @return a List containing the results of the query execution
420      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
421      * @see net.sf.hibernate.Session#find(String, Object, net.sf.hibernate.type.Type)
422      * @see net.sf.hibernate.Session#createQuery
423      */

424     List JavaDoc find(String JavaDoc queryString, Object JavaDoc value, Type type) throws DataAccessException;
425
426     /**
427      * Execute an HQL query, binding a number of values to "?" parameters
428      * in the query string.
429      * @param queryString a query expressed in Hibernate's query language
430      * @param values the values of the parameters
431      * @return a List containing the results of the query execution
432      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
433      * @see net.sf.hibernate.Session#find(String, Object[], net.sf.hibernate.type.Type[])
434      * @see net.sf.hibernate.Session#createQuery
435      */

436     List JavaDoc find(String JavaDoc queryString, Object JavaDoc[] values) throws DataAccessException;
437
438     /**
439      * Execute an HQL query, binding a number of values to "?" parameters
440      * of the given types in the query string.
441      * @param queryString a query expressed in Hibernate's query language
442      * @param values the values of the parameters
443      * @param types Hibernate types of the parameters (or <code>null</code>)
444      * @return a List containing the results of the query execution
445      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
446      * @see net.sf.hibernate.Session#find(String, Object[], net.sf.hibernate.type.Type[])
447      * @see net.sf.hibernate.Session#createQuery
448      */

449     List JavaDoc find(String JavaDoc queryString, Object JavaDoc[] values, Type[] types) throws DataAccessException;
450
451     /**
452      * Execute an HQL query, binding one value to a ":" named parameter
453      * in the query string.
454      * @param queryName the name of a Hibernate query in a mapping file
455      * @param paramName the name of parameter
456      * @param value the value of the parameter
457      * @return a List containing the results of the query execution
458      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
459      * @see net.sf.hibernate.Session#find(String, Object, net.sf.hibernate.type.Type)
460      * @see net.sf.hibernate.Session#getNamedQuery(String)
461      */

462     List JavaDoc findByNamedParam(String JavaDoc queryName, String JavaDoc paramName, Object JavaDoc value)
463             throws DataAccessException;
464
465     /**
466      * Execute an HQL query, binding one value to a ":" named parameter
467      * in the query string.
468      * @param queryName the name of a Hibernate query in a mapping file
469      * @param paramName the name of the parameter
470      * @param value the value of the parameter
471      * @param type Hibernate type of the parameter (or <code>null</code>)
472      * @return a List containing the results of the query execution
473      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
474      * @see net.sf.hibernate.Session#find(String, Object, net.sf.hibernate.type.Type)
475      * @see net.sf.hibernate.Session#getNamedQuery(String)
476      */

477     List JavaDoc findByNamedParam(String JavaDoc queryName, String JavaDoc paramName, Object JavaDoc value, Type type)
478             throws DataAccessException;
479
480     /**
481      * Execute an HQL query, binding a number of values to ":" named
482      * parameters in the query string.
483      * @param queryString a query expressed in Hibernate's query language
484      * @param paramNames the names of the parameters
485      * @param values the values of the parameters
486      * @return a List containing the results of the query execution
487      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
488      * @see net.sf.hibernate.Session#find(String, Object[], net.sf.hibernate.type.Type[])
489      * @see net.sf.hibernate.Session#getNamedQuery(String)
490      */

491     List JavaDoc findByNamedParam(String JavaDoc queryString, String JavaDoc[] paramNames, Object JavaDoc[] values)
492             throws DataAccessException;
493
494     /**
495      * Execute an HQL query, binding a number of values to ":" named
496      * parameters in the query string.
497      * @param queryString a query expressed in Hibernate's query language
498      * @param paramNames the names of the parameters
499      * @param values the values of the parameters
500      * @param types Hibernate types of the parameters (or <code>null</code>)
501      * @return a List containing the results of the query execution
502      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
503      * @see net.sf.hibernate.Session#find(String, Object[], net.sf.hibernate.type.Type[])
504      * @see net.sf.hibernate.Session#getNamedQuery(String)
505      */

506     List JavaDoc findByNamedParam(String JavaDoc queryString, String JavaDoc[] paramNames, Object JavaDoc[] values, Type[] types)
507             throws DataAccessException;
508
509     /**
510      * Execute an HQL query, binding the properties of the given bean to
511      * <i>named</i> parameters in the query string.
512      * @param queryString a query expressed in Hibernate's query language
513      * @param valueBean the values of the parameters
514      * @return a List containing the results of the query execution
515      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
516      * @see net.sf.hibernate.Query#setProperties
517      * @see net.sf.hibernate.Session#createQuery
518      */

519     List JavaDoc findByValueBean(String JavaDoc queryString, Object JavaDoc valueBean) throws DataAccessException;
520
521
522     //-------------------------------------------------------------------------
523
// Convenience finder methods for named queries
524
//-------------------------------------------------------------------------
525

526     /**
527      * Execute a named query.
528      * <p>A named query is defined in a Hibernate mapping file.
529      * @param queryName the name of a Hibernate query in a mapping file
530      * @return a List containing the results of the query execution
531      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
532      * @see net.sf.hibernate.Session#find(String)
533      * @see net.sf.hibernate.Session#getNamedQuery(String)
534      */

535     List JavaDoc findByNamedQuery(String JavaDoc queryName) throws DataAccessException;
536
537     /**
538      * Execute a named query, binding one value to a "?" parameter in the
539      * query string.
540      * <p>A named query is defined in a Hibernate mapping file.
541      * @param queryName the name of a Hibernate query in a mapping file
542      * @param value the value of the parameter
543      * @return a List containing the results of the query execution
544      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
545      * @see net.sf.hibernate.Session#find(String, Object, net.sf.hibernate.type.Type)
546      * @see net.sf.hibernate.Session#getNamedQuery(String)
547      */

548     List JavaDoc findByNamedQuery(String JavaDoc queryName, Object JavaDoc value) throws DataAccessException;
549
550     /**
551      * Execute a named query, binding one value to a "?" parameter in
552      * the query string.
553      * <p>A named query is defined in a Hibernate mapping file.
554      * @param queryName the name of a Hibernate query in a mapping file
555      * @param value the value of the parameter
556      * @param type Hibernate type of the parameter (or <code>null</code>)
557      * @return a List containing the results of the query execution
558      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
559      * @see net.sf.hibernate.Session#find(String, Object, net.sf.hibernate.type.Type)
560      * @see net.sf.hibernate.Session#getNamedQuery(String)
561      */

562     List JavaDoc findByNamedQuery(String JavaDoc queryName, Object JavaDoc value, Type type) throws DataAccessException;
563
564     /**
565      * Execute a named query, binding a number of values to "?" parameters
566      * in the query string.
567      * <p>A named query is defined in a Hibernate mapping file.
568      * @param queryName the name of a Hibernate query in a mapping file
569      * @param values the values of the parameters
570      * @return a List containing the results of the query execution
571      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
572      * @see net.sf.hibernate.Session#find(String, Object[], net.sf.hibernate.type.Type[])
573      * @see net.sf.hibernate.Session#getNamedQuery(String)
574      */

575     List JavaDoc findByNamedQuery(String JavaDoc queryName, Object JavaDoc[] values) throws DataAccessException;
576
577     /**
578      * Execute a named query, binding a number of values to "?" parameters
579      * in the query string.
580      * <p>A named query is defined in a Hibernate mapping file.
581      * @param queryName the name of a Hibernate query in a mapping file
582      * @param values the values of the parameters
583      * @param types Hibernate types of the parameters (or <code>null</code>)
584      * @return a List containing the results of the query execution
585      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
586      * @see net.sf.hibernate.Session#find(String, Object[], net.sf.hibernate.type.Type[])
587      * @see net.sf.hibernate.Session#getNamedQuery(String)
588      */

589     List JavaDoc findByNamedQuery(String JavaDoc queryName, Object JavaDoc[] values, Type[] types)
590             throws DataAccessException;
591
592     /**
593      * Execute a named query, binding one value to a ":" named parameter
594      * in the query string.
595      * <p>A named query is defined in a Hibernate mapping file.
596      * @param queryName the name of a Hibernate query in a mapping file
597      * @param paramName the name of parameter
598      * @param value the value of the parameter
599      * @return a List containing the results of the query execution
600      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
601      * @see net.sf.hibernate.Session#find(String, Object, net.sf.hibernate.type.Type)
602      * @see net.sf.hibernate.Session#getNamedQuery(String)
603      */

604     List JavaDoc findByNamedQueryAndNamedParam(String JavaDoc queryName, String JavaDoc paramName, Object JavaDoc value)
605             throws DataAccessException;
606
607     /**
608      * Execute a named query, binding one value to a ":" named parameter
609      * in the query string.
610      * <p>A named query is defined in a Hibernate mapping file.
611      * @param queryName the name of a Hibernate query in a mapping file
612      * @param paramName the name of the parameter
613      * @param value the value of the parameter
614      * @param type Hibernate type of the parameter (or <code>null</code>)
615      * @return a List containing the results of the query execution
616      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
617      * @see net.sf.hibernate.Session#find(String, Object, net.sf.hibernate.type.Type)
618      * @see net.sf.hibernate.Session#getNamedQuery(String)
619      */

620     List JavaDoc findByNamedQueryAndNamedParam(String JavaDoc queryName, String JavaDoc paramName, Object JavaDoc value, Type type)
621             throws DataAccessException;
622
623     /**
624      * Execute a named query, binding a number of values to ":" named
625      * parameters in the query string.
626      * <p>A named query is defined in a Hibernate mapping file.
627      * @param queryName the name of a Hibernate query in a mapping file
628      * @param paramNames the names of the parameters
629      * @param values the values of the parameters
630      * @return a List containing the results of the query execution
631      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
632      * @see net.sf.hibernate.Session#find(String, Object[], net.sf.hibernate.type.Type[])
633      * @see net.sf.hibernate.Session#getNamedQuery(String)
634      */

635     List JavaDoc findByNamedQueryAndNamedParam(String JavaDoc queryName, String JavaDoc[] paramNames, Object JavaDoc[] values)
636             throws DataAccessException;
637
638     /**
639      * Execute a named query, binding a number of values to ":" named
640      * parameters in the query string.
641      * <p>A named query is defined in a Hibernate mapping file.
642      * @param queryName the name of a Hibernate query in a mapping file
643      * @param paramNames the names of the parameters
644      * @param values the values of the parameters
645      * @param types Hibernate types of the parameters (or <code>null</code>)
646      * @return a List containing the results of the query execution
647      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
648      * @see net.sf.hibernate.Session#find(String, Object[], net.sf.hibernate.type.Type[])
649      * @see net.sf.hibernate.Session#getNamedQuery(String)
650      */

651     List JavaDoc findByNamedQueryAndNamedParam(String JavaDoc queryName, String JavaDoc[] paramNames, Object JavaDoc[] values, Type[] types)
652             throws DataAccessException;
653
654     /**
655      * Execute a named query, binding the properties of the given bean to
656      * ":" named parameters in the query string.
657      * <p>A named query is defined in a Hibernate mapping file.
658      * @param queryName the name of a Hibernate query in a mapping file
659      * @param valueBean the values of the parameters
660      * @return a List containing the results of the query execution
661      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
662      * @see net.sf.hibernate.Query#setProperties
663      * @see net.sf.hibernate.Session#getNamedQuery(String)
664      */

665     List JavaDoc findByNamedQueryAndValueBean(String JavaDoc queryName, Object JavaDoc valueBean)
666             throws DataAccessException;
667
668
669     //-------------------------------------------------------------------------
670
// Convenience query methods for iterate and delete
671
//-------------------------------------------------------------------------
672

673     /**
674      * Execute a query for persistent instances.
675      * <p>Returns the results as Iterator. Entities returned are initialized
676      * on demand. See Hibernate docs for details.
677      * @param queryString a query expressed in Hibernate's query language
678      * @return an Iterator containing 0 or more persistent instances
679      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
680      * @see net.sf.hibernate.Session#iterate(String)
681      * @see net.sf.hibernate.Session#createQuery
682      */

683     Iterator JavaDoc iterate(String JavaDoc queryString) throws DataAccessException;
684
685     /**
686      * Execute a query for persistent instances, binding one value
687      * to a "?" parameter in the query string.
688      * <p>Returns the results as Iterator. Entities returned are initialized
689      * on demand. See Hibernate docs for details.
690      * @param queryString a query expressed in Hibernate's query language
691      * @param value the value of the parameter
692      * @return an Iterator containing 0 or more persistent instances
693      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
694      * @see net.sf.hibernate.Session#iterate(String, Object, net.sf.hibernate.type.Type)
695      * @see net.sf.hibernate.Session#createQuery
696      */

697     Iterator JavaDoc iterate(String JavaDoc queryString, Object JavaDoc value) throws DataAccessException;
698
699     /**
700      * Execute a query for persistent instances, binding one value
701      * to a "?" parameter of the given type in the query string.
702      * <p>Returns the results as Iterator. Entities returned are initialized
703      * on demand. See Hibernate docs for details.
704      * @param queryString a query expressed in Hibernate's query language
705      * @param value the value of the parameter
706      * @param type Hibernate type of the parameter (or <code>null</code>)
707      * @return an Iterator containing 0 or more persistent instances
708      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
709      * @see net.sf.hibernate.Session#iterate(String, Object, net.sf.hibernate.type.Type)
710      * @see net.sf.hibernate.Session#createQuery
711      */

712     Iterator JavaDoc iterate(String JavaDoc queryString, Object JavaDoc value, Type type) throws DataAccessException;
713
714     /**
715      * Execute a query for persistent instances, binding a number of
716      * values to "?" parameters in the query string.
717      * <p>Returns the results as Iterator. Entities returned are initialized
718      * on demand. See Hibernate docs for details.
719      * @param queryString a query expressed in Hibernate's query language
720      * @param values the values of the parameters
721      * @return an Iterator containing 0 or more persistent instances
722      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
723      * @see net.sf.hibernate.Session#find(String, Object[], net.sf.hibernate.type.Type[])
724      * @see net.sf.hibernate.Session#createQuery
725      */

726     Iterator JavaDoc iterate(String JavaDoc queryString, Object JavaDoc[] values) throws DataAccessException;
727
728     /**
729      * Execute a query for persistent instances, binding a number of
730      * values to "?" parameters of the given types in the query string.
731      * <p>Returns the results as Iterator. Entities returned are initialized
732      * on demand. See Hibernate docs for details.
733      * @param queryString a query expressed in Hibernate's query language
734      * @param values the values of the parameters
735      * @param types Hibernate types of the parameters (or <code>null</code>)
736      * @return an Iterator containing 0 or more persistent instances
737      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
738      * @see net.sf.hibernate.Session#find(String, Object[], net.sf.hibernate.type.Type[])
739      * @see net.sf.hibernate.Session#createQuery
740      */

741     Iterator JavaDoc iterate(String JavaDoc queryString, Object JavaDoc[] values, Type[] types) throws DataAccessException;
742
743     /**
744      * Close an Iterator created by <i>iterate</i> operations immediately,
745      * instead of waiting until the session is closed or disconnected.
746      * @param it the Iterator to close
747      * @throws DataAccessException if the Iterator could not be closed
748      * @see net.sf.hibernate.Hibernate#close
749      */

750     void closeIterator(Iterator JavaDoc it) throws DataAccessException;
751
752     /**
753      * Delete all objects returned by the query.
754      * Return the number of entity instances deleted.
755      * @param queryString a query expressed in Hibernate's query language
756      * @return the number of instances deleted
757      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
758      * @see net.sf.hibernate.Session#delete(String)
759      */

760     int delete(String JavaDoc queryString) throws DataAccessException;
761
762     /**
763      * Delete all objects returned by the query.
764      * Return the number of entity instances deleted.
765      * @param queryString a query expressed in Hibernate's query language
766      * @param value the value of the parameter
767      * @param type Hibernate type of the parameter (or <code>null</code>)
768      * @return the number of instances deleted
769      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
770      * @see net.sf.hibernate.Session#delete(String, Object, net.sf.hibernate.type.Type)
771      */

772     int delete(String JavaDoc queryString, Object JavaDoc value, Type type) throws DataAccessException;
773
774     /**
775      * Delete all objects returned by the query.
776      * Return the number of entity instances deleted.
777      * @param queryString a query expressed in Hibernate's query language
778      * @param values the values of the parameters
779      * @param types Hibernate types of the parameters (or <code>null</code>)
780      * @return the number of instances deleted
781      * @throws org.springframework.dao.DataAccessException in case of Hibernate errors
782      * @see net.sf.hibernate.Session#delete(String, Object[], net.sf.hibernate.type.Type[])
783      */

784     int delete(String JavaDoc queryString, Object JavaDoc[] values, Type[] types) throws DataAccessException;
785
786 }
787
Popular Tags