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.foedeployer.ejb.ql;
023:
024: import javax.ejb.EntityBean;
025: import javax.ejb.EntityContext;
026: import javax.ejb.FinderException;
027: import javax.ejb.NoSuchEntityException;
028: import javax.ejb.ObjectNotFoundException;
029: import javax.ejb.RemoveException;
030: import javax.ejb.CreateException;
031: import javax.ejb.DuplicateKeyException;
032: import javax.ejb.EJBException;
033:
034: import javax.sql.DataSource;
035: import javax.naming.InitialContext;
036: import javax.naming.NamingException;
037:
038: import java.sql.Connection;
039: import java.sql.Statement;
040: import java.sql.ResultSet;
041: import java.sql.SQLException;
042:
043: import java.util.Collection;
044:
045: import org.apache.log4j.Category;
046:
047: /**
048: * Models a car.
049: *
050: * @ejb.bean
051: * name="Car"
052: * generate="true"
053: * view-type="local"
054: * type="CMP"
055: * local-jndi-name="CarEJB.CarHome"
056: * reentrant="False"
057: * cmp-version="2.x"
058: * primkey-field="number"
059: *
060: * @ejb.pk
061: * class="java.lang.String"
062: * generate="false"
063: *
064: * @ejb.transaction type="Required"
065: *
066: * @ejb.finder
067: * view-type="local"
068: * signature="java.util.Collection findAll()"
069: * query="SELECT OBJECT(c) FROM Car AS c"
070: *
071: * @ejb.finder
072: * view-type="local"
073: * signature="java.util.Collection findByColor( java.lang.String color )"
074: * query="SELECT OBJECT(c) FROM Car AS c WHERE c.color = ?1"
075: *
076: * @ejb.finder
077: * view-type="local"
078: * signature="java.util.Collection findAfterYear( int year )"
079: * query="SELECT OBJECT(c) FROM Car AS c WHERE c.year > ?1"
080: *
081: * @@ejb.persistence table-name="cars"
082: * @weblogic:table-name cars
083: *
084: * @jboss.create-table "${jboss.create.table}"
085: * @jboss.remove-table "${jboss.remove.table}"
086: *
087: * @author <a href="mailto:loubyansky@hotmail.com">Alex Loubyansky</a>
088: */
089: public abstract class CarBean implements EntityBean {
090: // Constants -----------------------------------------------------
091: static Category log = Category.getInstance(CarBean.class);
092:
093: // Attributes ----------------------------------------------------
094: private EntityContext ctx;
095:
096: // CMP Accessors -------------------------------------------------
097: /**
098: * Car's number: primary key field
099: *
100: * @ejb.pk-field
101: * @ejb.persistent-field
102: * @ejb.interface-method
103: *
104: * xdoclet needs to be updated
105: * @@ejb.persistence
106: * column-name="number"
107: * jdbc-type="VARCHAR"
108: * sql-type="VARCHAR(50)"
109: *
110: * @weblogic:dbms-column number
111: */
112: public abstract String getNumber();
113:
114: public abstract void setNumber(String number);
115:
116: /**
117: * Car's color: persistent field
118: *
119: * @ejb.persistent-field
120: * @ejb.interface-method
121: *
122: * xdoclet needs to be updated
123: * @@ejb.persistence
124: * column-name="color"
125: * jdbc-type="VARCHAR"
126: * sql-type="VARCHAR(30)"
127: *
128: * @weblogic:dbms-column color
129: */
130: public abstract String getColor();
131:
132: public abstract void setColor(String color);
133:
134: /**
135: * Year of birth: persistent field
136: *
137: * @ejb.persistent-field
138: * @ejb.interface-method
139: *
140: * xdoclet needs to be updated
141: * @@ejb.persistence
142: * column-name="year"
143: * jdbc-type="INTEGER"
144: * sql-type="INTEGER"
145: *
146: * @weblogic:dbms-column year
147: */
148: public abstract int getYear();
149:
150: public abstract void setYear(int year);
151:
152: // EntityBean Implementation -------------------------------------
153: /**
154: * @ejb:create-method
155: */
156: public String ejbCreate(String number, String color, int year)
157: throws CreateException {
158: setNumber(number);
159: setColor(color);
160: setYear(year);
161: return null; // See 9.4.2 of the EJB 1.1 specification
162: }
163:
164: public void ejbPostCreate(String number, String color, int year) {
165: }
166:
167: /**
168: * @ejb:interface-method
169: */
170: public void ejbRemove() throws RemoveException {
171: log.debug("removed: " + ctx.getPrimaryKey());
172: }
173:
174: public void setEntityContext(EntityContext ctx) {
175: this .ctx = ctx;
176: }
177:
178: public void unsetEntityContext() {
179: ctx = null;
180: }
181:
182: public void ejbActivate() {
183: }
184:
185: public void ejbPassivate() {
186: }
187:
188: public void ejbLoad() {
189: }
190:
191: public void ejbStore() {
192: }
193: }
|