You are on page 1of 5

Project Learning:

Need Understanding and Checking:

1.Important to pay attention to naming conventions:

EX:

UnCorrect Naming:

@Query(value = "SELECT company FROM suppliers",nativeQuery = true)

List<String> findSupplierCompany();

Correct Naming:

@Query(value = "SELECT company FROM suppliers",nativeQuery = true)

List<String> getListOfSupplierCompany();

2.Entity Query:

Use entity query in Repository instead of native query

DrawBack:

Native queries are typically written as strings within the Java code. This can lead to reduced code
readability and maintainability, as SQL syntax is embedded within the Java code, making it harder to
understand and modify the queries. Additionally, native queries do not benefit from compile-time
checks and can lead to runtime errors if the queries are not constructed correctly.

3.@Request Body:

We can pass only one object for Request Body but we can use more than one annotation for
method parameters.
4.Check first Mandatory condition(validation) before write the other validation:

EX:

SupplierEntity convertedSupplierEntity = modelMapper.map(requestDto,


SupplierEntity.class);

if (convertedSupplierEntity.getId() == null) {

supplierServiceRepository.save(convertedSupplierEntity);

if our first and mandatory condition is failed then next step or before do some validation is
waste

5.We need to understand what we do:

Need to know using some condition is need or not for Example,

if (!uniqueProductCodes.add(productCode.getProductCode())) {

duplicateProducts.add(productCode);

if (!duplicateProducts.isEmpty()) {

return returnResponse("BAD REQUEST", "You Gave Same Product Code....",

false , null);

Instead of this,

if (!uniqueProductCodes.add(productCode.getProductCode())) {

return returnResponse("BAD REQUEST", "You Gave Same Product Code....",

false , null);
}

6.we need to show what is client mistake:

EX:

if (productCode.getStandardCost().compareTo(productCode.getListPrice()) >= 0) {

return returnResponse("404", "Standard cost should be less than the price list.", false, null);

here user doesn't know what is their exact mistake.istead of this

if (productCode.getStandardCost().compareTo(productCode.getListPrice()) >= 0 ||

productCode.getReorderLevel() >= productCode.getTargetLevel()) {

return returnResponse("BAD REQUEST", "You Have to check two properties: " +

"1. Standard cost "+ productCode.getStandardCost() + " should be less than the
price list "+productCode.getListPrice() +

"2. Reorder level "+productCode.getReorderLevel()+" should be less than Target


Quantity "+productCode.getTargetLevel(),

false , null );

here passing the value what user given. By do this user will know what is their mistake.

7.Method create for repeat code or which code use more than one place :

EX:

we use ConvergentResponseBean many more time for return our message to user.
TO do this we put that one method and use whatever you want.

return ConvergentResponseBean.builder()

.data(supplierName)

.messageCode("200 OK")
.message("Supplier Name Saved")

.success(true)

.build();

By do this more time code get more bigger Instead of this,

private <T> ConvergentResponseBean<T> returnResponse(String messageCode, String message,


boolean success ,T data) {

return ConvergentResponseBean.<T>builder()

.data(data)

.messageCode(messageCode)

.message(message)

.success(success)

.build();

By do this we use returnResponse method can reduce the codeline and readability.

 Also we put this method into two type one is PassitiveReturnreponse and
NagativeReturnResponse by do this we can reduce the more time

9.Write correct queries:

For example check company name unique or not. For do this...

@Query(value = "SELECT u.companyName FROM SupplierEntity u")

List<String> getListOfSupplierCompany();

This is give list of company name but instead of we use where condition by get exact
name of given company name.

So we can reduce iterate time and increase application run speed.


 We need to reduce our app load time by reduce use more stream or loops and code
redundancy

 We don't need to do ModelMapper for single Feild because it's also take a time. Understand
and then write the code....

Exception:

----------

1.Stream method throw an error (NullPointer Exception) because the one of the fetching data null
While fetching and check if the data is already exist or not

You might also like