001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.db.sql;
030:
031: import com.caucho.log.Log;
032:
033: import java.sql.SQLException;
034: import java.util.ArrayList;
035: import java.util.logging.Logger;
036:
037: class LongExpr extends Expr {
038: private static final Logger log = Log.open(LongExpr.class);
039:
040: private long _value;
041:
042: LongExpr(long value) {
043: _value = value;
044: }
045:
046: /**
047: * Returns the type of the expression.
048: */
049: public Class getType() {
050: return long.class;
051: }
052:
053: /**
054: * Returns the cost based on the given FromList.
055: */
056: public long subCost(ArrayList<FromItem> fromList) {
057: return 0;
058: }
059:
060: /**
061: * Evaluates the expression as a long
062: *
063: * @param row the current data tuple
064: *
065: * @return the long value
066: */
067: public long evalLong(QueryContext context) throws SQLException {
068: return _value;
069: }
070:
071: /**
072: * Evaluates the expression as a date
073: *
074: * @param row the current data tuple
075: *
076: * @return the date value
077: */
078: public long evalDate(QueryContext context) throws SQLException {
079: return _value;
080: }
081:
082: /**
083: * Evaluates the expression as a double
084: *
085: * @param row the current data tuple
086: *
087: * @return the double value
088: */
089: public double evalDouble(QueryContext context) throws SQLException {
090: return _value;
091: }
092:
093: /**
094: * Evaluates the expression as a string
095: *
096: * @param row the current data tuple
097: *
098: * @return the string value
099: */
100: public String evalString(QueryContext context) throws SQLException {
101: return String.valueOf(_value);
102: }
103:
104: /**
105: * Evaluates the expression, writing to the result stream.
106: *
107: * @param context the query context
108: * @param result the output result
109: */
110: public void evalToResult(QueryContext context, SelectResult result) {
111: result.writeLong(_value);
112: }
113:
114: public String toString() {
115: return String.valueOf(_value);
116: }
117: }
|