Exercise – a simple change request

This simple exercise will again demonstrate the power of generics. Each record inserted into the database should now be logged at using logger.info() with the message:

The "className" record with ID=? has been inserted

In addition, records that are deleted should be logged using logger.warn() with the message:

The "className" record with ID=? has been deleted

In both cases, the ? token should be replaced with the ID of the entity being inserted or deleted while the className token should be replaced with the class name of the entity being inserted or deleted. This is a trivial change when using generics, as the code can be added to the persist and remove methods of the GenericDaoImpl class. Without the use of generics, each of the CompanyDaoImpl, ProjectDaoImpl, TaskDaoImpl, UserDaoImpl, and TaskLogDaoImpl classes would need to have this change made. When you consider that enterprise applications may have 20, 30, 40, or more tables represented in the DAO layer, such a trivial change may not be so trivial without the use of generics.

Your task is to implement the change request as outlined previously. Note that this exercise will introduce you to the instanceof operator.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.9.124