构建富 Internet 应用程序 :使用 OpenLaszlo、Eclipse Laszlo IDE 和 Web Tools
2009-12-19 00:00:00 来源:WEB开发网清单 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()]);
}
}
- ››构建Windows 8风格应用23-App Bar概述及使用规范
- ››构建域名服务器(DNS)
- ››Internet Explorer 无法打开
- ››应用程序的配置管理Poco
- ››构建Android平台Google Map应用
- ››构建WinForm 通用速选(全选、反选、清空)组件
- ››构建Wordpress网站首选的5家国外主机
- ››Internet Explorer 9 Platform 1.9.7916.6000 Pre...
- ››构建高性能和高弹性 WebSphere eXtreme Scale 应用...
- ››应用程序开发者偏好苹果也关注Android
- ››构建前端UI组件的新思路
- ››构建 Android 开发环境
更多精彩
赞助商链接