001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.sqlParser;
034:
035: /**
036: * OrderBy
037: *
038: * @author Gregor Schober (gregor.schober@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
039: */
040: public class OrderByValue extends Constant {
041:
042: private boolean ascending;
043: private SelectedValue sv;
044: private int columnIndex = -1;
045:
046: /**
047: * Constructor.
048: *
049: * @param ascending true if ascending, false if descending
050: * @param value the value
051: * @throws SqlParserException if a error occured
052: */
053: public OrderByValue(String value, boolean ascending)
054: throws SqlParserException {
055: super (value);
056: this .ascending = ascending;
057: }
058:
059: /**
060: * Internal setter for the selected value belonging to this order by.
061: *
062: * @param val the selected value
063: * @param columnIndex the index of the column to sort
064: */
065: protected void setSelectedValue(SelectedValue val, int columnIndex) {
066: this .sv = val;
067: this .columnIndex = columnIndex;
068: }
069:
070: /**
071: * Returns the selected value belonging to this order by.
072: *
073: * @return the selected value belonging to this order by
074: */
075: public SelectedValue getSelectedValue() {
076: return sv;
077: }
078:
079: /**
080: * The position of the column to sort in the selected values list, 0 based.
081: *
082: * @return The position of the column to sort in the selected values list
083: */
084: public int getColumnIndex() {
085: return columnIndex;
086: }
087:
088: /**
089: * Returns the sort order for this element (ascending or descending)
090: *
091: * @return true if ascending, false if descending
092: */
093: public boolean isAscending() {
094: return ascending;
095: }
096:
097: public String toString() {
098: return super .toString() + " "
099: + (this .ascending ? "asc" : "desc");
100: }
101: }
|