KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.*;
26 import oracle.toplink.essentials.internal.helper.*;
27 import oracle.toplink.essentials.expressions.*;
28
29 public class TableExpression extends DataExpression {
30     protected DatabaseTable table;
31
32     /**
33      * TableExpression constructor comment.
34      */

35     public TableExpression() {
36         super();
37     }
38
39     /**
40      * TableExpression constructor comment.
41      */

42     public TableExpression(DatabaseTable aTable) {
43         super();
44         table = aTable;
45     }
46
47     /**
48      * INTERNAL:
49      * Used for debug printing.
50      */

51     public String JavaDoc descriptionOfNodeType() {
52         return "Table";
53     }
54
55     /**
56      * INTERNAL:
57      * Fully-qualify the databaseField if the table is known.
58      * CR 3791
59      */

60     public Expression getField(String JavaDoc fieldName) {
61         // we need to check for full table qualification
62
DatabaseField field = new DatabaseField(fieldName);
63         if (!field.hasTableName()) {
64             field.setTable(getTable());
65         }
66         return getField(field);
67     }
68
69     /**
70      * INTERNAL:
71      */

72     public Vector getOwnedTables() {
73         Vector result = new Vector(1);
74         result.addElement(getTable());
75         return result;
76     }
77
78     public DatabaseTable getTable() {
79         return table;
80     }
81
82     public boolean isTableExpression() {
83         return true;
84     }
85
86     /**
87      * INTERNAL:
88      * Normalize the expression into a printable structure.
89      * Any joins must be added to form a new root.
90      */

91     public Expression normalize(ExpressionNormalizer normalizer) {
92         //Bug4736461 Only setTableQualifier if getDatasourceLogin().getTableQualifier() is an empty string to make the window much smaller when
93
//DatabaseTable.qualifiedName is reset
94
if (getTable().getTableQualifier().length() == 0 && (normalizer.getSession().getDatasourceLogin().getTableQualifier().length() != 0)) {
95             getTable().setTableQualifier(normalizer.getSession().getDatasourceLogin().getTableQualifier());
96         }
97         return super.normalize(normalizer);
98     }
99
100     /**
101      * INTERNAL:
102      * This expression is built on a different base than the one we want. Rebuild it and
103      * return the root of the new tree
104      */

105     public Expression rebuildOn(Expression newBase) {
106         Expression newLocalBase = getBaseExpression().rebuildOn(newBase);
107         return newLocalBase.getTable(getTable());
108
109     }
110
111     /**
112      * INTERNAL:
113      * Added for temporal querying.
114      */

115     public void setTable(DatabaseTable table) {
116         this.table = table;
117     }
118
119     /**
120      * INTERNAL:
121      * Rebuild myself against the base, with the values of parameters supplied by the context
122      * expression. This is used for transforming a standalone expression (e.g. the join criteria of a mapping)
123      * into part of some larger expression. You normally would not call this directly, instead calling twist
124      * See the comment there for more details"
125      */

126     public Expression twistedForBaseAndContext(Expression newBase, Expression context) {
127         Expression twistedBase = getBaseExpression().twistedForBaseAndContext(newBase, context);
128         return twistedBase.getTable(getTable());
129
130     }
131
132     /**
133      * INTERNAL:
134      * Used to print a debug form of the expression tree.
135      */

136     public void writeDescriptionOn(BufferedWriter writer) throws IOException {
137         writer.write(getTable().toString());
138         writer.write(tableAliasesDescription());
139     }
140 }
141
Popular Tags