In this article, I am going to show a simple demo application that demonstrates how you can use SQL to define a schema and manipulate data objects with Matisse. More detailed discussions will follow in the subsequent articles.
First of all, you need to start a database. Start the Enterprise Manager, select a database, and select the Start menu. The database will be on-line within a couple of seconds:
The data model that we are going to use is for project management, in which we define three classes Project
, Employee
, and Manager
as depicted using UML in the next figure.
If you have Rational Rose, you can simply export the UML diagram into your database. Choose Export to Database... menu under Tools/Matisse :
If you do not have Rational Rose, you can use SQL DDL or ODL (Object Definition Language). The following DDL statements are equivalent to the above UML diagram.
CREATE TABLE Project (
ProjectName STRING,
Budget NUMERIC(19,2),
Members REFERENCES (Employee)
CARDINALITY (1, -1)
INVERSE Employee.WorksIn,
ManagedBy REFERENCES (Manager)
CARDINALITY (1, 1)
INVERSE Manager.Manages
);
CREATE TABLE Employee (
Name STRING,
BirthDate DATE,
WorksIn REFERENCES (Project)
INVERSE Project.Members
);
CREATE TABLE Manager UNDER Employee (
Title STRING,
Manages REFERENCES (Project)
INVERSE Project.ManagedBy
);
To execute the above DDL statements, copy and paste them into the SQL Query Analyzer window, and execute them.
Here, you see an advantage in database modeling with Matisse. You do not need any transformation of your model, and all the semantic information about associations between classes and their constraints are kept in the database schema as they are. This is a big plus for maintenance and extension of the application.
We can now create objects in the database. Execute the following SQL statements in the SQL Query Analyzer window as shown above:
INSERT INTO Employee (Name, BirthDate)
VALUES ('John Venus', DATE '1955-10-01')
RETURNING INTO emp1;
INSERT INTO Employee (Name, BirthDate)
VALUES ('Amy Mars', DATE '1965-09-25')
RETURNING INTO emp2;
INSERT INTO Manager (Name, BirthDate, Title)
VALUES ('Ken Jupiter', DATE '1952-12-15', 'Director')
RETURNING INTO mgr1;
INSERT INTO Project (ProjectName, Budget, ManagedBy, Members)
VALUES ('Campaign Spring 04', 10000.00, mgr1, SELECTION(emp1, emp2));
The above statements create two Employee
objects, a Manager
object, a Project
object, and then assign the two employees to the project as its members and the manager as the project manager.
Comments