01: /**********************************************************************
02: Copyright (c) 2006 Erik Bengtson and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15: Contributors:
16: 2006 Alexander Bieber - Initial proposal and design
17: ...
18: **********************************************************************/package org.jpox.store.query;
19:
20: import java.io.Serializable;
21:
22: /**
23: * Metadata of JPOX query results.
24: * Can be for JDOQL, JPQL, or some other language in principle.
25: * @version $Revision: 1.3 $
26: */
27: public class JPOXResultSetMetaData implements Serializable {
28: /** type of all expressions in the result **/
29: final Class[] types;
30:
31: /**
32: * Constructor
33: * @param types type of all expressions in the result
34: */
35: public JPOXResultSetMetaData(Class[] types) {
36: this .types = types;
37: }
38:
39: /**
40: * The number of expressions in the result
41: * @return The number of expressions returned by the associated query.
42: */
43: public int getExpressionCount() {
44: return types.length;
45: }
46:
47: /**
48: * Returns the Java class of the expression referenced by the given index that
49: * is returned by the associated query.
50: * @param exprIndex The 0-based index of the expression the type should be returned for.
51: * @return The Java class of the expression with the given index.
52: * @throws IndexOutOfBoundsException if the index is out of range
53: */
54: public Class getExpressionType(int exprIndex) {
55: if (exprIndex < 0 || exprIndex >= types.length) {
56: // TODO Localise this message
57: throw new IndexOutOfBoundsException(
58: "Number of expressions in result set is "
59: + types.length
60: + ". You tried to access index "
61: + exprIndex);
62: }
63: return types[exprIndex];
64: }
65: }
|