系统分析与设计-hw5

领域建模、数据库建模

Posted by Lumman on April 29, 2018

1、领域建模

a. 阅读 Asg_RH 文档,按用例构建领域模型

按照Task2的要求来识别实体(E)和中介实体(M):实体类名以E开头,中介实体类名以M开头。构建的领域模型如下:

domain model

b. 数据库建模(E-R 模型)

用MySQL Workbench构建的系统的 E-R 模型(数据逻辑模型)如下:

database

导出Mysql物理数据库脚本如下:

-- MySQL Script generated by MySQL Workbench
-- Sun Apr 29 21:11:38 2018
-- Model: New Model    Version: 1.0
-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
USE `mydb` ;

-- -----------------------------------------------------
-- Table `mydb`.`Traveler`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Traveler` (
  `id` INT NOT NULL,
  `name` VARCHAR(45) NOT NULL,
  `email` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Location`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Location` (
  `code` INT NOT NULL,
  `name` VARCHAR(45) NOT NULL,
  `hot` INT NULL,
  PRIMARY KEY (`code`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Hotel`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Hotel` (
  `idHotel` INT NOT NULL,
  `name` VARCHAR(45) NOT NULL,
  `star level` INT NOT NULL,
  `address` VARCHAR(100) NOT NULL,
  `Location_idLocation` INT NOT NULL,
  PRIMARY KEY (`idHotel`),
  INDEX `Location_idLocation_idx` (`Location_idLocation` ASC),
  CONSTRAINT `Location_idLocation`
    FOREIGN KEY (`Location_idLocation`)
    REFERENCES `mydb`.`Location` (`code`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`CreditCard`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`CreditCard` (
  `number` INT NOT NULL,
  `type` VARCHAR(45) NULL,
  `security code` INT NOT NULL,
  `Traveler_idTraveler` INT NOT NULL,
  PRIMARY KEY (`number`),
  INDEX `Travler_idTraveler_idx` (`Traveler_idTraveler` ASC),
  CONSTRAINT `Travler_idTraveler`
    FOREIGN KEY (`Traveler_idTraveler`)
    REFERENCES `mydb`.`Traveler` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Payment`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Payment` (
  `idPayment` INT NOT NULL,
  `price` INT NOT NULL,
  `CreditCard_number` INT NOT NULL,
  PRIMARY KEY (`idPayment`),
  INDEX `CreditCard_number_idx` (`CreditCard_number` ASC),
  CONSTRAINT `CreditCard_number`
    FOREIGN KEY (`CreditCard_number`)
    REFERENCES `mydb`.`CreditCard` (`number`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Room`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Room` (
  `idRoom` INT NOT NULL,
  `price` INT NOT NULL,
  `type` VARCHAR(45) NOT NULL,
  `Hotel_idHotel` INT NOT NULL,
  PRIMARY KEY (`idRoom`),
  INDEX `Hotel_idHotel_idx` (`Hotel_idHotel` ASC),
  CONSTRAINT `Hotel_idHotel`
    FOREIGN KEY (`Hotel_idHotel`)
    REFERENCES `mydb`.`Hotel` (`idHotel`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`RoomState`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`RoomState` (
  `idRoomState` INT NOT NULL,
  `check in date` DATE NOT NULL,
  `check out date` DATE NOT NULL,
  `isAvaliable` TINYINT NOT NULL,
  `Room_idRoom` INT NOT NULL,
  PRIMARY KEY (`idRoomState`),
  INDEX `Room_idRoom_idx` (`Room_idRoom` ASC),
  CONSTRAINT `Room_idRoom`
    FOREIGN KEY (`Room_idRoom`)
    REFERENCES `mydb`.`Room` (`idRoom`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Reservation`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Reservation` (
  `idReservation` INT NOT NULL,
  `hotel name` VARCHAR(45) NOT NULL,
  `room type` VARCHAR(45) NOT NULL,
  `check in date` DATE NOT NULL,
  `check out date` DATE NOT NULL,
  `Customer_idCustomer` INT NOT NULL,
  `Hotel_idHotel` INT NOT NULL,
  `Payment_idPayment` INT NOT NULL,
  `RoomState_idRoomState` INT NOT NULL,
  PRIMARY KEY (`idReservation`, `RoomState_idRoomState`),
  INDEX `idCustomer_idx` (`Customer_idCustomer` ASC),
  INDEX `Hotel_idHotel_idx` (`Hotel_idHotel` ASC),
  INDEX `Payment_idPayment_idx` (`Payment_idPayment` ASC),
  INDEX `fk_Reservation_RoomState1_idx` (`RoomState_idRoomState` ASC),
  CONSTRAINT `Customer_idCustomer`
    FOREIGN KEY (`Customer_idCustomer`)
    REFERENCES `mydb`.`Traveler` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `Hotel_idHotel`
    FOREIGN KEY (`Hotel_idHotel`)
    REFERENCES `mydb`.`Hotel` (`idHotel`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `Payment_idPayment`
    FOREIGN KEY (`Payment_idPayment`)
    REFERENCES `mydb`.`Payment` (`idPayment`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Reservation_RoomState1`
    FOREIGN KEY (`RoomState_idRoomState`)
    REFERENCES `mydb`.`RoomState` (`idRoomState`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

数据库逻辑模型 与 领域模型 的异同

领域模型:对领域内的概念类或现实世界中对象的可视化表示。反映的是问题域的相关业务概念及其关系,领域模型是用户业务描述的高度抽象,来源于业务需求的描述,同时又可以帮助用户和需求分析人员更好的理解业务需求。

数据库逻辑模型:对数据库结构的表示,是对概念模型的具体化,是系统设计与开发的一部分。

相同点:领域建模和数据库建模都是通过类或实体、属性、关联构建的,表示形式很相似。

不同点:领域模型注重于从用例的概念类中找到它们之间的联系,而数据库逻辑模型注重于将类和属性转换为具体的数据存储类型,并将类之间的联系转换为实体间的关系。