KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.CharBuffer;
32
33 import com.caucho.amber.type.Type;
34 import com.caucho.amber.type.EntityType;
35
36 import com.caucho.amber.field.MapElementField;
37
38 /**
39  * Bound identifier expression.
40  */

41 public class MapFieldExpr extends AbstractAmberExpr {
42   protected PathExpr _parent;
43
44   private MapElementField _field;
45   private AmberExpr _index;
46
47   private FromItem _fromItem;
48   private FromItem _childFromItem;
49
50   /**
51    * Creates a new unbound id expression.
52    */

53   public MapFieldExpr(PathExpr parent,
54               MapElementField field,
55               AmberExpr index)
56   {
57     _parent = parent;
58     _field = field;
59     _index = index;
60   }
61
62   /**
63    * Binds the expression as a select item.
64    */

65   public AmberExpr bindSelect(QueryParser parser)
66   {
67     _fromItem = _parent.bindSubPath(parser);
68
69     // _childFromItem = parser.addFromItem(null, null, _field.getTable());
70

71     // _childFromItem.setJoinExpr(new MapLinkExpr());
72

73     _index = _index.bindSelect(parser);
74     
75     return this;
76   }
77
78   /**
79    * Returns true if the expression uses the from item.
80    */

81   public boolean usesFrom(FromItem from, int type, boolean isNot)
82   {
83     return (_childFromItem == from ||
84         _parent.usesFrom(from, type) ||
85         _index.usesFrom(from, type));
86   }
87
88   /**
89    * Returns the expr's type.
90    */

91   public Type getType()
92   {
93     return _field.getTargetType();
94   }
95
96   /**
97    * Returns the expr's type.
98    */

99   public EntityType getTableType()
100   {
101     return (EntityType) getType();
102   }
103   
104   /**
105    * Generates the select expression.
106    */

107   public void generateSelect(CharBuffer cb)
108   {
109     String table = _childFromItem.getName();
110
111     /*
112     if (_fromItem != null)
113       table = _fromItem.getName();
114     else
115       table = _parent.getTable();
116     */

117     
118     cb.append(_field.generateTargetSelect(table));
119   }
120   
121   /**
122    * Generates the where expression.
123    */

124   public void generateWhere(CharBuffer cb)
125   {
126     cb.append(_field.generateTargetSelect(_childFromItem.getName()));
127     /*
128     cb.append(_childFromItem.getName());
129     ArrayList<Column> column = _field.getColumns();
130     
131     cb.append('.');
132     cb.append(column.get(0).getName());
133     */

134   }
135
136   public String toString()
137   {
138     return _parent + "." + _field;
139   }
140 }
141
Popular Tags