Table A
| ID | shortdescription | thumbnailimage | linkactions | Country_id |
|---|---|---|---|---|
| 165 | shortdescription | thumbnailimage | linkactions | E1796BA |
Table B
| ID | name | Country_id |
|---|---|---|
| 1 | India | E1796BA |
Controller
public ResponseEntity<ContentManagePageVO> queryAllActionsWithPagination(
@RequestParam(defaultValue = "0") Integer pageNo,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false, defaultValue = "") String filter) {
return ResponseEntity.ok(contentManageService.queryAllActionsWithPagination(filter, pageNo, pageSize));
}
Service
public ContentManagePageVO queryAllActionsWithPagination(String filter, Integer pageNo, Integer pageSize) {
Pageable paging = PageRequest.of(pageNo, pageSize,Sort.by("id"));
Page<ContentCountryDto> contentManagePage;
if(StringUtils.isBlank(filter)) {
contentManagePage = contentManageRepository.findAllPaging(paging);
}else {
contentManagePage = contentManageRepository.findByTitlePaging(filter, paging);
}
if (contentManagePage.isEmpty()) {
log.error("No record found!!! ", filter);
throw new GenericSuccessException(StaffNotificationExceptionEnum.CONTENT_MANAGE_PAGE_SEARCH_NOT_FOUND_EXCEPTION);
}
ArrayList<ContentManageVO> ContentManageVOList = new ArrayList<>();
for (ContentCountryDto contentManage : contentManagePage) {
ContentManageVO contentManageVO = new ContentManageVO();
BeanUtils.copyProperties(contentManage, contentManageVO);
ContentManageVOList.add(contentManageVO);
}
return ContentManagePageVO.builder()
.page(contentManagePage.getNumber())
.pageSize(contentManagePage.getSize())
.result(ContentManageVOList)
.total(contentManagePage.getTotalElements())
.build();
}
Repository
@Transactional(rollbackFor = Exception.class)
@Query("select new com.model.entity.ContentCountryDto (A.id, A.position ,A.title,A.shortdescription,A.thumbnailimage, A.linkactions, A.last_updated_date, A.last_updated_by, A.country.countryId, A.country.countryName, A.date_published) " +
"from ContentManage as A inner join A.country as B where lower(A.title) like lower(concat('%', :filter,'%') ) or lower(A.shortdescription) like lower(concat('%', :filter,'%') ) or lower(B.countryName) like lower(concat('%', :filter,'%')) or lower(A.linkactions) like lower(concat('%', :filter,'%'))")
Page<ContentCountryDto> findByTitlePaging(String filter, Pageable pageable);
I would like to add index to retrieve data from the database more quickly. I have no idea on index, please suggest me how to achieve index in spring boot or JPA