The PSP Tools Database


One approach to developing our application was to defer the database until we absolutely were forced to implement it. If we were sure that we could release the first version of PSP Tools without a real database, we would have deferred it. But we were not sure and, if we did need it, it was important to get an estimate of how long it would take to get it working.

You may wonder how we would avoid creating the database. Java can "serialize" objects. The java.io package provides a Serializable interface. When your classes implement this interface, you are able to write objects of the class to some persistent storage, like a disk, and read them back later. We could have built a data model of the different classes and their relationships and serialized the data to a file, just as we ended up writing to a database. However, it seems much easier to let the DBMS worry about ensuring that the appropriate connections are made between objects and that two programs using the same database will not corrupt the database when they try to update the same information at the same time.

In this section we describe the physical layout of the database and look at how to access the database from Java. We will use some SQL (Structured Query Language) statements. If you are not familiar with SQL, there are many good references, but we will explain the statements we do use.

UML is a good language for describing databases, especially when you are working on an object-oriented system. [5] Even though our chosen DBMS is not an object-oriented database, we want to think of it as a data store that contains objects, not just tables. [6] We show the structure of the database and its objects in Figure 7.5.

[5] See UML for Database Design by Eric J. Naiburg and Robert A. Maksimchuk.

[6] An object-oriented database and an object-oriented database management system (OODBMS) offer advanced capabilities for storing and accessing objects. See "The Object-Oriented Database System Manifesto" by Atkinson et al. for one definition of an OODBMS. It is available on several Web sites. The easiest way to find the Manifesto is to use a search engine.

Figure 7.5. PSP Tools database structure

graphics/07fig05.gif

Figure 7.5 is quite simple, yet it conveys a lot of information. [7] It tells us that there is exactly one PSPDatabaseInfo object in any PSP Tools database. It also tells us the different types of objects that are stored in a PSP Tools database. The asterisk (*) on the arrow end of each aggregation association tells us that there can be any number of that type of object (like PSPTask) in a PSP Tools database. The objects shown in the diagram provide us with the information we need to identify the tables in our database.

[7] We assume that readers of this chapter have a basic understanding of UML. If not, there are many good references and Web sites that will give you enough information to understand the little bit of UML that we use here. A good starting place is www.omg.org/uml.

We could include more details in the diagram in Figure 7.5, but we think that more information would clutter it up. Instead, we chose to create another diagram that shows the different properties of the objects. It then becomes quite easy to use those properties to create the schema for our database. Figure 7.6 shows a diagram that describes our database in a different way, with more detail.

Figure 7.6. Diagram showing database tables and fields

graphics/07fig06.gif

We use a class diagram to show the objects that are stored in the database. There is one table for each class in the diagram. By making the attributes of each class visible, we can see the specific fields that belong in each table.

The information we get from the diagram in Figure 7.6 lets us create a script that creates an initial database. We created such a script, createdb .sql , and used it to build our test database for use during early testing. It was trivial to recreate the database when we wanted to run a new set of tests or rerun previous tests.

Figure 7.7 shows the specific fields for the PSPUser class and the associated code in createdb.sql that creates and populates the Users table. You can easily create similar diagrams to show the other table structures. We created the diagram in Figure 7.7 with Rational XDE. The figure illustrates a feature of UML tools that we think is important ”that tools such as XDE allow you to insert all kinds of information into a diagram in addition to the UML structures. In this figure, we placed the script we used to create the table in the database on the same class diagram with the associated UML class representation.

Figure 7.7. The PSPUser class and associated code from createdb.sql

graphics/07fig07.gif

We used several scripts with the Cloudview tool to create, update, and clean up our database as we made our way through the Elaboration phase. They are all available on the book's Web site.



Software Development for Small Teams. A RUP-Centric Approach
Software Development for Small Teams: A RUP-Centric Approach (The Addison-Wesley Object Technology Series)
ISBN: 0321199502
EAN: 2147483647
Year: 2003
Pages: 112

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net