KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > db > sql > OidExpr


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.db.sql;
30
31 import com.caucho.db.table.Table;
32 import com.caucho.db.table.TableIterator;
33 import com.caucho.log.Log;
34
35 import java.sql.SQLException JavaDoc;
36 import java.util.logging.Logger JavaDoc;
37
38 class OidExpr extends Expr {
39   private static final Logger JavaDoc log = Log.open(OidExpr.class);
40
41   private Table _table;
42   
43   private int _tableIndex;
44   
45   OidExpr(Table table, int tableIndex)
46   {
47     _table = table;
48     _tableIndex = tableIndex;
49   }
50
51   public Class JavaDoc getType()
52   {
53     return long.class;
54   }
55
56   /**
57    * Returns any column name.
58    */

59   public String JavaDoc getName()
60   {
61     return "resin_oid";
62   }
63
64   /**
65    * Returns the column's table.
66    */

67   public Table getTable()
68   {
69     return _table;
70   }
71
72   /**
73    * Returns true if the expression is null.
74    */

75   public boolean isNull(QueryContext context)
76     throws SQLException JavaDoc
77   {
78     return false;
79   }
80
81   /**
82    * Evaluates the expression as a string.
83    */

84   public String JavaDoc evalString(QueryContext context)
85     throws SQLException JavaDoc
86   {
87     TableIterator []rows = context.getTableIterators();
88     TableIterator row = rows[_tableIndex];
89
90     return String.valueOf(row.getRowAddress());
91   }
92
93   public int evalInt(QueryContext context)
94     throws SQLException JavaDoc
95   {
96     TableIterator []rows = context.getTableIterators();
97     TableIterator row = rows[_tableIndex];
98
99     return (int) row.getRowAddress();
100   }
101
102   public long evalLong(QueryContext context)
103     throws SQLException JavaDoc
104   {
105     TableIterator []rows = context.getTableIterators();
106     TableIterator row = rows[_tableIndex];
107
108     return row.getRowAddress();
109   }
110
111   public double evalDouble(QueryContext context)
112     throws SQLException JavaDoc
113   {
114     TableIterator []rows = context.getTableIterators();
115     TableIterator row = rows[_tableIndex];
116
117     return row.getRowAddress();
118   }
119
120   public String JavaDoc toString()
121   {
122     return "OidExpr[" + _tableIndex + "]";
123   }
124 }
125
Popular Tags