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.db.table.Table;
032: import com.caucho.db.table.TableIterator;
033: import com.caucho.log.Log;
034:
035: import java.sql.SQLException;
036: import java.util.logging.Logger;
037:
038: class OidExpr extends Expr {
039: private static final Logger log = Log.open(OidExpr.class);
040:
041: private Table _table;
042:
043: private int _tableIndex;
044:
045: OidExpr(Table table, int tableIndex) {
046: _table = table;
047: _tableIndex = tableIndex;
048: }
049:
050: public Class getType() {
051: return long.class;
052: }
053:
054: /**
055: * Returns any column name.
056: */
057: public String getName() {
058: return "resin_oid";
059: }
060:
061: /**
062: * Returns the column's table.
063: */
064: public Table getTable() {
065: return _table;
066: }
067:
068: /**
069: * Returns true if the expression is null.
070: */
071: public boolean isNull(QueryContext context) throws SQLException {
072: return false;
073: }
074:
075: /**
076: * Evaluates the expression as a string.
077: */
078: public String evalString(QueryContext context) throws SQLException {
079: TableIterator[] rows = context.getTableIterators();
080: TableIterator row = rows[_tableIndex];
081:
082: return String.valueOf(row.getRowAddress());
083: }
084:
085: public int evalInt(QueryContext context) throws SQLException {
086: TableIterator[] rows = context.getTableIterators();
087: TableIterator row = rows[_tableIndex];
088:
089: return (int) row.getRowAddress();
090: }
091:
092: public long evalLong(QueryContext context) throws SQLException {
093: TableIterator[] rows = context.getTableIterators();
094: TableIterator row = rows[_tableIndex];
095:
096: return row.getRowAddress();
097: }
098:
099: public double evalDouble(QueryContext context) throws SQLException {
100: TableIterator[] rows = context.getTableIterators();
101: TableIterator row = rows[_tableIndex];
102:
103: return row.getRowAddress();
104: }
105:
106: public String toString() {
107: return "OidExpr[" + _tableIndex + "]";
108: }
109: }
|