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.o2mb;
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.Set;
044:
045: import org.apache.log4j.Category;
046:
047: /**
048: * Models a company.
049: *
050: * @ejb.bean
051: * name="Company"
052: * generate="true"
053: * view-type="local"
054: * type="CMP"
055: * local-jndi-name="CompanyEJB.CompanyHome"
056: * reentrant="False"
057: * cmp-version="2.x"
058: * primkey-field="name"
059: *
060: * @ejb.pk
061: * class="java.lang.String"
062: * generate="false"
063: *
064: * @@ejb.finder signature="Collection findAll()"
065: *
066: * @ejb.transaction type="Required"
067: *
068: * @@ejb.persistence table-name="company"
069: * @weblogic:table-name company
070: *
071: * @jboss.create-table "${jboss.create.table}"
072: * @jboss.remove-table "${jboss.remove.table}"
073: *
074: * @author <a href="mailto:loubyansky@hotmail.com">Alex Loubyansky</a>
075: */
076: public abstract class CompanyBean implements EntityBean {
077: // Constants -----------------------------------------------------
078: static Category log = Category.getInstance(CompanyBean.class);
079:
080: // Attributes ----------------------------------------------------
081: private EntityContext ctx;
082:
083: // CMP
084: /**
085: * Company's name: primary key field
086: *
087: * @ejb.pk-field
088: * @ejb.persistent-field
089: * @ejb.interface-method
090: *
091: * xdoclet needs to be updated
092: * @@ejb.persistence
093: * column-name="name"
094: * jdbc-type="VARCHAR"
095: * sql-type="VARCHAR(50)"
096: *
097: * @weblogic:dbms-column name
098: */
099: public abstract String getName();
100:
101: public abstract void setName(String name);
102:
103: // CMR
104:
105: /**
106: * Employees: bidirectional CMR
107: *
108: * @ejb.relation
109: * name="Company-Employee"
110: * role-name="Company-Has-Employees"
111: * @ejb.interface-method
112: *
113: * @weblogic.column-map
114: * foreign-key-column="company_name"
115: * key-column="name"
116: */
117: public abstract Set getEmployees();
118:
119: /**
120: * @ejb.interface-method
121: */
122: public abstract void setEmployees(Set employees);
123:
124: // EntityBean Implementation -------------------------------------
125: /**
126: * @ejb.create-method
127: */
128: public String ejbCreate(String name) throws CreateException {
129: setName(name);
130: return null; // See 9.4.2 of the EJB 1.1 specification
131: }
132:
133: public void ejbPostCreate(String name) {
134: }
135:
136: public void ejbRemove() throws RemoveException {
137: log.debug("removed: " + ctx.getPrimaryKey());
138: }
139:
140: public void setEntityContext(EntityContext ctx) {
141: this .ctx = ctx;
142: }
143:
144: public void unsetEntityContext() {
145: ctx = null;
146: }
147:
148: public void ejbActivate() {
149: }
150:
151: public void ejbPassivate() {
152: }
153:
154: public void ejbLoad() {
155: }
156:
157: public void ejbStore() {
158: }
159: }
|