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 Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.amber.expr;
030:
031: import com.caucho.amber.entity.EntityItem;
032: import com.caucho.amber.manager.AmberConnection;
033: import com.caucho.amber.query.FromItem;
034: import com.caucho.amber.query.QueryParseException;
035: import com.caucho.amber.query.QueryParser;
036: import com.caucho.amber.type.Type;
037: import com.caucho.util.CharBuffer;
038:
039: import java.sql.ResultSet;
040: import java.sql.SQLException;
041:
042: /**
043: * Represents an Amber query expression
044: */
045: public interface AmberExpr {
046: public final static int USES_DATA = 0;
047: public final static int IS_INNER_JOIN = 1;
048:
049: /**
050: * Returns true for a boolean expression.
051: */
052: boolean isBoolean();
053:
054: /**
055: * Returns the expr type.
056: */
057: Type getType();
058:
059: /**
060: * Binds the expression as a select item.
061: */
062: AmberExpr bindSelect(QueryParser parser);
063:
064: /**
065: * Returns true if the expression uses the from item.
066: */
067: boolean usesFrom(FromItem from, int type);
068:
069: /**
070: * Returns true if the expression uses the from item.
071: */
072: boolean usesFrom(FromItem from, int type, boolean isNot);
073:
074: /**
075: * Returns true if the item is required to exist by the expression, e.g.
076: * foo.id='1' forces foo to exist.
077: */
078: boolean exists(FromItem from);
079:
080: /**
081: * Returns true if the expression item is required to exist, e.g.
082: * constants and arguments.
083: *
084: * (Can also apply to arguments required to exist after a particular
085: * from item, i.e. from items already proved to exist.)
086: */
087: boolean exists();
088:
089: /**
090: * Returns true if the expression uses the from item.
091: */
092: AmberExpr replaceJoin(JoinExpr join);
093:
094: /**
095: * Generates the where expression.
096: */
097: void generateWhere(CharBuffer cb);
098:
099: /**
100: * Generates the (update) where expression.
101: */
102: void generateUpdateWhere(CharBuffer cb);
103:
104: /**
105: * Generates the having expression.
106: */
107: void generateHaving(CharBuffer cb);
108:
109: /**
110: * Generates the where expression.
111: */
112: void generateJoin(CharBuffer cb);
113:
114: /**
115: * Generates the select expression.
116: */
117: void generateSelect(CharBuffer cb);
118:
119: /**
120: * Converts to a boolean expression.
121: */
122: public AmberExpr createBoolean() throws QueryParseException;
123:
124: /**
125: * Returns the object for the expr.
126: */
127: public Object getObject(AmberConnection aConn, ResultSet rs,
128: int index) throws SQLException;
129:
130: /**
131: * Returns the cache object for the expr.
132: */
133: public Object getCacheObject(AmberConnection aConn, ResultSet rs,
134: int index) throws SQLException;
135:
136: /**
137: * Returns true if this expr has any relationship.
138: */
139: public boolean hasRelationship();
140:
141: /**
142: * Returns the object for the expr.
143: */
144: public EntityItem findItem(AmberConnection aConn, ResultSet rs,
145: int index) throws SQLException;
146:
147: /**
148: * Binds the argument type based on another expr.
149: */
150: public void setInternalArgType(AmberExpr otherExpr);
151: }
|