WEB开发网
开发学院软件开发Java 构建富 Internet 应用程序 :使用 OpenLaszlo、Ec... 阅读

构建富 Internet 应用程序 :使用 OpenLaszlo、Eclipse Laszlo IDE 和 Web Tools

 2009-12-19 00:00:00 来源:WEB开发网   
核心提示: 清单 1 是下一节中公开为 Web 服务的 WorkOrderService 类。清单 1. WorkOrderService 类packagecom.ibm.laszlo.services;importjava.util.ArrayList;importjava.util.Date;impor

清单 1 是下一节中公开为 Web 服务的 WorkOrderService 类。


清单 1. WorkOrderService 类
package com.ibm.laszlo.services; 
 
import java.util.ArrayList; 
import java.util.Date; 
import java.util.List; 
 
import org.hibernate.Session; 
import org.hibernate.Transaction; 
 
import com.ibm.laszlo.dto.Building; 
import com.ibm.laszlo.dto.Floor; 
import com.ibm.laszlo.dto.WorkOrder; 
import com.ibm.laszlo.util.HibernateUtil; 
 
/** 
 * Service for work order management. 
 */ 
public class WorkOrderService { 
 
 /** 
  * Finds a specific work order by id. 
  * @param id unique id of work order. 
  * @return work order. 
  */ 
 public WorkOrder findWorkOrderById(int id) { 
  Session session = HibernateUtil.currentSession(); 
  Transaction tx = session.beginTransaction(); 
 
  WorkOrder workOrder = (WorkOrder) session.get( 
    WorkOrder.class, new Integer(id)); 
 
  tx.commit(); 
  HibernateUtil.closeSession(); 
 
  return workOrder; 
 } 
 
 /** 
  * Returns all work orders. 
  * @return all work orders. 
  */ 
 public WorkOrder[] findAllWorkOrders() { 
  Session session = HibernateUtil.currentSession(); 
  Transaction tx = session.beginTransaction(); 
 
  List workOrders = session.createQuery("from WorkOrder").list(); 
 
  tx.commit(); 
  HibernateUtil.closeSession(); 
 
  return (WorkOrder[])workOrders.toArray( 
     new WorkOrder[workOrders.size()]); 
 } 
 
 /** 
  * Create a new work order. 
  * @param contact contact person's name. 
  * @param phone contact person's phone number. 
  * @param email contact person's email. 
  * @param description description of problem. 
  * @param building building problem is in. 
  * @param floor floor in building with problem. 
  * @param severity severity of the problem. 
  * @return new work order's id. 
  */ 
 public int createWorkOrder(String contact, String phone, 
   String email, String description, 
   String building, String floor, int severity) { 
 
  Session session = HibernateUtil.currentSession(); 
  Transaction tx = session.beginTransaction(); 
 
  WorkOrder workOrder = new WorkOrder(contact, phone, 
    email, building, floor, description, severity); 
 
  Date currentDate = new Date(); 
  workOrder.setDateRequested(currentDate); 
  workOrder.setLastModified(currentDate); 
  workOrder.setStatus(WorkOrder.STATUS_REQUESTED); 
 
  session.saveOrUpdate(workOrder); 
 
  tx.commit(); 
  HibernateUtil.closeSession(); 
  return workOrder.getId(); 
 } 
 
 /** 
  * Collection of buildings and their floors. 
  * NOTE: Hard coded for simplicity but could be read from a 
  * database. 
  * @return 
  */ 
 public Building[] getBuildings() { 
  List buildings = new ArrayList(); 
  Building building = new Building(1, "HQ"); 
  building.addFloor(new Floor(1, "Floor 1")); 
  building.addFloor(new Floor(2, "Floor 2")); 
  building.addFloor(new Floor(3, "Mezzanine")); 
  buildings.add(building); 
  building = new Building(2, "Trump Tower"); 
  building.addFloor(new Floor(1, "Trump 1")); 
  building.addFloor(new Floor(2, "Trump 2")); 
  building.addFloor(new Floor(3, "Trump 3")); 
  buildings.add(building); 
  return (Building[])buildings.toArray( 
    new Building[buildings.size()]); 
 } 
} 

上一页  5 6 7 8 9 10 

Tags:构建 Internet 应用程序

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接