KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > ql > CollectionExpr


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 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.ejb.ql;
30
31 import com.caucho.amber.type.EntityType;
32 import com.caucho.config.ConfigException;
33 import com.caucho.ejb.cfg.CmrRelation;
34 import com.caucho.ejb.cfg.EjbEntityBean;
35 import com.caucho.util.CharBuffer;
36
37 /**
38  * Expression representing the a collection specified in the FROM field,
39  * e.g. FROM l in o.list
40  */

41 class CollectionExpr extends Expr {
42   // base expression
43
private PathExpr _base;
44   // field name
45
private String JavaDoc _fieldName;
46
47   // relation information
48
private CmrRelation _relation;
49
50   private CollectionIdExpr _id;
51   private boolean _usesField;
52
53   /**
54    * Creates a new field expression.
55    *
56    * @param base the base expression
57    * @param field name of the field
58    */

59   CollectionExpr(Query query, PathExpr base,
60                  String JavaDoc field, CmrRelation relation)
61     throws ConfigException
62   {
63     _query = query;
64     _base = base;
65     _fieldName = field;
66     _relation = relation;
67
68     base.setUsesField();
69     
70     // setJavaType(relation.getJavaType());
71
}
72
73   void setId(CollectionIdExpr id)
74   {
75     if (_id != null)
76       throw new RuntimeException JavaDoc();
77     
78     _id = id;
79   }
80
81   CollectionIdExpr getId()
82   {
83     return _id;
84   }
85
86   void setUsesField()
87   {
88     if (! _usesField) {
89       _usesField = true;
90     }
91   }
92
93   PathExpr getBase()
94   {
95     return _base;
96   }
97
98   EjbEntityBean getItemBean()
99   {
100     return _relation.getTargetBean();
101   }
102
103   int getComponentCount()
104   {
105     EjbEntityBean bean = getItemBean();
106
107     EntityType type = bean.getEntityType();
108     
109     return type.getId().getKeyCount();
110   }
111
112   /**
113    * Returns the EJB name.
114    */

115   String JavaDoc getReturnEJB()
116   {
117     return getItemBean().getEJBName();
118   }
119
120   CmrRelation getRelation()
121   {
122     return _relation;
123   }
124
125   /**
126    * Prints the select SQL for this expression
127    *
128    * @param cb the java code generator
129    */

130   void generateSelect(CharBuffer cb)
131   {
132     _base.generateSelect(cb);
133     cb.append('.');
134     cb.append(_fieldName);
135
136     // _id.generateSelect(cb);
137
}
138
139   public String JavaDoc toString()
140   {
141     return String.valueOf(_base) + "." + _fieldName;
142   }
143 }
144
Popular Tags