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.ejb.ql;
030:
031: import com.caucho.config.ConfigException;
032: import com.caucho.ejb.cfg.*;
033: import com.caucho.util.IntArray;
034:
035: /**
036: * A select/find query
037: */
038: class Query {
039: final static int IDENTIFIER = 128;
040: final static int INTEGER = IDENTIFIER + 1;
041: final static int LONG = INTEGER + 1;
042: final static int DOUBLE = LONG + 1;
043: final static int STRING = DOUBLE + 1;
044: final static int TRUE = STRING + 1;
045: final static int FALSE = TRUE + 1;
046: final static int UNKNOWN = FALSE + 1;
047: final static int MEMBER = UNKNOWN + 1;
048: final static int OF = MEMBER + 1;
049: final static int EMPTY = OF + 1;
050: final static int NULL = EMPTY + 1;
051:
052: final static int FROM = NULL + 1;
053: final static int IN = FROM + 1;
054: final static int SELECT = IN + 1;
055: final static int DISTINCT = SELECT + 1;
056: final static int WHERE = SELECT + 1;
057: final static int AS = WHERE + 1;
058: final static int ORDER = AS + 1;
059: final static int BY = ORDER + 1;
060: final static int ASC = BY + 1;
061: final static int DESC = ASC + 1;
062: final static int LIMIT = DESC + 1;
063: final static int OFFSET = LIMIT + 1;
064:
065: final static int BETWEEN = OFFSET + 1;
066: final static int LIKE = BETWEEN + 1;
067: final static int ESCAPE = LIKE + 1;
068: final static int IS = ESCAPE + 1;
069:
070: final static int EQ = IS + 1;
071: final static int NE = EQ + 1;
072: final static int LT = NE + 1;
073: final static int LE = LT + 1;
074: final static int GT = LE + 1;
075: final static int GE = GT + 1;
076:
077: final static int AND = GE + 1;
078: final static int OR = AND + 1;
079: final static int NOT = OR + 1;
080:
081: final static int EXTERNAL_DOT = NOT + 1;
082:
083: final static int ARG = EXTERNAL_DOT + 1;
084: final static int THIS = ARG + 1;
085:
086: private ApiMethod _method;
087: private EjbConfig _config;
088:
089: private IntArray _argSize = new IntArray();
090:
091: ApiMethod getMethod() {
092: return _method;
093: }
094:
095: void setMethod(ApiMethod method) {
096: _method = method;
097: }
098:
099: void setConfig(EjbConfig config) {
100: _config = config;
101: }
102:
103: EjbConfig getConfig() {
104: return _config;
105: }
106:
107: /**
108: * Sets the number of sub-arguments for an arg.
109: */
110: public void setArgSize(int index, int size) {
111: while (_argSize.size() < index) {
112: _argSize.add(0);
113: }
114:
115: _argSize.set(index - 1, size);
116: }
117:
118: /**
119: * Sets the number of sub-arguments for an arg.
120: */
121: public int getArgIndex(int index) {
122: int size = 1;
123:
124: for (int i = 0; i < index - 1; i++) {
125: size += _argSize.get(i);
126: }
127:
128: return size;
129: }
130:
131: /**
132: * Creates an error.
133: */
134: public ConfigException error(String msg) {
135: return new ConfigException(msg);
136: /*
137: msg += "\nin \"" + _query + "\"";
138: if (_qlConfig != null)
139: return new SelectLineParseException(_qlConfig.getFilename() + ":" +
140: _qlConfig.getLine() + ": " +
141: msg);
142: else if (_location != null)
143: return new SelectLineParseException(_location + msg);
144: else
145: return new SelectParseException(msg);
146: */
147: }
148: }
|