import java.io.Serializable; import java.util.Enumeration; import java.util.Vector; import javax.ejb.CreateException; import javax.ejb.DuplicateKeyException; import javax.ejb.EJBException; import javax.ejb.EntityBean; import javax.ejb.EntityContext; import javax.ejb.FinderException; import javax.ejb.NoSuchEntityException; import javax.ejb.ObjectNotFoundException; import javax.ejb.RemoveException; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; // // Illustration of compound primary key generation for EJBGen. The only changes // from the containerManaged examples are: // // - the prim-key-class below specifies a non-existent Java class (which will // be generated by EJBGen); // - each CMP field that is part of the compound primary key are tagged with // a primkey-field tag (accountType and accountID in this example). // // Based on those information, EJBGen will generate AccountPK.java with all // the relevant information. // /** * @ejbgen:entity * ejb-name = containerManaged * table-name = ejbAccounts * data-source-name = examples-dataSource-demoPool * prim-key-class = AccountPK * invalidation-target = ServiceDesignEJB * * @ejbgen:jndi-name * remote = ejb20-compoundPK-AccountHome * local = ejb20-compoundPK-AccountLocalHome * * @ejbgen:finder * signature = "Account findAccount(double balanceEqual)" * ejb-ql = "SELECT o FROM containerManaged o WHERE balance = ?1" * transaction-attribute = Mandatory * isolation-level = TRANSACTION_READ_COMMITTED_FOR_UPDATE * * @ejbgen:finder * signature = "Collection findBigAccounts(double balanceGreaterThan)" * ejb-ql = "SELECT o FROM containerManaged o WHERE balance > ?1" * * @ejbgen:finder * signature = "Collection findNullAccounts()" * ejb-ql = "SELECT o FROM containerManaged o WHERE accountType IS NULL" * */ abstract public class AccountEJB implements EntityBean { final static boolean VERBOSE = true; private EntityContext ctx; public AccountEJB() {}; /** * Sets the EntityContext for the EJBean. */ public void setEntityContext(EntityContext ctx) { log("setEntityContext called (" + id() + ")"); this.ctx = ctx; } /** * Unsets the EntityContext for the EJBean. * */ public void unsetEntityContext() { log("AccountEJB.unsetEntityContext (" + id() + ")"); this.ctx = null; } /** * container managed fields */ /** * @ejbgen:cmp-field column = id ordering-number = 1 * @ejbgen:primkey-field */ abstract public String getAccountId(); abstract public void setAccountId(String val); /** * @ejbgen:cmp-field column = bal ordering-number = 2 * @ejbgen:primkey-field */ abstract public double getBalance(); abstract public void setBalance(double val); /** * @ejbgen:cmp-field column = type ordering-number = 3 * @ejbgen:primkey-field */ abstract public String getAccountType(); abstract public void setAccountType(String val); /** * Returns the Primary Key identifying this EJBean. */ private String id() { return "" + System.identityHashCode(this) + ", PK = " + (String) ((ctx == null) ? "nullctx" : ((ctx.getPrimaryKey() == null ? "null" : ctx.getPrimaryKey().toString()))); } /** * This method is required by the EJB Specification, * but is not used by this example. * */ public void ejbActivate() { log("AccountEJB.ejbActivate (" + id() + ")"); } /** * This method is required by the EJB Specification, * but is not used by this example. * */ public void ejbPassivate() { log("AccountEJB.ejbPassivate (" + id() + ")"); } /** * This method is required by the EJB Specification, * but is not used by this example. * */ public void ejbLoad() { log("AccountEJB.ejbLoad (" + id() + ")"); } /** * Sets the EJBean's modified flag to false. * set to false to "reset" the variable for the next transaction. * */ public void ejbStore() { log("AccountEJB.ejbStore (" + id() + ")"); } /** * This method is required by the EJB Specification, * but is not used by this example. */ public void ejbRemove() throws RemoveException { log("AccountEJB.ejbRemove (" + id() + ")"); } public AccountPK ejbCreate(String accountId, double initialBalance, String type) throws CreateException { log("AccountEJB.ejbCreate( id = " + System.identityHashCode(this) + ", PK = " + accountId + ", " + "initial balance = $ " + initialBalance + ")"); setAccountId(accountId); setBalance(initialBalance); setAccountType(type); return null; // See 9.4.2 of the EJB 1.1 specification } public void ejbPostCreate(String accountId, double initialBalance, String type) { log("AccountEJB.ejbPostCreate (" + id() + ")"); } /** * @ejbgen:remote-method * transaction-attribute = Required * * @ejbgen:local-method * transaction-attribute = Required * */ public void localAndRemoteMethod() { } /** * @ejbgen:local-method * transaction-attribute = Required * */ public void localMethodWithThrow() throws FooException { } // Application defined methods /** * @ejbgen:remote-method * transaction-attribute = Required * */ public double deposit(double amount) { log("AccountEJB.deposit: Depositing $" + amount + " into '" + getAccountId() + "'"); setBalance(getBalance() + amount); return getBalance(); } /** * @ejbgen:remote-method transaction-attribute = Mandatory */ public double withdraw(double amount) throws ProcessingErrorException { log("AccountEJB.withdraw: Withdrawing $" + amount + " from '" + getAccountId() + "'"); if (amount > getBalance()) { throw new ProcessingErrorException( "Request to withdraw $" + amount + "; is more than balance $" + getBalance() + " in account " + getAccountId()); } setBalance(getBalance() - amount); return getBalance(); } /** * @ejbgen:remote-method */ public double balance() { log("AccountEJB.balance (" + id() + ")"); return getBalance(); } /** * Returns the account type. * * @ejbgen:remote-method */ public String accountType() { log("AccountEJB.accountType (" + id() + ")"); return getAccountType(); } // You might also consider using WebLogic's log service private void log(String s) { if (VERBOSE) System.out.println(s); } } /* This file was automatically generated */