JBoss 3.0 Template and Examples
源代码在线查看: transactionbean.java
/* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package transaction.entity; import java.util.Date; import javax.naming.InitialContext; import transaction.interfaces.Account; import transaction.interfaces.TransactionData; import transaction.interfaces.TransactionPK; /** * The Entity bean represents a bank transaction * * @author Andreas Schaefer * @version $Revision: 1.1 $ * * @ejb:bean name="bank/Transaction" * display-name="Bank Transaction Entity" * type="CMP" * view-type="remote" * jndi-name="ejb/bank/Transaction" * schema="Transaction" * * @ejb:interface extends="javax.ejb.EJBObject" * * @ejb:home extends="javax.ejb.EJBHome" * * @ejb:pk extends="java.lang.Object" * * @ejb:transaction type="Required" * * @ejb:data-object extends="java.lang.Object" * * @ejb:finder signature="java.util.Collection findAll()" * query="SELECT OBJECT(o) FROM Transaction AS o" * * @ejb:finder signature="java.util.Collection findByAccount( java.lang.String pAccountId )" * query="SELECT OBJECT(o) FROM Transaction AS o WHERE o.acountId = ?1" * * @jboss:finder-query name="findByAccount" * query="Account_Id = {0}" * order="Date" * * @jboss:table-name table-name="New_Transaction" * * @jboss:create-table create="true" * * @jboss:remove-table remove="true" */ public abstract class TransactionBean extends EntitySupport { // Constants ----------------------------------------------------- // Attributes ---------------------------------------------------- // Static -------------------------------------------------------- private static int sId = 0; // Constructors -------------------------------------------------- // Public -------------------------------------------------------- /** * @ejb:persistent-field * @ejb:pk-field * * @jboss:column-name name="Id" **/ abstract public String getId(); abstract public void setId( String pId ); /** * @ejb:persistent-field * * @jboss:column-name name="Account_Id" **/ abstract public String getAcountId(); abstract public void setAcountId( String pAcountId ); /** * @ejb:persistent-field * * @jboss:column-name name="Type" **/ abstract public int getType(); abstract public void setType( int pType ); /** * @ejb:persistent-field * * @jboss:column-name name="Amount" **/ abstract public float getAmount(); abstract public void setAmount( float pAmount ); /** * @ejb:persistent-field * * @jboss:column-name name="Date" **/ abstract public Date getDate(); abstract public void setDate( Date pDate ); /** * @ejb:persistent-field * * @jboss:column-name name="Description" **/ abstract public String getDescription(); abstract public void setDescription( String pDescription ); /** * @ejb:interface-method view-type="remote" **/ abstract public TransactionData getData(); abstract public void setData( TransactionData pDate ); // EntityHome implementation ------------------------------------- /** * @ejb:create-method view-type="remote" **/ public TransactionPK ejbCreate( String pAccountId, int pType, float pAmount, String pDescription ) { setId( "Tx: " + ( sId++ ) ); setAcountId( pAccountId ); setType( pType ); setAmount( pAmount ); setDescription( pDescription ); setDate( new Date() ); return null; } public void ejbPostCreate( String pAccountId, int pType, float pAmount, String pDescription ) { } /** * @ejb:create-method view-type="remote" **/ public TransactionPK ejbCreate( TransactionData pData ) { setId( "Tx: " + ( sId++ ) ); pData.setDate( new Date() ); setData( pData ); return null; } public void ejbPostCreate( TransactionData pData ) { } }