- 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.
推薦閱讀
- WindowsServer2012Hyper-V虛擬化部署與管理指南
- SOA實踐者說
- Linux集群和自動化運(yùn)維
- 精解Windows8
- Windows Vista融會貫通
- 嵌入式操作系統(tǒng)(Linux篇)(微課版)
- 8051軟核處理器設(shè)計實戰(zhàn)
- 無蘋果不生活 The New iPad隨身寶典
- OpenSolaris設(shè)備驅(qū)動原理與開發(fā)
- Windows 7使用詳解(修訂版)
- Linux應(yīng)用大全 基礎(chǔ)與管理
- Linux內(nèi)核API完全參考手冊(第2版)
- 電腦辦公(Windows 10 + Office 2016)入門與提高(超值版)
- 電腦辦公(Windows 7+Office 2016)入門與提高
- 深入理解Android:卷III