Project Learning
Project Learning
EX:
UnCorrect Naming:
List<String> findSupplierCompany();
Correct Naming:
List<String> getListOfSupplierCompany();
2.Entity 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:
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
if (!uniqueProductCodes.add(productCode.getProductCode())) {
duplicateProducts.add(productCode);
if (!duplicateProducts.isEmpty()) {
false , null);
Instead of this,
if (!uniqueProductCodes.add(productCode.getProductCode())) {
false , null);
}
EX:
if (productCode.getStandardCost().compareTo(productCode.getListPrice()) >= 0) {
return returnResponse("404", "Standard cost should be less than the price list.", false, null);
if (productCode.getStandardCost().compareTo(productCode.getListPrice()) >= 0 ||
"1. Standard cost "+ productCode.getStandardCost() + " should be less than the
price list "+productCode.getListPrice() +
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();
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
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.
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