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: * Every expression written in the Java programming language has a type that can
021: * be deduced from the structure of the expression and the types of the
022: * literals, variables, and methods mentioned in the expression. It is possible,
023: * however, to write an expression in a context where the type of the expression
024: * is not appropriate. In some cases, this leads to an error at compile time. In
025: * other cases, the context may be able to accept a type that is related to the
026: * type of the expression; as a convenience, rather than requiring the
027: * programmer to indicate a type conversion explicitly, the language performs an
028: * implicit conversion from the type of the expression to a type acceptable for
029: * its surrounding context.
030: * <p>
031: * Supported conversion types:
032: * <ul>
033: * <li>Widening conversion</li>
034: * <li>String conversion</li>
035: * </ul>
036: * </p>
037: * <h4>Widening conversion</h4>
038: * <p>
039: * Widening conversions do not lose information about the overall magnitude of a
040: * numeric value.
041: * </p>
042: * <h4>String conversion</h4>
043: * <p>
044: * If only one operand expression is of type String, then string conversion is
045: * performed on the other operand to produce a string at run time. The result is
046: * a reference to a String object (newly created, unless the expression is a
047: * compile-time constant expression (§15.28))that is the concatenation of the
048: * two operand strings. The characters of the left-hand operand precede the
049: * characters of the right-hand operand in the newly created string. If an
050: * operand of type String is null, then the string "null" is used instead of
051: * that operand.
052: * </p>
053: * @version $Revision: 1.2 $
054: */
055: public interface ExpressionConversionAdapter {
056: /**
057: * A Widening conversion that returns the appropriate expression for the
058: * <code>(int)'A'</code> expression. In SQL, it should compile something
059: * like:
060: * <p>
061: * <blockquote>
062: * <pre>
063: * ASCII('A')
064: * </pre>
065: * </blockquote>
066: * </p>
067: * @param expr The CharacterExpression
068: * @return The NumericExpression
069: */
070: NumericExpression toNumericExpression(CharacterExpression expr);
071:
072: /**
073: * A String conversion that converts a numeric expression to string.
074: * If the expr argument represents a Literal value, converts to a Literal string.
075: * In SQL, it should compile something like:
076: * <p>
077: * <blockquote>
078: * <pre>
079: * CAST(999999 AS VARCHAR(4000))
080: * </pre>
081: * </blockquote>
082: * </p>
083: * @param expr The NumericExpression
084: * @return the StringExpression
085: */
086: StringExpression toStringExpression(NumericExpression expr);
087:
088: /**
089: * A String conversion that converts a String literal to String expression. It will allow
090: * the String to be evaluated only at runtime.
091: * In SQL, it should compile something like:
092: * <p>
093: * <blockquote>
094: * <pre>
095: * CAST('value' AS VARCHAR(4000))
096: * </pre>
097: * </blockquote>
098: * </p>
099: * @param expr The StringLiteral
100: * @return the StringExpression
101: */
102: StringExpression toStringExpression(StringLiteral expr);
103: }
|