001: /**********************************************************************
002: Copyright (c) 2003 Andy Jefferson 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: import java.util.List;
020:
021: import org.jpox.store.mapping.JavaTypeMapping;
022:
023: /**
024: * Representation of an expression with an SQL time type (SQLDate, SQLTime,
025: * SQLTimestamp)
026: *
027: * @version $Revision: 1.10 $
028: **/
029: public class SqlTemporalExpression extends ScalarExpression {
030: protected SqlTemporalExpression(QueryExpression qs) {
031: super (qs);
032: }
033:
034: /**
035: *
036: * @param qs the QueryExpression
037: * @param mapping the mapping associated to this expression
038: * @param te the TableExpression where this expression refers to
039: */
040: public SqlTemporalExpression(QueryExpression qs,
041: JavaTypeMapping mapping, LogicSetExpression te) {
042: super (qs, mapping, te);
043: }
044:
045: /**
046: * Generates statement as "FUNCTION_NAME"
047: * @param functionName
048: * @param qs QueryExpression
049: */
050: public SqlTemporalExpression(String functionName, QueryExpression qs) {
051: super (qs);
052: st.append(functionName);
053: }
054:
055: /**
056: * Generates statement as e.g. FUNCTION_NAME(arg[,argN])
057: * @param functionName
058: * @param args ScalarExpression list
059: */
060: public SqlTemporalExpression(String functionName, List args) {
061: super (functionName, args);
062: }
063:
064: /**
065: * Performs a function on two arguments.
066: * op(operand1,operand2)
067: * operand1 op operand2
068: * @param operand1 the first expression
069: * @param op the operator between operands
070: * @param operand2 the second expression
071: */
072: public SqlTemporalExpression(ScalarExpression operand1,
073: DyadicOperator op, ScalarExpression operand2) {
074: super (operand1, op, operand2);
075: }
076:
077: public BooleanExpression eq(ScalarExpression expr) {
078: if (expr instanceof NullLiteral) {
079: return expr.eq(this );
080: } else if (expr instanceof SqlTemporalExpression) {
081: return new BooleanExpression(this , OP_EQ, expr);
082: } else {
083: return super .eq(expr);
084: }
085: }
086:
087: public BooleanExpression noteq(ScalarExpression expr) {
088: if (expr instanceof NullLiteral) {
089: return expr.noteq(this );
090: } else if (expr instanceof SqlTemporalExpression) {
091: return new BooleanExpression(this , OP_NOTEQ, expr);
092: } else {
093: return super .noteq(expr);
094: }
095: }
096:
097: public BooleanExpression lt(ScalarExpression expr) {
098: if (expr instanceof SqlTemporalExpression) {
099: return new BooleanExpression(this , OP_LT, expr);
100: } else {
101: return super .lt(expr);
102: }
103: }
104:
105: public BooleanExpression lteq(ScalarExpression expr) {
106: if (expr instanceof SqlTemporalExpression) {
107: return new BooleanExpression(this , OP_LTEQ, expr);
108: } else {
109: return super .lteq(expr);
110: }
111: }
112:
113: public BooleanExpression gt(ScalarExpression expr) {
114: if (expr instanceof SqlTemporalExpression) {
115: return new BooleanExpression(this , OP_GT, expr);
116: } else {
117: return super .gt(expr);
118: }
119: }
120:
121: public BooleanExpression gteq(ScalarExpression expr) {
122: if (expr instanceof SqlTemporalExpression) {
123: return new BooleanExpression(this , OP_GTEQ, expr);
124: } else {
125: return super .gteq(expr);
126: }
127: }
128:
129: public BooleanExpression in(ScalarExpression expr) {
130: return new BooleanExpression(this , OP_IN, expr);
131: }
132:
133: /**
134: * Method to return an expression for the day of the month (for this date).
135: * @return The expression for the day of the month.
136: **/
137: public NumericExpression getDayMethod() {
138: return qs.getStoreManager().getDatastoreAdapter().getDayMethod(
139: this );
140: }
141:
142: /**
143: * Method to return an expression for the month (for this date).
144: * @return The expression for the month.
145: **/
146: public NumericExpression getMonthMethod() {
147: return qs.getStoreManager().getDatastoreAdapter()
148: .getMonthMethod(this );
149: }
150:
151: /**
152: * Method to return an expression for the year (for this date).
153: * @return The expression for the year.
154: **/
155: public NumericExpression getYearMethod() {
156: return qs.getStoreManager().getDatastoreAdapter()
157: .getYearMethod(this );
158: }
159:
160: /**
161: * Method to return an expression for the hour (for this time).
162: * @return The expression for the hour.
163: **/
164: public NumericExpression getHourMethod() {
165: return qs.getStoreManager().getDatastoreAdapter()
166: .getHourMethod(this );
167: }
168:
169: /**
170: * Method to return an expression for the minute (for this time).
171: * @return The expression for the month.
172: **/
173: public NumericExpression getMinuteMethod() {
174: return qs.getStoreManager().getDatastoreAdapter()
175: .getMinuteMethod(this );
176: }
177:
178: /**
179: * Method to return an expression for the second (for this time).
180: * @return The expression for the second.
181: **/
182: public NumericExpression getSecondMethod() {
183: return qs.getStoreManager().getDatastoreAdapter()
184: .getSecondMethod(this);
185: }
186: }
|