Implement Repository Layer
Overview
Methods in the service layer, upon performing all the business logic, call methods in the repository layer to persist or lookup data i.e. it interacts with the configured data store. For executing the queries, JdbcTemplate class is used. JdbcTemplate takes care of the creation and release of resources such as creating and closing the connection etc. All database operations namely insert, update, search and delete can be performed on the database using methods of JdbcTemplate class.
Steps
On DIGIT the create and update operations are handled asynchronously.
The persister service listens on the topic to which service applications are pushed for insertion and updation. Persister then takes care of executing insert and update operations on the database without clogging the applicationβs threads.
The execution of search queries on the database returns applications as per the search parameters provided by the user.
Implement Repository Layer
Define POJOs - The Address object is defined in the common contract (refer to the API spec). Link it to the birth registration table via the registrationId as defined in the DB schema.
Update the Address POJO using the below code:
@JsonProperty("registrationId")
private String registrationId = null;Define a BirthApplicationSearchCriteria POJO to take care of search requests in the DB.
package digit.web.models;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import java.util.List;
@Data
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
public class BirthApplicationSearchCriteria {
@JsonProperty("tenantId")
private String tenantId;
@JsonProperty("status")
private String status;
@JsonProperty("ids")
private List<String> ids;
@JsonProperty("applicationNumber")
private String applicationNumber;
}Create packages - Add the
querybuilderandrowmapperpackages within the repository folder.Create a class - by the name of BirthApplicationQueryBuilder in
querybuilderfolder and annotate it with@Componentannotation.Insert the following content in BirthApplicationQueryBuilder class -
Create a class - by the name of BirthApplicationRowMapper within the rowmapper package and annotate it with @Component.
Add the following content to the class.
Create a class - by the name of BirthRegistrationRepository within the repository folder and annotate it with @Repository annotation.
Add the following content to the class.
The repository layer is implemented.
Last updated
Was this helpful?