01: package org.apache.ojb.jdo.jdoql;
02:
03: /* Copyright 2003-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * Encapsulates an ordering.
20: *
21: * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
22: */
23: public class Ordering extends QueryTreeNode {
24: /** The ordering expression */
25: private Expression _expr;
26: /** Whether this is an ascending ordering specification */
27: private boolean _isAscending = true;
28:
29: /**
30: * Creates a new ordering object.
31: *
32: * @param expr The ordering expression
33: * @param isAscending Whether this is an ascending ordering specification
34: */
35: public Ordering(Expression expr, boolean isAscending) {
36: _expr = expr;
37: _isAscending = isAscending;
38: }
39:
40: /**
41: * Returns the ordering expression.
42: *
43: * @return The expression
44: */
45: public Expression getExpression() {
46: return _expr;
47: }
48:
49: /**
50: * Returns whether this ordering is ascending or descending.
51: *
52: * @return <code>true</code> if the ordering is ascending
53: */
54: public boolean isAscending() {
55: return _isAscending;
56: }
57:
58: /* (non-Javadoc)
59: * @see org.apache.ojb.jdo.jdoql.Acceptor#accept(org.apache.ojb.jdo.jdoql.Visitor)
60: */
61: public void accept(Visitor visitor) {
62: visitor.visit(this );
63: }
64:
65: /* (non-Javadoc)
66: * @see java.lang.Object#toString()
67: */
68: public String toString() {
69: return _expr.toString() + " "
70: + (_isAscending ? "ascending" : "descending");
71: }
72: }
|