KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > parsing > DateFunctionNode


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.parsing;
23
24 import java.sql.Date JavaDoc;
25 import java.sql.Time JavaDoc;
26 import java.sql.Timestamp JavaDoc;
27
28 import oracle.toplink.essentials.queryframework.ObjectLevelReadQuery;
29 import oracle.toplink.essentials.queryframework.ReportQuery;
30 import oracle.toplink.essentials.expressions.*;
31
32 /**
33  * INTERNAL
34  * <p><b>Purpose</b>: Represent a date function: CURRENT_DATE, CURRENT_TIME,
35  * CURRENT_TIMESTAMP.
36  * <p><b>Responsibilities</b>:<ul>
37  * <li> Generate the correct expression for the date function
38  * </ul>
39  */

40 public class DateFunctionNode extends FunctionalExpressionNode {
41
42     private Class JavaDoc type;
43
44     /**
45      * DateFunctionNode constructor.
46      */

47     public DateFunctionNode() {
48         super();
49     }
50
51     /**
52      * INTERNAL
53      * Apply this node to the passed query
54      */

55     public void applyToQuery(ObjectLevelReadQuery theQuery, GenerationContext context) {
56         if (theQuery.isReportQuery()){
57             ReportQuery reportQuery = (ReportQuery)theQuery;
58             reportQuery.addAttribute("date", generateExpression(context), type);
59         }
60     }
61
62     /**
63      * INTERNAL
64      * Validate node and calculate its type.
65      */

66     public void validate(ParseTreeContext context) {
67         setType(type);
68     }
69
70     /**
71      * INTERNAL
72      * Generate the TopLink expression for this node
73      */

74     public Expression generateExpression(GenerationContext context) {
75         Expression expr = context.getBaseExpression();
76         if (expr == null) {
77             expr = new ExpressionBuilder();
78         }
79         return expr.currentDateDate();
80     }
81
82     /** */
83     public void useCurrentDate() {
84         type = Date JavaDoc.class;
85     }
86
87     /** */
88     public void useCurrentTime() {
89         type = Time JavaDoc.class;
90     }
91
92     /** */
93     public void useCurrentTimestamp() {
94         type = Timestamp JavaDoc.class;
95     }
96     
97 }
98
Popular Tags