Architecture for Database Interaction
The architecture is usual for applications with database interaction.
All business entities are described in the packaging artist.model. Here we have a description of 3 classes Artist, Song, SongWriter – main objects of application business logic.
These objects are processed on 3 layers:
- Database layer: deals with objects on database level by appropriate entity tables and Many-To-Many tables. Access to the objects inside the database is executed by SQL requests from the DAO layer;
- DAO layer: provides an interface for manipulating with objects and retrieving objects from the database;
- Service layer: provides information about current business objects structure to the main user interface. It gets information from the database via the DAO layer. In this implementation, Console Menu is also implemented inside the service class.
As for Spring beans, all necessary beans are declared in the configuration file AppConfiguration.java.
Mainly, these injected beans are responsible for database interaction: data source object, JdbcTemplate, Dao object instance. Obtained successfully initialized ArtistDao object is used by one more bean – ArtistService. This class is annotated with @Service.