KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > persistence > Query


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package javax.persistence;
24
25 import java.util.Calendar JavaDoc;
26 import java.util.Date JavaDoc;
27 import java.util.List JavaDoc;
28
29 /**
30  * Interface used to control query execution.
31  *
32  * @since Java Persistence 1.0
33  */

34 public interface Query {
35
36     /**
37      * Execute a SELECT query and return the query results
38      * as a List.
39      * @return a list of the results
40      * @throws IllegalStateException if called for a Java
41      * Persistence query language UPDATE or DELETE statement
42      */

43     public List JavaDoc getResultList();
44
45     /**
46      * Execute a SELECT query that returns a single result.
47      * @return the result
48      * @throws NoResultException if there is no result
49      * @throws NonUniqueResultException if more than one result
50      * @throws IllegalStateException if called for a Java
51      * Persistence query language UPDATE or DELETE statement
52      */

53     public Object JavaDoc getSingleResult();
54
55     /**
56      * Execute an update or delete statement.
57      * @return the number of entities updated or deleted
58      * @throws IllegalStateException if called for a Java
59      * Persistence query language SELECT statement
60      * @throws TransactionRequiredException if there is
61      * no transaction
62      */

63     public int executeUpdate();
64
65     /**
66      * Set the maximum number of results to retrieve.
67      * @param maxResult
68      * @return the same query instance
69      * @throws IllegalArgumentException if argument is negative
70      */

71     public Query setMaxResults(int maxResult);
72
73     /**
74      * Set the position of the first result to retrieve.
75      * @param startPosition the start position of the first result, numbered from 0
76      * @return the same query instance
77      * @throws IllegalArgumentException if argument is negative
78      */

79     public Query setFirstResult(int startPosition);
80
81     /**
82      * Set an implementation-specific hint.
83      * If the hint name is not recognized, it is silently ignored.
84      * @param hintName
85      * @param value
86      * @return the same query instance
87      * @throws IllegalArgumentException if the second argument is not
88      * valid for the implementation
89      */

90     public Query setHint(String JavaDoc hintName, Object JavaDoc value);
91
92     /**
93      * Bind an argument to a named parameter.
94      * @param name the parameter name
95      * @param value
96      * @return the same query instance
97      * @throws IllegalArgumentException if parameter name does not
98      * correspond to parameter in query string
99      * or argument is of incorrect type
100      */

101     public Query setParameter(String JavaDoc name, Object JavaDoc value);
102
103     /**
104      * Bind an instance of java.util.Date to a named parameter.
105      * @param name
106      * @param value
107      * @param temporalType
108      * @return the same query instance
109      * @throws IllegalArgumentException if parameter name does not
110      * correspond to parameter in query string
111      */

112     public Query setParameter(String JavaDoc name, Date JavaDoc value, TemporalType temporalType);
113
114     /**
115      * Bind an instance of java.util.Calendar to a named parameter.
116      * @param name
117      * @param value
118      * @param temporalType
119      * @return the same query instance
120      * @throws IllegalArgumentException if parameter name does not
121      * correspond to parameter in query string
122      */

123     public Query setParameter(String JavaDoc name, Calendar JavaDoc value, TemporalType temporalType);
124
125     /**
126      * Bind an argument to a positional parameter.
127      * @param position
128      * @param value
129      * @return the same query instance
130      * @throws IllegalArgumentException if position does not
131      * correspond to positional parameter of query
132      * or argument is of incorrect type
133      */

134     public Query setParameter(int position, Object JavaDoc value);
135
136     /**
137      * Bind an instance of java.util.Date to a positional parameter.
138      * @param position
139      * @param value
140      * @param temporalType
141      * @return the same query instance
142      * @throws IllegalArgumentException if position does not
143      * correspond to positional parameter of query
144      */

145     public Query setParameter(int position, Date JavaDoc value, TemporalType temporalType);
146
147     /**
148      * Bind an instance of java.util.Calendar to a positional parameter.
149      * @param position
150      * @param value
151      * @param temporalType
152      * @return the same query instance
153      * @throws IllegalArgumentException if position does not
154      * correspond to positional parameter of query
155      */

156     public Query setParameter(int position, Calendar JavaDoc value, TemporalType temporalType);
157
158     /**
159      * Set the flush mode type to be used for the query execution.
160      * The flush mode type applies to the query regardless of the
161      * flush mode type in use for the entity manager.
162      * @param flushMode
163      */

164     public Query setFlushMode(FlushModeType flushMode);
165 }
166
Popular Tags