- 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.
推薦閱讀
- 樂學(xué)Windows操作系統(tǒng)
- Linux運維實戰(zhàn):CentOS7.6操作系統(tǒng)從入門到精通
- Puppet實戰(zhàn)
- 白話區(qū)塊鏈
- 蘋果電腦玩全攻略 OS X 10.8 Mountain Lion
- 玩到極致 iPhone 4S完全攻略
- Instant Optimizing Embedded Systems using Busybox
- 數(shù)據(jù)中心系統(tǒng)工程及應(yīng)用
- 嵌入式系統(tǒng)原理及開發(fā)
- Ceph分布式存儲實戰(zhàn)
- Vim 8文本處理實戰(zhàn)
- Python UNIX和Linux系統(tǒng)管理指南
- μC/OS-III內(nèi)核實現(xiàn)與應(yīng)用開發(fā)實戰(zhàn)指南:基于STM32
- Linux內(nèi)核API完全參考手冊(第2版)
- Angular權(quán)威教程