EJB2之照猫画虎

代理
public class EnterpriseInfoProxy {
	private static Logger logger = Logger.getLogger(EnterpriseInfoProxy.class);

	private static EnterpriseInfoProxy instance = null;

	private EnterpriseInfoProxy() {
	}

	/**
	 * 返回单个本类对象
	 * 
	 * @return CaTabProxy
	 */
	public synchronized static EnterpriseInfoProxy getInstance() {
		if (instance == null) {
			instance = new EnterpriseInfoProxy();
		}
		return instance;
	}
	/**
	 * 查询企业信息列表
	 * @param cond
	 * @return
	 * @throws DaoException
	 * @throws SystemException
	 */
	public List queryEnterpriseList(EnterpriseInfoCond cond) throws DaoException, SystemException {
		List list = null;
		try {
			RemoteServiceLocator locator = null;
			locator = RemoteServiceLocator.getInstance();

			EnterpriseInfoFacade var = ((EnterpriseInfoFacadeHome) locator
					.getHome("EnterpriseInfoFacade")).create();
			list = var.queryEnterpriseList(cond);
		} catch (DaoException daoex) {
			logger.error(daoex, daoex);
			throw daoex;
		} catch (Exception ex) {
			logger.error(ex, ex);
			throw new SystemException(ex.getMessage());
		}
		return list;
	}
}	


public interface EnterpriseInfoFacade extends EJBObject {
	/**
	 * 查询企业信息列表
	 * @param cond
	 * @return
	 * @throws DaoException
	 * @throws SystemException
	 */
	public List queryEnterpriseList(EnterpriseInfoCond cond) throws DaoException, SystemException,RemoteException;
}

public class EnterpriseInfoFacadeBean implements SessionBean {
	SessionContext sessionContext;
	private static Logger logger = Logger
			.getLogger(EnterpriseInfoFacadeBean.class);
	
	public void ejbCreate() throws CreateException {
	}
	public void ejbActivate() throws EJBException, RemoteException {
	}

	public void ejbPassivate() throws EJBException, RemoteException {
	}

	public void ejbRemove() throws EJBException, RemoteException {
	}

	public void setSessionContext(SessionContext arg0) throws EJBException,
			RemoteException {
		this.sessionContext = arg0;
	}

	/**
	 * 查询企业信息列表
	 * 
	 * @param cond
	 * @return
	 * @throws DaoException
	 * @throws SystemException
	 */
	public List queryEnterpriseList(EnterpriseInfoCond cond)
			throws DaoException, SystemException {
		DaoManager dao = null;
		List list = null;
		try {
			// 获取DAO
			dao = DaoManagerFactory.getDaoManager();
			EnterpriseInfoDao var = (EnterpriseInfoDao) dao
					.getDao(EnterpriseInfoDao.class);

			dao.startTransaction();
			list = var.getInfoList(cond);
			dao.commitTransaction();
			logger.info(list);
			return list;
		} catch (DaoException ex) {
			logger.error(ex, ex);
			throw ex;
		} catch (Exception ex) {
			logger.error(ex, ex);
			throw new SystemException(ex.getMessage());
		} finally {
			if (dao != null) {
				dao.endTransaction(); // 关闭事务,关闭数据库连接
			}
		}
	}
}

public interface EnterpriseInfoFacadeHome extends EJBHome {

	public EnterpriseInfoFacade create() throws CreateException, RemoteException;;

}


在ejb-jar.xml和jboss.xml里配置所添加的实体,打包,发布

你可能感兴趣的:(DAO,xml,jboss,ejb)