KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 1998-2004 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 SoftwareFoundation, 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.type.Type;
32 import com.caucho.amber.type.EntityType;
33
34 import com.caucho.amber.field.KeyPropertyField;
35
36 import com.caucho.amber.table.Column;
37
38 /**
39  * Bound identifier expression.
40  */

41 public class KeyPropertyExpr extends AbstractAmberExpr implements IdFieldExpr {
42   protected PathExpr _parent;
43   private KeyPropertyField _field;
44   
45   /**
46    * Creates a new unbound id expression.
47    */

48   public KeyPropertyExpr(PathExpr parent, KeyPropertyField field)
49   {
50     _parent = parent;
51     _field = field;
52
53     // XXX: ejb/0a08
54
if (_field.getType() instanceof EntityType)
55       throw new IllegalStateException();
56   }
57
58   /**
59    * Binds the expression as a select item.
60    */

61   public AmberExpr bindSelect(QueryParser parser)
62   {
63     _parent = (PathExpr) _parent.bindSelect(parser);
64     
65     return this;
66   }
67
68   /**
69    * Returns the parent expression.
70    */

71   public PathExpr getParent()
72   {
73     return _parent;
74   }
75
76   /**
77    * Returns the parent expression.
78    */

79   public KeyPropertyField getField()
80   {
81     return _field;
82   }
83
84   /**
85    * Returns the expr type
86    */

87   public Type getType()
88   {
89     return getField().getType();
90   }
91
92   /**
93    * Returns the parent expression.
94    */

95   public Column getColumn()
96   {
97     return getField().getColumn();
98   }
99   
100   /**
101    * Creates the expr from the path.
102    */

103   /*
104   public PathExpr createField(QueryParser parser, String name)
105   {
106     Type type = getType();
107
108     if (! (type instanceof EntityType))
109       return null;
110
111     EntityType entityType = (EntityType) type;
112     
113     AbstractField field = entityType.getField(name);
114
115     if (field == null)
116       return null;
117     else {
118       EntityPathExpr dst = (EntityPathExpr) getField().createExpr(parser,
119                          new KeyManyToOneExpr(this));
120       PathExpr result = field.createExpr(parser, (EntityPathExprdst);
121       
122       return result;
123     }
124   }
125   */

126
127   /**
128    * Returns true if the expression uses the from item.
129    */

130   public boolean usesFrom(FromItem from, int type, boolean isNot)
131   {
132     if (_parent instanceof IdExpr) {
133       // IdExpr parent = (IdExpr) _parent;
134
// return (parent.getFromItem() == from && type == USES_ANY);
135

136       return type == IS_INNER_JOIN && _parent.usesFrom(from, type);
137     }
138     else
139       return _parent.usesFrom(from, type);
140   }
141
142   /**
143    * Replaces linked join to eliminate a table.
144    */

145   /*
146   public AmberExpr replaceJoin(JoinExpr join)
147   {
148     // _parent = (EntityPathExpr) _parent.replaceJoin(join);
149
150     if (_parent instanceof IdExpr)
151       return join.replace(this);
152     else
153       return super.replaceJoin(join);
154   }
155   */

156
157   /**
158    * Returns the child from item.
159    *
160    * XXX: untested
161    */

162   public FromItem getChildFromItem()
163   {
164     return _parent.getChildFromItem();
165   }
166
167   /**
168    * Returns the field string.
169    */

170   public String toString()
171   {
172     return "KeyPropertyExpr[" + _parent + "," + _field + "]";
173   }
174 }
175
Popular Tags