KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > ejbselect > ABean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cmp2.ejbselect;
23
24 import java.util.Collection JavaDoc;
25
26 import javax.ejb.CreateException JavaDoc;
27 import javax.ejb.EntityBean JavaDoc;
28 import javax.ejb.EntityContext JavaDoc;
29 import javax.ejb.FinderException JavaDoc;
30 import javax.ejb.RemoveException JavaDoc;
31
32 /**
33  * @ejb.bean
34  * name="A"
35  * type="CMP"
36  * cmp-version="2.x"
37  * view-type="local"
38  * primkey-field="id"
39  * @ejb.pk generate="true"
40  * @ejb.util generate="physical"
41  * @ejb.persistence table-name="TEST_A"
42  * @jboss.persistence
43  * create-table="true"
44  * remove-table="true"
45  *
46  * @jboss.declared-sql
47  * signature="Collection ejbSelectSomeBsDeclaredSQL(org.jboss.test.cmp2.ejbselect.ALocal a)"
48  * ejb-name="B"
49  * alias="b"
50  * from=", TEST_A a"
51  * where="a.ID={0.id} AND b.A_ID=a.ID"
52  *
53  * @author others + <a HREF="mailto:alex@jboss.org">Alex Loubyansky</a>
54  */

55 public abstract class ABean implements EntityBean JavaDoc
56 {
57    private EntityContext JavaDoc ctx;
58
59    /**
60     * @ejb.pk-field
61     * @ejb.persistent-field
62     * @ejb.interface-method
63     * @ejb.persistence column-name="ID"
64     */

65    public abstract String JavaDoc getId();
66    public abstract void setId(String JavaDoc id);
67
68    /**
69     * @ejb.persistent-field
70     * @ejb.interface-method
71     * @ejb.persistence column-name="INT_FIELD"
72     */

73    public abstract int getIntField();
74    /**
75     * @ejb.interface-method
76     */

77    public abstract void setIntField(int value);
78
79    /**
80     * @ejb.relation
81     * name="A-B"
82     * role-name="A-has-Bs"
83     * @ejb.interface-method
84     */

85    public abstract Collection JavaDoc getBs();
86    /**
87     * @ejb.interface-method
88     */

89    public abstract void setBs(Collection JavaDoc Bs);
90
91    // ejbSelect methods
92

93    /**
94     * @ejb.select query="SELECT OBJECT(b) FROM B AS b WHERE b.a = ?1"
95     */

96    public abstract Collection JavaDoc ejbSelectSomeBs(ALocal a) throws FinderException JavaDoc;
97
98    /**
99     * @ejb.select query="SELECT DISTINCT OBJECT(a) FROM A AS a WHERE a.bs IS NOT EMPTY"
100     */

101    public abstract Collection JavaDoc ejbSelectAWithBs() throws FinderException JavaDoc;
102
103    /**
104     * Declared SQL
105     * @ejb.select query=""
106     */

107    public abstract Collection JavaDoc ejbSelectSomeBsDeclaredSQL(ALocal a) throws FinderException JavaDoc;
108
109    /**
110     * NOTE: -1234 does not exist
111     * @ejb.select query="SELECT SUM(a.intField) FROM A AS a WHERE a.intField = -1234"
112     */

113    public abstract int ejbSelectNullSum() throws FinderException JavaDoc;
114
115    // Interface methods
116

117    /**
118     * @ejb.interface-method
119     */

120    public Collection JavaDoc getSomeBs() throws FinderException JavaDoc
121    {
122       return ejbSelectSomeBs((ALocal)ctx.getEJBLocalObject());
123    }
124
125    /**
126     * @ejb.interface-method
127     */

128    public Collection JavaDoc getSomeBsDeclaredSQL() throws FinderException JavaDoc
129    {
130       return ejbSelectSomeBsDeclaredSQL((ALocal)ctx.getEJBLocalObject());
131    }
132
133    /**
134     * @ejb.interface-method
135     */

136    public Collection JavaDoc getAWithBs() throws FinderException JavaDoc
137    {
138       return ejbSelectAWithBs();
139    }
140
141    // Home methods
142

143    /**
144     * @ejb.home-method
145     */

146    public Collection JavaDoc ejbHomeGetSomeBs(ALocal a) throws FinderException JavaDoc
147    {
148       return ejbSelectSomeBs(a);
149    }
150
151    /**
152     * @ejb.home-method
153     */

154    public Collection JavaDoc ejbHomeGetSomeBsDeclaredSQL(ALocal a) throws FinderException JavaDoc
155    {
156       return ejbSelectSomeBsDeclaredSQL(a);
157    }
158
159    /**
160     * @ejb.home-method
161     */

162    public void ejbHomeCheckFinderForNull() throws FinderException JavaDoc
163    {
164       ejbSelectNullSum();
165    }
166
167    /**
168     * @ejb.create-method
169     */

170    public String JavaDoc ejbCreate(String JavaDoc id) throws CreateException JavaDoc
171    {
172       setId(id);
173       return null;
174    }
175
176    public void ejbPostCreate(String JavaDoc id) {}
177
178    public void setEntityContext(EntityContext JavaDoc ctx)
179    {
180       this.ctx = ctx;
181    }
182
183    public void unsetEntityContext()
184    {
185       this.ctx = null;
186    }
187
188    public void ejbRemove() throws RemoveException JavaDoc {}
189    public void ejbActivate() {}
190    public void ejbPassivate() {}
191    public void ejbLoad() {}
192    public void ejbStore() {}
193 }
194
Popular Tags