Generic CRUD Service

Introduction

You can manage the flow from the Entity level to the REST or View (MVC's View) level with the SpringVIP Library.

res

JPARepository, IGenericServiceCrud and AGenericServiceCrud components could be seen on the figure above already provided by library and Spring Framework to the developer.

  • JPARepository which is a generic repository, already provided by Sping Data.
  • In additon to that IGenericServiceCrud and AGenericServiceCrud provided by SpringVIP library.

The core feature provided by SpringVIP library is that Generic CRUD Service implementation for service layer. Generic CRUD Service consists of two components.

  • IGenericServiceCrud provides definiitons of generic CRUD methods for entities
  • AGenericServiceCrud implements methods defined in IGenericServiceCrud in a generic manner.

Services extends to AGenericServiceCrud inherits methods from SpringVIP Library, like create, read, update, delete methods and so on. Thus developers can use boilerplate service methods quickly.

Methods

All DB operations are done via JPARepository in Generic CRUD Service. All exceptions occurred on JPARepository layer is handled by Generic CRUD Service then an exception thrown. There are some methods for basic CRUD operations are included in Generic CRUD Service. They are;

Description
GetAllTo get all records on the database
GetByIdTo get record that matching id
SaveTo save(create or update) entity
CreateTo create a record by entity
UpdateTo update a record by entity
DeleteTo delete a record by entity
DeleteByIdTo delete record by Id

Exceptions

There are some general exceptions can be thrown by generic CRUD service implementation (AGenericServiceCrud).

Description
DatabaseCreateExceptionindicates there is an error on Create operation
DatabaseDeleteExceptionindicates there is an error on Delete operation
DatabaseReadExceptionindicates there is an error on Read operation
DatabaseSaveExceptionindicates there is an error on Save operation
DatabaseUpdateExceptionindicates there is an error on Update operation

Example Usage

To use Generic CRUD Service feature you need following;

Let's assume you have an entity named as Person on database and you have entity repository named as IPersonRepo

1) Create a new service interface

2) Implement service created on previous step