官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 青州市| 秦安县| 江川县| 安仁县| 汾西县| 青州市| 寿宁县| 恩平市| 蒙自县| 灵武市| 平舆县| 咸丰县| 大新县| 皋兰县| 双峰县| 宁河县| 沙田区| 双桥区| 海宁市| 和顺县| 民乐县| 长乐市| 牙克石市| 保靖县| 娱乐| 全州县| 叶城县| 武宣县| 靖边县| 山东省| 五莲县| 阿图什市| 商丘市| 阳泉市| 项城市| 长阳| 汝南县| 綦江县| 马山县| 旺苍县| 黔南|