File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\dml\SelectOrderBy.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.command.dml;
8
9 import org.h2.expression.Expression;
10
11 /**
12 * Describes one element of the ORDER BY clause of a query.
13 */
14 public class SelectOrderBy {
15
16 /**
17 * The order by expression.
18 */
19 public Expression expression;
20
21 /**
22 * The column index expression. This can be a column index number (1 meaning
23 * the first column of the select list) or a parameter (the parameter is a
24 * number representing the column index number).
25 */
26 public Expression columnIndexExpr;
27
28 /**
29 * If the column should be sorted descending.
30 */
31 public boolean descending;
32
33 /**
34 * If NULL should be appear first.
35 */
36 public boolean nullsFirst;
37
38 /**
39 * If NULL should be appear at the end.
40 */
41 public boolean nullsLast;
42
43 public String getSQL() {
44 StringBuilder buff = new StringBuilder();
45 if (expression != null) {
46 buff.append('=').append(expression.getSQL());
47 } else {
48 buff.append(columnIndexExpr.getSQL());
49 }
50 if (descending) {
51 buff.append(" DESC");
52 }
53 if (nullsFirst) {
54 buff.append(" NULLS FIRST");
55 } else if (nullsLast) {
56 buff.append(" NULLS LAST");
57 }
58 return buff.toString();
59 }
60
61 }
62