In this part, we will discuss the tools that we can use in designing our database. We will also create a database schema of 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.
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.
- Database Initialization Using Liquibase
Slack Discussion Repositories https://github.com/terawarehouse/terawarehouse-cataloghttps://github.com/terawarehouse/terawarehouse-reactAfter you have finished running some tests using either the code or script base database initialization it’s now...
- Database Initialization Using Code
Slack Discussion Repositories https://github.com/terawarehouse/terawarehouse-cataloghttps://github.com/terawarehouse/terawarehouse-reactThere are various ways in which we can initialize the database. Mostly for testing purposes I find setting hibernate.ddl-auto...
- Working With Spring Data Repositories
Slack Discussion Repositories https://github.com/terawarehouse/terawarehouse-cataloghttps://github.com/terawarehouse/terawarehouse-reactJust like what we did with the entities the same approach can be used when creating the repository classes. And that...
- Spice Your Java With Lombok
Slack Discussion Repositories https://github.com/terawarehouse/terawarehouse-cataloghttps://github.com/terawarehouse/terawarehouse-react[show category entity class] Did you notice anything unusual? And this [show the rest of the catalog entity classes]...
- Create A Restful Web Service In Spring
Slack Discussion Repositories https://github.com/terawarehouse/terawarehouse-cataloghttps://github.com/terawarehouse/terawarehouse-reactTo prepare the project from future development, we will be creating a multi-maven project layout. Unfortunately,...