Sun应用实例Adventure Builder数据库设计

 
修订记录
Author
Contact
Change Time
 Version
Description
Lanning
thunder4393@gmail.com
2005-9-27
1.0
这是最初的版本

1       前言

1.1 背景

Java Adventure Builder Reference application是一个Sun 公司J2EE应用实例,它展示了如何在J2EE 1.4平台设计交互的和轻便的Web services。同时他也展示了J2EE技术的有效应用方式,这些技术包括JAX-RPC, JAXP, Servlet 2.4, JSP 2.0, JSTL EJBDBAdventure Builder数据库部分是用的pointbase数据库或是mysql数据库。读者可以自己选择其中的一个数据库。

1.2 写作动机和风格

Sun公司没有提供有关数据库相关设计架构方面的文章, 同时网上的也没有这方面的分析文章,这是我写这篇文章的初衷。这篇文章是对Sun所提供的BluePrints Adventure Builder数据库部分的分析和设计,依据的版本是Version 1.0.3 。这篇文章是我的最初的版本,本文侧重于分析和设计上,大量运用了图表的方式,这也是本文的创新之处,通过分析将一步一步的得出所需要的表。

Adventure Builder介绍部分我用的Sunarchitecture文章的原文,我感觉翻译过来容易失去它的本意,另一个原因我认为这对英文提高也有很大的帮助,现在一般的大点公司都是英文资料、英文邮件、英文交流,同志们英文是个前提啊。

1.3 数据库设计方法的选择

由于数据库设计的方式不同,因此,在数据库设计步骤的划分上存在差异。本文所采用的数据库的分析方法是New Orleans方法,它将数据库的设计划分为:需求分析、概念结构设计、逻辑结构设计、物理结构设计4个阶段。

1.4 谁适合阅读这篇文章?

由于这篇文章主要是对Adventure Builder 数据库部分的分析,它适合于以下人员阅读:

(1)  正在分析Adventure Builder源代码的程序员。

(2)  正在分析和设计自己所做项目数据库应用的数据库设计人员。

(3)  想学习如何分析和设计数据库的初级的数据库开发人员。

1.5 术语与缩写

ER模型的组成元素有:实体、属性、联系,ER模型用ER图表示。

实体:是用户工作环境中所涉及到事物。它相当于实体集、一个表,用矩形表示:

属性:是实体的特征的描述。是实体的性质。用椭圆表示,与实体之间用一条线相连接。

联系:实体之间的相互关系。用菱形表示。

复合实体:如果两个实体之间的联系是MN,则需要建立第三个实体,将MN联系转成两个1M联系,这第三个实体称为复合实体(composite)。

DBdatabase

2       Adventure Builder介绍

Let's start with a brief explanation of the Adventure Builder applications from a high-level perspective.

The adventure builder enterprise provides customers with a catalog of adventure packages, accommodations, and transportation options. From a browser, customers select from these options to build a vacation, such as an Adventure on Mt Kilimanjaro. Building a vacation includes selecting accommodations, mode of transport, and adventure activities, such as mountaineering, mountain biking to a hidden waterfall, and hiking the mountain. After assembling the vacation package, the customer clicks the submit order option. The customer Web site builds a purchase order and sends it to the order processing center (OPC). The order processing center, which is responsible for fulfilling the order, interacts with its internal departments, the bank(financial institution), and suppliers to complete the order.

In essence, the adventure builder enterprise consists of a front-end customer Web site, which provides a face to its customers, and a back-end order processing center, which handles the order fulfillment processing. Additionally there is a bank and three suppliers. See Figure1.

Figure 1 Adventure Builder Enterprise and Its Environment

As you can see from this diagram, there many participants in adventure builder's business process. Customers of the adventure builder Web site shop and place orders for vacation packages. They expect to have certain services available to them, such as the ability to track orders and receive e-mails about order status. Customers are expected to be browser based. The Java Adventure Builder consists of six applications ,including Customer Web site application, Order processing center application , Transportation supplier application , Lodging supplier application, Activity supplier application, Bank/financial institution application Each application is implemented as a J2EE application and the applications interact using Web services. These applications may be clients of a Web service and may also expose one or more Web service endpoints. Let's briefly discuss the six applications and the Web services they access and that they expose for other applications to access.

3       Adventure Builder概念结构设计

概念结构设计的目标是产生一个反映组织信息需的概念模型(ER模型)。其中它包括数据实体、实体之间的关系图等。

3.1  Adventure Builder实体(entity

根据Adventure Builder项目的业务环境,可以定义5个实体:冒险种类(category)、冒险包(package)、住宿(lodging)、冒险活动(activity)、帐户(account)、交通方式(transportation)。

冒险种类:冒险可以分为不同的类别,例如:Island AdventuresJungle AdventuresMountain AdventuresOrbital AdventuresSouth Pole AdventuresWestern Adventures

冒险包(package):客户可以定制的个性化冒险,通过设定住宿、冒险活动、交通方式以满足自己的需要的冒险,这里被成为冒险包。例如:Island Adventures冒险种类(category)包括: Maui Survival AdventureBahamas Relaxation tripTahiti Snorkeling Adventure。用户在选择了自己的冒险包的前提下,可以自由的设置个性化选项。

冒险活动(activity):客户实际所参见的娱乐或健身活动,客户可以自己进行设置。

3.2  Adventure Builder ER模型

根据项目的业务环境,可以得到下面的局部的ER模型:

1)      冒险(adventure)可以分成不同的冒险种类(category),每一个种类下面又包含不同的具体冒险包(在这个项目数据库表package中被称为packageid,即具体冒险活动名称)。

用户可以订阅自己喜欢的冒险包,并且可以根据自己的需求来进行设置包中的选项。

根据上述语义可知,冒险种类(category)和冒险包(package)实体之间是一对多的联系, 设计局部ER模型,如图1.1

category

sort

package

               

1                              M

 

Notesort:分类

2)      每一个冒险包(package)包括住宿(lodging)设置。它们之间是一对一的关系。设计局部ER模型,如图1.2

package

 contain

lodging

1                               1

 

 

 

3)      每一个冒险包包括了多项的冒险活动,而每一个冒险活动可以对多个冒险包。它们之间是多对多的关系。设计局部ER模型,如图1.3

package

 contain

activitylist

 M                                     N

 

 

 

4)      Adventure Builder项目中,还包含其他的两个实体,即帐户(account)、登陆(singon)、交通方式(transportation)。他们没有和其他实体发生关联。

3.3

package

category

lodging

activity

 

sort

contain

contain

整体ER模型

 

 


4       Adventure Builder逻辑结构设计

根据数据库的转换规则,可以将E-R模型转换成关系数据库。

4.1 确定表结构

这里仅举了几个例子,详细参见数据库实施。为了书写简单,用PK表示主码,FK表示外码。

1)      package(packageid, catid, locale, location, price, name, description, imageuri, lodgingid)

其中:PKpackageid,有参照完整性规则,不允许为空值(NOT NULL)。

      FKcatidlodgingid

2)      activitylist是个复合实体,是为了实现冒险包和冒险活动多对多的联系,将单独转换成一个表。这个表还包括一个locale属性。

activitylist(packageid, activityid, locale)

其中:PKpackageid , activityid ,locale。不能为空。

    FKpackageid, activityid

4.2 数据结构图

可以根据表之间的关系得出数据结构图,如图.

category(catid,locale……)

Lodging(lodgingid,locale…)

package(packageid,catid…, lodgingid

activity(activityid…)

activitylist(packageid,activityid,locale)

            Note:  

               1:1                          1:M                    

4.3 属性的某些特征

这里仅举了一个实例。当然可以先建立一个数据字典,如果项目很小的话,可以省略它。

1) 表结构:package(packageid, catid, locale, location, price, name, description, imageuri, lodgingid)

   输入实例:packageid 'PACK-1' char20, catid 'ISLAND', locale 'en_US', location 'The Island of Maui', price1115.00, name 'Maui Survival Adventure', description 'Practice your survival skills in an island paradise.', imageuri 'Island_Survival.gif', lodgingid 'LODG-1'   

5       Adventure Builder数据库实施

SQL语言建立数据库、定义表结构和插入数据,实现数据库设计的最终目标。

5.1 定义数据库和表结构

1)      建立数据库

create database adventurebuild            // suppose DB name

2)      SQL语言定义表的结构和插入的数据

请参考源代码: SourceCodeHomeDir/src/setup

6       总结

这篇文章是在Sun BluePrints提供的Adventure Builder源代码分析基础上写成的,主要参考了数据库部分,同时也参考实际运行的程序界面。通过采用常用的数据库设计方式,分为项目介绍(提供了需求)、概念设计、逻辑设计、数据库实施等阶段。

在文章中会有一些Bugs,请各位同志给出评论和指点,我会不断的完善它,我希望能给大家在分析Adventure Builder源代码和做自己相关的项目是有所帮助。

7       感悟和未来展望

Sun发布的BluePrints对软件开发人员有很大的指导意义,但是也有它的不足。在自己的项目要合理的选择,千万不要完全采用它的解决方案,因为它提供的实例是应用是适合一定的场合。

今后我想写Adventure Builder中项目管理工具ant是如何运用的文章。也想写petstore数据库设计,它的比较复杂,更有挑战性。也会写如何分析源代码的文章。但是还没有明确发布的时间表。

8       致谢

首先要感谢Sun公司给我们提供了这么好的一个实例,在这个实例中运用了最近的Webservice技术,它对需求分析人员、架构人员、程序员提供很好的参考。

9       参考资源

(1)  https://adventurebuilder.dev.java.net/。在这可以下载最新的版本,同时也以加入这个项目。

(2)  http://java.sun.com/reference/blueprints/index.html。这里提供了Sun公司BluePrints,例如Adventure BuilderPetstore

(3)  http://java.sun.com/blueprints/guidelines/designing_webservices/,提供了一本书Designing Web Services with the J2EE(TM) 1.4 Platform : JAX-RPC, SOAP, and XML Technologies。这本书对这个Adventure Builder实例有很好的分析,同时也包括关于Adventure Builder architecture分析。

(4)  http://www.csdn.netjava板块和community板块提供了很好的最新的技术文章,同时也是一个很好的交流的场所。

(5)  《数据库技术》华中理工大学出版社, 这本书是一本很好的基础书,同时它也给出了很多很好的实例。非常适合初学者学习。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值