In this part, we will discuss the tools that we can use in designing our database. We will also create a database schema for our catalog project.
I normally use SQL Power Architect when I’m designing a database schema of a project from scratch. I include the primary as well as the foreign keys but not the rest of the columns since for now, I’m only after about the relationship of the tables with each other.
[show the SQL power architect]
Again, here’s our schema. Really there’s nothing trivial here.
Let’s create the java classes accordingly.
When dealing with business entities like category, product, dealer, dealer group, etc we normally assign a unique identifier to them. Let’s call that code and let’s also add a description. At the very least, we now have 2 common fields within a subset of the entity classes and note that we have the primary key id too.
[show businessEntity class]
We can refactor code and description as an abstract base class. Let’s name it BusinessEntity. And we could go further like creating abstract EnableEntity which as the name implies, lets us enable and disable an entity. AuditableEntity, which has an embeddable field Auditable that contains the author and date when an entity is created or updated. And finally, the BaseEntity which contains the autogenerated id of UUID type.
[show enable, auditable and base entity classes]
Let’s take a look at the entity classes and compared it to our schema diagram.