01: package org.odmg;
02:
03: /**
04: * The interface to an OQL query object.
05: * @author David Jordan (as Java Editor of the Object Data Management Group)
06: * @version ODMG 3.0
07: */
08:
09: public interface OQLQuery {
10:
11: /**
12: * Create an OQL query from the string parameter.
13: * In order to execute a query, an <code>OQLQuery</code> object must be created
14: * by calling <code>Implementation.newOQLQuery</code>, then calling the
15: * <code>create</code> method with the query string.
16: * The <code>create</code> method might throw <code>QueryInvalidException</code>
17: * if the query could not be compiled properly. Some implementations may not want
18: * to compile the query before <code>execute</code> is called. In this case
19: * <code>QueryInvalidException</code> is thrown when <code>execute</code> is called.
20: * @param query An OQL query.
21: * @exception QueryInvalidException The query syntax is invalid.
22: */
23: public void create(String query) throws QueryInvalidException;
24:
25: /**
26: * Bind a parameter to the query.
27: * A parameter is denoted in the query string passed to <code>create</code> by <i>$i</i>,
28: * where <i>i</i> is the rank of the parameter, beginning with 1.
29: * The parameters are set consecutively by calling this method <code>bind</code>.
30: * The <i>ith</i> variable is set by the <i>ith</i> call to the <code>bind</code> method.
31: * If any of the <i>$i</i> are not set by a call to <code>bind</code> at the point
32: * <code>execute</code> is called, <code>QueryParameterCountInvalidException</code> is thrown.
33: * The parameters must be objects, and the result is an <code>Object</code>.
34: * Objects must be used instead of primitive types (<code>Integer</code> instead
35: * of <code>int</code>) for passing the parameters.
36: * <p>
37: * If the parameter is of the wrong type,
38: * <code>QueryParameterTypeInvalidException</code> is thrown.
39: * After executing a query, the parameter list is reset.
40: * @parameter A value to be substituted for a query parameter.
41: * @exception QueryParameterCountInvalidException The number of calls to
42: * <code>bind</code> has exceeded the number of parameters in the query.
43: * @exception QueryParameterTypeInvalidException The type of the parameter does
44: * not correspond with the type of the parameter in the query.
45: */
46: public void bind(Object parameter)
47: throws QueryParameterCountInvalidException,
48: QueryParameterTypeInvalidException;
49:
50: /**
51: * Execute the query.
52: * After executing a query, the parameter list is reset.
53: * Some implementations may throw additional exceptions that are also derived
54: * from <code>ODMGException</code>.
55: * @return The object that represents the result of the query.
56: * The returned data, whatever its OQL type, is encapsulated into an object.
57: * For instance, when OQL returns an integer, the result is put into an
58: * <code>Integer</code> object. When OQL returns a collection (literal or object),
59: * the result is always a Java collection object of the same kind
60: * (for instance, a <code>DList</code>).
61: * @exception QueryException An exception has occurred while executing the query.
62: */
63: public Object execute() throws QueryException;
64: }
|