KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > expressions > SQLStatement


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.expressions;
23
24 import java.io.*;
25 import oracle.toplink.essentials.internal.helper.*;
26 import oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl;
27 import oracle.toplink.essentials.expressions.*;
28 import oracle.toplink.essentials.internal.databaseaccess.DatabaseCall;
29 import oracle.toplink.essentials.internal.sessions.AbstractRecord;
30 import oracle.toplink.essentials.internal.sessions.AbstractSession;
31
32 /**
33  * <p><b>Purpose</b>: Mirror SQL behavior.
34  * <p><b>Responsibilities</b>:<ul>
35  * <li> Mirror SQL behavior.
36  * <li> Print as SQL string.
37  * </ul>
38  * @author Dorin Sandu
39  * @since TOPLink/Java 1.0
40  */

41 public abstract class SQLStatement implements Serializable, Cloneable JavaDoc {
42     protected Expression whereClause;
43     protected ExpressionBuilder builder;
44     protected AbstractRecord translationRow;
45
46     /**
47      * Return SQL call for the statement, through generating the SQL string.
48      */

49     public abstract DatabaseCall buildCall(AbstractSession session);
50
51     /**
52      * Clone the Statement
53      */

54     public Object JavaDoc clone() {
55         try {
56             return super.clone();
57         } catch (CloneNotSupportedException JavaDoc e) {
58             throw new InternalError JavaDoc();
59         }
60     }
61
62     public ExpressionBuilder getBuilder() {
63         return builder;
64     }
65
66     public ExpressionBuilder getExpressionBuilder() {
67         return builder;
68     }
69
70     /**
71      * INTERNAL:
72      * Return the row for translation
73      */

74     public AbstractRecord getTranslationRow() {
75         return translationRow;
76     }
77
78     public Expression getWhereClause() {
79         return whereClause;
80     }
81
82     protected void setBuilder(ExpressionBuilder aBuilder) {
83         builder = aBuilder;
84     }
85
86     /**
87      * INTERNAL:
88      * Set the row for translation
89      */

90     public void setTranslationRow(AbstractRecord theRow) {
91         translationRow = theRow;
92     }
93
94     public void setWhereClause(Expression expression) {
95         whereClause = expression;
96         if (expression != null) {
97             builder = expression.getBuilder();
98         }
99     }
100
101     /**
102      * Try to print the SQL.
103      */

104     public String JavaDoc toString() {
105         StringWriter writer = new StringWriter();
106         writer.write(Helper.getShortClassName(getClass()));
107         writer.write("(");
108
109         try {
110             DatabaseCall call = buildCall(new DatabaseSessionImpl(new oracle.toplink.essentials.sessions.DatabaseLogin()));
111             writer.write(call.getSQLString());
112         } catch (Exception JavaDoc exception) {
113         }
114         writer.write(")");
115
116         return writer.toString();
117     }
118 }
119
Popular Tags