Chapter 1. Magazine Shop
Prev | Part VI. Reverse Mapping Tool Tutorial | Next

## Chapter 1. Magazine Shop

You run a shop that sells magazines. You store information about your inventory in a relational database with the following schema:

    -- Holds information on available magazines
    CREATE TABLE MAGAZINE (
        ISBN VARCHAR(8) NOT NULL,
        ISSUE INTEGER NOT NULL,
        NAME VARCHAR(255),
        PUBLISHER_NAME VARCHAR(255)
        PRICE FLOAT NOT NULL,
        PRIMARY KEY (ISBN, ISSUE)
        FOREIGN KEY (PUBLISHER_NAME) REFERENCES PUBLISHER (NAME)
    );

    -- Holds information on magazine articles
    CREATE TABLE ARTICLE (
        TITLE VARCHAR(255) NOT NULL,
        AUTHOR_NAME VARCHAR(128),
        PRIMARY KEY (TITLE)
    );

    -- Holds all the subtitles of an article
    CREATE TABLE ARTICLE_SUBTITLES (
        ARTICLE_TITLE VARCHAR(255),
        SUBTITLE VARCHAR(128),
        FOREIGN KEY (ARTICLE_TITLE) REFERENCES ARTICLE (TITLE)
    );

    -- Join table linking magazines and articles
    CREATE TABLE MAGAZINE_ARTICLES (
        MAGAZINE_ISBN VARCHAR(8),
        MAGAZINE_ISSUE INTEGER,
        ARTICLE_TITLE VARCHAR(255),
        FOREIGN KEY (MAGAZINE_ISBN, MAGAZINE_ISSUE) REFERENCES MAGAZINE (ISBN, ISSUE),
        FOREIGN KEY (ARTICLE_TITLE) REFERENCES ARTICLE (TITLE)
    );

    -- Each magazine has a 1-1 relation to its publisher
    CREATE TABLE PUBLISHER (
        NAME VARCHAR(255) NOT NULL,
        REVENUE FLOAT NOT NULL,
        PRIMARY KEY (NAME)
    );

You've decided to write an application that will let you query your database through JDO.

Prev | Up | Next
Introduction to the Reverse Mapping Tool Tutorial | Home | Chapter 2. Setup