KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > queryframework > ValueReadQuery


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.queryframework;
23
24 import oracle.toplink.essentials.internal.queryframework.*;
25 import oracle.toplink.essentials.exceptions.*;
26
27 /**
28  * <p><b>Purpose</b>:
29  * Concrete class to perform a read of a single data value.
30  * <p>
31  * <p><b>Responsibilities</b>:
32  * Used in conjunction with CursoredStream size and Platform getSequence.
33  * This can be used to read a single data value (i.e. one field).
34  * A single data value is returned, or null if no rows are returned.
35  *
36  * @author James Sutherland
37  * @since TOPLink/Java 1.2
38  */

39 public class ValueReadQuery extends DirectReadQuery {
40
41     /**
42      * PUBLIC:
43      * Initialize the state of the query.
44      */

45     public ValueReadQuery() {
46         super();
47     }
48
49     /**
50      * PUBLIC:
51      * Initialize the query to use the specified SQL string.
52      */

53     public ValueReadQuery(String JavaDoc sqlString) {
54         super(sqlString);
55     }
56
57     /**
58      * PUBLIC:
59      * Initialize the query to use the specified call.
60      */

61     public ValueReadQuery(Call call) {
62         super(call);
63     }
64
65     /**
66      * INTERNAL:
67      * Execute the query.
68      * Perform the work to execute the SQL string.
69      * @exception DatabaseException an error has occurred on the database
70      * @return Object the data value or null.
71      */

72     public Object JavaDoc executeDatabaseQuery() throws DatabaseException {
73         Object JavaDoc values = super.executeDatabaseQuery();
74         ContainerPolicy cp = getContainerPolicy();
75         if (cp.sizeFor(values) == 0) {
76             return null;
77         } else {
78             return cp.next(cp.iteratorFor(values), getSession());
79         }
80     }
81 }
82
Popular Tags