- Java EE 8 Design Patterns and Best Practices
- Rhuan Rocha Jo?o Purifica??o
- 158字
- 2021-07-23 16:55:01
Implementing the EmployeeBusiness class
The EmployeeBusiness class has the employee business logic:
import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.Optional;
@Stateless
public class EmployeeBusiness{
@Inject @Persistence
protected PersistenceManager persistenceManager;
public boolean save ( Employee employee ) throws Exception {
//Begin Transaction
persistenceManager.begin();
persistenceManager.persist(employee);
//End Transaction
persistenceManager.commit();
return true;
}
public Optional<Employee> findById(Employee employee ){
return Optional.ofNullable( (Employee) persistenceManager.load(employee.getId()).get());
}
}
In the preceding code block, we have the EmployeeBusiness class, which has the employee business logic. This class has the save(Employee) method, which is used to save employee data, and findById(Employee ), which is used to find an employee according to their ID. Note that, on the save method, we call the begin() method as well as commit() from the PersistenceManager class. These calls define the delimiting of a transaction and only the data is saved at the data source when the commit() method is called.
推薦閱讀
- Mastering vRealize Operations Manager(Second Edition)
- Linux系統架構與運維實戰
- Modern Web Testing with TestCafe
- 網絡操作系統:Windows Server 2003管理與應用
- Kali Linux滲透測試全流程詳解
- 玩到極致 iPhone 4S完全攻略
- Linux性能優化
- 網絡操作系統教程:Windows Server 2016管理與配置
- jQuery UI Cookbook
- 計算機系統:基于x86+Linux平臺
- OpenSolaris設備驅動原理與開發
- Social Data Visualization with HTML5 and JavaScript
- Windows 8實戰從入門到精通(超值版)
- VMware Horizon View Essentials
- Linux網絡配置與安全管理