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

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.

主站蜘蛛池模板: 荥经县| 城固县| 富平县| 丹凤县| 仁布县| 怀集县| 溆浦县| 海宁市| 安平县| 固原市| 郓城县| 津南区| 浮梁县| 裕民县| 襄城县| 航空| 竹山县| 余庆县| 奉新县| 新余市| 台前县| 新丰县| 双江| 鱼台县| 龙山县| 阳谷县| 阿拉善盟| 阳西县| 获嘉县| 公主岭市| 娄底市| 光泽县| 北宁市| 宁晋县| 文山县| 安远县| 格尔木市| 会泽县| 玛多县| 舞钢市| 浦东新区|