据源中的JNDI要一致。得到SQL DLL后,我们可以根据techniquespec表生成CMP 2.0 Entity Beans,在这里我们采用LocalHome访问Entity Beans,为什么采用?后续文章中都会详细阐述。现在想返回表techniquespec中列techniqueitem的所有内容。首先,真假一个findByTypes Finder方法,EJB QL语句为:SELECT OBJECT(p) from Techniquespec AS p,其中返回值为Collection。下面给出代码。
LocalHome接口:
package cacdsystem;
import javax.ejb.*;
import java.util.*;
public interface TechniquespecHome extends javax.ejb.EJBLocalHome
{
public Techniquespec create(String techniqueitem)
throws CreateException;
public Collection findByTypes()
throws FinderException;
//添加的Finder方法
public Techniquespec findByPrimaryKey(String techniqueitem)
throws FinderException;
}
Local接口:
package cacdsystem;
import javax.ejb.*;
import java.util.*;
import java.math.*;
public interface Techniquespec extends javax.ejb.EJBLocalObject
{
public String getTechniqueitem();
public void setUnits(String units);
public String getUnits();
public void setMinvalue(BigDecimal minvalue);
public BigDecimal getMinvalue();
public void setMaxvalue(BigDecimal maxvalue);
public BigDecimal getMaxvalue();
public void setTypes(String types);
public String getTypes();
public void setSignon(String signon);
public String getSignon();}
bean类:
package cacdsystem;
import javax.ejb.*;
abstract public class TechniquespecBean implements EntityBean
{
EntityContext entityContext;
public java.lang.String ejbCreate(java.lang.String techniqueitem)
throws CreateException
{
setTechniqueitem(techniqueitem);
return null;
}
public void ejbPostCreate(java.lang.String techniqueitem)
throws CreateException {}
public void ejbRemove() throws RemoveException {}
public abstract void setTechniqueitem(java.lang.String techniqueitem);
public abstract void setUnits(java.lang.String units);
public abstract void setMinvalue(java.math.BigDecimal minvalue);
public abstract void setMaxvalue(java.math.BigDecimal maxvalue);
public abstract void setTypes(java.lang.String types);
public abstract void setSignon(java.lang.String signon);
public abstract java.lang.String getTechniqueitem();
public abstract java.lang.String getUnits();
public abstract java.math.BigDecimal getMinvalue();
public abstract java.math.BigDecimal getMaxvalue();
public abstract java.lang.String getTypes();
public abstract java.lang.String getSignon();
public void ejbLoad(){}
public void ejbStore(){}
public void ejbActivate(){}
public void ejbPassivate(){}
public void unsetEntityContext()
{
this.entityContext = null;
}
public void setEntityContext(EntityContext entityContext)
{
this.entityContext = entityContext;
}
}
EJB技术之旅(二)(3)
时间:2010-12-10
4.无状态Session Beans的开发:通过EJB 图形设计器,生成一个Session Bean,代码如下。
Home接口:
package cacdsystem;
import javax.ejb.*;
import ja
|