001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cmp2.ejbselect;
023:
024: import java.util.Collection;
025:
026: import javax.ejb.CreateException;
027: import javax.ejb.EntityBean;
028: import javax.ejb.EntityContext;
029: import javax.ejb.FinderException;
030: import javax.ejb.RemoveException;
031:
032: /**
033: * @ejb.bean
034: * name="A"
035: * type="CMP"
036: * cmp-version="2.x"
037: * view-type="local"
038: * primkey-field="id"
039: * @ejb.pk generate="true"
040: * @ejb.util generate="physical"
041: * @ejb.persistence table-name="TEST_A"
042: * @jboss.persistence
043: * create-table="true"
044: * remove-table="true"
045: *
046: * @jboss.declared-sql
047: * signature="Collection ejbSelectSomeBsDeclaredSQL(org.jboss.test.cmp2.ejbselect.ALocal a)"
048: * ejb-name="B"
049: * alias="b"
050: * from=", TEST_A a"
051: * where="a.ID={0.id} AND b.A_ID=a.ID"
052: *
053: * @author others + <a href="mailto:alex@jboss.org">Alex Loubyansky</a>
054: */
055: public abstract class ABean implements EntityBean {
056: private EntityContext ctx;
057:
058: /**
059: * @ejb.pk-field
060: * @ejb.persistent-field
061: * @ejb.interface-method
062: * @ejb.persistence column-name="ID"
063: */
064: public abstract String getId();
065:
066: public abstract void setId(String id);
067:
068: /**
069: * @ejb.persistent-field
070: * @ejb.interface-method
071: * @ejb.persistence column-name="INT_FIELD"
072: */
073: public abstract int getIntField();
074:
075: /**
076: * @ejb.interface-method
077: */
078: public abstract void setIntField(int value);
079:
080: /**
081: * @ejb.relation
082: * name="A-B"
083: * role-name="A-has-Bs"
084: * @ejb.interface-method
085: */
086: public abstract Collection getBs();
087:
088: /**
089: * @ejb.interface-method
090: */
091: public abstract void setBs(Collection Bs);
092:
093: // ejbSelect methods
094:
095: /**
096: * @ejb.select query="SELECT OBJECT(b) FROM B AS b WHERE b.a = ?1"
097: */
098: public abstract Collection ejbSelectSomeBs(ALocal a)
099: throws FinderException;
100:
101: /**
102: * @ejb.select query="SELECT DISTINCT OBJECT(a) FROM A AS a WHERE a.bs IS NOT EMPTY"
103: */
104: public abstract Collection ejbSelectAWithBs()
105: throws FinderException;
106:
107: /**
108: * NOTE: -1234 does not exist
109: * @ejb.select query="SELECT SUM(a.intField) FROM A AS a WHERE a.intField = -1234"
110: */
111: public abstract int ejbSelectNullSum() throws FinderException;
112:
113: /**
114: * Declared SQL
115: * @ejb.select query=""
116: */
117: public abstract Collection ejbSelectSomeBsDeclaredSQL(ALocal a)
118: throws FinderException;
119:
120: // Interface methods
121:
122: /**
123: * @ejb.interface-method
124: */
125: public Collection getSomeBs() throws FinderException {
126: return ejbSelectSomeBs((ALocal) ctx.getEJBLocalObject());
127: }
128:
129: /**
130: * @ejb.interface-method
131: */
132: public Collection getSomeBsDeclaredSQL() throws FinderException {
133: return ejbSelectSomeBsDeclaredSQL((ALocal) ctx
134: .getEJBLocalObject());
135: }
136:
137: /**
138: * @ejb.interface-method
139: */
140: public Collection getAWithBs() throws FinderException {
141: return ejbSelectAWithBs();
142: }
143:
144: // Home methods
145:
146: /**
147: * @ejb.home-method
148: */
149: public Collection ejbHomeGetSomeBs(ALocal a) throws FinderException {
150: return ejbSelectSomeBs(a);
151: }
152:
153: /**
154: * @ejb.home-method
155: */
156: public Collection ejbHomeGetSomeBsDeclaredSQL(ALocal a)
157: throws FinderException {
158: return ejbSelectSomeBsDeclaredSQL(a);
159: }
160:
161: /**
162: * @ejb.home-method
163: */
164: public void ejbHomeCheckFinderForNull() throws FinderException {
165: ejbSelectNullSum();
166: }
167:
168: /**
169: * @ejb.create-method
170: */
171: public String ejbCreate(String id) throws CreateException {
172: setId(id);
173: return null;
174: }
175:
176: public void ejbPostCreate(String id) {
177: }
178:
179: public void setEntityContext(EntityContext ctx) {
180: this .ctx = ctx;
181: }
182:
183: public void unsetEntityContext() {
184: this .ctx = null;
185: }
186:
187: public void ejbRemove() throws RemoveException {
188: }
189:
190: public void ejbActivate() {
191: }
192:
193: public void ejbPassivate() {
194: }
195:
196: public void ejbLoad() {
197: }
198:
199: public void ejbStore() {
200: }
201: }
|