hotelmanagerfacadebean.java
来自「hotel management system」· Java 代码 · 共 420 行
JAVA
420 行
/*
* Copyright 2005-2007 Kevin A. Lee
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package net.sourceforge.hoteldj.ejb;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import javax.ejb.EJBException;
import javax.ejb.ObjectNotFoundException;
import javax.ejb.SessionContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import net.sourceforge.hoteldj.ejb.ReservationLocal;
import net.sourceforge.hoteldj.ejb.CustomerLocal;
/**
* Stateless Session Bean to act as Facade
*
* @author Kevin A. Lee
* @email kevin.lee@buildmeister.com
*
* <!-- begin-xdoclet-definition -->
* @ejb.bean name="HotelManagerFacadeBean" type="Stateless"
* jndi-name="net.sourceforge.hoteldj.ejb.HotelManagerFacadeBean"
* local-jndi-name="java:comp/env/ejb/HotelManagerFacade"
* view-type="both"
*
* @ejb.permission unchecked="true"
*
* @ejb.interface generate="local,remote"
* local-class="net.sourceforge.hoteldj.ejb.HotelManagerFacadeLocal"
* remote-class="net.sourceforge.hoteldj.ejb.HotelManagerFacade"
* @ejb.home generate="local,remote"
* local-class="net.sourceforge.hoteldj.ejb.HotelManagerFacadeLocalHome"
* remote-class="net.sourceforge.hoteldj.ejb.HotelManagerFacadeHome"
* @ejb.util generate="physical"
*
* @ejb.ejb-ref ejb-name="Customer" view-type="local" ref-name="ejb/Customer"
* @ejb.ejb-ref ejb-name="Reservation" view-type="local"
* ref-name="ejb/Reservation"
*
* @web.ejb-local-ref name="ejb/HotelManagerFacade" type="Session"
* home="net.sourceforge.hoteldj.ejb.HotelManagerFacadeLocalHome"
* local="net.sourceforge.hoteldj.ejb.ManagerFacadeLocal"
* link="HotelManagerFacadeBean" <!-- end-xdoclet-definition
* -->
*
* @generated
*/
public abstract class HotelManagerFacadeBean implements javax.ejb.SessionBean {
/**
* get a specific customer via their unique id
*
* @ejb.interface-method view-type="local"
* @param customerId
* @return CustomerLocal
*/
public CustomerLocal getCustomer(Integer customerId) {
Context context = null;
CustomerLocal customer = null;
try {
context = new InitialContext();
CustomerLocalHome customerHome = (CustomerLocalHome) context
.lookup(CustomerLocalHome.JNDI_NAME);
customer = customerHome.findByPrimaryKey(customerId);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
return customer;
}
/**
* get a customer by their name
*
* @ejb.interface-method view-type="local"
* @param customerId
* @return CustomerLocal
*/
public CustomerLocal getCustomerByName(String firstName, String lastName) {
Context context = null;
CustomerLocal customer = null;
try {
context = new InitialContext();
CustomerLocalHome customerHome = (CustomerLocalHome) context
.lookup(CustomerLocalHome.JNDI_NAME);
customer = customerHome.findByName(lastName);
} catch (ObjectNotFoundException ex) {
// customer does not exist - ignore
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
return customer;
}
/**
* create a new customer
*
* @ejb.interface-method view-type="local"
* @param firstName
* @param lastName
* @return CustomerLocal
*/
public CustomerLocal newCustomer(String firstName, String lastName) {
Context context = null;
CustomerLocal customer = null;
try {
context = new InitialContext();
CustomerLocalHome customerHome = (CustomerLocalHome) context
.lookup(CustomerLocalHome.JNDI_NAME);
customer = customerHome.create(firstName, lastName);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
return customer;
}
/**
* get a Reservation by its unique id
*
* @ejb.interface-method view-type="local"
* @param resId
* @return ReservationLocal
*/
public ReservationLocal getReservation(Integer resId) {
Context context = null;
ReservationLocal res = null;
try {
context = new InitialContext();
ReservationLocalHome resHome = (ReservationLocalHome) context
.lookup(ReservationLocalHome.JNDI_NAME);
res = resHome.findByPrimaryKey(resId);
} catch (ObjectNotFoundException e) {
return null;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
return res;
}
/**
* get all of the Reservations for a Customer
*
* @ejb.interface-method view-type="local"
* @param customerId
* @return
*/
public Collection getReservationsInformation(Integer customerId) {
Context context = null;
ArrayList resBeanList = new ArrayList();
try {
context = new InitialContext();
CustomerLocalHome customerHome = (CustomerLocalHome) context
.lookup(CustomerLocalHome.JNDI_NAME);
CustomerLocal customer = customerHome.findByPrimaryKey(customerId);
Iterator resIterator = customer.getReservations().iterator();
while (resIterator.hasNext()) {
ReservationData reservation = new ReservationData();
ReservationLocal resLocal = (ReservationLocal) resIterator
.next();
reservation.setArrival_date(resLocal.getArrival_date());
reservation.setNum_guests(resLocal.getNum_guests());
reservation.setNum_nights(resLocal.getNum_nights());
resBeanList.add(reservation);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
return resBeanList;
}
/**
* create a new Reservation
*
* @ejb.interface-method view-type="local"
* @param arrivalDate
* @return ReservationLocal
*/
public ReservationLocal newReservation(Integer numGuests, Date arrivalDate,
Integer numNights, Integer custID) {
Context context = null;
ReservationLocal reservation = null;
try {
context = new InitialContext();
ReservationLocalHome reservationHome = (ReservationLocalHome) context
.lookup(ReservationLocalHome.JNDI_NAME);
reservation = reservationHome.create(numGuests, arrivalDate,
numNights);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
reservation.setCust_id_fk(custID);
return reservation;
}
/**
* check room availability
*
* @ejb.interface-method view-type="local"
* @param arrivalDate
* @return ReservationLocal
*/
public boolean checkAvailability(Integer numGuests, Date arrivalDate,
Integer numNights) {
Context context = null;
//ReservationLocal reservation = null;
boolean available = true;
try {
context = new InitialContext();
//ReservationLocalHome reservationHome = (ReservationLocalHome) context
// .lookup(ReservationLocalHome.JNDI_NAME);
//TODO: check room table
// reservation = reservationHome.create(numGuests, arrivalDate,
// numNights);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
return available;
}
/**
* update a Reservation by its id
*
* @ejb.interface-method view-type="local"
* @param resId
* @return ReservationLocal
*/
public ReservationLocal updateReservation(Integer resId, Date arrivalDate,
Integer numNights, Integer numGuests) {
Context context = null;
ReservationLocal res = null;
try {
context = new InitialContext();
ReservationLocalHome resHome = (ReservationLocalHome) context
.lookup(ReservationLocalHome.JNDI_NAME);
res = resHome.findByPrimaryKey(resId);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
res.setArrival_date(new java.sql.Date(arrivalDate.getTime()));
res.setNum_nights(numNights);
res.setNum_guests(numGuests);
return res;
}
/**
* delete a Reservation by its id
*
* @ejb.interface-method view-type="local"
* @param resId
* @return ReservationLocal
*/
public boolean deleteReservation(Integer resId) {
Context context = null;
ReservationLocal res = null;
try {
context = new InitialContext();
ReservationLocalHome resHome = (ReservationLocalHome) context
.lookup(ReservationLocalHome.JNDI_NAME);
res = resHome.findByPrimaryKey(resId);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
try {
res.remove();
} catch (Exception ex) {
return false;
}
return true;
}
/**
*
* <!-- begin-xdoclet-definition -->
*
* @ejb.create-method view-type="remote" <!-- end-xdoclet-definition -->
* @generated
*
* //TODO: Must provide implementation for bean create stub
*/
public void ejbCreate() {
}
/*
* (non-Javadoc)
*
* @see javax.ejb.SessionBean#ejbActivate()
*/
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/*
* (non-Javadoc)
*
* @see javax.ejb.SessionBean#ejbPassivate()
*/
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/*
* (non-Javadoc)
*
* @see javax.ejb.SessionBean#ejbRemove()
*/
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/*
* (non-Javadoc)
*
* @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
*/
public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {
// TODO Auto-generated method stub
}
/*
*
*/
public HotelManagerFacadeBean() {
// TODO Auto-generated constructor stub
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?