⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employeeaction.java

📁 EJB 开发 EJB 开发 EJB 开发 EJB 开发 EJB 开发 EJB 开发
💻 JAVA
字号:
package employee;import javax.ejb.*;import javax.naming.NamingException;import java.rmi.RemoteException;import java.util.ArrayList;import java.sql.*;import java.math.BigDecimal;public class EmployeeAction{  public EmployeeModel add( EmployeeModel model ) throws NamingException, RemoteException, CreateException  {    model.setID(SequenceUtil.getUniteCode());    try    {      SbnEmployeeHome home = (SbnEmployeeHome) EjbCommon.getRemoteEJBHome(EjbCommon.S_EMPLOYEE_JNDI, SbnEmployeeHome.class);      SbnEmployee remote = home.create();      return remote.insert(model);    }    catch (NamingException e) {throw e;}    catch (RemoteException e) {throw e;}    catch (CreateException e) {throw e;}  }  public boolean delete(String strPk) throws NamingException, RemoteException, CreateException,RemoveException,FinderException  {    try    {      SbnEmployeeHome home = (SbnEmployeeHome) EjbCommon.getRemoteEJBHome(EjbCommon.S_EMPLOYEE_JNDI, SbnEmployeeHome.class);      SbnEmployee remote = home.create();      boolean b = remote.del(strPk);      return b;    }    catch (NamingException e) {throw e;}    catch (RemoteException e) {throw e;}    catch (CreateException e) {throw e;}    catch (RemoveException e) {throw e;}    catch (FinderException e) {throw e;}  }  public boolean delSome(String[] sId) throws Exception  {    try    {      SbnEmployeeHome home = (SbnEmployeeHome) EjbCommon.getRemoteEJBHome(EjbCommon.S_EMPLOYEE_JNDI, SbnEmployeeHome.class);      SbnEmployee remote = home.create();      remote.delSome(sId);    }    catch (Exception e) {throw e;}    return true;  }  public EmployeeModel update(EmployeeModel model) throws NamingException, RemoteException, CreateException,FinderException  {    try    {      SbnEmployeeHome home = (SbnEmployeeHome) EjbCommon.getRemoteEJBHome(EjbCommon.S_EMPLOYEE_JNDI, SbnEmployeeHome.class);      SbnEmployee remote = home.create();      return remote.update(model);    }    catch (NamingException e) {throw e;}    catch (RemoteException e) {throw e;}    catch (CreateException e) {throw e;}    catch (FinderException e) {throw e;}  }  public EmployeeModel findByPk(String strPk)  throws NamingException, RemoteException, CreateException,FinderException  {    try    {      SbnEmployeeHome home = (SbnEmployeeHome) EjbCommon.getRemoteEJBHome(EjbCommon.S_EMPLOYEE_JNDI, SbnEmployeeHome.class);      SbnEmployee remote = home.create();      return remote.findByPk(strPk );    }    catch (NamingException e) {throw e;}    catch (RemoteException e) {throw e;}    catch (CreateException e) {throw e;}    catch (FinderException e) {throw e;}  }  public ArrayList queryBySql(String sql)  throws NamingException, RemoteException, CreateException,SQLException  {    try    {      SbnEmployeeHome home = (SbnEmployeeHome) EjbCommon.getRemoteEJBHome(EjbCommon.S_EMPLOYEE_JNDI, SbnEmployeeHome.class);      SbnEmployee remote = home.create();      return remote.queryBySql(sql);    }    catch (NamingException e) {throw e;}    catch (RemoteException e) {throw e;}    catch (CreateException e) {throw e;}    catch (SQLException e) {throw e; }  }  public boolean deleteBatch(String[] sId) throws NamingException, RemoteException, CreateException,SQLException  {    boolean b = false;    try    {      SbnEmployeeHome home = (SbnEmployeeHome) EjbCommon.getRemoteEJBHome(EjbCommon.S_EMPLOYEE_JNDI, SbnEmployeeHome.class);      SbnEmployee remote = home.create();      b = remote.delBatch(sId);    }    catch (NamingException e) {throw e;}    catch (RemoteException e) {throw e;}    catch (CreateException e) {throw e;}    catch (SQLException  e) {throw e;}    finally{return b;}  }  public EmployeeAction() {}  public static void main(String[] args)  {    EmployeeAction action = new EmployeeAction();    EmployeeModel model = new EmployeeModel();    /*测试add()方法    System.out.println("测试add()方法");    for (int i = 0; i <19; i++)    {      System.out.println("第 "+i+"个, ");      model.setName("name" + i);      model.setJob("job1");      model.setHireDate(java.sql.Date.valueOf( "2003-07-21") );      model.setSal(java.math.BigDecimal.valueOf(199));      try      {        action.add(model);      }      catch (Exception e) {e.printStackTrace();}    }    //测试delete()方法    System.out.println("测试delete()方法");    try    {      action.delete("ID_2004052855D680DF81085725842500"); //这个主键的值是都数据库里面找的。    }    catch (Exception e) {e.printStackTrace();}    //测试deleteBatch()方法*/    String[] strSID = { "ID_2004052855D680DF81085725846046", "ID_2004052855D680DF81085725846125", "ID_2004052855D680DF81085725846187" };    try    {      //action.deleteBatch( strSID );      action.delSome( strSID );    }    catch ( Exception e ) { e.printStackTrace(); }    /*/测试findByPk()方法    String strPK = "ID_2004052855D680DF81085725846046";    try    {      model = action.findByPk( strPK );      System.out.println("找到的name=" + model.getName());    }    catch ( Exception e ) {e.printStackTrace();}    //测试queryBySql()方法    String strSql = "job='job1'";    ArrayList alRet = null;    try{      alRet = action.queryBySql( strSql );      if ( alRet != null && alRet.size() > 0)      {        for ( int i = 0; i < alRet.size(); i ++ )        {          model = ( EmployeeModel ) alRet.get( i );          System.out.println("找到符合条件的第" + (i+1) + "个记录,name=" + model.getName());        }      }      else      {        System.out.println("没有找到记录");      }    }    catch ( Exception e ) {e.printStackTrace();}    //调试update()函数    String strPK1 = "ID_2004052855D680DF81085725846046";    try    {      model = action.findByPk( strPK1 );      System.out.println("找到的旧的name=" + model.getName());      model.setName( "我是你老汉" );      action.update( model );    }    catch ( Exception e ) {e.printStackTrace();}*/    System.out.println("*********结束!");  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -