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

📄 suppliercontrollerbean.java

📁 一个java
💻 JAVA
字号:
package bookstore.ejb;import bookstore.util.*;import java.sql.*;import javax.sql.*;import java.util.*;import javax.ejb.*;public class SupplierControllerBean implements SessionBean{  SessionContext sessionContext;  private String supplierID;  private SupplierHome supplierHome;  private Supplier supplier;  private Connection con;  /*************************** removal methods*****************************/public String createSupplier(SupplierDetails supplierValue) throws Exception {      // makes a new Supplier and enters it into db,      // returns SupplierId      System.out.println("SupplierControllerBean createSupplier");      try      {        supplier = supplierHome.create(supplierValue);      }      catch (Exception ex)      {          throw new EJBException           ("createSupplier: " + ex.getMessage());      }      return supplierID;  }// createSupplier  public void removeSupplier(String supplierId) throws NoSuchEntityException {    //抛出RunTimeException的子类,有利于事务管理       // removes Supplier from db        System.out.println("SupplierControllerBean removeSupplier");        if (isSupplierExist(supplierId) == false)            throw new NoSuchEntityException(supplierId);        try {             supplier.remove();//Supplier已在isSupplierExist中获得            }catch (Exception ex)            {             throw new EJBException             ("removeSupplier: " + ex.getMessage());        }    } // removeSupplier    public void updateSupplier(SupplierDetails supplierValue)        throws NoSuchEntityException     {       System.out.println("SupplierControllerBean updateSupplier");       if (isSupplierExist(supplierValue.getSupplierID()) == false)            throw new NoSuchEntityException(supplierValue.getSupplierID());         supplier.setCompany(supplierValue.getCompany());         supplier.setPerson(supplierValue.getPerson());         supplier.setPhone(supplierValue.getPhone());         supplier.setAddress(supplierValue.getAddress());         supplier.setZip(supplierValue.getZip());     }//updateSupplier     public SupplierDetails getSupplierValue(String supplierId)     {       System.out.println("SupplierControllerBean getSupplierValue");       try            {                supplier = supplierHome.findByPrimaryKey(supplierId);                this.supplierID = supplierId;            } catch (Exception ex)            {                return null;            }            return supplier.getDetails();     }/******************************ejb methods*********************************/  public void ejbCreate() throws CreateException {    System.out.println("SupplierControllerBean ejbCreate");        try {            //创建下一层的引导接口            supplierHome=EJBGetter.getSupplierHome();        } catch (Exception ex) {             System.out.println("SupplierControllerBean catch");             throw new EJBException("ejbCreate: " +                 ex.getMessage());        }        supplier = null;        supplierID = null;  }//ejbCreate  public void ejbRemove() {    /**@todo Complete this method*/  }  public void ejbActivate() {    /**@todo Complete this method*/  }  public void ejbPassivate() {    /**@todo Complete this method*/  }  public void setSessionContext(SessionContext sessionContext) {    this.sessionContext = sessionContext;  }  /**********************************util methods****************************/  private boolean isSupplierExist(String supplierId) {        // If a business method has been invoked with        // a different SupplierId, then update the        // SupplierId and Supplier variables.        // Return null if the Supplier is not found.        System.out.println("SupplierControllerBean isSupplierExist");        if (supplierId.equals(this.supplierID) == false)        {            try            {                supplier = supplierHome.findByPrimaryKey(supplierId);                this.supplierID = supplierId;            } catch (Exception ex)            {                return false;            }        } // if        return true;    }// isSupplierExist}

⌨️ 快捷键说明

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