/
Apathy21
/
company
Обзор
Документация
Войти
/
Apathy21
/
company
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
MainService/src/main/java/org/example/service/CompanyService.java
43 строки
1 KB
alexeev509
Skeletop company app realization
13 сен 2024, 19:21
13 сен 2024, 19:21
2a02e11
Код
Авторство
О чём код?
package org.example.service; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.inject.Named; import jakarta.transaction.Transactional; import org.example.Entity.Address; import org.example.Entity.Company; import org.example.dao.AddressDaoImpl; import org.example.dao.api.CompanyDao; import java.util.List; import java.util.Optional; @Named("companyService") @ApplicationScoped public class CompanyService { @Inject private CompanyDao companyDao; @Inject private AddressDaoImpl daoAddress; public List<Company> findAllWithRangeConstraint(int currentPage, int pageSize) { int from = (currentPage - 1) * pageSize; int to = currentPage * pageSize; return companyDao.findAllWithRangeConstraint(from, to); } @Transactional public void save(Company createdCompany) { // #logic-explanation: we must check: have we such Address in db or not: Optional<Address> addressByLocation = daoAddress.getAddressByLocation(createdCompany.getAddress()); // #logic-explanation: if we have this address -> we must use actual and don't create new; addressByLocation.ifPresent(createdCompany::setAddress); companyDao.save(createdCompany); } @Transactional public void delete(Company company) { companyDao.delete(company); } }