Source code: javatools/db/DbOrderBy.java
1 /*
2 Javatools (modified version) - Some useful general classes.
3 Copyright (C) 2002-2003 Chris Bitmead (original) Antonio Petrelli (modified)
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Contact me at: brenmcguire@users.sourceforge.net
20 */
21 package javatools.db;
22
23 /**
24 * A class that represents an ORDER BY clause in a SELECT.
25 *
26 * An order by clause consists of a column and an optional DESC descending
27 * clause.
28 *
29 * Usually this class will not be referred to directly in an application.
30 * More usually you will use DbSelector.addOrderBy().
31 *
32 * @author Chris Bitmead
33 * @version 0.7
34 * @commentedby Antonio Petrelli
35 */
36
37 public class DbOrderBy {
38 /** <CODE>true</CODE>: if the order is descending;
39 * <CODE>false</CODE>: if the order is ascending.
40 */
41 boolean descending;
42 /** The column to be used for sorting.
43 */
44 DbExpr column;
45
46 /** Creates a new DbOrderBy expression.
47 * @param column The column to be used for sorting.
48 * @param descending <CODE>true</CODE>: if the order is descending;
49 * <CODE>false</CODE>: if the order is ascending.
50 */
51 public DbOrderBy(DbExpr column, boolean descending) {
52 this.column = column;
53 this.descending = descending;
54 }
55
56 /**
57 * Is this clause descending order?
58 * @return <CODE>true</CODE>: if the order is descending;
59 * <CODE>false</CODE>: if the order is ascending.
60 */
61 public boolean getDescending() {
62 return descending;
63 }
64
65 /**
66 * The column to sort on.
67 * @return The column.
68 */
69 public DbExpr getColumn() {
70 return column;
71 }
72
73 /** Returns the query string related to these expression.
74 * @throws DbException If something goes wrong.
75 * @return The requested query string.
76 */
77 public String getQueryString() throws DbException {
78 String rtn = column.getQueryString();
79 if (descending) {
80 rtn += " DESC";
81 }
82 return rtn;
83 }
84 }