KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > amber > query > FromItem


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free Software Foundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.amber.query;
30
31 import com.caucho.amber.entity.AmberEntityHome;
32 import com.caucho.amber.expr.CollectionIdExpr;
33 import com.caucho.amber.expr.IdExpr;
34 import com.caucho.amber.expr.JoinExpr;
35 import com.caucho.amber.expr.PathExpr;
36 import com.caucho.amber.table.Table;
37 import com.caucho.amber.type.EntityType;
38
39 public class FromItem {
40   private String JavaDoc _name;
41
42   private Table _table;
43
44   private AbstractQuery _query;
45
46   private PathExpr _collectionExpr;
47
48   private IdExpr _idExpr;
49
50   private int _index;
51
52   private JoinExpr _joinExpr;
53
54   private boolean _isUsed;
55
56   enum JoinSemantics { UNKNOWN, INNER, OUTER }
57
58   private JoinSemantics _joinSemantics
59     = JoinSemantics.UNKNOWN;
60
61   FromItem(Table table, String JavaDoc name, int index)
62   {
63     _table = table;
64     _name = name;
65     _index = index;
66   }
67
68   /**
69    * Sets the id expr.
70    */

71   public void setIdExpr(IdExpr idExpr)
72   {
73     _idExpr = idExpr;
74   }
75
76   /**
77    * Gets the id expr.
78    */

79   public IdExpr getIdExpr()
80   {
81     if (_idExpr != null) {
82     }
83     else if (_collectionExpr != null) {
84       _idExpr = new CollectionIdExpr(this, _collectionExpr);
85     }
86     else
87       _idExpr = new IdExpr(this);
88
89     return _idExpr;
90   }
91
92   /**
93    * Sets the collection expr.
94    */

95   public void setCollectionExpr(PathExpr collectionExpr)
96   {
97     _collectionExpr = collectionExpr;
98   }
99
100   /**
101    * Gets the id expr.
102    */

103   public PathExpr getCollectionExpr()
104   {
105     return _collectionExpr;
106   }
107
108   /**
109    * Returns the owning query.
110    */

111   public AbstractQuery getQuery()
112   {
113     return _query;
114   }
115
116   /**
117    * Sets the owning query.
118    */

119   public void setQuery(AbstractQuery query)
120   {
121     _query = query;
122   }
123
124   /**
125    * Returns the from item's name.
126    */

127   public String JavaDoc getName()
128   {
129     return _name;
130   }
131
132   /**
133    * Gets the entity class.
134    */

135   public EntityType getEntityType()
136   {
137     return (EntityType) getTableType();
138   }
139
140   /**
141    * Gets the table type
142    */

143   public EntityType getTableType()
144   {
145     return (EntityType) _table.getType();
146   }
147
148   /**
149    * Returns the table.
150    */

151   public Table getTable()
152   {
153     return _table;
154   }
155
156   /**
157    * Sets the table.
158    */

159   public void setTable(Table table)
160   {
161     _table = table;
162   }
163
164   /**
165    * Sets the join expr.
166    */

167   public void setJoinExpr(JoinExpr joinExpr)
168   {
169     _joinExpr = joinExpr;
170   }
171
172   /**
173    * Returns true if the from is used.
174    */

175   public boolean isUsed()
176   {
177     return _isUsed;
178   }
179
180   /**
181    * Returns true if the from is used.
182    */

183   public void setUsed(boolean isUsed)
184   {
185     _isUsed = isUsed;
186   }
187
188   /**
189    * Returns true if the from has no outer join.
190    */

191   public boolean isInnerJoin()
192   {
193     return _joinSemantics == JoinSemantics.INNER;
194   }
195
196   /**
197    * Returns true if the from needs an outer join.
198    */

199   public boolean isOuterJoin()
200   {
201     return _joinSemantics == JoinSemantics.OUTER;
202   }
203
204   /**
205    * Sets the join semantics.
206    */

207   public void setJoinSemantics(JoinSemantics joinSemantics)
208   {
209     _joinSemantics = joinSemantics;
210   }
211
212   /**
213    * Sets the join semantics to OUTER (true) or
214    * INNER (false).
215    */

216   public void setOuterJoin(boolean isOuterJoin)
217   {
218     _joinSemantics = isOuterJoin ?
219       JoinSemantics.OUTER : JoinSemantics.INNER;
220   }
221
222   /**
223    * Gets the join expr.
224    */

225   public JoinExpr getJoinExpr()
226   {
227     return _joinExpr;
228   }
229
230   /**
231    * Returns the entity home.
232    */

233   public AmberEntityHome getEntityHome()
234   {
235     return ((EntityType) getTableType()).getHome();
236   }
237
238   /**
239    * Gets the index within the cartesian product for the item.
240    */

241   public int getIndex()
242   {
243     return _index;
244   }
245
246   public String JavaDoc toString()
247   {
248     return "FromItem[" + _table.getName() + " AS " + getName() + "]";
249   }
250 }
251
Popular Tags