001: /**********************************************************************
002: Copyright (c) 2005 Erik Bengtson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015: Contributors:
016: ...
017: **********************************************************************/package org.jpox.store.expression;
018:
019: /**
020: * Interface that allows one datastore adapt operations
021: * @version $Revision: 1.11 $
022: */
023: public interface ExpressionMethodAdapter {
024: /**
025: * Returns the absolute expression for the JDOQL Math.abs(EXPRESSION)
026: * method.
027: * In SQL, it may compile to:
028: * <p>
029: * <blockquote><pre>
030: * ABS(str)
031: * </pre></blockquote>
032: *
033: * @param expr The argument to the abs() method.
034: * @return The expression.
035: */
036: NumericExpression absMethod(ScalarExpression expr);
037:
038: /**
039: * Returns the expression for the JDOQL Math.sqrt(EXPRESSION)
040: * method.
041: * In SQL, it may compile to:
042: * <p>
043: * <blockquote><pre>
044: * SQRT(str)
045: * </pre></blockquote>
046: *
047: * @param expr The argument to the sqrt() method.
048: * @return The expression.
049: */
050: NumericExpression sqrtMethod(ScalarExpression expr);
051:
052: /**
053: * Returns the expression for the JDOQL Math.cos(EXPRESSION)
054: * method.
055: * In SQL, it may compile to:
056: * <p>
057: * <blockquote><pre>
058: * COS(str)
059: * </pre></blockquote>
060: *
061: * @param expr The argument to the cos() method.
062: * @return The expression.
063: */
064: NumericExpression cosMethod(ScalarExpression expr);
065:
066: /**
067: * Returns the expression for the JDOQL Math.sin(EXPRESSION)
068: * method.
069: * In SQL, it may compile to:
070: * <p>
071: * <blockquote><pre>
072: * SIN(str)
073: * </pre></blockquote>
074: *
075: * @param expr The argument to the sin() method.
076: * @return The expression.
077: */
078: NumericExpression sinMethod(ScalarExpression expr);
079:
080: /**
081: * Returns the expression for the JDOQL Math.tan(EXPRESSION)
082: * method.
083: * In SQL, it may compile to:
084: * <p>
085: * <blockquote><pre>
086: * TAN(str)
087: * </pre></blockquote>
088: *
089: * @param expr The argument to the tan() method.
090: * @return The expression.
091: */
092: NumericExpression tanMethod(ScalarExpression expr);
093:
094: /**
095: * Returns the expression for the JDOQL Math.acos(EXPRESSION)
096: * method.
097: * In SQL, it may compile to:
098: * <p>
099: * <blockquote><pre>
100: * ACOS(str)
101: * </pre></blockquote>
102: *
103: * @param expr The argument to the cos() method.
104: * @return The expression.
105: */
106: NumericExpression acosMethod(ScalarExpression expr);
107:
108: /**
109: * Returns the expression for the JDOQL Math.asin(EXPRESSION)
110: * method.
111: * In SQL, it may compile to:
112: * <p>
113: * <blockquote><pre>
114: * ASIN(str)
115: * </pre></blockquote>
116: *
117: * @param expr The argument to the asin() method.
118: * @return The expression.
119: */
120: NumericExpression asinMethod(ScalarExpression expr);
121:
122: /**
123: * Returns the expression for the JDOQL Math.tan(EXPRESSION)
124: * method.
125: * In SQL, it may compile to:
126: * <p>
127: * <blockquote><pre>
128: * ATAN(str)
129: * </pre></blockquote>
130: *
131: * @param expr The argument to the atan() method.
132: * @return The expression.
133: */
134: NumericExpression atanMethod(ScalarExpression expr);
135:
136: /**
137: * Returns whether this string ends with the specified string.
138: * @param leftOperand the source string
139: * @param rightOperand The string to compare against.
140: * @return Whether it ends with the string.
141: **/
142: BooleanExpression endsWithMethod(ScalarExpression leftOperand,
143: ScalarExpression rightOperand);
144:
145: /**
146: * Returns the expression for the JDOQL Math.exp(EXPRESSION)
147: * method.
148: * In SQL, it may compile to:
149: * <p>
150: * <blockquote><pre>
151: * EXP(str)
152: * </pre></blockquote>
153: *
154: * @param expr The argument to the exp() method.
155: * @return The expression.
156: */
157: NumericExpression expMethod(ScalarExpression expr);
158:
159: /**
160: * Returns the expression for the JDOQL Math.log(EXPRESSION)
161: * method.
162: * In SQL, it may compile to:
163: * <p>
164: * <blockquote><pre>
165: * LOG(str)
166: * </pre></blockquote>
167: *
168: * @param expr The argument to the log() method.
169: * @return The expression.
170: */
171: NumericExpression logMethod(ScalarExpression expr);
172:
173: /**
174: * Returns the expression for the JDOQL Math.floor(EXPRESSION)
175: * method.
176: * In SQL, it may compile to:
177: * <p>
178: * <blockquote><pre>
179: * FLOOR(str)
180: * </pre></blockquote>
181: *
182: * @param expr The argument to the floor() method.
183: * @return The expression.
184: */
185: NumericExpression floorMethod(ScalarExpression expr);
186:
187: /**
188: * Returns the expression for the JDOQL Math.ceil(EXPRESSION)
189: * method.
190: * In SQL, it may compile to:
191: * <p>
192: * <blockquote><pre>
193: * CEIL(str)
194: * </pre></blockquote>
195: *
196: * @param expr The argument to the ceil() method.
197: * @return The expression.
198: */
199: NumericExpression ceilMethod(ScalarExpression expr);
200:
201: /**
202: * Returns the expression for the JDOQL String.length()
203: * method.
204: * In SQL, it may compile to:
205: * <p>
206: * <blockquote><pre>
207: * CHAR_LENGTH(str)
208: * </pre></blockquote>
209: *
210: * @param str The argument to the length() method.
211: * @return The expression.
212: */
213: NumericExpression lengthMethod(StringExpression str);
214:
215: /**
216: * Returns the expression for the JDOQL
217: * String.substring(str,begin) method.
218: * In SQL, it may compile to:
219: * <p>
220: * <pre>
221: * SUBSTRING(str FROM begin)
222: * </pre>
223: * Note that the value of <var>begin</var> is base 0(Java-style), while most
224: * SQL string functions use base 1.
225: *
226: * @param str The first argument to the substring() method.
227: * @param begin The second argument to the substring() method.
228: * @return The expression.
229: */
230: StringExpression substringMethod(StringExpression str,
231: NumericExpression begin);
232:
233: /**
234: * Returns the expression for the JDOQL
235: * String.substring(str,begin,end) method.
236: * In SQL, it may compile to:
237: * <p>
238: * <blockquote><pre>
239: * SUBSTRING(str FROM begin FOR len)
240: * </pre></blockquote>
241: * Note that the value of <var>begin</var> is base 0 (Java-style), while most
242: * SQL string functions use base 1.
243: * Note also that an end position is given, while most SQL substring
244: * functions take a length.
245: *
246: * @param str The first argument to the substring() method.
247: * @param begin The second argument to the substring() method.
248: * @param end The third argument to the substring() method.
249: * @return The expression.
250: */
251: StringExpression substringMethod(StringExpression str,
252: NumericExpression begin, NumericExpression end);
253:
254: /**
255: * Method to handle the starts with operation.
256: * @param source The expression with the searched string
257: * @param str The expression for the search string
258: * @return The expression.
259: **/
260: BooleanExpression startsWithMethod(ScalarExpression source,
261: ScalarExpression str);
262:
263: /**
264: * Method to handle the indexOf operation.
265: * @param source The expression with the searched string
266: * @param str The expression for the search string
267: * @param from Position to start searching from
268: * @return The expression.
269: **/
270: NumericExpression indexOfMethod(ScalarExpression source,
271: ScalarExpression str, NumericExpression from);
272:
273: /**
274: * Returns the expression for the JDOQL String.trim(str) method.
275: * In SQL, it may compile to:
276: * <pre>TRIM(str)</pre>
277: * @param str The first argument to the trim() method.
278: * @param leading Whether to trim leading spaces
279: * @param trailing Whether to trim trailing spaces
280: * @return The expression.
281: */
282: StringExpression trimMethod(StringExpression str, boolean leading,
283: boolean trailing);
284:
285: /**
286: * Method to handle the Date.getDay() method in JDOQL.
287: * @param source The date expression to find the day of month for
288: * @return The expression for the day of the month.
289: **/
290: NumericExpression getDayMethod(SqlTemporalExpression source);
291:
292: /**
293: * Method to handle the Date.getMonth() method in JDOQL.
294: * @param source The date expression to find the month for
295: * @return The expression for the month.
296: **/
297: NumericExpression getMonthMethod(SqlTemporalExpression source);
298:
299: /**
300: * Method to handle the Date.getYear() method in JDOQL.
301: * @param source The date expression to find the year for
302: * @return The expression for the year.
303: **/
304: NumericExpression getYearMethod(SqlTemporalExpression source);
305:
306: /**
307: * Method to handle the Time.getHour() method in JDOQL.
308: * @param source The time expression to find the hour for
309: * @return The expression for the hour.
310: **/
311: NumericExpression getHourMethod(SqlTemporalExpression source);
312:
313: /**
314: * Method to handle the Time.getMinute() method in JDOQL.
315: * @param source The time expression to find the minute for
316: * @return The expression for the minute.
317: **/
318: NumericExpression getMinuteMethod(SqlTemporalExpression source);
319:
320: /**
321: * Method to handle the Time.getSecond() method in JDOQL.
322: * @param source The time expression to find the second for
323: * @return The expression for the second.
324: **/
325: NumericExpression getSecondMethod(SqlTemporalExpression source);
326:
327: /**
328: * Matches this to the argument expression pattern. Use "." to find any
329: * character and ".*" for wildcard matches. A global case-insensitive flag
330: * "(?i)" can be set for the pattern. If used, the global case-insensitive
331: * flag must prefix the pattern. The pattern passed to matches must be a
332: * literal or parameter.
333: * @param text The argument to the length() method.
334: * @param pattern The literal expression with the pattern.
335: * @return the match expression.
336: */
337: BooleanExpression matchesMethod(StringExpression text,
338: StringExpression pattern);
339:
340: /**
341: * Method to translate all chars in this expression to the <code>fromExpr</code> which
342: * corresponds to <code>toExpr</code>.
343: * @return The expression.
344: **/
345: StringExpression translateMethod(ScalarExpression expr,
346: ScalarExpression toExpr, ScalarExpression fromExpr);
347:
348: /**
349: * Method to return an expression for the current date in the datastore.
350: * @param qs QueryExpression
351: * @return Current date expression for this datastore
352: */
353: ScalarExpression getCurrentDateMethod(QueryExpression qs);
354:
355: /**
356: * Method to return an expression for the current time in the datastore.
357: * @param qs QueryExpression
358: * @return Current time expression for this datastore
359: */
360: ScalarExpression getCurrentTimeMethod(QueryExpression qs);
361:
362: /**
363: * Method to return an expression for the current timestamp in the datastore.
364: * @param qs QueryExpression
365: * @return Current timestamp expression for this datastore
366: */
367: ScalarExpression getCurrentTimestampMethod(QueryExpression qs);
368: }
|